Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] IPyWidgets Backend for TraitsUI #469

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
edd78d1
Initial commit of ipywidgets toolkit code.
corranwebster Jul 14, 2018
be0f877
WIP: First cut of bool and text editors.
prabhuramachandran Jul 15, 2018
1e12dcf
First working widgets.
corranwebster Jul 15, 2018
9017638
Test Jupyter notebook.
corranwebster Jul 15, 2018
a73b3f2
Get grid layouts working.
corranwebster Jul 15, 2018
60ca4a9
Add button_editor file
ku-ya Jul 15, 2018
2ffcfb4
More work on getting things up and running. Tabbed and VFold now work.
corranwebster Jul 15, 2018
1c4c74d
ENH: add html editor for ipywidgets
ku-ya Jul 15, 2018
23b8535
CLN: remove button editor from ipywidgets
ku-ya Jul 15, 2018
285e634
FLK: remove unused import
ku-ya Jul 15, 2018
8844c59
Merge pull request #470 from enthought/enh/ipywidgets-html-editor
corranwebster Jul 15, 2018
d5b6d62
Adding a range editor.
prabhuramachandran Jul 21, 2018
e622c7b
Adding a very simple button editor.
prabhuramachandran Jul 22, 2018
21e7529
Update notebook with more traits.
prabhuramachandran Jul 22, 2018
c9bc71c
Allow traits object to be immediately displayed.
prabhuramachandran Jul 22, 2018
9627db2
Mirror changes in #473.
prabhuramachandran Jul 25, 2018
a37da63
First cut at image support for IPyWidgets (untested).
corranwebster Jul 30, 2018
913c5c8
Get image editor working.
corranwebster Jul 13, 2019
b1c6069
First attempt at a date editor.
corranwebster Jul 13, 2019
8babcf8
Merge branch 'master' into feature/ipywidgets-backend
corranwebster Jul 13, 2019
8d212fc
Add stubbed-out pyface action API to avoid import errors.
corranwebster Jul 13, 2019
398f41b
Clean up HasTraits patching.
corranwebster Jul 13, 2019
1f90ac9
Better way of adding Jupyter HTML rendering of traits.
corranwebster Jul 13, 2019
02f3d97
Merge branch 'master' of github.com:enthought/traitsui into feature/i…
Apr 27, 2021
a166c26
FIX : Ignore flake8 errors in traitsui.ipywidgets for now
Apr 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exclude =
traitsui/list_str_adapter.py,
traitsui/menu.py,
traitsui/null,
traitsui/ipywidgets,
traitsui/qt4/__init__.py,
traitsui/qt4/array_editor.py,
traitsui/qt4/basic_editor_factory.py,
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ def additional_commands():
'wx = traitsui.wx:toolkit',
'qt = traitsui.qt4:toolkit',
'null = traitsui.null:toolkit',
'ipywidgets = traitsui.ipywidgets:toolkit',
],
'pyface.toolkits': [
'ipywidgets = traitsui.ipywidgets:toolkit',
],
'etsdemo_data': [
'demo = traitsui.extras._demo_info:info',
Expand Down
236 changes: 236 additions & 0 deletions traitsui/ipywidgets/TestIPyWidgets.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from traits.etsconfig.api import ETSConfig\n",
"\n",
"ETSConfig.toolkit = 'ipywidgets'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from traits.api import HasTraits, Unicode, Bool, Int, Range, Button\n",
"\n",
"from traitsui.group import VGroup, Tabbed, VFold, VGrid\n",
"from traitsui.item import Item\n",
"from traitsui.view import View\n",
"from traitsui.ui import UI"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class TestObjInline(HasTraits):\n",
" text = Unicode\n",
" boolean = Bool\n",
" integer = Int\n",
" rng = Range(0, 100, 10)\n",
" large_range = Range(0.0, 10000000.0, 1.0)\n",
" button = Button('Click me!')\n",
"\n",
" view = View(\n",
" Tabbed(\n",
" VGroup(\n",
" Item(label='test'),\n",
" Item('text'),\n",
" Item('rng'),\n",
" Item('large_range'),\n",
"# Item('button'),\n",
" label=\"Tab 1\",\n",
" ),\n",
" VGroup(\n",
" Item('boolean'),\n",
" Item('integer'),\n",
" label=\"Tab 2\"\n",
" ),\n",
" ),\n",
" )\n",
"\n",
" def _button_fired(self):\n",
" print(\"Clicked\")\n",
" self.integer += 1\n",
" self.large_range += 1.0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t1 = TestObjInline()\n",
"t1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class TestObj(HasTraits):\n",
" text = Unicode\n",
" boolean = Bool\n",
" integer = Int\n",
"\n",
"test_obj = TestObj()\n",
" \n",
"test_view = View(\n",
" Tabbed(\n",
" VGroup(\n",
" Item(label='test'),\n",
" Item('text'),\n",
" label=\"Tab 1\",\n",
" ),\n",
" VGroup(\n",
" Item('boolean'),\n",
" Item('integer'),\n",
" label=\"Tab 2\"\n",
" ),\n",
" ),\n",
")\n",
"ui = test_obj.edit_traits(view=test_view, kind='live')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(ui.control)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = ui.control\n",
"t"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_obj.configure_traits(view=test_view, kind='live')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_obj.text"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_obj.text = \"Other way\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_obj.boolean"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_obj.integer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_obj.integer = 100"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_obj.boolean = True"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import GridBox, Button, ButtonStyle, Layout\n",
"gb = GridBox(children=[Button(layout=Layout(width='auto', height='auto'),\n",
" style=ButtonStyle(button_color='darkseagreen')) for i in range(9)\n",
" ],\n",
" layout=Layout(\n",
" width='50%',\n",
" grid_template_columns='100px 50px 100px',\n",
" grid_template_rows='80px auto 80px',\n",
" grid_gap='5px 10px')\n",
" )\n",
"gb"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
5 changes: 5 additions & 0 deletions traitsui/ipywidgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

from .toolkit import GUIToolkit

# Reference to the GUIToolkit object for IPyWidgets.
toolkit = GUIToolkit('traitsui', 'ipywidgets', 'traitsui.ipywidgets')
Empty file.
14 changes: 14 additions & 0 deletions traitsui/ipywidgets/action/menu_bar_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pyface.action.action_manager import ActionManager


class MenuBarManager(ActionManager):
""" A menu bar manager realizes itself in a menu bar control. """

# ------------------------------------------------------------------------
# 'MenuBarManager' interface.
# ------------------------------------------------------------------------

def create_menu_bar(self, parent, controller=None):
""" Creates a menu bar representation of the manager. """
# IPyWidgets doesn't currently support menus.
pass
41 changes: 41 additions & 0 deletions traitsui/ipywidgets/action/menu_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pyface.action.action import Action
from pyface.action.action_manager import ActionManager
from pyface.action.action_manager_item import ActionManagerItem
from traits.api import Unicode, Instance


class MenuManager(ActionManager, ActionManagerItem):
""" A menu manager realizes itself in a menu control.
This could be a sub-menu or a context (popup) menu.
"""

# 'MenuManager' interface -----------------------------------------------

#: The menu manager's name
name = Unicode

#: The default action for tool button when shown in a toolbar (Qt only)
action = Instance(Action)

# ------------------------------------------------------------------------
# 'MenuManager' interface.
# ------------------------------------------------------------------------

def create_menu(self, parent, controller=None):
""" Creates a menu representation of the manager. """
# IPyWidgets doesn't currently support menus.
pass

# ------------------------------------------------------------------------
# 'ActionManagerItem' interface.
# ------------------------------------------------------------------------

def add_to_menu(self, parent, menu, controller):
""" Adds the item to a menu. """
# IPyWidgets doesn't currently support menus.
pass

def add_to_toolbar(self, parent, tool_bar, image_cache, controller,
show_labels=True):
""" Adds the item to a tool bar. """
pass
33 changes: 33 additions & 0 deletions traitsui/ipywidgets/action/tool_bar_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pyface.action.action_manager import ActionManager
from traits.api import Bool, Enum, Str, Tuple


class ToolBarManager(ActionManager):
""" A tool bar manager realizes itself as a tool bar widget.
"""

# 'ToolBarManager' interface -----------------------------------------------

#: The size of tool images (width, height).
image_size = Tuple((16, 16))

#: The toolbar name (used to distinguish multiple toolbars).
name = Str('ToolBar')

#: The orientation of the toolbar.
orientation = Enum('horizontal', 'vertical')

#: Should we display the name of each tool bar tool under its image?
show_tool_names = Bool(True)

#: Should we display the horizontal divider?
show_divider = Bool(True)

# ------------------------------------------------------------------------
# 'ToolBarManager' interface.
# ------------------------------------------------------------------------

def create_tool_bar(self, parent, controller=None):
""" Creates a tool bar. """
# IPyWidgets doesn't currently support toolbars.
pass
Loading