Skip to content

Releases: hanjinliu/magic-class

v0.6.0

12 Mar 13:38
Compare
Choose a tag to compare

New Features

  • Function call will be recorded in macro even if it is called programmatically. Accordingly, macro history is newly introduced to avoid recording too much.
  • Even if a sub magic class is defined outside the main magic class and used as a part of it, class will be copied and name space is correctly modified. Now you don't have to literally nest classes. Instead of
    @magicclass
    class Main:
        @magicclass
        class A:
            ...
    you can define them separately to keep codes clean.
    @magicclass
    class A:
        ...
    
    @magicclass
    class Main:
        A_widget = A
  • Logger widget is available in magicclass.widgets. This is a very powerful widget for outputs. You can stream print, logging outputs into the widget using context manager logger.set_stdout() and logger.set_logger(), or plt.plot in this widget just like inline plot using logger.set_plt().
  • Fields can be created if widget_type is specified.
  • Useful types in magicclass.types. If List, Tuple or Optional is imported from this submodule, these type annotations will be recognized by @magicgui and converted into ListEdit, TupleEdit and OptionalWidget respectively. These are temporary ones and may be replaced by magicgui in the future.
  • RangeSlider and FloatRangeSlider are available in magicclass.widgets. These are temporary ones and may be replaced by magicgui in the future.

Bug fixes

  • Sub widgets were sometimes completely hidden if closed in napari.
  • If multiple viewers are created, macro did not work.

Changes

  • __call__ will not be converted to widget because it is meaningless.
  • Macro recording of function calls.
  • Some types and variables such as Bound will be deleted from the main module. They should be imported from submodules from now on. DeprecationWarning is raised but will be error in the future.

v0.5.22

28 Feb 05:15
Compare
Choose a tag to compare

New Features

  • xticks and yticks are available in Figure widget, just like plt.xticks and plt.yticks.
  • Initial support of vispy for mini-viewer. Available in magicclass.ext.vispy.

Improvements

  • Inherit style sheet from toolbar to menu hidden in tool buttons.
  • Remove underscores in nested menus.
  • Warn on widget creation if set_options got parameters that do not exists in the wrapping function.
  • "choices" option did not work in some nested class.
  • Remove duplicated __magicclass_children__.
  • Now mypy can correctly resolve typing defined by Bound.
  • Ensure ui["x"] returns a widget (previously returns widget value if x is a MagicValueField).
  • Fix inconsistency in field names.

v0.5.21

20 Feb 05:27
Compare
Choose a tag to compare

New Features

  • OptionalWidget is available for methods that have optional arguments with None as the default .
    from magicgui import magicgui
    from magicclass import Optional
    
    @magicgui
    def func(x: Optional[int] = None):
        print(x)
    Currently you have to import Optional type from magicclass but may also work with typing.Optional or int | None in the future.
  • The "choices" option in categorical widgets can be used with instance methods. See document for the detail.
  • enabled argument in field and vfield.

Important Changes

  • The btn_text in containers are deprecated now in favor of text.
  • Bound(...) no longer works because the Bound type is a generic alias now. You should use Bound[...] instead.
  • Widget alignment of ScrollableContainer is changed to Qt.AlignTop.
  • Delete imports from magicgui.events. Now all the warnings of callbacks will raise errors.
  • The type_matching submodule is removed. Similar method may be implemented in magicgui.

Bug Fixes

  • Use custom merge_super_sigs for correct module updates.
  • Some event emissions in ColorEdit and ColorSlider were broken.
  • MagicField did not work in Python 3.10 due to wrong tox settings.
  • Resolve QColor warnings.

v0.5.20

04 Feb 08:32
Compare
Choose a tag to compare

New Features

  • New widgets SpreadSheet, ColorEdit, ColorSlider are available in magicclass.widgets.
  • "Show traceback" button in error message box.

Bug Fixes

  • Ignore property in menu and toolbar.
  • Ignore classmethod.
  • Macro was not locked in callbacks of fields.
  • Make LiteralEvalLineEdit compatible with magic classes.
  • Text was not correctly set in widget actions.

v0.5.19

26 Jan 12:22
Compare
Choose a tag to compare

Highlights

  • New method find_ancestor is available for any magic classes. ui.find_ancestor(X) will return an widget of X if it is a parent of ui. This will be an alternative way to get access to parents, instead of using @wraps.
  • At proper timing, macro recorders for napari types (Viewer and Layer types) will be loaded. They will be recorded like viewer.layers["name"] by default.
  • Class inheritance is supported in most cases. It safe to define methods, fields or nested classes in the base class and create multiple magic subclasses. See the document for details.

New Features

  • find_ancestor method to search for parent widget.
  • The matplotlib's widget Figure in magicclass.widgets now has many methods similar to those used with plt. You can use such as widget.plot(...) (corresponds to plt.plot) and widget.xlim(...) (corresponds to plt.xlim) instead of widget.ax.plot() (correspond to ax.plot).
  • Load macro recorders for napari types.
  • @nogui decorator is available. Methods decorated with this will not be converted to widgets.
  • Initial support for stylesheet templates.
  • Add weak reference of parent widget to FunctionGuiPlus widgets.
  • Experimental support of add_dock_widget and remove_dock_widget methods for widget_type="mainwindow".
  • Avoid recording macro if function call ended with an exception.
  • New mode @magicclass(error_mode="stdout"). In this mode error will be printed.

Improvements

  • Don't convert private methods into widgets (previously they were converted but not added).
  • Raise clearer error in FreeWidget if subclasses are not initialized correctly.
  • Support class inheritance.

Bug Fixes

  • ListDataView was not recorded in macro correctly.
  • tqdm.ProgressBar was not updating.
  • Safely append functions after widget construction.
  • Callbacks of container variations was not called.
  • Macro recording of Enum was not correct in some cases.

v0.5.18

19 Jan 09:17
Compare
Choose a tag to compare

New Features

  • collapsed property in collapsible containers. It enables expanding/collapsing widgets programmatically, by such as ui.collapsed = True.
  • When a magic class has multiple classes decorated with @magictoolbar, then toolbars will be tabified.
  • You can change the initial visibility of a widget by option @magicclass(visible=False).
  • FrameContainer is available, which is similar to GroupBoxContainer but does not have title on its top. Available via @magicclass(widget_type="frame").
  • Make copies of method using wraps decorator, using keyword argument @wraps(copy=True) or without it if multiple @wraps decorate the same method.
  • "Execute selected lines" action in macro widget.
  • magicclass.tqdm extends tqdm usage in magicgui.tqdm, which makes ProgressBar more useful in magic classes.
  • New option set_options(labels=False) similar to magicgui(labels=False).
  • @confirm decorator is added (experimentally though). Method decorated with @confirm("xxx") will open a GUI that confirms whether it's OK to run function.

Bug Fixes and Improvements

  • Adding menu bar and/or toolbar to certain type of containers did not work. Now works with any widgets. This bug fix includes improvement in containers that have scroll area. Menu bar and toolbar will be added outside the scroll area so that they are always visible.
  • Many improvements in type annotation of field and vfield.
  • core.pyi was not installed.
  • Many fixes in type annotation of magicclass and other relevant functions.
  • GUI took very long time to show up when napari is installed because the contents of napari happened to be imported in show() method.
  • Use object.__setattr__ instead of setattr to make widget construction a little bit faster.
  • The current_index property of tabbed container was broken.
  • Remove matplotlib dependency.

v0.5.17

13 Jan 15:46
Compare
Choose a tag to compare

This release fixed an important bug in v0.5.16.

Bug Fixes

  • NameError when optional packages are not installed.
  • labels=False option in menu bar and toolbar took no effect.

Changes

  • All the extended widgets such as QtConsole and QtPlotCanvas are moved to magicclss.ext submodule. They are no longer available in magicclass.widgets.

Improvements

  • Better typing in MagicField. For instance, if you have a field f = field(SpinBox) then type checker knows that f will be a SpinBox when accessed via GUI instance.
  • Containers with scroll area (magicclass options widget_type="scrollable" or widget_type="draggable") will assign menu bar and tool bar outside their scroll area so that menu bar and tool bar are always visible.

v0.5.16

09 Jan 13:51
Compare
Choose a tag to compare

New Features

  • New methods add_text, add_infline in pyqtgraph based widgets.
  • Initial support for pyvista (WIP). Available in magicclass.widgets
  • Both menu and toolbar can be defined in non-main window.
  • set_options can take auto_call, call_button, layout arguments.

Bug Fixes

  • MagicField callback bug fix.
  • Toolbar updates its style sheet when added to napari viewer.
  • Update FunctionGui categorical widgets hidden in buttons and actions.

v0.5.15

03 Jan 12:03
Compare
Choose a tag to compare

New Features

  • Many updates in pyqtgraph based widgets.
    • QtPlotCanvas supports histogram and bar plot. It also has a linear region item in canvas.region by default.
    • QtImageCanvas has scale bar by default. The LUT histogram is hidden by the button on the upper-left corner now.
    • Much more unified API between line plot item, scatter plot item and others, such as face_color, edge_color and symbol.
    • QtMultiPlotCanvas, QtMultiImageCanvas can contain multiple plots and images in a single widget.
    • Qt2YPlotCanvas has two Y-axis and shared X-axis.
  • to_napari function is available in magicclass.ext submodule. Any magic classes, no matter it is a widget or a menu, can directly docked into napari viewer by simple syntax:
    from magicclass.ext import to_napari
    @to_napari
    @magicclass
    class A: ...
  • Now functions can be converted into buttons or menus after construction of magic classes. This also follows the magicgui's typing rule.
    def func(a: int): ...
    ui.Menu.append(func)  # this code will create a new action in Menu.

Changes

  • parent_viewer finds viewer ancestor in a safer way now. It uses napari's method so that it will also work with newer napari in the future.
  • Use pyi file to improve code completion.

v0.5.14

17 Dec 15:18
Compare
Choose a tag to compare

New Features

  • magictoolbar creates a ToolBarGui, which appears as a tool bar on the top of a widget. It is inter-nestable with magicmenu.
  • Horizontal collapsible container using widget_type="hcollapsible".
  • Automatically determine how to execute QApplication. In the previous versions you had to add such as input() to prevent application exiting immediately if you ran a ".py" file with python command. Now you don't have to do that.
  • Icon supports in many widgets.
  • icon_path is now a universal option for widgets and fields. It can be used as @magicclass(icon_path="..."), field(int, options={"icon_path": "..."}).
  • ConsoleTextEdit has new property tab_size, with which you can set the size of tab.

Bug Fixes

  • Checkable actions in menus were not working.
  • wraps was not working when a magic class was defined locally.

Others

  • Added many tests.
  • Remove matplotlib dependency.