Browse Source

Add move up/down buttons in settings. Add empty item in settings on initial launch. Auto fit settings cells to content. Show unavailable printers greyed out in menu. Add Separators. Add Refresh Action. Show host in status dialog.

Thomas Buck 3 years ago
parent
commit
b546666823
1 changed files with 60 additions and 5 deletions
  1. 60
    5
      src/octotray.py

+ 60
- 5
src/octotray.py View File

54
                 item = QTableWidgetItem(p[j])
54
                 item = QTableWidgetItem(p[j])
55
                 self.table.setItem(i, j, item)
55
                 self.table.setItem(i, j, item)
56
 
56
 
57
+        buttons2 = QHBoxLayout()
58
+        box.addLayout(buttons2, 0)
59
+
60
+        self.up = QPushButton("Move &Up")
61
+        self.up.clicked.connect(self.moveUp)
62
+        buttons2.addWidget(self.up)
63
+
64
+        self.down = QPushButton("Move &Down")
65
+        self.down.clicked.connect(self.moveDown)
66
+        buttons2.addWidget(self.down)
67
+
68
+        self.table.setHorizontalHeaderLabels(["Hostname", "API Key"])
57
         self.table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
69
         self.table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
58
         self.table.resizeColumnsToContents()
70
         self.table.resizeColumnsToContents()
59
 
71
 
72
+        if self.rows <= 0:
73
+            self.addPrinter()
74
+
60
     def tableToList(self):
75
     def tableToList(self):
61
         printers = []
76
         printers = []
62
         for i in range(0, self.rows):
77
         for i in range(0, self.rows):
71
             r = self.parent.showDialog(self.parent.name + " Settings Changed", "Do you want to save the new list of printers?", "This will restart the application!", True, False, False)
86
             r = self.parent.showDialog(self.parent.name + " Settings Changed", "Do you want to save the new list of printers?", "This will restart the application!", True, False, False)
72
             if r == True:
87
             if r == True:
73
                 self.parent.writeSettings(newPrinters)
88
                 self.parent.writeSettings(newPrinters)
74
-                QCoreApplication.exit(42)
89
+                self.parent.restartApp()
75
         self.parent.removeSettingsWindow()
90
         self.parent.removeSettingsWindow()
76
 
91
 
77
     def addPrinter(self):
92
     def addPrinter(self):
79
         self.table.setRowCount(self.rows)
94
         self.table.setRowCount(self.rows)
80
         self.table.setItem(self.rows - 1, 0, QTableWidgetItem("HOSTNAME"))
95
         self.table.setItem(self.rows - 1, 0, QTableWidgetItem("HOSTNAME"))
81
         self.table.setItem(self.rows - 1, 1, QTableWidgetItem("API_KEY"))
96
         self.table.setItem(self.rows - 1, 1, QTableWidgetItem("API_KEY"))
97
+        self.table.resizeColumnsToContents()
82
 
98
 
83
     def removePrinter(self):
99
     def removePrinter(self):
84
         r = self.table.currentRow()
100
         r = self.table.currentRow()
86
             self.rows -= 1
102
             self.rows -= 1
87
             self.table.removeRow(r)
103
             self.table.removeRow(r)
88
 
104
 
105
+    def moveUp(self):
106
+        i = self.table.currentRow()
107
+        if i <= 0:
108
+            return
109
+        host = self.table.item(i, 0).text()
110
+        key = self.table.item(i, 1).text()
111
+        self.table.item(i, 0).setText(self.table.item(i - 1, 0).text())
112
+        self.table.item(i, 1).setText(self.table.item(i - 1, 1).text())
113
+        self.table.item(i - 1, 0).setText(host)
114
+        self.table.item(i - 1, 1).setText(key)
115
+
116
+    def moveDown(self):
117
+        i = self.table.currentRow()
118
+        if i >= (self.rows - 1):
119
+            return
120
+        host = self.table.item(i, 0).text()
121
+        key = self.table.item(i, 1).text()
122
+        self.table.item(i, 0).setText(self.table.item(i + 1, 0).text())
123
+        self.table.item(i, 1).setText(self.table.item(i + 1, 1).text())
124
+        self.table.item(i + 1, 0).setText(host)
125
+        self.table.item(i + 1, 1).setText(key)
126
+
89
 class AspectRatioPixmapLabel(QLabel):
127
 class AspectRatioPixmapLabel(QLabel):
90
     def __init__(self, *args, **kwargs):
128
     def __init__(self, *args, **kwargs):
91
         super(AspectRatioPixmapLabel, self).__init__(*args, **kwargs)
129
         super(AspectRatioPixmapLabel, self).__init__(*args, **kwargs)
277
             print("Printer " + p[0] + " has method " + method)
315
             print("Printer " + p[0] + " has method " + method)
278
             if method == "unknown":
316
             if method == "unknown":
279
                 unknownCount += 1
317
                 unknownCount += 1
318
+
319
+                action = QAction(self.getName(p[0], p[1]))
320
+                action.setEnabled(False)
321
+                p.append(action)
322
+                self.menu.addAction(action)
323
+
280
                 continue
324
                 continue
281
 
325
 
282
             commands = self.getSystemCommands(p[0], p[1])
326
             commands = self.getSystemCommands(p[0], p[1])
303
                 p.append(action)
347
                 p.append(action)
304
                 menu.addAction(action)
348
                 menu.addAction(action)
305
 
349
 
350
+            menu.addSeparator()
351
+
306
             action = QAction("Get Status")
352
             action = QAction("Get Status")
307
             action.triggered.connect(lambda chk, x=p: self.printerStatusAction(x))
353
             action.triggered.connect(lambda chk, x=p: self.printerStatusAction(x))
308
             p.append(action)
354
             p.append(action)
318
             p.append(action)
364
             p.append(action)
319
             menu.addAction(action)
365
             menu.addAction(action)
320
 
366
 
367
+        self.menu.addSeparator()
368
+
321
         self.settingsAction = QAction("&Settings")
369
         self.settingsAction = QAction("&Settings")
322
         self.settingsAction.triggered.connect(self.showSettingsAction)
370
         self.settingsAction.triggered.connect(self.showSettingsAction)
323
         self.menu.addAction(self.settingsAction)
371
         self.menu.addAction(self.settingsAction)
324
 
372
 
373
+        self.refreshAction = QAction("&Refresh")
374
+        self.refreshAction.triggered.connect(self.restartApp)
375
+        self.menu.addAction(self.refreshAction)
376
+
325
         self.quitAction = QAction("&Quit")
377
         self.quitAction = QAction("&Quit")
326
         self.quitAction.triggered.connect(self.exit)
378
         self.quitAction.triggered.connect(self.exit)
327
         self.menu.addAction(self.quitAction)
379
         self.menu.addAction(self.quitAction)
585
 
637
 
586
     def printerStatusAction(self, item):
638
     def printerStatusAction(self, item):
587
         progress = self.getProgress(item[0], item[1])
639
         progress = self.getProgress(item[0], item[1])
588
-        s = ""
640
+        s = item[0] + "\n"
589
         warning = False
641
         warning = False
590
         if ("completion" in progress) and ("printTime" in progress) and ("printTimeLeft" in progress) and (progress["completion"] != None) and (progress["printTime"] != None) and (progress["printTimeLeft"] != None):
642
         if ("completion" in progress) and ("printTime" in progress) and ("printTimeLeft" in progress) and (progress["completion"] != None) and (progress["printTime"] != None) and (progress["printTimeLeft"] != None):
591
-            s = "%.1f%% Completion\n" % progress["completion"]
643
+            s += "%.1f%% Completion\n" % progress["completion"]
592
             s += "Printing since " + time.strftime("%H:%M:%S", time.gmtime(progress["printTime"])) + "\n"
644
             s += "Printing since " + time.strftime("%H:%M:%S", time.gmtime(progress["printTime"])) + "\n"
593
             s += time.strftime("%H:%M:%S", time.gmtime(progress["printTimeLeft"])) + " left"
645
             s += time.strftime("%H:%M:%S", time.gmtime(progress["printTimeLeft"])) + " left"
594
         elif ("completion" in progress) and ("printTime" in progress) and ("printTimeLeft" in progress):
646
         elif ("completion" in progress) and ("printTime" in progress) and ("printTimeLeft" in progress):
595
-            s = "No job is currently running"
647
+            s += "No job is currently running"
596
         else:
648
         else:
597
-            s = "Could not read printer status!"
649
+            s += "Could not read printer status!"
598
             warning = True
650
             warning = True
599
         t = self.getTemperatureString(item[0], item[1])
651
         t = self.getTemperatureString(item[0], item[1])
600
         if len(t) > 0:
652
         if len(t) > 0:
644
     def removeSettingsWindow(self):
696
     def removeSettingsWindow(self):
645
         self.settingsWindow = None
697
         self.settingsWindow = None
646
 
698
 
699
+    def restartApp(self):
700
+        QCoreApplication.exit(42)
701
+
647
     def closeAll(self):
702
     def closeAll(self):
648
         for cw in self.camWindows:
703
         for cw in self.camWindows:
649
             cw.close()
704
             cw.close()

Loading…
Cancel
Save