Skip to content

Commit

Permalink
Added customized button and fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
romanofski committed Mar 21, 2010
1 parent a7a3275 commit af8acce
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/superorganism/gui/app.txt
Expand Up @@ -46,7 +46,7 @@ widgets on the screen.

We can also change the statusbar text:

>>> view.statusmsg = u'Foobar'
>>> view.widget.set_statusmsg(u'Foobar')
>>> view.render()
(helpbar) Topbar
...
Expand Down
7 changes: 7 additions & 0 deletions src/superorganism/gui/interfaces.py
Expand Up @@ -101,6 +101,13 @@ def set(value):
"""Set the widget text to value."""


class IButton(zope.interface.Interface):
"""Marker interface for a button."""

signals = zope.interface.Attribute(
"A list of signals associated with the button.")


class ITextInputWidget(IFormWidget):
"""A text input widget providing a title and description, as well as
an input field.
Expand Down
19 changes: 11 additions & 8 deletions src/superorganism/gui/projects.py
Expand Up @@ -22,12 +22,11 @@ def run(self):

for key in keys:
self.widget.set_statusmsg('Key: %s' % key)
if (hasattr(widget, 'get_label') and\
widget.get_label().startswith('Save') and key == 'q'):
return zope.component.getMultiAdapter(
(self.context.__parent__, self.screen),
name='dashboard').run()

if superorganism.gui.interfaces.IButton.providedBy(widget):
if (widget.get_label().startswith('Save') and key == 'enter'):
return zope.component.getMultiAdapter(
(self.context.__parent__, self.screen),
name='dashboard').run()
self.widget.keypress(size, key)

def update_widgets(self):
Expand All @@ -40,6 +39,10 @@ def get_form_contents(self):
widgets.append(
zope.component.getMultiAdapter(
(field, self), superorganism.gui.interfaces.IFormWidget))
button = urwid.Button('Save')
widgets.append(button)
widgets.append(
urwid.GridFlow(
[superorganism.gui.widgets.DialogButton("Save"),
superorganism.gui.widgets.DialogButton("Cancel")],
10, 3, 1, 'center'
))
return urwid.SimpleListWalker(widgets)
5 changes: 3 additions & 2 deletions src/superorganism/gui/projects.txt
Expand Up @@ -40,10 +40,11 @@ Paul presses the "p" key which opens the dialog to create a new project:
>>> view = zope.component.getMultiAdapter(
... (project, screen), name='newproject')
>>> view.render()
(helpbar) Topbar
(focus) Projecttitle
...
Project Description
Versions
(background) Project Description
(background) Versions
...

He fills out the fields about `title` (Adult Care) and a `description`.
Expand Down
4 changes: 4 additions & 0 deletions src/superorganism/gui/view.py
Expand Up @@ -14,3 +14,7 @@ def render(self):
size = self.screen.get_cols_rows()
canvas = self.widget.render(size, focus=True)
self.screen.draw_screen(size, canvas)

def update_widgets(self):
# XXX implemented in subclasses
pass
20 changes: 20 additions & 0 deletions src/superorganism/gui/widgets.py
Expand Up @@ -4,6 +4,26 @@
import zope.schema.interfaces


class DialogButton(urwid.Button):

zope.interface.implements(superorganism.gui.interfaces.IButton)

def __init__(self, label, on_press=None, user_data=None):
self._label = urwid.SelectableIcon("", 0)
self._w = urwid.AttrMap(urwid.Columns([
('fixed', 1, urwid.Text("<")),
self._label,
('fixed', 1, urwid.Text(">"))],
dividechars=1), 'button', 'focus')

# The old way of listening for a change was to pass the callback
# in to the constructor. Just convert it to the new way:
if on_press:
connect_signal(self, 'click', on_press, user_data)

self.set_label(label)


class BaseFormWidget(urwid.WidgetWrap):

def __init__(self, field, form):
Expand Down

0 comments on commit af8acce

Please sign in to comment.