跳转至

maliang.theme.manager

字数 324 个   代码 42 行   阅读时间 2 分钟   访问量

源代码:maliang/theme/manager.py

Support for theme

🔵_callback

function protected

1
2
3
def _callback(
    theme: str,
) -> None: ...
Callback function that is triggered when a system theme is switched. Valid only if the theme mode is set to follow system.

  • theme: theme name

🔵_process_event

function protected

1
2
3
def _process_event(
    theme: typing.Literal['light', 'dark'],
) -> None: ...
Handle registered callback functions.

  • theme: theme name

🔵apply_file_dnd

function public

1
2
3
4
5
def apply_file_dnd(
    window: tkinter.Tk,
    *,
    command: collections.abc.Callable[[str], typing.Any],
) -> None: ...
Apply file drag and drop in a widget.

  • window: the window which being customized
  • command: callback function, accept a parameter that represents the path of the file

This function is only works on Windows OS!

🔵apply_theme

function public

1
2
3
4
5
def apply_theme(
    window: tkinter.Tk,
    *,
    theme: typing.Literal['mica', 'acrylic', 'acrylic2', 'aero', 'transparent', 'optimised', 'win7', 'inverse', 'native', 'popup', 'dark', 'normal'],
) -> None: ...
Apply some Windows themes to the window.

  • window: the window which being customized
  • theme: different themes for windows

This function is only works on Windows OS! And some parameters are useless on Windows 7/10!

🔵customize_window

function public

def customize_window(
    window: tkinter.Tk,
    *,
    border_color: str | None = None,
    header_color: str | None = None,
    title_color: str | None = None,
    hide_title_bar: bool | None = None,
    hide_button: typing.Literal['all', 'maxmin', 'none'] | None = None,
    disable_minimize_button: bool | None = None,
    disable_maximize_button: bool | None = None,
    border_type: typing.Literal['rectangular', 'smallround', 'round'] | None = None,
) -> None: ...
Customize the relevant properties of the window

  • window: the window which being customized
  • border_color: border color of the window
  • header_color: header color of the window
  • title_color: title color of the window
  • hide_title_bar: Wether hide the whole title bar
  • hide_button: Wether hide part of buttons on title bar
  • disable_minimize_button: Wether disable minimize button
  • disable_maximize_button: Wether disable maximize button
  • border_type: border type of the window

This function is only works on Windows OS! And some parameters are useless on Windows 7/10!

🔵get_color_mode

function public

def get_color_mode(
) -> typing.Literal['dark', 'light']: ...
Get the color mode of the program.

🔵register_event

function public

1
2
3
4
def register_event(
    func: collections.abc.Callable[..., typing.Any],
    *args: typing.Any,
) -> None: ...
When the system accent color changes, the registered function will be called, and the parameter is a boolean value indicating whether it is currently a dark theme.

  • func: callback function
  • args: extra arguments

🔵remove_event

function public

1
2
3
def remove_event(
    func: collections.abc.Callable[..., typing.Any],
) -> None: ...
Remove a registered function.

  • func: callback function

🔵set_color_mode

function public

1
2
3
def set_color_mode(
    mode: typing.Literal['system', 'dark', 'light'] = 'system',
) -> None: ...
Set the color mode of the program

  • mode: it can be "light", "dark", and "system"

TIP:

"system" is the following system

🟣_callback_events

variable protected

_callback_events: dict = {}

🟣_color_mode

variable protected

_color_mode: str = 'system'