13
13
from PyQt5 .QtCore import pyqtSignal , Qt , QThread
14
14
from PyQt5 .QtGui import QPixmap , QColor , QPalette , QTextCursor , QFont , QIcon
15
15
from PyQt5 .QtWidgets import QWidget , QPushButton , QHBoxLayout , QGroupBox , QVBoxLayout , \
16
- QFileDialog , QTextEdit , QTabWidget , QLabel , QSplitter
16
+ QFileDialog , QTextEdit , QTabWidget , QLabel , QSplitter , QAction , QMenuBar
17
17
18
18
from apiClient import ApiClient
19
19
from constants import starting_height , DefaultCache , wqueue
@@ -41,9 +41,8 @@ class MainWindow(QWidget):
41
41
# signal: UTXO list loading percent (emitted by load_utxos_thread in tabRewards)
42
42
sig_UTXOsLoading = pyqtSignal (int )
43
43
44
-
45
44
def __init__ (self , parent , imgDir ):
46
- super (QWidget , self ).__init__ (parent )
45
+ super ().__init__ (parent )
47
46
self .parent = parent
48
47
self .imgDir = imgDir
49
48
self .runInThread = ThreadFuns .runInThread
@@ -79,7 +78,7 @@ def __init__(self, parent, imgDir):
79
78
self .hwdevice = HWdevice (self )
80
79
81
80
# -- init Api Client
82
- self .apiClient = ApiClient (self . isTestnetRPC )
81
+ self .apiClient = ApiClient (self ) # Pass 'self' as main_wnd reference
83
82
84
83
# -- Create Queue to redirect stdout
85
84
self .queue = wqueue
@@ -257,15 +256,15 @@ def checkVersion(self, ctrl):
257
256
(remote_version [0 ] == local_version [0 ] and remote_version [1 ] > local_version [1 ]) or \
258
257
(remote_version [0 ] == local_version [0 ] and remote_version [1 ] == local_version [1 ] and remote_version [2 ] >
259
258
local_version [2 ]):
260
- self .versionMess = '<b style="color:red">New Version Available:</b> %s ' % ( self .gitVersion )
259
+ self .versionMess = f '<b style="color:red">New Version Available:</b> { self .gitVersion } '
261
260
self .versionMess += '(<a href="https://github.com/PIVX-Project/PET4L/releases/">download</a>)'
262
261
else :
263
262
self .versionMess = "You have the latest version of PET4L"
264
263
265
264
def updateVersion (self ):
266
265
if self .versionMess is not None :
267
266
self .versionLabel .setText (self .versionMess )
268
- printOK ("Remote version: %s" % str ( self .gitVersion ) )
267
+ printOK (f "Remote version: { self .gitVersion } " )
269
268
270
269
def onChangeSelectedHW (self , i ):
271
270
# Clear status
@@ -288,14 +287,13 @@ def onSaveConsole(self):
288
287
timestamp = strftime ('%Y-%m-%d_%H-%M-%S' , gmtime (now ()))
289
288
options = QFileDialog .Options ()
290
289
options |= QFileDialog .DontUseNativeDialog
291
- fileName , _ = QFileDialog .getSaveFileName (self , "Save Logs to file" , " PET4L_Logs_%s .txt" % timestamp , "All Files (*);; Text Files (*.txt)" , options = options )
290
+ fileName , _ = QFileDialog .getSaveFileName (self , f "Save Logs to file PET4L_Logs_{ timestamp } .txt" , "All Files (*);; Text Files (*.txt)" , options = options )
292
291
try :
293
292
if fileName :
294
- printOK ("Saving logs to %s" % fileName )
295
- log_file = open (fileName , 'w+' , encoding = "utf-8" )
296
- log_text = self .consoleArea .toPlainText ()
297
- log_file .write (log_text )
298
- log_file .close ()
293
+ printOK (f"Saving logs to { fileName } " )
294
+ with open (fileName , 'w+' , encoding = "utf-8" ) as log_file :
295
+ log_text = self .consoleArea .toPlainText ()
296
+ log_file .write (log_text )
299
297
300
298
except Exception as e :
301
299
err_msg = "error writing Log file"
@@ -315,14 +313,14 @@ def onToggleConsole(self):
315
313
316
314
def showHWstatus (self ):
317
315
self .updateHWleds ()
318
- myPopUp_sb (self , "info" , 'PET4L - hw check' , "%s" % self .hwStatusMess )
316
+ myPopUp_sb (self , "info" , 'PET4L - hw check' , f" { self .hwStatusMess } " )
319
317
320
318
def showRPCstatus (self , server_index , fDebug ):
321
319
# Update displayed status only if selected server is not changed
322
320
if server_index == self .header .rpcClientsBox .currentIndex ():
323
321
self .updateRPCled (fDebug )
324
322
if fDebug :
325
- myPopUp_sb (self , "info" , 'PET4L - rpc check' , "%s" % self .rpcStatusMess )
323
+ myPopUp_sb (self , "info" , 'PET4L - rpc check' , f" { self .rpcStatusMess } " )
326
324
327
325
def updateHWleds (self ):
328
326
if self .hwStatus == 1 :
@@ -342,7 +340,7 @@ def updateHWstatus(self, ctrl):
342
340
printDbg (str (e ))
343
341
pass
344
342
345
- printDbg ("status:%s - mess: %s" % ( self .hwStatus , self . hwStatusMess ) )
343
+ printDbg (f "status:{ self . hwStatus } - mess: { self .hwStatusMess } " )
346
344
347
345
def updateLastBlockLabel (self ):
348
346
text = '--'
@@ -370,9 +368,9 @@ def updateLastBlockPing(self):
370
368
color = "green"
371
369
self .header .lastPingIcon .setPixmap (self .connGreen_icon )
372
370
if self .rpcResponseTime is not None :
373
- self .header .responseTimeLabel .setText ("%.3f" % self .rpcResponseTime )
374
- self .header .responseTimeLabel .setStyleSheet ("color: %s" % color )
375
- self .header .lastPingIcon .setStyleSheet ("color: %s" % color )
371
+ self .header .responseTimeLabel .setText (f" { self .rpcResponseTime :.3f } " )
372
+ self .header .responseTimeLabel .setStyleSheet (f "color: { color } " )
373
+ self .header .lastPingIcon .setStyleSheet (f "color: { color } " )
376
374
377
375
def updateRPCled (self , fDebug = False ):
378
376
if self .rpcConnected :
@@ -403,7 +401,7 @@ def updateRPClist(self):
403
401
# Add public servers (italics)
404
402
italicsFont = QFont ("Times" , italic = True )
405
403
for s in public_servers :
406
- url = s [ " protocol" ] + " ://" + s [ " host" ].split (':' )[0 ]
404
+ url = f" { s [ ' protocol' ] } ://{ s [ ' host' ].split (':' )[0 ]} "
407
405
self .header .rpcClientsBox .addItem (url , s )
408
406
self .header .rpcClientsBox .setItemData (self .getServerListIndex (s ), italicsFont , Qt .FontRole )
409
407
# Add Local Wallet (bold)
@@ -413,7 +411,7 @@ def updateRPClist(self):
413
411
self .header .rpcClientsBox .setItemData (self .getServerListIndex (custom_servers [0 ]), boldFont , Qt .FontRole )
414
412
# Add custom servers
415
413
for s in custom_servers [1 :]:
416
- url = s [ " protocol" ] + " ://" + s [ " host" ].split (':' )[0 ]
414
+ url = f" { s [ ' protocol' ] } ://{ s [ ' host' ].split (':' )[0 ]} "
417
415
self .header .rpcClientsBox .addItem (url , s )
418
416
# reset index
419
417
if self .parent .cache ['selectedRPC_index' ] >= self .header .rpcClientsBox .count ():
@@ -428,7 +426,7 @@ def updateRPClist(self):
428
426
def updateRPCstatus (self , ctrl , fDebug = False ):
429
427
rpc_index , rpc_protocol , rpc_host , rpc_user , rpc_password = self .getRPCserver ()
430
428
if fDebug :
431
- printDbg ("Trying to connect to RPC %s ://%s ..." % ( rpc_protocol , rpc_host ) )
429
+ printDbg (f "Trying to connect to RPC { rpc_protocol } ://{ rpc_host } ..." )
432
430
433
431
try :
434
432
rpcClient = RpcClient (rpc_protocol , rpc_host , rpc_user , rpc_password )
0 commit comments