Skip to main content

build GUIs from functions, using magic

Project description

icon

License Version conda-forge Python Version Build Status codecov

magicgui: build GUIs from functions, using magic.

📖 Docs

Installation

magicgui uses qtpy to support both pyside2 and pyqt5 backends. However, you must have one of those installed for magicgui to work.

install with pip

pip install magicgui[pyqt5]
# or
pip install magicgui[pyside2]

or with conda:

conda install -c conda-forge magicgui pyqt  # or pyside2 instead of pyqt

:information_source: If you'd like to help us extend support to a different backend, please open an issue.

Basic usage

from magicgui import magicgui
from enum import Enum

class Medium(Enum):
    Glass = 1.520
    Oil = 1.515
    Water = 1.333
    Air = 1.0003

# decorate your function with the @magicgui decorator
@magicgui(call_button="calculate", result_widget=True)
def snells_law(aoi=30.0, n1=Medium.Glass, n2=Medium.Water, degrees=True):
    import math

    aoi = math.radians(aoi) if degrees else aoi
    try:
        result = math.asin(n1.value * math.sin(aoi) / n2.value)
        return math.degrees(result) if degrees else result
    except ValueError:
        return "Total internal reflection!"

# your function is now capable of showing a GUI
snells_law.show(run=True)

snells

But that's just the beginning! Please see Documentation for many more details and usage examples.

Contributing

Contributions are welcome!

Please note: magicgui attempts to adhere to strict coding rules and employs the following static analysis tools to prevent errors from being introduced into the codebase:

To prevent continuous integration failures when contributing, please consider installing pre-commit in your environment to run all of these checks prior to checking in new code.

pre-commit install

Changelog

v0.2.9 (2021-04-05)

Full Changelog

v0.2.9 is a minor feature & bugfix release.

The most noticeable new feature is that Slider widgets now show their current value with an (editable) spinbox (#211). To hide the readout widget on a Slider, use readout=False. The Table widget has also been given a .changed event emitter that will emit a dict of information about the cell being edited (#209)

This release also fixes a couple event issues with FileDialogs, and some layout issues with RadioButtons.

Implemented enhancements:

  • Display slider current value and range min/max in the magicgui widget #19
  • Display current slider value (editable) #211 (tlambert03)
  • Add table.changed event emitter #209 (tlambert03)
  • Coerce RadioButton with Enum/choices to RadioButtons #202 (tlambert03)
  • Compute correct widget width for rich text labels #199 (maweigert)

Fixed bugs:

  • FileEdit changed event value wrong #204
  • Radiobuttons are duplicated during reset\_choices in Qt <5.15.2 #197
  • Tests fail when both PySide2 and PyQt5 are installed in the test env #196
  • Fix tests when both pyside2 and pyqt5 are installed #210 (tlambert03)
  • Disconnect filedialog button from value.changed events #208 (tlambert03)
  • Fix persist issue with cached parameter that has been removed #203 (uschmidt83)
  • Delete button when removing from qt RadioGroup #198 (tlambert03)

Closed issues:

  • Add table-cell change callbacks #205
  • Update widget interactively #190

Merged pull requests:

v0.2.8 (2021-03-24)

Full Changelog

v0.2.8 is a minor feature & bugfix release including:

  • a new widgets.RadioButtons widget. Uses the same "CategoricalWidget" API as ComboBox, but presents options as a group of RadioButtons.
  • fixes some issues with event emission in FileEdit dialogs
  • undoes a bug introduced by changing the text in the call button while the function is running.

Implemented enhancements:

  • Update call button to default True when auto_call is False #194 (jni)
  • add RadioButtons widget #183 (tlambert03)

Fixed bugs:

  • Duplicate change events for RadioButtons widget #188
  • Magicgui 0.2.7 update broke affinder — missing required argument despite binding #179
  • small decimals not working in Qt Backend #177
  • FunctionGuis added to containers not showing when container is shown #174
  • Parameter value persistance causes error with napari layers as parameter types #169
  • Better error message on bad keyword argument to magicgui #165
  • fix enum choices in radiobuttons #201 (tlambert03)
  • Fix RadioButtons double event emissions #189 (tlambert03)
  • don't ever change the call_button text silly #180 (tlambert03)
  • Fix extreme float values for slider and spinbox #178 (tlambert03)
  • Fix FileEdit events #176 (tlambert03)
  • fix nested functiongui show #175 (tlambert03)
  • Fail gracefully with persistence errors, better debounce #170 (tlambert03)

Closed issues:

  • tooltips for magic_factory gui #172

Merged pull requests:

v0.2.7 (2021-02-28)

Full Changelog

v0.2.7 is a minor feature & bugfix release including:

  • parameter value persistence: use @magicgui(persist=True) to store the values in the GUI to disk when they are changed, and restore them when the GUI is recreated in a future session (#160).
  • a preliminary Image widget magicgui.widgets.Image. Requires pip install magicgui[image] to work (#140)
  • adds a widget_init parameter to magic_factory... useful for connecting events and such after a factory creates a new widget instance (#159).
  • fixes a bug when a parameter-less function is used with call_button=True (#149)
  • fixes FileEdit used with directory mode
  • fixes a bug in Range/SliceEdits

Implemented enhancements:

Fixed bugs:

  • RangeEdit and SliceEdit behave unexpectedly #162
  • "No module named numpy" #161
  • FileEdit widget error with mode='d' #156
  • Cannot connect event callbacks to MagicFactory #155
  • Core dump error when running example napari parameter sweep #153
  • decorating a function that uses napari.viewer.add\_points with magicgui generates a Shader compilation error #147
  • vertical layout with no widgets error in \_unify\_label\_widths #146
  • annotating an argument as magicgui.types.PathLike does not create a files widget #144
  • Label option for boolean parameters has no effect #109
  • fix range/slice edits #166 (tlambert03)
  • Work without numpy #164 (tlambert03)
  • Fix FileEdit with directory mode #158 (tlambert03)
  • fix function with no params and callbutton #149 (tlambert03)
  • Fix typesafety checks with numpy 1.20 #141 (tlambert03)
  • Disable call button while function is running #139 (tlambert03)

Closed issues:

  • Contrib module #40

Merged pull requests:

v0.2.6 (2021-01-25)

Full Changelog

v0.2.6 is a significant feature release, introducing a number of new widgets and APIs:

  • New Table Widget allowing easy creation and modification of Table UIs using a variety of pure python types as input (#61)
  • Tooltips for each widget in a @magicgui are now automatically taken from docstrings (numpy, google, and sphinx-rst format accepted)(#100)
  • New ProgressBar widget (#104) and magicgui.tqdm wrapper (#105) allow both manual and automatically-added progress bars to long-running iterator-based functions. magicgui.tqdm.tqdm acts as a drop-in replacement for tqdm.tqdm that will fall back to the standard (console output) behavior if used outside of a magicgui function, or inside of a magicgui widget that is not yet visible.
  • New MainWindow/MainFunctionGui subclasses allow creating top level "application" windows, with a basic API for adding items to the application menubar (#110).
  • The new @magic_factory decorator creates a callable that, when called, returns a FunctionGui instance (as opposed to @magicgui which immediately creates the FunctionGui instance. Think of this as returning a "class" as opposed to returning an "instance":
    @magic_factory(call_button=True)
    def my_factory(x: int, y = 'hi'):
        ...
    
    # can add to or override original factory arguments
    widget = my_factory(main_window=True)
    widget.show()
    
  • "vertical" is now the default layout for Containers and magicgui widgets.

Merged pull requests:

v0.2.5 (2021-01-13)

Full Changelog

v0.2.5 greatly improves support for binding a value or a callback to a function parameter, and fixes a bug in recursively updating categorical widgets nested deeply inside of a container.

Merged pull requests:

v0.2.4 (2021-01-12)

Full Changelog

Merged pull requests:

  • Extend combobox api with set_choice, get_choice, del_choice #92 (tlambert03)

v0.2.3 (2021-01-08)

Full Changelog

v0.2.3 adds two new widgets DateEdit and TimeEdit (for datetime.date and datetime.time types respectively), in addition to the existing DateTimeEdit widget. It also continues to improve warnings and deprecation messages from the v0.2.0 release.

Fixed bugs:

  • magicgui.widgets.CategoricalWidget not found in magicgui 0.2.1 #81

Closed issues:

  • QTimeEdit widgets #78

Merged pull requests:

v0.2.2 (2021-01-02)

Full Changelog

Merged pull requests:

v0.2.1 (2020-12-29)

Full Changelog

v0.2.1 fixes some issues with the 0.2.0 release. ForwardRef annotations are now resolved automatically on both parameter and return type annotations. And the orientation parameter on Container widgets (such as those returned by the magicgui decorator) has been renamed back to layout as in <v0.2.0. Test coverage is also improved.

Fixed bugs:

  • napari examples in the docs are broken #72
  • Functions without arguments are not finding napari parent widgets #64
  • "Layout" parameter doesn't work anymore in recent dev version #54

Closed issues:

  • Should we permanently resolve ForwardRef type annotations? #65
  • Need consensus on "layout" vs "orientation" #63

Merged pull requests:

v0.2.0 (2020-12-26)

Full Changelog

v0.2.0 includes a complete rewrite of magicgui. The primary goals were as follows:

  • make a clean separation between the Qt backend and the end-use API, clarifying the interface that a backend must implement in order to work with magicgui
  • create a "direct API" that enables procedural widget creation, with the potential for subclassing and custom widget creation
  • create a more direct link between an individual widget and an inspect.Parameter object, and a collection or layout of widgets and an inspect.Signature object.

See PR #43 for full details of the rewrite.

Deprecations and possible breaking changes!

Some of the API has been deprecated or changed, though an attempt was made to make the pre-0.2.0 API still work (with warnings). Please see the v0.2.0 migration guide for details.

Lastly, we have new documentation, using the amazing jupyter-book project! Note the new url at https://napari.org/magicgui

Implemented enhancements:

  • Provide more direct "autowidget generation" without requiring function body. #7

Fixed bugs:

  • call_button not responding #44
  • Removal of docks: are widgets singletons? #28

Closed issues:

  • Enable magicgui decorator on class member functions #53
  • Recognize widget types as strings #47
  • Recognize napari layer types as strings #46
  • Widget label editable #45
  • Add support for Annotated type #34
  • Pull signature parsing code from MagicGuiBase #33

Merged pull requests:

v0.1.6 (2020-07-23)

Full Changelog

Implemented enhancements:

  • Use eval'd text box as fallback when type inference fails #29

Closed issues:

  • conda recipe #21
  • Feature request: support for QFileDialog (file and directory choosers) #20
  • Unable to visualize QBoxlayout nor QTable #12

Merged pull requests:

v0.1.5 (2020-05-24)

Full Changelog

Fixed bugs:

  • Error running examples #6

Closed issues:

  • Automagically add labels per field #13

Merged pull requests:

v0.1.4 (2020-05-19)

Full Changelog

Merged pull requests:

v0.1.3 (2020-05-04)

Full Changelog

Merged pull requests:

v0.1.2 (2020-03-06)

Full Changelog

Closed issues:

  • Register callbacks on return types #3

Merged pull requests:

v0.1.1 (2020-02-19)

Full Changelog

Merged pull requests:

v0.1.0 (2020-02-18)

Full Changelog

Merged pull requests:

v0.0.8 (2020-02-11)

Full Changelog

v0.0.7 (2020-02-09)

Full Changelog

v0.0.6 (2020-02-09)

Full Changelog

* This Changelog was automatically generated by github_changelog_generator

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

magicgui-0.2.9.tar.gz (20.8 MB view hashes)

Uploaded Source

Built Distribution

magicgui-0.2.9-py2.py3-none-any.whl (123.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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