Magic-class

Latest version: v0.7.14

Safety actively analyzes 706267 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 10 of 11

0.4.2

New Features
---------------
- Lots of new `Container`s are now available. Use `magicclass(widget_type="scrollable")` for scrollable Containers, `magicclass(widget_type="button")` for Containers that are hidden in push buttons, `magicclass(widget_type="tabbed")` for Containers with many tabs, and so on.
- When checkable widgets are defined in `magicmenu`, then it will be converted to a checkable action.
- Instead of line number recording before v0.4.1, I switched widget ordering to a new way that depends on `__dict__`. Therefore, you don't have to add some widgets like `w = field(LineEdit)`, but `w = LineEdit()` also works.
- With `wraps` function you can copy signature from a template function to other methods. For example, if you defined a lot of methods that take argument `path`, you don't have to add annotation `Path` for every function. Define a template function
python
def template(path: Path): pass

and decorate methods.
python
wraps(template)
def method1(self, path): ...

`wraps` method of `magicclass` also support the same wrapping strategy but currently need keyword "template=".

Changes
----------
- Docstring of class was converted into `Label` widget before. But this was usually useless. Now it will be converted into tooltip. If you want a `Label` widget, create a widget inside `magicclass` like
python
magicclass
class Main:
label = Label(...)
def func(self): ...

- When a `magicclass` is docked into `napari`, all the `magicgui`s and macro windows were opened via `add_dock_widget` and `setFloating`. However, it is no general and is not a good way in general. Now parent is set for every `magicgui` and macro window.

Bug fixes
----------
- When `magicclass` is nested for three times it resulted in wrong macro.
- When method arguments conflict with any attributes of `FunctionGui`, `magicclass` raised error when recording parameter histories.
- When more than one `magicgui`s were added in a same `magicclass`, only one of them was shown up.

0.4.1

This is the first release for PyPI.

0.4.0

New Features
---------------
- You can make menu bar very easily using `magicmenu` decorator. The newly defined class, `MenuGui`, has almost the same API with `ClassGui`, supports macro recording and interactive with its parent class. See "examples/use_menubar.py" as an example.
- New widgets that are useful for better UI.
- `TupleEdit`, `ListEdit`: Container widgets that composed of same widgets. These widgets are useful for input such as `list[int]`.
- `CheckButton`: Checkable button widget.
- `ListWidget`: Python `list` like widget that can contain any Python objects, with simple API for defining different callbacks, context menus and/or delegates.

Improvements
----------------
- If a method takes only one argument that will be converted to `FileEdit`, it will not create `FunctionGui` but launch file dialog directly.
- `click` wrapper accepts method object, as well as `str`.
- `wraps` method can take `FunctionGui` as the input.

0.3.0

Highlight
----------
Class method `ClassGui.wraps` can make parent namespace discoverable from its children.
When you try to make a nice GUI, you usually have to make many magic-classes inside the main one, while keep their attributes visible from each other. It was very hard to achieve in previous versions.

python
magicclass
class Main:
x = field(int) "global" attribute of GUI

magicclass
class A:
a1 = field(int) "inner" attribute
def main_func(self): ... pre-define here to make sure widgets will be aligned in the correct order in class A.

A.wraps
def main_func(self): ... self is always Main object but this function will be a method of class A.


Value changed event can be connected to functions much easier now, using `MagicField.connect` method.

python
magicclass
class Main:
x = field(int)

x.connect
def _callback(self):
This function will be called on value change of x.
To avoid being converted into push button, add "_".


Changes
---------
- When magic-classes is nested, parent magic-classes are accessible from their children via `__magicclass_parent__` attribute.
- ⚠️ `field` now always returns `Widget`.
`self.i = field(int)` used to return integer which is connected to its corresponding widget value changes. This is because I thought it should be convenient to be able to get the value via `self.i`. However, this design turned out to restrict the value like a read-only property since it is usually hard to set value to the widget. Now you always need to use `self.i.value` to get the value.
- `click` wrapper can change properties of buttons in other nested magic-class. If class A and B are nested in class Main, then `A.xx` is accessible from class Main by `click("A.xx")`, and is also accessible from class B by `click(".A.xx")`.

Bug fixes
----------
- Method wrappers in "wrapper.py" were not working correctly when more than one wrapper is called on the same method.
- `magicclass` decorator received wrong line number if nested.
- Macro was not correctly recorded if child magic-classes are constructed inside their parent.

0.2.0

Highlights
-----------
Now you can **add non-button widgets** easily with `field` function, in a way similar to `dataclass`. Following code:

python
magicclass
class C:
i = field(int)
s = field("some string")


will create a `Slider` widget, whose value is connected to `self.i`, and a `LineEdit` widget, whose value is connected to `self.s`. Since `field` function can remember the line number of itself, all the widgets are sorted in the same order as in the source code.
(In the previous version you had to call `magicgui` inside `__post_init__` and append the widget to the magic-class)

Also, **macro recording** is working! Inspired by Julia language, I implemented `Expr` class to make function calls and value setting programmable. Executable Python scripts will be automatically recorded and you can see it by calling `create_macro()` method of magic-class.

Changes
---------
- Updated API for magicgui==0.2.11
- Confirmed compatibility of `magicgui` inside a magic-class.
- Confirmed compatibility of nested magic-class.
- Make `dataclass` as compatible as possible.
- Do not add too many labels.
- Renamed `BaseGui` to `ClassGui` for consistency with `FunctionGui`.
- Simple logger is available, but still work in progress. With `debug()` context manager you can open a logger window.
- Result widget, like `FunctionGui`.

Bug Fixes
----------
- Parameter history was not correctly recorded if magic-class is used in napari.

0.1.0

This is the first minor release. It's much easier to customize buttons and their actions.

New Features
---------------
- Wrapper functions that can set attributes to push buttons itself.
- `set_options` can change parameter options of method arguments just like `magicgui`.
- `click` can set button properties related to clicking, or connect special behaviors to button click event, such as disabling or hiding buttons.
- `button_design` can change the design of push buttons. Currently support button size including min/max, font size, font family, text color, background color, icon and icon size.
- `__post_init__` method can be called after `__init__`.
- This is useful when you want to append other widgets after all the methods are converted to buttons (If `self.append` is called inside `__init__` then the widget will appear on the top of the main widget).
- Custom widgets (`Figure` and `Separator`) are available in `magicclass.widgets`.
- `Figure` is a `matplotlib` figure canvas widget. You can directly append it to `Container` widgets.
- `Separator` is a simple separator.
- You can suppress popup by the option `magicclass(popup=False)`.

Improvements
----------------
- Methods are sorted in the same order as the order in the source code.
- Each method remembers the last input and will be recalled on the next function call.
- `napari.Viewer` was imported in a weird timing. Now it's fixed.

Bug fixes
----------
- Jupyter froze when GUI is build for the second time.
- Could not add multiple dock widgets to `napari`.

Page 10 of 11

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.