|
@@ -7,17 +7,37 @@
|
7
|
7
|
# UI for changes to application configuration.
|
8
|
8
|
|
9
|
9
|
import string
|
|
10
|
+import pprint
|
10
|
11
|
from PyQt5 import QtWidgets
|
11
|
|
-from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout, QHBoxLayout, QTableWidget, QTableWidgetItem, QPushButton, QLineEdit, QGridLayout
|
|
12
|
+from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout, QHBoxLayout, QTableWidget, QTableWidgetItem, QPushButton, QLineEdit, QGridLayout, QComboBox
|
12
|
13
|
from PyQt5.QtGui import QFontDatabase, QIntValidator
|
13
|
14
|
from PyQt5.QtCore import Qt
|
14
|
15
|
|
15
|
16
|
class Printer(object):
|
16
|
|
- pass
|
|
17
|
+ # field 'api' for actual I/O
|
|
18
|
+ # field 'host' etc. for settings
|
|
19
|
+
|
|
20
|
+ def __repr__(self):
|
|
21
|
+ return pprint.pformat(vars(self))
|
17
|
22
|
|
18
|
23
|
class SettingsWindow(QWidget):
|
19
|
|
- columns = [ "Hostname", "API Key", "Tool Preheat", "Bed Preheat" ]
|
20
|
|
- presets = [ "octopi.local", "000000000_API_KEY_HERE_000000000", "0", "0" ]
|
|
24
|
+ genericColumns = [
|
|
25
|
+ ( "Hostname", "octopi.local" ),
|
|
26
|
+ ( "Interface", "OctoPrint" ),
|
|
27
|
+ ( "Tool Temp", "0" ),
|
|
28
|
+ ( "Bed Temp", "0" ),
|
|
29
|
+ ( "Jog Speed", "600" ),
|
|
30
|
+ ( "Jog Length", "10" ),
|
|
31
|
+ ]
|
|
32
|
+
|
|
33
|
+ apiColumns = [
|
|
34
|
+ ( "OctoPrint", [
|
|
35
|
+ ( "API Key", "000000000_API_KEY_HERE_000000000", [] )
|
|
36
|
+ ]),
|
|
37
|
+ ( "Moonraker", [
|
|
38
|
+ ( "Webcam", "0", [] )
|
|
39
|
+ ]),
|
|
40
|
+ ]
|
21
|
41
|
|
22
|
42
|
def __init__(self, parent, *args, **kwargs):
|
23
|
43
|
super(SettingsWindow, self).__init__(*args, **kwargs)
|
|
@@ -29,37 +49,9 @@ class SettingsWindow(QWidget):
|
29
|
49
|
box = QVBoxLayout()
|
30
|
50
|
self.setLayout(box)
|
31
|
51
|
|
32
|
|
- staticSettings = QGridLayout()
|
33
|
|
- box.addLayout(staticSettings, 0)
|
34
|
|
-
|
35
|
|
- self.jogSpeedText = QLabel("Jog Speed")
|
36
|
|
- staticSettings.addWidget(self.jogSpeedText, 0, 0)
|
37
|
|
-
|
38
|
|
- self.jogSpeed = QLineEdit(str(self.parent.jogMoveSpeed))
|
39
|
|
- self.jogSpeed.setValidator(QIntValidator(1, 6000))
|
40
|
|
- staticSettings.addWidget(self.jogSpeed, 0, 1)
|
41
|
|
-
|
42
|
|
- self.jogSpeedUnitText = QLabel("mm/min")
|
43
|
|
- staticSettings.addWidget(self.jogSpeedUnitText, 0, 2)
|
44
|
|
-
|
45
|
|
- self.jogLengthText = QLabel("Jog Length")
|
46
|
|
- staticSettings.addWidget(self.jogLengthText, 1, 0)
|
47
|
|
-
|
48
|
|
- self.jogLength = QLineEdit(str(self.parent.jogMoveLength))
|
49
|
|
- self.jogLength.setValidator(QIntValidator(1, 100))
|
50
|
|
- staticSettings.addWidget(self.jogLength, 1, 1)
|
51
|
|
-
|
52
|
|
- self.jogLengthUnitText = QLabel("mm")
|
53
|
|
- staticSettings.addWidget(self.jogLengthUnitText, 1, 2)
|
54
|
|
-
|
55
|
|
- helpText = "Usage:\n"
|
56
|
|
- helpText += "1st Column: Printer Hostname or IP address\n"
|
57
|
|
- helpText += "2nd Column: OctoPrint API Key (32 char hexadecimal)\n"
|
58
|
|
- helpText += "3rd Column: Tool Preheat Temperature (0 to disable)\n"
|
59
|
|
- helpText += "4th Column: Bed Preheat Temperature (0 to disable)"
|
60
|
|
- self.helpText = QLabel(helpText)
|
61
|
|
- box.addWidget(self.helpText, 0)
|
62
|
|
- box.setAlignment(self.helpText, Qt.AlignHCenter)
|
|
52
|
+ self.openWeb = QPushButton("&Open Web UI of selected")
|
|
53
|
+ self.openWeb.clicked.connect(self.openWebUI)
|
|
54
|
+ box.addWidget(self.openWeb, 0)
|
63
|
55
|
|
64
|
56
|
buttons = QHBoxLayout()
|
65
|
57
|
box.addLayout(buttons, 0)
|
|
@@ -72,73 +64,154 @@ class SettingsWindow(QWidget):
|
72
|
64
|
self.remove.clicked.connect(self.removePrinter)
|
73
|
65
|
buttons.addWidget(self.remove)
|
74
|
66
|
|
75
|
|
- printers = self.parent.readSettings()
|
76
|
|
- self.rows = len(printers)
|
77
|
|
- self.table = QTableWidget(self.rows, len(self.columns))
|
78
|
|
- box.addWidget(self.table, 1)
|
|
67
|
+ buttons2 = QHBoxLayout()
|
|
68
|
+ box.addLayout(buttons2, 0)
|
79
|
69
|
|
80
|
|
- for i in range(0, self.rows):
|
81
|
|
- p = printers[i]
|
|
70
|
+ self.up = QPushButton("Move &Up")
|
|
71
|
+ self.up.clicked.connect(self.moveUp)
|
|
72
|
+ buttons2.addWidget(self.up)
|
82
|
73
|
|
|
74
|
+ self.down = QPushButton("Move &Down")
|
|
75
|
+ self.down.clicked.connect(self.moveDown)
|
|
76
|
+ buttons2.addWidget(self.down)
|
|
77
|
+
|
|
78
|
+ # Printer data from OctoTray settings
|
|
79
|
+ self.data = self.parent.readSettings()
|
|
80
|
+ self.originalData = self.data.copy()
|
|
81
|
+
|
|
82
|
+ # Table of printers
|
|
83
|
+ self.printerCount = len(self.data)
|
|
84
|
+ self.printers = QTableWidget(self.printerCount, len(self.genericColumns))
|
|
85
|
+ box.addWidget(self.printers, 1)
|
|
86
|
+
|
|
87
|
+ # Populate table of printers
|
|
88
|
+ for i in range(0, self.printerCount):
|
|
89
|
+ p = self.data[i]
|
|
90
|
+
|
|
91
|
+ # hostname in first column
|
83
|
92
|
item = QTableWidgetItem(p.host)
|
84
|
|
- self.table.setItem(i, 0, item)
|
|
93
|
+ self.printers.setItem(i, 0, item)
|
85
|
94
|
|
86
|
|
- item = QTableWidgetItem(p.key)
|
87
|
|
- self.table.setItem(i, 1, item)
|
88
|
95
|
font = item.font()
|
89
|
96
|
font.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family())
|
90
|
97
|
item.setFont(font)
|
91
|
98
|
|
92
|
|
- if p.tempTool == None:
|
93
|
|
- item = QTableWidgetItem("0")
|
94
|
|
- else:
|
95
|
|
- item = QTableWidgetItem(p.tempTool)
|
96
|
|
- self.table.setItem(i, 2, item)
|
|
99
|
+ # API selection in second column
|
|
100
|
+ item = QComboBox()
|
|
101
|
+ for api, options in self.apiColumns:
|
|
102
|
+ item.addItem(api)
|
|
103
|
+ if p.apiType == api:
|
|
104
|
+ item.setCurrentText(api)
|
|
105
|
+ item.currentIndexChanged.connect(self.selectionChanged)
|
|
106
|
+ self.printers.setCellWidget(i, 1, item)
|
97
|
107
|
|
98
|
|
- if p.tempBed == None:
|
99
|
|
- item = QTableWidgetItem("0")
|
100
|
|
- else:
|
101
|
|
- item = QTableWidgetItem(p.tempBed)
|
102
|
|
- self.table.setItem(i, 3, item)
|
|
108
|
+ # Tool Temp in third column
|
|
109
|
+ item = QTableWidgetItem(p.tempTool)
|
|
110
|
+ self.printers.setItem(i, 2, item)
|
103
|
111
|
|
104
|
|
- buttons2 = QHBoxLayout()
|
105
|
|
- box.addLayout(buttons2, 0)
|
|
112
|
+ # Bed Temp in fourth column
|
|
113
|
+ item = QTableWidgetItem(p.tempBed)
|
|
114
|
+ self.printers.setItem(i, 3, item)
|
106
|
115
|
|
107
|
|
- self.up = QPushButton("Move &Up")
|
108
|
|
- self.up.clicked.connect(self.moveUp)
|
109
|
|
- buttons2.addWidget(self.up)
|
|
116
|
+ # Jog Speed in fifth column
|
|
117
|
+ item = QTableWidgetItem(p.jogSpeed)
|
|
118
|
+ self.printers.setItem(i, 4, item)
|
110
|
119
|
|
111
|
|
- self.down = QPushButton("Move &Down")
|
112
|
|
- self.down.clicked.connect(self.moveDown)
|
113
|
|
- buttons2.addWidget(self.down)
|
|
120
|
+ # Jog Length in sixth column
|
|
121
|
+ item = QTableWidgetItem(p.jogLength)
|
|
122
|
+ self.printers.setItem(i, 5, item)
|
114
|
123
|
|
115
|
|
- self.openWeb = QPushButton("&Open Web UI of selected")
|
116
|
|
- self.openWeb.clicked.connect(self.openWebUI)
|
117
|
|
- box.addWidget(self.openWeb, 0)
|
|
124
|
+ self.apiColumns[0][1][0][2].append(p.key)
|
|
125
|
+ self.apiColumns[1][1][0][2].append(p.webcam)
|
|
126
|
+
|
|
127
|
+ # Table of settings
|
|
128
|
+ self.settings = QTableWidget(1, 2)
|
|
129
|
+ box.addWidget(self.settings, 1)
|
|
130
|
+
|
|
131
|
+ # Callback to update settings when printers selection changes
|
|
132
|
+ self.printers.itemSelectionChanged.connect(self.selectionChanged)
|
|
133
|
+ self.settings.itemChanged.connect(self.settingsChanged)
|
|
134
|
+
|
|
135
|
+ # Put usage hint in settings table
|
|
136
|
+ self.populateDefaultSettings()
|
118
|
137
|
|
119
|
|
- self.table.setHorizontalHeaderLabels(self.columns)
|
120
|
|
- self.table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
|
121
|
|
- self.table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows);
|
122
|
|
- self.table.resizeColumnsToContents()
|
|
138
|
+ # Setup tables
|
|
139
|
+ self.setupTableHeaders()
|
123
|
140
|
|
124
|
|
- if self.rows <= 0:
|
|
141
|
+ # Initialize empty entry when none are available
|
|
142
|
+ if len(self.data) <= 0:
|
125
|
143
|
self.addPrinter()
|
126
|
144
|
|
127
|
|
- def tableToList(self):
|
128
|
|
- printers = []
|
129
|
|
- for i in range(0, self.rows):
|
130
|
|
- p = Printer()
|
|
145
|
+ def setupTableHeaders(self):
|
|
146
|
+ for t, tc in [
|
|
147
|
+ ( self.printers, [ i[0] for i in self.genericColumns ] ),
|
|
148
|
+ ( self.settings, [ "Option", "Value" ] )
|
|
149
|
+ ]:
|
|
150
|
+ t.setHorizontalHeaderLabels(tc)
|
|
151
|
+ t.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
|
|
152
|
+ t.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows);
|
|
153
|
+ t.resizeColumnsToContents()
|
|
154
|
+
|
|
155
|
+ def settingsChanged(self, item):
|
|
156
|
+ printer = self.printers.currentRow()
|
|
157
|
+ if (printer < 0) or (item.column() < 1):
|
|
158
|
+ return
|
|
159
|
+
|
|
160
|
+ apiType = self.printers.cellWidget(printer, 1).currentText()
|
|
161
|
+ if apiType == self.apiColumns[0][0]:
|
|
162
|
+ self.apiColumns[0][1][item.row()][2][printer] = item.text()
|
|
163
|
+ elif apiType == self.apiColumns[1][0]:
|
|
164
|
+ self.apiColumns[1][1][item.row()][2][printer] = item.text()
|
|
165
|
+
|
|
166
|
+ def populateDefaultSettings(self):
|
|
167
|
+ self.settings.clear()
|
|
168
|
+ self.settings.setRowCount(1)
|
|
169
|
+ self.settings.setColumnCount(2)
|
|
170
|
+
|
|
171
|
+ item = QTableWidgetItem("Select printer for")
|
|
172
|
+ self.settings.setItem(0, 0, item)
|
|
173
|
+ item = QTableWidgetItem("detailed settings")
|
|
174
|
+ self.settings.setItem(0, 1, item)
|
|
175
|
+
|
|
176
|
+ self.setupTableHeaders()
|
|
177
|
+ self.settings.resizeColumnsToContents()
|
|
178
|
+
|
|
179
|
+ def selectionChanged(self):
|
|
180
|
+ i = self.printers.currentRow()
|
|
181
|
+ apiType = self.printers.cellWidget(i, 1).currentText()
|
|
182
|
+ for api, nv in self.apiColumns:
|
|
183
|
+ if api == apiType:
|
|
184
|
+ self.settings.clear()
|
|
185
|
+ self.settings.setRowCount(len(nv))
|
|
186
|
+ self.settings.setColumnCount(2)
|
|
187
|
+
|
|
188
|
+ n = 0
|
|
189
|
+ for name, value, data in nv:
|
|
190
|
+ item = QTableWidgetItem(name)
|
|
191
|
+ self.settings.setItem(n, 0, item)
|
|
192
|
+ item = QTableWidgetItem(data[i])
|
|
193
|
+ self.settings.setItem(n, 1, item)
|
|
194
|
+ n += 1
|
|
195
|
+
|
|
196
|
+ self.setupTableHeaders()
|
|
197
|
+ self.settings.resizeColumnsToContents()
|
|
198
|
+ return
|
131
|
199
|
|
132
|
|
- p.host = self.table.item(i, 0).text()
|
133
|
|
- p.key = self.table.item(i, 1).text()
|
134
|
|
- p.tempTool = self.table.item(i, 2).text()
|
135
|
|
- p.tempBed = self.table.item(i, 3).text()
|
|
200
|
+ self.populateDefaultSettings()
|
136
|
201
|
|
137
|
|
- if p.tempTool == "0":
|
138
|
|
- p.tempTool = None
|
|
202
|
+ def printersToList(self):
|
|
203
|
+ printers = []
|
|
204
|
+ for i in range(0, self.printerCount):
|
|
205
|
+ p = Printer()
|
139
|
206
|
|
140
|
|
- if p.tempBed == "0":
|
141
|
|
- p.tempBed = None
|
|
207
|
+ p.host = self.printers.item(i, 0).text()
|
|
208
|
+ p.apiType = self.printers.cellWidget(i, 1).currentText()
|
|
209
|
+ p.tempTool = self.printers.item(i, 2).text()
|
|
210
|
+ p.tempBed = self.printers.item(i, 3).text()
|
|
211
|
+ p.jogSpeed = self.printers.item(i, 4).text()
|
|
212
|
+ p.jogLength = self.printers.item(i, 5).text()
|
|
213
|
+ p.key = self.apiColumns[0][1][0][2][i]
|
|
214
|
+ p.webcam = self.apiColumns[1][1][0][2][i]
|
142
|
215
|
|
143
|
216
|
printers.append(p)
|
144
|
217
|
return printers
|
|
@@ -148,9 +221,18 @@ class SettingsWindow(QWidget):
|
148
|
221
|
# p.host needs to be valid hostname or IP
|
149
|
222
|
# TODO
|
150
|
223
|
|
151
|
|
- # p.key needs to be valid API key (hexadecimal, 32 chars)
|
152
|
|
- if (len(p.key) != 32) or not all(c in string.hexdigits for c in p.key):
|
153
|
|
- return (False, "API Key not 32-digit hexadecimal")
|
|
224
|
+ # p.apiType
|
|
225
|
+ # TODO
|
|
226
|
+
|
|
227
|
+ if p.apiType == self.apiColumns[0][0]:
|
|
228
|
+ # p.key only for octoprint
|
|
229
|
+ # p.key needs to be valid API key (hexadecimal, 32 chars)
|
|
230
|
+ if (len(p.key) != 32) or not all(c in string.hexdigits for c in p.key):
|
|
231
|
+ return (False, "API Key not 32-digit hexadecimal")
|
|
232
|
+ elif p.apiType == self.apiColumns[1][0]:
|
|
233
|
+ # p.webcam only for moonraker
|
|
234
|
+ if (len(p.webcam) < 1) or (len(p.webcam) > 1) or not all(c in string.digits for c in p.webcam):
|
|
235
|
+ return (False, "Webcam ID not a number from 0...9")
|
154
|
236
|
|
155
|
237
|
# p.tempTool and p.tempBed need to be integer temperatures (0...999)
|
156
|
238
|
for s in [ p.tempTool, p.tempBed ]:
|
|
@@ -159,18 +241,22 @@ class SettingsWindow(QWidget):
|
159
|
241
|
if (len(s) < 1) or (len(s) > 3) or not all(c in string.digits for c in s):
|
160
|
242
|
return (False, "Temperature not a number from 0...999")
|
161
|
243
|
|
162
|
|
- js = int(self.jogSpeed.text())
|
163
|
|
- if (js < 1) or (js > 6000):
|
164
|
|
- return (False, "Jog Speed not a number from 1...6000")
|
|
244
|
+ js = p.jogSpeed
|
|
245
|
+ if js == None:
|
|
246
|
+ js = "0"
|
|
247
|
+ if (len(js) < 1) or (len(js) > 3) or not all(c in string.digits for c in js) or (int(js) < 0) or (int(js) > 6000):
|
|
248
|
+ return (False, "Jog Speed not a number from 0...6000")
|
165
|
249
|
|
166
|
|
- jl = int(self.jogLength.text())
|
167
|
|
- if (jl < 1) or (jl > 100):
|
168
|
|
- return (False, "Jog Length not a number from 1...100")
|
|
250
|
+ jl = p.jogLength
|
|
251
|
+ if jl == None:
|
|
252
|
+ jl = "0"
|
|
253
|
+ if (len(jl) < 1) or (len(jl) > 3) or not all(c in string.digits for c in jl) or (int(jl) < 0) or (int(jl) > 100):
|
|
254
|
+ return (False, "Jog Length not a number from 0...100")
|
169
|
255
|
|
170
|
256
|
return (True, "")
|
171
|
257
|
|
172
|
258
|
def printerDiffers(self, a, b):
|
173
|
|
- if (a.host != b.host) or (a.key != b.key) or (a.tempTool != b.tempTool) or (a.tempBed != b.tempBed):
|
|
259
|
+ if (a.host != b.host) or (a.key != b.key) or (a.tempTool != b.tempTool) or (a.tempBed != b.tempBed) or (a.jogSpeed != b.jogSpeed) or (a.jogLength != b.jogLength) or (a.webcam != b.webcam):
|
174
|
260
|
return True
|
175
|
261
|
return False
|
176
|
262
|
|
|
@@ -186,7 +272,7 @@ class SettingsWindow(QWidget):
|
186
|
272
|
|
187
|
273
|
def closeEvent(self, event):
|
188
|
274
|
oldPrinters = self.parent.printers
|
189
|
|
- newPrinters = self.tableToList()
|
|
275
|
+ newPrinters = self.printersToList()
|
190
|
276
|
|
191
|
277
|
valid, errorText = self.settingsValid(newPrinters)
|
192
|
278
|
if valid == False:
|
|
@@ -198,63 +284,105 @@ class SettingsWindow(QWidget):
|
198
|
284
|
self.parent.removeSettingsWindow()
|
199
|
285
|
return
|
200
|
286
|
|
201
|
|
- js = int(self.jogSpeed.text())
|
202
|
|
- jl = int(self.jogLength.text())
|
203
|
|
-
|
204
|
|
- if self.printersDiffer(oldPrinters, newPrinters) or (js != self.parent.jogMoveSpeed) or (jl != self.parent.jogMoveLength):
|
|
287
|
+ if self.printersDiffer(oldPrinters, newPrinters):
|
205
|
288
|
r = self.parent.showDialog(self.parent.name + " Settings Changed", "Do you want to save the new configuration?", "This will restart the application!", True, False, False)
|
206
|
289
|
if r == True:
|
207
|
|
- self.parent.jogMoveSpeed = js
|
208
|
|
- self.parent.jogMoveLength = jl
|
209
|
290
|
self.parent.writeSettings(newPrinters)
|
|
291
|
+ self.parent.removeSettingsWindow()
|
210
|
292
|
self.parent.restartApp()
|
211
|
293
|
|
212
|
294
|
self.parent.removeSettingsWindow()
|
213
|
295
|
|
214
|
296
|
def addPrinter(self):
|
215
|
|
- self.rows += 1
|
216
|
|
- self.table.setRowCount(self.rows)
|
217
|
|
- for i in range(0, len(self.columns)):
|
218
|
|
- item = QTableWidgetItem(self.presets[i])
|
219
|
|
- self.table.setItem(self.rows - 1, i, item)
|
220
|
|
- if i == 1:
|
221
|
|
- font = item.font()
|
222
|
|
- font.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family())
|
223
|
|
- item.setFont(font)
|
224
|
|
- self.table.resizeColumnsToContents()
|
225
|
|
- self.table.setCurrentItem(self.table.item(self.rows - 1, 0))
|
|
297
|
+ self.printerCount += 1
|
|
298
|
+ self.printers.setRowCount(self.printerCount)
|
|
299
|
+ for i in range(0, len(self.genericColumns)):
|
|
300
|
+ if i != 1:
|
|
301
|
+ item = QTableWidgetItem(self.genericColumns[i][1])
|
|
302
|
+ self.printers.setItem(self.printerCount - 1, i, item)
|
|
303
|
+ if i == 0:
|
|
304
|
+ font = item.font()
|
|
305
|
+ font.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family())
|
|
306
|
+ item.setFont(font)
|
|
307
|
+ else:
|
|
308
|
+ item = QComboBox()
|
|
309
|
+ for api, options in self.apiColumns:
|
|
310
|
+ item.addItem(api)
|
|
311
|
+ if self.genericColumns[i][1] == api:
|
|
312
|
+ item.setCurrentText(api)
|
|
313
|
+ item.currentIndexChanged.connect(self.selectionChanged)
|
|
314
|
+ self.printers.setCellWidget(self.printerCount - 1, i, item)
|
|
315
|
+
|
|
316
|
+ # add default values for api specific settings
|
|
317
|
+ self.apiColumns[0][1][0][2].append(self.apiColumns[0][1][0][1])
|
|
318
|
+ self.apiColumns[1][1][0][2].append(self.apiColumns[1][1][0][1])
|
|
319
|
+
|
|
320
|
+ self.printers.resizeColumnsToContents()
|
|
321
|
+ self.printers.setCurrentItem(self.printers.item(self.printerCount - 1, 0))
|
226
|
322
|
|
227
|
323
|
def removePrinter(self):
|
228
|
|
- r = self.table.currentRow()
|
229
|
|
- if (r >= 0) and (r < self.rows):
|
230
|
|
- self.rows -= 1
|
231
|
|
- self.table.removeRow(r)
|
232
|
|
- self.table.setCurrentItem(self.table.item(min(r, self.rows - 1), 0))
|
|
324
|
+ r = self.printers.currentRow()
|
|
325
|
+ if (r >= 0) and (r < self.printerCount):
|
|
326
|
+ self.printerCount -= 1
|
|
327
|
+ self.printers.removeRow(r)
|
|
328
|
+ self.printers.setCurrentItem(self.printers.item(min(r, self.printerCount - 1), 0))
|
|
329
|
+
|
|
330
|
+ # also remove values for api specific settings
|
|
331
|
+ del self.apiColumns[0][1][0][2][r]
|
|
332
|
+ del self.apiColumns[1][1][0][2][r]
|
233
|
333
|
|
234
|
334
|
def moveUp(self):
|
235
|
|
- i = self.table.currentRow()
|
|
335
|
+ i = self.printers.currentRow()
|
236
|
336
|
if i <= 0:
|
237
|
337
|
return
|
238
|
|
- host = self.table.item(i, 0).text()
|
239
|
|
- key = self.table.item(i, 1).text()
|
240
|
|
- self.table.item(i, 0).setText(self.table.item(i - 1, 0).text())
|
241
|
|
- self.table.item(i, 1).setText(self.table.item(i - 1, 1).text())
|
242
|
|
- self.table.item(i - 1, 0).setText(host)
|
243
|
|
- self.table.item(i - 1, 1).setText(key)
|
244
|
|
- self.table.setCurrentItem(self.table.item(i - 1, 0))
|
|
338
|
+
|
|
339
|
+ for c in range(0, self.printers.columnCount()):
|
|
340
|
+ if c != 1:
|
|
341
|
+ a = self.printers.takeItem(i, c)
|
|
342
|
+ b = self.printers.takeItem(i - 1, c)
|
|
343
|
+ self.printers.setItem(i, c, b)
|
|
344
|
+ self.printers.setItem(i - 1, c, a)
|
|
345
|
+ else:
|
|
346
|
+ a = self.printers.cellWidget(i, c).currentText()
|
|
347
|
+ b = self.printers.cellWidget(i - 1, c).currentText()
|
|
348
|
+ self.printers.cellWidget(i, c).setCurrentText(b)
|
|
349
|
+ self.printers.cellWidget(i - 1, c).setCurrentText(a)
|
|
350
|
+
|
|
351
|
+ # also move values for api specific settings
|
|
352
|
+ for v in [ self.apiColumns[0][1][0][2], self.apiColumns[1][1][0][2] ]:
|
|
353
|
+ a = v[i]
|
|
354
|
+ b = v[i - 1]
|
|
355
|
+ v[i] = b
|
|
356
|
+ v[i - 1] = a
|
|
357
|
+
|
|
358
|
+ self.printers.setCurrentItem(self.printers.item(i - 1, 0))
|
245
|
359
|
|
246
|
360
|
def moveDown(self):
|
247
|
|
- i = self.table.currentRow()
|
248
|
|
- if i >= (self.rows - 1):
|
|
361
|
+ i = self.printers.currentRow()
|
|
362
|
+ if i >= (self.printerCount - 1):
|
249
|
363
|
return
|
250
|
|
- host = self.table.item(i, 0).text()
|
251
|
|
- key = self.table.item(i, 1).text()
|
252
|
|
- self.table.item(i, 0).setText(self.table.item(i + 1, 0).text())
|
253
|
|
- self.table.item(i, 1).setText(self.table.item(i + 1, 1).text())
|
254
|
|
- self.table.item(i + 1, 0).setText(host)
|
255
|
|
- self.table.item(i + 1, 1).setText(key)
|
256
|
|
- self.table.setCurrentItem(self.table.item(i + 1, 0))
|
|
364
|
+
|
|
365
|
+ for c in range(0, self.printers.columnCount()):
|
|
366
|
+ if c != 1:
|
|
367
|
+ a = self.printers.takeItem(i, c)
|
|
368
|
+ b = self.printers.takeItem(i + 1, c)
|
|
369
|
+ self.printers.setItem(i, c, b)
|
|
370
|
+ self.printers.setItem(i + 1, c, a)
|
|
371
|
+ else:
|
|
372
|
+ a = self.printers.cellWidget(i, c).currentText()
|
|
373
|
+ b = self.printers.cellWidget(i + 1, c).currentText()
|
|
374
|
+ self.printers.cellWidget(i, c).setCurrentText(b)
|
|
375
|
+ self.printers.cellWidget(i + 1, c).setCurrentText(a)
|
|
376
|
+
|
|
377
|
+ # also move values for api specific settings
|
|
378
|
+ for v in [ self.apiColumns[0][1][0][2], self.apiColumns[1][1][0][2] ]:
|
|
379
|
+ a = v[i]
|
|
380
|
+ b = v[i + 1]
|
|
381
|
+ v[i] = b
|
|
382
|
+ v[i + 1] = a
|
|
383
|
+
|
|
384
|
+ self.printers.setCurrentItem(self.printers.item(i + 1, 0))
|
257
|
385
|
|
258
|
386
|
def openWebUI(self):
|
259
|
|
- host = self.table.item(self.table.currentRow(), 0).text()
|
|
387
|
+ host = self.printers.item(self.printers.currentRow(), 0).text()
|
260
|
388
|
self.parent.openBrowser(host)
|