2424versionString , _ , _ = uCore .getVersionString (APP_NAME )
2525
2626settings = loadSettings ()
27+ updatingSettingsUI = False
2728
2829root = tk .Tk ()
2930root .title (APP_NAME + " " + versionString )
@@ -361,14 +362,6 @@ def _fixed_map(style, style_name, option):
361362history .column (2 , anchor = "e" )
362363history .column (3 , anchor = "e" )
363364
364- if settings ["useHistoryColors" ] == 1 :
365- history .tag_configure ("none" , background = settings ["noneBackground" ], foreground = settings ["noneForeground" ])
366- history .tag_configure ("win" , background = settings ["winBackground" ], foreground = settings ["winForeground" ])
367- history .tag_configure ("loss" , background = settings ["lossBackground" ], foreground = settings ["lossForeground" ])
368- history .tag_configure ("draw" , background = settings ["drawBackground" ], foreground = settings ["drawForeground" ])
369-
370- history .tag_configure ("selected" , background = settings ["selectedBackground" ], foreground = settings ["selectedForeground" ])
371-
372365# Create history Scrollbar
373366historyScrollbar = Scrollbar (historyListContainer , orient = VERTICAL , command = history .yview )
374367historyScrollbar .pack (side = tk .LEFT , fill = "y" )
@@ -457,12 +450,10 @@ def _fixed_map(style, style_name, option):
457450settingsContainer .grid_columnconfigure (2 , weight = 1 )
458451settingsContainer .grid_columnconfigure (3 , weight = 1 )
459452
460- bufferDaysSettingVar = IntVar ()
453+ bufferDaysSettingVar = StringVar ()
461454ttk .Label (settingsContainer , text = "Buffer Days:" ).grid (padx = 8 , pady = 2 , columnspan = 2 , column = 0 , row = 0 , sticky = "we" )
462455bufferDaysSettingEntry = ttk .Entry (settingsContainer , textvariable = bufferDaysSettingVar )
463456bufferDaysSettingEntry .grid (padx = 8 , pady = 2 , columnspan = 2 , column = 2 , row = 0 , sticky = "we" )
464- bufferDaysSettingEntry .delete (0 )
465- bufferDaysSettingEntry .insert (0 , settings ["bufferDays" ])
466457
467458enableColorsSettingVar = IntVar ()
468459ttk .Label (settingsContainer , text = "Enable colors in history:" ).grid (padx = 8 , pady = 2 , columnspan = 2 , column = 0 , row = 1 , sticky = "we" )
@@ -619,10 +610,7 @@ def defaultSettingsCallback():
619610 if res == "yes" :
620611 initSettings ()
621612 settings = loadSettings ()
622- updateSettings ()
623-
624- def applySettingsCallback ():
625- pass
613+ updateValues (True )
626614
627615def aboutCallback ():
628616 pass
@@ -668,6 +656,9 @@ def init():
668656 seasonIndex .set (len (data ["seasons" ]) - 1 )
669657 seasonNameVar .set (data ["seasons" ][seasonIndex .get ()]["name" ])
670658
659+ bufferDaysSettingEntry .delete (0 , len (str (bufferDaysSettingVar .get ())))
660+ bufferDaysSettingEntry .insert (0 , settings ["bufferDays" ])
661+
671662# --------------------------------
672663# Update Values
673664# --------------------------------
@@ -682,6 +673,47 @@ def initData(seasonName, activeBPLevel, cXP, remainingDays):
682673 data = {"seasons" : [{"name" : seasonName , "activeBPLevel" : int (activeBPLevel ), "cXP" : int (cXP ), "endDate" : seasonEndDateStr , "xpHistory" : [{"time" : datetime .now ().timestamp (), "description" : "Initialization" , "amount" : int (totalXPCollected )}]}]}
683674 core .writeData (data )
684675
676+ def updateSettings ():
677+ if updatingSettingsUI : return
678+
679+ bufferDaysSetting = bufferDaysSettingVar .get ()
680+ updateBufferDays = True
681+
682+ data = core .readData ()
683+ seasonEndDate = datetime .strptime (data ["seasons" ][seasonIndex .get ()]["endDate" ], "%d.%m.%Y" ).date ()
684+ dateDelta = seasonEndDate - datetime .fromtimestamp (data ["seasons" ][seasonIndex .get ()]["xpHistory" ][0 ]["time" ]).date ()
685+ duration = dateDelta .days
686+
687+ try :
688+ bufferDaysSetting = int (bufferDaysSetting )
689+ if bufferDaysSetting < 0 : bufferDaysSettingEntry .delete (0 )
690+ if bufferDaysSetting >= duration : bufferDaysSettingEntry .delete (len (str (bufferDaysSetting )) - 1 )
691+ except :
692+ bufferDaysSettingEntry .delete (len (str (bufferDaysSetting )) - 1 )
693+
694+ bufferDaysSetting = bufferDaysSettingVar .get ()
695+
696+ try :
697+ settings ["bufferDays" ] = int (bufferDaysSetting )
698+ except :
699+ updateBufferDays = False
700+
701+ settings ["useHistoryColors" ] = enableColorsSettingVar .get ()
702+
703+ settings ["winBackground" ] = winBackgroundSettingBtn .color
704+ settings ["winForeground" ] = winForegroundSettingBtn .color
705+ settings ["lossBackground" ] = lossBackgroundSettingBtn .color
706+ settings ["lossForeground" ] = lossForegroundSettingBtn .color
707+ settings ["drawBackground" ] = drawBackgroundSettingBtn .color
708+ settings ["drawForeground" ] = drawForegroundSettingBtn .color
709+ settings ["noneBackground" ] = noneBackgroundSettingBtn .color
710+ settings ["noneForeground" ] = noneForegroundSettingBtn .color
711+ settings ["selectedBackground" ] = selectedBackgroundSettingBtn .color
712+ settings ["selectedForeground" ] = selectedForegroundSettingBtn .color
713+
714+ updateValues (updateBufferDays )
715+ saveSettings (settings )
716+
685717def addXP (description , amount ):
686718 data = core .readData ()
687719
@@ -1021,11 +1053,36 @@ def updateGraph(data, epilogue, drawEpilogue, plot):
10211053
10221054 return yAxisYou , yAxisIdeal , yAxisDailyIdeal
10231055
1024- # TODO: Implement updateSettings() to update UI
1025- def updateSettings ():
1026- pass
1056+ def updateSettingsUI (updateBufferDays ):
1057+ global updatingSettingsUI
1058+ updatingSettingsUI = True
1059+
1060+ if updateBufferDays :
1061+ bufferDaysSettingEntry .delete (0 , len (str (bufferDaysSettingVar .get ())))
1062+ bufferDaysSettingEntry .insert (0 , settings ["bufferDays" ])
1063+ enableColorsSettingVar .set (settings ["useHistoryColors" ])
1064+
1065+ winBackgroundSettingBtn .setValues (color = settings ["winBackground" ])
1066+ winForegroundSettingBtn .setValues (color = settings ["winForeground" ])
1067+ lossBackgroundSettingBtn .setValues (color = settings ["lossBackground" ])
1068+ lossForegroundSettingBtn .setValues (color = settings ["lossForeground" ])
1069+ drawBackgroundSettingBtn .setValues (color = settings ["drawBackground" ])
1070+ drawForegroundSettingBtn .setValues (color = settings ["drawForeground" ])
1071+ noneBackgroundSettingBtn .setValues (color = settings ["noneBackground" ])
1072+ noneForegroundSettingBtn .setValues (color = settings ["noneForeground" ])
1073+ selectedBackgroundSettingBtn .setValues (color = settings ["selectedBackground" ])
1074+ selectedForegroundSettingBtn .setValues (color = settings ["selectedForeground" ])
1075+
1076+ if settings ["useHistoryColors" ] == 1 :
1077+ history .tag_configure ("none" , background = settings ["noneBackground" ], foreground = settings ["noneForeground" ])
1078+ history .tag_configure ("win" , background = settings ["winBackground" ], foreground = settings ["winForeground" ])
1079+ history .tag_configure ("loss" , background = settings ["lossBackground" ], foreground = settings ["lossForeground" ])
1080+ history .tag_configure ("draw" , background = settings ["drawBackground" ], foreground = settings ["drawForeground" ])
1081+
1082+ history .tag_configure ("selected" , background = settings ["selectedBackground" ], foreground = settings ["selectedForeground" ])
1083+ updatingSettingsUI = False
10271084
1028- def updateValues ():
1085+ def updateValues (updateBufferDays = True ):
10291086 data = core .readData ()
10301087 drawEpilogue = False
10311088
@@ -1106,6 +1163,8 @@ def updateValues():
11061163 miscStrongestDayAmountLabel ["text" ] = str (miscStrongestDayAmount ) + " XP"
11071164 miscWeakestDayDateLabel ["text" ] = str (miscWeakestDayDate )
11081165 miscWeakestDayAmountLabel ["text" ] = str (miscWeakestDayAmount ) + " XP"
1166+
1167+ updateSettingsUI (updateBufferDays )
11091168
11101169 history .delete (* history .get_children ())
11111170 xpHistoryData = data ["seasons" ][seasonIndex .get ()]["xpHistory" ]
@@ -1130,6 +1189,20 @@ def updateValues():
11301189# Settings Callbacks
11311190# ================================
11321191
1192+ bufferDaysSettingVar .trace ("w" , lambda a , b , c : updateSettings ())
1193+ enableColorsSettingCheck .configure (command = lambda : updateSettings ())
1194+
1195+ winBackgroundSettingBtn .setValues (command = lambda : updateSettings ())
1196+ winForegroundSettingBtn .setValues (command = lambda : updateSettings ())
1197+ lossBackgroundSettingBtn .setValues (command = lambda : updateSettings ())
1198+ lossForegroundSettingBtn .setValues (command = lambda : updateSettings ())
1199+ drawBackgroundSettingBtn .setValues (command = lambda : updateSettings ())
1200+ drawForegroundSettingBtn .setValues (command = lambda : updateSettings ())
1201+ noneBackgroundSettingBtn .setValues (command = lambda : updateSettings ())
1202+ noneForegroundSettingBtn .setValues (command = lambda : updateSettings ())
1203+ selectedBackgroundSettingBtn .setValues (command = lambda : updateSettings ())
1204+ selectedForegroundSettingBtn .setValues (command = lambda : updateSettings ())
1205+
11331206# ================================
11341207# Buttons
11351208# ================================
@@ -1155,18 +1228,15 @@ def updateValues():
11551228delBTN = ttk .Button (historyBtnContainer , text = "Delete Element" , command = deleteElementCallback )
11561229delBTN .pack (side = tk .LEFT , fill = "both" , expand = True )
11571230
1158- resetDataSettingBtn = ttk .Button (settingsBtnContainer , text = "Reset Data" , command = resetCallback )
1159- resetDataSettingBtn .pack (side = tk .LEFT , fill = "both" , expand = True )
1160-
11611231resetSettingsBtn = ttk .Button (settingsBtnContainer , text = "Default settings" , command = defaultSettingsCallback )
11621232resetSettingsBtn .pack (side = tk .LEFT , fill = "both" , expand = True )
11631233
1234+ resetDataSettingBtn = ttk .Button (settingsBtnContainer , text = "Reset Data" , command = resetCallback )
1235+ resetDataSettingBtn .pack (side = tk .LEFT , fill = "both" , expand = True )
1236+
11641237aboutSettingBtn = ttk .Button (settingsBtnContainer , text = "About" , command = aboutCallback )
11651238aboutSettingBtn .pack (side = tk .LEFT , fill = "both" , expand = True )
11661239
1167- applySettingBtn = ttk .Button (settingsBtnContainer , text = "Apply" , command = applySettingsCallback )
1168- applySettingBtn .pack (side = tk .LEFT , fill = "both" , expand = True )
1169-
11701240# ================================
11711241# Main Loop
11721242# ================================
0 commit comments