all repos — m12-patcher @ 2aaac7b27ad8359b672aaf1a66f566952a2c118d

better preset menu
Marco Andronaco andronacomarco@gmail.com
Wed, 06 Jul 2022 14:58:33 +0200
commit

2aaac7b27ad8359b672aaf1a66f566952a2c118d

parent

a3ee9a2765e757a657cda957903abfaa40b2e458

4 files changed, 61 insertions(+), 21 deletions(-)

jump to
M .gitignore.gitignore

@@ -1,4 +1,5 @@

.vscode +pygubu build dist __pycache__
M Functions.pyFunctions.py

@@ -15,9 +15,13 @@ file_hash.update(chunk)

return file_hash.hexdigest() == 'f41e36204356974c94fabf7d144dd32a' -def apply_preset(app, preset): - for key in preset.keys(): +def apply_preset(app, preset_name): + if preset_name in Constants.PRESETS: + preset = Constants.PRESETS[preset_name] + for key in preset.keys(): getattr(app, key).set(preset[key]) + return True + return False def apply_patch(base, ips): patch = Patch.load(ips)
M patcher.pypatcher.py

@@ -8,6 +8,8 @@

PROJECT_PATH = Path(__file__).parent PROJECT_UI = PROJECT_PATH / "patcher.ui" + + class PatcherApp: def __init__(self, master=None): self.builder = builder = Builder()

@@ -15,7 +17,8 @@ builder.add_resource_path(PROJECT_PATH)

builder.add_from_file(PROJECT_UI) # Main widget self.mainwindow = builder.get_object("main_frame", master) - + self.apply_button = builder.get_object("apply_button") + self.browse_path = None self.preset = None self.font = None

@@ -39,10 +42,10 @@ "progress",

"status_text", ], ) - apply_preset(self, next(iter(Constants.PRESETS.items()))[1]) + + self.preset.trace('w', self.on_change_preset) + self.preset.set(next(iter(Constants.PRESETS.keys()))) self.status_text.set(Constants.STATUS_START) - - self.apply_button = builder.get_object("apply_button") baserom = None for file in os.listdir('.'):

@@ -61,11 +64,14 @@ def on_browse_button(self):

fn = askopenfilename(filetypes=[(Constants.VAR_FILEPICKER, '*.gba')]) self.browse_path.set(fn) - def on_change_preset(self, option): - preset = Constants.PRESETS[option] - apply_preset(self, preset) - - set_progress(self, 0, Constants.STATUS_PRESET) + def trace_f(self, var, index, mode): + preset = var.get() + if apply_preset(self, preset): + set_progress(self, 0, Constants.STATUS_PRESET) + + def on_change_preset(self, *arg): + if apply_preset(self, self.preset.get()): + set_progress(self, 0, Constants.STATUS_PRESET) def on_apply_button(self): self.apply_button['state'] = 'disabled'

@@ -78,6 +84,8 @@ self.apply_button['state'] = 'normal'

return self.baserom = baserom_temp start_patching(self) + self.apply_button['state'] = 'enabled' + set_progress(self, 0, Constants.STATUS_START) def main(): if not os.path.isdir(Constants.PATH_TOOLS):

@@ -86,6 +94,7 @@ return

root = tkinter.Tk() root.title(Constants.VAR_WINDOW_TITLE) + root.resizable(False, False) app = PatcherApp(root) app.run()
M patcher.uipatcher.ui

@@ -26,6 +26,7 @@ <property name="justify">left</property>

<property name="textvariable">string:browse_path</property> <property name="width">23</property> <layout manager="pack"> + <property name="expand">true</property> <property name="fill">x</property> <property name="padx">3</property> <property name="pady">5</property>

@@ -39,6 +40,8 @@ <property name="command" type="command" cbtype="simple">on_browse_button</property>

<property name="text" translatable="yes">...</property> <property name="width">2</property> <layout manager="pack"> + <property name="expand">false</property> + <property name="fill">x</property> <property name="ipadx">2</property> <property name="padx">5</property> <property name="side">right</property>

@@ -62,13 +65,14 @@ <property name="row">0</property>

<property name="sticky">ew</property> </layout> <child> - <object class="tk.OptionMenu" id="preset_menu"> - <property name="command" type="command" cbtype="simple">on_change_preset</property> - <property name="value">Scelte consigliate</property> - <property name="values">Scelte consigliate,EB Beginnings (US),Mother 1 (JP),Mother 1+2</property> - <property name="variable">string:preset</property> + <object class="ttk.Combobox" id="preset_combo"> + <property name="state">readonly</property> + <property name="textvariable">string:preset</property> + <property name="values">"Scelte consigliate" "EB Beginnings (US)" "Mother 1 (JP)" "Mother 1+2"</property> <layout manager="pack"> <property name="fill">x</property> + <property name="padx">5</property> + <property name="pady">8</property> <property name="side">top</property> </layout> </object>

@@ -96,6 +100,8 @@ <property name="value">1</property>

<property name="variable">int:font</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -107,6 +113,8 @@ <property name="value">2</property>

<property name="variable">int:font</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -129,11 +137,13 @@ <property name="sticky">ew</property>

</layout> <child> <object class="ttk.Radiobutton" id="places_us"> - <property name="text" translatable="yes">Americani</property> + <property name="text" translatable="yes">Occidentali</property> <property name="value">6</property> <property name="variable">int:places</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -145,6 +155,8 @@ <property name="value">7</property>

<property name="variable">int:places</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -172,6 +184,8 @@ <property name="value">3</property>

<property name="variable">int:sprites</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -183,6 +197,8 @@ <property name="value">4</property>

<property name="variable">int:sprites</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -194,6 +210,8 @@ <property name="value">5</property>

<property name="variable">int:sprites</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -212,7 +230,7 @@ <property name="ipady">2</property>

<property name="padx">5</property> <property name="pady">5</property> <property name="row">2</property> - <property name="sticky">ew</property> + <property name="sticky">new</property> </layout> <child> <object class="ttk.Radiobutton" id="palette_nes">

@@ -221,6 +239,8 @@ <property name="value">8</property>

<property name="variable">int:palette</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -232,17 +252,21 @@ <property name="value">9</property>

<property name="variable">int:palette</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object> </child> <child> - <object class="ttk.Radiobutton" id="palette_vc"> - <property name="text" translatable="yes">Virtual Console Wii e Wii U</property> - <property name="value">11</property> + <object class="ttk.Radiobutton" id="palette_ncm"> + <property name="text" translatable="yes">Nintendo Classic Mini - NES</property> + <property name="value">10</property> <property name="variable">int:palette</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>

@@ -272,6 +296,8 @@ <property name="text" translatable="yes">Avvia automaticamente Mother 1</property>

<property name="variable">int:skip_m1</property> <layout manager="pack"> <property name="anchor">w</property> + <property name="padx">5</property> + <property name="pady">1</property> <property name="side">top</property> </layout> </object>