From eabb9cd4c47c9e28e870ce7be0df851ea1f22d49 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Thu, 4 Apr 2024 21:30:43 -0400 Subject: add set-profile-in-use --- srb_tk.py | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'srb_tk.py') diff --git a/srb_tk.py b/srb_tk.py index b4113e6..88610a3 100755 --- a/srb_tk.py +++ b/srb_tk.py @@ -20,12 +20,11 @@ # icon courtesy of https://icons8.com/icon/9336/aircraft # possible way to have a widget store its variable: https://stackoverflow.com/questions/63871376/tkinter-widget-cgetvariable # count number of 1s in a binary value https://stackoverflow.com/questions/8871204/count-number-of-1s-in-binary-representation/71307775#71307775 +# https://stackoverflow.com/questions/67334913/can-i-possibly-put-an-image-label-into-an-option-box-in-tkinter # Improve: -# Enable the checkbox for profile-in-use # Add reset-level-breakables # disable/gray out levels labels not reachable because of levelset_available_levels # setting that sets the background colors of the regions -# add images to option menus if possible: https://stackoverflow.com/questions/67334913/can-i-possibly-put-an-image-label-into-an-option-box-in-tkinter # Dependencies: # dep-devuan: python3-tkinter, python3-pil.imagetk # rec-devuan: python3-cairosvg @@ -95,12 +94,12 @@ class App(tk.Frame): self.silent.set(True) # data variables + # Do not use traces for most things, because it will catch itself in a loop. Instead, use the bind on the form fields. self.current_file = tk.StringVar(value = os.path.join(os.getenv("HOME"),"Documents","Snoopy vs. the Red Baron","Profile 1","Profile 1.sav")) #print(f"beginning: {self.current_file.get()}") self.checksum = tk.IntVar() self.selected_profile = tk.IntVar(value=1) self.prof1_used = tk.BooleanVar() - # Do not use traces for most things though, because it will catch itself in a loop. Instead, use the bind on the form fields. self.prof1name = tk.StringVar() self.prof1tut = tk.BooleanVar() self.prof2_used = tk.BooleanVar() @@ -174,44 +173,46 @@ class App(tk.Frame): self.frm_profiles = tk.Frame(self.master) #,background="orange",borderwidth=1) self.frm_profiles.grid(row=3,column=0,columnspan=2) # investigate radio button key-bind, up-down, to increment/decrement choice? + tk.Label(self.frm_profiles,text="Used").grid(row=0,column=2) + tk.Label(self.frm_profiles,text="Tutorial").grid(row=0,column=3) self.rad_prof1 = stk.Radiobutton(self.frm_profiles,value=1,text="Profile 1",variable=self.selected_profile,underline=8) - self.rad_prof1.grid(row=0,column=0) - self.chk_prof1_used = tk.Checkbutton(self.frm_profiles,text="used",state="disabled",variable=self.prof1_used) - self.chk_prof1_used.grid(row=0,column=2) - self.chk_prof1_tut = stk.Checkbutton(self.frm_profiles,text="tutorial",variable=self.prof1tut,func=self.load_form_into_data) + self.rad_prof1.grid(row=1,column=0) + self.chk_prof1_used = tk.Checkbutton(self.frm_profiles,variable=self.prof1_used) + self.chk_prof1_used.grid(row=1,column=2) + self.chk_prof1_tut = stk.Checkbutton(self.frm_profiles,variable=self.prof1tut,func=self.load_form_into_data) #self.hook_checkbox_enter_keys(self.chk_prof1_tut,self.load_form_into_data) - self.chk_prof1_tut.grid(row=0,column=3) + self.chk_prof1_tut.grid(row=1,column=3) self.ent_prof1name = stk.Entry(self.frm_profiles,textvariable=self.prof1name,func=self.load_form_into_data,width=11) self.ent_prof1name.bind("",self.load_form_into_data) self.ent_prof1name.bind("",self.load_form_into_data) - self.ent_prof1name.grid(row=0,column=4) + self.ent_prof1name.grid(row=1,column=4) self.rad_prof2 = stk.Radiobutton(self.frm_profiles,value=2,text="Profile 2",variable=self.selected_profile,underline=8) - self.rad_prof2.grid(row=1,column=0) + self.rad_prof2.grid(row=2,column=0) self.prof2_used.set(False) - self.chk_prof2_used = tk.Checkbutton(self.frm_profiles,text="used",state="disabled",variable=self.prof2_used) - self.chk_prof2_used.grid(row=1,column=2) - self.chk_prof2_tut = stk.Checkbutton(self.frm_profiles,text="tutorial",variable=self.prof2tut,func=self.load_form_into_data) + self.chk_prof2_used = tk.Checkbutton(self.frm_profiles,variable=self.prof2_used) + self.chk_prof2_used.grid(row=2,column=2) + self.chk_prof2_tut = stk.Checkbutton(self.frm_profiles,variable=self.prof2tut,func=self.load_form_into_data) #self.hook_checkbox_enter_keys(self.chk_prof2_tut,self.load_form_into_data) - self.chk_prof2_tut.grid(row=1,column=3) + self.chk_prof2_tut.grid(row=2,column=3) self.ent_prof2name = stk.Entry(self.frm_profiles,textvariable=self.prof2name,func=self.load_form_into_data,width=11) self.ent_prof2name.bind("",self.load_form_into_data) - self.ent_prof2name.grid(row=1,column=4) + self.ent_prof2name.grid(row=2,column=4) self.rad_prof3 = stk.Radiobutton(self.frm_profiles,value=3,text="Profile 3",variable=self.selected_profile,underline=8) - self.rad_prof3.grid(row=2,column=0) + self.rad_prof3.grid(row=3,column=0) self.prof3_used.set(False) - self.chk_prof3_used = tk.Checkbutton(self.frm_profiles,text="used",state="disabled",variable=self.prof3_used) - self.chk_prof3_used.grid(row=2,column=2) - self.chk_prof3_tut = stk.Checkbutton(self.frm_profiles,text="tutorial",variable=self.prof3tut,func=self.load_form_into_data) + self.chk_prof3_used = tk.Checkbutton(self.frm_profiles,variable=self.prof3_used) + self.chk_prof3_used.grid(row=3,column=2) + self.chk_prof3_tut = stk.Checkbutton(self.frm_profiles,variable=self.prof3tut,func=self.load_form_into_data) #self.hook_checkbox_enter_keys(self.chk_prof3_tut,self.load_form_into_data) - self.chk_prof3_tut.grid(row=2,column=3) + self.chk_prof3_tut.grid(row=3,column=3) self.ent_prof3name = stk.Entry(self.frm_profiles,textvariable=self.prof3name,func=self.load_form_into_data,width=11) self.ent_prof3name.bind("",self.load_form_into_data) - self.ent_prof3name.grid(row=2,column=4) + self.ent_prof3name.grid(row=3,column=4) #self.selected_profile.set(1) # purposefully do not set this value. # one profile, so we will have to use the value of self.selected_profile self.frm_curprof = tk.Frame(self.master) #,background="red") - self.frm_curprof.grid(row=4,column=0,rowspan=22,columnspan=2) + self.frm_curprof.grid(row=5,column=0,rowspan=22,columnspan=2) # most form fields are inside the current profile self.img_money = get_srb_image("money.png",20,16) self.lbl_money = tk.Label(self.frm_curprof,text="Money",image=self.img_money,compound="right") @@ -410,6 +411,9 @@ class App(tk.Frame): else: raise Exception("No file loaded.") try: + bdata, _ = srb_lib.set_profile_in_use(bdata,1,self.prof1_used.get()) + bdata, _ = srb_lib.set_profile_in_use(bdata,2,self.prof2_used.get()) + bdata, _ = srb_lib.set_profile_in_use(bdata,3,self.prof3_used.get()) bdata, message = srb_lib.set_name(bdata,1,self.prof1name.get()) if message != "": self.flash_entry(self.ent_prof1name) @@ -563,7 +567,10 @@ class App(tk.Frame): self.health, self.stunt, self.gun, - self.equipped_weapon + self.equipped_weapon, + self.prof1_used, + self.prof2_used, + self.prof3_used, #self.prof1name, # do not trace the profile names, because it prevents spaces ending on the variables #self.prof2name, #self.prof3name, @@ -582,6 +589,9 @@ class App(tk.Frame): self.stunt, self.gun, self.equipped_weapon, + self.prof1_used, + self.prof2_used, + self.prof3_used, ] + self.levelset_status_ints + self.level_statuses: for i in j.trace_info(): if i[0][0] == "write": -- cgit