def __init__(self, MEDIA_FOLDER): QtGui.QWidget.__init__(self) self.is_active = True self.max_hist_len = 5 self._c = 0#count all added backups self.reset() self.setContentsMargins (0, 0, 0, 0) #HISTORY MENU self.menu = QtGui.QMenu() self.menu.aboutToShow.connect(self._showMenu) hl = QtGui.QHBoxLayout() hl.setContentsMargins (0, 0, 0, 0) self.setLayout(hl) icon_path = MEDIA_FOLDER.join("icons") #UNDO BUTTON self.btn_undo = QtGui.QToolButton() self.btn_undo.setAutoRaise(True) self.btn_undo.setToolTip('Undo') self.btn_undo.setIcon(QtGui.QIcon(icon_path.join('undo.svg'))) self.btn_undo.setShortcut (QtGui.QKeySequence.Undo) self.btn_undo.clicked.connect(self.undo) self.btn_undo.setEnabled(False) #MENU BUTTON self.btn_menu = QtGui.QToolButton() self.btn_menu.setAutoRaise(True) self.btn_menu.setFixedWidth(9) self.btn_menu.setToolTip('Undo/Redo options') self.btn_menu.setMenu(self.menu) self.btn_menu.setPopupMode(QtGui.QToolButton.InstantPopup) self.menu_options = _MenuOptions() self.menu_options.activate.stateChanged.connect(self.setActive) action = QtGui.QWidgetAction(self) action.setDefaultWidget(self.menu_options) self.menu.addAction(action) #REDO BUTTON self.btn_redo = QtGui.QToolButton() self.btn_redo.setAutoRaise(True) self.btn_redo.setToolTip('Redo') self.btn_redo.setIcon(QtGui.QIcon(icon_path.join('redo.svg'))) self.btn_redo.clicked.connect(self.redo) self.btn_redo.setShortcut (QtGui.QKeySequence.Redo) self.btn_redo.setEnabled(False) hl.addWidget(self.btn_undo) hl.addWidget(self.btn_menu) hl.addWidget(self.btn_redo)
def __init__(self, display): QtGui.QToolButton.__init__(self) self.display = display self.view = display.widget.view.vb #SET ICON icon = getattr(self, 'icon', None) if icon: if not os.path.exists(icon): icon = ICONFOLDER.join(icon) self.setIcon (QtGui.QIcon(icon)) #SET TOOLTIP if self.__doc__: #USING THE CLASS DOC t = '%s\n\t%s' %(self.__class__.__name__, self.__doc__) else: #USING THE CLASS NAME t =self.__class__.__name__ self.setToolTip(t) #SETUP CHECKABILITY: if hasattr(self, 'activate'): try: #if a tool has a method deactivate it should be checkable self.deactivate self.setCheckable(True) except AttributeError: self.deactivate = self._deactivate self.setCheckable(False) else: self.setPopupMode(QtGui.QToolButton.InstantPopup) self.clicked.connect(self.toggle)