Metadata-Version: 2.3
Name: magic-class
Version: 0.7.11
Summary: Generate multifunctional GUIs from classes
Project-URL: Download, https://github.com/hanjinliu/magic-class
Author-email: Hanjin Liu <liuhanjin-sc@g.ecc.u-tokyo.ac.jp>
License: BSD 3-Clause License
        
        Copyright (c) 2021, hanjinliu
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Requires-Dist: docstring-parser>=0.15
Requires-Dist: macro-kit>=0.4.6
Requires-Dist: magicgui>=0.8.0
Requires-Dist: psygnal>=0.9.0
Requires-Dist: qtpy>=1.10.0
Requires-Dist: superqt[iconify]>=0.6.1
Requires-Dist: typing-extensions>=4.5.0
Provides-Extra: docs
Requires-Dist: docutils>=0.17.1; extra == 'docs'
Requires-Dist: matplotlib>=3.8.2; extra == 'docs'
Requires-Dist: mkdocs; extra == 'docs'
Requires-Dist: mkdocs-autorefs==0.5.0; extra == 'docs'
Requires-Dist: mkdocs-gen-files; extra == 'docs'
Requires-Dist: mkdocs-material-extensions==1.3.1; extra == 'docs'
Requires-Dist: mkdocs-material==9.5.2; extra == 'docs'
Requires-Dist: mkdocstrings-python==1.7.5; extra == 'docs'
Requires-Dist: mkdocstrings==0.24.0; extra == 'docs'
Requires-Dist: numpy; extra == 'docs'
Requires-Dist: pandas>=2.1; extra == 'docs'
Requires-Dist: pyqt5>=5.12.0; extra == 'docs'
Requires-Dist: pyqtgraph>=0.13.2; extra == 'docs'
Requires-Dist: vispy>=0.11.0; extra == 'docs'
Provides-Extra: pyqt5
Requires-Dist: pyqt5>=5.12.0; extra == 'pyqt5'
Provides-Extra: pyqt6
Requires-Dist: pyqt6; extra == 'pyqt6'
Provides-Extra: pyside2
Requires-Dist: pyside2>=5.15; (python_version >= '3.9') and extra == 'pyside2'
Provides-Extra: pyside6
Requires-Dist: pyside6; extra == 'pyside6'
Provides-Extra: testing
Requires-Dist: dask; extra == 'testing'
Requires-Dist: numpy; extra == 'testing'
Requires-Dist: pandas>=1.5.0; extra == 'testing'
Requires-Dist: polars>=0.17.10; extra == 'testing'
Requires-Dist: pyqtgraph>=0.13.2; extra == 'testing'
Requires-Dist: pytest; extra == 'testing'
Requires-Dist: pytest-qt; extra == 'testing'
Requires-Dist: vispy>=0.11.0; extra == 'testing'
Description-Content-Type: text/markdown

[![BSD 3-Clause License](https://img.shields.io/pypi/l/magic-class.svg?color=green)](https://github.com/hanjinliu/magic-class/blob/main/LICENSE)
[![Python package index download statistics](https://img.shields.io/pypi/dm/magic-class.svg)](https://pypistats.org/packages/magic-class)
[![PyPI version](https://badge.fury.io/py/magic-class.svg)](https://badge.fury.io/py/magic-class)
[![Conda version](https://anaconda.org/conda-forge/magic-class/badges/version.svg)](https://anaconda.org/conda-forge/magic-class/badges/version.svg)


# magic-class

![](https://github.com/hanjinliu/magic-class/blob/main/Figs/Example.gif)

`magic-class` makes GUI development as easy as daily coding by converting well-typed Python class directly into GUI. It is powered by [magicgui](https://github.com/pyapp-kit/magicgui) and has a smooth interface with [napari](https://github.com/napari/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](https://hanjinliu.github.io/magic-class/).

## 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.

``` python
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.

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

You can continue analysis in console.

``` python
ui.plot()
```

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

``` python
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.

``` python
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`:

``` python
@magicclass
class PlotData:
    @magicclass
    class Menu: ...
```

add a menubar with `@magicmenu` decorator:

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

add context menu with `@magiccontext` decorator:

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

```

directly integrate `magicgui` and its widgets:

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

... and so on.

Other examples are in the "examples" folder.
