From 3b68d421d10175fc971378c025ca0e0722b8d487 Mon Sep 17 00:00:00 2001 From: Et0h Date: Fri, 18 Jul 2014 13:57:50 +0100 Subject: [PATCH] Disable subitems when parent is unchecked --- syncplay/ui/GuiConfiguration.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index ab37d21..e3f127b 100644 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -284,6 +284,21 @@ class ConfigDialog(QtGui.QDialog): elif isinstance(widget, QLineEdit): self.config[valueName] = widget.text() + def connectChildren(self, widget): + widgetName = str(widget.objectName()) + if self.subitems.has_key(widgetName) and isinstance(widget, QCheckBox): + widget.stateChanged.connect(lambda: self.updateSubwidgets(self, widget)) + self.updateSubwidgets(self, widget) + + def updateSubwidgets(self, container, parentwidget, subwidgets=None): + widgetName = parentwidget.objectName() + if not subwidgets: + subwidgets = self.subitems[widgetName] + for widget in container.children(): + self.updateSubwidgets(widget, parentwidget, subwidgets) + if hasattr(widget, 'objectName') and widget.objectName() and widget.objectName() in subwidgets: + widget.setDisabled(not parentwidget.isChecked()) + def addBasicTab(self): config = self.config playerpaths = self.playerpaths @@ -459,6 +474,9 @@ class ConfigDialog(QtGui.QDialog): self.desyncSettingsLayout.addWidget(self.rewindThresholdLabel, 4, 0, 1, 1, Qt.AlignLeft) self.desyncSettingsLayout.addWidget(self.rewindThresholdSpinbox, 4, 1, Qt.AlignLeft) + self.subitems['slowOnDesync'] = ["slowdown-threshold"] + self.subitems['rewindOnDesync'] = ["rewind-threshold"] + self.desyncSettingsLayout.setAlignment(Qt.AlignLeft) self.desyncSettingsGroup.setLayout(self.desyncSettingsLayout) self.desyncSettingsOptionsLayout.addWidget(self.desyncFrame) @@ -518,6 +536,8 @@ class ConfigDialog(QtGui.QDialog): self.showOSDWarningsCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "bullet_black.png")) self.osdSettingsLayout.addWidget(self.showOSDWarningsCheckbox) + self.subitems['showOSD'] = ["showSameRoomOSD", "showDifferentRoomOSD", "showSlowdownOSD", "showOSDWarnings"] + self.osdSettingsGroup.setLayout(self.osdSettingsLayout) self.osdSettingsLayout.setAlignment(Qt.AlignTop) self.messageLayout.addWidget(self.osdSettingsGroup) @@ -702,6 +722,7 @@ class ConfigDialog(QtGui.QDialog): self.playerpaths = playerpaths self.datacleared = False self.config['resetConfig'] = False + self.subitems = {} if self.config['clearGUIData'] == True: self.config['clearGUIData'] = False @@ -758,4 +779,5 @@ class ConfigDialog(QtGui.QDialog): if constants.SHOW_TOOLTIPS: self.processWidget(self, lambda w: self.loadTooltips(w)) - self.processWidget(self, lambda w: self.loadValues(w)) \ No newline at end of file + self.processWidget(self, lambda w: self.loadValues(w)) + self.processWidget(self, lambda w: self.connectChildren(w)) \ No newline at end of file