pysnt.gui_utils module#
GUI utilities for PySNT to handle threading and platform-specific issues.
- safe_gui_call(func: Callable, *args, fallback_func: Callable | None = None, **kwargs) Any[source]#
Safely call a GUI function with proper thread handling.
This function helps avoid the common macOS threading issue where Qt/GUI applications must be created on the main thread.
- Parameters:
func (callable) – The GUI function to call
*args – Arguments to pass to the function
fallback_func (callable, optional) – Fallback function to call if GUI function fails
**kwargs – Keyword arguments to pass to the function
- Returns:
Result of the function call, or None if failed
- Return type:
Any
Examples
>>> def show_gui(): ... # Some GUI code that might fail on macOS ... return pandasgui.show(df) >>> >>> def fallback(): ... print("GUI failed, showing in console") ... print(df) >>> >>> safe_gui_call(show_gui, fallback_func=fallback)
- configure_gui_safety(enabled: bool = True) None[source]#
Configure GUI safety mode.
When enabled, GUI operations that might cause threading issues on macOS will fall back to console-based alternatives.
- Parameters:
enabled (bool, default True) – Whether to enable GUI safety mode
Examples
>>> # Disable GUI safety to try GUI operations anyway >>> pysnt.configure_gui_safety(False) >>> >>> # Re-enable for safety >>> pysnt.configure_gui_safety(True)
- main_thread_wrapper(func: Callable) Callable[source]#
Decorator to ensure a function runs in the main thread.
This is useful for GUI functions that must run in the main thread. Note: This is a simple implementation and may not work in all cases.
- Parameters:
func (callable) – Function to wrap
- Returns:
Wrapped function
- Return type:
callable
Examples
>>> @main_thread_wrapper ... def show_gui(): ... return pandasgui.show(df)