-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * better error on incorrect protocol * members -> methods * methods * one good working widget * implement lots of widgets * add _IPySupportsText * add note * working container * add notebook example * update notebook * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * kinda working again * fix tests * remove guimodel test * remove comment * add ipywidgets to testing * fix type annotation * Update magicgui/widgets/_bases/button_widget.py Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com> * add extra * fix qwidg * change test * move test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
- Loading branch information
1 parent
284999e
commit 83f9ab0
Showing
12 changed files
with
648 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "1df96bcb5361429faddb252e3acfa608", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"VBox(children=(HBox(children=(Label(value='aoi', layout=Layout(min_width='40px')), FloatText(value=1.0, step=1…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"import math\n", | ||
"from enum import Enum\n", | ||
"\n", | ||
"from magicgui import magicgui, use_app\n", | ||
"use_app(\"ipynb\")\n", | ||
"\n", | ||
"class Medium(Enum):\n", | ||
" \"\"\"Enum for various media and their refractive indices.\"\"\"\n", | ||
"\n", | ||
" Glass = 1.520\n", | ||
" Oil = 1.515\n", | ||
" Water = 1.333\n", | ||
" Air = 1.0003\n", | ||
"\n", | ||
"\n", | ||
"@magicgui(\n", | ||
" call_button=\"calculate\", result_widget=True, layout='vertical', auto_call=True\n", | ||
")\n", | ||
"def snells_law(aoi=1.0, n1=Medium.Glass, n2=Medium.Water, degrees=True):\n", | ||
" \"\"\"Calculate the angle of refraction given two media and an AOI.\"\"\"\n", | ||
" if degrees:\n", | ||
" aoi = math.radians(aoi)\n", | ||
" try:\n", | ||
" n1 = n1.value\n", | ||
" n2 = n2.value\n", | ||
" result = math.asin(n1 * math.sin(aoi) / n2)\n", | ||
" return round(math.degrees(result) if degrees else result, 2)\n", | ||
" except ValueError: # math domain error\n", | ||
" return \"TIR!\"\n", | ||
"\n", | ||
"\n", | ||
"snells_law" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from .application import ApplicationBackend | ||
from .widgets import ( | ||
CheckBox, | ||
ComboBox, | ||
Container, | ||
DateEdit, | ||
DateTimeEdit, | ||
EmptyWidget, | ||
FloatSlider, | ||
FloatSpinBox, | ||
Label, | ||
LineEdit, | ||
LiteralEvalLineEdit, | ||
PushButton, | ||
RadioButton, | ||
Slider, | ||
SpinBox, | ||
TextEdit, | ||
TimeEdit, | ||
get_text_width, | ||
) | ||
|
||
# DateTimeEdit | ||
# show_file_dialog, | ||
|
||
__all__ = [ | ||
"ApplicationBackend", | ||
"CheckBox", | ||
"ComboBox", | ||
"Container", | ||
"DateEdit", | ||
"TimeEdit", | ||
"DateTimeEdit", | ||
"EmptyWidget", | ||
"FloatSlider", | ||
"FloatSpinBox", | ||
"Label", | ||
"LineEdit", | ||
"LiteralEvalLineEdit", | ||
"PushButton", | ||
"RadioButton", | ||
"Slider", | ||
"SpinBox", | ||
"TextEdit", | ||
"get_text_width", | ||
"show_file_dialog", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from magicgui.widgets._protocols import BaseApplicationBackend | ||
|
||
|
||
class ApplicationBackend(BaseApplicationBackend): | ||
def _mgui_get_backend_name(self): | ||
return "ipynb" | ||
|
||
def _mgui_process_events(self): | ||
raise NotImplementedError() | ||
|
||
def _mgui_run(self): | ||
pass # We run in IPython, so we don't run! | ||
|
||
def _mgui_quit(self): | ||
pass # We don't run so we don't quit! | ||
|
||
def _mgui_get_native_app(self): | ||
return self | ||
|
||
def _mgui_start_timer(self, interval=0, on_timeout=None, single=False): | ||
raise NotImplementedError() | ||
|
||
def _mgui_stop_timer(self): | ||
raise NotImplementedError() |
Oops, something went wrong.