def create_control(self, parent): """ Creates the underlying wxPython window used for the notebook. """ # Create the correct type of window based on whether or not it should # be scrollable: if self.scrollable: self.control = control = TraitsUIScrolledPanel(parent) control.SetScrollRate(6, 6) control.SetSize(wx.Size(0, 0)) else: self.control = control = TraitsUIPanel(parent, -1) control._image_slice = getattr(parent, '_image_slice', None) control.SetSizer(ThemedVerticalNotebookSizer(self)) # Set up the painting event handlers: wx.EVT_ERASE_BACKGROUND(control, self._erase_background) wx.EVT_PAINT(control, self._paint) return control
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)
def __init__(self, panel, group, ui, suppress_label, is_dock_window, create_panel): """ Initializes the object. """ # Get the contents of the group: content = group.get_content() # Create a group editor object if one is needed: self.control = self.sizer = editor = None self.ui = ui self.group = group self.is_horizontal = (group.orientation == 'horizontal') layout = group.layout is_scrolled_panel = group.scrollable is_splitter = (layout == 'split') is_tabbed = (layout == 'tabbed') id = group.id # Assume our contents are not resizable: self.resizable = False if is_dock_window and (is_splitter or is_tabbed): if is_splitter: self.dock_contents = self.add_dock_window_splitter_items( panel, content, group) else: self.resizable = group.springy self.dock_contents = create_notebook_for_items( content, ui, panel, group, self.add_notebook_item, True) return if (is_dock_window or create_panel or is_scrolled_panel or (id != '') or (group.visible_when != '') or (group.enabled_when != '')): if is_scrolled_panel: new_panel = TraitsUIScrolledPanel(panel) new_panel.SetMinSize(panel.GetMinSize()) self.resizable = True else: new_panel = TraitsUIPanel(panel, -1) sizer = panel.GetSizer() if sizer is None: sizer = wx.BoxSizer(wx.VERTICAL) panel.SetSizer(sizer) self.control = panel = new_panel if is_splitter or is_tabbed: editor = DockWindowGroupEditor(control=panel, ui=ui) else: editor = GroupEditor(control=panel) if id != '': ui.info.bind(group.id, editor) if group.visible_when != '': ui.add_visible(group.visible_when, editor) if group.enabled_when != '': ui.add_enabled(group.enabled_when, editor) self.panel = panel self.dock_contents = None # Determine the horizontal/vertical orientation of the group: if self.is_horizontal: orientation = wx.HORIZONTAL else: orientation = wx.VERTICAL # Set up a group with or without a border around its contents: label = '' if not suppress_label: label = group.label if group.show_border: box = wx.StaticBox(panel, -1, label) self._set_owner(box, group) self.sizer = wx.StaticBoxSizer(box, orientation) else: if layout == 'flow': self.sizer = FlowSizer(orientation) else: self.sizer = wx.BoxSizer(orientation) if label != '': self.sizer.Add( heading_text(panel, text=label).control, 0, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 4) # If no sizer has been specified for the panel yet, make the new sizer # the layout sizer for the panel: if panel.GetSizer() is None: panel.SetSizer(self.sizer) # Set up scrolling now that the sizer has been set: if is_scrolled_panel: if self.is_horizontal: panel.SetupScrolling(scroll_y=False) else: panel.SetupScrolling(scroll_x=False) if is_splitter: dw = DockWindow(panel, handler=ui.handler, handler_args=(ui.info, ), id=ui.id, theme=group.dock_theme).control if editor is not None: editor.dock_window = dw dw.SetSizer( DockSizer(contents=self.add_dock_window_splitter_items( dw, content, group))) self.sizer.Add(dw, 1, wx.EXPAND) elif len(content) > 0: if is_tabbed: self.resizable = group.springy dw = create_notebook_for_items(content, ui, panel, group, self.add_notebook_item) if editor is not None: editor.dock_window = dw self.sizer.Add(dw, self.resizable, wx.EXPAND) # Check if content is all Group objects: elif layout == 'fold': self.resizable = True self.sizer.Add(self.create_fold_for_items(panel, content), 1, wx.EXPAND) elif isinstance(content[0], Group): # If so, add them to the panel and exit: self.add_groups(content, panel) else: self.add_items(content, panel, self.sizer) # If the caller is a DockWindow, we need to define the content we are # adding to it: if is_dock_window: self.dock_contents = DockRegion(contents=[ DockControl(name=group.get_label(self.ui), image=group.image, id=group.get_id(), style=group.dock, dockable=DockableViewElement(ui=ui, element=group), export=group.export, control=panel) ])
def __init__(self, ui, parent, allow_buttons): """ Initializes the object. """ self.ui = ui history = None view = ui.view title = view.title # Reset any existing history listeners: history = ui.history 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) # Determine if we need any buttons or an 'undo' history: buttons = [self.coerce_button(button) for button in view.buttons] nbuttons = len(buttons) if nbuttons == 0: if view.undo: self.check_button(buttons, UndoButton) if view.revert: self.check_button(buttons, RevertButton) if view.help: self.check_button(buttons, HelpButton) if allow_buttons and (history is None): for button in buttons: if (self.is_button(button, 'Undo') or self.is_button(button, 'Revert')): history = UndoHistory() break ui.history = history # Create a container panel to put everything in: cpanel = getattr(self, 'control', None) if cpanel is not None: cpanel.SetSizer(None) cpanel.DestroyChildren() else: self.control = cpanel = TraitsUIPanel(parent, -1) # Create the actual trait sheet panel and embed it in a scrollable # window (if requested): sw_sizer = wx.BoxSizer(wx.VERTICAL) if ui.scrollable: sizer = wx.BoxSizer(wx.VERTICAL) sw = TraitsUIScrolledPanel(cpanel) sizer.Add(panel(ui, sw), 1, wx.EXPAND) sw.SetSizerAndFit(sizer) sw.SetScrollRate(16, 16) else: sw = panel(ui, cpanel) if ((title != '') and (not isinstance(getattr(parent, 'owner', None), DockWindow))): sw_sizer.Add( heading_text(cpanel, text=title).control, 0, wx.EXPAND) self.add_toolbar(sw_sizer) sw_sizer.Add(sw, 1, wx.EXPAND) if (allow_buttons and ((nbuttons != 1) or (not self.is_button(buttons[0], '')))): # Add the special function buttons: sw_sizer.Add(wx.StaticLine(cpanel, -1), 0, wx.EXPAND) b_sizer = wx.BoxSizer(wx.HORIZONTAL) for button in buttons: if self.is_button(button, 'Undo'): self.undo = self.add_button(button, b_sizer, self._on_undo, False) 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') elif self.is_button(button, 'Revert'): self.revert = self.add_button(button, b_sizer, self._on_revert, False) history.on_trait_change(self._on_revertable, 'undoable', dispatch='ui') elif self.is_button(button, 'Help'): self.add_button(button, b_sizer, self._on_help) elif not self.is_button(button, ''): self.add_button(button, b_sizer) sw_sizer.Add(b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5) cpanel.SetSizerAndFit(sw_sizer)
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()