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[pyqt5] -U  # with pyqt5 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.23

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.23
File Size Uploaded
magic_class-0.7.23.tar.gz 209.7 kB Details

Built distribution (wheel)

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

Total release size: 484.9 kB

Release files / magic_class-0.7.23.tar.gz

Download URL magic_class-0.7.23.tar.gz
Size 209.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2f50c094e0143915bcd9cddb9597b8443431bde74972b33bae0fbd18419e288a
BLAKE2b-256 checksum
How to use checksums
f6376293c3f60b4d7c9f373f130d56e4838a7bdc30b0b55f9975c22da5c4383f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

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

Download URL magic_class-0.7.23-py3-none-any.whl
Size 275.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b547383509be86b7dbf6848678ea0ebf287f60934feb1adb8df2c275efca16ba
BLAKE2b-256 checksum
How to use checksums
6ff8d5ac378465d39c02fb720dff29a5dba0d5c022c6c13612d0c026c54c59ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release history Release notifications | RSS feed

This release

0.7.23 This release

2 release files

0.7.22

2 release files

0.7.18

2 release files

0.7.17

2 release files

0.7.12

2 release files

0.7.11

2 release files

0.7.10

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.15

2 release files

0.6.14

2 release files

0.6.11

2 release files

0.6.10

2 release files

0.6.9

2 release files

0.6.8

2 release files

0.6.7

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.22

2 release files

0.5.21

2 release files

0.5.19

2 release files

0.5.18

2 release files

0.5.17

2 release files

0.5.14

2 release files

0.5.13

2 release files

0.5.12

2 release files

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

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