Skip to content

Commit

Permalink
feat(config-registrar): add has_option method and improve GUI handling
Browse files Browse the repository at this point in the history
- Add a new method `has_option` in the config_registrar.ConfigKey class.- Refactor GUI_main to improve item widget handling and data setting.
- Resolve conflicts and adjust the layout in the main.ui file.
- Update Ui_MainWindow to reflect layout and widget changes.
- The configuration editor now correctly handles editable items and
  displays options as comboboxes where appropriate.

BREAKING CHANGE: The configuration handling has been modified, which
might affect users depending on the previous implementation.
  • Loading branch information
northgreen committed Jul 1, 2024
1 parent 0010ed1 commit 343c113
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 29 deletions.
35 changes: 28 additions & 7 deletions ictye-live-dm/src/ictye_live_dm/GUI/Ui_MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setWindowModality(QtCore.Qt.NonModal)
Form.resize(765, 681)
Form.resize(823, 681)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(".\\../ictye_live_dm/icon.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Form.setWindowIcon(icon)
Expand Down Expand Up @@ -126,27 +126,46 @@ def setupUi(self, Form):
self.settingScrollArea.setAlignment(QtCore.Qt.AlignCenter)
self.settingScrollArea.setObjectName("settingScrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 732, 592))
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 749, 592))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem)
self.pushButton_3 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_5.addWidget(self.pushButton_3)
self.pushButton_2 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout_5.addWidget(self.pushButton_2)
self.verticalLayout_5.addLayout(self.horizontalLayout_5)
self.settingTreeWidget = QtWidgets.QTreeWidget(self.scrollAreaWidgetContents)

Check notice on line 144 in ictye-live-dm/src/ictye_live_dm/GUI/Ui_MainWindow.py

View workflow job for this annotation

GitHub Actions / qodana

An instance attribute is defined outside `__init__`

Instance attribute settingTreeWidget defined outside __init__
self.settingTreeWidget.setMinimumSize(QtCore.QSize(710, 117))
self.settingTreeWidget.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.settingTreeWidget.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked|QtWidgets.QAbstractItemView.EditKeyPressed|QtWidgets.QAbstractItemView.SelectedClicked)
self.settingTreeWidget.setObjectName("settingTreeWidget")
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.settingTreeWidget.headerItem().setFont(0, font)
self.settingTreeWidget.headerItem().setBackground(0, QtGui.QColor(255, 255, 255))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.settingTreeWidget.headerItem().setFont(1, font)
self.verticalLayout_5.addWidget(self.settingTreeWidget)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()

Check notice on line 158 in ictye-live-dm/src/ictye_live_dm/GUI/Ui_MainWindow.py

View workflow job for this annotation

GitHub Actions / qodana

An instance attribute is defined outside `__init__`

Instance attribute horizontalLayout_3 defined outside __init__
self.horizontalLayout_3.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.horizontalLayout_3.setSpacing(6)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
spacerItem = QtWidgets.QSpacerItem(90, 20, QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem)
spacerItem1 = QtWidgets.QSpacerItem(90, 20, QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem1)
self.applyButton = QtWidgets.QPushButton(self.scrollAreaWidgetContents)

Check notice on line 164 in ictye-live-dm/src/ictye_live_dm/GUI/Ui_MainWindow.py

View workflow job for this annotation

GitHub Actions / qodana

An instance attribute is defined outside `__init__`

Instance attribute applyButton defined outside __init__
self.applyButton.setObjectName("applyButton")
self.horizontalLayout_3.addWidget(self.applyButton)
spacerItem1 = QtWidgets.QSpacerItem(90, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem1)
spacerItem2 = QtWidgets.QSpacerItem(90, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem2)
self.verticalLayout_5.addLayout(self.horizontalLayout_3)
self.settingScrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout_3.addWidget(self.settingScrollArea)
Expand Down Expand Up @@ -180,6 +199,8 @@ def retranslateUi(self, Form):
item = self.pluginListTable.horizontalHeaderItem(1)
item.setText(_translate("Form", "Description"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.pluginListPage), _translate("Form", "Plugins"))
self.pushButton_3.setText(_translate("Form", "PushButton"))
self.pushButton_2.setText(_translate("Form", "PushButton"))
self.settingTreeWidget.headerItem().setText(0, _translate("Form", "Item"))
self.settingTreeWidget.headerItem().setText(1, _translate("Form", "Value"))
self.applyButton.setText(_translate("Form", "Apply"))
Expand Down
33 changes: 19 additions & 14 deletions ictye-live-dm/src/ictye_live_dm/GUI_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@ def createEditor(self, parent, option, index):

class SettingTreeWidgetItem(QTreeWidgetItem):
def __init__(self, parent, key, values: Union[config_registrar.ConfigTree, config_registrar.ConfigKey]):
keys = [str(key), str(values.get_value() if isinstance(values, config_registrar.ConfigTree) else values.get())]
if isinstance(values, config_registrar.ConfigKey) and values.has_option():
del keys[1]
print(values)
self.__value = values
keys = [str(key), str("" if isinstance(values, config_registrar.ConfigTree) else values.get())]
super().__init__(parent, keys)

if isinstance(values, config_registrar.ConfigKey) and values.has_option():
combo_box = QComboBox()
combo_box.addItems([str(item) for item in values.get_options()])
self.treeWidget().setItemWidget(self, 1, combo_box)

def setData(self, column, role, value):
print(value)
if isinstance(self.__value, config_registrar.ConfigKey):
self.__value.set(value)
super().setData(column, role, value)


class SettingTreeBuilder:
def __init__(self, tree_widget):
Expand All @@ -41,23 +52,17 @@ def build_tree(self, config_tree: config_registrar.ConfigTree):
if config_tree.is_list():
for i, v in enumerate(config_tree.values()):
parent = SettingTreeWidgetItem(self.tree_widget, i, v)
parent.setFlags(parent.flags() | Qt.ItemIsEditable)
if isinstance(v, config_registrar.ConfigKey) and v.has_option():
combo_box = QComboBox()
combo_box.addItems([str(item) for item in v.get_options()])
self.tree_widget.setItemWidget(parent, 1, combo_box)
if isinstance(v, config_registrar.ConfigKey):
parent.setFlags(parent.flags() | Qt.ItemIsEditable)

if isinstance(v, config_registrar.ConfigTree):
SettingTreeBuilder(parent).build_tree(v)

elif config_tree.is_dict():
for k, v in config_tree.items():
parent = SettingTreeWidgetItem(self.tree_widget, k, v)
parent.setFlags(parent.flags() | Qt.ItemIsEditable)
if isinstance(v, config_registrar.ConfigKey) and v.has_option():
combo_box = QComboBox()
combo_box.addItems([str(item) for item in v.get_options()])
self.tree_widget.setItemWidget(parent, 1, combo_box)
if isinstance(v, config_registrar.ConfigKey):
parent.setFlags(parent.flags() | Qt.ItemIsEditable)

if isinstance(v, config_registrar.ConfigTree):
SettingTreeBuilder(parent).build_tree(v)
Expand Down Expand Up @@ -89,7 +94,7 @@ def __init__(self, parent=None):
def init_setting_tab(self):
config = configs.ConfigManager()
tree_builder = SettingTreeBuilder(self.settingTreeWidget)
self.settingTreeWidget.setItemDelegateForColumn(0, NonEditableDelegate(self))
# self.settingTreeWidget.setItemDelegateForColumn(0, NonEditableDelegate(self))
config_tree = config.get_config_tree()
tree_builder.build_tree(config_tree)

Expand Down
60 changes: 52 additions & 8 deletions ictye-live-dm/src/ictye_live_dm/QT-GUI/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>765</width>
<width>823</width>
<height>681</height>
</rect>
</property>
Expand Down Expand Up @@ -263,19 +263,44 @@
<rect>
<x>0</x>
<y>0</y>
<width>732</width>
<width>749</width>
<height>592</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="settingTreeWidget">
<property name="minimumSize">
<size>
<width>710</width>
<height>117</height>
</size>
</property>
<property name="cursor" stdset="0">
<cursorShape>ArrowCursor</cursorShape>
</property>
Expand All @@ -286,11 +311,30 @@
<property name="text">
<string>Item</string>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="background">
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
</column>
</widget>
</item>
Expand Down
4 changes: 4 additions & 0 deletions ictye-live-dm/src/ictye_live_dm/depends/config_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def get(self, key: str) -> Union[ConfigKey]:
# 对于字典存储,直接使用键来获取值
return self.__content[key]

def has_option(self):
return False

def __getitem__(self, item):
return self.get(item)

Expand Down Expand Up @@ -294,6 +297,7 @@ def dump(self, value):
self.config = ConfigTree(is_list=True, build_list=value)

def dump_default(self, value):
# TODO:要在這裏合并所有配置
if isinstance(value, dict):
self.config = ConfigTree(build_dict=value, build_with_default=True) + self.config
elif isinstance(value, list):
Expand Down

0 comments on commit 343c113

Please sign in to comment.