Skip to content

editor_dialog

editor_dialog

Classes

ConfigEditorDialog(config, parent=None, delete_on_close=False)

Bases: QDialog

Floating, non-modal dialog editing the layers of a LayeredConfig.

Intended to be spawned by a host application, which owns it through parent.

Attributes:

Name Type Description
saved Signal

Emitted with the layer name after a layer is saved.

Initialize the dialog.

Parameters:

Name Type Description Default
config LayeredConfig

The config whose layers are edited.

required
parent QWidget | None

Parent widget.

None
delete_on_close bool

Delete the dialog once it is closed.

False
Source code in src/json_config_qt/editor_dialog.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(
    self,
    config: LayeredConfig,
    parent: QtWidgets.QWidget | None = None,
    delete_on_close: bool = False,
):
    """Initialize the dialog.

    Args:
        config (LayeredConfig): The config whose layers are edited.
        parent (QtWidgets.QWidget | None, optional): Parent widget.
        delete_on_close (bool, optional): Delete the dialog once it is closed.
    """
    super().__init__(parent)
    self.setModal(False)
    self.setWindowFlag(QtCore.Qt.WindowType.WindowMinimizeButtonHint)
    self.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose, delete_on_close)
    self.resize(900, 700)
    self.editor = ConfigEditorWidget(config, self)
    self.document = self.editor.document
    self._create_widgets()
    self._create_layouts()
    self._create_connections()
    self._update_title()
Attributes
document = self.editor.document instance-attribute
editor = ConfigEditorWidget(config, self) instance-attribute
saved = QtCore.Signal(str) class-attribute instance-attribute
Methods:
reject()

Close the dialog unless the user cancels the unsaved-changes prompt.

Source code in src/json_config_qt/editor_dialog.py
112
113
114
115
def reject(self) -> None:
    """Close the dialog unless the user cancels the unsaved-changes prompt."""
    if self.editor.confirm_discard():
        super().reject()
show_for(config, parent=None) classmethod

Show the editor for config, reusing the open one if there is one.

Parameters:

Name Type Description Default
config LayeredConfig

The config whose layers are edited.

required
parent QWidget | None

Parent widget for a new dialog.

None

Returns:

Name Type Description
ConfigEditorDialog ConfigEditorDialog

The shown dialog, deleted when closed.

Source code in src/json_config_qt/editor_dialog.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@classmethod
def show_for(
    cls, config: LayeredConfig, parent: QtWidgets.QWidget | None = None
) -> ConfigEditorDialog:
    """Show the editor for *config*, reusing the open one if there is one.

    Args:
        config (LayeredConfig): The config whose layers are edited.
        parent (QtWidgets.QWidget | None, optional): Parent widget for a new dialog.

    Returns:
        ConfigEditorDialog: The shown dialog, deleted when closed.
    """
    key = id(config)
    dialog = cls._instances.get(key)
    if dialog is None:
        dialog = cls(config, parent, delete_on_close=True)
        cls._instances[key] = dialog
        dialog.destroyed.connect(lambda *_: cls._instances.pop(key, None))
    dialog.show()
    dialog.raise_()
    dialog.activateWindow()
    return dialog