def __init__(self, parent=None): QtWidgets.QTableWidget.__init__(self, parent) self.setColumnCount(6) self.setHorizontalHeaderLabels( ["Type", "File name", "Line", "Description", 'Details']) try: # pyqt4 self.horizontalHeader().setResizeMode( QtWidgets.QHeaderView.ResizeToContents) self.horizontalHeader().setResizeMode( COL_MSG, QtWidgets.QHeaderView.Stretch) except AttributeError: # pyqt5 self.horizontalHeader().setSectionResizeMode( QtWidgets.QHeaderView.ResizeToContents) self.horizontalHeader().setSectionResizeMode( COL_MSG, QtWidgets.QHeaderView.Stretch) self.setMinimumSize(900, 200) self.itemActivated.connect(self._on_item_activated) self.setSelectionMode(self.SingleSelection) self.setSelectionBehavior(self.SelectRows) self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self._show_context_menu) self.context_mnu = QtWidgets.QMenu() self.action_details = QtWidgets.QAction('View details', self) self.action_details.triggered.connect(self.showDetails) self.action_copy = QtWidgets.QAction('Copy error', self) self.action_copy.triggered.connect(self._copy_cell_text) self.context_mnu.addAction(self.action_details) self.context_mnu.addAction(self.action_copy) self.clear()
def on_state_changed(self, state): if state: self.editor.mouse_wheel_activated.connect(self._on_wheel_event) self.mnu_zoom = QtWidgets.QMenu("Zoom", self.editor) # Zoom in a = QtWidgets.QAction(QtGui.QIcon.fromTheme('zoom-in'), 'Zoom in', self.editor) a.setShortcutContext(QtCore.Qt.WidgetShortcut) self.mnu_zoom.addAction(a) a.setShortcut('Ctrl++') a.triggered.connect(self.editor.zoom_in) # Zoom out a = QtWidgets.QAction(QtGui.QIcon.fromTheme('zoom-out'), 'Zoom out', self.editor) a.setShortcutContext(QtCore.Qt.WidgetShortcut) self.mnu_zoom.addAction(a) a.setShortcut('Ctrl+-') a.triggered.connect(self.editor.zoom_out) # Reset zoom a = QtWidgets.QAction(QtGui.QIcon.fromTheme('zoom-fit-best'), 'Reset zoom', self.editor) a.setShortcutContext(QtCore.Qt.WidgetShortcut) self.mnu_zoom.addAction(a) a.setShortcut('Ctrl+0') a.triggered.connect(self.editor.reset_zoom) # Zoom menu a = self.mnu_zoom.menuAction() a.setIcon(QtGui.QIcon.fromTheme('zoom')) self.editor.add_action(a, sub_menu=None) else: self.editor.mouse_wheel_activated.disconnect(self._on_wheel_event) self.editor.remove_action(self.mnu_zoom.menuAction(), sub_menu=None)
def on_install(self, editor): """ Add the folding menu to the editor, on install. :param editor: editor instance on which the mode has been installed to. """ super(FoldingPanel, self).on_install(editor) self.context_menu = QtWidgets.QMenu('Folding', self.editor) action = self.action_collapse = QtWidgets.QAction( 'Collapse', self.context_menu) action.setShortcut('Shift+-') action.triggered.connect(self._on_action_toggle) self.context_menu.addAction(action) action = self.action_expand = QtWidgets.QAction('Expand', self.context_menu) action.setShortcut('Shift++') action.triggered.connect(self._on_action_toggle) self.context_menu.addAction(action) self.context_menu.addSeparator() action = self.action_collapse_all = QtWidgets.QAction( 'Collapse all', self.context_menu) action.setShortcut('Ctrl+Shift+-') action.triggered.connect(self._on_action_collapse_all_triggered) self.context_menu.addAction(action) action = self.action_expand_all = QtWidgets.QAction( 'Expand all', self.context_menu) action.setShortcut('Ctrl+Shift++') action.triggered.connect(self._on_action_expand_all_triggered) self.context_menu.addAction(action) self.editor.add_menu(self.context_menu)
def update_actions(self): """ Updates the list of actions. """ self.clear() self.recent_files_actions[:] = [] for file in self.manager.get_recent_files(): action = QtWidgets.QAction(self) action.setText(os.path.split(file)[1]) action.setToolTip(file) action.setStatusTip(file) action.setData(file) action.setIcon(self.icon_provider.icon(QtCore.QFileInfo(file))) action.triggered.connect(self._on_action_triggered) self.addAction(action) self.recent_files_actions.append(action) self.addSeparator() action_clear = QtWidgets.QAction('Clear list', self) action_clear.triggered.connect(self.clear_recent_files) if isinstance(self.clear_icon, QtGui.QIcon): action_clear.setIcon(self.clear_icon) elif self.clear_icon: theme = '' if len(self.clear_icon) == 2: theme, path = self.clear_icon else: path = self.clear_icon icons.icon(theme, path, 'fa.times-circle') self.addAction(action_clear)
def __init__(self): super(DirMenu, self).__init__() # Actions self.parentDirAction = QtWidgets.QAction('Parent Directory', self) self.addAction(self.parentDirAction) self.openDirAction = QtWidgets.QAction('Open &Directory...', self) self.addAction(self.openDirAction)
def _setup_windows_menu(self, ui): ui.actionZoom_height.triggered.connect(self.zoom_height) ui.menuTools.addActions(self.createPopupMenu().actions()) action_prev_window = QtWidgets.QAction(self) action_prev_window.setShortcut('Alt+Up') action_prev_window.triggered.connect(self._show_prev_window) self.addAction(action_prev_window) action_next_window = QtWidgets.QAction(self) action_next_window.setShortcut('Alt+Down') action_next_window.triggered.connect(self._show_next_window) self.addAction(action_next_window)
def get_new_user_actions(self): # New module self.action_new_module = QtWidgets.QAction('&Module', self) self.action_new_module.setIcon(QtGui.QIcon(icons.python_mimetype)) self.action_new_module.triggered.connect(self._on_new_module_triggered) # New package self.action_new_package = QtWidgets.QAction('&Package', self) self.action_new_package.setIcon(QtGui.QIcon(icons.folder)) self.action_new_package.triggered.connect( self._on_new_package_triggered) # separator with the regular entries action = QtWidgets.QAction(self) action.setSeparator(True) return [self.action_new_module, self.action_new_package, action]
def _create_actions(self): """ Create associated actions """ self.action_to_lower = QtWidgets.QAction(self.editor) self.action_to_lower.triggered.connect(self.to_lower) self.action_to_upper = QtWidgets.QAction(self.editor) self.action_to_upper.triggered.connect(self.to_upper) self.action_to_lower.setText('Convert to lower case') self.action_to_lower.setShortcut('Ctrl+U') self.action_to_upper.setText('Convert to UPPER CASE') self.action_to_upper.setShortcut('Ctrl+Shift+U') self.menu = QtWidgets.QMenu('Case', self.editor) self.menu.addAction(self.action_to_lower) self.menu.addAction(self.action_to_upper) self._actions_created = True
def __init__(self, parent=None, root=True, create_popup=True): super(SplittableTabWidget, self).__init__(parent) if root: self._action_popup = QtWidgets.QAction(self) self._action_popup.setShortcutContext(QtCore.Qt.WindowShortcut) self._shortcut = 'Ctrl+T' self._action_popup.setShortcut(self._shortcut) self._action_popup.triggered.connect(self._show_popup) self.addAction(self._action_popup) self.popup = OpenFilesPopup() self.popup.setWindowFlags( QtCore.Qt.Popup | QtCore.Qt.FramelessWindowHint) self.popup.triggered.connect(self._on_popup_triggered) self.child_splitters = [] self.main_tab_widget = self.tab_widget_klass(self) self.main_tab_widget.last_tab_closed.connect( self._on_last_tab_closed) self.main_tab_widget.split_requested.connect(self.split) self.addWidget(self.main_tab_widget) self._parent_splitter = None self._current = None self.root = root if root: QtWidgets.QApplication.instance().focusChanged.connect( self._on_focus_changed) self._uuid = uuid.uuid1() self._tabs = []
def __init__(self): super(QuickDocPanel, self).__init__(dynamic=True) # layouts layout = QtWidgets.QHBoxLayout() self.setLayout(layout) child_layout = QtWidgets.QVBoxLayout() # A QTextEdit to show the doc self.text_edit = QtWidgets.QTextEdit() self.text_edit.setReadOnly(True) self.text_edit.setAcceptRichText(True) layout.addWidget(self.text_edit) # A QPushButton (inside a child layout for a better alignment) # to close the panel self.bt_close = QtWidgets.QPushButton() self.bt_close.setIcon(icons.icon( 'window-close', ':/pyqode-icons/rc/close.png', 'fa.close')) self.bt_close.setIconSize(QtCore.QSize(16, 16)) self.bt_close.clicked.connect(self.hide) child_layout.addWidget(self.bt_close) child_layout.addStretch() layout.addLayout(child_layout) # Action self.action_quick_doc = QtWidgets.QAction( _('Show documentation'), self) self.action_quick_doc.setShortcut('Alt+Q') icon = icons.icon(qta_name='fa.book') if icon: self.action_quick_doc.setIcon(icon) self.action_quick_doc.triggered.connect( self._on_action_quick_doc_triggered)
def __init__(self, parent=None): super(DockBase, self).__init__(parent) self.viewAction = QtWidgets.QAction("", self) self.viewAction.triggered.connect(self.toggleView) self.viewAction.setCheckable(True) self.updateStatus()
def _create_tab_bar_menu(self): context_mnu = QtWidgets.QMenu() for action in self.context_actions: context_mnu.addAction(action) if self.context_actions: context_mnu.addSeparator() menu = QtWidgets.QMenu('Split', context_mnu) menu.setIcon(QtGui.QIcon.fromTheme('split')) a = menu.addAction('Split horizontally') a.triggered.connect(self._on_split_requested) a.setIcon(QtGui.QIcon.fromTheme('view-split-left-right')) a = menu.addAction('Split vertically') a.setIcon(QtGui.QIcon.fromTheme('view-split-top-bottom')) a.triggered.connect(self._on_split_requested) context_mnu.addMenu(menu) context_mnu.addSeparator() for name, slot in [('Close', self.close), ('Close others', self.close_others), ('Close all', self.close_all)]: qaction = QtWidgets.QAction(name, self) qaction.triggered.connect(slot) context_mnu.addAction(qaction) self.addAction(qaction) self._context_mnu = context_mnu return context_mnu
def show_context_menu(self, pt): """ Shows the recent files list context menu which allow to remove an item from the list or to clear the entire list. """ actionRemove = QtWidgets.QAction('Remove from recent files list', self) actionClear = QtWidgets.QAction('Clear recent files list', self) actionRemove.triggered.connect(self.remove_current_requested) actionClear.triggered.connect(self.clear_requested) actionClear.setIcon( QtGui.QIcon.fromTheme( 'edit-clear', QtGui.QIcon(':/ide-icons/rc/edit-clear.png'))) menu = QtWidgets.QMenu() menu.addAction(actionRemove) menu.addAction(actionClear) menu.exec_(self.mapToGlobal(pt))
def __init__(self): super(CommentsMode, self).__init__() self.action = QtWidgets.QAction("Comment/Uncomment", self.editor) self.action.setShortcut("Ctrl+/") icon = icons.icon(qta_name='fa.comment') if icon: self.action.setIcon(icon)
def __init__(self): super(GoToAssignmentsMode, self).__init__() self._definitions = [] self._goto_requested = False self.action_goto = QtWidgets.QAction("Go to assignments", self) self.action_goto.setShortcut(self.shortcut) self.action_goto.triggered.connect(self.request_goto) self.word_clicked.connect(self._on_word_clicked) self._runner = DelayJobRunner(delay=1)
def __init__(self): super(FileBrowserMenu, self).__init__() self.OpenAction = QtWidgets.QAction('&Open', self) self.OpenAction.setShortcut('Ctrl+Shift+O') # self.execAction.setIcon(_icon( # 'edit-cut', ':/pyqode-icons/rc/edit-cut.png')) self.addAction(self.OpenAction) self.addSeparator() # actions self.execAction = QtWidgets.QAction('&Execute', self) self.execAction.setShortcut('Shift+Ctrl+Alt+X') # self.execAction.setIcon(_icon( # 'edit-cut', ':/pyqode-icons/rc/edit-cut.png')) self.addAction(self.execAction) self.execAction.triggered.connect(self.execFile)
def setup_mnu_panels(self, editor): for panel in editor.panels: a = QtWidgets.QAction(self.menuModes) a.setText(panel.name) a.setCheckable(True) a.setChecked(True) a.changed.connect(self.on_panel_state_changed) a.panel = weakref.proxy(panel) self.menuPanels.addAction(a)
def setup_mnu_modes(self, editor): for mode in editor.modes: a = QtWidgets.QAction(self.menuModes) a.setText(mode.name) a.setCheckable(True) a.setChecked(True) a.changed.connect(self.on_mode_state_changed) a.mode = weakref.proxy(mode) self.menuModes.addAction(a)
def __init__(self, window): super(PyFileSystemContextMenu, self).__init__() self.window = window # Create run config action self.action_create_run_cfg = QtWidgets.QAction( '&Create run configuration', self) self.action_create_run_cfg.setIcon(QtGui.QIcon(icons.configure)) self.action_create_run_cfg.triggered.connect( self._on_action_create_run_cfg_triggered) # Run script action self.action_run = QtWidgets.QAction('&Run', self) self.action_run.setIcon(QtGui.QIcon(icons.run)) self.action_run.triggered.connect(self._on_action_run_triggered) self.addSeparator() self.addAction(self.action_create_run_cfg) self.addAction(self.action_run)
def __init__(self, parent=None): super(InterpreterConfigDialog, self).__init__(parent) self.setupUi(self) self.autoRB.toggled.connect(self.onAutoToggled) self.locRB.toggled.connect(self.onLocToggled) self.locBtnAction = QtWidgets.QAction("...", self) self.locBtn.setDefaultAction(self.locBtnAction) self.locBtn.triggered.connect(self.onLocBtn) self._loadSettings() self._updateWidgets()
def add_separator(self): """ Adds a sepqrator to the editor's context menu. :return: The sepator that has been added. :rtype: QtWidgets.QAction """ action = QtWidgets.QAction(self) action.setSeparator(True) self._actions.append(action) self.addAction(action) return action
def __init__(self): super(GoToAssignmentsMode, self).__init__() self._definitions = [] self._goto_requested = False self.action_goto = QtWidgets.QAction(_("Go to assignments"), self) self.action_goto.setShortcut(self.shortcut) self.action_goto.triggered.connect(self.request_goto) icon = icons.icon(qta_name='fa.share') if icon: self.action_goto.setIcon(icon) self.word_clicked.connect(self._on_word_clicked) self._runner = DelayJobRunner(delay=1)
def test_actions(editor): assert len(editor.actions()) nb_actions_expected = len(editor.actions()) action = QtWidgets.QAction('my_action', editor) editor.add_action(action, sub_menu=None) nb_actions_expected += 1 assert len(editor.actions()) == nb_actions_expected editor.add_separator(sub_menu=None) nb_actions_expected += 1 assert len(editor.actions()) == nb_actions_expected editor.add_separator(sub_menu='Advanced') nb_actions_expected += 1 assert len(editor.actions()) != nb_actions_expected
def __init__(self): super(ExtendedSelectionMode, self).__init__() self.extended_sel_modifier = QtCore.Qt.ControlModifier self.matched_sel_modifier = QtCore.Qt.AltModifier self.continuation_characters = ('.',) self.word_sel_shortcut = QtGui.QKeySequence('Ctrl+W') self.action_select_word = QtWidgets.QAction(self.editor) self.action_select_word.setText('Select word') self.action_select_word.setShortcut(self.word_sel_shortcut) self.action_select_word.triggered.connect(self.perform_word_selection) self.action_select_word.setShortcutContext( QtCore.Qt.WidgetShortcut) self.extended_sel_shortcut = QtGui.QKeySequence('Ctrl+Shift+W') self.action_select_extended_word = QtWidgets.QAction(self.editor) self.action_select_extended_word.setText('Select extended word') self.action_select_extended_word.setShortcut( self.extended_sel_shortcut) self.action_select_extended_word.triggered.connect( self.perform_extended_selection) self.action_select_extended_word.setShortcutContext( QtCore.Qt.WidgetShortcut) self.matched_sel_shortcut = QtGui.QKeySequence('Ctrl+E') self.action_select_matched = QtWidgets.QAction(self.editor) self.action_select_matched.setText('Matched select') self.action_select_matched.setShortcut(self.matched_sel_shortcut) self.action_select_matched.triggered.connect( self.perform_matched_selection) self.action_select_matched.setShortcutContext( QtCore.Qt.WidgetShortcut) self.line_sel_shortcut = QtGui.QKeySequence('Ctrl+Shift+L') self.action_select_line = QtWidgets.QAction(self.editor) self.action_select_line.setText('Select line') self.action_select_line.setShortcut(self.line_sel_shortcut) self.action_select_line.triggered.connect(self.perform_line_selection) self.action_select_line.setShortcutContext( QtCore.Qt.WidgetShortcut)
def _refresh(self): self._clear_actions() for i, encoding in enumerate(sorted(Cache().preferred_encodings)): encoding = convert_to_codec_key(encoding) try: alias, lang = ENCODINGS_MAP[encoding] except KeyError: _logger().debug('KeyError with encoding:', encoding) else: action = QtWidgets.QAction('%s (%s)' % (alias, lang), self) action.setData(encoding) action.setCheckable(True) if encoding == self._current_encoding or \ convert_to_codec_key(alias) == self._current_encoding: action.setChecked(True) self.addAction(action) self._group.addAction(action) self._group.triggered.connect(self._on_encoding_triggered) self.addSeparator() self._edit_action = QtWidgets.QAction('Add or remove', self) self._edit_action.triggered.connect(self._on_edit_requested) self.addAction(self._edit_action)
def __init__(self): super(Window, self).__init__() self.setMinimumWidth(800) self.setMinimumHeight(600) self.editor = JSONCodeEdit(self) self.setCentralWidget(self.editor) self.editor.file.open( os.path.abspath(os.path.join( '..', 'test', 'files', 'example.json'))) self.action_open = QtWidgets.QAction('open file', self) self.action_open.setShortcut('Ctrl+O') self.action_open.triggered.connect(self.open_file) self.addAction(self.action_open)
def __init__(self, title='Encodings', parent=None, selected_encoding=locale.getpreferredencoding()): from pyqode.core.api import CodeEdit assert isinstance(parent, CodeEdit) super(EncodingsContextMenu, self).__init__( title, parent, selected_encoding) self.reload_requested.connect(self._on_reload_requested) parent.new_text_set.connect(self._refresh) sep = QtWidgets.QAction(self.parent()) sep.setSeparator(True) self.parent().add_menu(self) self._timer = QtCore.QTimer() self._timer.setInterval(1) self._timer.timeout.connect(self._reload) self._refresh()
def update_actions(self): """ Updates the list of actions. """ self.clear() self.recent_files_actions[:] = [] for file in self.manager.get_recent_files(): action = QtWidgets.QAction(self) action.setText(os.path.split(file)[1]) action.setToolTip(file) action.setStatusTip(file) action.setData(file) action.setIcon(self.icon_provider.icon(QtCore.QFileInfo(file))) action.triggered.connect(self._on_action_triggered) self.addAction(action) self.recent_files_actions.append(action) self.addSeparator() action_clear = QtWidgets.QAction('Clear list', self) action_clear.triggered.connect(self.clear_recent_files) if self.clear_icon and len(self.clear_icon) == 2: action_clear.setIcon( QtGui.QIcon.fromTheme(self.clear_icon[0], QtGui.QIcon(self.clear_icon[1]))) self.addAction(action_clear)
def setup_mnu_panels(self, editor): """ Setup the panels menu for the current editor. :param editor: """ for panel in editor.panels: if panel.dynamic: continue a = QtWidgets.QAction(self.menuModes) a.setText(panel.name) a.setCheckable(True) a.setChecked(panel.enabled) a.changed.connect(self.on_panel_state_changed) a.panel = weakref.proxy(panel) self.menuPanels.addAction(a)
def update_windows_menu(self, open_windows): _logger(self).debug('update windows menu: %r' % open_windows) self._open_windows = open_windows self.ui.menuWindows.clear() self.ui.menuWindows.addAction(self.ui.actionZoom_height) self.ui.menuWindows.addSeparator() self.ui.menuWindows.addMenu(self.ui.menuTools) self.ui.menuWindows.addSeparator() for win in open_windows: action = QtWidgets.QAction(self) if win == self: action.setDisabled(True) action.setText(win.windowTitle()) action.setData(win) action.triggered.connect(self._show_window_from_action) self.ui.menuWindows.addAction(action)