Ejemplo n.º 1
0
    def on_change(self):
        sender = self.sender()
        if sender.parent().objectName() == 'global':
            user = sender.parent().parent().objectName()
            if isinstance(sender, QLineEdit):
                if sender.text().isdigit():
                    self.config[user]['global'][sender.objectName()] = eval(sender.text())
            if isinstance(sender, QComboBox):
                self.config[user]['global'][sender.objectName()] = translate(sender.currentText())
        else:
            user = sender.parent().parent().parent().parent().objectName()
            rule_index = int(sender.parent().objectName().split()[1])
            rule = self.config[user]['rules'][rule_index]
            if isinstance(sender, QLineEdit):
                try:
                    value = int(sender.text())
                except ValueError:
                    try:
                        value = float(sender.text())
                    except ValueError:
                        value = translate(sender.text())
            else:
                value = translate(sender.currentText())

            target = f'rule'
            for item in sender.objectName().split():
                if item.isdigit():
                    target += f'[{item}]'
                else:
                    target += f'["{item}"]'
            exec(target + '= value')

        if self.validator(sender):
            write_cfg(self.config)
            self.onRefresh()
Ejemplo n.º 2
0
 def on_remove_rule(self):
     tab = self.tab_widget.currentWidget()
     user = tab.objectName()
     cfg = self.config[user]
     current_index_of_rule = tab.rule_tab_widget.currentIndex()
     delete_rule(self.config[user], current_index_of_rule)
     tab.rule_tab_widget.removeTab(current_index_of_rule)
     write_cfg(self.config)
Ejemplo n.º 3
0
 def on_add_rule(self):
     tab = self.tab_widget.currentWidget()
     user = tab.objectName()
     cfg = self.config[user]
     new_rule = add_rule(cfg)
     write_cfg(self.config)
     rules_amount = len(self.config[user]['rules'])
     self.set_a_rule(tab, new_rule, rules_amount - 1)
Ejemplo n.º 4
0
    def on_add_step(self):
        sender = self.sender()
        user = sender.parent().parent().parent().parent().objectName()
        rule_index = int(sender.parent().objectName().split()[1])
        rule = self.config[user]['rules'][rule_index]
        widgets = sender.parent().widgets

        step = add_step(rule)
        write_cfg(self.config)
        step_widgets = self.setup_step_widgets(step, len(rule['steps']) - 1)
        widgets = widgets[:-2] + step_widgets + widgets[-2:]
        sender.parent().widgets = widgets
        self.lay_rule_widgets(sender.parent().layout(), widgets)
        self.onRefresh()
Ejemplo n.º 5
0
    def on_rm_step(self):
        sender = self.sender()
        user = sender.parent().parent().parent().parent().objectName()
        rule_index = int(sender.parent().objectName().split()[1])
        rule = self.config[user]['rules'][rule_index]
        widgets = sender.parent().widgets
        layout = sender.parent().layout()
        widgets = widgets[:-20] + widgets[-2:]
        sender.parent().widgets = widgets

        if rm_step(rule):
            write_cfg(self.config)
            for i in reversed(range(layout.count())):
                widgetToRemove = layout.itemAt(i).widget()
                # remove it from the layout list
                # layout.removeWidget(widgetToRemove)
                # remove it from the gui
                widgetToRemove.setParent(None)
            self.lay_rule_widgets(layout, widgets)
            self.onRefresh()