11import yaml , os , logging , sys
22from PyQt5 .QtWidgets import QLineEdit , QPushButton , QApplication , QMainWindow , \
3- QFileDialog , QInputDialog , QLabel , QMessageBox , QWidget
3+ QFileDialog , QInputDialog , QLabel , QMessageBox , QWidget , QCheckBox , \
4+ QComboBox
45from PyQt5 import QtCore , QtGui
56from PyQt5 .QtGui import QPalette , QColor
67
1314
1415DEBUG = False
1516
17+ DEFAULT_SETTINGS = {"compare_column_sum_choice" : "Current Split" }
1618
19+ class Second (QMainWindow ):
20+ SCREEN_WIDTH = 400
21+ SCREEN_HEIGHT = 200
22+ def __init__ (self , parent = None ):
23+ super (Second , self ).__init__ (parent )
24+
25+ self .init_settings_from_file ()
26+
27+ self .setFixedSize (self .SCREEN_WIDTH ,self .SCREEN_HEIGHT )
28+ self .compare_column_sum_label = QLabel ("Compare column sum:" , self )
29+ self .compare_column_sum_label .setGeometry (QtCore .QRect (5 , 10 , 220 , 40 ))
30+ self .compare_column_sum_choice = QComboBox (self )
31+ self .compare_column_sum_choice .addItem ("Current Split" )
32+ self .compare_column_sum_choice .addItem ("Total" )
33+ self .compare_column_sum_choice .setCurrentText (self .settings ['compare_column_sum_choice' ])
34+ self .compare_column_sum_choice .setGeometry (QtCore .QRect (240 , 10 , 150 , 40 ))
35+ self .compare_column_sum_label .setToolTip ('Current Split: Column sum will compare all current splits in run to PB splits up to the same point.\n Total: Column sum will compare current splits in run to entire sum of PB.' )
36+ self .compare_column_sum_choice .setToolTip ('Current Split: Column sum will compare all current splits in run to PB splits up to the same point.\n Total: Column sum will compare current splits in run to entire sum of PB.' )
37+
38+ self .compare_column_sum_choice .activated [str ].connect (self .update_settings )
1739
1840
19- class QMainWindow2 (QMainWindow ):
20- # if not DEBUG:
21- # def closeEvent(self,event):
22- # result = QMessageBox.question(self,
23- # "Confirm exit",
24- # "Confirm exit? Save splits manually before closing.",
25- # QMessageBox.Yes| QMessageBox.No)
26- # event.ignore()
27-
28- # if result == QMessageBox.Yes:
29- # event.accept()
30- pass
41+ self .setWindowTitle ('Settings' )
42+ self .icon = QtGui .QIcon ()
43+ self .icon .addPixmap (QtGui .QPixmap (os .path .join (THIS_FILEPATH ,"ico.ico" )), QtGui .QIcon .Normal , QtGui .QIcon .Off )
44+ self .setWindowIcon (self .icon )
45+
46+
47+
48+
49+ def update_settings (self ):
50+ self .settings ['compare_column_sum_choice' ] = self .compare_column_sum_choice .currentText ()
51+
52+ def init_settings_from_file (self ):
53+
54+ try :
55+ with open ("settings.txt" , 'r' ) as f :
56+ self .settings = yaml .safe_load (f )
57+ except :
58+ self .settings = DEFAULT_SETTINGS
59+ self .save_settings_file ()
60+
61+ def save_settings_file (self ):
62+ with open ("settings.txt" , 'w' ) as f :
63+ yaml .dump (self .settings ,f )
64+
65+ w = None
66+ def closeEvent (self , event ):
67+ if self .w :
68+ self .w .close ()
69+ self .save_settings_file ()
70+
71+ class MainWindow (QMainWindow ):
72+ def __init__ (self , mainapp , app , parent = None ):
73+ super (QMainWindow , self ).__init__ (parent )
74+ self .app = app
75+ self .mainapp = mainapp
3176
77+ w = None
78+ def closeEvent (self , event ):
79+ if self .w :
80+ self .w .close ()
3281
33- class MainWindow (object ):
82+ self .app .closeAllWindows ()
83+ def wheelEvent (self ,event ):
84+ if self .mainapp .current_status == "started" or self .mainapp .current_status == "not_started" or self .mainapp .current_status == "finished" :
85+
86+
87+
88+ if event .angleDelta ().y () > 0 :
89+ self .mainapp .current_idx_viewing -= 1
90+ if event .angleDelta ().y () < 0 :
91+ self .mainapp .current_idx_viewing += 1
92+ self .mainapp .show_current_splits ()
93+
94+
95+
96+ class MainApp (object ):
3497
3598 size = 1
3699
@@ -40,9 +103,10 @@ class MainWindow(object):
40103 RESET_X = 125
41104 INPUT_X = 220
42105 UNDO_X = 280
43- LOAD_X = 60
44- CREATE_X = 195
45- SAVE_X = 325
106+ LOAD_X = 40
107+ CREATE_X = 140
108+ SAVE_X = 240
109+ SETTINGS_X = 340
46110 BOTTOM_BUTTON_Y = 440
47111
48112 CURRENT_LABEL_X = 170
@@ -73,6 +137,7 @@ class MainWindow(object):
73137 LOAD_X = 60
74138 CREATE_X = 230
75139 SAVE_X = 390
140+ SETTINGS_X = 480
76141 BOTTOM_BUTTON_Y = 440
77142
78143 CURRENT_LABEL_X = 180
@@ -98,7 +163,7 @@ class MainWindow(object):
98163
99164 def __init__ (self ):
100165 self .app = QApplication ([])
101- self .window = QMainWindow2 ( )
166+ self .window = MainWindow ( self , self . app )
102167 self .window .setFixedSize (self .SCREEN_WIDTH ,self .SCREEN_HEIGHT )
103168 self .window .setWindowTitle ('No Damage Tracker' )
104169 self .icon = QtGui .QIcon ()
@@ -115,9 +180,11 @@ def __init__(self):
115180 self .split_values = list (self .splits_dict .values ())
116181
117182
183+ self .settings_window = Second ()
118184
119185
120186 self .current_idx = 0
187+ self .current_idx_viewing = 0
121188 self .current_status = "waiting_for_splits"
122189
123190 self .end_idx = len (self .splits )
@@ -154,6 +221,10 @@ def __init__(self):
154221 self .save_button .setGeometry (QtCore .QRect (self .SAVE_X , self .BOTTOM_BUTTON_Y , 80 , 30 ))
155222 self .save_button .clicked .connect (self .save_splits )
156223
224+ self .save_button = QPushButton ("Settings" ,self .window )
225+ self .save_button .setGeometry (QtCore .QRect (self .SETTINGS_X , self .BOTTOM_BUTTON_Y , 80 , 30 ))
226+ self .save_button .clicked .connect (self .settings_click )
227+
157228
158229
159230
@@ -284,7 +355,10 @@ def init_splits(self):
284355 self .entry_current .hide ()
285356
286357
287- self .entry_pb = QLabel (str (self .split_values [idx ]), self .window )
358+ pb_amt = str (self .split_values [idx ])
359+ if pb_amt == "99" :
360+ pb_amt = "-"
361+ self .entry_pb = QLabel (pb_amt , self .window )
288362 self .entry_pb .setGeometry (QtCore .QRect (self .ENTRY_PB_X , 5 + 30 * OFFSET , 30 , 30 ))
289363 self .entry_pb .setAlignment (QtCore .Qt .AlignCenter )
290364 self .entry_pb .setStyleSheet ("font:bold;" )
@@ -355,8 +429,16 @@ def reset_splits_click(self):
355429 QMessageBox .about (self .window , "Error" , "Load splits before starting" )
356430 else :
357431 if self .current_status == "finished" :
358- if int (self .total_current .text ()) <= int (self .total_pb .text ()):
359-
432+ self .reset_button .setText ("Reset" )
433+ pass_flag = False
434+ if self .total_pb .text () == "-" :
435+ pass_flag = True
436+
437+ elif int (self .total_current .text ()) <= int (self .total_pb .text ()):
438+ pass_flag = True
439+
440+
441+ if pass_flag :
360442 qm = QMessageBox
361443 ret = qm .question (self .window ,'Keep splits?' , "Use this run for PB splits?" , qm .Yes | qm .No )
362444
@@ -379,7 +461,7 @@ def create_splits_click(self):
379461 d = {}
380462 for s in split_names :
381463 if s :
382- d [str (s ).strip ()] = 10
464+ d [str (s ).strip ()] = 99
383465
384466 self .splits_dict = d
385467
@@ -389,7 +471,11 @@ def create_splits_click(self):
389471
390472
391473
474+ def settings_click (self ):
475+ self .settings_window .show ()
476+
392477
478+
393479
394480 def update_pb_splits (self ):
395481
@@ -420,6 +506,8 @@ def confirm_pb_save(self):
420506
421507 def reset_splits (self ):
422508 self .current_idx = 0
509+ self .current_idx_viewing = 0
510+ self .show_current_splits ()
423511 w = [i for i in self .window .children () if i .property ("widget_type" ) == "entry" ]
424512 for i in w :
425513 style = i .styleSheet ()
@@ -476,8 +564,9 @@ def post_current_entry(self):
476564 self .current_split_input .setText ("" )
477565
478566 self .current_idx = self .current_idx + 1
567+ self .current_idx_viewing = self .current_idx
479568 if self .current_idx == self .end_idx :
480- self .start_button .setText ("Finish" )
569+ self .reset_button .setText ("Finish" )
481570 self .current_status = "finished"
482571 self .current_split_input .hide ()
483572 else :
@@ -487,18 +576,25 @@ def post_current_entry(self):
487576 self .show_current_splits ()
488577
489578 def calculate_compare (self ):
579+
490580 entry_compare = [i for i in self .window .children () if i .property ("widget_type" ) == "entry_compare" and i .property ("idx" ) == self .current_idx ][0 ]
491581 entry_current = [i for i in self .window .children () if i .property ("widget_type" ) == "entry_current" and i .property ("idx" ) == self .current_idx ][0 ]
492582 entry_pb = [i for i in self .window .children () if i .property ("widget_type" ) == "entry_pb" and i .property ("idx" ) == self .current_idx ][0 ]
493583
494- update_num = int ( entry_current . text ()) - int ( entry_pb .text () )
584+ pb_amt = entry_pb .text ()
495585
496- if update_num < 0 :
497- color = 'green'
498- elif update_num > 0 :
499- color = 'red'
586+ if pb_amt == "-" :
587+ update_num = "-"
588+ color = "white"
500589 else :
501- color = 'white'
590+ update_num = int (entry_current .text ()) - int (pb_amt )
591+
592+ if update_num < 0 :
593+ color = 'green'
594+ elif update_num > 0 :
595+ color = 'red'
596+ else :
597+ color = 'white'
502598
503599 style = entry_compare .styleSheet ()
504600 style = "%s;color:%s;" % (style , color )
@@ -510,14 +606,47 @@ def calculate_compare(self):
510606 self .calculate_total_compare ()
511607
512608 def calculate_total_compare (self ):
513- update_num = int (self .total_current .text ()) - int (self .total_pb .text ())
514609
515- if update_num < 0 :
516- color = 'green'
517- elif update_num > 0 :
518- color = 'red'
519- else :
520- color = 'white'
610+
611+
612+
613+ if (self .settings_window .settings ['compare_column_sum_choice' ] == "Current Split" ):
614+
615+ pb_total = self .total_pb .text ()
616+
617+ if pb_total == "-" :
618+ update_num = "-"
619+ color = 'white'
620+ else :
621+ temp_num = 0
622+ for idx in range (0 , self .current_idx + 1 ):
623+ pb = [i for i in self .window .children () if i .property ("widget_type" ) == "entry_pb" and i .property ("idx" ) == idx ][0 ]
624+ temp_num += int (pb .text ())
625+
626+ update_num = int (self .total_current .text ()) - temp_num
627+
628+ if update_num < 0 :
629+ color = 'green'
630+ elif update_num > 0 :
631+ color = 'red'
632+ else :
633+ color = 'white'
634+
635+ elif (self .settings_window .compare_column_sum_choice .currentText () == "Total" ):
636+ pb_total = self .total_pb .text ()
637+
638+ if pb_total == "-" :
639+ color = 'white'
640+ update_num = "-"
641+ else :
642+ update_num = int (self .total_current .text ()) - int (pb_total )
643+
644+ if update_num < 0 :
645+ color = 'green'
646+ elif update_num > 0 :
647+ color = 'red'
648+ else :
649+ color = 'white'
521650
522651
523652 update_text = str (update_num )
@@ -536,7 +665,7 @@ def show_current_splits(self):
536665
537666
538667
539- cur_idx = self .current_idx
668+ cur_idx = self .current_idx_viewing
540669 OFFSET = 4
541670
542671 if self .end_idx < 8 :
@@ -635,8 +764,11 @@ def undo_split(self):
635764 self .current_status = "started"
636765
637766 def save_splits (self , bypass = False , use_splits_path = False ):
767+
768+ if self .current_status == 'finished' :
769+ QMessageBox .about (self .window , "Error" , "Finish/Reset splits before saving" )
638770
639- if self .current_status != 'waiting_for_splits' or bypass :
771+ elif self .current_status != 'waiting_for_splits' or bypass :
640772
641773 if not use_splits_path :
642774
@@ -685,8 +817,12 @@ def load_splits(self, new_file = False):
685817 self .end_idx = len (self .splits )
686818
687819 self .total_hits = 0
820+ pb_sum = sum (self .split_values )
821+
822+ if pb_sum % 99 == 0 :
823+ pb_sum = "-"
688824
689- self .total_hits_pb = sum ( self . split_values )
825+ self .total_hits_pb = pb_sum
690826 self .total_pb .setText (str (self .total_hits_pb ))
691827
692828
@@ -702,6 +838,6 @@ def load_splits(self, new_file = False):
702838
703839
704840if __name__ == '__main__' :
705- main_window = MainWindow ()
841+ main_window = MainApp ()
706842 main_window .window .show ()
707843 main_window .app .exec_ ()
0 commit comments