def ask_user(self): # Ask the user for a factor by which to multiply all font sizes factor, ok = QInputDialog.getDouble( self.gui, 'Enter a magnification factor', 'Allow font sizes in the book will be multiplied by the specified factor', value=2, min=0.1, max=4) if ok: # Ensure any in progress editing the user is doing is present in the container self.boss.commit_all_editors_to_container() try: self.magnify_fonts(factor) except Exception: # Something bad happened report the error to the user import traceback error_dialog( self.gui, _('Failed to magnify fonts'), _('Failed to magnify fonts, click "Show details" for more info' ), det_msg=traceback.format_exc(), show=True) # Revert to the saved restore point self.boss.revert_requested( self.boss.global_undo.previous_container) else: # Show the user what changes we have made, allowing her to # revert them if necessary self.boss.show_current_diff() # Update the editor UI to take into account all the changes we # have made self.boss.apply_container_update_to_gui()
def create_new_bookmark(self, pos_data): base_default_title = self.toc.model().title_for_current_node or _( 'Bookmark') all_titles = {bm['title'] for bm in self.get_bookmarks()} c = 0 while True: c += 1 default_title = '{} #{}'.format(base_default_title, c) if default_title not in all_titles: break title, ok = QInputDialog.getText(self, _('Add bookmark'), _('Enter title for bookmark:'), text=pos_data.get('selected_text') or default_title) title = unicode_type(title).strip() if not ok or not title: return title = self.uniqify_bookmark_title(title) cfi = (pos_data.get('selection_bounds') or {}).get('start') or pos_data['cfi'] bm = { 'title': title, 'pos_type': 'epubcfi', 'pos': cfi, 'timestamp': utcnow().isoformat(), } bookmarks = self.get_bookmarks() bookmarks.append(bm) self.set_bookmarks(bookmarks) self.set_current_bookmark(bm) self.edited.emit(bookmarks)
def anchor_clicked(self, qurl): url = qurl.toString() if url.startswith('err:'): errnum = int(url[4:]) err = self.errors[errnum] newurl, ok = QInputDialog.getText(self, _('Fix URL'), _('Enter the corrected URL:') + '\xa0' * 40, text=err[2]) if not ok: return nmap = defaultdict(set) for name, href in {(l[0], l[1]) for l in err[0]}: nmap[name].add(href) for name, hrefs in iteritems(nmap): raw = oraw = get_data(name) for href in hrefs: raw = raw.replace(href, newurl) if raw != oraw: set_data(name, raw) self.fixed_errors.add(errnum) self.populate_results() elif url.startswith('loc:'): lnum, name = url[4:].partition(',')[::2] lnum = int(lnum or 1) editor = get_boss().edit_file(name) if lnum and editor is not None and editor.has_line_numbers: editor.current_line = lnum
def save_ruleset(self): if not self.rules: error_dialog(self, _('No rules'), _('Cannot save as no rules have been created'), show=True) return text, ok = QInputDialog.getText(self, _('Save ruleset as'), _('Enter a name for this ruleset:'), text=self.loaded_ruleset or '') if ok and text: if self.loaded_ruleset and text == self.loaded_ruleset: if not question_dialog( self, _('Are you sure?'), _('A ruleset with the name "%s" already exists, do you want to replace it?' ) % text): return self.loaded_ruleset = text rules = self.rules if rules: self.PREFS_OBJECT[text] = self.rules elif text in self.PREFS_OBJECT: del self.PREFS_OBJECT[text] self.build_load_menu()
def rename_requested(self, name, location): LibraryDatabase = db_class() loc = location.replace('/', os.sep) base = os.path.dirname(loc) old_name = name.replace('&&', '&') newname, ok = QInputDialog.getText( self.gui, _('Rename') + ' ' + old_name, '<p>' + _('Choose a new name for the library <b>%s</b>. ') % name + '<p>' + _('Note that the actual library folder will be renamed.'), text=old_name) newname = sanitize_file_name(str(newname)) if not ok or not newname or newname == old_name: return newloc = os.path.join(base, newname) if os.path.exists(newloc): return error_dialog( self.gui, _('Already exists'), _('The folder %s already exists. Delete it first.') % newloc, show=True) if (iswindows and len(newloc) > LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT): return error_dialog( self.gui, _('Too long'), _('Path to library too long. It must be less than' ' %d characters.') % LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT, show=True) if not os.path.exists(loc): error_dialog( self.gui, _('Not found'), _('Cannot rename as no library was found at %s. ' 'Try switching to this library first, then switch back ' 'and retry the renaming.') % loc, show=True) return self.gui.library_broker.remove_library(loc) try: os.rename(loc, newloc) except: import traceback det_msg = 'Location: %r New Location: %r\n%s' % ( loc, newloc, traceback.format_exc()) error_dialog( self.gui, _('Rename failed'), _('Failed to rename the library at %s. ' 'The most common cause for this is if one of the files' ' in the library is open in another program.') % loc, det_msg=det_msg, show=True) return self.stats.rename(location, newloc) self.rename_library_icon(old_name, newname) self.build_menus() self.gui.iactions['Copy To Library'].build_menus()
def add_insert_tag(self): name, ok = QInputDialog.getText(self, _('Name of tag to add'), _('Enter the name of the tag')) if ok: mru = tprefs['insert_tag_mru'] mru.insert(0, name) tprefs['insert_tag_mru'] = mru self._build_insert_tag_button_menu()
def create_folder(self, item): text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder')) if ok and str(text): c = QTreeWidgetItem(item, (str(text),)) c.setIcon(0, QIcon(I('mimetypes/dir.png'))) for item in self.folders.selectedItems(): item.setSelected(False) c.setSelected(True) self.folders.setCurrentItem(c)
def save(self): spec = self.current_sort_spec if not spec: return self.no_column_selected_error() name, ok = QInputDialog.getText(self, _('Choose name'), _('Choose a name for these settings')) if ok: q = self.saved_specs q[name] = spec self.saved_specs = q
def oilify_image(self): val, ok = QInputDialog.getDouble( self, _('Oilify image'), _('The strength of the operation (higher numbers have larger effects)' ), value=4, min=0.1, max=20) if ok: self.canvas.oilify_image(radius=val)
def blur_image(self): val, ok = QInputDialog.getInt( self, _('Blur image'), _('The standard deviation for the Gaussian blur operation (higher means more blurring)' ), value=3, min=1, max=20) if ok: self.canvas.blur_image(sigma=val)
def sharpen_image(self): val, ok = QInputDialog.getInt( self, _('Sharpen image'), _('The standard deviation for the Gaussian sharpen operation (higher means more sharpening)' ), value=3, min=1, max=20) if ok: self.canvas.sharpen_image(sigma=val)
def request_change_ext(self): names = self.request_rename_common() if names is not None: text, ok = QInputDialog.getText(self, _('Rename files'), _('New file extension:')) if ok and text: ext = text.lstrip('.') def change_name(name): base = posixpath.splitext(name)[0] return base + '.' + ext name_map = {n:change_name(n) for n in names} self.bulk_rename_requested.emit(name_map)
def export_settings(self): name, ok = QInputDialog.getText(self, _('Name for these settings'), _('Theme name:'), text=_('My cover style')) if ok: base = os.path.join(config_dir, 'cover-generation-themes') os.makedirs(base, exist_ok=True) path = make_long_path_useable(os.path.join(base, name + '.json')) raw = self.settings.serialized_prefs with open(path, 'wb') as f: f.write(raw)
def change_name(self): ci = self.plist.currentItem() if ci is None: return error_dialog(self, _('No selection'), _( 'No application selected'), show=True) name = ci.data(Qt.ItemDataRole.DisplayRole) name, ok = QInputDialog.getText(self, _('Enter new name'), _('New name for {}').format(name), text=name) if ok and name: entry = ci.data(ENTRY_ROLE) change_name_in_entry(entry, name) ci.setData(ENTRY_ROLE, entry) self.update_stored_config() ci.setData(Qt.ItemDataRole.DisplayRole, name)
def save_settings(self): if not self.something_selected: return error_dialog(self, _('No actions selected'), _('You must select at least one action before saving'), show=True) name, ok = QInputDialog.getText(self, _('Choose name'), _('Choose a name for these settings')) if ok: name = str(name).strip() if name: settings = {ac:getattr(self, 'opt_'+ac).isChecked() for ac in self.all_actions} saved = gprefs.get('polish_settings', {}) saved[name] = settings gprefs.set('polish_settings', saved) self.setup_load_button()
def save_settings(self): xpaths = self.xpaths if not xpaths: return error_dialog(self, _('No XPaths'), _('No XPaths have been entered'), show=True) if not self.check(): return name, ok = QInputDialog.getText(self, _('Choose name'), _('Choose a name for these settings')) if ok: name = str(name).strip() if name: saved = self.prefs.get('xpath_toc_settings', {}) # in JSON all keys have to be strings saved[name] = {str(i):x for i, x in enumerate(xpaths)} self.prefs.set('xpath_toc_settings', saved) self.setup_load_button()