magicclass.utils package

Submodules

magicclass.utils.qt module

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

Bases: Enum

An enumeration.

ABOUT = 'about'
ERROR = 'error'
INFO = 'info'
QUESTION = 'question'
WARNING = 'warn'
magicclass.utils.qt.move_to_screen_center(qwidget: 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.Callback(f: Callable[[], Any])[source]

Bases: object

Callback object that can be recognized by thread_worker.

static catch(out, macro: GuiMacro)[source]
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

property aborted: CallbackList[None]

Event that will be emitted on aborted.

property errored: CallbackList[Exception]

Event that will be emitted on errored.

property finished: CallbackList[None]

Event that will be emitted on finished.

property func: Callable[[_P], _R1]
property is_generator: bool

True if bound function is a generator function.

property returned: CallbackList[_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: CallbackList[None]

Event that will be emitted on started.

static to_callback(callback: Callable, *args, **kwargs) Callback[source]

Convert a callback to a callback object.

property yielded: CallbackList[_R1]

Event that will be emitted on yielded.

magicclass.utils.qtsignal module

class magicclass.utils.qtsignal.QtSignal[source]

Bases: QObject

Dummy qt object for pyqt signal operations.

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

Module contents