def setShortcut(self, modifier, key, action): shortcut = (modifier, key) if shortcut in self.shortcuts.values(): self.prompt('Warning', 'This combination is already in use.', 'OK', helpId='shortcutWarning') return False self.shortcuts[action.name] = shortcut mh.setShortcut(modifier, key, action) return True
def createShortcuts(self): for action, (modifier, key) in self.shortcuts.iteritems(): action = getattr(self.actions, action, None) if action is not None: mh.setShortcut(modifier, key, action)
def createFilterModeSwitch(self): action = gui.Action('switchFilterMode', language.getLanguageString('Switch Filter Mode'), self.switchFilterMode) gui3d.app.mainwin.addAction(action) mh.setShortcut(mh.Modifiers.ALT, mh.Keys.f, action)
def createShortcuts(self): for action, (modifier, key) in self.shortcuts.iteritems(): action = getattr(self.actions, action, None) if action is not None: mh.setShortcut(modifier, key, action)
def __init__(self, category): super(ShellTaskView, self).__init__(category, 'Shell') self.globals = {'G': G} self.history = [] self.histitem = None if hasIpython: # Use the more advanced Ipython console self.console = self.addTopWidget( ipythonconsole.IPythonConsoleWidget()) def gotoshell(): mh.changeTask('Utilities', 'Shell') action = gui.Action('ishell', language.getLanguageString('IPython shell'), gotoshell) G.app.mainwin.addAction(action) mh.setShortcut(mh.Modifiers.CTRL, mh.Keys.i, action) return # Fall back to old console self.console = None self.main = self.addTopWidget(QtWidgets.QWidget()) self.layout = QtWidgets.QGridLayout(self.main) self.layout.setRowStretch(0, 0) self.layout.setRowStretch(1, 0) self.layout.setColumnStretch(0, 1) self.layout.setColumnStretch(1, 0) self.text = gui.DocumentEdit() self.text.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.layout.addWidget(self.text, 0, 0, 1, 2) self.line = ShellTextEdit() self.line.setFocusPolicy(QtCore.Qt.StrongFocus) self.layout.addWidget(self.line, 1, 0, 1, 1) self.globals = {'G': G} self.clear = gui.Button("Clear") self.layout.addWidget(self.clear, 1, 1, 1, 1) action = gui.Action('shell', language.getLanguageString('Default shell'), self.gotodefaultshell) G.app.mainwin.addAction(action) mh.setShortcut(mh.Modifiers.SHIFT, mh.Keys.s, action) @self.line.mhEvent def onActivate(text): self.execute(text) self.history.append(text) self.histitem = None self.line.setText('') @self.line.mhEvent def onTabPressed(edit): def _longest_common_substring(s1, s2): """ This is simply the O(n) left-aligned version """ limit = min(len(s1), len(s2)) i = 0 while i < limit and s1[i] == s2[i]: i += 1 return s1[:i] def _largest_common(strings): strings = list(strings) try: strings.remove('...') except: pass if len(strings) == 0: return "" elif len(strings) == 1: return strings[0] else: result = strings[0] for s in strings[1:]: result = _longest_common_substring(result, s) return result line = edit.getText() suggestions = self.getSuggestions(line) if len(suggestions) == 0: return if len(suggestions) > 1: self.write('\n'.join(suggestions) + "\n") scrollbar = self.text.verticalScrollBar() scrollbar.setSliderPosition(scrollbar.maximum()) edit.setText(_largest_common(suggestions)) elif len(suggestions) == 1: edit.setText(suggestions[0]) @self.clear.mhEvent def onClicked(event): self.clearText() @self.line.mhEvent def onUpArrow(_dummy): self.upArrow() @self.line.mhEvent def onDownArrow(_dummy): self.downArrow()