def set_shortcut(self, shortcut: None | QtGui.QKeySequence | str): if shortcut is None: shortcut = "" if isinstance(shortcut, str): shortcut = gui.KeySequence( shortcut, gui.KeySequence.SequenceFormat.PortableText) self.setShortcut(shortcut)
def test_keysequenceedit(): seq = gui.KeySequence("Ctrl+A") edit = widgets.KeySequenceEdit(seq) edit.set_value("Ctrl+A") assert edit.get_value() == "Ctrl+A" assert edit.is_valid() repr(edit)
def get_key(self) -> gui.KeySequence: """Return the shortcut's key sequence. Returns: Key sequence """ return gui.KeySequence(self.key().toString(), gui.KeySequence.SequenceFormat.PortableText)
def _setup_actions(self): """Create the main window actions.""" # Show/hide callable objects self.toggle_callable_action = widgets.Action( text="Show callable attributes", parent=self, checkable=True, shortcut=gui.KeySequence("Alt+C"), statustip= "Shows/hides callable attributes (functions, methods, etc.)", ) self.toggle_callable_action.toggled.connect( self._proxy_tree_model.set_show_callables) # Show/hide special attributes self.toggle_special_attribute_action = widgets.Action( text="Show __special__ attributes", parent=self, checkable=True, shortcut=gui.KeySequence("Alt+S"), statustip="Shows or hides __special__ attributes", ) self.toggle_special_attribute_action.toggled.connect( self._proxy_tree_model.set_show_special_attrs) # Toggle auto-refresh on/off self.toggle_auto_refresh_action = widgets.Action( text="Auto-refresh", parent=self, checkable=True, statustip=f"Auto refresh every {self._refresh_rate} seconds", ) self.toggle_auto_refresh_action.toggled.connect( self.toggle_auto_refresh) # Add another refresh action with a different shortcut. An action must be added to # a visible widget for it to receive events. It is added to the main windows to # prevent it from being displayed again in the menu self.refresh_action_f5 = widgets.Action(self, text="&Refresh2", shortcut="F5") self.refresh_action_f5.triggered.connect(self._tree_model.refresh_tree) self.addAction(self.refresh_action_f5)
def test_keysequence(): assert ( gui.KeySequence.to_shortcut_str(0x41, QtCore.Qt.KeyboardModifier.ShiftModifier) == "Shift+A" ) seq = gui.KeySequence("Ctrl+C") assert seq.get_matches("Ctrl+C") == "exact" with open("data.pkl", "wb") as jar: pickle.dump(seq, jar) with open("data.pkl", "rb") as jar: seq = pickle.load(jar)
def get_shortcut(self) -> gui.KeySequence | None: shortcut = self.shortcut() if not shortcut: return None return gui.KeySequence(shortcut.toString(), gui.KeySequence.SequenceFormat.PortableText)
def __init__(self): super().__init__() self.setMinimumSize(400, 300) self.set_title("Icon Browser") from prettyqt import iconprovider iconprovider._instance() font_maps = iconprovider._instance().charmap icon_names = [ f"{font_collection}.{icon_name}" for font_collection, font_data in font_maps.items() for icon_name in font_data ] self._filter_timer = core.Timer(self) self._filter_timer.setSingleShot(True) self._filter_timer.setInterval(AUTO_SEARCH_TIMEOUT) self._filter_timer.timeout.connect(self._update_filter) model = IconModel(self.get_palette().get_color("text")) model.setStringList(sorted(icon_names)) self._proxy_model = core.SortFilterProxyModel() self._proxy_model.setSourceModel(model) self._proxy_model.set_filter_case_sensitive(True) self._listview = IconListView(self) self._listview.setUniformItemSizes(True) self._listview.set_view_mode("icon") self._listview.set_model(self._proxy_model) self._listview.set_contextmenu_policy("custom") self._listview.doubleClicked.connect(self._copy_icon_text) self._lineedit = widgets.LineEdit(parent=self) self._lineedit.textChanged.connect(self._filter_timer.restart) self._lineedit.returnPressed.connect(self._trigger_instant_update) self._combobox = widgets.ComboBox(parent=self) self._combobox.setMinimumWidth(75) self._combobox.currentIndexChanged.connect( self._trigger_instant_update) self._combobox.addItems([ALL_COLLECTIONS] + sorted(font_maps.keys())) lyt = widgets.BoxLayout("horizontal") lyt.set_margin(0) lyt.add(self._combobox) lyt.add(self._lineedit) search_bar_frame = widgets.Frame(self) search_bar_frame.setLayout(lyt) self._copy_button = widgets.PushButton("Copy Name", self) self._copy_button.clicked.connect(self._copy_icon_text) lyt = widgets.BoxLayout("vertical") lyt.add(search_bar_frame) lyt.add(self._listview) lyt.add(self._copy_button) frame = widgets.Frame(self) frame.set_layout(lyt) self.setCentralWidget(frame) widgets.Shortcut(gui.KeySequence("return"), self, self._copy_icon_text) self._lineedit.setFocus() self.center()
def get_shortcut(self) -> gui.KeySequence: return gui.KeySequence(self.shortcut().toString(), gui.KeySequence.SequenceFormat.PortableText)