Skip to main content

BSD 3-Clause License Python package index download statistics PyPI version PyPI - Python Version Conda version

magic-class

magic-class makes GUI development as easy as daily coding by converting well-typed Python class directly into GUI. It is powered by magicgui and has a smooth interface with napari. magic-class is also implemented with useful widgets such as matplotlib figure canvas, logger widget and color edit.

Target users

  • Researchers who already have their Python functions and classes and are planing to take a step forward to improve the interface using GUI, with minimum effort.
  • Non-professional programmers who don't want to spend time on debugging and maintaining GUI.
  • Users who are not satisfied with the low reproducibility of the most of the GUI.
  • People who are familiar with magicgui and interested in more sophisticated GUI using typing.

How magic-class solves your problems

  • Decorate your class with @magicclass and you are ready to use the class both in GUI and from console.
  • @magicclass implements macro-recorder in the class. You can easily create executable Python codes from the history of manual operations.
  • Your code looks almost "Pythonic". No need to be confused by messy class structure pecuilar to GUI development anymore.

magic-class is work in progress. Feel free to report issues, make suggestions and contribute!

Documentation

Documentation is available here.

Installation

  • use pip
pip install magic-class -U
pip install magic-class[pyqt6] -U  # with pyqt6 backend
  • get the latest version
pip install git+https://github.com/hanjinliu/magic-class.git

Example

Let's make a simple GUI that can load 1-D data and plot it.

from magicclass import magicclass
from pathlib import Path

@magicclass
class PlotData:
    """Load 1D data and plot it."""

    def load(self, path: Path):
        """
        Load file.

        Parameters
        ----------
        path : Path
            File path
        """
        self.data = np.loadtxt(str(path))

    def plot(self):
        """Plot data."""
        plt.plot(self.data)
        plt.show()

Classes decorated with @magicclass are converted to magicgui's Container widgets. GUI starts with show method.

ui = PlotData(title="Title")
ui.show()

You can continue analysis in console.

ui.plot()

For people doing image analysis, it can be added to a napari viewer as a dock widget.

import napari
viewer = napari.Viewer()
viewer.window.add_dock_widget(ui)

Executable Python code (so called "macro" in many GUI tools) is available in macro attribute.

print(ui.macro)  # print macro
ui.macro.widget.show()  # open a text editor widget with macro written in

To make nicer GUI, you can also nest magic-class:

@magicclass
class PlotData:
    @magicclass
    class Menu: ...

add a menubar with @magicmenu decorator:

@magicclass
class PlotData:
    @magicmenu
    class File: ...
    @magicmenu
    class Edit: ...

add context menu with @magiccontext decorator:

@magicclass
class PlotData:
    @magiccontext
    class contextmenu: ...
        def Copy(self): ...
        def Paste(self): ...

directly integrate magicgui and its widgets:

@magicclass
class PlotData:
    line = LineEdit()
    @magicgui
    def load(self, path: Path): ...

... and so on.

Other examples are in the "examples" folder.

Metadata

Release files for magic-class 0.7.24

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magic-class 0.7.24
File Size Uploaded Provenance Actions
magic_class-0.7.24.tar.gz 210.1 kB Without provenance Details for magic_class-0.7.24.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for magic-class 0.7.24
File Interpreter ABI Platform Actions
magic_class-0.7.24-py3-none-any.whl Python 3 none any Details for magic_class-0.7.24-py3-none-any.whl

Total release size: 485.6 kB

Release files / magic_class-0.7.24.tar.gz

Download URL magic_class-0.7.24.tar.gz
Size 210.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6a484286e45a0139f303c8b60ff35d91c10e0289cfd7e23cd02eff4ae2d574cb
BLAKE2b-256 checksum
How to use checksums
91829de8a9d3b08a97f4cc5fe513bdfa9575f2f2d6a4737a4cedb2bc56f2c9ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.1 {"ci":null,"cpu":"AMD64","implementation":{"name":"CPython","version":"3.10.14"},"installer":{"name":"hatch","version":"1.18.1"},"openssl_version":"OpenSSL 3.4.0 22 Oct 2024","python":"3.10.14","system":{"name":"Windows","release":"10"}} HTTPX2/2.13.1

Release files / magic_class-0.7.24-py3-none-any.whl

Download URL magic_class-0.7.24-py3-none-any.whl
Size 275.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1880c3af2ffa5d7cb5adaa0168482b6b7649179df15b2e4de7188e7db82797d2
BLAKE2b-256 checksum
How to use checksums
652e03e7ad24a9e3a04ff35405952039e55a0e5dd34fde076f6cc7a05e1c1059
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.1 {"ci":null,"cpu":"AMD64","implementation":{"name":"CPython","version":"3.10.14"},"installer":{"name":"hatch","version":"1.18.1"},"openssl_version":"OpenSSL 3.4.0 22 Oct 2024","python":"3.10.14","system":{"name":"Windows","release":"10"}} HTTPX2/2.13.1

Security for magic-class 0.7.24

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.24 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page