UI Module
New in version 0.1.2.
Classes for creating and displaying various UI elements.
Classes:
|
A class for creating and interacting with an alert dialog window. |
|
A momentary HUD window that displays a message to the user. |
|
A section header within a menu. |
|
A menu item containing an image. |
|
|
|
|
|
A class for managing and interacting with notifications. |
|
A segmented control UI element. |
|
A menu item containing a segmented control. |
|
A menu item containing a separator. |
|
A slider UI element. |
|
A menu item containing a slider. |
|
A switch UI element. |
|
A menu item containing a labelled switch. |
|
A menu item containing text. |
|
A menu item containing a URL or path. |
- class PyXA.Additions.UI.XAAlert(title: str = 'Alert!', message: str = '', buttons=['Ok', 'Cancel'], icon: XAImage | None = None)[source]
Bases:
object
A class for creating and interacting with an alert dialog window.
New in version 0.0.5.
Attributes:
A list specifying the buttons available for the user to click
The icon displayed in the alert window
The detail message text of the alert
The title text of the alert
Methods:
display
()Displays the alert.
- buttons: list[str]
A list specifying the buttons available for the user to click
- display() int [source]
Displays the alert.
- Returns:
A number representing the button that the user selected, if any
- Return type:
int
New in version 0.0.5.
- icon
The icon displayed in the alert window
- message: str
The detail message text of the alert
- title: str
The title text of the alert
- class PyXA.Additions.UI.XAHUD(message: str, font_size: int = 20, duration: float = 3.0, background_color: XAColor | None = None, text_color: XAColor | None = None)[source]
Bases:
object
A momentary HUD window that displays a message to the user.
New in version 0.1.1.
Attributes:
The background color of the HUD window
The font size of the HUD's message text
The HUD's message text
The text color of the HUD's message text
Methods:
display
()Displays the HUD in the center of the screen.
- duration: float
- font_size
The font size of the HUD’s message text
- message
The HUD’s message text
- class PyXA.Additions.UI.XAHeaderMenuItem(parent: XAMenuBarMenu, label: str)[source]
Bases:
XAMenuBarMenuItem
A section header within a menu.
New in version 0.2.0.
- class PyXA.Additions.UI.XAImageMenuItem(parent: XAMenuBarMenu, image: str | int | float | XAImage | XAURL | XAPath, tooltip: str | None = None)[source]
Bases:
XAMenuBarMenuItem
A menu item containing an image.
New in version 0.1.2.
- class PyXA.Additions.UI.XAMenuBar[source]
Bases:
object
Methods:
display
()Displays the custom menus on the menu bar.
new_menu
([content, icon, tooltip, ...])Adds a new menu to be displayed in the system menu bar.
remove_menu
(id)Removes a menu from the status bar.
Attributes:
The menus to be displayed in the status bar, keyed by ID
- display()[source]
Displays the custom menus on the menu bar.
- Example:
>>> import PyXA >>> menu_bar = PyXA.XAMenuBar() >>> menu_bar.new_menu("🔥", tooltip="Fire") >>> menu_bar.new_menu("💧", tooltip="Water") >>> menu_bar.display()
New in version 0.0.9.
The menus to be displayed in the status bar, keyed by ID
Adds a new menu to be displayed in the system menu bar.
- Parameters:
content (Union[str, int, float, XABase.XAImage, XABase.XAURL, XABase.XAPath, None], optional) – The content of the menu (the string or icon shown in the menubar), defaults to None
icon (Union[XABase.XAImage, None], optional) – The icon for the menu, defaults to None
tooltip (Union[str, None], optional) – The tooltip to display on hovering over the menu, defaults to None
icon_dimensions (tuple[int, int], optional) – The width and height of the image, in pixels, defaults to (30, 30)
action (Callable[[XAMenuBarMenu, None], None], optional) – The method, if any, to associate with the menu (the method called when the menu is opened), defaults to None
id (Union[str, None], optional) – A unique identifier for the menu, or None to use the title, defaults to None
index (int, optional) – The position to insert the menu in the list of menus, defaults to -1
label – The label for the menu item, defaults to None
- Return type:
- Example:
>>> import random >>> import threading >>> import time >>> >>> emojis = ["😀", "😍", "🙂", "😎", "🤩", "🤯", "😭", "😱", "😴", "🤒", "😈", "🤠"] >>> >>> menu_bar = PyXA.XAMenuBar() >>> emoji_bar = menu_bar.new_menu() >>> >>> def update_display(): >>> while True: >>> new_emoji = random.choice(emojis) >>> emoji_bar.title = new_emoji >>> time.sleep(0.25) >>> >>> threading.Thread(target=update_display).start() >>> menu_bar.display()
New in version 0.1.1.
Removes a menu from the status bar.
- Parameters:
id (str) – The ID of the menu to remove
New in version 0.1.1.
- class PyXA.Additions.UI.XAMenuBarMenu(content: str | int | float | XAObject, icon: XAImage | None = None, tooltip: str | None = None, icon_dimensions: tuple[int, int] = (30, 30), action: Callable[[XAMenuBarMenu, None], None] | None = None, id: str | None = None, index: int = -1)[source]
Bases:
object
Attributes:
The method to call when the menu is opened
The content of the menu.
The image associated with the menu.
The width and height of the menu's image, in pixels.
The unique identifier for the menu
The menu items, keyed by their IDs
The tooltip that appears when hovering over the menu.
Methods:
delete
()Deletes the menu.
new_header
(text[, index])new_image_item
(image[, tooltip, index])Creates a new image menu item at the specified index or the current insertion point.
new_item
([content, icon, action, args, ...])Creates a new menu item and adds it to this menu at the current insertion point.
new_segmented_control_item
(segments[, ...])Creates a new segmented control menu item at the specified index or the current insertion point.
new_separator
([id, index])Adds a separator to the menu at the current insertion point.
new_slider_item
([tooltip, action, args, index])Creates a new slider menu item at the specified index or the current insertion point.
new_switch_item
([label, tooltip, action, ...])Creates a new switch menu item at the specified index or the current insertion point.
new_url_item
(url[, label, icon, ...])Creates a new URL menu item at the specified index or the current insertion point.
remove_item
(id)Removes an item from this menu.
- action
The method to call when the menu is opened
- property content: str
The content of the menu.
- property icon_dimensions: tuple[int, int]
The width and height of the menu’s image, in pixels.
- id
The unique identifier for the menu
- items
The menu items, keyed by their IDs
- new_image_item(image: str | XAImage, tooltip: str | None = None, index: int = -1) XAImageMenuItem [source]
Creates a new image menu item at the specified index or the current insertion point.
- Parameters:
image (Union[str, XABase.XAImage]) – An image object or the path to an image file to display in the menu
tooltip (Union[str, None], optional) – The tooltip text to display when the cursor hovers over the image, defaults to None
index (int, optional) – The position to insert the separator in the list of menu items, defaults to -1
- Returns:
The newly created image menu item
- Return type:
New in version 0.1.2.
- new_item(content: str | None = None, icon: XAImage | None = None, action: Callable[[], None] | None = None, args: list[Any] | None = None, icon_dimensions: tuple[int, int] = (20, 20), id: str | None = None, index: int = -1, label: str | None = None, tooltip: str | None = None, multiselect: bool = False) XAMenuBarMenuItem [source]
Creates a new menu item and adds it to this menu at the current insertion point.
- Parameters:
content (Union[str, None], optional) – The title text of the item, defaults to None
icon (Union[XABase.XAImage, None], optional) – The image for the item, defaults to None
action (Union[Callable[[], None], None], optional) – The method to call when the item is clicked, defaults to None
args (Union[list[Any], None], optional) – The arguments to pass to the action method upon execution, defaults to None
icon_dimensions (tuple[int, int], optional) – The width and height of the image, in pixels, defaults to (20, 20)
id (Union[str, None], optional) – A unique identifier for the item, defaults to None
index (int, optional) – The position to insert the item in the list of menu items, defaults to -1
label (Union[str, None], optional) – The label to the left of the item’s content
tooltip (Union[str, None], optional) – The tooltip text for the menu item, defaults to None
multiselect (bool, optional) – Whether multiple options in a segmented control item can be selected at once, defaults to False
- Returns:
The newly created menu item object
- Return type:
- Example:
>>> import PyXA >>> menu_bar = PyXA.XAMenuBar() >>> >>> img1 = PyXA.XAColor.red().make_swatch(10, 10) >>> img2 = PyXA.XAImage("https://avatars.githubusercontent.com/u/7865925?v=4") >>> img3 = PyXA.XAImage.symbol("flame.circle") >>> >>> m1 = menu_bar.new_menu("Menu 1") >>> m1.new_item("Item 1", lambda _: print("Action 1"), [], img1, (100, 100)) >>> m1.new_item("Item 2", lambda _: print("Action 2"), [], img2, (100, 100)) >>> >>> m2 = menu_bar.new_menu("Menu 2") >>> m2.new_item("Item 1", lambda _: print("Action 3"), image=img3, icon_dimensions=(50, 50)) >>> >>> menu_bar.display()
New in version 0.1.1.
- new_segmented_control_item(segments: list[str] | list[XAImage], tooltip: str | None = None, action: Callable[[XASlider], None] | None = None, args: list[Any] | None = None, multiselect: bool = False, index: int = -1) XASegmentedControlMenuItem [source]
Creates a new segmented control menu item at the specified index or the current insertion point.
- Parameters:
segments (Union[list[str], list[XABase.XAImage]]) – The strings or images to display as button options
tooltip (Union[str, None], optional) – The tooltip to display when the cursor hovers over the segmented control, defaults to None
action (Union[Callable[[XASlider], None], None], optional) – The method to call when the user changes the state of the segmented control (when the user activates/deactivates a button), defaults to None
args (Union[list[Any], None], optional) – The arguments to pass to the action method upon execution, defaults to None
multiselect (bool optional) – Whether multiple options can be selected at a time, defaults to False
index (int, optional) – The position to insert the separator in the list of menu items, defaults to -1
- Returns:
The newly created segmented control menu item
- Return type:
New in version 0.1.2.
- new_separator(id: str | None = None, index: int = -1) XAMenuBarMenuItem [source]
Adds a separator to the menu at the current insertion point.
- Parameters:
id (Union[str, None], optional) – A unique identifier for the separator, defaults to None
index (int, optional) – The position to insert the separator in the list of menu items, defaults to -1
- Returns:
The newly created separator menu item object
- Return type:
New in version 0.1.1.
- new_slider_item(tooltip: str | None = None, action: Callable[[XASlider], None] | None = None, args: list[Any] | None = None, index: int = -1) XASliderMenuItem [source]
Creates a new slider menu item at the specified index or the current insertion point.
- Parameters:
tooltip (Union[str, None], optional) – The tooltip text to display when the cursor hovers over the item, defaults to None
action (Union[Callable[[XASlider], None], None], optional) – The method to call when the user changes the slider’s value, defaults to None
args (Union[list[Any], None], optional) – The arguments to pass to the action method upon execution, defaults to None
index (int, optional) – The position to insert the separator in the list of menu items, defaults to -1
- Returns:
The newly created slider menu item
- Return type:
New in version 0.1.2.
- new_switch_item(label: str | None = None, tooltip: str | None = None, action: Callable[[XASlider], None] | None = None, args: list[Any] | None = None, index: int = -1) XASwitchMenuItem [source]
Creates a new switch menu item at the specified index or the current insertion point.
- Parameters:
label (Union[str, None], optional) – The label text to display left of the switch, defaults to None
tooltip (Union[str, None], optional) – The tooltip text to display when the cursor hovers over the switch, defaults to None
action (Union[Callable[[XASlider], None], None], optional) – The method to call when the user changes the switch’s state, defaults to None
args (Union[list[Any], None], optional) – The arguments to pass to the action method upon execution, defaults to None
index (int, optional) – The position to insert the separator in the list of menu items, defaults to -1
- Returns:
The newly created switch menu item
- Return type:
New in version 0.1.2.
- new_url_item(url: str | XAURL | XAPath, label: str | None = None, icon: XAImage | None = None, icon_dimensions: tuple[int, int] = (20, 20), tooltip: str | None = None, action: Callable[[XAURLMenuItem], None] | None = None, args: list[Any] | None = None, index: int = -1) XAURLMenuItem [source]
Creates a new URL menu item at the specified index or the current insertion point.
- Parameters:
url (Union[str, XABase.XAURL, XABase.XAPath]) – The URL or file path that the item will link to
label (Union[str, None]) – The label for the item, or None to use the full URL as the label
icon (Union[XABase.XAImage, None], optional) – The icon to display to the left of the label, defaults to None
icon_dimensions (tuple[int, int], optional) – The dimensions of the icon, defaults to (20, 20)
tooltip (Union[str, None], optional) – The tooltip text to display when the cursor hovers over this item, defaults to None
action (Union[Callable[[XAURLMenuItem], None], None], optional) – The method to call when the user clicks this item, or None to open the URL using standard methods, defaults to None
args (Union[list[Any], None], optional) – The arguments to pass to the action method upon execution, defaults to None
index (int, optional) – The position to insert the separator in the list of menu items, defaults to -1
- Returns:
The newly created URL menu item
- Return type:
New in version 0.1.2.
- remove_item(id)[source]
Removes an item from this menu.
- Parameters:
id (str) – The ID of the item to remove
New in version 0.1.1.
- property tooltip: str
The tooltip that appears when hovering over the menu.
- class PyXA.Additions.UI.XAMenuBarMenuItem(parent: XAMenuBarMenu, content: str | int | float | XAImage | XAURL | XAPath, icon: XAImage | None = None, action: Callable[[XAMenuBarMenuItem, Any], None] | None = None, args: list[Any] | None = None, tooltip: str | None = None)[source]
Bases:
XAMenuBarMenu
Attributes:
The method to call when this menu item is clicked
The arguments to pass to the action method upon execution
The parent menu or menu item of this item
The tooltip text displayed when the cursor hovers over the menu item.
Methods:
delete
()Deletes the item.
new_item
([content, icon, action, args, ...])Creates a new menu item and places it in a submenu of this item.
remove_item
(id)Removes a subitem from this item's submenu.
- action
The method to call when this menu item is clicked
- args
The arguments to pass to the action method upon execution
- new_item(content: str | None = None, icon: XAImage | None = None, action: Callable[[], None] | None = None, args: list[Any] | None = None, icon_dimensions: tuple[int, int] = (20, 20), id: str | None = None, index: int = -1, label: str | None = None, tooltip: str | None = None, multiselect: bool = False) XAMenuBarMenuItem [source]
Creates a new menu item and places it in a submenu of this item.
This will create a new submenu as needed, or will append to the existing submenu if one is already available on this item.
- Parameters:
content (Union[str, None], optional) – The title text of the item, defaults to None
icon (Union[XABase.XAImage, None], optional) – The image for the item, defaults to None
action (Union[Callable[[], None], None], optional) – The method to call when the item is clicked, defaults to None
args (Union[list[Any], None], optional) – The arguments to pass to the action method upon execution, defaults to None
icon_dimensions (tuple[int, int], optional) – The width and height of the image, in pixels, defaults to (20, 20)
id (Union[str, None], optional) – A unique identifier for the item, defaults to None
index (int, optional) – The position to insert the item in the list of menu items, defaults to -1
label (Union[str, None], optional) – The label to the left of the item’s content
tooltip (Union[str, None], optional) – The tooltip text for the menu item, defaults to None
multiselect (bool, optional) – Controls whether one or multiple options can be selected in a segmented control menu item, defaults to False
- Returns:
The newly created menu item object
- Return type:
- Example:
>>> import PyXA >>> menu_bar = PyXA.XAMenuBar() >>> m1 = menu_bar.new_menu("Menu 1") >>> i1 = m1.new_item("Item 1") >>> i2 = i1.new_subitem("Item 1.1") >>> i3 = i2.new_subitem("Item 1.1.1") >>> i4 = i3.new_subitem("Item 1.1.1.1") >>> menu_bar.display()
New in version 0.1.2.
- parent
The parent menu or menu item of this item
- remove_item(id: str)[source]
Removes a subitem from this item’s submenu.
- Parameters:
id (str) – The ID of the subitem to remove
New in version 0.1.1.
- property tooltip: str
The tooltip text displayed when the cursor hovers over the menu item.
- class PyXA.Additions.UI.XANotification(text: str, title: str | None = None, subtitle: str | None = None, image: XAImage | None = None, sound_name: str | None = None, primary_button_title: str | None = None, show_reply_button: bool = False, click_action: Callable[[], None] | None = None, primary_action: Callable[[], None] | None = None, reply_action: Callable[[], None] | None = None, timeout: float = -1)[source]
Bases:
object
A class for managing and interacting with notifications.
New in version 0.0.9.
Attributes:
The method to run when the user clicks the notification
The content image of the notification
The method to run when the user clicks the primary action button
The method to run when the user replies to the notification.
The subtitle of the notification
The main text of the notification
The number of seconds to wait for the user to act on the notification, or -1 to wait infinitely
The title of the notification
Methods:
display
()Displays the notification.
- click_action: Callable[[XANotification], None] | None
The method to run when the user clicks the notification
- primary_action: Callable[[XANotification], None] | None
The method to run when the user clicks the primary action button
- primary_button_title: str
- reply_action: Callable[[XANotification, str], None] | None
The method to run when the user replies to the notification. Overrides the primary action and replaces the primary action button with a “Reply” button.
- subtitle: str
The subtitle of the notification
- text: str
The main text of the notification
- timeout: float
The number of seconds to wait for the user to act on the notification, or -1 to wait infinitely
- title: str
The title of the notification
- class PyXA.Additions.UI.XASegmentedControl(segments: list[str] | list[XAImage], action: Callable[[XASlider, int, Any], None] | None = None, args: list[Any] | None = None, multiselect: bool = False)[source]
Bases:
object
A segmented control UI element. Wrapper around AppKit.NSSegmentedControl functionality.
New in version 0.1.2.
Attributes:
The method to run when the value of the slider changes
The arguments to pass to the action method upon execution
The list of currently selected segments.
Methods:
run_action_
(slider, _)Runs the action method associated with the segmented control.
- action
The method to run when the value of the slider changes
- args
The arguments to pass to the action method upon execution
- class PyXA.Additions.UI.XASegmentedControlMenuItem(parent: XAMenuBarMenu, segments: list[str] | list[XAImage], tooltip: str | None = None, action: Callable[[XASlider, Any], None] | None = None, args: list[Any] | None = None, multiselect: bool = False)[source]
Bases:
XAMenuBarMenuItem
A menu item containing a segmented control.
New in version 0.1.2.
- class PyXA.Additions.UI.XASeparatorMenuItem(parent: XAMenuBarMenu)[source]
Bases:
XAMenuBarMenuItem
A menu item containing a separator.
New in version 0.1.2.
- class PyXA.Additions.UI.XASlider(action: Callable[[XASlider, int, Any], None] | None = None, args: list[Any] | None = None, value: float = 50.0, min_value: float = 0, max_value: float = 100)[source]
Bases:
object
A slider UI element. Wrapper around AppKit.NSSlider functionality.
New in version 0.1.2.
Attributes:
The method to run when the value of the slider changes
The arguments to pass to the action method upon execution
The maximum value that the slider can be set to.
The minimum value that the slider can be set to.
The current value of the slider.
Methods:
run_action_
(slider, _)Runs the action method associated with the slider.
- action
The method to run when the value of the slider changes
- args
The arguments to pass to the action method upon execution
- property max_value: float
The maximum value that the slider can be set to.
- property min_value: float
The minimum value that the slider can be set to.
- run_action_(slider, _)[source]
Runs the action method associated with the slider.
New in version 0.1.2.
- property value: float
The current value of the slider.
- class PyXA.Additions.UI.XASliderMenuItem(parent: XAMenuBarMenu, tooltip: str | None = None, action: Callable[[XASlider, Any], None] | None = None, args: list[Any] | None = None, value: float = 50, min_value: float = 0, max_value: float = 100)[source]
Bases:
XAMenuBarMenuItem
A menu item containing a slider.
New in version 0.1.2.
Attributes:
- property value: float
- class PyXA.Additions.UI.XASwitch(action: Callable[[XASwitch, int, Any], None] | None = None, args: list[Any] | None = None)[source]
Bases:
object
A switch UI element. Wrapper around AppKit.NSSwitch functionality.
New in version 0.1.2.
Attributes:
The method to run when the switch's state changes
The arguments to pass to the action method upon execution
The current state of the switch.
Methods:
run_action_
(slider, _)Runs the action method attached to the switch.
toggle
()Toggles the switch on or off.
- action
The method to run when the switch’s state changes
- args
The arguments to pass to the action method upon execution
- run_action_(slider, _)[source]
Runs the action method attached to the switch.
- Parameters:
switch (AppKit.NSSwitch) – The NSSwitch object associated with this object
New in version 0.1.2.
- property state: bool
The current state of the switch.
- class PyXA.Additions.UI.XASwitchMenuItem(parent: XAMenuBarMenu, label: str | None = None, tooltip: str | None = None, action: Callable[[XASwitch, int, Any], None] | None = None, args: list[Any] | None = None)[source]
Bases:
XAMenuBarMenuItem
A menu item containing a labelled switch.
New in version 0.1.2.
Attributes:
The label for this switch menu item.
- property label: str
The label for this switch menu item.
- class PyXA.Additions.UI.XATextMenuItem(parent: XAMenuBarMenu, text: str, icon: XAImage | None = None, icon_dimensions: tuple[int, int] = (20, 20), tooltip: str | None = None, action: Callable[[XAURLMenuItem, int, Any], None] | None = None, args: list[Any] | None = None)[source]
Bases:
XAMenuBarMenuItem
A menu item containing text.
New in version 0.1.2.
Attributes:
Whether the menu item is enabled (vs.
The image associated with the menu item.
The width and height of the menu item's image, in pixels.
The level of indentation of the menu item, from 0 to 15.
Methods:
new_subitem
([content, icon, action, args, ...])Creates a new menu item and places it in a submenu of this item.
remove_subitem
(id)Removes a subitem from this item's submenu.
- property enabled: int
Whether the menu item is enabled (vs. appearing grayed out).
- property icon_dimensions: tuple[int, int]
The width and height of the menu item’s image, in pixels.
- property indent: int
The level of indentation of the menu item, from 0 to 15.
- new_subitem(content: str | None = None, icon: XAImage | None = None, action: Callable[[], None] | None = None, args: list[Any] | None = None, icon_dimensions: tuple[int, int] = (20, 20), id: str | None = None, index: int = -1, label: str | None = None, tooltip: str | None = None) XAMenuBarMenuItem [source]
Creates a new menu item and places it in a submenu of this item.
This will create a new submenu as needed, or will append to the existing submenu if one is already available on this item.
- Parameters:
content (Union[str, None], optional) – The title text of the item, defaults to None
icon (Union[XABase.XAImage, None], optional) – The image for the item, defaults to None
action (Union[Callable[[], None], None], optional) – The method to call when the item is clicked, defaults to None
args (Union[list[Any], None], optional) – The arguments to pass to the action method upon execution, defaults to None
icon_dimensions (tuple[int, int], optional) – The width and height of the image, in pixels, defaults to (20, 20)
id (Union[str, None], optional) – A unique identifier for the item, defaults to None
index (int, optional) – The position to insert the item in the list of menu items, defaults to -1
label (Union[str, None], optional) – The label to the left of the item’s content
tooltip (Union[str, None], optional) – The tooltip text for the menu item, defaults to None
- Returns:
The newly created menu item object
- Return type:
- Example:
>>> import PyXA >>> menu_bar = PyXA.XAMenuBar() >>> m1 = menu_bar.new_menu("Menu 1") >>> i1 = m1.new_item("Item 1") >>> i2 = i1.new_subitem("Item 1.1") >>> i3 = i2.new_subitem("Item 1.1.1") >>> i4 = i3.new_subitem("Item 1.1.1.1") >>> menu_bar.display()
New in version 0.1.1.
- remove_subitem(id: str)[source]
Removes a subitem from this item’s submenu.
- Parameters:
id (str) – The ID of the subitem to remove
New in version 0.1.1.
- property text: str
- class PyXA.Additions.UI.XAURLMenuItem(parent: XAMenuBarMenu, url: XAURL | XAPath, label: str | None = None, icon: XAImage | None = None, icon_dimensions: tuple[int, int] = (20, 20), tooltip: str | None = None, action: Callable[[XAURLMenuItem, int, Any], None] | None = None, args: list[Any] | None = None)[source]
Bases:
XATextMenuItem
A menu item containing a URL or path.
New in version 0.1.2.
Attributes:
The URL or path that the menu item refers to.
- property label: str