Beispiel #1
0
 def setup_context_menu(self):
     """Reimplements ShellBaseWidget method"""
     ShellBaseWidget.setup_context_menu(self)
     self.copy_without_prompts_action = create_action(
         self,
         _("Copy without prompts"),
         icon=ima.icon('copywop'),
         triggered=self.copy_without_prompts)
     clear_line_action = create_action(
         self,
         _("Clear line"),
         QKeySequence(get_shortcut('console', 'Clear line')),
         icon=ima.icon('editdelete'),
         tip=_("Clear line"),
         triggered=self.clear_line)
     clear_action = create_action(self,
                                  _("Clear shell"),
                                  QKeySequence(
                                      get_shortcut('console',
                                                   'Clear shell')),
                                  icon=ima.icon('editclear'),
                                  tip=_("Clear shell contents "
                                        "('cls' command)"),
                                  triggered=self.clear_terminal)
     add_actions(self.menu, (self.copy_without_prompts_action,
                             clear_line_action, clear_action))
Beispiel #2
0
 def add_actions_to_context_menu(self, menu):
     """Add actions to IPython widget context menu"""
     # See spyderlib/widgets/ipython.py for more details on this method
     inspect_action = create_action(
         self,
         _("Inspect current object"),
         QKeySequence(get_shortcut('console', 'inspect current object')),
         icon=get_std_icon('MessageBoxInformation'),
         triggered=self.inspect_object)
     clear_line_action = create_action(self,
                                       _("Clear line or block"),
                                       QKeySequence("Shift+Escape"),
                                       icon=get_icon('eraser.png'),
                                       triggered=self.clear_line)
     clear_console_action = create_action(
         self,
         _("Clear console"),
         QKeySequence(get_shortcut('console', 'clear shell')),
         icon=get_icon('clear.png'),
         triggered=self.clear_console)
     quit_action = create_action(self,
                                 _("&Quit"),
                                 icon='exit.png',
                                 triggered=self.exit_callback)
     add_actions(menu, (None, inspect_action, clear_line_action,
                        clear_console_action, None, quit_action))
     return menu
Beispiel #3
0
    def validate_sequence(self):
        """Provide additional checks for accepting or rejecting shortcuts."""
        if self.invalid_key_flag:
            self.update_warning(warning_type=INVALID_KEY)
            return

        for mod in MODIFIERS:
            non_mod = set(self.key_non_modifiers)
            non_mod.discard(mod)
            if mod in self.key_non_modifiers:
                self.key_non_modifiers.remove(mod)

        self.key_modifiers = self.key_modifiers - non_mod

        while u'' in self.key_text:
            self.key_text.remove(u'')

        self.key_text = [k.upper() for k in self.key_text]

        # Fix Backtab, Tab issue
        if os.name == 'nt':
            if Qt.Key_Backtab in self.key_non_modifiers:
                idx = self.key_non_modifiers.index(Qt.Key_Backtab)
                self.key_non_modifiers[idx] = Qt.Key_Tab

        if len(self.key_modifiers) == 0:
            # Filter single key allowed
            if self.key_non_modifiers[0] not in VALID_SINGLE_KEYS:
                return
            # Filter
            elif len(self.key_non_modifiers) > 1:
                return

        # QKeySequence accepts a maximum of 4 different sequences
        if len(self.keys) > 4:
            # Update warning
            self.update_warning(warning_type=SEQUENCE_LENGTH)
            return

        keys = []
        for i in range(len(self.keys)):
            key_seq = 0
            for m in self.key_modifiers:
                key_seq += MODIFIERS[m]
            key_seq += self.key_non_modifiers[i]
            keys.append(key_seq)

        sequence = QKeySequence(*keys)

        self.set_sequence(sequence.toString())
Beispiel #4
0
    def create_dockwidget(self):
        """Add to parent QMainWindow as a dock widget"""

        # This is not clear yet why the following do not work...
        # (see Issue #880)
        ##         # Using Qt.Window window flags solves Issue #880 (detached dockwidgets
        ##         # are not painted after restarting Spyder and restoring their hexstate)
        ##         # but it does not work with PyQt <=v4.7 (dockwidgets can't be docked)
        ##         # or non-Windows platforms (lot of warnings are printed out)
        ##         # (so in those cases, we use the default window flags: Qt.Widget):
        ##         flags = Qt.Widget if is_old_pyqt or os.name != 'nt' else Qt.Window
        dock = SpyderDockWidget(self.get_plugin_title(), self.main)  #, flags)

        dock.setObjectName(self.__class__.__name__ + "_dw")
        dock.setAllowedAreas(self.ALLOWED_AREAS)
        dock.setFeatures(self.FEATURES)
        dock.setWidget(self)
        self.update_margins()
        dock.visibilityChanged.connect(self.visibility_changed)
        dock.plugin_closed.connect(self.plugin_closed)
        self.dockwidget = dock
        if self.shortcut is not None:
            sc = QShortcut(QKeySequence(self.shortcut), self.main,
                           self.switch_to_plugin)
            self.register_shortcut(sc, "_", "Switch to %s" % self.CONF_SECTION)
        return (dock, self.LOCATION)
Beispiel #5
0
def create_shortcut(action, context, name, parent):
    """Creates a QShortcut for a widget and returns its associated data"""
    keystr = get_shortcut(context, name)
    qsc = QShortcut(QKeySequence(keystr), parent, action)
    qsc.setContext(Qt.WidgetWithChildrenShortcut)
    sc = Shortcut(data=(qsc, name, keystr))
    return sc
Beispiel #6
0
    def data(self, index, role=Qt.DisplayRole):
        """Qt Override."""
        row = index.row()
        if not index.isValid() or not (0 <= row < len(self.shortcuts)):
            return to_qvariant()

        shortcut = self.shortcuts[row]
        key = shortcut.key
        column = index.column()

        if role == Qt.DisplayRole:
            if column == CONTEXT:
                return to_qvariant(shortcut.context)
            elif column == NAME:
                color = self.text_color
                if self._parent == QApplication.focusWidget():
                    if self.current_index().row() == row:
                        color = self.text_color_highlight
                    else:
                        color = self.text_color
                text = self.rich_text[row]
                text = '<p style="color:{0}">{1}</p>'.format(color, text)
                return to_qvariant(text)
            elif column == SEQUENCE:
                text = QKeySequence(key).toString(QKeySequence.NativeText)
                return to_qvariant(text)
            elif column == SEARCH_SCORE:
                # Treating search scores as a table column simplifies the
                # sorting once a score for a specific string in the finder
                # has been defined. This column however should always remain
                # hidden.
                return to_qvariant(self.scores[row])
        elif role == Qt.TextAlignmentRole:
            return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
        return to_qvariant()
Beispiel #7
0
    def validate_sequence(self):
        """Provide additional checks for accepting or rejecting shortcuts."""
        for mod in MODIFIERS:
            non_mod = set(self.key_non_modifiers)
            non_mod.discard(mod)
            if mod in self.key_non_modifiers:
                self.key_non_modifiers.remove(mod)

        self.key_modifiers = self.key_modifiers - non_mod

        while u'' in self.key_text:
            self.key_text.remove(u'')

        self.key_text = [k.upper() for k in self.key_text]

        # Fix Backtab, Tab issue
        if os.name == 'nt':
            if Qt.Key_Backtab in self.key_non_modifiers:
                idx = self.key_non_modifiers.index(Qt.Key_Backtab)
                self.key_non_modifiers[idx] = Qt.Key_Tab

        if len(self.key_modifiers) == 0:
            # Filter single key allowed
            if self.key_non_modifiers[0] not in VALID_SINGLE_KEYS:
                return
            # Filter
            elif len(self.key_non_modifiers) > 1:
                return

        # QKeySequence accepts a maximum of 4 different sequences
        if len(self.keys) > 4:
            # If the user enters more than 4, take the first 4 only
            self.keys = set([0, 1, 2, 3])

        keys = []
        for i in range(len(self.keys)):
            key_seq = 0
            for m in self.key_modifiers:
                key_seq += MODIFIERS[m]
            key_seq += self.key_non_modifiers[i]
            keys.append(key_seq)

        sequence = QKeySequence(*keys)
        self.set_sequence(sequence.toString())
Beispiel #8
0
 def get_options_menu(self):
     """Return options menu"""
     restart_action = create_action(self, _("Restart kernel"),
                                    shortcut=QKeySequence("Ctrl+."),
                                    icon=ima.icon('restart'),
                                    triggered=self.restart_kernel)
     restart_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     
     # Main menu
     if self.menu_actions is not None:
         actions = [restart_action, None] + self.menu_actions
     else:
         actions = [restart_action]
     return actions
Beispiel #9
0
 def create_toggle_view_action(self):
     """Associate a toggle view action with each plugin"""
     title = self.get_plugin_title()
     if self.CONF_SECTION == 'editor':
         title = _('Editor')
     if self.shortcut is not None:
         action = create_action(self,
                                title,
                                toggled=self.toggle_view,
                                shortcut=QKeySequence(self.shortcut))
         action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     else:
         action = create_action(self, title, toggled=self.toggle_view)
     self.toggle_view_action = action
Beispiel #10
0
def keybinding(attr):
    """Return keybinding"""
    ks = getattr(QKeySequence, attr)
    return from_qvariant(QKeySequence.keyBindings(ks)[0], str)
Beispiel #11
0
def keybinding(attr):
    """Return keybinding"""
    ks = getattr(QKeySequence, attr)
    return from_qvariant(QKeySequence.keyBindings(ks)[0], str)
Beispiel #12
0
 def newsc(keystr, triggered):
     sc = QShortcut(QKeySequence(keystr), parent, triggered)
     sc.setContext(Qt.WidgetWithChildrenShortcut)
     return sc
def new_shortcut(keystr, parent, action):
    """Define a new shortcut according to a keysequence string"""
    sc = QShortcut(QKeySequence(keystr), parent, action)
    sc.setContext(Qt.WidgetWithChildrenShortcut)
    return sc