def _wx_initialize_editor_dock_control(self, editor, editor_dock_control):
        """ Initializes an editor dock control.

        fixme: We only need this method because of a problem with the dock
        window API in the 'SetStructureHandler' class. Currently we do not get
        a reference to the dock control in 'resolve_id' and hence we cannot set
        up the 'on_close' and trait change handlers etc.

        """

        # Some editors append information to their name to indicate status (in
        # our case this is often a 'dirty' indicator that shows when the
        # contents of an editor have been modified but not saved). When the
        # dock window structure is persisted it contains the name of each dock
        # control, which obviously includes any appended state information.
        # Here we make sure that when the dock control is recreated its name is
        # set to the editor name and nothing more!
        editor_dock_control.set_name(editor.name)

        # fixme: Should we roll the traits UI stuff into the default editor.
        if hasattr(editor, 'ui') and editor.ui is not None:
            from traitsui.dockable_view_element import DockableViewElement
            # This makes the control draggable outside of the main window.
            #editor_dock_control.export = 'pyface.workbench.editor'
            editor_dock_control.dockable = DockableViewElement(
                should_close=True, ui=editor.ui)

        editor_dock_control.on_close = self._wx_on_editor_closed

        def on_id_changed(editor, trait_name, old, new):
            editor_dock_control.id = editor.id
            return

        editor.on_trait_change(on_id_changed, 'id')

        def on_name_changed(editor, trait_name, old, new):
            editor_dock_control.set_name(editor.name)
            return

        editor.on_trait_change(on_name_changed, 'name')

        def on_activated_changed(editor_dock_control, trait_name, old, new):
            editor.set_focus()
            return

        editor_dock_control.on_trait_change(on_activated_changed, 'activated')

        return
Example #2
0
    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,
                    )
                ]
            )
Example #3
0
def create_notebook_for_items(
    content, ui, parent, group, item_handler=None, is_dock_window=False
):
    """ Creates a notebook and adds a list of groups or items to it as separate
        pages.
    """
    if is_dock_window:
        nb = parent
    else:
        dw = DockWindow(
            parent, handler=ui.handler, handler_args=(ui.info,), id=ui.id
        )
        if group is not None:
            dw.theme = group.dock_theme
        nb = dw.control
    pages = []
    count = 0

    # Create a notebook page for each group or item in the content:
    active = 0
    for index, item in enumerate(content):
        if isinstance(item, Group):
            # Create the group as a nested DockWindow item:
            if item.selected:
                active = index
            sg_sizer, resizable, contents = fill_panel_for_group(
                nb, item, ui, suppress_label=True, is_dock_window=True
            )

            # If the result is a region (i.e. notebook) with only one page,
            # collapse it down into just the contents of the region:
            if isinstance(contents, DockRegion) and (
                len(contents.contents) == 1
            ):
                contents = contents.contents[0]

            # Add the content to the notebook as a new page:
            pages.append(contents)
        else:
            # Create the new page as a simple DockControl containing the
            # specified set of controls:
            page_name = item.get_label(ui)
            count += 1
            if page_name == "":
                page_name = "Page %d" % count

            sizer = wx.BoxSizer(wx.VERTICAL)

            panel = TraitsUIPanel(nb, -1)
            panel.SetSizer(sizer)

            pages.append(
                DockControl(
                    name=page_name,
                    image=item.image,
                    id=item.get_id(),
                    style=item.dock,
                    dockable=DockableViewElement(ui=ui, element=item),
                    export=item.export,
                    control=panel,
                )
            )
            item_handler(item, panel, sizer)
            panel.GetSizer().Fit(panel)

    region = DockRegion(contents=pages, active=active)

    # If the caller is a DockWindow, return the region as the result:
    if is_dock_window:
        return region

    nb.SetSizer(DockSizer(contents=DockSection(contents=[region])))

    # Return the notebook as the result:
    return nb
Example #4
0
def create_dock_window ( parent, editor ):
    """ Creates a window for editing a workflow canvas.
    """
    try:
     main     = DockWindow( parent ).control
     view_uis = [ AView().edit_traits( parent = main ) for i in range( 6 ) ]
     views    = [ ui.control for ui in view_uis ]
     edit     = DockWindow( main ).control
     editors  = [ AnEditor().edit_traits( parent = edit ) for i in range( 6 ) ]
     controls = []
     for i in range( 6 ):
         dockable = DockableViewElement( ui = editors[i] )
         controls.append( DockControl(
                              name      = 'Editor %d' % (i + 1),
                              image     = image1,
                              closeable = True,
                              on_close  = dockable.close_dock_control,
                              control   = editors[i].control,
                              export    = 'editor',
                              dockable  = dockable,
                              style     = style ) )
     edit_sizer = DockSizer( contents = [ tuple( controls ) ] )
     dve0 = DockableViewElement( ui = view_uis[0] )
     dve1 = DockableViewElement( ui = view_uis[1] )
     main_sizer = DockSizer( contents =
                   [ [ DockControl( name      = 'View 1',
                                    image     = image1,
                                    closeable = True,
                                    on_close  = dve0.close_dock_control,
                                    dockable  = dve0,
                                    control   = views[0],
                                    style     = style ),
                       DockControl( name      = 'View 2',
                                    image     = image1,
                                    closeable = True,
                                    on_close  = dve1.close_dock_control,
                                    dockable  = dve1,
                                    height    = 400,
                                    control   = views[1],
                                    style     = style ) ],
                     [ DockControl( name      = 'Editors',
                                    image     = image1,
                                    control   = edit,
                                    style     = 'fixed' ),
                       [ DockControl( name    = 'View 3',
                                      image   = image2,
                                      control = views[2],
                                      style   = style ),
                         DockControl( name    = 'View 4',
                                      image   = image2,
                                      control = views[3],
                                      style   = style ) ] ],
                     [ DockControl( name      = 'View 5',
                                    control   = views[4],
                                    style     = style ),
                       DockControl( name      = 'View 6',
                                    control   = views[5],
                                    style     = style ) ] ] )
     edit.SetSizer( edit_sizer )
     main.SetSizer( main_sizer )

     return main
    except:
        import traceback
        traceback.print_exc()
        raise