Commit 2e12551d authored by Andoni Jimenez's avatar Andoni Jimenez
Browse files

Refactor Radiobutton add text and shorcut

parent 3e450981
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -148,18 +148,13 @@ class Ui(QtWidgets.QMainWindow):
                    for element in tconf['elements']:
                        element:dict
                        try:
                            shortcut = ''
                            if 'shortcut' in element.keys():
                                shortcut = element['shortcut']

                            eid = element['id']
                            wid = f"rb_{eid}"
                            # radiobutton
                            widget = QtWidgets.QRadioButton(None)
                            widget.setObjectName(wid)
                            widget.setSizePolicy(QtWidgets.QSizePolicy(policy.Minimum, policy.Fixed))
                            widget.setText(f"{element['name']}")
                            widget.setShortcut(shortcut)
                            addRadioButtonTexts()
                            addToolTip(widget, element)
                            
                            gbb.addButton(widget)
@@ -171,10 +166,10 @@ class Ui(QtWidgets.QMainWindow):
                            self.rbNames.append(wid)
                            
                            # shortcut label
                            if shortcut != '':
                            if 'shortcut' in element.keys():
                                widget = QtWidgets.QLabel(None)
                                widget.setSizePolicy(QtWidgets.QSizePolicy(policy.Preferred, policy.Preferred))
                                widget.setText(f"[{shortcut}]")
                                widget.setText(f"[{element['shortcut']}]")
                                gb.layout().addWidget(widget, count//cols, count%cols)
                            count += 1
                        except KeyError as e:
@@ -556,3 +551,18 @@ def addCheckBoxTexts(widget: QtWidgets.QCheckBox, element:dict) -> None:
            widget.setShortcut(shortcut)
            text = f"[{shortcut}] {name}"
        widget.setText(text)
        
def addRadioButtonTexts(widget: QtWidgets.QRadioButton, element:dict) -> None:
    id, name, shortcut = None, None, None
    try:
        id = element['id']
        name = element['name']
        shortcut = element['shortcut']
    except KeyError as e:
        if name is None:
            name = id.capitalize()
        print(e)
    finally:
        if shortcut is not None:
            widget.setShortcut(shortcut)
        widget.setText(name)
 No newline at end of file