@@ -123,7 +123,7 @@ def __init__(self):
123
123
)
124
124
self .children = []
125
125
126
- # MainWindow Signals
126
+ # menu_bar signals
127
127
self .actionAbout .triggered .connect (self .about )
128
128
self .actionReportIssue .triggered .connect (self .open_issues )
129
129
self .actionSourceCode .triggered .connect (self .open_source )
@@ -135,10 +135,11 @@ def __init__(self):
135
135
self .actionSetDefaultAPIPassword .triggered .connect (self .show_api_config )
136
136
self .actionCopySelectedElements .triggered .connect (self .copy_selected )
137
137
self .actionExport .triggered .connect (self .export_table )
138
-
138
+ # api config signals
139
+ self .actionIPRSetPasswd .clicked .connect (self .set_api_passwd )
140
+ # listener signals
139
141
self .actionIPRStart .clicked .connect (self .start_listen )
140
142
self .actionIPRStop .clicked .connect (self .stop_listen )
141
- self .actionIPRSetPasswd .clicked .connect (self .set_api_passwd )
142
143
143
144
logger .info (" read settings from config." )
144
145
self .config_path = Path (Path .home (), ".config" , "ipr" ).resolve ()
@@ -182,6 +183,13 @@ def __init__(self):
182
183
if self .actionAutoStartOnLaunch .isChecked ():
183
184
self .start_listen ()
184
185
186
+ def update_stacked_widget (self ):
187
+ if self .actionEnableIDTable .isChecked ():
188
+ logger .info (" show table view." )
189
+ self .stackedWidget .setCurrentIndex (0 )
190
+ else :
191
+ self .stackedWidget .setCurrentIndex (1 )
192
+
185
193
def about (self ):
186
194
QMessageBox .information (
187
195
self ,
@@ -195,6 +203,9 @@ def open_issues(self):
195
203
def open_source (self ):
196
204
webbrowser .open (f"{ app_info ['source' ]} " , new = 2 )
197
205
206
+ def open_dashboard (self , ip ):
207
+ webbrowser .open ("http://{0}" .format (ip ), new = 2 )
208
+
198
209
def start_listen (self ):
199
210
logger .info (" start listeners." )
200
211
self .actionIPRStart .setEnabled (False )
@@ -234,6 +245,92 @@ def restart_listen(self):
234
245
self .stop_listen ()
235
246
self .start_listen ()
236
247
248
+ # confirm
249
+ def retrieve_iceriver_mac_addr (self , ip ):
250
+ with requests .Session () as s :
251
+ host = f"http://{ ip } "
252
+ s .head (host )
253
+ res = s .post (
254
+ url = f"{ host } /user/ipconfig" ,
255
+ data = {"post" : 1 },
256
+ headers = {"Referer" : host },
257
+ )
258
+ r_data = res .json ()["data" ]
259
+ if "mac" in r_data :
260
+ return r_data ["mac" ]
261
+
262
+ def show_confirm (self ):
263
+ logger .info (" show IP confirmation." )
264
+ if not self .actionDisableInactiveTimer .isChecked ():
265
+ self .inactive .start ()
266
+ ip , mac , type = self .thread .data .split ("," )
267
+ logger .info (f"show_confirm : got { ip } ,{ mac } ,{ type } from listener thread." )
268
+ if mac == "ice-river" :
269
+ mac = self .retrieve_iceriver_mac_addr (ip )
270
+ logger .info (f"show_confirm : got iceriver mac addr : { mac } " )
271
+ if self .actionAlwaysOpenIPInBrowser .isChecked ():
272
+ self .open_dashboard (ip )
273
+ if self .actionEnableIDTable .isChecked ():
274
+ self .activateWindow ()
275
+ elif self .actionDisableIPConfirmations .isChecked ():
276
+ self .activateWindow ()
277
+ else :
278
+ confirm = IPRConfirmation ()
279
+ # IPRConfirmation Signals
280
+ confirm .actionOpenBrowser .clicked .connect (
281
+ lambda : self .open_dashboard (ip )
282
+ )
283
+ confirm .accept .clicked .connect (lambda : self .hide_confirm (confirm ))
284
+ # copy action
285
+ confirm .lineIPField .actionCopy = confirm .lineIPField .addAction (
286
+ self .style ().standardIcon (QStyle .StandardPixmap .SP_FileIcon ),
287
+ QLineEdit .ActionPosition .TrailingPosition ,
288
+ )
289
+ confirm .lineIPField .actionCopy .triggered .connect (
290
+ lambda : self .copy_text (confirm .lineIPField )
291
+ )
292
+ confirm .lineMACField .actionCopy = confirm .lineMACField .addAction (
293
+ self .style ().standardIcon (QStyle .StandardPixmap .SP_FileIcon ),
294
+ QLineEdit .ActionPosition .TrailingPosition ,
295
+ )
296
+ confirm .lineMACField .actionCopy .triggered .connect (
297
+ lambda : self .copy_text (confirm .lineMACField )
298
+ )
299
+ logger .info ("show_confirm : show IPRConfirmation." )
300
+ confirm .lineIPField .setText (ip )
301
+ confirm .lineMACField .setText (mac )
302
+ confirm .show ()
303
+ confirm .activateWindow ()
304
+ self .children .append (confirm )
305
+ if self .actionEnableIDTable .isChecked ():
306
+ t_data = self .get_table_data_from_ip (type , ip )
307
+ logger .info ("show_confirm : write table data." )
308
+ rowPosition = self .tableWidget .rowCount ()
309
+ self .tableWidget .insertRow (rowPosition )
310
+ self .tableWidget .setItem (rowPosition , 0 , QTableWidgetItem (ip ))
311
+ self .tableWidget .setItem (rowPosition , 1 , QTableWidgetItem (mac ))
312
+ self .tableWidget .setItem (
313
+ rowPosition , 2 , QTableWidgetItem (t_data ["serial" ])
314
+ )
315
+ # ASIC TYPE
316
+ self .tableWidget .setItem (rowPosition , 3 , QTableWidgetItem (type ))
317
+ # SUBTYPE
318
+ self .tableWidget .setItem (
319
+ rowPosition , 4 , QTableWidgetItem (t_data ["subtype" ])
320
+ )
321
+
322
+ def hide_confirm (self , confirm ):
323
+ confirm .close ()
324
+
325
+ def copy_text (self , lineEdit ):
326
+ lineEdit .selectAll ()
327
+ lineEdit .copy ()
328
+
329
+ # api config view
330
+ def show_api_config (self ):
331
+ logger .info (" show api config view." )
332
+ self .stackedWidget .setCurrentIndex (2 )
333
+
237
334
def set_api_passwd (self ):
238
335
logger .info (" set api password." )
239
336
passwd = self .linePasswdField .text ()
@@ -261,29 +358,7 @@ def set_api_passwd(self):
261
358
self .linePasswdField .clear ()
262
359
self .update_stacked_widget ()
263
360
264
- def open_dashboard (self , ip ):
265
- webbrowser .open ("http://{0}" .format (ip ), new = 2 )
266
-
267
- def update_stacked_widget (self ):
268
- if self .actionEnableIDTable .isChecked ():
269
- logger .info (" show table view." )
270
- self .stackedWidget .setCurrentIndex (0 )
271
- else :
272
- self .stackedWidget .setCurrentIndex (1 )
273
-
274
- def retrieve_iceriver_mac_addr (self , ip ):
275
- with requests .Session () as s :
276
- host = f"http://{ ip } "
277
- s .head (host )
278
- res = s .post (
279
- url = f"{ host } /user/ipconfig" ,
280
- data = {"post" : 1 },
281
- headers = {"Referer" : host },
282
- )
283
- r_data = res .json ()["data" ]
284
- if "mac" in r_data :
285
- return r_data ["mac" ]
286
-
361
+ # id table view
287
362
def get_table_data_from_ip (self , type , ip ):
288
363
result = {"serial" : "N/A" , "subtype" : "N/A" }
289
364
logger .info (f" get table data from ip { ip } ." )
@@ -379,66 +454,6 @@ def get_table_data_from_ip(self, type, ip):
379
454
pass
380
455
return result
381
456
382
- def show_confirm (self ):
383
- logger .info (" show IP confirmation." )
384
- if not self .actionDisableInactiveTimer .isChecked ():
385
- self .inactive .start ()
386
- ip , mac , type = self .thread .data .split ("," )
387
- logger .info (f"show_confirm : got { ip } ,{ mac } ,{ type } from listener thread." )
388
- if mac == "ice-river" :
389
- mac = self .retrieve_iceriver_mac_addr (ip )
390
- logger .info (f"show_confirm : got iceriver mac addr : { mac } " )
391
- if self .actionAlwaysOpenIPInBrowser .isChecked ():
392
- self .open_dashboard (ip )
393
- if self .actionEnableIDTable .isChecked ():
394
- self .activateWindow ()
395
- elif self .actionDisableIPConfirmations .isChecked ():
396
- self .activateWindow ()
397
- else :
398
- confirm = IPRConfirmation ()
399
- # IPRConfirmation Signals
400
- confirm .actionOpenBrowser .clicked .connect (
401
- lambda : self .open_dashboard (ip )
402
- )
403
- confirm .accept .clicked .connect (lambda : self .hide_confirm (confirm ))
404
- # copy action
405
- confirm .lineIPField .actionCopy = confirm .lineIPField .addAction (
406
- self .style ().standardIcon (QStyle .StandardPixmap .SP_FileIcon ),
407
- QLineEdit .ActionPosition .TrailingPosition ,
408
- )
409
- confirm .lineIPField .actionCopy .triggered .connect (
410
- lambda : self .copy_text (confirm .lineIPField )
411
- )
412
- confirm .lineMACField .actionCopy = confirm .lineMACField .addAction (
413
- self .style ().standardIcon (QStyle .StandardPixmap .SP_FileIcon ),
414
- QLineEdit .ActionPosition .TrailingPosition ,
415
- )
416
- confirm .lineMACField .actionCopy .triggered .connect (
417
- lambda : self .copy_text (confirm .lineMACField )
418
- )
419
- logger .info ("show_confirm : show IPRConfirmation." )
420
- confirm .lineIPField .setText (ip )
421
- confirm .lineMACField .setText (mac )
422
- confirm .show ()
423
- confirm .activateWindow ()
424
- self .children .append (confirm )
425
- if self .actionEnableIDTable .isChecked ():
426
- t_data = self .get_table_data_from_ip (type , ip )
427
- logger .info ("show_confirm : write table data." )
428
- rowPosition = self .tableWidget .rowCount ()
429
- self .tableWidget .insertRow (rowPosition )
430
- self .tableWidget .setItem (rowPosition , 0 , QTableWidgetItem (ip ))
431
- self .tableWidget .setItem (rowPosition , 1 , QTableWidgetItem (mac ))
432
- self .tableWidget .setItem (
433
- rowPosition , 2 , QTableWidgetItem (t_data ["serial" ])
434
- )
435
- # ASIC TYPE
436
- self .tableWidget .setItem (rowPosition , 3 , QTableWidgetItem (type ))
437
- # SUBTYPE
438
- self .tableWidget .setItem (
439
- rowPosition , 4 , QTableWidgetItem (t_data ["subtype" ])
440
- )
441
-
442
457
def toggle_table_settings (self ):
443
458
if self .actionEnableIDTable .isChecked ():
444
459
self .actionDisableIPConfirmations .setEnabled (True )
@@ -447,10 +462,6 @@ def toggle_table_settings(self):
447
462
self .update_settings ()
448
463
self .actionDisableIPConfirmations .setEnabled (False )
449
464
450
- def show_api_config (self ):
451
- logger .info (" show set api password view." )
452
- self .stackedWidget .setCurrentIndex (2 )
453
-
454
465
def copy_selected (self ):
455
466
logger .info (" copy selected elements." )
456
467
rows = self .tableWidget .rowCount ()
@@ -502,13 +513,6 @@ def export_table(self):
502
513
self , "BitCapIPR" , f"Successfully wrote csv to { p } ."
503
514
)
504
515
505
- def hide_confirm (self , confirm ):
506
- confirm .close ()
507
-
508
- def copy_text (self , lineEdit ):
509
- lineEdit .selectAll ()
510
- lineEdit .copy ()
511
-
512
516
def update_settings (self ):
513
517
logger .info (" write settings to config." )
514
518
instance = {
0 commit comments