This repository was archived by the owner on Jan 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEndlessPixelAppui.py
More file actions
72 lines (65 loc) · 2.11 KB
/
EndlessPixelAppui.py
File metadata and controls
72 lines (65 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
import pathlib
import tkinter as tk
import tkinter.ttk as ttk
import pygubu
class EndlessPixelAppUI:
def __init__(
self,
master=None,
*,
project_ui,
resource_paths=None,
translator=None,
on_first_object_cb=None,
data_pool=None,
):
self.builder = pygubu.Builder(
translator=translator,
on_first_object=on_first_object_cb,
data_pool=data_pool
)
self.builder.add_from_file(project_ui)
if resource_paths is not None:
self.builder.add_resource_paths(resource_paths)
# Main widget
self.mainwindow: tk.Toplevel = self.builder.get_object("game", master)
def center_window(self):
if self.mainwindow.winfo_ismapped():
min_w, min_h = self.mainwindow.wm_minsize()
max_w, max_h = self.mainwindow.wm_maxsize()
screen_w = self.mainwindow.winfo_screenwidth()
screen_h = self.mainwindow.winfo_screenheight()
final_w = min(
screen_w,
max_w,
max(
min_w,
self.mainwindow.winfo_width(),
self.mainwindow.winfo_reqwidth(),
),
)
final_h = min(
screen_h,
max_h,
max(
min_h,
self.mainwindow.winfo_height(),
self.mainwindow.winfo_reqheight(),
),
)
x = (screen_w // 2) - (final_w // 2)
y = (screen_h // 2) - (final_h // 2)
geometry = f"{final_w}x{final_h}+{x}+{y}"
def set_geometry():
self.mainwindow.geometry(geometry)
self.mainwindow.after_idle(set_geometry)
else:
# Window is not mapped, wait and try again later.
self.mainwindow.after(5, self.center_window)
def run(self, center=False):
if center:
self.center_window()
self.mainwindow.mainloop()
def callback(self, event=None):
pass