pydui.core package¶
Submodules¶
pydui.core.appearance_manager module¶
pydui.core.application module¶
PyDuiApplication module
Example:
PyDuiApplication.main_run()
pydui.core.builder module¶
PyDuiBuilder module
PyDuiBuilder provider construct Widget from xml resource. The resource xml file read from local path by default. But you can custom the resource provider to compose the ui resources.
Example:
PyDuiBuilder.build_window(path='res/main.xml')
- class pydui.core.builder.PyDuiBuilder¶
Bases:
object
Build Widget, Window from xml resource
- build_widget(path: str) PyDuiWidget ¶
Build widget from path
- Parameters:
path (str) – xml resource path
- Returns:
return the widget
- Return type:
- build_window(path: str, handler: Type[PyDuiWindowHandler]) PyDuiWindow ¶
Build window from path and handler
- Parameters:
path (str) – xml resource path
handler (Type[PyDuiWindowHandler]) – handler class
- Returns:
return window object.
- Return type:
- get_loader() PyDuiResourceLoader ¶
- register_resource_loader(loader: PyDuiResourceLoader)¶
pydui.core.event module¶
- class pydui.core.event.ButtonEvent(x: int, y: int, button: pydui.core.event.ButtonType, event: pydui.core.event.ButtonEventType, time: int)¶
Bases:
EventObject
- button: ButtonType¶
- event: ButtonEventType¶
- time: int¶
- x: int¶
- y: int¶
- class pydui.core.event.ButtonEventType(value)¶
Bases:
Enum
An enumeration.
- DBPRESS = 2¶
- PRESS = 1¶
- RELEASE = 4¶
- TRIPRESS = 3¶
- UNDEFINED = 0¶
- class pydui.core.event.ButtonType(value)¶
Bases:
Enum
An enumeration.
- BUTTON_LEFT = 1¶
- BUTTON_RIGHT = 2¶
- UNDEFINED = 0¶
- class pydui.core.event.EventObject¶
Bases:
object
- class pydui.core.event.NCAreaType(value)¶
Bases:
Enum
An enumeration.
- BOTTOM = 5¶
- CAPTION = 1¶
- CLIENT = 10¶
- LEFT = 2¶
- LEFT_BOTTOM = 8¶
- LEFT_TOP = 6¶
- RIGHT = 4¶
- RIGHT_BOTTOM = 9¶
- RIGHT_TOP = 7¶
- TOP = 3¶
- UNDEFINED = 0¶
- class pydui.core.event.ScrollDirection(value)¶
Bases:
Enum
An enumeration.
- DOWN = 1¶
- LEFT = 2¶
- RIGHT = 3¶
- SMOOTH = 4¶
- UP = 0¶
- class pydui.core.event.ScrollEvent(x: int, y: int, delta_x: float, delta_y: float, direction: pydui.core.event.ScrollDirection, time: int)¶
Bases:
EventObject
- delta_x: float¶
- delta_y: float¶
- direction: ScrollDirection¶
- time: int¶
- x: int¶
- y: int¶
pydui.core.layout module¶
- class pydui.core.layout.PyDuiLayout¶
Bases:
PyDuiWidget
Layout base class, all layouts inherit from PyDuiLayout
- add_child(child: PyDuiWidget)¶
Add child widget.
if child has been added, ignore.
- Parameters:
child (PyDuiWidget) – child widget
- add_child_at(child: PyDuiWidget, index: int)¶
Add child widget at index
if the index overbound, it will add widget to last position.
- Parameters:
child (PyDuiWidget) – child widget
index (int) – target index
- Returns:
return widget object.
- Return type:
- property child_count: int¶
- find_widget_by_pos(x: float, y: float, *, filter: ~typing.Callable[[~pydui.core.widget.PyDuiWidget], bool] = <function PyDuiWidget.find_widget_default_filter>) Optional[PyDuiWidget] ¶
Get child by position
- property fitrule: List[str]¶
- get_child(widget_id: str) Optional[PyDuiWidget] ¶
Get child widget by widget_id
- Parameters:
widget_id (str) – widget id
- Returns:
return widget object.
- Return type:
- get_child_at(index: int) Optional[PyDuiWidget] ¶
Get child widget at index
if the index overbound, it will return None.
- Parameters:
index (int) – child index
- Returns:
return widget object.
- Return type:
- get_children_range_fixed_height(start: int, stop: int) float ¶
- get_children_range_fixed_width(start: int, stop: int) float ¶
- property halign: PyDuiAlign¶
- layout(x: float, y: float, width: float, height: float, constraint: PyDuiLayoutConstraint)¶
- Parameters:
x (float) – x offset relative to parent
y (float) – y offset relative to parent
width (float) – widget width
height (float) – widget height
constraint (PyDuiLayoutConstraint) – layout constraint
- parse_attrib(k: str, v: str) None ¶
Parse single attribute
- Parameters:
attrib (Dict[str, str]) – attributes dict key=value …
- remove_child(child: PyDuiWidget)¶
Remove child widget.
- Parameters:
widget (PyDuiWidget) – widget object
- remove_child_at(index: int)¶
Remove child widget at index
if the index overbound, do nothing.
- Parameters:
index (int) – widget index
- remove_child_by_id(widget_id: str)¶
Remove child widget by widget_id
- Parameters:
widget_id (str) – widget id
- property valign: PyDuiAlign¶
pydui.core.render module¶
- class pydui.core.render.PyDuiRender¶
Bases:
object
Render static function
- static DrawImage(ctx: ~cairo.Context, loader: ~pydui.core.resource_loader.PyDuiResourceLoader, path: str, xy: ~typing.Tuple[float, float], wh: ~typing.Tuple[float, float], corner: ~pydui.common.base.PyDuiEdge = <pydui.common.base.PyDuiEdge object>)¶
- static DrawText(ctx: ~cairo.Context, *, text: str, font: str, font_size: int, color: ~gi.overrides.Gdk.RGBA, xy: ~typing.Tuple[float, float], wh: ~typing.Tuple[float, float], hvalign: ~typing.Tuple[~pydui.common.base.PyDuiAlign, ~pydui.common.base.PyDuiAlign] = (<PyDuiAlign.CENTER: 0>, <PyDuiAlign.CENTER: 0>), ellipsis_mode: ~gi.repository.Pango.EllipsizeMode = <enum PANGO_ELLIPSIZE_END of type Pango.EllipsizeMode>, wrap_mode: ~gi.repository.Pango.WrapMode = <enum PANGO_WRAP_WORD of type Pango.WrapMode>, line_spacing: float = 1.25)¶
- static EstimateImageSize(loader: PyDuiResourceLoader, path: str, limit_width: float, limit_height: float) Tuple[float, float] ¶
- static EstimateTextSize(ctx: ~cairo.Context, *, text: str, font: str, fontsize: int, limit_wh: ~typing.Tuple[float, float] = (-1, -1), hvalign: ~typing.Tuple[~pydui.common.base.PyDuiAlign, ~pydui.common.base.PyDuiAlign] = (<PyDuiAlign.CENTER: 0>, <PyDuiAlign.CENTER: 0>), ellipsis_mode: ~gi.repository.Pango.EllipsizeMode = <enum PANGO_ELLIPSIZE_END of type Pango.EllipsizeMode>, wrap_mode: ~gi.repository.Pango.WrapMode = <enum PANGO_WRAP_WORD of type Pango.WrapMode>, line_spacing: float = 1.25) Tuple[float, float] ¶
Estimate text size
- static Rectangle(ctx: Context, color: RGBA, x: float, y: float, w: float, h: float)¶
pydui.core.render_canvas module¶
pydui.core.resource_loader module¶
Resource Loader Module
- class pydui.core.resource_loader.PyDuiResourceLoader¶
Bases:
ABC
- abstract load_data(path: str) bytes ¶
Load data
- abstract load_image(path: str) Tuple[bytes, float] ¶
Load image buffer with hi-dpi suppose
- abstract load_string(sid: str) str ¶
Load intl language text by text id
- abstract load_xml(path: str) str ¶
Load xml layout file
- abstract scheme() str ¶
Return loader scheme
- pydui.core.resource_loader.create_default_resource_loader() PyDuiResourceLoader ¶
pydui.core.screen module¶
pydui.core.widget module¶
- class pydui.core.widget.LazyStr(fn: Callable[[...], str])¶
Bases:
object
- class pydui.core.widget.PyDuiConstraint(min_width: float = 0, max_width: float = 9223372036854775807, min_height: float = 0, max_height: float = 9223372036854775807)¶
Bases:
object
Constraint dataclass
- max_height: float = 9223372036854775807¶
- max_width: float = 9223372036854775807¶
- min_height: float = 0¶
- min_width: float = 0¶
- class pydui.core.widget.PyDuiObject¶
Bases:
object
- class pydui.core.widget.PyDuiWidget¶
Bases:
PyDuiObject
Widget base class
- property autofit: bool¶
- bind_event(event_name: str, callback: Callable[[...], bool])¶
- property bkcolor: Optional[RGBA]¶
- property bkimage: str¶
- static build_name() str ¶
- property can_focus: bool¶
- connect(signal_name: str, callback: Callable[[...], bool])¶
- property constraint: PyDuiConstraint¶
- contain_pos(x: float, y: float) bool ¶
- disconnect(signal_name: str, callback: Callable[[...], bool])¶
- disconnect_signal(signal_name: str)¶
- do_bind_event(event_name: str, *args: Any, **kwargs: Any) bool ¶
- emit(signal_name: str, *args: Any, **kwargs: Any)¶
- property enable_mouse_event: bool¶
- property enable_mouse_wheel_event: bool¶
- property enabled: bool¶
- estimate_size(parent_width: float, parent_height: float, constraint: PyDuiLayoutConstraint) Tuple[float, float] ¶
- static find_widget_default_filter(widget: PyDuiWidget) bool ¶
- static find_widget_mouse_event_filter(widget: PyDuiWidget) bool ¶
- static find_widget_mouse_wheel_event_filter(widget: PyDuiWidget) bool ¶
- property fixed_height: float¶
- property fixed_size: Tuple[float, float]¶
- property fixed_width: float¶
- property fixed_x: float¶
- property fixed_xy: Tuple[float, float]¶
- property fixed_y: float¶
- get_bindevents() List[str] ¶
- get_id() str ¶
Return widget id
- Returns:
widget id
- Return type:
str
- get_signals() List[str] ¶
- get_window_client() PyDuiWindowClientInterface ¶
Get the widget window client
The widget will setup window client after call do_post_init. before the widget init finish, window client will be empty.
- has_window_client() bool ¶
- property height: float¶
- property is_float: bool¶
- property is_focused: bool¶
- layout(x: float, y: float, width: float, height: float, constraint: PyDuiLayoutConstraint)¶
- on_lbutton_click(x: float, y: float) None ¶
- on_lbutton_dbclick(x: float, y: float) None ¶
- on_lbutton_press(x: float, y: float) bool ¶
- on_lbutton_release(x: float, y: float) bool ¶
- on_lbutton_tripleclick(x: float, y: float) None ¶
- on_mouse_enter() None ¶
- on_mouse_leave(next_widget: Optional[PyDuiWidget]) None ¶
- on_mouse_move(x: float, y: float) None ¶
- on_post_init() None ¶
- on_rbutton_click(x: float, y: float) None ¶
- on_rbutton_dbclick(x: float, y: float) None ¶
- on_rbutton_press(x: float, y: float) bool ¶
- on_rbutton_release(x: float, y: float) bool ¶
- on_rbutton_tripleclick(x: float, y: float) None ¶
- on_scroll_event(event: ScrollEvent) bool ¶
- property parent: Optional[PyDuiWidget]¶
- parse_attrib(k: str, v: str)¶
Parse single attribute
- Parameters:
attrib (Dict[str, str]) – attributes dict key=value …
- parse_attributes(attrib: dict[str, str])¶
Parse all attributes
- Parameters:
attrib (dict[str, str]) – attributes dict key=value …
- property root_x: float¶
- property root_y: float¶
- set_focus()¶
- set_parent(parent: PyDuiWidget)¶
- set_window_client(window_client: PyDuiWindowClientInterface)¶
Set the window client
Do not call this function yourself if you do not know what it is for!
- property size: Tuple[float, float]¶
- translate_to_relative_pos(x: float, y: float) Tuple[float, float] ¶
- unbind_event(event_name: str, callback: Callable[[...], bool])¶
- property visible: bool¶
- property width: float¶
- property x: float¶
- property xy: Tuple[float, float]¶
- property y: float¶
- property zindex: int¶
pydui.core.window module¶
- class pydui.core.window.PyDuiWindow(loader: PyDuiResourceLoader, config: PyDuiWindowConfig, rootview: PyDuiLayout, handler: Optional[Type[PyDuiWindowHandler]] = None)¶
Bases:
PyDuiWindowInterface
- create_embedded_widget(widget_typename: str) PyDuiEmbeddedWidgetHost[Any] ¶
- get_widget(widget_id: str) Optional[PyDuiWidget] ¶
- get_window_provider() PyDuiWindowProvider ¶
- show()¶
pydui.core.window_client module¶
- class pydui.core.window_client.PyDuiWindowClient(window: PyDuiWindowInterface, config: PyDuiWindowConfig, loader: PyDuiResourceLoader, rootview: PyDuiLayout, handler: Optional[Type[PyDuiWindowHandler]])¶
Bases:
PyDuiWindowClientInterface
Window client
- add_embedded_widget(widget: PyDuiEmbeddedWidgetHost[Any])¶
- add_event_observer(key: str, fn: Callable[[...], Any]) None ¶
- cancel_task(task_id: str) None ¶
- create_embedded_widget(widget_typename: str) PyDuiEmbeddedWidgetHost[Any] ¶
- get_appearance() PyDuiAppearanceManager ¶
- get_customize_titlebar() bool ¶
- get_render_context() Context ¶
- get_resource_loader()¶
- get_rootview() PyDuiLayout ¶
Return root view widget.
- Returns:
root view.
- Return type:
- get_widget(widget_id: str) Optional[PyDuiWidget] ¶
Get widget by widget id
- Parameters:
widget_id (str) – widget id
- get_widget_by_pos(x: float, y: float, *, filter: ~typing.Callable[[~pydui.core.widget.PyDuiWidget], bool] = <function PyDuiWidget.find_widget_default_filter>) Optional[PyDuiWidget] ¶
- get_window_provider() PyDuiWindowProvider ¶
- get_window_size() Tuple[float, float] ¶
- init_window(config: PyDuiWindowConfig, ondraw: Callable[[Any, float, float], None])¶
- notify_redraw()¶
- post_task(fn: Callable[[...], Any], *args: Any, **kwargs: Any) str ¶
- post_task_with_delay(delay: float, fn: Callable[[...], Any], *args: Any, **kwargs: Any) str ¶
- release()¶
- remove_embedded_widget(widget: PyDuiEmbeddedWidgetHost[Any])¶
- remove_event_observer(key: str, fn: Callable[[...], Any]) None ¶
- set_window_size(width: float, height: float)¶
- update_embedded_widget_position(widget: PyDuiEmbeddedWidgetHost[Any], x: float, y: float)¶
- update_embedded_widget_viewport(widget: PyDuiEmbeddedWidgetHost[Any], rect: PyDuiRect)¶
pydui.core.window_client_interface module¶
- class pydui.core.window_client_interface.PyDuiWindowClientInterface¶
Bases:
ABC
- abstract add_embedded_widget(widget: PyDuiEmbeddedWidgetHost[Any]) None ¶
- abstract add_event_observer(key: str, fn: Callable[[...], Any]) None ¶
- abstract cancel_task(task_id: str) None ¶
- abstract create_embedded_widget(widget_typename: str) PyDuiEmbeddedWidgetHost[Any] ¶
- abstract get_appearance() PyDuiAppearanceManager ¶
- abstract get_customize_titlebar() bool ¶
- abstract get_render_context() Context ¶
- abstract get_resource_loader() PyDuiResourceLoader ¶
- abstract get_widget(widget_id: str) Optional[Any] ¶
- abstract get_widget_by_pos(x: float, y: float, *, filter: Callable[[Any], bool]) Optional[Any] ¶
- abstract get_window_provider() PyDuiWindowProvider ¶
- abstract get_window_size() Tuple[float, float] ¶
- abstract init_window(config: PyDuiWindowConfig, ondraw: Callable[[Any, float, float], None]) None ¶
- abstract notify_redraw() None ¶
- abstract post_task(fn: Callable[[...], Any], *args: Any, **kwargs: Any) str ¶
- abstract post_task_with_delay(delay: float, fn: Callable[[...], Any], *args: Any, **kwargs: Any) str ¶
- abstract release()¶
- abstract remove_embedded_widget(widget: PyDuiEmbeddedWidgetHost[Any]) None ¶
- abstract remove_event_observer(key: str, fn: Callable[[...], Any]) None ¶
- abstract set_window_size(width: float, height: float) None ¶
- abstract update_embedded_widget_position(widget: PyDuiEmbeddedWidgetHost[Any], x: float, y: float) None ¶
- abstract update_embedded_widget_viewport(widget: PyDuiEmbeddedWidgetHost[Any], rect: PyDuiRect) None ¶
pydui.core.window_config module¶
- class pydui.core.window_config.PyDuiWindowConfig(title: str, size: ~typing.Tuple[int, int], min_size: ~typing.Tuple[int, int], max_size: ~typing.Tuple[int, int], position: ~gi.repository.Gtk.WindowPosition = <enum GTK_WIN_POS_CENTER of type Gtk.WindowPosition>, default_font: str = 'Arial', default_fontsize: int = 16, default_fontbold: bool = False, customize_titlebar: bool = False, caption_height: int = 0, box_size: ~pydui.common.base.PyDuiEdge = <pydui.common.base.PyDuiEdge object>)¶
Bases:
object
Window config dataclass
- caption_height: int = 0¶
- customize_titlebar: bool = False¶
- default_font: str = 'Arial'¶
- default_fontbold: bool = False¶
- default_fontsize: int = 16¶
- max_size: Tuple[int, int]¶
- min_size: Tuple[int, int]¶
- position: WindowPosition = <enum GTK_WIN_POS_CENTER of type Gtk.WindowPosition>¶
- size: Tuple[int, int]¶
- title: str¶
pydui.core.window_event_dispatcher module¶
- class pydui.core.window_event_dispatcher.PyDuiWindowEventDispatcher(window: PyDuiWindowInterface, client: PyDuiWindowClientInterface, handler: Optional[Type[PyDuiWindowHandler]], on_init: Callable[[], None])¶
Bases:
object
Window Event Dispatcher
- add_event_observer(key: str, fn: Callable[[...], Any]) None ¶
- property handler: PyDuiWindowHandler¶
- init_events() None ¶
- on_button_press(event: ButtonEvent) bool ¶
- on_button_release(event: ButtonEvent) bool ¶
- on_configure_event(x: float, y: float, w: float, h: float) bool ¶
- on_motion_notify(x: int, y: int, x_root: int, y_root: int) bool ¶
- on_scroll_event(event: ScrollEvent) bool ¶
- on_window_destroy() None ¶
- on_window_hide() None ¶
- on_window_show() None ¶
- on_window_state_event()¶
- remove_event_observer(key: str, fn: Callable[[...], Any]) None ¶
pydui.core.window_handler module¶
- class pydui.core.window_handler.PyDuiWindowHandler¶
Bases:
object
Window handler
- on_nchittest(x: float, y: float) NCAreaType ¶
- on_window_destroy()¶
On window destroy event
- on_window_init(window: PyDuiWindowInterface)¶
On window init event
- on_window_position_changed(x: float, y: float)¶
On window position changed event
- Parameters:
x (float) – x coordinate
y (float) – y coordinate
- on_window_size_changed(w: float, h: float)¶
On window size changed event
- Parameters:
w (float) – window width
h (float) – window height
- on_window_visible_changed(show: bool)¶
On window visible changed event
- Parameters:
show – window is visible
pydui.core.window_interface module¶
- class pydui.core.window_interface.PyDuiWindowInterface¶
Bases:
ABC
- abstract create_embedded_widget(widget_typename: str) PyDuiEmbeddedWidgetHost[Any] ¶
- abstract get_widget(widget_id: str) Optional[PyDuiWidget] ¶
- abstract get_window_provider() PyDuiWindowProvider ¶
- abstract show()¶
pydui.core.window_provider module¶
- class pydui.core.window_provider.PyDuiWindowProvider(*args, **kwargs)¶
Bases:
Protocol
- abstract begin_move_drag(x: float, y: float)¶
- abstract begin_resize_drag(area_type: NCAreaType, x: float, y: float)¶
- abstract connect(signal: str, fn: Callable[[...], Any])¶
- abstract disaconnect_all(signal: str)¶
- abstract disconnect(signal: str, fn: Callable[[...], Any])¶
- abstract get_embedded_widget_provider() PyDuiEmbeddedWidgetProvider ¶
- abstract get_render_context() Any ¶
- abstract get_window_size() Tuple[float, float] ¶
- abstract init_window(config: PyDuiWindowConfig, ondraw: Callable[[Any, float, float], None])¶
- abstract notify_redraw()¶
- abstract set_render_context(context: Any)¶
- abstract set_window_size(width: float, height: float)¶
- abstract show()¶
Module contents¶
Core Module