Module TkZero.Platform

Get the windowing system.

Expand source code
"""
Get the windowing system.
"""

import tkinter as tk
from typing import Union


class WindowingSystem:
    """
    A bunch of variables on the possible windowing systems.
    """

    X11 = "x11"
    WIN32 = "win32"
    AQUA = "aqua"


def on_platform(
    widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]], system: str
) -> bool:
    """
    Return a bool if we are on the windowing system passed in.

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :param system: A str of "x11", "win32", or "aqua".
    :return: A bool on whether we are on the system passed in.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return widget.tk.call("tk", "windowingsystem") == system


def on_x11(widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]) -> bool:
    """
    Return whether we are on an X11 windowing system. (Usually Linux)

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :return: A bool on whether we are on an X11 windowing system.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return on_platform(widget=widget, system=WindowingSystem.X11)


def on_win32(widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]) -> bool:
    """
    Return whether we are on a win32 windowing system. (Usually Windows)

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :return: A bool on whether we are on a win32 windowing system.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return on_platform(widget=widget, system=WindowingSystem.WIN32)


def on_aqua(widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]) -> bool:
    """
    Return whether we are on an aqua windowing system. (Usually macOS)

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :return: A bool on whether we are on an aqau windowing system.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return on_platform(widget=widget, system=WindowingSystem.AQUA)

Functions

def on_aqua(widget: Union[tkinter.Widget, tkinter.Tk, tkinter.Toplevel]) ‑> bool

Return whether we are on an aqua windowing system. (Usually macOS)

:param widget: A Tkinter thing that we need to use so we can call into Tk. (Probably something like root or self) :return: A bool on whether we are on an aqau windowing system.

Expand source code
def on_aqua(widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]) -> bool:
    """
    Return whether we are on an aqua windowing system. (Usually macOS)

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :return: A bool on whether we are on an aqau windowing system.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return on_platform(widget=widget, system=WindowingSystem.AQUA)
def on_platform(widget: Union[tkinter.Widget, tkinter.Tk, tkinter.Toplevel], system: str) ‑> bool

Return a bool if we are on the windowing system passed in.

:param widget: A Tkinter thing that we need to use so we can call into Tk. (Probably something like root or self) :param system: A str of "x11", "win32", or "aqua". :return: A bool on whether we are on the system passed in.

Expand source code
def on_platform(
    widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]], system: str
) -> bool:
    """
    Return a bool if we are on the windowing system passed in.

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :param system: A str of "x11", "win32", or "aqua".
    :return: A bool on whether we are on the system passed in.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return widget.tk.call("tk", "windowingsystem") == system
def on_win32(widget: Union[tkinter.Widget, tkinter.Tk, tkinter.Toplevel]) ‑> bool

Return whether we are on a win32 windowing system. (Usually Windows)

:param widget: A Tkinter thing that we need to use so we can call into Tk. (Probably something like root or self) :return: A bool on whether we are on a win32 windowing system.

Expand source code
def on_win32(widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]) -> bool:
    """
    Return whether we are on a win32 windowing system. (Usually Windows)

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :return: A bool on whether we are on a win32 windowing system.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return on_platform(widget=widget, system=WindowingSystem.WIN32)
def on_x11(widget: Union[tkinter.Widget, tkinter.Tk, tkinter.Toplevel]) ‑> bool

Return whether we are on an X11 windowing system. (Usually Linux)

:param widget: A Tkinter thing that we need to use so we can call into Tk. (Probably something like root or self) :return: A bool on whether we are on an X11 windowing system.

Expand source code
def on_x11(widget: Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]) -> bool:
    """
    Return whether we are on an X11 windowing system. (Usually Linux)

    :param widget: A Tkinter thing that we need to use so we can call into Tk.
     (Probably something like root or self)
    :return: A bool on whether we are on an X11 windowing system.
    """
    if not isinstance(widget, (tk.Widget, tk.Tk, tk.Toplevel)):
        raise TypeError(
            f"widget is not a Union[tk.Widget, Union[tk.Tk, tk.Toplevel]]! "
            f"(type passed in: {repr(type(widget))})"
        )
    return on_platform(widget=widget, system=WindowingSystem.X11)

Classes

class WindowingSystem

A bunch of variables on the possible windowing systems.

Expand source code
class WindowingSystem:
    """
    A bunch of variables on the possible windowing systems.
    """

    X11 = "x11"
    WIN32 = "win32"
    AQUA = "aqua"

Class variables

var AQUA
var WIN32
var X11