Beispiel #1
0
    def __init__(self, parent):
        """Data Catalog Tree constructor."""
        super(DataCatalogTree, self).__init__(parent)

        self._initVariablesCatalog()

        wx.EVT_TREE_BEGIN_DRAG(self, wx.ID_ANY, self.OnBeginDrag)
        wx.EVT_TREE_END_DRAG(self, wx.ID_ANY, self.OnEndDrag)

        wx.EVT_TREE_END_LABEL_EDIT(self, wx.ID_ANY, self.OnEditLabel)
        wx.EVT_TREE_BEGIN_LABEL_EDIT(self, wx.ID_ANY, self.OnStartEditLabel)
Beispiel #2
0
    def __init__(self, parent, image_size=(16, 16), **traits):
        """ Creates a new tree viewer.

        'parent' is the toolkit-specific control that is the tree's parent.

        'image_size' is a tuple in the form (int width, int height) that
        specifies the size of the label images (if any) displayed in the tree.

        """

        # Base class constructor.
        super(TreeViewer, self).__init__(**traits)

        # Create the toolkit-specific control.
        self.control = tree = wx.TreeCtrl(parent, -1, style=self._get_style())

        # Get our actual Id.
        wxid = tree.GetId()

        # Wire up the wx tree events.
        wx.EVT_CHAR(tree, self._on_char)
        wx.EVT_LEFT_DOWN(tree, self._on_left_down)
        wx.EVT_RIGHT_DOWN(tree, self._on_right_down)
        wx.EVT_TREE_ITEM_ACTIVATED(tree, wxid, self._on_tree_item_activated)
        wx.EVT_TREE_ITEM_COLLAPSED(tree, wxid, self._on_tree_item_collapsed)
        wx.EVT_TREE_ITEM_COLLAPSING(tree, wxid, self._on_tree_item_collapsing)
        wx.EVT_TREE_ITEM_EXPANDED(tree, wxid, self._on_tree_item_expanded)
        wx.EVT_TREE_ITEM_EXPANDING(tree, wxid, self._on_tree_item_expanding)
        wx.EVT_TREE_BEGIN_LABEL_EDIT(tree, wxid,
                                     self._on_tree_begin_label_edit)
        wx.EVT_TREE_END_LABEL_EDIT(tree, wxid, self._on_tree_end_label_edit)
        wx.EVT_TREE_BEGIN_DRAG(tree, wxid, self._on_tree_begin_drag)
        wx.EVT_TREE_SEL_CHANGED(tree, wxid, self._on_tree_sel_changed)

        # The image list is a wxPython-ism that caches all images used in the
        # control.
        self._image_list = ImageList(image_size[0], image_size[1])
        if self.show_images:
            tree.AssignImageList(self._image_list)

        # Mapping from element to wx tree item Ids.
        self._element_to_id_map = {}

        # Add the root item.
        if self.input is not None:
            self._add_element(None, self.input)

        return
Beispiel #3
0
    def __init__(self, parent, image_size=(16, 16), **traits):
        """ Creates a new tree.

        'parent' is the toolkit-specific control that is the tree's parent.

        'image_size' is a tuple in the form (int width, int height) that
        specifies the size of the images (if required) displayed in the tree.

        """

        # Base class constructors.
        super(Tree, self).__init__(**traits)

        # Get our wx Id.
        wxid = wx.NewId()

        # Create the toolkit-specific control.
        self.control = tree = _Tree(self,
                                    parent,
                                    wxid,
                                    style=self._get_style())

        # Wire up the wx tree events.
        wx.EVT_CHAR(tree, self._on_char)
        wx.EVT_LEFT_DOWN(tree, self._on_left_down)
        # fixme: This is not technically correct as context menus etc should
        # appear on a right up (or right click).  Unfortunately,  if we
        # change this to 'EVT_RIGHT_UP' wx does not fire the event unless the
        # right mouse button is double clicked 8^()  Sad,  but true!
        wx.EVT_RIGHT_DOWN(tree, self._on_right_down)
        # fixme: This is not technically correct as we would really like to use
        # 'EVT_TREE_ITEM_ACTIVATED'. Unfortunately, (in 2.6 at least), it
        # throws an exception when the 'Enter' key is pressed as the wx tree
        # item Id in the event seems to be invalid. It also seems to cause
        # any child frames that my be created in response to the event to
        # appear *behind* the parent window, which is, errrr, not great ;^)
        wx.EVT_LEFT_DCLICK(tree, self._on_tree_item_activated)
        #wx.EVT_TREE_ITEM_ACTIVATED(tree, wxid, self._on_tree_item_activated)
        wx.EVT_TREE_ITEM_COLLAPSING(tree, wxid, self._on_tree_item_collapsing)
        wx.EVT_TREE_ITEM_COLLAPSED(tree, wxid, self._on_tree_item_collapsed)
        wx.EVT_TREE_ITEM_EXPANDING(tree, wxid, self._on_tree_item_expanding)
        wx.EVT_TREE_ITEM_EXPANDED(tree, wxid, self._on_tree_item_expanded)
        wx.EVT_TREE_BEGIN_LABEL_EDIT(tree, wxid,
                                     self._on_tree_begin_label_edit)
        wx.EVT_TREE_END_LABEL_EDIT(tree, wxid, self._on_tree_end_label_edit)
        wx.EVT_TREE_BEGIN_DRAG(tree, wxid, self._on_tree_begin_drag)
        wx.EVT_TREE_SEL_CHANGED(tree, wxid, self._on_tree_sel_changed)
        wx.EVT_TREE_DELETE_ITEM(tree, wxid, self._on_tree_delete_item)

        # Enable the tree as a drag and drop target.
        self.control.SetDropTarget(PythonDropTarget(self))

        # The image list is a wxPython-ism that caches all images used in the
        # control.
        self._image_list = ImageList(image_size[0], image_size[1])
        if self.show_images:
            tree.AssignImageList(self._image_list)

        # Mapping from node to wx tree item Ids.
        self._node_to_id_map = {}

        # Add the root node.
        if self.root is not None:
            self._add_root_node(self.root)

        # Listen for changes to the model.
        self._add_model_listeners(self.model)

        return
Beispiel #4
0
    def __init__(self, toolbar, settings, parent):
        self.__toolbar = toolbar
        self.__visible = toolbar.visibleUICommands()

        super(_ToolBarEditorInterior, self).__init__(parent)

        vsizer = wx.BoxSizer(wx.VERTICAL)

        # Toolbar preview
        sb = wx.StaticBox(self, wx.ID_ANY, _('Preview'))
        from taskcoachlib.gui.toolbar import ToolBar
        self.__preview = ToolBar(self, settings,
                                 self.__toolbar.GetToolBitmapSize())
        sbsz = wx.StaticBoxSizer(sb)
        sbsz.Add(self.__preview, 1)
        vsizer.Add(sbsz, 0, wx.EXPAND | wx.ALL, 3)
        self.__HackPreview()

        hsizer = wx.BoxSizer(wx.HORIZONTAL)

        self.__imgList = wx.ImageList(16, 16)
        self.__imgListIndex = dict()
        empty = wx.EmptyImage(16, 16)
        empty.Replace(0, 0, 0, 255, 255, 255)
        self.__imgListIndex['nobitmap'] = self.__imgList.Add(
            empty.ConvertToBitmap())
        for uiCommand in toolbar.uiCommands():
            if uiCommand is not None and not isinstance(
                    uiCommand, int) and uiCommand.bitmap != 'nobitmap':
                self.__imgListIndex[uiCommand.bitmap] = self.__imgList.Add(
                    wx.ArtProvider.GetBitmap(uiCommand.bitmap, wx.ART_MENU,
                                             (16, 16)))

        # Remaining commands list
        sb = wx.StaticBox(self, wx.ID_ANY, _('Available tools'))
        self.__remainingCommands = _AutoWidthTree(
            self,
            agwStyle=htl.TR_NO_BUTTONS | htl.TR_SINGLE | htl.TR_NO_LINES
            | htl.TR_HIDE_ROOT | htl.TR_NO_HEADER | htl.TR_FULL_ROW_HIGHLIGHT)
        self.__remainingCommands.AddColumn('Command')
        self.__remainingCommands.SetImageList(self.__imgList)

        sbsz = wx.StaticBoxSizer(sb)
        sbsz.Add(self.__remainingCommands, 1, wx.EXPAND)
        hsizer.Add(sbsz, 1, wx.EXPAND | wx.ALL, 3)

        self.__PopulateRemainingCommands()

        # Show/hide buttons
        btnSizer = wx.BoxSizer(wx.VERTICAL)
        self.__showButton = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap('next', wx.ART_BUTTON, (16, 16)))
        self.__showButton.Enable(False)
        self.__showButton.SetToolTip(
            wx.ToolTip(_('Make this tool visible in the toolbar')))
        btnSizer.Add(self.__showButton, wx.ALL, 3)
        self.__hideButton = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap('prev', wx.ART_BUTTON, (16, 16)))
        self.__hideButton.Enable(False)
        self.__hideButton.SetToolTip(
            wx.ToolTip(_('Hide this tool from the toolbar')))
        btnSizer.Add(self.__hideButton, wx.ALL, 3)
        hsizer.Add(btnSizer, 0, wx.ALIGN_CENTRE)

        # Visible commands list
        sb = wx.StaticBox(self, wx.ID_ANY, _('Tools'))
        self.__visibleCommands = _AutoWidthTree(
            self,
            agwStyle=htl.TR_NO_BUTTONS | htl.TR_SINGLE | htl.TR_NO_LINES
            | htl.TR_HIDE_ROOT | htl.TR_NO_HEADER | htl.TR_FULL_ROW_HIGHLIGHT)
        self.__visibleCommands.AddColumn('Command')
        self.__visibleCommands.SetImageList(self.__imgList)

        sbsz = wx.StaticBoxSizer(sb)
        sbsz.Add(self.__visibleCommands, 1, wx.EXPAND)
        hsizer.Add(sbsz, 1, wx.EXPAND | wx.ALL, 3)

        # Move buttons
        btnSizer = wx.BoxSizer(wx.VERTICAL)
        self.__moveUpButton = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap('up', wx.ART_BUTTON, (16, 16)))
        self.__moveUpButton.Enable(False)
        self.__moveUpButton.SetToolTip(
            wx.ToolTip(_('Move the tool up (to the left of the toolbar)')))
        btnSizer.Add(self.__moveUpButton, wx.ALL, 3)
        self.__moveDownButton = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider.GetBitmap('down', wx.ART_BUTTON, (16, 16)))
        self.__moveDownButton.Enable(False)
        self.__moveDownButton.SetToolTip(
            wx.ToolTip(_('Move the tool down (to the right of the toolbar)')))
        btnSizer.Add(self.__moveDownButton, wx.ALL, 3)
        hsizer.Add(btnSizer, 0, wx.ALIGN_CENTRE)

        self.__PopulateVisibleCommands()

        vsizer.Add(hsizer, 1, wx.EXPAND | wx.ALL, 3)
        self.SetSizer(vsizer)

        self.__remainingSelection = None
        self.__visibleSelection = None
        self.__draggedItem = None
        self.__draggingFromAvailable = False
        wx.EVT_TREE_SEL_CHANGED(self.__remainingCommands, wx.ID_ANY,
                                self.__OnRemainingSelectionChanged)
        wx.EVT_TREE_SEL_CHANGED(self.__visibleCommands, wx.ID_ANY,
                                self.__OnVisibleSelectionChanged)
        wx.EVT_BUTTON(self.__hideButton, wx.ID_ANY, self.__OnHide)
        wx.EVT_BUTTON(self.__showButton, wx.ID_ANY, self.__OnShow)
        wx.EVT_BUTTON(self.__moveUpButton, wx.ID_ANY, self.__OnMoveUp)
        wx.EVT_BUTTON(self.__moveDownButton, wx.ID_ANY, self.__OnMoveDown)
        wx.EVT_TREE_BEGIN_DRAG(self.__visibleCommands, wx.ID_ANY,
                               self.__OnBeginDrag)
        wx.EVT_TREE_END_DRAG(self.__visibleCommands, wx.ID_ANY,
                             self.__OnEndDrag)
        wx.EVT_TREE_BEGIN_DRAG(self.__remainingCommands, wx.ID_ANY,
                               self.__OnBeginDrag2)

        wx.CallAfter(
            wx.GetTopLevelParent(self).AddBalloonTip,
            settings,
            'customizabletoolbars_dnd',
            self.__visibleCommands,
            title=_('Drag and drop'),
            message=
            _('''Reorder toolbar buttons by drag and dropping them in this list.'''
              ))