mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
added return value of geometry method for CTk and CTkToplevel
This commit is contained in:
parent
b3c0388958
commit
67f2072e07
@ -129,16 +129,42 @@ class CTk(tkinter.Tk):
|
|||||||
if self.current_height > height: self.current_height = height
|
if self.current_height > height: self.current_height = height
|
||||||
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
|
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
|
||||||
|
|
||||||
def geometry(self, geometry_string):
|
def geometry(self, geometry_string: str = None):
|
||||||
super().geometry(self.apply_geometry_scaling(geometry_string))
|
if geometry_string is not None:
|
||||||
|
super().geometry(self.apply_geometry_scaling(geometry_string))
|
||||||
|
|
||||||
# update width and height attributes
|
# update width and height attributes
|
||||||
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers
|
numbers = list(map(int, re.split(r"[x+-]", geometry_string))) # split geometry string into list of numbers
|
||||||
self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max
|
self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max
|
||||||
self.current_height = max(self.min_height, min(numbers[1], self.max_height))
|
self.current_height = max(self.min_height, min(numbers[1], self.max_height))
|
||||||
|
else:
|
||||||
|
return self.reverse_geometry_scaling(super().geometry())
|
||||||
|
|
||||||
def apply_geometry_scaling(self, geometry_string):
|
def apply_geometry_scaling(self, geometry_string):
|
||||||
return re.sub(re.compile("\d+"), lambda match_obj: str(round(int(match_obj.group(0)) * self.window_scaling)), geometry_string)
|
value_list = re.split(r"[x+-]", geometry_string)
|
||||||
|
separator_list = re.split(r"\d+", geometry_string)
|
||||||
|
|
||||||
|
if len(value_list) == 2:
|
||||||
|
scaled_width = str(round(int(value_list[0]) * self.window_scaling))
|
||||||
|
scaled_height = str(round(int(value_list[1]) * self.window_scaling))
|
||||||
|
return f"{scaled_width}x{scaled_height}"
|
||||||
|
elif len(value_list) == 4:
|
||||||
|
scaled_width = str(round(int(value_list[0]) * self.window_scaling))
|
||||||
|
scaled_height = str(round(int(value_list[1]) * self.window_scaling))
|
||||||
|
return f"{scaled_width}x{scaled_height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
|
||||||
|
|
||||||
|
def reverse_geometry_scaling(self, scaled_geometry_string):
|
||||||
|
value_list = re.split(r"[x+-]", scaled_geometry_string)
|
||||||
|
separator_list = re.split(r"\d+", scaled_geometry_string)
|
||||||
|
|
||||||
|
if len(value_list) == 2:
|
||||||
|
width = str(round(int(value_list[0]) / self.window_scaling))
|
||||||
|
height = str(round(int(value_list[1]) / self.window_scaling))
|
||||||
|
return f"{width}x{height}"
|
||||||
|
elif len(value_list) == 4:
|
||||||
|
width = str(round(int(value_list[0]) / self.window_scaling))
|
||||||
|
height = str(round(int(value_list[1]) / self.window_scaling))
|
||||||
|
return f"{width}x{height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
|
||||||
|
|
||||||
def apply_window_scaling(self, value):
|
def apply_window_scaling(self, value):
|
||||||
if isinstance(value, (int, float)):
|
if isinstance(value, (int, float)):
|
||||||
|
@ -84,18 +84,30 @@ class CTkToplevel(tkinter.Toplevel):
|
|||||||
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
|
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
|
||||||
|
|
||||||
def apply_geometry_scaling(self, geometry_string):
|
def apply_geometry_scaling(self, geometry_string):
|
||||||
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers
|
value_list = re.split(r"[x+-]", geometry_string)
|
||||||
|
separator_list = re.split(r"\d+", geometry_string)
|
||||||
|
|
||||||
if len(numbers) == 2:
|
if len(value_list) == 2:
|
||||||
return f"{self.apply_window_scaling(numbers[0]):.0f}x" +\
|
scaled_width = str(round(int(value_list[0]) * self.window_scaling))
|
||||||
f"{self.apply_window_scaling(numbers[1]):.0f}"
|
scaled_height = str(round(int(value_list[1]) * self.window_scaling))
|
||||||
elif len(numbers) == 4:
|
return f"{scaled_width}x{scaled_height}"
|
||||||
return f"{self.apply_window_scaling(numbers[0]):.0f}x" +\
|
elif len(value_list) == 4:
|
||||||
f"{self.apply_window_scaling(numbers[1]):.0f}+" +\
|
scaled_width = str(round(int(value_list[0]) * self.window_scaling))
|
||||||
f"{self.apply_window_scaling(numbers[2]):.0f}+" +\
|
scaled_height = str(round(int(value_list[1]) * self.window_scaling))
|
||||||
f"{self.apply_window_scaling(numbers[3]):.0f}"
|
return f"{scaled_width}x{scaled_height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
|
||||||
else:
|
|
||||||
return geometry_string
|
def reverse_geometry_scaling(self, scaled_geometry_string):
|
||||||
|
value_list = re.split(r"[x+-]", scaled_geometry_string)
|
||||||
|
separator_list = re.split(r"\d+", scaled_geometry_string)
|
||||||
|
|
||||||
|
if len(value_list) == 2:
|
||||||
|
width = str(round(int(value_list[0]) / self.window_scaling))
|
||||||
|
height = str(round(int(value_list[1]) / self.window_scaling))
|
||||||
|
return f"{width}x{height}"
|
||||||
|
elif len(value_list) == 4:
|
||||||
|
width = str(round(int(value_list[0]) / self.window_scaling))
|
||||||
|
height = str(round(int(value_list[1]) / self.window_scaling))
|
||||||
|
return f"{width}x{height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
|
||||||
|
|
||||||
def apply_window_scaling(self, value):
|
def apply_window_scaling(self, value):
|
||||||
if isinstance(value, (int, float)):
|
if isinstance(value, (int, float)):
|
||||||
@ -103,13 +115,16 @@ class CTkToplevel(tkinter.Toplevel):
|
|||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def geometry(self, geometry_string):
|
def geometry(self, geometry_string: str = None):
|
||||||
super().geometry(self.apply_geometry_scaling(geometry_string))
|
if geometry_string is not None:
|
||||||
|
super().geometry(self.apply_geometry_scaling(geometry_string))
|
||||||
|
|
||||||
# update width and height attributes
|
# update width and height attributes
|
||||||
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers
|
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers
|
||||||
self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max
|
self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max
|
||||||
self.current_height = max(self.min_height, min(numbers[1], self.max_height))
|
self.current_height = max(self.min_height, min(numbers[1], self.max_height))
|
||||||
|
else:
|
||||||
|
return self.reverse_geometry_scaling(super().geometry())
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
AppearanceModeTracker.remove(self.set_appearance_mode)
|
AppearanceModeTracker.remove(self.set_appearance_mode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user