magicclass.utils package

Submodules

magicclass.utils.functions module

class magicclass.utils.functions.Tooltips(obj: Any)[source]

Bases: object

property attributes: dict[str, str]
property desc
property parameters: dict[str, str]
magicclass.utils.functions.argcount(func: Callable) int[source]

Count the number of parameters of a callable object.

Basically, this function returns identical result as: >>> len(inspect.signature(func).parameters) but ~10x faster.

magicclass.utils.functions.get_signature(func)[source]

Similar to inspect.signature but safely returns Signature.

magicclass.utils.functions.is_instance_method(func: Callable) bool[source]

Check if a function is defined in a class.

magicclass.utils.functions.iter_members(cls: type, exclude_prefix: str = '__') Iterable[tuple[str, typing.Any]][source]

Iterate over all the members in the order of source code line number. This function is identical to inspect.getmembers except for the order of the results. We have to sort the name in the order of line number.

magicclass.utils.functions.method_as_getter(self, getter: Callable)[source]
magicclass.utils.functions.rst_to_html(rst: str, unescape: bool = True) str[source]

Convert rST string into HTML.

magicclass.utils.functions.show_tree(ui: BaseGui) str[source]

magicclass.utils.qt module

class magicclass.utils.qt.MessageBoxMode(value)[source]

Bases: enum.Enum

An enumeration.

ABOUT = 'about'
ERROR = 'error'
INFO = 'info'
QUESTION = 'question'
WARNING = 'warn'
magicclass.utils.qt.move_to_screen_center(qwidget: PyQt5.QtWidgets.QWidget) None[source]

Move a QWidget to the center of screen.

magicclass.utils.qt.open_url(link: str) None[source]

Open the link with the default browser.

Parameters

link (str) -- Link to the home page.

magicclass.utils.qt.screen_center()[source]

Get the center coordinate of the screen.

magicclass.utils.qt.screen_scale() float[source]

Get the scale of main screen.

magicclass.utils.qt.show_messagebox(mode: str | MessageBoxMode = MessageBoxMode.INFO, title: str = None, text: str = None, parent=None) bool[source]

Freeze the GUI and open a messagebox dialog.

Parameters
  • mode (str or MessageBoxMode, default is MessageBoxMode.INFO) -- Mode of message box. Must be "error", "warn", "info", "question" or "about".

  • title (str, optional) -- Title of messagebox.

  • text (str, optional) -- Text in messagebox.

  • parent (QWidget, optional) -- Parent widget.

Returns

If "OK" or "Yes" is clicked, return True. Otherwise return False.

Return type

bool

magicclass.utils.qt.to_clipboard(obj) None[source]

Copy an object of any type to the clipboard. You can copy text, ndarray as an image or data frame as a table data.

Parameters

obj (Any) -- Object to be copied.

magicclass.utils.qthreading module

class magicclass.utils.qthreading.Timer[source]

Bases: object

A timer class with intuitive API.

format_time(fmt: str = '{hour:0>2}:{min:0>2}:{sec:0>2}') str[source]

Format current time.

lap() float[source]

Return lap time.

reset()[source]

Reset timer.

property sec: float

Return current second.

start()[source]

Start timer.

stop() float[source]

Stop timer.

class magicclass.utils.qthreading.thread_worker(f: Callable[_P, _R1] | None = None, *, ignore_errors: bool = False, progress: ProgressDict | None = None)[source]

Bases: object

Create a worker in a superqt/napari style.

property aborted: magicclass.utils.qthreading.Callbacks[None]

Event that will be emitted on aborted.

property errored: magicclass.utils.qthreading.Callbacks[Exception]

Event that will be emitted on errored.

property finished: magicclass.utils.qthreading.Callbacks[None]

Event that will be emitted on finished.

property is_generator: bool

True if bound function is a generator function.

property returned: magicclass.utils.qthreading.Callbacks[magicclass.utils.qthreading._R1]

Event that will be emitted on returned.

classmethod set_default(pbar_cls: Callable | str)[source]

Set the default progressbar class.

This class method is useful when there is an user-defined class that follows _SupportProgress protocol.

Parameters

pbar_cls (callable or str) -- The default class. In principle this parameter does not have to be a class. As long as pbar_cls(max=...) returns a _SupportProgress object it works. Either "default" or "napari" is also accepted.

property started: magicclass.utils.qthreading.Callbacks[None]

Event that will be emitted on started.

property yielded: magicclass.utils.qthreading.Callbacks[magicclass.utils.qthreading._R1]

Event that will be emitted on yielded.

magicclass.utils.qtsignal module

class magicclass.utils.qtsignal.QtSignal[source]

Bases: PyQt5.QtCore.QObject

Dummy qt object for pyqt signal operations.

connect(slot: Callable)[source]
emit(val: Optional[Any] = None)[source]
signal

Module contents