Merge remote-tracking branch 'origin/master'

# Conflicts:
#	test/manual_integration_tests/test_new_menu_design.py
This commit is contained in:
Tom Schimansky 2022-05-25 18:38:49 +02:00
commit fd8135129c
3 changed files with 37 additions and 14 deletions

View File

@ -162,10 +162,11 @@ class ScalingTracker:
def check_dpi_scaling(cls):
# check for every window if scaling value changed
for window in cls.window_widgets_dict:
current_dpi_scaling_value = cls.get_window_dpi_scaling(window)
if current_dpi_scaling_value != cls.window_dpi_scaling_dict[window]:
cls.window_dpi_scaling_dict[window] = current_dpi_scaling_value
cls.update_scaling_callbacks_for_window(window)
if window.winfo_exists():
current_dpi_scaling_value = cls.get_window_dpi_scaling(window)
if current_dpi_scaling_value != cls.window_dpi_scaling_dict[window]:
cls.window_dpi_scaling_dict[window] = current_dpi_scaling_value
cls.update_scaling_callbacks_for_window(window)
# find an existing tkinter object for the next call of .after()
for app in cls.window_widgets_dict.keys():

View File

@ -13,6 +13,7 @@ class CTkFrame(CTkBaseClass):
corner_radius="default_theme",
width=200,
height=200,
overwrite_preferred_drawing_method: str = None,
**kwargs):
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
@ -21,6 +22,7 @@ class CTkFrame(CTkBaseClass):
# color
self.border_color = ThemeManager.theme["color"]["frame_border"] if border_color == "default_theme" else border_color
# determine fg_color of frame
if fg_color == "default_theme":
if isinstance(self.master, CTkFrame):
if self.master.fg_color == ThemeManager.theme["color"]["frame_low"]:
@ -43,6 +45,7 @@ class CTkFrame(CTkBaseClass):
self.canvas.place(x=0, y=0, relwidth=1, relheight=1)
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self.appearance_mode))
self.draw_engine = DrawEngine(self.canvas)
self._overwrite_preferred_drawing_method = overwrite_preferred_drawing_method
self.bind('<Configure>', self.update_dimensions_event)
@ -77,7 +80,8 @@ class CTkFrame(CTkBaseClass):
requires_recoloring = self.draw_engine.draw_rounded_rect_with_border(self.apply_widget_scaling(self.current_width),
self.apply_widget_scaling(self.current_height),
self.apply_widget_scaling(self.corner_radius),
self.apply_widget_scaling(self.border_width))
self.apply_widget_scaling(self.border_width),
overwrite_preferred_drawing_method=self._overwrite_preferred_drawing_method)
if no_color_updates is False or requires_recoloring:
if self.fg_color is None:

View File

@ -1,5 +1,6 @@
import customtkinter
import tkinter
import sys
class CTkMenu(tkinter.Toplevel):
@ -7,14 +8,25 @@ class CTkMenu(tkinter.Toplevel):
super().__init__()
self.overrideredirect(True)
self.overrideredirect(False)
self.wm_attributes("-transparent", True) # turn off shadow
self.config(bg='systemTransparent') # transparent bg
self.geometry(f"120x{len(options) * (25 + 3) + 3}+{x}+{y}")
self.bind("<FocusOut>", self.focus_loss_event)
self.focus_force()
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740")
if sys.platform.startswith("darwin"):
self.overrideredirect(False)
self.wm_attributes("-transparent", True) # turn off shadow
self.config(bg='systemTransparent') # transparent bg
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740")
elif sys.platform.startswith("win"):
self.configure(bg="#FFFFF1")
self.wm_attributes("-transparent", "#FFFFF1")
self.focus()
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
overwrite_preferred_drawing_method="circle_shapes")
else:
self.configure(bg="#FFFFF1")
self.wm_attributes("-transparent", "#FFFFF1")
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
overwrite_preferred_drawing_method="circle_shapes")
self.frame.grid(row=0, column=0, sticky="nsew", rowspan=len(options) + 1, columnspan=1, ipadx=0, ipady=0)
self.frame.grid_rowconfigure(len(options) + 1, minsize=3)
@ -29,14 +41,18 @@ class CTkMenu(tkinter.Toplevel):
button.grid(row=index, column=0, padx=(3, 3), pady=(3, 0), columnspan=1, rowspan=1, sticky="ew")
self.buttons.append(button)
self.bind("<FocusOut>", self.focus_loss_event)
self.frame.canvas.bind("<Button-1>", self.focus_loss_event)
def focus_loss_event(self, event):
print("focus loss")
self.destroy()
self.update()
# self.update()
def button_click(self):
print("button press")
self.destroy()
self.update()
# self.update()
app = customtkinter.CTk()
@ -46,8 +62,10 @@ app.geometry("600x500")
def open_menu():
menu = CTkMenu(app, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])
button = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
button.pack(pady=20)
button_2 = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
button_2.pack(pady=60)
app.mainloop()