Pyloid
PylonApp is an application class that extends PySide6's QApplication, providing various features for desktop application development.
Initialization
app_name is used as the key name when auto-starting and single instance mode.
Parameters
app_name
(str): Application name(used as the key name when auto-starting and single instance mode)single_instance
(bool): Activate single instance mode. Default is True.
Main Methods
Window Management
create_window
Creates a new browser window.
Parameters
title
(str): Window title. Default is "pylon app".width
(int): Window width. Default is 800.height
(int): Window height. Default is 600.x
(int): Window x coordinate. Default is 200.y
(int): Window y coordinate. Default is 200.frame
(bool): Show window frame. Default is True.context_menu
(bool): Enable context menu. Default is False.dev_tools
(bool): Enable developer tools. Default is False.js_apis
(List[PylonAPI]): List of JavaScript APIs. Default is an empty list.
Returns
BrowserWindow
: Created browser window object.
get_windows
Returns a list of all browser windows.
Returns
List[BrowserWindow]
: List of browser window objects.
show_main_window
Shows the main window.
focus_main_window
Focuses the main window.
show_and_focus_main_window
Shows and focuses the main window.
close_all_windows
Closes all windows.
quit
Quits the application.
Window Management by ID
get_window_by_id
Searches for a window by ID.
Parameters
window_id
(str): ID of the window to search for.
Returns
Optional[BrowserWindow]
: Found window object or None.
hide_window_by_id
Hides a window by ID.
Parameters
window_id
(str): ID of the window to hide.
show_window_by_id
Shows and focuses a window by ID.
Parameters
window_id
(str): ID of the window to show.
close_window_by_id
Closes a window by ID.
Parameters
window_id
(str): ID of the window to close.
toggle_fullscreen_by_id
Toggles fullscreen mode for a window by ID.
Parameters
window_id
(str): ID of the window to toggle fullscreen.
minimize_window_by_id
Minimizes a window by ID.
Parameters
window_id
(str): ID of the window to minimize.
maximize_window_by_id
Maximizes a window by ID.
Parameters
window_id
(str): ID of the window to maximize.
unmaximize_window_by_id
Unmaximizes a window by ID.
Parameters
window_id
(str): ID of the window to unmaximize.
capture_window_by_id
Captures a window by ID and saves the image.
Parameters
window_id
(str): ID of the window to capture.save_path
(str): Path to save the captured image.
Returns
Optional[str]
: Saved image file path or None (if failed).
System Tray
run_tray
Sets up the system tray icon and menu.
set_tray_actions
Sets the tray icon activation actions.
Parameters
actions
(Dict[QSystemTrayIcon.ActivationReason, Callable]): Dictionary of activation reasons and callback functions.
show_notification
Displays a system tray notification.
Parameters
title
(str): Notification title.message
(str): Notification content.
Monitor Information
get_all_monitors
Returns information for all connected monitors.
Returns
List[Monitor]
: List of Monitor objects.
get_primary_monitor
Returns information for the primary monitor.
Returns
Monitor
: Monitor object for the primary monitor.
Clipboard
set_clipboard_text
Copies text to the clipboard.
Parameters
text
(str): Text to copy.
get_clipboard_text
Retrieves text from the clipboard.
Returns
str
: Text from the clipboard.
set_clipboard_image
Copies an image to the clipboard.
Parameters
image
(Union[str, bytes, os.PathLike]): Image file path or byte data to copy.
get_clipboard_image
Retrieves an image from the clipboard.
Returns
Optional[QImage]
: Image from the clipboard or None (if no image).
Autostart
set_auto_start
Sets the application to start automatically with the system.
Parameters
enable
(bool): True to enable auto-start, False to disable.
Notes
set_auto_start(True)
only works in production environment.set_auto_start(False)
works in both production and non-production environments.In non-production environment, calling
set_auto_start(True)
will print a warning message and return None.
Returns
bool
: True if auto-start is successfully enabled, False if disabled, None if not supported in the current environment.
is_auto_start
Checks if the application is set to start automatically with the system.
Returns
bool
: True if auto-start is enabled, False otherwise.
Miscellaneous
set_icon
Sets the application icon.
Parameters
icon_path
(str): Icon file path.
set_tray_icon
Sets the tray icon.
Parameters
tray_icon_path
(str): Tray icon file path.
set_tray_menu_items
Sets the tray menu items.
Parameters
tray_menu_items
(Dict[str, Callable]): Dictionary of menu item labels and callback functions.
run
Runs the application event loop. This must be executed at the end of your script.
Last updated