all repos — m12-patcher @ cfe07ba4b9c6d81b80cc98d91d4b0197b2f94676

Gui.py (view raw)

 1#!/usr/bin/python3
 2import tkinter as tk
 3from tkinter.filedialog import askopenfilename
 4import pathlib, pygubu
 5
 6PROJECT_PATH = pathlib.Path(__file__).parent
 7PROJECT_UI = PROJECT_PATH / "patcher.ui"
 8
 9presets = {
10    "Scelte consigliate": {
11        'font': 1,
12        'sprites': 3,
13        'places': 6,
14        'palette': 8,
15        'skip_m1': 1
16        },
17    "EB Beginnings (US)": {
18        'font': 1,
19        'sprites': 4,
20        'places': 6,
21        'palette': 8,
22        'skip_m1': 1
23        },
24    "Mother 1 (JP)": {
25        'font': 1,
26        'sprites': 5,
27        'places': 7,
28        'palette': 8,
29        'skip_m1': 1
30        },
31    "Mother 1+2": {
32        'font': 1,
33        'sprites': 4,
34        'places': 7,
35        'palette': 9,
36        'skip_m1': 0
37        }
38}
39
40class PatcherApp:
41    def __init__(self, master=None):
42        self.builder = builder = pygubu.Builder()
43        builder.add_resource_path(PROJECT_PATH)
44        builder.add_from_file(PROJECT_UI)
45        # Main widget
46        self.mainwindow = builder.get_object("main_frame", master)
47
48        self.browse_path = None
49        self.preset = None
50        self.font = None
51        self.places = None
52        self.sprites = None
53        self.palette = None
54        self.skip_m1 = None
55        builder.import_variables(
56            self,
57            [
58                "browse_path",
59                "preset",
60                "font",
61                "places",
62                "sprites",
63                "palette",
64                "skip_m1",
65            ],
66        )
67        self.font.set(1)
68        self.sprites.set(3)
69        self.places.set(6)
70        self.palette.set(8)
71        self.skip_m1.set(1)
72        
73        builder.connect_callbacks(self)
74
75    def run(self):
76        self.mainwindow.mainloop()
77
78    def on_browse_button(self):
79        fn = askopenfilename(filetypes=[('ROM giapponese di Mother 1+2', '*.gba'), ('Tutti i file', '*')])
80        self.browse_path.set(fn)
81
82    def on_change_preset(self, option):
83        new_vars = presets[option]
84        
85        for key in new_vars.keys():
86            getattr(self, key).set(new_vars[key])
87
88    def on_apply_button(self):
89        pass
90
91
92if __name__ == "__main__":
93    root = tk.Tk()
94    app = PatcherApp(root)
95    app.run()