ui: Let users edit list configurations
offlate/ui/listsettingsedit.py
18 | 18 | from PyQt5.QtGui import * | |
19 | 19 | from PyQt5.QtCore import * | |
20 | 20 | ||
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 | + | ||
21 | 56 | class ListSettingsEdit(QWidget): | |
22 | 57 | textChanged = pyqtSignal() | |
23 | 58 | ||
… | |||
63 | 98 | line.append(d[s.key]) | |
64 | 99 | self.addLine(line) | |
65 | 100 | ||
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 | + | ||
66 | 117 | def initUI(self): | |
67 | 118 | vbox = QVBoxLayout() | |
68 | 119 | hbox = QHBoxLayout() | |
69 | 120 | self.setLayout(vbox) | |
70 | 121 | self.treeWidget = QTreeWidget() | |
71 | 122 | self.treeWidget.setColumnCount(len(self.conf.specifications)) | |
123 | + | self.treeWidget.itemDoubleClicked.connect(self.editLine) | |
72 | 124 | vbox.addWidget(self.treeWidget) | |
73 | 125 | ||
74 | 126 | self.widgets = [] |