Browse Source

tweak settings window, always select whole rows, keep item selected after moving, show api key in fixed width font, add button to open web ui.

Thomas Buck 3 years ago
parent
commit
7dc20e162d
1 changed files with 23 additions and 1 deletions
  1. 23
    1
      src/octotray.py

+ 23
- 1
src/octotray.py View File

19
 from os import path
19
 from os import path
20
 from PyQt5 import QtWidgets, QtGui, QtCore, QtNetwork
20
 from PyQt5 import QtWidgets, QtGui, QtCore, QtNetwork
21
 from PyQt5.QtWidgets import QSystemTrayIcon, QAction, QMenu, QMessageBox, QWidget, QLabel, QVBoxLayout, QHBoxLayout, QDesktopWidget, QSizePolicy, QSlider, QLayout, QTableWidget, QTableWidgetItem, QPushButton
21
 from PyQt5.QtWidgets import QSystemTrayIcon, QAction, QMenu, QMessageBox, QWidget, QLabel, QVBoxLayout, QHBoxLayout, QDesktopWidget, QSizePolicy, QSlider, QLayout, QTableWidget, QTableWidgetItem, QPushButton
22
-from PyQt5.QtGui import QIcon, QPixmap, QImageReader, QDesktopServices
22
+from PyQt5.QtGui import QIcon, QPixmap, QImageReader, QDesktopServices, QFontDatabase
23
 from PyQt5.QtCore import QCoreApplication, QSettings, QUrl, QTimer, QSize, Qt, QSettings
23
 from PyQt5.QtCore import QCoreApplication, QSettings, QUrl, QTimer, QSize, Qt, QSettings
24
 
24
 
25
 class SettingsWindow(QWidget):
25
 class SettingsWindow(QWidget):
69
                     text = "0"
69
                     text = "0"
70
                 item = QTableWidgetItem(text)
70
                 item = QTableWidgetItem(text)
71
                 self.table.setItem(i, j, item)
71
                 self.table.setItem(i, j, item)
72
+                if j == 1:
73
+                    font = item.font()
74
+                    font.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family())
75
+                    item.setFont(font)
72
 
76
 
73
         buttons2 = QHBoxLayout()
77
         buttons2 = QHBoxLayout()
74
         box.addLayout(buttons2, 0)
78
         box.addLayout(buttons2, 0)
81
         self.down.clicked.connect(self.moveDown)
85
         self.down.clicked.connect(self.moveDown)
82
         buttons2.addWidget(self.down)
86
         buttons2.addWidget(self.down)
83
 
87
 
88
+        self.openWeb = QPushButton("&Open Web UI of selected")
89
+        self.openWeb.clicked.connect(self.openWebUI)
90
+        box.addWidget(self.openWeb, 0)
91
+
84
         self.table.setHorizontalHeaderLabels(self.columns)
92
         self.table.setHorizontalHeaderLabels(self.columns)
85
         self.table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
93
         self.table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
94
+        self.table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows);
86
         self.table.resizeColumnsToContents()
95
         self.table.resizeColumnsToContents()
87
 
96
 
88
         if self.rows <= 0:
97
         if self.rows <= 0:
136
             if r == True:
145
             if r == True:
137
                 self.parent.writeSettings(newPrinters)
146
                 self.parent.writeSettings(newPrinters)
138
                 self.parent.restartApp()
147
                 self.parent.restartApp()
148
+
139
         self.parent.removeSettingsWindow()
149
         self.parent.removeSettingsWindow()
140
 
150
 
141
     def addPrinter(self):
151
     def addPrinter(self):
144
         for i in range(0, len(self.columns)):
154
         for i in range(0, len(self.columns)):
145
             item = QTableWidgetItem(self.presets[i])
155
             item = QTableWidgetItem(self.presets[i])
146
             self.table.setItem(self.rows - 1, i, item)
156
             self.table.setItem(self.rows - 1, i, item)
157
+            if i == 1:
158
+                font = item.font()
159
+                font.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family())
160
+                item.setFont(font)
147
         self.table.resizeColumnsToContents()
161
         self.table.resizeColumnsToContents()
162
+        self.table.setCurrentItem(self.table.item(self.rows - 1, 0))
148
 
163
 
149
     def removePrinter(self):
164
     def removePrinter(self):
150
         r = self.table.currentRow()
165
         r = self.table.currentRow()
151
         if (r >= 0) and (r < self.rows):
166
         if (r >= 0) and (r < self.rows):
152
             self.rows -= 1
167
             self.rows -= 1
153
             self.table.removeRow(r)
168
             self.table.removeRow(r)
169
+            self.table.setCurrentItem(self.table.item(min(r, self.rows - 1), 0))
154
 
170
 
155
     def moveUp(self):
171
     def moveUp(self):
156
         i = self.table.currentRow()
172
         i = self.table.currentRow()
162
         self.table.item(i, 1).setText(self.table.item(i - 1, 1).text())
178
         self.table.item(i, 1).setText(self.table.item(i - 1, 1).text())
163
         self.table.item(i - 1, 0).setText(host)
179
         self.table.item(i - 1, 0).setText(host)
164
         self.table.item(i - 1, 1).setText(key)
180
         self.table.item(i - 1, 1).setText(key)
181
+        self.table.setCurrentItem(self.table.item(i - 1, 0))
165
 
182
 
166
     def moveDown(self):
183
     def moveDown(self):
167
         i = self.table.currentRow()
184
         i = self.table.currentRow()
173
         self.table.item(i, 1).setText(self.table.item(i + 1, 1).text())
190
         self.table.item(i, 1).setText(self.table.item(i + 1, 1).text())
174
         self.table.item(i + 1, 0).setText(host)
191
         self.table.item(i + 1, 0).setText(host)
175
         self.table.item(i + 1, 1).setText(key)
192
         self.table.item(i + 1, 1).setText(key)
193
+        self.table.setCurrentItem(self.table.item(i + 1, 0))
194
+
195
+    def openWebUI(self):
196
+        host = self.table.item(self.table.currentRow(), 0).text()
197
+        self.parent.openBrowser(host)
176
 
198
 
177
 class AspectRatioPixmapLabel(QLabel):
199
 class AspectRatioPixmapLabel(QLabel):
178
     def __init__(self, *args, **kwargs):
200
     def __init__(self, *args, **kwargs):

Loading…
Cancel
Save