@@ -292,9 +292,9 @@ def resize_image(image: Image.Image, wanted_width: int, width_is_height: bool =
292292HEADING3 = Font (root , family = 'SUSE Semibold' , size = 16 if settings .small_fonts else 17 )
293293SUBTITLE = Font (root , family = 'SUSE Regular' , size = 12 )
294294REGULAR_TEXT = Font (root , family = 'SUSE Regular' , size = 12 if settings .small_fonts else 14 )
295- LIGHT_TEXT = Font (root , family = 'SUSE Light' , size = 12 if settings .small_fonts else 14 )
296- XLIGHT_TEXT = Font (root , family = 'SUSE ExtraLight' , size = 12 if settings .small_fonts else 14 )
297- THIN_TEXT = Font (root , family = 'SUSE Thin' , size = 12 if settings .small_fonts else 14 )
295+ LIGHT_TEXT = Font (root , family = 'SUSE Light' , size = 10 if settings .small_fonts else 12 )
296+ XLIGHT_TEXT = Font (root , family = 'SUSE ExtraLight' , size = 10 if settings .small_fonts else 12 )
297+ THIN_TEXT = Font (root , family = 'SUSE Thin' , size = 10 if settings .small_fonts else 12 )
298298BOLD_TEXT = Font (root , family = 'SUSE Medium' , size = 12 if settings .small_fonts else 14 )
299299PRIMARY_BUTTON = Font (root , family = 'SUSE Semibold' , size = 10 if settings .small_fonts else 12 , underline = False )
300300SECONDARY_BUTTON = Font (root , family = 'SUSE Light' , size = 10 if settings .small_fonts else 12 )
@@ -690,18 +690,148 @@ def setup_play_screen():
690690 PLAY_ITEMS .pack ()
691691
692692
693- def open_database_editor (): # TODO
694- database_win = tk .Toplevel (root )
695- chosen_db = tk .StringVar (database_win , DATABASES [0 ].source )
693+ def open_database_editor (master : tk .Toplevel ) -> None :
694+ def run_button (action : int , ** kw ) -> None | int | Database | bool :
695+ match action :
696+ case 0 :
697+ DATABASES [chosen_db_index .get ()].use ()
698+ settings .databases = [i .source for i in DATABASES ]
699+
700+ settings .save_settings ()
701+ database_win .destroy ()
702+ master .destroy ()
703+ PLAY_ITEMS .destroy ()
704+ play_butt .configure (state = tk .ACTIVE )
705+ root .focus_force ()
706+ return
707+
708+ case 1 :
709+ chosen_db_index .set (chosen_db_index .get () - 1 )
710+ chosen_db .set (DATABASES [chosen_db_index .get ()].source [:90 ] if len (DATABASES [chosen_db_index .get ()].source ) > 90 else DATABASES [chosen_db_index .get ()].source )
711+ down .configure (state = tk .ACTIVE )
712+
713+ if chosen_db .get () == DATABASES [0 ].source :
714+ up .configure (state = tk .DISABLED )
715+ return
716+
717+ case 2 :
718+ chosen_db_index .set (chosen_db_index .get () + 1 )
719+ chosen_db .set (DATABASES [chosen_db_index .get ()].source [:90 ] if len (DATABASES [chosen_db_index .get ()].source ) > 90 else DATABASES [chosen_db_index .get ()].source )
720+ up .configure (state = tk .ACTIVE )
721+
722+ if chosen_db .get () == DATABASES [- 1 ].source :
723+ down .configure (state = tk .DISABLED )
724+ return
725+
726+ case 3 :
727+ return DATABASES [chosen_db_index .get ()].remove ()
728+
729+ case 4 :
730+ input_text : str = add_db_entry .get ()
731+
732+ if len (input_text ) == 0 :
733+ return handle_error (54 , "URL expected, yet DoomMapGuesser received nothing." )
734+
735+ test_var = get_database (add_db_entry , handle_error )
736+
737+ if isinstance (test_var , int ):
738+ del test_var
739+ return handle_error (54 , "This database cannot be used by DoomMapGuesser. Please refer to the previously showed error." )
740+
741+ del test_var
742+
743+ return add_database (input_text )
744+
745+ case 5 :
746+ add_db_entry .delete (0 , tk .END )
747+ return
748+
749+ case 6 :
750+ input_text : str = add_db_entry .get ()
751+
752+ if len (input_text ) == 0 :
753+ return handle_error (54 , "URL expected, yet DoomMapGuesser received nothing." )
754+
755+ return simple_webbrowser .website (input_text )
756+
757+ case 7 :
758+ database_win .destroy ()
759+ master .destroy ()
760+ PLAY_ITEMS .destroy ()
761+ play_butt .configure (state = tk .ACTIVE )
762+ root .focus_force ()
763+ return
764+
765+ case _:
766+ print ('wrong action ID' )
767+
768+ database_win = tk .Toplevel (master )
769+ chosen_db_index = tk .IntVar (database_win , 0 )
770+ chosen_db = tk .StringVar (database_win , DATABASES [0 ].source [:90 ] if len (DATABASES [0 ].source ) > 90 else DATABASES [0 ].source )
696771
772+ f_existing = ttk .Frame (database_win )
697773 f_controls = ttk .Frame (database_win )
698774
699- title = ttk .Label (database_win , text = 'Database Settings' , font = HEADING2 )
700- db_picker = ttk .Label (f_controls , textvariable = chosen_db , font = LIGHT_TEXT )
701- mark_as_default = ttk .Button (f_controls , 'Use' )
775+ title = ttk .Label (database_win , text = 'Database Settings' , font = HEADING1 )
776+ existing = ttk .Label (database_win , text = 'Select a Database...' , font = HEADING2 )
777+ new = ttk .Label (database_win , text = '...or add a new one' , font = HEADING2 )
778+
779+ db_picker = ttk .Button (f_existing , textvariable = chosen_db , width = 120 , command = lambda :
780+ simple_webbrowser .website (chosen_db .get ()))
781+
782+ up = ttk .Button (f_existing , text = '↑' , command = lambda :
783+ run_button (1 ))
784+ down = ttk .Button (f_existing , text = '↓' , command = lambda :
785+ run_button (2 ))
786+ remove = ttk .Button (f_existing , text = 'X' , command = lambda :
787+ run_button (3 ))
788+
789+ add_db_entry = ttk .Entry (f_controls , validate_command = lambda :
790+ run_button (4 ))
791+ add_db_button = ttk .Button (f_controls , text = '+' , command = lambda : # [i] if the user doesn't hit enter they could always use the button, right?
792+ run_button (4 ))
793+ cancel_add_db = ttk .Button (f_controls , text = 'X' , command = lambda :
794+ run_button (5 ))
795+ test_db_butt = ttk .Button (f_controls , text = 'Test' , command = lambda :
796+ run_button (6 ))
797+
798+ apply = ttk .Button (database_win , text = 'Apply' , command = lambda :
799+ run_button (0 ))
800+ cancel = ttk .Button (database_win , text = 'Cancel' , command = lambda :
801+ run_button (7 ))
802+
803+ warning_label_1 = ttk .Label (database_win , text = 'Sorting databases can only be done by editing the actual JSON file. This interface is intended for users that lack programming skills.' , font = LIGHT_TEXT )
804+ warning_label_2 = ttk .Label (database_win , text = 'Databases should be raw JSON. An example is the default database. It\' s highly recommended to also host it in a safe way that promotes easy access from scripts, such as GitHub.' , font = LIGHT_TEXT )
805+
806+ existing .pack (side = 'left' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
807+
808+ title .pack (side = 'left' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
809+
810+ db_picker .grid (column = 0 , row = 0 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
811+ up .grid (column = 1 , row = 0 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
812+ down .grid (column = 2 , row = 0 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
813+ remove .grid (column = 3 , row = 0 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
814+
815+ f_existing .pack (side = 'left' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
816+
817+ warning_label_1 .pack (side = 'left' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
818+
819+ new .pack (side = 'left' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
820+
821+ add_db_entry .grid (column = 0 , row = 0 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
822+ add_db_button .grid (column = 1 , row = 0 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
823+ test_db_butt .grid (column = 0 , row = 1 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
824+ cancel_add_db .grid (column = 1 , row = 1 , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
825+
826+ f_controls .pack (side = 'left' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
827+
828+ warning_label_2 .pack (side = 'left' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
829+
830+ apply .pack (side = 'right' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
831+ cancel .pack (side = 'right' , padx = 5 // int (settings .small_fonts + 1 ), pady = 5 // int (settings .small_fonts + 1 ), ipadx = 5 // int (settings .small_fonts + 1 ), ipady = 5 // int (settings .small_fonts + 1 ))
702832
703833
704- def open_settings ():
834+ def open_settings (): # TODO
705835 settings_win = tk .Toplevel (root )
706836
707837 chosen_theme = tk .StringVar (settings_win , settings .theme )
0 commit comments