Skip to content

Commit

Permalink
Merge pull request enthought#96 from enthought/fix-examples
Browse files Browse the repository at this point in the history
Fix traitsui examples.
  • Loading branch information
Pietro Berkes committed Mar 8, 2013
2 parents 351f1e4 + e363c62 commit 53faa74
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 26 deletions.
1 change: 0 additions & 1 deletion examples/demo/Advanced/Apply_Revert_handler_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class ApplyRevertDemo(HasTraits):
height = 300,
title = 'Apply/Revert example',
buttons = [ 'Apply', 'Revert' ],
kind = 'modal',
handler = ApplyRevert_Handler
)

Expand Down
2 changes: 2 additions & 0 deletions examples/tutorials/doc_examples/examples/enum_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ class EnumExample(HasTraits):
'Low' : '4:Low',
'Lowest' : '5:Lowest', })))


EnumExample().configure_traits()
11 changes: 4 additions & 7 deletions examples/tutorials/doc_examples/examples/include_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@

# include_extra.py --- Example of Include object
# provided for subclasses
from traits.api import HasTraits, Int, Str, Trait
from traits.api import HasTraits, Int, Str
from traitsui.api import Group, Include, View
import traitsui

class Person(HasTraits):
name = Str
age = Int

person_view = View('name', Include('extra'), 'age',
kind='livemodal')

Person().configure_traits()
person_view = View('name', Include('extra'), 'age')

class LocatedPerson(Person):
street = Str
Expand All @@ -24,5 +20,6 @@ class LocatedPerson(Person):

extra = Group('street', 'city', 'state', 'zip')

LocatedPerson().configure_traits()

Person().configure_traits()
LocatedPerson().configure_traits()
8 changes: 4 additions & 4 deletions examples/tutorials/doc_examples/examples/override_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

# override_editor.py --- Example of overriding a trait
# editor
from traits.api import HasTraits, Trait
import traitsui
from traits.api import HasTraits, Trait, Color
from traitsui.api import ColorEditor
from wxPython import wx

class Polygon(HasTraits):
line_color = Trait(wx.wxColour(0, 0, 0),
line_color = Trait(Color((0, 0, 0)),
editor=ColorEditor())

Polygon().configure_traits()
12 changes: 8 additions & 4 deletions examples/tutorials/doc_examples/examples/tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
HGroup, Handler, Group
from traitsui.menu \
import Menu, Action, Separator
from traitsui.wx.tree_editor \
import NewAction, CopyAction, CutAction, \
PasteAction, DeleteAction, RenameAction

try:
from traitsui.wx.tree_editor \
import NewAction, CopyAction, CutAction, \
PasteAction, DeleteAction, RenameAction
except RuntimeError:
from traitsui.qt4.tree_editor \
import NewAction, CopyAction, CutAction, \
PasteAction, DeleteAction, RenameAction
#--[Code]-----------------------------------------------------------------------

# DATA CLASSES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# attribute of a class
from traits.api import HasTraits, Int, Str, Trait
from traitsui.api import View
import traitsui

class Person(HasTraits):
first_name = Str
Expand Down
2 changes: 0 additions & 2 deletions examples/tutorials/doc_examples/examples/view_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import wx
from traits.api import HasTraits, Int, Str, Trait
from traitsui.api import View
import traitsui

class Person(HasTraits):
first_name = Str
Expand Down Expand Up @@ -38,4 +37,3 @@ def OnInit ( self ):

# Main program:
TraitApp( bill, person_view )

5 changes: 2 additions & 3 deletions examples/tutorials/doc_examples/examples/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# License: BSD Style.

# wizard.py ---Example of a traits-based wizard UI
from traits.api import HasTraits, Int, Str, Trait
import traitsui
from traits.api import HasTraits, Int, Str

class Person(HasTraits):
name = Str
Expand All @@ -14,4 +13,4 @@ class Person(HasTraits):
pcode = Str

bill = Person()
bill.configure_traits(kind='modal')
bill.configure_traits()
3 changes: 3 additions & 0 deletions examples/tutorials/traitsui_4.0/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ def _get_sum ( self ):

popup = Adder()


if __name__ == '__main__':
popup.configure_traits()
3 changes: 3 additions & 0 deletions examples/tutorials/traitsui_4.0/deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ def _go_changed ( self ):

demo = Count()


if __name__ == '__main__':
demo.configure_traits()
3 changes: 3 additions & 0 deletions examples/tutorials/traitsui_4.0/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,6 @@ def _team_changed ( self, team ):
teams = [ blue_birds, chicken_hawks, eagles ] )
)


if __name__ == '__main__':
demo.configure_traits()
3 changes: 3 additions & 0 deletions examples/tutorials/traitsui_4.0/model_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ def _get_family ( self ):
# Create the controller for the model:
demo = ChildModelView( model = son )


if __name__ == '__main__':
demo.configure_traits()
11 changes: 7 additions & 4 deletions examples/tutorials/tutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@

from traitsui.wx.extra.windows.flash_editor \
import FlashEditor
wx_available = True
except:
IEHTMLEditor = FlashEditor = None
IEHTMLEditor = HTMLEditor
FlashEditor = ValueEditor # Set this to a random editor to prevent error.
wx_available = False

#-------------------------------------------------------------------------------
# Constants:
Expand Down Expand Up @@ -1312,7 +1315,7 @@ def _add_rst_item ( self, path ):
def _add_swf_item ( self, path ):
""" Creates a description item for a Flash file.
"""
if is_windows:
if is_windows and wx_available:
self.descriptions.append( FlashItem( path = path ) )

def _add_mov_item ( self, path ):
Expand Down Expand Up @@ -1473,7 +1476,7 @@ def _add_description ( self, lines, title ):
settings_overrides = settings )

# Choose the right HTML renderer:
if is_windows:
if is_windows and wx_available:
item = IEHTMLStrItem( content = html, title = title )
else:
item = HTMLStrItem( content = html, title = title )
Expand All @@ -1485,7 +1488,7 @@ def _create_html_item ( self, **traits ):
""" Creates a platform specific html item and adds it to the list of
descriptions.
"""
if is_windows:
if is_windows and wx_available:
item = IEHTMLItem( **traits )
else:
item = HTMLItem( **traits )
Expand Down

0 comments on commit 53faa74

Please sign in to comment.