def __init__(self, book_ids, db, opts, root, parent=None, pool=None): QObject.__init__(self, parent) self.db = db.new_api self.plugboards = self.db.pref('plugboards', {}) self.template_functions = self.db.pref('user_template_functions', []) load_user_template_functions('', self.template_functions) self.collected_data = {} self.errors = defaultdict(list) self._book_id_data = {} self.all_book_ids = frozenset(book_ids) self.pd = ProgressDialog(_('Saving %d books...') % len(self.all_book_ids), _('Collecting metadata...'), min=0, max=0, parent=parent, icon='save.png') self.do_one_signal.connect(self.tick, type=Qt.ConnectionType.QueuedConnection) self.do_one = self.do_one_collect self.ids_to_collect = iter(self.all_book_ids) self.tdir = PersistentTemporaryDirectory('_save_to_disk') self.pool = pool self.pd.show() self.root, self.opts, self.path_length = sanitize_args(root, opts) self.do_one_signal.emit() if DEBUG: self.start_time = time.time()
def __init__(self, gui, ids, callback): from calibre.gui2.dialogs.progress import ProgressDialog QObject.__init__(self, gui) self.model = gui.library_view.model() self.ids = ids self.permanent = False if can_recycle and len(ids) > 100: if question_dialog(gui, _('Are you sure?'), '<p>'+ _('You are trying to delete %d books. ' 'Sending so many files to the Recycle' ' Bin <b>can be slow</b>. Should calibre skip the' ' recycle bin? If you click Yes the files' ' will be <b>permanently deleted</b>.')%len(ids), add_abort_button=True ): self.permanent = True self.gui = gui self.failures = [] self.deleted_ids = [] self.callback = callback single_shot(self.delete_one) self.pd = ProgressDialog(_('Deleting...'), parent=gui, cancelable=False, min=0, max=len(self.ids), icon='trash.png') self.pd.setModal(True) self.pd.show()
def __init__(self, parent=None, config_name='shortcuts/main'): QObject.__init__(self, parent) self.config = JSONConfig(config_name) self.shortcuts = OrderedDict() self.keys_map = {} self.groups = {}
def __init__(self, page): QObject.__init__(self, page) self._signals = json.dumps(tuple({k for k, v in iteritems(self.__class__.__dict__) if isinstance(v, pyqtSignal)})) self._signals_registered = False page.titleChanged.connect(self._title_changed) for k, v in iteritems(self.__class__.__dict__): if isinstance(v, to_js): v.name = k
def __init__(self, config, seralize_books_function, timeout): Thread.__init__(self) QObject.__init__(self) self.daemon = True self.config = config self.seralize_books = seralize_books_function self.timeout = timeout self._run = True
def __init__(self, opts, args, actions, app, gui_debug=None): self.startup_time = monotonic() self.timed_print('Starting up...') self.opts, self.args, self.app = opts, args, app self.gui_debug = gui_debug self.actions = actions self.main = None QObject.__init__(self) self.splash_screen = None self.timer = QTimer.singleShot(1, self.initialize)
def __init__(self, parent, debug=False): QObject.__init__(self, parent) self.debug = debug self.timer = QTimer(self) self.timer.timeout.connect(self.check) self.threshold = gc.get_threshold() gc.disable() self.timer.start(self.INTERVAL)
def __init__(self, parent=None): QObject.__init__(self, parent) self.free = [-1, -1, -1] self.count = 0 self.location_actions = QActionGroup(self) self.location_actions.setExclusive(True) self.current_location = 'library' self._mem = [] self.tooltips = {} self.all_actions = [] def ac(name, text, icon, tooltip): icon = QIcon(I(icon)) ac = self.location_actions.addAction(icon, text) setattr(self, 'location_' + name, ac) ac.setAutoRepeat(False) ac.setCheckable(True) receiver = partial(self._location_selected, name) ac.triggered.connect(receiver) self.tooltips[name] = tooltip m = QMenu(parent) self._mem.append(m) a = m.addAction(icon, tooltip) a.triggered.connect(receiver) if name != 'library': self._mem.append(a) a = m.addAction(QIcon(I('eject.png')), _('Eject this device')) a.triggered.connect(self._eject_requested) self._mem.append(a) a = m.addAction(QIcon(I('config.png')), _('Configure this device')) a.triggered.connect(self._configure_requested) self._mem.append(a) a = m.addAction(QIcon(I('sync.png')), _('Update cached metadata on device')) a.triggered.connect( lambda x: self.update_device_metadata.emit()) self._mem.append(a) else: ac.setToolTip(tooltip) ac.setMenu(m) ac.calibre_name = name self.all_actions.append(ac) return ac self.library_action = ac('library', _('Library'), 'lt.png', _('Show books in calibre library')) ac('main', _('Device'), 'reader.png', _('Show books in the main memory of the device')) ac('carda', _('Card A'), 'sd.png', _('Show books in storage card A')) ac('cardb', _('Card B'), 'sd.png', _('Show books in storage card B'))
def __init__(self, location_manager, parent): QObject.__init__(self, parent) self.gui = parent self.location_manager = location_manager self.added_actions = [] self.last_actions = [] self.donate_action = QAction(_('Donate'), self) self.donate_menu = QMenu() self.donate_menu.addAction(self.gui.donate_action) self.donate_action.setMenu(self.donate_menu) self.refresh_timer = t = QTimer(self) t.setInterval(200), t.setSingleShot(True), t.timeout.connect(self.refresh_bar)
def __init__(self, location_manager, parent): QObject.__init__(self, parent) self.menu_bar = QMenuBar(parent) self.menu_bar.is_native_menubar = False parent.setMenuBar(self.menu_bar) self.gui = parent self.location_manager = location_manager self.added_actions = [] self.donate_action = QAction(_('Donate'), self) self.donate_menu = QMenu() self.donate_menu.addAction(self.gui.donate_action) self.donate_action.setMenu(self.donate_menu)
def __init__(self, location_manager, parent): QObject.__init__(self, parent) f = factory(app_id='com.calibre-ebook.gui') self.menu_bar = f.create_window_menubar(parent) self.is_native_menubar = self.menu_bar.is_native_menubar self.gui = parent self.location_manager = location_manager self.added_actions = [] self.donate_action = QAction(_('Donate'), self) self.donate_menu = QMenu() self.donate_menu.addAction(self.gui.donate_action) self.donate_action.setMenu(self.donate_menu)
def __init__(self, path, parent): QObject.__init__(self, parent) if path and os.path.isdir(path) and os.access(path, os.R_OK|os.W_OK): self.watcher = QFileSystemWatcher(self) self.worker = Worker(path, self.metadata_read.emit) self.watcher.directoryChanged.connect(self.dir_changed, type=Qt.ConnectionType.QueuedConnection) self.metadata_read.connect(self.add_to_db, type=Qt.ConnectionType.QueuedConnection) QTimer.singleShot(2000, self.initialize) self.auto_convert.connect(self.do_auto_convert, type=Qt.ConnectionType.QueuedConnection) elif path: prints(path, 'is not a valid directory to watch for new ebooks, ignoring')
def __init__(self, **kw): global _sni_count QObject.__init__(self, parent=kw.get('parent')) self.context_menu = None self.is_visible = True self.tool_tip = '' path = I('calibre-tray.png') if path and os.path.exists(path): self._icon = QIcon(path) else: self._icon = QApplication.instance().windowIcon() self.show_menu.connect(self._show_menu, type=Qt.ConnectionType.QueuedConnection) _sni_count += 1 kw['num'] = _sni_count self.dbus_api = StatusNotifierItemAPI(self, **kw)
def __init__(self, object_path, parent=None, bus=None): QObject.__init__(self, parent) # Unity barfs is the Event DBUS method does not return immediately, so # handle it asynchronously self.handle_event_signal.connect( self.handle_event, type=Qt.ConnectionType.QueuedConnection) self.dbus_api = DBusMenuAPI(self, object_path, bus=bus) self.set_status = self.dbus_api.set_status self._next_id = 0 self.action_changed_timer = t = QTimer(self) t.setInterval(0), t.setSingleShot(True), t.timeout.connect( self.actions_changed) self.layout_changed_timer = t = QTimer(self) t.setInterval(0), t.setSingleShot(True), t.timeout.connect( self.layouts_changed) self.init_maps()
def __init__(self, parent, notify=None): QObject.__init__(self, parent) self.count = 0 self.last_saved = -1 self.requests = LifoQueue() self.notify_requests = LifoQueue() self.notify_data = notify t = Thread(name='save-thread', target=self.run) t.daemon = True t.start() t = Thread(name='notify-thread', target=self.notify_calibre) t.daemon = True t.start() self.status_widget = w = SaveWidget(parent) self.start_save.connect(w.start, type=Qt.ConnectionType.QueuedConnection) self.save_done.connect(w.stop, type=Qt.ConnectionType.QueuedConnection)
def __init__(self, donate_action, location_manager, parent): QObject.__init__(self, parent) self.location_manager = location_manager bars = [ToolBar(donate_action, location_manager, parent) for i in range(3)] self.main_bars = tuple(bars[:2]) self.child_bars = tuple(bars[2:]) self.reveal_bar = RevealBar(parent) self.menu_bar = MenuBar(self.location_manager, self.parent()) is_native_menubar = self.menu_bar.is_native_menubar self.adapt_menu_bar_for_dialog = AdaptMenuBarForDialog(self.menu_bar) self.menubar_fallback = native_menubar_defaults['action-layout-menubar'] if is_native_menubar else () self.menubar_device_fallback = native_menubar_defaults['action-layout-menubar-device'] if is_native_menubar else () self.apply_settings() self.init_bars()
def __init__(self, app_id=None): QObject.__init__(self) self.app_id = app_id or QApplication.instance().applicationName( ) or 'unknown_application' if iswindows or ismacos: self.dbus = None else: try: import dbus self.dbus = dbus except ImportError as err: log('Failed to import dbus, with error:', unicode_type(err)) self.dbus = None self.menu_registrar = None self.status_notifier = None self._bus = None self.status_notifiers, self.window_menus = [], []
def __init__(self, parent, db): QObject.__init__(self, parent) self.internet_connection_failed = False self._parent = parent self.no_internet_msg = _( 'Cannot download news as no internet connection ' 'is active') self.no_internet_dialog = d = error_dialog(self._parent, self.no_internet_msg, _('No internet connection'), show_copy_button=False) d.setModal(False) self.recipe_model = RecipeModel() self.db = db self.lock = QMutex(QMutex.RecursionMode.Recursive) self.download_queue = set() self.news_menu = QMenu() self.news_icon = QIcon(I('news.png')) self.scheduler_action = QAction(QIcon(I('scheduler.png')), _('Schedule news download'), self) self.news_menu.addAction(self.scheduler_action) self.scheduler_action.triggered[bool].connect(self.show_dialog) self.cac = QAction(QIcon(I('user_profile.png')), _('Add or edit a custom news source'), self) self.cac.triggered[bool].connect(self.customize_feeds) self.news_menu.addAction(self.cac) self.news_menu.addSeparator() self.all_action = self.news_menu.addAction( QIcon.ic('download-metadata.png'), _('Download all scheduled news sources'), self.download_all_scheduled) self.timer = QTimer(self) self.timer.start(int(self.INTERVAL * 60 * 1000)) self.timer.timeout.connect(self.check) self.oldest = gconf['oldest_news'] QTimer.singleShot(5 * 1000, self.oldest_check)
def __init__(self, opts, log, container_root): QObject.__init__(self) self.interceptor = RequestInterceptor(self) self.has_maths = {} self.interceptor.log = self.log = log self.interceptor.container_root = os.path.normcase(os.path.abspath(container_root)) self.interceptor.resources_root = os.path.normcase(os.path.abspath(os.path.dirname(mathjax_dir()))) ans = QWebEngineProfile(QApplication.instance()) ua = 'calibre-pdf-output ' + __version__ ans.setHttpUserAgent(ua) s = ans.settings() s.setDefaultTextEncoding('utf-8') ans.setUrlRequestInterceptor(self.interceptor) self.profile = ans self.opts = opts self.workers = [] self.max_workers = detect_ncpus() if iswindows: self.original_signal_handlers = {} else: self.original_signal_handlers = setup_unix_signals(self)
def __init__(self, view): QObject.__init__(self, view) if touch_supported: view.viewport().setAttribute( Qt.WidgetAttribute.WA_AcceptTouchEvents) self.state = State() self.state.tapped.connect( self.handle_tap, type=Qt.ConnectionType.QueuedConnection ) # has to be queued otherwise QApplication.keyboardModifiers() does not work self.state.flicking.connect(self.handle_flicking) connect_lambda(self.state.tap_hold_started, self, lambda self, tp: self.handle_tap_hold('start', tp)) connect_lambda(self.state.tap_hold_updated, self, lambda self, tp: self.handle_tap_hold('update', tp)) connect_lambda(self.state.tap_hold_finished, self, lambda self, tp: self.handle_tap_hold('end', tp)) self.evmap = { QEvent.Type.TouchBegin: 'start', QEvent.Type.TouchUpdate: 'update', QEvent.Type.TouchEnd: 'end' } self.last_tap_at = 0 if touch_supported: self.scroller = QScroller.scroller(view.viewport())
def __init__(self, parent): QObject.__init__(self, parent) self.running = False
def __init__(self, bridge, name): QObject.__init__(self, bridge) self.name = name
def __init__(self, parent=None): QObject.__init__(self, parent) self._tts_client = None self.dispatch_on_main_thread_signal.connect( self.dispatch_on_main_thread)
def __init__(self, parent, site_customization): QObject.__init__(self, parent) self.setObjectName(self.name) self.gui = parent self.site_customization = site_customization self.interface_action_base_plugin = None
def __init__(self, source, single_book_per_directory=True, db=None, parent=None, callback=None, pool=None, list_of_archives=False): if isinstance(source, str): source = make_long_path_useable(source) else: source = list(map(make_long_path_useable, source)) if not validate_source(source, parent): return QObject.__init__(self, parent) self.author_map_rules = None if gprefs.get('author_map_on_add_rules'): from calibre.ebooks.metadata.author_mapper import compile_rules as acr self.author_map_rules = acr(gprefs['author_map_on_add_rules']) self.single_book_per_directory = single_book_per_directory self.ignore_opf = False self.list_of_archives = list_of_archives self.callback = callback self.add_formats_to_existing = prefs['add_formats_to_existing'] self.do_one_signal.connect(self.tick, type=Qt.ConnectionType.QueuedConnection) self.pool = pool self.pd = ProgressDialog(_('Adding books...'), _('Scanning for files...'), min=0, max=0, parent=parent, icon='add_book.png') self.win_id = None if parent is not None and hasattr(parent, 'effectiveWinId'): self.win_id = parent.effectiveWinId() if self.win_id is not None: self.win_id = int(self.win_id) self.db = getattr(db, 'new_api', None) if self.db is not None: self.dbref = weakref.ref(db) self.source = source self.tdir = PersistentTemporaryDirectory('_add_books') self.scan_error = None self.file_groups = OrderedDict() self.abort_scan = False self.duplicates = [] self.report = [] self.items = [] self.added_book_ids = set() self.merged_formats_added_to = set() self.merged_books = set() self.added_duplicate_info = set() self.pd.show() self.scan_thread = Thread(target=self.scan, name='ScanBooks') self.scan_thread.daemon = True self.scan_thread.start() self.do_one = self.monitor_scan self.do_one_signal.emit() if DEBUG: self.start_time = time.time()
def __init__( self, title=_('Choose Files'), filters=[], add_all_files_filter=True, parent=None, modal=True, name='', mode=QFileDialog.FileMode.ExistingFiles, default_dir=u'~', no_save_dir=False, combine_file_and_saved_dir=False ): from calibre.gui2 import dynamic, sanitize_env_vars from calibre.gui2.ui import get_gui gui = get_gui() adapt_menubar = gui.bars_manager.adapt_menu_bar_for_dialog if gui is not None else Dummy() QObject.__init__(self) ftext = '' has_long_filter = False if filters: for filter in filters: text, extensions = filter extensions = ['*'+(i if i.startswith('.') else '.'+i) for i in extensions] etext = '%s (%s);;'%(text, ' '.join(extensions)) if len(etext) > 72: has_long_filter = True ftext += etext if add_all_files_filter or not ftext: ftext += 'All files (*)' if ftext.endswith(';;'): ftext = ftext[:-2] self.dialog_name = dialog_name(name, title) self.selected_files = None self.fd = None if combine_file_and_saved_dir: bn = os.path.basename(default_dir) prev = dynamic.get(self.dialog_name, os.path.expanduser(u'~')) if os.path.exists(prev): if os.path.isfile(prev): prev = os.path.dirname(prev) else: prev = os.path.expanduser(u'~') initial_dir = os.path.join(prev, bn) elif no_save_dir: initial_dir = os.path.expanduser(default_dir) else: initial_dir = dynamic.get(self.dialog_name, os.path.expanduser(default_dir)) if not isinstance(initial_dir, string_or_bytes): initial_dir = os.path.expanduser(default_dir) if not initial_dir or (not os.path.exists(initial_dir) and not ( mode == QFileDialog.FileMode.AnyFile and (no_save_dir or combine_file_and_saved_dir))): initial_dir = select_initial_dir(initial_dir) self.selected_files = [] use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ with sanitize_env_vars(): opts = QFileDialog.Option() if not use_native_dialog: opts |= QFileDialog.Option.DontUseNativeDialog if has_long_filter: opts |= QFileDialog.Option.HideNameFilterDetails if mode == QFileDialog.FileMode.AnyFile: with adapt_menubar: f = QFileDialog.getSaveFileName(parent, title, initial_dir, ftext, "", opts) if f and f[0]: self.selected_files.append(f[0]) elif mode == QFileDialog.FileMode.ExistingFile: with adapt_menubar: f = QFileDialog.getOpenFileName(parent, title, initial_dir, ftext, "", opts) if f and f[0] and os.path.exists(f[0]): self.selected_files.append(f[0]) elif mode == QFileDialog.FileMode.ExistingFiles: with adapt_menubar: fs = QFileDialog.getOpenFileNames(parent, title, initial_dir, ftext, "", opts) if fs and fs[0]: for f in fs[0]: f = unicode_type(f) if not f: continue if not os.path.exists(f): # QFileDialog for some reason quotes spaces # on linux if there is more than one space in a row f = unquote(f) if f and os.path.exists(f): self.selected_files.append(f) else: if mode == QFileDialog.FileMode.Directory: opts |= QFileDialog.Option.ShowDirsOnly with adapt_menubar: f = unicode_type(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts)) if os.path.exists(f): self.selected_files.append(f) if self.selected_files: self.selected_files = [unicode_type(q) for q in self.selected_files] saved_loc = self.selected_files[0] if os.path.isfile(saved_loc): saved_loc = os.path.dirname(saved_loc) if not no_save_dir: dynamic[self.dialog_name] = saved_loc self.accepted = bool(self.selected_files)
def __init__(self, parent): QObject.__init__(self, parent) self.events = []
def __init__(self, editor): QObject.__init__(self, editor) self.active_templates = [] self.last_selected_text = '' editor.document().contentsChange.connect(self.contents_changed) self.snip_func = None
def __init__(self, attach_to_Class, which_widget, tab_signal): QObject.__init__(self, attach_to_Class) self.tab_signal = tab_signal self.which_widget = which_widget
def __init__(self): QObject.__init__(self) self.called = Event() self.call.connect(self.run_func, Qt.ConnectionType.QueuedConnection)