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,9 +54,24 @@ class SettingsWindow(QWidget):
54 54
                 item = QTableWidgetItem(p[j])
55 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 69
         self.table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
58 70
         self.table.resizeColumnsToContents()
59 71
 
72
+        if self.rows <= 0:
73
+            self.addPrinter()
74
+
60 75
     def tableToList(self):
61 76
         printers = []
62 77
         for i in range(0, self.rows):
@@ -71,7 +86,7 @@ class SettingsWindow(QWidget):
71 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 87
             if r == True:
73 88
                 self.parent.writeSettings(newPrinters)
74
-                QCoreApplication.exit(42)
89
+                self.parent.restartApp()
75 90
         self.parent.removeSettingsWindow()
76 91
 
77 92
     def addPrinter(self):
@@ -79,6 +94,7 @@ class SettingsWindow(QWidget):
79 94
         self.table.setRowCount(self.rows)
80 95
         self.table.setItem(self.rows - 1, 0, QTableWidgetItem("HOSTNAME"))
81 96
         self.table.setItem(self.rows - 1, 1, QTableWidgetItem("API_KEY"))
97
+        self.table.resizeColumnsToContents()
82 98
 
83 99
     def removePrinter(self):
84 100
         r = self.table.currentRow()
@@ -86,6 +102,28 @@ class SettingsWindow(QWidget):
86 102
             self.rows -= 1
87 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 127
 class AspectRatioPixmapLabel(QLabel):
90 128
     def __init__(self, *args, **kwargs):
91 129
         super(AspectRatioPixmapLabel, self).__init__(*args, **kwargs)
@@ -277,6 +315,12 @@ class OctoTray():
277 315
             print("Printer " + p[0] + " has method " + method)
278 316
             if method == "unknown":
279 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 324
                 continue
281 325
 
282 326
             commands = self.getSystemCommands(p[0], p[1])
@@ -303,6 +347,8 @@ class OctoTray():
303 347
                 p.append(action)
304 348
                 menu.addAction(action)
305 349
 
350
+            menu.addSeparator()
351
+
306 352
             action = QAction("Get Status")
307 353
             action.triggered.connect(lambda chk, x=p: self.printerStatusAction(x))
308 354
             p.append(action)
@@ -318,10 +364,16 @@ class OctoTray():
318 364
             p.append(action)
319 365
             menu.addAction(action)
320 366
 
367
+        self.menu.addSeparator()
368
+
321 369
         self.settingsAction = QAction("&Settings")
322 370
         self.settingsAction.triggered.connect(self.showSettingsAction)
323 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 377
         self.quitAction = QAction("&Quit")
326 378
         self.quitAction.triggered.connect(self.exit)
327 379
         self.menu.addAction(self.quitAction)
@@ -585,16 +637,16 @@ class OctoTray():
585 637
 
586 638
     def printerStatusAction(self, item):
587 639
         progress = self.getProgress(item[0], item[1])
588
-        s = ""
640
+        s = item[0] + "\n"
589 641
         warning = False
590 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 644
             s += "Printing since " + time.strftime("%H:%M:%S", time.gmtime(progress["printTime"])) + "\n"
593 645
             s += time.strftime("%H:%M:%S", time.gmtime(progress["printTimeLeft"])) + " left"
594 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 648
         else:
597
-            s = "Could not read printer status!"
649
+            s += "Could not read printer status!"
598 650
             warning = True
599 651
         t = self.getTemperatureString(item[0], item[1])
600 652
         if len(t) > 0:
@@ -644,6 +696,9 @@ class OctoTray():
644 696
     def removeSettingsWindow(self):
645 697
         self.settingsWindow = None
646 698
 
699
+    def restartApp(self):
700
+        QCoreApplication.exit(42)
701
+
647 702
     def closeAll(self):
648 703
         for cw in self.camWindows:
649 704
             cw.close()

Loading…
Cancel
Save