def __init__(self, parent, shellStack): QtWidgets.QToolButton.__init__(self, parent) # Store reference of shell stack self._shellStack = shellStack # Keep reference of actions corresponding to shells self._shellActions = [] # Set text and tooltip self.setText("Warming up ...") self.setToolTip(translate("shells", "Click to select shell.")) self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.setPopupMode(self.InstantPopup) # Set icon self._iconMaker = ShellIconMaker(self) self._iconMaker.updateIcon("busy") # Busy initializing # Create timer self._elapsedTimesTimer = QtCore.QTimer(self) self._elapsedTimesTimer.setInterval(1000) self._elapsedTimesTimer.setSingleShot(False) self._elapsedTimesTimer.timeout.connect(self.onElapsedTimesTimer)
def __init__(self, parent, shellStack): QtGui.QToolButton.__init__(self, parent) # Store reference of shell stack self._shellStack = shellStack # Keep reference of actions corresponding to shells self._shellActions = [] # Set text and tooltip self.setText('Warming up ...') self.setToolTip("Click to select shell.") self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.setPopupMode(self.InstantPopup) # Set icon self._iconMaker = ShellIconMaker(self) self._iconMaker.updateIcon('busy') # Busy initializing # Create timer self._elapsedTimesTimer = QtCore.QTimer(self) self._elapsedTimesTimer.setInterval(200) self._elapsedTimesTimer.setSingleShot(False) self._elapsedTimesTimer.timeout.connect(self.onElapsedTimesTimer)
class ShellControl(QtWidgets.QToolButton): """A button that can be used to select a shell and start a new shell.""" def __init__(self, parent, shellStack): QtWidgets.QToolButton.__init__(self, parent) # Store reference of shell stack self._shellStack = shellStack # Keep reference of actions corresponding to shells self._shellActions = [] # Set text and tooltip self.setText("Warming up ...") self.setToolTip(translate("shells", "Click to select shell.")) self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.setPopupMode(self.InstantPopup) # Set icon self._iconMaker = ShellIconMaker(self) self._iconMaker.updateIcon("busy") # Busy initializing # Create timer self._elapsedTimesTimer = QtCore.QTimer(self) self._elapsedTimesTimer.setInterval(1000) self._elapsedTimesTimer.setSingleShot(False) self._elapsedTimesTimer.timeout.connect(self.onElapsedTimesTimer) def updateShellMenu(self, shellToUpdate=None): """Update the shell menu. Ensure that there is a menu item for each shell. If shellToUpdate is given, updates the corresponding menu item. """ menu = self.menu() # Get shells now active currentShell = self._shellStack.currentWidget() shells = [ self._shellStack.widget(i) for i in range(self._shellStack.count()) ] # Synchronize actions. Remove invalid actions for action in self._shellActions: # Check match with shells if action._shell in shells: shells.remove(action._shell) else: menu.removeAction(action) # Update checked state if action._shell is currentShell and currentShell: action.setChecked(True) else: action.setChecked(False) # Update text if necessary if action._shell is shellToUpdate: action.setText(shellTitle(shellToUpdate, True)) # Any items left in shells need a menu item # Dont give them an icon, or the icon is used as checkbox thingy for shell in shells: text = shellTitle(shell) action = menu.addItem(text, None, self._shellStack.setCurrentWidget, shell) action._shell = shell action.setCheckable(True) self._shellActions.append(action) # Is the shell being updated the current? if currentShell is shellToUpdate and currentShell is not None: self._iconMaker.updateIcon(currentShell._state) self.setText(shellTitle(currentShell)) elif currentShell is None: self._iconMaker.updateIcon("") self.setText("No shell selected") def onElapsedTimesTimer(self): # Automatically turn timer off is menu is hidden if not self.menu().isVisible(): self._elapsedTimesTimer.stop() return # Update text for each shell action for action in self._shellActions: action.setText(shellTitle(action._shell, True))
class ShellControl(QtGui.QToolButton): """ A button that can be used to select a shell and start a new shell. """ def __init__(self, parent, shellStack): QtGui.QToolButton.__init__(self, parent) # Store reference of shell stack self._shellStack = shellStack # Keep reference of actions corresponding to shells self._shellActions = [] # Set text and tooltip self.setText('Warming up ...') self.setToolTip("Click to select shell.") self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.setPopupMode(self.InstantPopup) # Set icon self._iconMaker = ShellIconMaker(self) self._iconMaker.updateIcon('busy') # Busy initializing # Create timer self._elapsedTimesTimer = QtCore.QTimer(self) self._elapsedTimesTimer.setInterval(200) self._elapsedTimesTimer.setSingleShot(False) self._elapsedTimesTimer.timeout.connect(self.onElapsedTimesTimer) def updateShellMenu(self, shellToUpdate=None): """ Update the shell menu. Ensure that there is a menu item for each shell. If shellToUpdate is given, updates the corresponding menu item. """ menu = self.menu() # Get shells now active currentShell = self._shellStack.currentWidget() shells = [self._shellStack.widget(i) for i in range(self._shellStack.count())] # Synchronize actions. Remove invalid actions for action in self._shellActions: # Check match with shells if action._shell in shells: shells.remove(action._shell) else: menu.removeAction(action) # Update checked state if action._shell is currentShell and currentShell: action.setChecked(True) else: action.setChecked(False) # Update text if necessary if action._shell is shellToUpdate: action.setText(shellTitle(shellToUpdate, True)) # Any items left in shells need a menu item # Dont give them an icon, or the icon is used as checkbox thingy for shell in shells: text = shellTitle(shell) action = menu.addItem(text, None, self._shellStack.setCurrentWidget, shell) action._shell = shell action.setCheckable(True) self._shellActions.append(action) # Is the shell being updated the current? if currentShell is shellToUpdate and currentShell is not None: self._iconMaker.updateIcon(currentShell._state) self.setText(shellTitle(currentShell)) elif currentShell is None: self._iconMaker.updateIcon('') self.setText('No shell selected') def onElapsedTimesTimer(self): # Automatically turn timer off is menu is hidden if not self.menu().isVisible(): self._elapsedTimesTimer.stop() return # Update text for each shell action for action in self._shellActions: action.setText(shellTitle(action._shell, True))