def _load_ebook_worker(self, pathtoebook, open_at, reload_book): try: ans = prepare_book(pathtoebook, force=reload_book, prepare_notify=self.prepare_notify) except WorkerError as e: if not sip.isdeleted(self): self.book_prepared.emit(False, { 'exception': e, 'tb': e.orig_tb, 'pathtoebook': pathtoebook }) except Exception as e: import traceback if not sip.isdeleted(self): self.book_prepared.emit( False, { 'exception': e, 'tb': traceback.format_exc(), 'pathtoebook': pathtoebook }) else: performance_monitor('prepared emitted') if not sip.isdeleted(self): self.book_prepared.emit( True, { 'base': ans, 'pathtoebook': pathtoebook, 'open_at': open_at, 'reloaded': reload_book })
def get_themes(self): self.usage = {} def get_usage(): try: self.usage = json.loads( bz2.decompress( get_https_resource_securely(BASE_URL + '/usage.json.bz2'))) except Exception: import traceback traceback.print_exc() t = Thread(name='IconThemeUsage', target=get_usage) t.daemon = True t.start() try: self.themes = json.loads( bz2.decompress( get_https_resource_securely(BASE_URL + '/themes.json.bz2'))) except Exception: import traceback self.themes = traceback.format_exc() t.join() if not sip.isdeleted(self): self.themes_downloaded.emit()
def about_to_show(self): if sip.isdeleted(self.clone): return cm = self.clone.menu() if cm is None: return before = list(QMenu.actions(cm)) cm.aboutToShow.emit() after = list(QMenu.actions(cm)) if before != after: self.clone_menu()
def set_editor_data(self, name, editor): if sip.isdeleted(editor): return editor.setText(name) ext_pos = name.rfind('.') slash_pos = name.rfind('/') if slash_pos == -1 and ext_pos > 0: editor.setSelection(0, ext_pos) elif ext_pos > -1 and slash_pos > -1 and ext_pos > slash_pos + 1: editor.setSelection(slash_pos+1, ext_pos - slash_pos - 1) else: editor.selectAll()
def render(self): self.current_tdir = os.path.join(self.tdir, str(self.first)) self.error = None try: os.mkdir(self.current_tdir) page_images(self.pdfpath, self.current_tdir, first=self.first, last=self.first + PAGES_PER_RENDER - 1) except Exception as e: if self.covers.count(): pass else: self.error = as_unicode(e) if not sip.isdeleted(self) and self.isVisible(): self.rendering_done.emit()
def send_reply(rq, mime_type, data): if sip.isdeleted(rq): return # make the buf a child of rq so that it is automatically deleted when # rq is deleted buf = QBuffer(parent=rq) buf.open(QIODevice.OpenModeFlag.WriteOnly) # we have to copy data into buf as it will be garbage # collected by python buf.write(data) buf.seek(0) buf.close() rq.reply(mime_type.encode('ascii'), buf)
def finalize(shortcuts, custom_keys_map={}): # {{{ ''' Resolve conflicts and assign keys to every action in shortcuts, which must be a OrderedDict. User specified mappings of unique names to keys (as a list of strings) should be passed in in custom_keys_map. Return a mapping of unique names to resolved keys. Also sets the set_to_default member correctly for each shortcut. ''' seen, keys_map = {}, {} for unique_name, shortcut in iteritems(shortcuts): custom_keys = custom_keys_map.get(unique_name, None) if custom_keys is None: candidates = shortcut['default_keys'] shortcut['set_to_default'] = True else: candidates = custom_keys shortcut['set_to_default'] = False keys = [] for x in candidates: ks = QKeySequence(x, QKeySequence.SequenceFormat.PortableText) x = unicode_type( ks.toString(QKeySequence.SequenceFormat.PortableText)) if x in seen: if DEBUG: prints('Key %r for shortcut %s is already used by' ' %s, ignoring' % (x, shortcut['name'], seen[x]['name'])) keys_map[unique_name] = () continue seen[x] = shortcut keys.append(ks) keys = tuple(keys) keys_map[unique_name] = keys ac = shortcut['action'] if ac is None or sip.isdeleted(ac): if ac is not None and DEBUG: prints('Shortcut %r has a deleted action' % unique_name) continue ac.setShortcuts(list(keys)) return keys_map
def printing_done(self, pdf_data): self.working = False if not sip.isdeleted(self): self.work_done.emit(self, bytes(pdf_data))
def safe_delete(x): if not sip.isdeleted(x): sip.delete(x)
def callback(metadata, x): if not sip.isdeleted(dialog) and not dialog.dialog_closed: dialog.cover_downloaded.emit(metadata, x)
def eventFilter(self, obj, e): 'Redirect key presses from the popup to the widget' widget = self.parent() if widget is None or sip.isdeleted(widget): return False etype = e.type() if obj is not self: return QObject.eventFilter(self, obj, e) # self.debug_event(e) if etype == QEvent.Type.KeyPress: try: key = e.key() except AttributeError: return QObject.eventFilter(self, obj, e) if key == Qt.Key.Key_Escape: self.hide() e.accept() return True if key == Qt.Key.Key_F4 and e.modifiers( ) & Qt.KeyboardModifier.AltModifier: self.hide() e.accept() return True if key in (Qt.Key.Key_Enter, Qt.Key.Key_Return): # We handle this explicitly because on OS X activated() is # not emitted on pressing Enter. idx = self.currentIndex() if idx.isValid(): self.item_chosen(idx) self.hide() e.accept() return True if key == Qt.Key.Key_Tab: idx = self.currentIndex() if idx.isValid(): self.item_chosen(idx) self.hide() elif self.model().rowCount() > 0: self.next_match() e.accept() return True if key in (Qt.Key.Key_PageUp, Qt.Key.Key_PageDown): # Let the list view handle these keys return False if key in (Qt.Key.Key_Up, Qt.Key.Key_Down): self.next_match(previous=key == Qt.Key.Key_Up) e.accept() return True # Send to widget widget.eat_focus_out = False widget.keyPressEvent(e) widget.eat_focus_out = True if not widget.hasFocus(): # Widget lost focus hide the popup self.hide() if e.isAccepted(): return True elif ismacos and etype == QEvent.Type.InputMethodQuery and e.queries( ) == (Qt.InputMethodQuery.ImHints | Qt.InputMethodQuery.ImEnabled) and self.isVisible(): # In Qt 5 the Esc key causes this event and the line edit does not # handle it, which causes the parent dialog to be closed # See https://bugreports.qt-project.org/browse/QTBUG-41806 e.accept() return True elif etype == QEvent.Type.MouseButtonPress and hasattr( e, 'globalPos') and not self.rect().contains( self.mapFromGlobal(e.globalPos())): # A click outside the popup, close it if isinstance(widget, QComboBox): # This workaround is needed to ensure clicking on the drop down # arrow of the combobox closes the popup opt = QStyleOptionComboBox() widget.initStyleOption(opt) sc = widget.style().hitTestComplexControl( QStyle.ComplexControl.CC_ComboBox, opt, widget.mapFromGlobal(e.globalPos()), widget) if sc == QStyle.SubControl.SC_ComboBoxArrow: QTimer.singleShot(0, self.hide) e.accept() return True self.hide() e.accept() return True elif etype in (QEvent.Type.InputMethod, QEvent.Type.ShortcutOverride): QApplication.sendEvent(widget, e) return False
def host_widget(self): ans = self._host_widget if ans is not None and not sip.isdeleted(ans): return ans
def rewrap_button(w): if not sip.isdeleted(w) and w.defaultAction() is not None: w.setText(wrap_button_text(w.defaultAction().text()))
def do_trigger(self, checked=False): if not sip.isdeleted(self.clone): self.clone.trigger()