2022-09-17 14:41:58 +03:00
|
|
|
__version__ = "4.6.3"
|
2021-07-13 12:23:34 +03:00
|
|
|
|
2022-05-17 22:44:59 +03:00
|
|
|
import os
|
|
|
|
import sys
|
2022-11-11 15:06:26 +03:00
|
|
|
from tkinter import Variable, StringVar, IntVar, DoubleVar, BooleanVar
|
|
|
|
from tkinter.constants import *
|
2022-11-12 16:01:54 +03:00
|
|
|
import tkinter.filedialog as filedialog
|
2022-11-11 15:06:26 +03:00
|
|
|
|
2022-11-12 16:01:54 +03:00
|
|
|
_ = Variable, StringVar, IntVar, DoubleVar, BooleanVar, CENTER, filedialog # prevent IDE from removing unused imports
|
2022-05-17 22:44:59 +03:00
|
|
|
|
|
|
|
# import manager classes
|
2022-10-29 14:11:55 +03:00
|
|
|
from .windows.widgets.appearance_mode.appearance_mode_tracker import AppearanceModeTracker
|
|
|
|
from .windows.widgets.font.font_manager import FontManager
|
|
|
|
from .windows.widgets.scaling.scaling_tracker import ScalingTracker
|
|
|
|
from .windows.widgets.theme.theme_manager import ThemeManager
|
|
|
|
from .windows.widgets.core_rendering.draw_engine import DrawEngine
|
2022-05-17 22:44:59 +03:00
|
|
|
|
|
|
|
AppearanceModeTracker.init_appearance_mode()
|
2022-06-21 00:44:35 +03:00
|
|
|
|
|
|
|
# load default blue theme
|
|
|
|
try:
|
|
|
|
ThemeManager.load_theme("blue")
|
|
|
|
except FileNotFoundError as err:
|
|
|
|
raise FileNotFoundError(f"{err}\n\nThe .json theme file for CustomTkinter could not be found.\n" +
|
|
|
|
f"If packaging with pyinstaller was used, have a look at the wiki:\n" +
|
|
|
|
f"https://github.com/TomSchimansky/CustomTkinter/wiki/Packaging#windows-pyinstaller-auto-py-to-exe")
|
|
|
|
|
2022-05-17 22:44:59 +03:00
|
|
|
FontManager.init_font_manager()
|
|
|
|
|
2022-05-22 01:02:45 +03:00
|
|
|
# determine draw method based on current platform
|
|
|
|
if sys.platform == "darwin":
|
|
|
|
DrawEngine.preferred_drawing_method = "polygon_shapes"
|
|
|
|
else:
|
|
|
|
DrawEngine.preferred_drawing_method = "font_shapes"
|
|
|
|
|
2022-05-26 20:16:01 +03:00
|
|
|
if sys.platform.startswith("win") and sys.getwindowsversion().build < 9000: # No automatic scaling on Windows < 8.1
|
|
|
|
ScalingTracker.deactivate_automatic_dpi_awareness = True
|
|
|
|
|
2022-05-22 02:55:58 +03:00
|
|
|
# load Roboto fonts (used on Windows/Linux)
|
2022-05-17 22:44:59 +03:00
|
|
|
script_directory = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf"))
|
|
|
|
FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf"))
|
|
|
|
|
2022-05-22 02:55:58 +03:00
|
|
|
# load font necessary for rendering the widgets (used on Windows/Linux)
|
2022-05-30 16:35:23 +03:00
|
|
|
if FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "CustomTkinter_shapes_font.otf")) is False:
|
2022-05-22 02:55:58 +03:00
|
|
|
# change draw method if font loading failed
|
2022-05-22 01:02:45 +03:00
|
|
|
if DrawEngine.preferred_drawing_method == "font_shapes":
|
2022-05-17 22:44:59 +03:00
|
|
|
sys.stderr.write("customtkinter.__init__ warning: " +
|
|
|
|
"Preferred drawing method 'font_shapes' can not be used because the font file could not be loaded.\n" +
|
2022-10-23 23:33:57 +03:00
|
|
|
"Using 'circle_shapes' instead. The rendering quality will be bad!\n")
|
2022-05-22 01:02:45 +03:00
|
|
|
DrawEngine.preferred_drawing_method = "circle_shapes"
|
2022-05-17 22:44:59 +03:00
|
|
|
|
2022-05-16 17:51:19 +03:00
|
|
|
# import widgets
|
2022-10-29 14:11:55 +03:00
|
|
|
from .windows.widgets.ctk_button import CTkButton
|
|
|
|
from .windows.widgets.ctk_checkbox import CTkCheckBox
|
|
|
|
from .windows.widgets.ctk_combobox import CTkComboBox
|
|
|
|
from .windows.widgets.ctk_entry import CTkEntry
|
|
|
|
from .windows.widgets.ctk_frame import CTkFrame
|
|
|
|
from .windows.widgets.ctk_label import CTkLabel
|
|
|
|
from .windows.widgets.ctk_optionmenu import CTkOptionMenu
|
|
|
|
from .windows.widgets.ctk_progressbar import CTkProgressBar
|
|
|
|
from .windows.widgets.ctk_radiobutton import CTkRadioButton
|
|
|
|
from .windows.widgets.ctk_scrollbar import CTkScrollbar
|
|
|
|
from .windows.widgets.ctk_segmented_button import CTkSegmentedButton
|
|
|
|
from .windows.widgets.ctk_slider import CTkSlider
|
|
|
|
from .windows.widgets.ctk_switch import CTkSwitch
|
|
|
|
from .windows.widgets.ctk_tabview import CTkTabview
|
|
|
|
from .windows.widgets.ctk_textbox import CTkTextbox
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-05-16 17:51:19 +03:00
|
|
|
# import windows
|
2022-05-02 00:29:14 +03:00
|
|
|
from .windows.ctk_tk import CTk
|
|
|
|
from .windows.ctk_toplevel import CTkToplevel
|
|
|
|
from .windows.ctk_input_dialog import CTkInputDialog
|
2021-03-04 20:27:46 +03:00
|
|
|
|
2022-10-29 01:42:33 +03:00
|
|
|
# font classes
|
2022-10-29 14:11:55 +03:00
|
|
|
from .windows.widgets.font.ctk_font import CTkFont
|
2022-10-16 21:13:19 +03:00
|
|
|
|
2022-11-01 02:37:30 +03:00
|
|
|
# image classes
|
|
|
|
from .windows.widgets.image.ctk_image import CTkImage
|
|
|
|
|
2021-03-04 20:27:46 +03:00
|
|
|
|
2022-05-22 02:55:58 +03:00
|
|
|
def set_appearance_mode(mode_string: str):
|
|
|
|
""" possible values: light, dark, system """
|
2021-03-04 20:27:46 +03:00
|
|
|
AppearanceModeTracker.set_appearance_mode(mode_string)
|
|
|
|
|
|
|
|
|
2022-05-22 02:55:58 +03:00
|
|
|
def get_appearance_mode() -> str:
|
|
|
|
""" get current state of the appearance mode (light or dark) """
|
2021-03-04 20:27:46 +03:00
|
|
|
if AppearanceModeTracker.appearance_mode == 0:
|
|
|
|
return "Light"
|
|
|
|
elif AppearanceModeTracker.appearance_mode == 1:
|
|
|
|
return "Dark"
|
|
|
|
|
|
|
|
|
2022-05-22 02:55:58 +03:00
|
|
|
def set_default_color_theme(color_string: str):
|
|
|
|
""" set color theme or load custom theme file by passing the path """
|
2022-05-17 22:44:59 +03:00
|
|
|
ThemeManager.load_theme(color_string)
|
2022-02-21 17:35:08 +03:00
|
|
|
|
|
|
|
|
2022-05-22 02:55:58 +03:00
|
|
|
def set_widget_scaling(scaling_value: float):
|
|
|
|
""" set scaling for the widget dimensions """
|
2022-05-05 21:25:37 +03:00
|
|
|
ScalingTracker.set_widget_scaling(scaling_value)
|
2022-05-22 01:02:45 +03:00
|
|
|
|
|
|
|
|
2022-05-22 02:55:58 +03:00
|
|
|
def set_window_scaling(scaling_value: float):
|
|
|
|
""" set scaling for window dimensions """
|
|
|
|
ScalingTracker.set_window_scaling(scaling_value)
|
|
|
|
|
|
|
|
|
2022-05-22 01:02:45 +03:00
|
|
|
def deactivate_automatic_dpi_awareness():
|
2022-05-22 02:55:58 +03:00
|
|
|
""" deactivate DPI awareness of current process (windll.shcore.SetProcessDpiAwareness(0)) """
|
2022-05-22 01:02:45 +03:00
|
|
|
ScalingTracker.deactivate_automatic_dpi_awareness = False
|