Skip to main content

Generate multifunctional GUIs from classes

Project description

License BSD-3 Downloads PyPI 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 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
  • get 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magic-class-0.6.10.tar.gz (148.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

magic_class-0.6.10-py3-none-any.whl (173.4 kB view details)

Uploaded Python 3

File details

Details for the file magic-class-0.6.10.tar.gz.

File metadata

  • Download URL: magic-class-0.6.10.tar.gz
  • Upload date:
  • Size: 148.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.7

File hashes

Hashes for magic-class-0.6.10.tar.gz
Algorithm Hash digest
SHA256 fcc284addcdcf5e3f4ce99978941cd6210278484faad1d89ef7fb3f48dd900df
MD5 54ecb1ef038e71116f40b2e96c8ec6f2
BLAKE2b-256 5fb1c160ed4347857a523779f9e47a04363912b69ac52d5a2efc6b2b53e8f5cb

See more details on using hashes here.

File details

Details for the file magic_class-0.6.10-py3-none-any.whl.

File metadata

  • Download URL: magic_class-0.6.10-py3-none-any.whl
  • Upload date:
  • Size: 173.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.7

File hashes

Hashes for magic_class-0.6.10-py3-none-any.whl
Algorithm Hash digest
SHA256 a1d86b5221c4fb782f6073ece84e4c9d4b02c29d12dad7bad6119606197cae41
MD5 0a261fbf5da50164a2546ea3842fcdd9
BLAKE2b-256 963d4c6097b8e86be3809aa41cece72d3b1f4c402d0e462de81f62b1bac3dfd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page