ui: Let users edit list configurations

Julien LepillerSun Aug 29 14:23:30+0200 2021

14fe2f4

ui: Let users edit list configurations

offlate/ui/listsettingsedit.py

1818
from PyQt5.QtGui import *
1919
from PyQt5.QtCore import *
2020
21+
class ListSettingsRowEdit(QDialog):
22+
    def __init__(self, specifications, content, parent = None):
23+
        super().__init__(parent)
24+
        self.content = content
25+
        self.specifications = specifications
26+
        self.widgets = {}
27+
        self.initUI()
28+
29+
    def initUI(self):
30+
        vbox = QVBoxLayout()
31+
        hbox = QHBoxLayout()
32+
33+
        for s in self.specifications:
34+
            edit = QLineEdit()
35+
            edit.setPlaceholderText(self.tr(s.placeholder))
36+
            edit.setText(self.content[s.key])
37+
            self.widgets[s.key] = edit
38+
            hbox.addWidget(edit)
39+
40+
        vbox.addLayout(hbox)
41+
42+
        buttons = QHBoxLayout()
43+
        buttons.addStretch(1)
44+
        okbutton = QPushButton(self.tr("OK"))
45+
        buttons.addWidget(okbutton)
46+
        okbutton.clicked.connect(self.save)
47+
        vbox.addLayout(buttons)
48+
        self.setLayout(vbox)
49+
50+
    def save(self):
51+
        self.content = {}
52+
        for s in self.specifications:
53+
            self.content[s.key] = self.widgets[s.key].text()
54+
        self.close()
55+
2156
class ListSettingsEdit(QWidget):
2257
    textChanged = pyqtSignal()
2358

6398
                line.append(d[s.key])
6499
            self.addLine(line)
65100
101+
    def editLine(self, item, column):
102+
        specs = self.conf.specifications
103+
        data = {}
104+
        i = 0
105+
        for s in specs:
106+
            data[s.key] = item.text(i)
107+
            i += 1
108+
109+
        w = ListSettingsRowEdit(specs, data, self)
110+
        w.exec_()
111+
        i = 0
112+
        for s in specs:
113+
            item.setText(i, w.content[s.key])
114+
            i += 1
115+
        self.textChanged.emit()
116+
66117
    def initUI(self):
67118
        vbox = QVBoxLayout()
68119
        hbox = QHBoxLayout()
69120
        self.setLayout(vbox)
70121
        self.treeWidget = QTreeWidget()
71122
        self.treeWidget.setColumnCount(len(self.conf.specifications))
123+
        self.treeWidget.itemDoubleClicked.connect(self.editLine)
72124
        vbox.addWidget(self.treeWidget)
73125
74126
        self.widgets = []