Utils
import { Aside } from “@astrojs/starlight/components”; import TypeSignature from “@components/TypeSignature.astro”;
<TypeSignature typeName={ “PixbufUtils” } typePrefix={ “class” }> PixbufUtils
Bases: object
<TypeSignature typeName={ “from_cairo_surface” } typePrefix={ “static” } typeArgList={ “(surface: ImageSurface, x_offset: int = 0, y_offset: int = 0, target_width: int | None = None, target_height: int | None = None)” } returnType={ “Pixbuf” }> from_cairo_surface
<TypeSignature typeName={ “set_cairo_source” } typePrefix={ “static” } typeArgList={ “(pixbuf: Pixbuf, cr: Context, x_offset: int = 0, y_offset: int = 0)” }> set_cairo_source
<TypeSignature typeName={ “rotate” } typePrefix={ “static” } typeArgList={ “(pixbuf: Pixbuf, angle: float)” } returnType={ “Pixbuf” }> rotate
return a rotated version of the given GdkPixbuf.Pixbuf to a given angle
- Parameters:
- pixbuf (GdkPixbuf.Pixbuf) — the input pixbuf
- angle (float) — the desired rotation angle in degrees
- Returns: the newly rotated pixbuf
- Return type: GdkPixbuf.Pixbuf
<TypeSignature typeName={ “FormattedString” } typePrefix={ “class” } typeArgList={ “(string: str, **kwargs)” }> FormattedString
Bases: object
simple string fomatter made to be baked mid-runtime
<TypeSignature typeName={ “FormatDict” } typePrefix={ “class” } typeArgList={ ”(*args, **kwargs)” }> FormatDict
Bases: dict
<TypeSignature typeName={ “format” } typePrefix={ “def” } typeArgList={ ”(**kwargs)” } returnType={ “str” }> format
<TypeSignature typeName={ “DesktopApp” } typePrefix={ “class” } typeArgList={ “(app: gi.overrides.GioUnix.DesktopAppInfo, icon_theme: gi.repository.Gtk.IconTheme | None = None)” }> DesktopApp
Bases: object
<TypeSignature typeName={ “name” } typePrefix={ “attribute” } returnType={ “str” }> name
<TypeSignature typeName={ “generic_name” } typePrefix={ “attribute” } returnType={ “str | None” }> generic_name
<TypeSignature typeName={ “display_name” } typePrefix={ “attribute” } returnType={ “str | None” }> display_name
<TypeSignature typeName={ “description” } typePrefix={ “attribute” } returnType={ “str | None” }> description
<TypeSignature typeName={ “window_class” } typePrefix={ “attribute” } returnType={ “str | None” }> window_class
<TypeSignature typeName={ “executable” } typePrefix={ “attribute” } returnType={ “str | None” }> executable
<TypeSignature typeName={ “command_line” } typePrefix={ “attribute” } returnType={ “str | None” }> command_line
<TypeSignature typeName={ “icon” } typePrefix={ “attribute” } returnType={ “Icon | ThemedIcon | FileIcon | LoadableIcon | EmblemedIcon | None” }> icon
<TypeSignature typeName={ “icon_name” } typePrefix={ “attribute” } returnType={ “str | None” }> icon_name
<TypeSignature typeName={ “hidden” } typePrefix={ “attribute” } returnType={ “bool” }> hidden
<TypeSignature typeName={ “launch” } typePrefix={ “def” } typeArgList={ ”()” }> launch
<TypeSignature typeName={ “get_icon_pixbuf” } typePrefix={ “def” } typeArgList={ “(size: int = 48, default_icon: str | None = ‘image-missing’, flags: IconLookupFlags = Gtk.IconLookupFlags.FORCE_REGULAR | Gtk.IconLookupFlags.FORCE_SIZE)” } returnType={ “Pixbuf | None” }> get_icon_pixbuf
get a pixbuf from the icon (if any)
- Parameters:
- size (int , optional) — the size of the icon, defaults to 48
- default_icon (str | None , optional) — the name of the default icon. pass None if you want to receive None upon failing, defaults to “image-missing”
- flags (Gtk.IconLookupFlags , defaults to *(*Gtk.IconLookupFlags.FORCE_REGULAR | Gtk.IconLookupFlags.FORCE_SIZE ) , optional) — the Gtk.IconLookupFlags to use when fetching the icon
- Returns: the pixbuf
- Return type: GdkPixbuf.Pixbuf | None
<TypeSignature typeName={ “get_desktop_applications” } typePrefix={ “def” } typeArgList={ “(include_hidden: bool = False)” } returnType={ “list[DesktopApp]” }> get_desktop_applications
get a list of all desktop applications this might be useful for writing application launchers
- Parameters: include_hidden (bool , optional) — whether to include applications unintended to be visible to normal users, defaults to false
- Returns: a list of all desktop applications
- Return type: list[DesktopApp]
<TypeSignature typeName={ “parse_color” } typePrefix={ “def” } typeArgList={ “(color: str | Iterable[int | float])” } returnType={ “RGBA” }> parse_color
parse a serialized color data over to a Gdk.RGBA object
- Parameters: color (str | Iterable *[*Number ]) — the color data, example of an iterable color; (255, 255, 255) / (255, 255, 255, 255), for a list of parseable string formats head over to https://docs.gtk.org/gdk3/method.RGBA.parse.html
- Raises: ValueError — if the passed in color data is unparseable
- Returns: the newly created Gdk.RGBA (alpha is set to opaque if the passed in color data is RGB only)
- Return type: Gdk.RGBA
<TypeSignature typeName={ “get_gdk_rgba” } typePrefix={ “def” } typeArgList={ “(color: str | Iterable[int | float])” } returnType={ “RGBA” }> get_gdk_rgba
<TypeSignature typeName={ “compile_css” } typePrefix={ “def” } typeArgList={ “(css_string: str, base_path: str = ’.’, exposed_functions: dict[str, Callable] | Iterable[Callable] | None = None)” } returnType={ “str” }> compile_css
preprocess and transpile a CSS string to GTK’s CSS syntax.
supports transpiling web-css like variables over to GTK’s @define-color syntax.
also supports having CSS macros. syntax example:
/* define a macro */@define my-macro(--arg-1, --arg-2) { /* CSS body goes here. example body.. */ color: --arg-1; background-color: --arg-2;}
#my-widget { @apply my-macro(red, blue); /* compiles to color: --arg-1; background-color: --arg-2; */}Note: this function relies on a series of regular expressions for its processing, which may lead to potential issues in certain edge cases.
- Parameters:
- css_string (str) — the input CSS as a string.
- base_path (str , optional) — for @import statements, used for relative imports.
- exposed_functions (dict *[*str , Callable ] | Iterable *[*Callable ] | None , optional) — a dictionary of macro functions or an iterable of callable functions to use as extra macros. if a dictionary is provided, the keys are macro names, and the values are the corresponding functions.
- Returns: the compiled CSS string converted to GTK’s CSS syntax.
- Return type: str
<TypeSignature typeName={ “bulk_replace” } typePrefix={ “def” } typeArgList={ “(string: str, patterns: Iterable[str], replacements: Iterable[str], regex: bool = False)” } returnType={ “str” }> bulk_replace
Replaces occurrences of multiple patterns in a string with corresponding replacements.
- Parameters:
- string (str) — the input string in which replacements will be made.
- patterns (Iterable *[*str ]) — the patterns to be replaced, this can be a list of strings or a list of regular expressions.
- replacements (Iterable *[*str ]) — the replacements for each text.
- regex (bool , optional) — Whether to interpret the patterns as regular expressions. Defaults to False.
- Returns: the string with replacements made.
- Return type: str
- Raises: ValueError — If the lengths of patterns and replacements are not the same.
<TypeSignature typeName={ “bulk_connect” } typePrefix={ “def” } typeArgList={ “(connectable: Object, mapping: dict[str, Callable])” } returnType={ “tuple[int, …]” }> bulk_connect
connects a list of signals to a list of callbacks to an object
- Parameters:
- connectable (GObject.Object) — the object to connect the signals to
- mapping (dict *[*str , Callable ]) — the mapping of signals to callback functions
- Return type: tuple[int, …]
<TypeSignature typeName={ “bulk_disconnect” } typePrefix={ “def” } typeArgList={ “(disconnectable: Object, signals_or_funcs: Iterable[str | Callable])” } returnType={ “tuple[int, …]” }> bulk_disconnect
does the opposite of bulk_connect
- Parameters:
- disconnectable (GObject.Object | object) — the object to disconnect the signals from
- signals_or_funcs — iterable of signals/callbacks to disconnect
- Returns: a list of return values from the disconnect function
- Return type: tuple[int]
<TypeSignature typeName={ “clamp” } typePrefix={ “def” } typeArgList={ “(value: int | float, min_value: int | float, max_value: int | float)” } returnType={ “int | float” }> clamp
clamp a value between a minimum and maximum value
- Parameters:
- value (float or int) — the value to be clamped
- min_value (float or int) — the minimum value to clamp to
- max_value (float or int) — the maximum value to clamp to
- Returns: the clamped value
- Return type: float or int
<TypeSignature typeName={ “extract_css_values” } typePrefix={ “def” } typeArgList={ “(css_string: str)” } returnType={ “tuple[int, int, int, int]” }> extract_css_values
extracs and return a tuple of four CSS values from a given CSS string.
- Parameters: css_string (str) — the CSS string to extract the values from.
- Returns: a tuple of four integers representing the extracted CSS values. If the CSS string does not contain enough values, the missing values are filled with zeros.
- Return type: tuple
<TypeSignature typeName={ “monitor_file” } typePrefix={ “def” } typeArgList={ “(file_path: str, flags: Literal[‘none’, ‘watch-mounts’, ‘send-moved’, ‘watch-hard-links’, ‘watch-moves’] | FileMonitorFlags = Gio.FileMonitorFlags.NONE)” } returnType={ “FileMonitor” }> monitor_file
creates a monitor for a specified file or directory path
- Parameters:
- file_path (str) — the path of the file or directory to be monitored
- flags (Literal [ “none” , “watch-mounts” , “send-moved” , “watch-hard-links” , “watch-moves” ] , optional) — the flags to configure the file monitor. Defaults to None.
- Returns: the monitor for the specified path
- Return type: Gio.FileMonitor
<TypeSignature typeName={ “cooldown” } typePrefix={ “def” } typeArgList={ “(cooldown_time: int, error: Callable | None = None, return_error: bool = False)” }> cooldown
Decorator function that adds a cooldown period to a given function
- Parameters:
- cooldown_time (int) — the time in seconds to wait before calling the function again
- error (Callable , optional) — the function to call if the cooldown period has not been reached yet. Defaults to None
- Return type: decorator
<TypeSignature typeName={ “exec_shell_command” } typePrefix={ “def” } typeArgList={ “(cmd: str)” } returnType={ “str | Literal[False]” }> exec_shell_command
executes a shell command and returns the output
- Parameters: cmd (str) — the shell command to execute
- Returns: the output of the command or False if an error has occurred
- Return type: str | Literal[False]
<TypeSignature typeName={ “exec_shell_command_async” } typePrefix={ “def” } typeArgList={ “(cmd: str | list[str], callback: Callable[[str], Any] | None = None)” } returnType={ “tuple[Subprocess | None, DataInputStream]” }> exec_shell_command_async
executes a shell command and returns the output asynchronously
- Parameters:
- cmd (str) — the shell command to execute
- callback (Callable [ *[*str ] , Any ] | None , optional) — a function to retrieve the result at or None to ignore the result
- Returns: a Gio.Subprocess object which holds a referance to your process and a Gio.DataInputStream object for stdout
- Return type: tuple[Gio.Subprocess | None, Gio.DataInputStream]
<TypeSignature typeName={ “invoke_repeater” } typePrefix={ “def” } typeArgList={ “(interval: int, func: Callable, *args, initial_call: bool = True)” } returnType={ “int” }> invoke_repeater
invokes a function repeatedly with a given interval
- Parameters:
- interval (int) — the interval in milliseconds to invoke the function
- func (Callable) — the function to invoke
<TypeSignature typeName={ “get_relative_path” } typePrefix={ “def” } typeArgList={ “(path: str, level: int = 1)” } returnType={ “str” }> get_relative_path
converts a path to a relative path according to caller’s file variable
NOTE: This function only works if the caller file variable is set. means this will work only if you’re calling from a python file (not a IDLE / REPL), else it will fallback to the current working directory as file
- Parameters:
- path (str) — the path to convert
- level (int , optional) — the stack level to get the file variable from. Defaults to 1
- Returns: the relative path
- Return type: str
<TypeSignature typeName={ “load_dbus_xml” } typePrefix={ “def” } typeArgList={ “(path_to_xml: str)” }> load_dbus_xml
<TypeSignature typeName={ “snake_case_to_pascal_case” } typePrefix={ “def” } typeArgList={ “(string: str)” } returnType={ “str” }> snake_case_to_pascal_case
<TypeSignature typeName={ “pascal_case_to_snake_case” } typePrefix={ “def” } typeArgList={ “(string: str)” } returnType={ “str” }> pascal_case_to_snake_case
<TypeSignature typeName={ “snake_case_to_kebab_case” } typePrefix={ “def” } typeArgList={ “(string: str)” } returnType={ “str” }> snake_case_to_kebab_case
<TypeSignature typeName={ “kebab_case_to_snake_case” } typePrefix={ “def” } typeArgList={ “(string: str)” } returnType={ “str” }> kebab_case_to_snake_case
<TypeSignature typeName={ “get_enum_member” } typePrefix={ “def” } typeArgList={ “(enum: type[E], member: str | E, mapping: dict[str, str] = {}, default: Any = MISSING)” } returnType={ “E” }> get_enum_member
<TypeSignature typeName={ “get_enum_member_name” } typePrefix={ “def” } typeArgList={ “(member: Enum | Any, mapping: dict[str, str] = {}, default: Any = MISSING)” } returnType={ “str” }> get_enum_member_name
<TypeSignature typeName={ “bridge_signal” } typePrefix={ “def” } typeArgList={ “(source: Object, source_signal: str, target: Object, target_signal: str, notify: bool = False)” } returnType={ “int” }> bridge_signal
<TypeSignature typeName={ “generate_random_string” } typePrefix={ “def” } typeArgList={ “(length: int = 8)” } returnType={ “str” }> generate_random_string
<TypeSignature typeName={ “FunctionAnnotations” } typePrefix={ “class” } typeArgList={ “(arguments, return_type)” }> FunctionAnnotations
Bases: NamedTuple, Generic[T]
Create new instance of FunctionAnnotations(arguments, return_type)
<TypeSignature typeName={ “arguments” } typePrefix={ “attribute” } returnType={ “dict[str, type]” }> arguments
Alias for field number 0
<TypeSignature typeName={ “return_type” } typePrefix={ “attribute” } returnType={ “T | None” }> return_type
Alias for field number 1
<TypeSignature typeName={ “get_function_annotations” } typePrefix={ “def” } typeArgList={ “(func: Callable[[P], T])” } returnType={ “FunctionAnnotations[T]” }> get_function_annotations
<TypeSignature typeName={ “truncate” } typePrefix={ “def” } typeArgList={ “(string: str, max_length: int, suffix: str = ’…’)” } returnType={ “str” }> truncate
<TypeSignature typeName={ “idle_add” } typePrefix={ “def” } typeArgList={ “(func: Callable, *args, pin: bool = False)” } returnType={ “int” }> idle_add
add a function to be invoked in a lazy manner in the main thread, useful for multi-threaded code
- Parameters:
- func (Callable) — the function to be queued
- args — arguments will be passed to the given function
- pin (bool , optional) — whether the function should be invoked as long as it’s return value is True, when the function returns False it won’t be called again
<TypeSignature typeName={ “remove_handler” } typePrefix={ “def” } typeArgList={ “(handler_id: int)” }> remove_handler
<TypeSignature typeName={ “get_connectables_for_kwargs” } typePrefix={ “def” } typeArgList={ “(kwargs: dict[str, Callable])” } returnType={ “Generator” }> get_connectables_for_kwargs
get_connectables_for_kwargs is deprecated and will be removed in later versions of Fabric.
<TypeSignature typeName={ “set_stylesheet_from_file” } typePrefix={ “def” } typeArgList={ “(file_path: str, compiled: bool = True)” } returnType={ “None” }> set_stylesheet_from_file
set_stylesheet_from_file is deprecated and will be removed in later versions of Fabric. consider using Application.add_stylesheet_from_file instead.
<TypeSignature typeName={ “set_stylesheet_from_string” } typePrefix={ “def” } typeArgList={ “(css_string: str, compiled: bool = True)” } returnType={ “None” }> set_stylesheet_from_string
set_stylesheet_from_string is deprecated and will be removed in later versions of Fabric. consider using Application.add_stylesheet_from_string instead.
<TypeSignature typeName={ “idlify” } typePrefix={ “def” } typeArgList={ “(func: Callable, *args)” } returnType={ “int” }> idlify
idlify is deprecated and will be removed in later versions of Fabric. consider using idle_add instead.