Skip to main content

A library for easy configuration v2

Project description

EasyConfig

This library provides a quick and easy way to create configuration dialogs in pyQt. To get started it is necessary to create a EasyConfig object and add the needed configuration options. All must be done after having created a QApplication.

import sys
from PyQt5.QtWidgets import QPushButton, QApplication, QMainWindow, QWidget, QVBoxLayout, QMessageBox
from EasyConfig import EasyConfig

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.v_layout = QVBoxLayout()
        helper = QWidget()
        helper.setLayout(self.v_layout)
        self.setCentralWidget(helper)

        show_btn = QPushButton("Show")
        self.v_layout.addWidget(show_btn)

        name_btn = QPushButton("Get Data")
        self.v_layout.addWidget(name_btn)

        save_btn = QPushButton("Save")
        self.v_layout.addWidget(save_btn)

        show_btn.clicked.connect(self.show_info)
        save_btn.clicked.connect(self.save)
        name_btn.clicked.connect(self.get_name)
        
        # Configure configuration dialog 
        
        self.config = EasyConfig(editable=True)

        root = self.config.root()
        self.info = root.addSubSection("info", pretty="Information")
        self.name = self.info.getString("name", pretty="Name", default="John")
        surname = self.info.addString("surname", pretty="Surname", default="Doe", editable=False, save=False)
        self.age = self.info.addInt("age", pretty="Age", default=30)
        self.cb = self.info.addCheckbox("married", pretty="Married", default=False)
        secret = self.info.addString("account", default="bvghfhfgh", hidden=True)

        self.work = root.getSubSection("job", pretty="Job")

        self.slider = self.work.addSlider("salary", pretty="Salary (K)", default=500, min=0, max=1000, den=10, fmt="{:.0f}", callback=lambda x, y: print(x, y))
        self.combo_box = self.work.addCombobox("position", pretty="Position", default=1, items=["Manager", "Employee", "Owner"])

        hidden = root.addHidden("hidden")
        hidden.addString("hidden_string", default="This is an Hidden String")

        self.config.load("config.yaml")

    def show_info(self):
        self.config.exec(self.config.root())
        # self.config.exec(self.info)

    def save(self):
        self.config.save("config.yaml")

    def get_name(self):
        QMessageBox.information(self, "Name",
                                "The name can be obtained this way: " + self.name.get_value() + " or this way: " + self.info.get("name") +
                                " or this way: " + self.config.root().get("info/name"))

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.exec()


This example creates a simple button that, when clicked, will show a basic configuration dialog.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easyconfig2-0.0.1.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easyconfig2-0.0.1-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file easyconfig2-0.0.1.tar.gz.

File metadata

  • Download URL: easyconfig2-0.0.1.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for easyconfig2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c96a9d3c899795f86540bd49c5f77e8a848c859b362b635f27fe841083279544
MD5 0d0a853f773b0b713dc95f73e8fca8e0
BLAKE2b-256 bbc96e6508f816746c6a225e1842ee2661fe7f363cdb54d615187f8b63c8d2a3

See more details on using hashes here.

File details

Details for the file easyconfig2-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: easyconfig2-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for easyconfig2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0542cfb349436c8360a3cb98c88651c7bd8e61c030a6878946d52f7381c31b48
MD5 80f3fe2f1a3e44d1f7a1a35de7e648c8
BLAKE2b-256 1908fc4354b2a86d1ef25ef531b9c4ead1b30ef7685187f72270b7f1cc3fa84a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page