コード例 #1
0
    def _insert_tab(self, index, label):
        # add tab/page
        tabs_p = self.properties["tabs"]
        tabs = tabs_p.get()  # the value will be modified in place
        tabs.insert(index, [
            label,
        ])
        tabs_p.set(tabs)
        self.children.insert(index, None)

        # adjust pos of the following pages
        for i, page in enumerate(self.children[index + 1:]):
            pos_p = page.properties["pos"]
            pos_p.set(index + 1 + i)

        # create panel and node, add to tree
        editor = EditPanel(self.next_pane_name(), self, index)

        if self.widget:
            # add to widget
            editor.create()
            compat.SetToolTip(editor.widget,
                              _("Notebook page pane:\nAdd a sizer here"))
            self.vs_insert_tab(index)

            try:
                wx.CallAfter(editor.sel_marker.update)
            except AttributeError:
                #self._logger.exception(_('Internal Error'))
                if config.debugging: raise

            self.widget.SetSelection(index)

        self.properties["tabs"].update_display()
        return editor
コード例 #2
0
def builder(parent, pos):
    "Factory function for EditSplitterWindow objects"
    dialog = wcodegen.WidgetStyleSelectionDialog(dlg_title, box_title, choices,
                                                 ["Create panels"], [True])
    with misc.disable_stay_on_top(common.adding_window or parent):
        res = dialog.ShowModal()
    orientation = dialog.get_selection().split(" ")[0]
    create_panels = dialog.get_options()[0]
    dialog.Destroy()
    if res != wx.ID_OK:
        return

    name = parent.toplevel_parent.get_next_contained_name('window_%d')
    with parent.frozen():
        editor = EditSplitterWindow(name, parent, orientation, pos)
        editor.properties["style"].set_to_default()
        if create_panels:
            pane1 = EditPanel(name + '_pane_1', editor, 0)
            pane2 = EditPanel(name + '_pane_2', editor, 1)

        editor.properties["proportion"].set(1)
        editor.properties["flag"].set("wxEXPAND")

        if parent.widget: editor.create()

        return editor
コード例 #3
0
def builder(parent, sizer, pos, number=[1]):
    "Factory function for EditSplitterWindow objects"
    dialog = wcodegen.WidgetStyleSelectionDialog(dlg_title, box_title, choices,
                                                 ["Create panels"], [True])
    with misc.disable_stay_on_top(common.adding_window or parent):
        res = dialog.ShowModal()
    orientation = dialog.get_selection().split(" ")[0]
    create_panels = dialog.get_options()[0]
    dialog.Destroy()
    if res != wx.ID_OK:
        return

    label = '%s_%d' % (tmpl_label, number[0])
    while common.app_tree.has_name(label):
        number[0] += 1
        label = '%s_%d' % (tmpl_label, number[0])

    with parent.frozen():
        widget = editor_class(label, parent, -1, None, None, orientation,
                              sizer, pos)
        widget.properties["style"].set_to_default()
        if create_panels:
            widget._window_1 = pane1 = EditPanel(label + '_pane_1', widget,
                                                 wx.NewId(),
                                                 widget.virtual_sizer, 1)
            widget._window_2 = pane2 = EditPanel(label + '_pane_2', widget,
                                                 wx.NewId(),
                                                 widget.virtual_sizer, 2)

        node = Node(widget)
        widget.node = node
        widget.virtual_sizer.node = node

        widget.properties["proportion"].set(1)
        widget.properties["flag"].set("wxEXPAND")

        common.app_tree.insert(node, sizer.node, pos - 1)

        if create_panels:
            node2 = Node(widget._window_1)
            node3 = Node(widget._window_2)
        else:
            node2 = SlotNode(widget._window_1)
            node3 = SlotNode(widget._window_2)
        widget._window_1.node = node2
        common.app_tree.add(node2, widget.node)
        widget._window_2.node = node3
        common.app_tree.add(node3, widget.node)

        if parent.widget: widget.create()
コード例 #4
0
    def insert_tab(self, index, label):
        # add tab/page this needs to be done before EditPanel calls self.virtual_sizer.add_item
        tabs_p = self.properties["tabs"]
        tabs = tabs_p.get()  # the value will be modified in place
        tabs.insert(index, [
            label,
        ])
        tabs_p.set(tabs)
        self.pages.insert(index, None)

        # adjust pos of the following pages
        for i, page in enumerate(self.pages[index + 1:]):
            pos_p = page.properties["pos"]
            pos_p.set(index + 2 + i)

        # create panel and node, add to tree
        pos = index + 1
        window = EditPanel(self.next_pane_name(), self, -1, self.virtual_sizer,
                           pos)
        window._dont_destroy = True
        window.node = node = Node(window)

        #common.app_tree.add(node, self.node, index)
        self.virtual_sizer.add_item(window, pos)
        common.app_tree.insert(node, self.node, index)

        if self.widget:
            # add to widget
            window.create()
            compat.SetToolTip(window.widget,
                              _("Notebook page pane:\nAdd a sizer here"))
            self.virtual_sizer.insert_tab(index)

            try:
                wx.CallAfter(window.sel_marker.update)
            except AttributeError:
                #self._logger.exception(_('Internal Error'))
                if config.debugging: raise

            self.widget.SetSelection(index)

        self.properties["tabs"].update_display()
コード例 #5
0
def builder(parent, sizer, pos, number=[1]):
    "Factory function for EditSplitterWindow objects"
    dialog = wcodegen.WidgetStyleSelectionDialog(dlg_title, box_title, choices)
    res = dialog.ShowModal()
    orientation = dialog.get_selection().split(" ")[0]
    dialog.Destroy()
    if res != wx.ID_OK:
        return

    label = '%s_%d' % (tmpl_label, number[0])
    while common.app_tree.has_name(label):
        number[0] += 1
        label = '%s_%d' % (tmpl_label, number[0])

    widget = editor_class(label, parent, -1, None, None, None, orientation,
                          sizer, pos)
    widget._window_1 = pane1 = EditPanel(label + '_pane_1', widget, wx.NewId(),
                                         widget.virtual_sizer, 1)
    widget._window_2 = pane2 = EditPanel(label + '_pane_2', widget, wx.NewId(),
                                         widget.virtual_sizer, 2)

    node = Node(widget)
    widget.node = node
    widget.virtual_sizer.node = node

    widget.properties["proportion"].set(1)
    widget.properties["flag"].set("wxEXPAND")

    common.app_tree.insert(node, sizer.node, pos - 1)

    node2 = Node(widget._window_1)
    widget._window_1.node = node2
    common.app_tree.add(node2, widget.node)

    node3 = Node(widget._window_2)
    widget._window_2.node = node3
    common.app_tree.add(node3, widget.node)

    sizer.set_item(widget.pos, 1, wx.EXPAND)
コード例 #6
0
 def set_tabs(self, tabs):
     delta = len(self.tabs) - len(tabs)
     if delta > 0:
         self._is_removing_pages = True
         # we have to remove some pages
         i = len(tabs)
         if self.widget:
             for n, window in self.tabs[i:]:
                 self.widget.RemovePage(i)
                 window.remove(False)
         del self.tabs[i:]
         if self.widget: self.widget.SetSelection(0)
         self._is_removing_pages = False
     elif delta < 0:
         # we have to add some pages
         number = len(self.tabs) + 1
         while common.app_tree.has_name(self.name + '_pane_%s' % number):
             number += 1
         pos = len(self.tabs)
         for i in range(-delta):
             self.tabs.append(['', None])
             pos += 1
             if _has_panel:
                 window = EditPanel(self.name + '_pane_%s' % number, self,
                                    -1, self.virtual_sizer, pos,
                                    self.property_window)
                 self._add_tab(window, pos)
             else:
                 self._add_tab(None, pos)
             number += 1
         if self.widget:
             self.widget.SetSelection(self.widget.GetPageCount() - 1)
     # finally, we must update the labels of the tabs
     for i in range(len(tabs)):
         tt = misc.wxstr(tabs[i][0])
         if self.widget:
             self.widget.SetPageText(i, tt)
         self.tabs[i][0] = tt
コード例 #7
0
ファイル: notebook.py プロジェクト: NonPlayerCtrl/FreePLC_IDE
    def insert_tab(self, index, label):

        # add tab/page this needs to be done before EditPanel calls self.virtual_sizer.add_item
        tabs_p = self.properties["tabs"]
        tabs = tabs_p.get()
        tabs.insert(index, [
            label,
        ])
        tabs_p.set(tabs)
        self.pages.insert(index, None)
        # adjust pos of the following pages
        for i, page in enumerate(self.pages[index + 1:]):
            pos_p = page.properties["pos"]
            pos_p.set(index + 2 + i)

        pos = index + 1
        window = EditPanel(self.next_pane_name(suggestion=label), self, -1,
                           self.virtual_sizer, pos)
        window._dont_destroy = True
        node = Node(window)

        window.node = node
        common.app_tree.add(node, self.node)

        if self.widget:
            window.create()
            compat.SetToolTip(window.widget,
                              _("Notebook page pane:\nAdd a sizer here"))
            self.virtual_sizer.insert_tab(index)

            try:
                wx.CallAfter(window.sel_marker.update)
            except AttributeError:
                #self._logger.exception(_('Internal Error'))
                import os
                if 'WINGDB_ACTIVE' in os.environ: raise
        self.properties["tabs"].update_display()
コード例 #8
0
ファイル: splitter_window.py プロジェクト: italomaia/spe
def builder(parent, sizer, pos, number=[1]):
    """\
    factory function for EditSplitterWindow objects.
    """
    class Dialog(wx.Dialog):
        def __init__(self):
            wx.Dialog.__init__(self, None, -1, 'Select orientation')
            self.orientations = [wx.SPLIT_VERTICAL, wx.SPLIT_HORIZONTAL]
            self.orientation = wx.SPLIT_VERTICAL
            prop = RadioProperty(self,
                                 'orientation',
                                 self,
                                 ['wxSPLIT_VERTICAL', 'wxSPLIT_HORIZONTAL'],
                                 label=_("orientation"))
            szr = wx.BoxSizer(wx.VERTICAL)
            szr.Add(prop.panel, 0, wx.ALL | wx.EXPAND, 10)
            btn = wx.Button(self, wx.ID_OK, _('OK'))
            btn.SetDefault()
            szr.Add(btn, 0, wx.BOTTOM | wx.ALIGN_CENTER, 10)
            self.SetAutoLayout(True)
            self.SetSizer(szr)
            szr.Fit(self)
            self.CenterOnScreen()

        def __getitem__(self, value):
            def set_orientation(o):
                self.orientation = self.orientations[o]

            return (lambda: self.orientation, set_orientation)

    # end of inner class

    dialog = Dialog()
    dialog.ShowModal()
    name = 'window_%d' % number[0]
    while common.app_tree.has_name(name):
        number[0] += 1
        name = 'window_%d' % number[0]
    window = EditSplitterWindow(name,
                                parent,
                                wx.NewId(),
                                None,
                                None,
                                None,
                                dialog.orientation,
                                sizer,
                                pos,
                                common.property_panel,
                                show=False)
    try:
        from panel import EditPanel
        have_panels = True
    except ImportError:
        have_panels = False
    if have_panels:
        pane1 = EditPanel(name + '_pane_1', window, wx.NewId(),
                          window.virtual_sizer, 1, common.property_panel)
        pane2 = EditPanel(name + '_pane_2', window, wx.NewId(),
                          window.virtual_sizer, 2, common.property_panel)
        window.window_1 = pane1
        window.window_2 = pane2

    node = Tree.Node(window)
    window.node = node
    window.virtual_sizer.node = node

    window.set_option(1)
    window.set_flag("wxEXPAND")
    window.show_widget(True)

    common.app_tree.insert(node, sizer.node, pos - 1)

    if have_panels:
        node2 = Tree.Node(window.window_1)
        window.window_1.node = node2
        common.app_tree.add(node2, window.node)

        node3 = Tree.Node(window.window_2)
        window.window_2.node = node3
        common.app_tree.add(node3, window.node)

    sizer.set_item(window.pos, 1, wx.EXPAND)
コード例 #9
0
    def set_tabs(self, old_names,
                 indices):  # called from tabs proberty on Apply button
        """tabs: list of strings
        indices: the current indices of the tabs or None for a new tab; re-ordering is currently not supported"""
        keep_indices = [i for i in indices if i is not None]
        if keep_indices != sorted(keep_indices):
            raise ValueError("Re-ordering is not yet implemented")
        keep_indices = set(keep_indices)
        new_names = old_names[:]

        # set tab labels of existing pages, if modified
        for (name, ), index in zip(self.tabs, indices):
            if index is not None and old_names[index] != name:
                new_names[index] = [
                    name,
                ]
                if self.widget:
                    self.widget.SetPageText(index, name)

        # remove tabs
        for index in range(len(old_names) - 1, -1, -1):
            if not index in keep_indices:
                self._is_removing_pages = True
                self.virtual_sizer.remove_tab(
                    index)  # remove from sizer; does not delete window
                self.pages[index]._remove(
                )  # delete the page content without setting the focus
                common.app_tree.remove(
                    self.pages[index].node)  # remove from tree
                del self.pages[index]  # delete from page list
                del new_names[index]  # delete from list of names
                self._is_removing_pages = False

        # insert/add tabs
        added = None
        for i, (name, ) in enumerate(self.tabs):
            index = indices[i]
            if index is not None:
                # old tab to be kept, just ensure that pos is correct
                pos_p = self.pages[i].properties["pos"]
                if pos_p.value != i + 1: pos_p.set(i + 1)
                continue

            # actually add/insert
            new_names.insert(
                i, [
                    name,
                ]
            )  # this needs to be done before EditPanel calls self.virtual_sizer.add_item
            self.pages.insert(i, None)
            # create panel and node, add to tree
            pos = i + 1
            suggestion = "%s_%s" % (self.name, name)
            window = EditPanel(self.next_pane_name(suggestion), self, -1,
                               self.virtual_sizer, pos)
            window._dont_destroy = True
            node = window.node = Node(window)

            # adjust pos of the following pages
            for p, page in enumerate(self.pages[i + 1:]):
                pos_p = page.properties["pos"]
                pos_p.set(i + 2 + p)

            self.virtual_sizer.add_item(window, pos)
            common.app_tree.insert(node, self.node, i, select=False)

            if self.widget:
                # add to widget
                window.create()
                compat.SetToolTip(window.widget,
                                  _("Notebook page pane:\nAdd a sizer here"))
                self.virtual_sizer.insert_tab(i)

                try:
                    wx.CallAfter(window.sel_marker.update)
                except AttributeError:
                    if config.debugging: raise

                added = i  # remember last added index for selection

        # select the last added tab
        if added is not None and self.widget:
            self.widget.SetSelection(added)

        # update tree labels
        for node in self.node.children:
            node.refresh(refresh_label=True, refresh_image=False)
コード例 #10
0
ファイル: notebook.py プロジェクト: NonPlayerCtrl/FreePLC_IDE
    def set_tabs(self, old_names, indices):
        """tabs: list of strings
        indices: the current indices of the tabs or None for a new tab; re-ordering is currently not supported"""
        keep_indices = [i for i in indices if i is not None]
        if keep_indices != sorted(keep_indices):
            raise ValueError("Re-ordering is not yet implemented")
        keep_indices = set(keep_indices)
        new_names = old_names[:]

        # set tab labels of existing pages, if modified
        for (name, ), index in zip(self.tabs, indices):
            if index is not None and old_names[index] != name:
                new_names[index] = [
                    name,
                ]
                if self.widget:
                    self.widget.SetPageText(index, name)

        # remove tabs
        for index in range(len(old_names) - 1, -1, -1):
            if not index in keep_indices:
                self._is_removing_pages = True
                self.virtual_sizer.remove_tab(
                    index)  # remove from sizer; does not delete window
                self.pages[index].remove(False)  # delete the page content
                del self.pages[index]  # delete from page list
                del new_names[index]  # delete from list of names
                self._is_removing_pages = False

        # insert/add tabs
        added = None
        for i, (name, ) in enumerate(self.tabs):
            index = indices[i]
            if index is not None: continue  # old tab to be kept

            # actually add/insert
            new_names.insert(
                i, [
                    name,
                ]
            )  # this needs to be done before EditPanel calls self.virtual_sizer.add_item
            self.pages.insert(i, None)
            # create panel and node, add to tree
            pos = i + 1
            window = EditPanel(self.next_pane_name(name), self, -1,
                               self.virtual_sizer, pos)
            window._dont_destroy = True
            node = window.node = Node(window)

            # adjust pos of the following pages
            for p, page in enumerate(self.pages[i + 1:]):
                pos_p = page.properties["pos"]
                pos_p.set(i + 2 + p)

            self.virtual_sizer.add_item(window, pos)
            common.app_tree.insert(node, self.node, i)
            # add to widget
            if self.widget:
                window.create()
                compat.SetToolTip(window.widget,
                                  _("Notebook page pane:\nAdd a sizer here"))
                self.virtual_sizer.insert_tab(i)

                try:
                    wx.CallAfter(window.sel_marker.update)
                except AttributeError:
                    import os
                    if 'WINGDB_ACTIVE' in os.environ: raise

                added = i  # remember last added index for selection

        # select the last added tab
        if added is not None and self.widget:
            self.widget.SetSelection(added)
コード例 #11
0
def builder(parent, sizer, pos, number=[1]):
    """\
    factory function for EditNotebook objects.
    """
    class Dialog(wx.Dialog):
        def __init__(self):
            wx.Dialog.__init__(self, None, -1, _('Select tab placement'))
            self.styles = [0, wx.NB_BOTTOM, wx.NB_LEFT, wx.NB_RIGHT]
            self.style = 0
            prop = RadioProperty(
                self,
                'tab_placement',
                self, [_('Top'), _('Bottom'),
                       _('Left'), _('Right')],
                columns=2,
                label=_('tab_placement'))
            szr = wx.BoxSizer(wx.VERTICAL)
            szr.Add(prop.panel, 0, wx.ALL | wx.EXPAND, 10)
            btn = wx.Button(self, wx.ID_OK, _('OK'))
            btn.SetDefault()
            szr.Add(btn, 0, wx.BOTTOM | wx.ALIGN_CENTER, 10)
            self.SetAutoLayout(True)
            self.SetSizer(szr)
            szr.Fit(self)
            self.CenterOnScreen()

        def __getitem__(self, value):
            def set_style(s):
                self.style = self.styles[s]

            return (lambda: self.style, set_style)

    # end of inner class

    dialog = Dialog()
    dialog.ShowModal()
    name = 'notebook_%d' % number[0]
    while common.app_tree.has_name(name):
        number[0] += 1
        name = 'notebook_%d' % number[0]
    window = EditNotebook(name,
                          parent,
                          wx.NewId(),
                          dialog.style,
                          sizer,
                          pos,
                          common.property_panel,
                          show=False)
    if _has_panel:
        pane1 = EditPanel(name + '_pane_1', window, wx.NewId(),
                          window.virtual_sizer, 1, common.property_panel)

    node = Tree.Node(window)
    window.node = node
    window.virtual_sizer.node = node

    window.set_option(1)
    window.set_flag("wxEXPAND")
    window.show_widget(True)
    common.app_tree.insert(node, sizer.node, pos - 1)

    if _has_panel:
        window._add_tab(pane1, 1)

    sizer.set_item(window.pos, 1, wx.EXPAND)
コード例 #12
0
    def set_tabs(self, old_labels,
                 indices):  # called from tabs proberty on Apply button
        """tabs: list of strings
        indices: the current indices of the tabs or None for a new tab; re-ordering is currently not supported"""
        keep_indices = [pos for pos in indices if pos is not None]
        if keep_indices != sorted(keep_indices):
            raise ValueError("Re-ordering is not yet implemented")
        keep_indices = set(keep_indices)
        new_labels = old_labels[:]

        # set tab labels of existing pages, if modified
        for (label, ), index in zip(self.tabs, indices):
            if index is not None and old_labels[index] != label:
                new_labels[index] = [
                    label,
                ]
                if self.widget:
                    self.widget.SetPageText(index, label)

        # remove tabs
        for index in range(len(old_labels) - 1, -1, -1):
            if not index in keep_indices:
                self._is_removing_pages = True
                self.children[index].recursive_remove()
                if self.widget:
                    self.widget.RemovePage(index)  # deletes the specified page
                del new_labels[index]  # delete from list of names
                self._is_removing_pages = False

        # insert/add tabs
        added = None
        for pos, (label, ) in enumerate(self.tabs):
            index = indices[pos]
            if index is not None:
                # old tab to be kept, just ensure that pos is correct
                pos_p = self.children[pos].properties["pos"]
                if pos_p.value != pos: pos_p.set(pos)
                continue

            # actually add/insert
            new_labels.insert(
                pos, [
                    label,
                ]
            )  # this needs to be done before EditPanel calls self.virtual_sizer.add_item
            self.children.insert(pos, None)
            # create panel and node, add to tree
            suggestion = "%s_%s" % (self.name, label)
            editor = EditPanel(self.next_pane_name(suggestion), self, pos)

            # adjust pos of the following pages
            for p, page in enumerate(self.children[pos + 1:]):
                pos_p = page.properties["pos"]
                pos_p.set(pos + 2 + p)

            if self.widget:
                # add to widget
                editor.create()
                self.vs_insert_tab(pos)

                try:
                    wx.CallAfter(editor.sel_marker.update)
                except AttributeError:
                    if config.debugging: raise

                added = pos  # remember last added index for selection

        # select the last added tab
        if added is not None and self.widget:
            self.widget.SetSelection(added)

        common.app_tree.build(self, recursive=False)