Exemplo n.º 1
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.'''
              ))