Beispiel #1
0
 def __init__ ( self, ui, parent ):
     wx.Dialog.__init__( self, parent, -1, ui.view.title )
     wx.EVT_CLOSE( self, self._on_close_page )
     wx.EVT_CHAR(  self, self._on_key )
     
     history = None
     self.ui = ui
     view    = ui.view
     if view.undo or view.revert or view.ok:
         ui.history = history = UndoHistory()
     
     # Create the actual trait sheet panel and imbed it in a scrollable 
     # window:
     sizer       = wx.BoxSizer( wx.VERTICAL )
     sw          = wx.ScrolledWindow( self )
     trait_sheet = panel( ui, sw )
     sizer.Add( trait_sheet, 1, wx.EXPAND | wx.ALL, 4 )
     tsdx, tsdy = trait_sheet.GetSizeTuple()
     tsdx += 8
     tsdy += 8
     
     max_dy = (2 * screen_dy) / 3
     sw.SetAutoLayout( True )
     sw.SetSizer( sizer )
     sw.SetSize( wx.Size( tsdx + ((tsdy > max_dy) * scrollbar_dx), 
                          min( tsdy, max_dy ) ) )
     sw.SetScrollRate( 16, 16 )
     
     sw_sizer = wx.BoxSizer( wx.VERTICAL )
     sw_sizer.Add( sw, 1, wx.EXPAND )
     
     # Check to see if we need to add any of the special function buttons:
     if (history is not None) or view.help:
         sw_sizer.Add( wx.StaticLine( self, -1 ), 0, wx.EXPAND )
         b_sizer = wx.BoxSizer( wx.HORIZONTAL )
         if view.undo:
             self.undo = self._add_button( 'Undo', self._on_undo, b_sizer, 
                                           False )
             self.redo = self._add_button( 'Redo', self._on_redo, b_sizer, 
                                           False )
             history.on_trait_change( self._on_undoable, 'undoable',
                                      dispatch = 'ui' )
             history.on_trait_change( self._on_redoable, 'redoable',
                                      dispatch = 'ui' )
         if view.revert:
             self.revert = self._add_button( 'Revert', self._on_revert, 
                                             b_sizer, False )
             history.on_trait_change( self._on_revertable, 'undoable',
                                      dispatch = 'ui' )
         if view.ok:
             self._add_button( 'OK', self._on_close_page, b_sizer )
             self._add_button( 'Cancel', self._on_cancel, b_sizer )
         if view.help:
             self._add_button( 'Help', self._on_help, b_sizer )
         sw_sizer.Add( b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5 )
      
     # Lay all of the dialog contents out:            
     sw_sizer.Fit( self )
     self.SetSizer( sw_sizer )
     self.SetAutoLayout( True )
Beispiel #2
0
    def __init__(self, ui, parent):
        wx.Dialog.__init__(self, parent, -1, ui.view.title)
        wx.EVT_CLOSE(self, self._on_cancel)
        wx.EVT_CHAR(self, self._on_key)

        self.ui = ui

        # Create the 'context' copies we will need while editing:
        context = ui.context
        ui._context = context
        ui.context = self._copy_context(context)
        ui._revert = self._copy_context(context)

        # Create the actual trait sheet panel and imbed it in a scrollable
        # window:
        sizer = wx.BoxSizer(wx.VERTICAL)
        sw = wx.ScrolledWindow(self)
        trait_sheet = panel(ui, sw)
        sizer.Add(trait_sheet, 1, wx.EXPAND | wx.ALL, 4)
        tsdx, tsdy = trait_sheet.GetSizeTuple()
        tsdx += 8
        tsdy += 8

        max_dy = (2 * screen_dy) / 3
        sw.SetAutoLayout(True)
        sw.SetSizer(sizer)
        sw.SetSize(
            wx.Size(tsdx + ((tsdy > max_dy) * scrollbar_dx), min(tsdy,
                                                                 max_dy)))
        sw.SetScrollRate(16, 16)

        sw_sizer = wx.BoxSizer(wx.VERTICAL)
        sw_sizer.Add(sw, 1, wx.EXPAND)

        # Create the necessary special function buttons:
        sw_sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
        b_sizer = wx.BoxSizer(wx.HORIZONTAL)
        if ui.view.apply:
            self.apply = self._add_button('Apply', self._on_apply, b_sizer,
                                          False)
            ui.on_trait_change(self._on_applyable, 'modified', dispatch='ui')
            if ui.view.revert:
                self.revert = self._add_button('Revert', self._on_revert,
                                               b_sizer, False)
        self._add_button('OK', self._on_ok, b_sizer)
        self._add_button('Cancel', self._on_cancel, b_sizer)
        if ui.view.help:
            self._add_button('Help', self._on_help, b_sizer)
        sw_sizer.Add(b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        # Lay all of the dialog contents out:
        sw_sizer.Fit(self)
        self.SetSizer(sw_sizer)
        self.SetAutoLayout(True)
Beispiel #3
0
 def __init__ ( self, ui, parent ):
     wx.Dialog.__init__( self, parent, -1, ui.view.title )
     wx.EVT_CLOSE( self, self._on_cancel )
     wx.EVT_CHAR(  self, self._on_key )
     
     self.ui = ui
     
     # Create the 'context' copies we will need while editing:
     context     = ui.context
     ui._context = context
     ui.context  = self._copy_context( context )
     ui._revert  = self._copy_context( context )
     
     # Create the actual trait sheet panel and imbed it in a scrollable 
     # window:
     sizer       = wx.BoxSizer( wx.VERTICAL )
     sw          = wx.ScrolledWindow( self )
     trait_sheet = panel( ui, sw )
     sizer.Add( trait_sheet, 1, wx.EXPAND | wx.ALL, 4 )
     tsdx, tsdy = trait_sheet.GetSizeTuple()
     tsdx += 8
     tsdy += 8
     
     max_dy = (2 * screen_dy) / 3
     sw.SetAutoLayout( True )
     sw.SetSizer( sizer )
     sw.SetSize( wx.Size( tsdx + ((tsdy > max_dy) * scrollbar_dx), 
                          min( tsdy, max_dy ) ) )
     sw.SetScrollRate( 16, 16 )
     
     sw_sizer = wx.BoxSizer( wx.VERTICAL )
     sw_sizer.Add( sw, 1, wx.EXPAND )
     
     # Create the necessary special function buttons:
     sw_sizer.Add( wx.StaticLine( self, -1 ), 0, wx.EXPAND )
     b_sizer = wx.BoxSizer( wx.HORIZONTAL )
     if ui.view.apply:
         self.apply = self._add_button( 'Apply', self._on_apply, b_sizer, 
                                        False )
         ui.on_trait_change( self._on_applyable, 'modified', 
                             dispatch = 'ui' )
         if ui.view.revert:
             self.revert = self._add_button( 'Revert', self._on_revert, 
                                             b_sizer, False )
     self._add_button( 'OK', self._on_ok, b_sizer )
     self._add_button( 'Cancel', self._on_cancel, b_sizer )
     if ui.view.help:
         self._add_button( 'Help', self._on_help, b_sizer )
     sw_sizer.Add( b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5 )
      
     # Lay all of the dialog contents out:            
     sw_sizer.Fit( self )
     self.SetSizer( sw_sizer )
     self.SetAutoLayout( True )
Beispiel #4
0
    def init(self, ui, parent, style):
        self.is_modal = style == MODAL
        self.rc = None
        window_style = set()
        view = ui.view

        title = view.title
        if title == "":
            title = DefaultTitle

        history = ui.history
        window = ui.control
        if window is not None:
            if history is not None:
                history.on_facet_set(self._on_undoable, "undoable", remove=True)
                history.on_facet_set(self._on_redoable, "redoable", remove=True)
                history.on_facet_set(self._on_revertable, "undoable", remove=True)
            window.layout = None
            ui.reset()
        else:
            self.ui = ui
            if style == MODAL:
                if view.resizable:
                    window_style.add("resizable")
                    window_style.add("min_max")

                window_style.add("dialog")
                window = toolkit().create_frame(parent, window_style, title)
            elif style == NONMODAL:
                if parent is not None:
                    window_style.add("non_modal_child")

                window_style.add("frame")
                window = toolkit().create_frame(parent, window_style, title)
            else:
                if len(window_style) == 0:
                    window_style.add("simple")

                # Only use the parent if it is part of a modal window; otherwise
                # just make it a top-level window:
                while parent is not None:
                    if parent.modal:
                        break

                    parent = parent.parent

                window = toolkit().create_frame(parent, window_style)
                window.set_event_handler(deactivate=self._on_close_popup)
                window.kind = ui.kind
                self._monitor = None
                if style != POPOUT:
                    self._monitor = MouseMonitor(ui=ui)

            # Set the correct default window background color:
            window.background_color = WindowColor

            self.control = window
            window.set_event_handler(close=self._on_close_page, key=self._on_key)

        self.set_icon(view.icon)
        buttons = self.get_buttons(view)
        nbuttons = len(buttons)
        no_buttons = (nbuttons == 1) and self.is_button(buttons[0], "")
        has_buttons = (not no_buttons) and (nbuttons > 0)
        if has_buttons or ((view.menubar is not None) and (not view.undo)):
            if history is None:
                history = UndoHistory()
        else:
            history = None

        ui.history = history

        # Create the actual facets UI panel:
        sw = panel(ui, window)

        # Attempt an optimization that prevents creating nested vertical box
        # layouts:
        if isinstance(sw, Layout) and sw.is_vertical:
            sw_layout = sw
        else:
            sw_layout = toolkit().create_box_layout()
            sw_layout.add(sw, stretch=1)

        # Check to see if we need to add any of the special function buttons:
        if (not no_buttons) and has_buttons:
            sw_layout.add(toolkit().create_separator(window, False))
            b_layout = toolkit().create_box_layout(False, align="right")

            # Create a button for each button action:
            for button in buttons:
                button = self.coerce_button(button)
                if self.is_button(button, "Undo"):
                    self.undo = self.add_button(button, b_layout, self._on_undo, False)
                    self.redo = self.add_button(button, b_layout, self._on_redo, False, "Redo")
                    history.on_facet_set(self._on_undoable, "undoable", dispatch="ui")
                    history.on_facet_set(self._on_redoable, "redoable", dispatch="ui")
                    if history.can_undo:
                        self._on_undoable(True)

                    if history.can_redo:
                        self._on_redoable(True)

                elif self.is_button(button, "Revert"):
                    self.revert = self.add_button(button, b_layout, self._on_revert, False)
                    history.on_facet_set(self._on_revertable, "undoable", dispatch="ui")
                    if history.can_undo:
                        self._on_revertable(True)

                elif self.is_button(button, "OK"):
                    self.ok = self.add_button(button, b_layout, self._on_ok_button)
                    ui.on_facet_set(self._on_error, "errors", dispatch="ui")

                elif self.is_button(button, "Cancel"):
                    self.add_button(button, b_layout, self._on_cancel_button)

                elif self.is_button(button, "Help"):
                    self.add_button(button, b_layout, self._on_help)

                elif not self.is_button(button, ""):
                    self.add_button(button, b_layout)

            sw_layout.add(b_layout, fill=False, align="right", left=5, right=5, top=5, bottom=5)

        # Set the layout for the window:
        window.layout = sw_layout

        # Add the menu bar, tool bar and status bar (if any):
        self.add_menubar()
        self.add_toolbar()
        self.add_statusbar()

        # Lay out all of the dialog contents:
        window.shrink_wrap()
Beispiel #5
0
    def init(self, ui, parent, style):
        self.is_modal = (style == MODAL)
        window_style = 0
        view = ui.view
        if view.resizable:
            window_style |= wx.RESIZE_BORDER

        title = view.title
        if title == '':
            title = DefaultTitle

        history = ui.history
        window = ui.control
        if window is not None:
            if history is not None:
                history.on_trait_change(self._on_undoable, 'undoable',
                                        remove=True)
                history.on_trait_change(self._on_redoable, 'redoable',
                                        remove=True)
                history.on_trait_change(self._on_revertable, 'undoable',
                                        remove=True)
            window.SetSizer(None)
            ui.reset()
        else:
            self.ui = ui
            if style == MODAL:
                if view.resizable:
                    window_style |= (wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX)
                window = wx.Dialog(
                    parent, -1, title, style=window_style | wx.DEFAULT_DIALOG_STYLE)
            elif style == NONMODAL:
                if parent is not None:
                    window_style |= (wx.FRAME_FLOAT_ON_PARENT |
                                     wx.FRAME_NO_TASKBAR)
                window = wx.Frame(parent, -1, title, style=window_style |
                                  (wx.DEFAULT_FRAME_STYLE & (~wx.RESIZE_BORDER)))
            else:
                if window_style == 0:
                    window_style = wx.SIMPLE_BORDER
                if parent is not None:
                    window_style |= (wx.FRAME_FLOAT_ON_PARENT |
                                     wx.FRAME_NO_TASKBAR)

                window = wx.Frame(parent, -1, '', style=window_style)
                window._kind = ui.view.kind
                self._monitor = MouseMonitor(ui)

            # Set the correct default window background color:
            window.SetBackgroundColour(WindowColor)

            self.control = window
            wx.EVT_CLOSE(window, self._on_close_page)
            wx.EVT_CHAR(window, self._on_key)

        self.set_icon(view.icon)
        buttons = [self.coerce_button(button)
                   for button in view.buttons]
        nbuttons = len(buttons)
        no_buttons = ((nbuttons == 1) and self.is_button(buttons[0], ''))
        has_buttons = (
            (not no_buttons) and (
                (nbuttons > 0) or view.undo or view.revert or view.ok or view.cancel))
        if has_buttons or (view.menubar is not None):
            if history is None:
                history = UndoHistory()
        else:
            history = None
        ui.history = history

        # Create the actual trait sheet panel and imbed it in a scrollable
        # window (if requested):
        sw_sizer = wx.BoxSizer(wx.VERTICAL)
        if ui.scrollable:
            sizer = wx.BoxSizer(wx.VERTICAL)
            sw = TraitsUIScrolledPanel(window)
            trait_sheet = panel(ui, sw)
            sizer.Add(trait_sheet, 1, wx.EXPAND)
            tsdx, tsdy = trait_sheet.GetSize()
            sw.SetScrollRate(16, 16)
            max_dy = (2 * screen_dy) / 3
            sw.SetSizer(sizer)
            sw.SetSize(wx.Size(tsdx + ((tsdy > max_dy) * scrollbar_dx),
                               min(tsdy, max_dy)))
        else:
            sw = panel(ui, window)

        sw_sizer.Add(sw, 1, wx.EXPAND)
        sw_sizer.SetMinSize(sw.GetSize())

        # Check to see if we need to add any of the special function buttons:
        if (not no_buttons) and (has_buttons or view.help):
            sw_sizer.Add(wx.StaticLine(window, -1), 0, wx.EXPAND)
            b_sizer = wx.BoxSizer(wx.HORIZONTAL)

            # Convert all button flags to actual button actions if no buttons
            # were specified in the 'buttons' trait:
            if nbuttons == 0:
                if view.undo:
                    self.check_button(buttons, UndoButton)

                if view.revert:
                    self.check_button(buttons, RevertButton)

                if view.ok:
                    self.check_button(buttons, OKButton)

                if view.cancel:
                    self.check_button(buttons, CancelButton)

                if view.help:
                    self.check_button(buttons, HelpButton)

            # Create a button for each button action:
            for raw_button, button in zip(view.buttons, buttons):
                button = self.coerce_button(button)
                default = raw_button == view.default_button

                if self.is_button(button, 'Undo'):
                    self.undo = self.add_button(
                        button, b_sizer, self._on_undo, False, default=default)
                    self.redo = self.add_button(button, b_sizer,
                                                self._on_redo, False, 'Redo')
                    history.on_trait_change(self._on_undoable, 'undoable',
                                            dispatch='ui')
                    history.on_trait_change(self._on_redoable, 'redoable',
                                            dispatch='ui')
                    if history.can_undo:
                        self._on_undoable(True)

                    if history.can_redo:
                        self._on_redoable(True)

                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(
                        button, b_sizer, self._on_revert, False, default=default)
                    history.on_trait_change(self._on_revertable, 'undoable',
                                            dispatch='ui')
                    if history.can_undo:
                        self._on_revertable(True)

                elif self.is_button(button, 'OK'):
                    self.ok = self.add_button(button, b_sizer, self._on_ok,
                                              default=default)
                    ui.on_trait_change(self._on_error, 'errors',
                                       dispatch='ui')

                elif self.is_button(button, 'Cancel'):
                    self.add_button(button, b_sizer, self._on_cancel,
                                    default=default)

                elif self.is_button(button, 'Help'):
                    self.add_button(button, b_sizer, self._on_help,
                                    default=default)

                elif not self.is_button(button, ''):
                    self.add_button(button, b_sizer, default=default)

            sw_sizer.Add(b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        # Add the menu bar, tool bar and status bar (if any):
        self.add_menubar()
        self.add_toolbar()
        self.add_statusbar()

        # Lay all of the dialog contents out:
        window.SetSizer(sw_sizer)
        window.Fit()
Beispiel #6
0
    def init(self, ui, parent, style):
        """Initialise the object.
        """
        self.ui = ui
        self.control = ui.control
        view = ui.view

        revert = apply = False

        if self.control is not None:
            if hasattr(self, 'revert'):
                revert = self.revert.isEnabled()

            if hasattr(self, 'apply'):
                apply = self.apply.isEnabled()

            ui.reset()
        else:
            self.create_dialog(parent, style)

            # Create the 'context' copies we will need while editing:
            context = ui.context
            ui._context = context
            ui.context = self._copy_context(context)
            ui._revert = self._copy_context(context)

        self.set_icon(view.icon)

        # Convert the buttons to actions.
        buttons = [self.coerce_button(button) for button in view.buttons]
        nr_buttons = len(buttons)

        if (nr_buttons != 1) or (not self.is_button(buttons[0], '')):
            bbox = QtGui.QDialogButtonBox()

            # Create the necessary special function buttons.
            if nr_buttons == 0:
                if view.apply:
                    self.check_button(buttons, ApplyButton)
                    if view.revert:
                        self.check_button(buttons, RevertButton)
                if view.ok:
                    self.check_button(buttons, OKButton)
                if view.cancel:
                    self.check_button(buttons, CancelButton)
                if view.help:
                    self.check_button(buttons, HelpButton)

            for raw_button, button in zip(view.buttons, buttons):
                default = raw_button == view.default_button

                if self.is_button(button, 'Apply'):
                    self.apply = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ApplyRole,
                        self._on_apply,
                        enabled=apply,
                        default=default)
                    ui.on_trait_change(self._on_applyable, 'modified',
                                       dispatch='ui')

                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ResetRole,
                        self._on_revert,
                        enabled=revert,
                        default=default)

                elif self.is_button(button, 'OK'):
                    self.ok = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.AcceptRole,
                        self.control.accept,
                        default=default)
                    ui.on_trait_change(self._on_error, 'errors', dispatch='ui')

                elif self.is_button(button, 'Cancel'):
                    self.add_button(button, bbox,
                                    QtGui.QDialogButtonBox.RejectRole,
                                    self.control.reject, default=default)

                elif self.is_button(button, 'Help'):
                    self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.HelpRole,
                        self._on_help,
                        default=default)

                elif not self.is_button(button, ''):
                    self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ActionRole,
                        default=default)

        else:
            bbox = None

        self.add_contents(panel(ui), bbox)
Beispiel #7
0
    def init(self, ui, parent, is_modal):
        self.is_modal = is_modal
        style = 0
        view = ui.view
        if view.resizable:
            style |= wx.RESIZE_BORDER

        title = view.title
        if title == '':
            title = DefaultTitle

        revert = apply = False
        window = ui.control
        if window is not None:
            window.SetSizer(None)
            ui.reset()
            if hasattr(self, 'revert'):
                revert = self.revert.IsEnabled()
            if hasattr(self, 'apply'):
                apply = self.apply.IsEnabled()
        else:
            self.ui = ui
            if is_modal:
                window = wx.Dialog(parent, -1, title,
                                   style=style | wx.DEFAULT_DIALOG_STYLE)
            else:
                window = wx.Frame(parent, -1, title, style=style |
                                  (wx.DEFAULT_FRAME_STYLE & (~wx.RESIZE_BORDER)))

            window.SetBackgroundColour(WindowColor)
            self.control = window
            self.set_icon(view.icon)
            wx.EVT_CLOSE(window, self._on_close_page)
            wx.EVT_CHAR(window, self._on_key)

            # Create the 'context' copies we will need while editing:
            context = ui.context
            ui._context = context
            ui.context = self._copy_context(context)
            ui._revert = self._copy_context(context)

        # Create the actual trait sheet panel and imbed it in a scrollable
        # window (if requested):
        sw_sizer = wx.BoxSizer(wx.VERTICAL)
        if ui.scrollable:
            sizer = wx.BoxSizer(wx.VERTICAL)
            sw = TraitsUIScrolledPanel(window)
            trait_sheet = panel(ui, sw)
            sizer.Add(trait_sheet, 1, wx.EXPAND | wx.ALL, 4)
            tsdx, tsdy = trait_sheet.GetSizeTuple()
            tsdx += 8
            tsdy += 8
            sw.SetScrollRate(16, 16)
            max_dy = (2 * screen_dy) / 3
            sw.SetSizer(sizer)
            sw.SetSize(wx.Size(tsdx + ((tsdy > max_dy) * scrollbar_dx),
                               min(tsdy, max_dy)))
        else:
            sw = panel(ui, window)

        sw_sizer.Add(sw, 1, wx.EXPAND)

        buttons = [self.coerce_button(button) for button in view.buttons]
        nbuttons = len(buttons)
        if (nbuttons != 1) or (not self.is_button(buttons[0], '')):

            # Create the necessary special function buttons:
            sw_sizer.Add(wx.StaticLine(window, -1), 0, wx.EXPAND)
            b_sizer = wx.BoxSizer(wx.HORIZONTAL)

            if nbuttons == 0:
                if view.apply:
                    self.check_button(buttons, ApplyButton)
                    if view.revert:
                        self.check_button(buttons, RevertButton)

                if view.ok:
                    self.check_button(buttons, OKButton)

                if view.cancel:
                    self.check_button(buttons, CancelButton)

                if view.help:
                    self.check_button(buttons, HelpButton)

            for raw_button, button in zip(view.buttons, buttons):
                default = raw_button == view.default_button

                if self.is_button(button, 'Apply'):
                    self.apply = self.add_button(
                        button, b_sizer, self._on_apply, apply, default=default)
                    ui.on_trait_change(self._on_applyable, 'modified',
                                       dispatch='ui')

                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(
                        button, b_sizer, self._on_revert, revert, default=default)

                elif self.is_button(button, 'OK'):
                    self.ok = self.add_button(button, b_sizer, self._on_ok,
                                              default=default)
                    ui.on_trait_change(self._on_error, 'errors',
                                       dispatch='ui')

                elif self.is_button(button, 'Cancel'):
                    self.add_button(button, b_sizer, self._on_cancel,
                                    default=default)

                elif self.is_button(button, 'Help'):
                    self.add_button(button, b_sizer, self._on_help,
                                    default=default)

                elif not self.is_button(button, ''):
                    self.add_button(button, b_sizer, default=default)

            sw_sizer.Add(b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        # Add the menu bar, tool bar and status bar (if any):
        self.add_menubar()
        self.add_toolbar()
        self.add_statusbar()

        # Lay all of the dialog contents out:
        window.SetSizerAndFit(sw_sizer)
Beispiel #8
0
    def init ( self, ui, parent, is_modal ):
        self.is_modal = is_modal
        style         = 0
        view          = ui.view
        if view.resizable:
            style |= wx.RESIZE_BORDER

        title = view.title
        if title == '':
            title = DefaultTitle

        revert = apply = False
        window = ui.control
        if window is not None:
            window.SetSizer( None )
            ui.reset()
            if hasattr( self, 'revert' ):
                revert = self.revert.IsEnabled()
            if hasattr( self, 'apply' ):
                apply = self.apply.IsEnabled()
        else:
            self.ui = ui
            if is_modal:
                window = wx.Dialog( parent, -1, title,
                                    style = style | wx.DEFAULT_DIALOG_STYLE )
            else:
                window = wx.Frame(  parent, -1, title, style = style |
                            (wx.DEFAULT_FRAME_STYLE & (~wx.RESIZE_BORDER) ) )

            window.SetBackgroundColour( WindowColor )
            self.control = window
            self.set_icon( view.icon )
            wx.EVT_CLOSE( window, self._on_close_page )
            wx.EVT_CHAR(  window, self._on_key )

            # Create the 'context' copies we will need while editing:
            context     = ui.context
            ui._context = context
            ui.context  = self._copy_context( context )
            ui._revert  = self._copy_context( context )

        # Create the actual trait sheet panel and imbed it in a scrollable
        # window (if requested):
        sw_sizer = wx.BoxSizer( wx.VERTICAL )
        if ui.scrollable:
            sizer       = wx.BoxSizer( wx.VERTICAL )
            sw          = TraitsUIScrolledPanel( window )
            trait_sheet = panel( ui, sw )
            sizer.Add( trait_sheet, 1, wx.EXPAND | wx.ALL, 4 )
            tsdx, tsdy = trait_sheet.GetSizeTuple()
            tsdx += 8
            tsdy += 8
            sw.SetScrollRate( 16, 16 )
            max_dy = (2 * screen_dy) / 3
            sw.SetSizer( sizer )
            sw.SetSize( wx.Size( tsdx + ((tsdy > max_dy) * scrollbar_dx),
                                 min( tsdy, max_dy ) ) )
        else:
            sw = panel( ui, window )

        sw_sizer.Add( sw, 1, wx.EXPAND )

        buttons  = [ self.coerce_button( button ) for button in view.buttons ]
        nbuttons = len( buttons )
        if (nbuttons != 1) or (not self.is_button( buttons[0], '' )):

            # Create the necessary special function buttons:
            sw_sizer.Add( wx.StaticLine( window, -1 ), 0, wx.EXPAND )
            b_sizer = wx.BoxSizer( wx.HORIZONTAL )

            if nbuttons == 0:
                if view.apply:
                    self.check_button( buttons, ApplyButton )
                    if view.revert:
                        self.check_button( buttons, RevertButton )

                if view.ok:
                    self.check_button( buttons, OKButton )

                if view.cancel:
                    self.check_button( buttons, CancelButton )

                if view.help:
                    self.check_button( buttons, HelpButton )

            for raw_button, button in zip( view.buttons, buttons ):
                default = raw_button == view.default_button
                
                if self.is_button( button, 'Apply' ):
                    self.apply = self.add_button( button, b_sizer,
                            self._on_apply, apply, default = default )
                    ui.on_trait_change( self._on_applyable, 'modified',
                                        dispatch = 'ui' )

                elif self.is_button( button, 'Revert' ):
                    self.revert = self.add_button( button, b_sizer,
                            self._on_revert, revert, default = default )

                elif self.is_button( button, 'OK' ):
                    self.ok = self.add_button( button, b_sizer, self._on_ok,
                                               default = default )
                    ui.on_trait_change( self._on_error, 'errors',
                                        dispatch = 'ui' )

                elif self.is_button( button, 'Cancel' ):
                    self.add_button( button, b_sizer, self._on_cancel,
                                     default = default)

                elif self.is_button( button, 'Help' ):
                    self.add_button( button, b_sizer, self._on_help,
                                     default = default)

                elif not self.is_button( button, '' ):
                    self.add_button( button, b_sizer, default = default )

            sw_sizer.Add( b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5 )

        # Add the menu bar, tool bar and status bar (if any):
        self.add_menubar()
        self.add_toolbar()
        self.add_statusbar()

        # Lay all of the dialog contents out:
        window.SetSizerAndFit( sw_sizer )
Beispiel #9
0
    def init(self, ui, parent, style):
        """Initialise the object.

           FIXME: Note that we treat MODAL and POPUP as equivalent until we
           have an example that demonstrates how POPUP is supposed to work.
        """
        self.ui = ui
        self.control = ui.control
        view = ui.view
        history = ui.history

        if self.control is not None:
            if history is not None:
                history.on_trait_change(self._on_undoable, 'undoable',
                        remove=True)
                history.on_trait_change(self._on_redoable, 'redoable',
                        remove=True)
                history.on_trait_change(self._on_revertable, 'undoable',
                        remove=True)

            ui.reset()
        else:
            self.create_dialog(parent, style)

        self.set_icon(view.icon)

        # Convert the buttons to actions.
        buttons = [self.coerce_button(button) for button in view.buttons]
        nr_buttons = len(buttons)

        no_buttons = ((nr_buttons == 1) and self.is_button(buttons[0], ''))

        has_buttons = ((not no_buttons) and ((nr_buttons > 0) or view.undo or
                view.revert or view.ok or view.cancel))

        if has_buttons or (view.menubar is not None):
            if history is None:
                history = UndoHistory()
        else:
            history = None

        ui.history = history

        if (not no_buttons) and (has_buttons or view.help):
            bbox = QtGui.QDialogButtonBox()

            # Create the necessary special function buttons.
            if nr_buttons == 0:
                if view.undo:
                    self.check_button(buttons, UndoButton)
                if view.revert:
                    self.check_button(buttons, RevertButton)
                if view.ok:
                    self.check_button(buttons, OKButton)
                if view.cancel:
                    self.check_button(buttons, CancelButton)
                if view.help:
                    self.check_button(buttons, HelpButton)

            for button in buttons:
                if self.is_button(button, 'Undo'):
                    self.undo = self.add_button(button, bbox,
                            QtGui.QDialogButtonBox.ActionRole, self._on_undo,
                            False)
                    history.on_trait_change(self._on_undoable, 'undoable',
                            dispatch='ui')
                    if history.can_undo:
                        self._on_undoable(True)

                    self.redo = self.add_button(button, bbox,
                            QtGui.QDialogButtonBox.ActionRole, self._on_redo,
                            False, 'Redo')
                    history.on_trait_change(self._on_redoable, 'redoable',
                            dispatch='ui')
                    if history.can_redo:
                        self._on_redoable(True)

                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(button, bbox,
                            QtGui.QDialogButtonBox.ResetRole, self._on_revert,
                            False)
                    history.on_trait_change(self._on_revertable, 'undoable',
                            dispatch='ui')
                    if history.can_undo:
                        self._on_revertable(True)

                elif self.is_button(button, 'OK'):
                    self.ok = self.add_button(button, bbox,
                            QtGui.QDialogButtonBox.AcceptRole,
                            self.control.accept)
                    ui.on_trait_change(self._on_error, 'errors', dispatch='ui')

                elif self.is_button(button, 'Cancel'):
                    self.add_button(button, bbox,
                            QtGui.QDialogButtonBox.RejectRole,
                            self.control.reject)

                elif self.is_button(button, 'Help'):
                    self.add_button(button, bbox,
                            QtGui.QDialogButtonBox.HelpRole, self._on_help)

                elif not self.is_button(button, ''):
                    self.add_button(button, bbox,
                            QtGui.QDialogButtonBox.ActionRole)

        else:
            bbox = None

        self.add_contents(panel(ui), bbox)
Beispiel #10
0
    def init ( self, ui, parent, is_modal ):
        self.is_modal = is_modal
        style         = set()
        view          = ui.view
        if view.resizable:
            style.add( 'resizable' )

        title = view.title
        if title == '':
            title = DefaultTitle

        revert = apply = False
        window = ui.control
        if window is not None:
            window.layout = None
            ui.reset()
            if hasattr( self, 'revert' ):
                revert = self.revert.enabled

            if hasattr( self, 'apply' ):
                apply = self.apply.enabled
        else:
            self.ui = ui
            if is_modal:
                style.add( 'dialog' )
                window = toolkit().create_frame( parent, style, title )
            else:
                style.add( 'frame' )
                window = toolkit().create_frame( parent, style, title )

            window.background_color = WindowColor
            self.control            = window
            self.set_icon( view.icon )
            window.set_event_handler(
                close = self._on_close_page,
                key   = self._on_key
            )

            # Create the 'context' copies we will need while editing:
            context     = ui.context
            ui._context = context
            ui.context  = self._copy_context( context )
            ui._revert  = self._copy_context( context )

        # Create the actual facet sheet panel:
        sw_layout = toolkit().create_box_layout()
        sw_layout.add( panel( ui, window ), stretch = 1 )

        buttons  = self.get_buttons( view )
        nbuttons = len( buttons )
        if (nbuttons != 1) or (not self.is_button( buttons[0], '' )):

            # Create the necessary special function buttons:
            sw_layout.add( toolkit().create_separator( window, False ) )
            b_layout = toolkit().create_box_layout( False, align = 'right' )

            for button in buttons:
                if self.is_button( button, 'Apply' ):
                    self.apply = self.add_button( button, b_layout,
                                                  self._on_apply, apply )
                    ui.on_facet_set( self._on_applyable, 'modified',
                                     dispatch = 'ui' )

                elif self.is_button( button, 'Revert' ):
                    self.revert = self.add_button( button, b_layout,
                                                   self._on_revert, revert )

                elif self.is_button( button, 'OK' ):
                    self.ok = self.add_button( button, b_layout, self._on_ok )
                    ui.on_facet_set( self._on_error, 'errors',
                                     dispatch = 'ui' )

                elif self.is_button( button, 'Cancel' ):
                    self.add_button( button, b_layout, self._on_cancel )

                elif self.is_button( button, 'Help' ):
                    self.add_button( button, b_layout, self._on_help )

                elif not self.is_button( button, '' ):
                    self.add_button( button, b_layout )

            sw_layout.add( b_layout, align = 'right', left = 5, right = 5,
                           top = 5, bottom = 5 )

        # Add the menu bar, tool bar and status bar (if any):
        self.add_menubar()
        self.add_toolbar()
        self.add_statusbar()

        # Lay all of the dialog contents out:
        window.layout = sw_layout
        window.shrink_wrap()
Beispiel #11
0
    def init(self, ui, parent, style):
        self.is_modal = (style == MODAL)
        window_style = 0
        view = ui.view
        if view.resizable:
            window_style |= wx.RESIZE_BORDER

        title = view.title
        if title == '':
            title = DefaultTitle

        history = ui.history
        window = ui.control
        if window is not None:
            if history is not None:
                history.on_trait_change(self._on_undoable,
                                        'undoable',
                                        remove=True)
                history.on_trait_change(self._on_redoable,
                                        'redoable',
                                        remove=True)
                history.on_trait_change(self._on_revertable,
                                        'undoable',
                                        remove=True)
            window.SetSizer(None)
            ui.reset()
        else:
            self.ui = ui
            if style == MODAL:
                if view.resizable:
                    window_style |= (wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX)
                window = wx.Dialog(parent,
                                   -1,
                                   title,
                                   style=window_style
                                   | wx.DEFAULT_DIALOG_STYLE)
            elif style == NONMODAL:
                if parent is not None:
                    window_style |= (wx.FRAME_FLOAT_ON_PARENT
                                     | wx.FRAME_NO_TASKBAR)
                window = wx.Frame(parent,
                                  -1,
                                  title,
                                  style=window_style |
                                  (wx.DEFAULT_FRAME_STYLE &
                                   (~wx.RESIZE_BORDER)))
            else:
                if window_style == 0:
                    window_style = wx.SIMPLE_BORDER
                if parent is not None:
                    window_style |= (wx.FRAME_FLOAT_ON_PARENT
                                     | wx.FRAME_NO_TASKBAR)

                window = wx.Frame(parent, -1, '', style=window_style)
                window._kind = ui.view.kind
                self._monitor = MouseMonitor(ui)

            # Set the correct default window background color:
            window.SetBackgroundColour(WindowColor)

            self.control = window
            wx.EVT_CLOSE(window, self._on_close_page)
            wx.EVT_CHAR(window, self._on_key)

        self.set_icon(view.icon)
        buttons = [self.coerce_button(button) for button in view.buttons]
        nbuttons = len(buttons)
        no_buttons = ((nbuttons == 1) and self.is_button(buttons[0], ''))
        has_buttons = ((not no_buttons)
                       and ((nbuttons > 0) or view.undo or view.revert
                            or view.ok or view.cancel))
        if has_buttons or (view.menubar is not None):
            if history is None:
                history = UndoHistory()
        else:
            history = None
        ui.history = history

        # Create the actual trait sheet panel and imbed it in a scrollable
        # window (if requested):
        sw_sizer = wx.BoxSizer(wx.VERTICAL)
        if ui.scrollable:
            sizer = wx.BoxSizer(wx.VERTICAL)
            sw = TraitsUIScrolledPanel(window)
            trait_sheet = panel(ui, sw)
            sizer.Add(trait_sheet, 1, wx.EXPAND)
            tsdx, tsdy = trait_sheet.GetSize()
            sw.SetScrollRate(16, 16)
            max_dy = (2 * screen_dy) / 3
            sw.SetSizer(sizer)
            sw.SetSize(
                wx.Size(tsdx + ((tsdy > max_dy) * scrollbar_dx),
                        min(tsdy, max_dy)))
        else:
            sw = panel(ui, window)

        sw_sizer.Add(sw, 1, wx.EXPAND)
        sw_sizer.SetMinSize(sw.GetSize())

        # Check to see if we need to add any of the special function buttons:
        if (not no_buttons) and (has_buttons or view.help):
            sw_sizer.Add(wx.StaticLine(window, -1), 0, wx.EXPAND)
            b_sizer = wx.BoxSizer(wx.HORIZONTAL)

            # Convert all button flags to actual button actions if no buttons
            # were specified in the 'buttons' trait:
            if nbuttons == 0:
                if view.undo:
                    self.check_button(buttons, UndoButton)

                if view.revert:
                    self.check_button(buttons, RevertButton)

                if view.ok:
                    self.check_button(buttons, OKButton)

                if view.cancel:
                    self.check_button(buttons, CancelButton)

                if view.help:
                    self.check_button(buttons, HelpButton)

            # Create a button for each button action:
            for raw_button, button in zip(view.buttons, buttons):
                button = self.coerce_button(button)
                default = raw_button == view.default_button

                if self.is_button(button, 'Undo'):
                    self.undo = self.add_button(button,
                                                b_sizer,
                                                self._on_undo,
                                                False,
                                                default=default)
                    self.redo = self.add_button(button, b_sizer, self._on_redo,
                                                False, 'Redo')
                    history.on_trait_change(self._on_undoable,
                                            'undoable',
                                            dispatch='ui')
                    history.on_trait_change(self._on_redoable,
                                            'redoable',
                                            dispatch='ui')
                    if history.can_undo:
                        self._on_undoable(True)

                    if history.can_redo:
                        self._on_redoable(True)

                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(button,
                                                  b_sizer,
                                                  self._on_revert,
                                                  False,
                                                  default=default)
                    history.on_trait_change(self._on_revertable,
                                            'undoable',
                                            dispatch='ui')
                    if history.can_undo:
                        self._on_revertable(True)

                elif self.is_button(button, 'OK'):
                    self.ok = self.add_button(button,
                                              b_sizer,
                                              self._on_ok,
                                              default=default)
                    ui.on_trait_change(self._on_error, 'errors', dispatch='ui')

                elif self.is_button(button, 'Cancel'):
                    self.add_button(button,
                                    b_sizer,
                                    self._on_cancel,
                                    default=default)

                elif self.is_button(button, 'Help'):
                    self.add_button(button,
                                    b_sizer,
                                    self._on_help,
                                    default=default)

                elif not self.is_button(button, ''):
                    self.add_button(button, b_sizer, default=default)

            sw_sizer.Add(b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        # Add the menu bar, tool bar and status bar (if any):
        self.add_menubar()
        self.add_toolbar()
        self.add_statusbar()

        # Lay all of the dialog contents out:
        window.SetSizer(sw_sizer)
        window.Fit()
Beispiel #12
0
    def init(self, ui, parent, style):
        """Initialise the object.
        """
        self.ui = ui
        self.control = ui.control
        view = ui.view

        revert = apply = False

        if self.control is not None:
            if hasattr(self, 'revert'):
                revert = self.revert.isEnabled()

            if hasattr(self, 'apply'):
                apply = self.apply.isEnabled()

            ui.reset()
        else:
            self.create_dialog(parent, style)

            # Create the 'context' copies we will need while editing:
            context = ui.context
            ui._context = context
            ui.context = self._copy_context(context)
            ui._revert = self._copy_context(context)

        self.set_icon(view.icon)

        # Convert the buttons to actions.
        buttons = [self.coerce_button(button) for button in view.buttons]
        nr_buttons = len(buttons)

        if (nr_buttons != 1) or (not self.is_button(buttons[0], '')):
            bbox = QtGui.QDialogButtonBox()

            # Create the necessary special function buttons.
            if nr_buttons == 0:
                if view.apply:
                    self.check_button(buttons, ApplyButton)
                    if view.revert:
                        self.check_button(buttons, RevertButton)
                if view.ok:
                    self.check_button(buttons, OKButton)
                if view.cancel:
                    self.check_button(buttons, CancelButton)
                if view.help:
                    self.check_button(buttons, HelpButton)

            for raw_button, button in zip(view.buttons, buttons):
                default = raw_button == view.default_button

                if self.is_button(button, 'Apply'):
                    self.apply = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ApplyRole,
                        self._on_apply,
                        enabled=apply,
                        default=default)
                    ui.on_trait_change(self._on_applyable,
                                       'modified',
                                       dispatch='ui')

                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ResetRole,
                        self._on_revert,
                        enabled=revert,
                        default=default)

                elif self.is_button(button, 'OK'):
                    self.ok = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.AcceptRole,
                        self.control.accept,
                        default=default)
                    ui.on_trait_change(self._on_error, 'errors', dispatch='ui')

                elif self.is_button(button, 'Cancel'):
                    self.add_button(button,
                                    bbox,
                                    QtGui.QDialogButtonBox.RejectRole,
                                    self.control.reject,
                                    default=default)

                elif self.is_button(button, 'Help'):
                    self.add_button(button,
                                    bbox,
                                    QtGui.QDialogButtonBox.HelpRole,
                                    self._on_help,
                                    default=default)

                elif not self.is_button(button, ''):
                    self.add_button(button,
                                    bbox,
                                    QtGui.QDialogButtonBox.ActionRole,
                                    default=default)

        else:
            bbox = None

        self.add_contents(panel(ui), bbox)
Beispiel #13
0
    def init(self, ui, parent, style):
        """Initialise the object.

           FIXME: Note that we treat MODAL and POPUP as equivalent until we
           have an example that demonstrates how POPUP is supposed to work.
        """
        self.ui = ui
        self.control = ui.control
        view = ui.view
        history = ui.history

        if self.control is not None:
            if history is not None:
                history.on_trait_change(self._on_undoable, 'undoable',
                                        remove=True)
                history.on_trait_change(self._on_redoable, 'redoable',
                                        remove=True)
                history.on_trait_change(self._on_revertable, 'undoable',
                                        remove=True)

            ui.reset()
        else:
            self.create_dialog(parent, style)

        self.set_icon(view.icon)

        # Convert the buttons to actions.
        buttons = [self.coerce_button(button) for button in view.buttons]
        nr_buttons = len(buttons)

        no_buttons = ((nr_buttons == 1) and self.is_button(buttons[0], ''))

        has_buttons = (
            (not no_buttons) and (
                (nr_buttons > 0) or view.undo or view.revert or view.ok or view.cancel))

        if has_buttons or (view.menubar is not None):
            if history is None:
                history = UndoHistory()
        else:
            history = None

        ui.history = history

        if (not no_buttons) and (has_buttons or view.help):
            bbox = QtGui.QDialogButtonBox()

            # Create the necessary special function buttons.
            if nr_buttons == 0:
                if view.undo:
                    self.check_button(buttons, UndoButton)
                if view.revert:
                    self.check_button(buttons, RevertButton)
                if view.ok:
                    self.check_button(buttons, OKButton)
                if view.cancel:
                    self.check_button(buttons, CancelButton)
                if view.help:
                    self.check_button(buttons, HelpButton)

            for raw_button, button in zip(view.buttons, buttons):
                default = raw_button == view.default_button

                if self.is_button(button, 'Undo'):
                    self.undo = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ActionRole,
                        self._on_undo,
                        False,
                        default=default)
                    history.on_trait_change(self._on_undoable, 'undoable',
                                            dispatch='ui')
                    if history.can_undo:
                        self._on_undoable(True)

                    self.redo = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ActionRole,
                        self._on_redo,
                        False,
                        'Redo')
                    history.on_trait_change(self._on_redoable, 'redoable',
                                            dispatch='ui')
                    if history.can_redo:
                        self._on_redoable(True)

                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ResetRole,
                        self._on_revert,
                        False,
                        default=default)
                    history.on_trait_change(self._on_revertable, 'undoable',
                                            dispatch='ui')
                    if history.can_undo:
                        self._on_revertable(True)

                elif self.is_button(button, 'OK'):
                    self.ok = self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.AcceptRole,
                        self.control.accept,
                        default=default)
                    ui.on_trait_change(self._on_error, 'errors', dispatch='ui')

                elif self.is_button(button, 'Cancel'):
                    self.add_button(button, bbox,
                                    QtGui.QDialogButtonBox.RejectRole,
                                    self.control.reject, default=default)

                elif self.is_button(button, 'Help'):
                    self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.HelpRole,
                        self._on_help,
                        default=default)

                elif not self.is_button(button, ''):
                    self.add_button(
                        button,
                        bbox,
                        QtGui.QDialogButtonBox.ActionRole,
                        default=default)

        else:
            bbox = None

        self.add_contents(panel(ui), bbox)
Beispiel #14
0
    def __init__(self, ui, parent):
        wx.Dialog.__init__(self, parent, -1, ui.view.title)
        wx.EVT_CLOSE(self, self._on_close_page)
        wx.EVT_CHAR(self, self._on_key)

        history = None
        self.ui = ui
        view = ui.view
        if view.undo or view.revert or view.ok:
            ui.history = history = UndoHistory()

        # Create the actual trait sheet panel and imbed it in a scrollable
        # window:
        sizer = wx.BoxSizer(wx.VERTICAL)
        sw = wx.ScrolledWindow(self)
        trait_sheet = panel(ui, sw)
        sizer.Add(trait_sheet, 1, wx.EXPAND | wx.ALL, 4)
        tsdx, tsdy = trait_sheet.GetSizeTuple()
        tsdx += 8
        tsdy += 8

        max_dy = (2 * screen_dy) / 3
        sw.SetAutoLayout(True)
        sw.SetSizer(sizer)
        sw.SetSize(
            wx.Size(tsdx + ((tsdy > max_dy) * scrollbar_dx), min(tsdy,
                                                                 max_dy)))
        sw.SetScrollRate(16, 16)

        sw_sizer = wx.BoxSizer(wx.VERTICAL)
        sw_sizer.Add(sw, 1, wx.EXPAND)

        # Check to see if we need to add any of the special function buttons:
        if (history is not None) or view.help:
            sw_sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
            b_sizer = wx.BoxSizer(wx.HORIZONTAL)
            if view.undo:
                self.undo = self._add_button('Undo', self._on_undo, b_sizer,
                                             False)
                self.redo = self._add_button('Redo', self._on_redo, b_sizer,
                                             False)
                history.on_trait_change(self._on_undoable,
                                        'undoable',
                                        dispatch='ui')
                history.on_trait_change(self._on_redoable,
                                        'redoable',
                                        dispatch='ui')
            if view.revert:
                self.revert = self._add_button('Revert', self._on_revert,
                                               b_sizer, False)
                history.on_trait_change(self._on_revertable,
                                        'undoable',
                                        dispatch='ui')
            if view.ok:
                self._add_button('OK', self._on_close_page, b_sizer)
                self._add_button('Cancel', self._on_cancel, b_sizer)
            if view.help:
                self._add_button('Help', self._on_help, b_sizer)
            sw_sizer.Add(b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        # Lay all of the dialog contents out:
        sw_sizer.Fit(self)
        self.SetSizer(sw_sizer)
        self.SetAutoLayout(True)