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,7 +19,7 @@ import urllib.request
19 19
 from os import path
20 20
 from PyQt5 import QtWidgets, QtGui, QtCore, QtNetwork
21 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 23
 from PyQt5.QtCore import QCoreApplication, QSettings, QUrl, QTimer, QSize, Qt, QSettings
24 24
 
25 25
 class SettingsWindow(QWidget):
@@ -69,6 +69,10 @@ class SettingsWindow(QWidget):
69 69
                     text = "0"
70 70
                 item = QTableWidgetItem(text)
71 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 77
         buttons2 = QHBoxLayout()
74 78
         box.addLayout(buttons2, 0)
@@ -81,8 +85,13 @@ class SettingsWindow(QWidget):
81 85
         self.down.clicked.connect(self.moveDown)
82 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 92
         self.table.setHorizontalHeaderLabels(self.columns)
85 93
         self.table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
94
+        self.table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows);
86 95
         self.table.resizeColumnsToContents()
87 96
 
88 97
         if self.rows <= 0:
@@ -136,6 +145,7 @@ class SettingsWindow(QWidget):
136 145
             if r == True:
137 146
                 self.parent.writeSettings(newPrinters)
138 147
                 self.parent.restartApp()
148
+
139 149
         self.parent.removeSettingsWindow()
140 150
 
141 151
     def addPrinter(self):
@@ -144,13 +154,19 @@ class SettingsWindow(QWidget):
144 154
         for i in range(0, len(self.columns)):
145 155
             item = QTableWidgetItem(self.presets[i])
146 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 161
         self.table.resizeColumnsToContents()
162
+        self.table.setCurrentItem(self.table.item(self.rows - 1, 0))
148 163
 
149 164
     def removePrinter(self):
150 165
         r = self.table.currentRow()
151 166
         if (r >= 0) and (r < self.rows):
152 167
             self.rows -= 1
153 168
             self.table.removeRow(r)
169
+            self.table.setCurrentItem(self.table.item(min(r, self.rows - 1), 0))
154 170
 
155 171
     def moveUp(self):
156 172
         i = self.table.currentRow()
@@ -162,6 +178,7 @@ class SettingsWindow(QWidget):
162 178
         self.table.item(i, 1).setText(self.table.item(i - 1, 1).text())
163 179
         self.table.item(i - 1, 0).setText(host)
164 180
         self.table.item(i - 1, 1).setText(key)
181
+        self.table.setCurrentItem(self.table.item(i - 1, 0))
165 182
 
166 183
     def moveDown(self):
167 184
         i = self.table.currentRow()
@@ -173,6 +190,11 @@ class SettingsWindow(QWidget):
173 190
         self.table.item(i, 1).setText(self.table.item(i + 1, 1).text())
174 191
         self.table.item(i + 1, 0).setText(host)
175 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 199
 class AspectRatioPixmapLabel(QLabel):
178 200
     def __init__(self, *args, **kwargs):

Loading…
Cancel
Save