2022-03-01 21:10:18 +03:00
|
|
|
__version__ = "2.4"
|
2021-07-13 12:23:34 +03:00
|
|
|
|
2022-03-02 02:53:58 +03:00
|
|
|
from .customtkinter_dialog import CTkDialog
|
2021-03-04 20:27:46 +03:00
|
|
|
from .customtkinter_button import CTkButton
|
|
|
|
from .customtkinter_slider import CTkSlider
|
|
|
|
from .customtkinter_frame import CTkFrame
|
|
|
|
from .customtkinter_progressbar import CTkProgressBar
|
|
|
|
from .customtkinter_label import CTkLabel
|
|
|
|
from .customtkinter_entry import CTkEntry
|
2021-08-25 18:02:16 +03:00
|
|
|
from .customtkinter_checkbox import CTkCheckBox
|
2021-12-31 21:07:53 +03:00
|
|
|
from .customtkinter_tk import CTk
|
2022-02-21 17:35:08 +03:00
|
|
|
from .customtkinter_canvas import CTkCanvas
|
|
|
|
from .customtkinter_toplevel import CTkToplevel
|
2022-02-23 01:50:03 +03:00
|
|
|
from .customtkinter_settings import CTkSettings
|
2021-03-04 20:27:46 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
from .appearance_mode_tracker import AppearanceModeTracker
|
2022-02-23 00:38:40 +03:00
|
|
|
from .customtkinter_theme_manager import CTkThemeManager
|
2021-03-04 20:27:46 +03:00
|
|
|
|
|
|
|
from distutils.version import StrictVersion as Version
|
|
|
|
import tkinter
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def enable_macos_darkmode():
|
|
|
|
if sys.platform == "darwin": # macOS
|
|
|
|
if Version(tkinter.Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
|
|
|
os.system("defaults write -g NSRequiresAquaSystemAppearance -bool No")
|
|
|
|
|
|
|
|
sys.stderr.write("WARNING (customtkinter.enable_macos_darkmode): " +
|
2021-10-11 14:28:21 +03:00
|
|
|
"This command forces macOS dark-mode on all programs. " +
|
2021-03-04 20:27:46 +03:00
|
|
|
"This can cause bugs on some other programs.\n" +
|
2021-03-06 15:47:49 +03:00
|
|
|
"Disable it by calling customtkinter.disable_macos_darkmode() at the end of the program.\n")
|
2021-03-04 20:27:46 +03:00
|
|
|
else:
|
|
|
|
sys.stderr.write("WARNING (customtkinter.enable_macos_darkmode): " +
|
|
|
|
"Currently this works only with anaconda python version (Tcl/Tk >= 8.6.9).\n" +
|
|
|
|
"(python.org Tcl/Tk version is only 8.6.8)\n")
|
|
|
|
else:
|
|
|
|
sys.stderr.write("WARNING (customtkinter.enable_macos_darkmode): " +
|
|
|
|
"System is not macOS, but the following: {}\n".format(sys.platform))
|
|
|
|
|
|
|
|
|
|
|
|
def disable_macos_darkmode():
|
|
|
|
if sys.platform == "darwin": # macOS
|
|
|
|
if Version(tkinter.Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
|
|
|
os.system("defaults delete -g NSRequiresAquaSystemAppearance")
|
|
|
|
# This command reverts the dark-mode setting for all programs.
|
|
|
|
|
|
|
|
|
|
|
|
def set_appearance_mode(mode_string):
|
|
|
|
AppearanceModeTracker.set_appearance_mode(mode_string)
|
|
|
|
|
|
|
|
|
|
|
|
def get_appearance_mode():
|
|
|
|
if AppearanceModeTracker.appearance_mode == 0:
|
|
|
|
return "Light"
|
|
|
|
elif AppearanceModeTracker.appearance_mode == 1:
|
|
|
|
return "Dark"
|
|
|
|
|
|
|
|
|
2022-01-08 02:29:53 +03:00
|
|
|
def set_default_color_theme(color_string):
|
2022-03-02 02:53:58 +03:00
|
|
|
CTkThemeManager.load_theme(color_string)
|
2022-02-21 17:35:08 +03:00
|
|
|
|
|
|
|
|
2022-02-28 02:35:52 +03:00
|
|
|
if not sys.platform == "darwin":
|
|
|
|
import warnings
|
|
|
|
warnings.simplefilter("ignore", category=UserWarning)
|
2022-02-21 17:35:08 +03:00
|
|
|
|
2022-02-28 02:35:52 +03:00
|
|
|
import pyglet.font
|
2022-02-21 17:35:08 +03:00
|
|
|
|
2022-02-28 02:35:52 +03:00
|
|
|
# load text fonts and custom font with circle shapes for round corner rendering
|
|
|
|
script_directory = os.path.dirname(os.path.abspath(__file__))
|
2022-03-02 02:53:58 +03:00
|
|
|
pyglet.font.add_file(os.path.join(script_directory, "assets", "CustomTkinter_shapes_font-fine.otf"))
|
2022-02-28 02:35:52 +03:00
|
|
|
pyglet.font.add_file(os.path.join(script_directory, "assets", "Roboto", "Roboto-Regular.ttf"))
|
|
|
|
pyglet.font.add_file(os.path.join(script_directory, "assets", "Roboto", "Roboto-Medium.ttf"))
|
|
|
|
CTkSettings.circle_font_is_ready = pyglet.font.have_font("CustomTkinter_shapes_font")
|
2022-02-21 17:48:59 +03:00
|
|
|
|
2022-02-28 02:35:52 +03:00
|
|
|
warnings.simplefilter("default")
|
2022-02-24 02:19:40 +03:00
|
|
|
|
2022-02-28 02:35:52 +03:00
|
|
|
# correct drawing method if font could not be loaded
|
|
|
|
if not CTkSettings.circle_font_is_ready:
|
|
|
|
if CTkSettings.preferred_drawing_method == "font_shapes":
|
|
|
|
sys.stderr.write("WARNING (customtkinter.CTkSettings): " +
|
2022-03-02 02:53:58 +03:00
|
|
|
"Preferred drawing method 'font_shapes' can not be used because the font file could not be loaded.\n" +
|
|
|
|
"Using 'circle_shapes' instead. The rendering quality will be very bad!")
|
2022-02-28 02:35:52 +03:00
|
|
|
CTkSettings.preferred_drawing_method = "circle_shapes"
|