Exemplo n.º 1
0
    def accept(self):
        txt = unicode(self.textbox.toPlainText()).rstrip()
        if self.coloring:
            if self.colored_field.currentIndex() == -1:
                error_dialog(self, _('No column chosen'),
                    _('You must specify a column to be colored'), show=True)
                return
            if not txt:
                error_dialog(self, _('No template provided'),
                    _('The template box cannot be empty'), show=True)
                return

            self.rule = (unicode(self.colored_field.itemData(
                                self.colored_field.currentIndex()) or ''), txt)
        elif self.iconing:
            rt = unicode(self.icon_kind.itemData(self.icon_kind.currentIndex()) or '')
            self.rule = (rt,
                         unicode(self.icon_field.itemData(
                                self.icon_field.currentIndex()) or ''),
                         txt)
        elif self.embleming:
            self.rule = ('icon', 'title', txt)
        else:
            self.rule = ('', txt)
        QDialog.accept(self)
Exemplo n.º 2
0
 def accept(self):
     if self.trim_action.isEnabled():
         self.trim_action.trigger()
     if self.canvas.is_modified:
         self.image_data = self.canvas.get_image_data()
     self.cleanup()
     QDialog.accept(self)
Exemplo n.º 3
0
 def accept(self):
     from calibre.gui2.ui import get_gui
     db = get_gui().current_db
     self.save_current_search()
     ss = {name:self.searches[name] for name in self.searches}
     db.saved_search_set_all(ss)
     QDialog.accept(self)
Exemplo n.º 4
0
 def accept(self):
     un = unicode(self.username.text())
     if self.service.get('at_in_username', False) and '@' not in un:
         return error_dialog(self, _('Incorrect username'),
                 _('%s needs the full email address as your username') %
                 self.service['name'], show=True)
     QDialog.accept(self)
Exemplo n.º 5
0
 def accept(self):
     action = 'move'
     if self.existing_library.isChecked():
         action = 'existing'
     elif self.empty_library.isChecked():
         action = 'new'
     text = unicode_type(self.location.text()).strip()
     if not text:
         return error_dialog(self, _('No location'), _('No location selected'),
                 show=True)
     loc = os.path.abspath(text)
     if action == 'move':
         try:
             os.makedirs(loc)
         except EnvironmentError as e:
             if e.errno != errno.EEXIST:
                 raise
     if not loc or not os.path.exists(loc) or not os.path.isdir(loc):
         if action == 'new' and not os.path.exists(loc):
             os.makedirs(loc)
         else:
             return error_dialog(self, _('Bad location'),
                     _('%s is not an existing folder')%loc, show=True)
     if not self.check_action(action, loc):
         return
     self.location.save_history()
     self.perform_action(action, loc)
     QDialog.accept(self)  # Must be after perform action otherwise the progress dialog is not updated on windows
Exemplo n.º 6
0
 def accept(self):
     if len(self.key_name) == 0 or self.key_name.isspace():
         errmsg = u"Please enter an eInk Kindle Serial Number or click Cancel in the dialog."
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_name) != 16:
         errmsg = u"EInk Kindle Serial Numbers must be 16 characters long. This is {0:d} characters long.".format(len(self.key_name))
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     QDialog.accept(self)
Exemplo n.º 7
0
 def accept(self):
     if len(self.key_name) == 0 or self.key_name.isspace():
         errmsg = u"Please enter a Mobipocket PID or click Cancel in the dialog."
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_name) != 8 and len(self.key_name) != 10:
         errmsg = u"Mobipocket PIDs must be 8 or 10 characters long. This is {0:d} characters long.".format(len(self.key_name))
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     QDialog.accept(self)
Exemplo n.º 8
0
 def accept(self):
     if len(self.key_name) == 0 or self.key_name.isspace():
         errmsg = u"All fields are required!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_name) < 4:
         errmsg = u"Key name must be at <i>least</i> 4 characters long!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     QDialog.accept(self)
Exemplo n.º 9
0
 def accept(self):
     from calibre.gui2.ui import get_gui
     db = get_gui().current_db
     if self.current_search_name:
         self.searches[self.current_search_name] = unicode(self.search_text.toPlainText())
     ss = {name:self.searches[name] for name in self.searches}
     db.saved_search_set_all(ss)
     QDialog.accept(self)
Exemplo n.º 10
0
 def accept(self):
     newloc = unicode(self.loc.text())
     if not db_class().exists_at(newloc):
         error_dialog(self, _("No library found"), _("No existing calibre library found at %s") % newloc, show=True)
         return
     self.stats.rename(self.location, newloc)
     self.newloc = newloc
     QDialog.accept(self)
Exemplo n.º 11
0
 def accept(self):
     recs = GuiRecommendations()
     for w in self._groups_model.widgets:
         if not w.pre_commit_check():
             return
         x = w.commit(save_defaults=False)
         recs.update(x)
     self._recommendations = recs
     QDialog.accept(self)
Exemplo n.º 12
0
 def accept(self):
     if "{word}" not in self.url.text():
         return error_dialog(
             self,
             _("Invalid URL"),
             _("The URL {0} does not have {1} in it.").format(self.url.text(), "{word}"),
             show=True,
         )
     QDialog.accept(self)
Exemplo n.º 13
0
 def accept(self):
     if self.rule_kind != 'color':
         fname = self.get_filenames_from_box()
         if not fname:
             error_dialog(self, _('No icon selected'),
                     _('You must choose an icon for this rule'), show=True)
             return
     if self.validate():
         QDialog.accept(self)
Exemplo n.º 14
0
 def accept(self):
     # Prevent the usual dialog accept mechanisms from working
     gprefs['metadata_single_gui_geom'] = bytearray(self.saveGeometry())
     if DEBUG_DIALOG:
         if self.stack.currentIndex() == 2:
             return QDialog.accept(self)
     else:
         if self.stack.currentIndex() == 1:
             return QDialog.accept(self)
Exemplo n.º 15
0
 def accept(self):
     self.save_category()
     for cat in sorted(self.categories.keys(), key=sort_key):
         components = cat.split('.')
         for i in range(0,len(components)):
             c = '.'.join(components[0:i+1])
             if c not in self.categories:
                 self.categories[c] = []
     QDialog.accept(self)
Exemplo n.º 16
0
 def accept(self):
     name = self.name.text()
     if not name or len(name) < 2 or not name.startswith('#'):
         return error_dialog(self, _('Invalid name'), _(
             'The color scheme name "%s" is invalid. It must start with a # and be at least two characters long.') % name, show=True)
     if name in self.existing_names:
         if not self.is_editing or name != self.scheme_name:
             return error_dialog(self, _('Invalid name'), _(
                 'A color scheme with the name "%s" already exists.') % name, show=True)
     QDialog.accept(self)
Exemplo n.º 17
0
 def accept(self):
     un = unicode(self.username.text())
     if self.service.get("at_in_username", False) and "@" not in un:
         return error_dialog(
             self,
             _("Incorrect username"),
             _("%s needs the full email address as your username") % self.service["name"],
             show=True,
         )
     QDialog.accept(self)
Exemplo n.º 18
0
 def on_all_done(self):
     if not self.error:
         # The cc widgets can only be accessed in the GUI thread
         try:
             for w in self.cc_widgets:
                 w.commit(self.ids)
         except Exception as err:
             import traceback
             self.error = (err, traceback.format_exc())
     self.pi.stopAnimation()
     QDialog.accept(self)
Exemplo n.º 19
0
 def accept(self):
     if len(self.file_name) == 0 or len(self.key_value) == 0:
         errmsg = u"Please choose a Kindle for Android backup file."
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_name) == 0 or self.key_name.isspace():
         errmsg = u"Please enter a key name."
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_name) < 4:
         errmsg = u"Key name must be at <i>least</i> 4 characters long!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     QDialog.accept(self)
Exemplo n.º 20
0
 def accept(self):
     if len(self.key_name) == 0 or len(self.user_name) == 0 or len(self.cc_number) == 0 or self.key_name.isspace() or self.user_name.isspace() or self.cc_number.isspace():
         errmsg = u"All fields are required!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if not self.cc_number.isdigit():
         errmsg = u"Numbers only in the credit card number field!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_name) < 4:
         errmsg = u"Key name must be at <i>least</i> 4 characters long!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     QDialog.accept(self)
Exemplo n.º 21
0
 def accept(self):
     if self.stack.currentIndex() == 0:
         self.on_shutdown()
         return QDialog.accept(self)
     try:
         close = self.commit()
     except AbortCommit:
         return
     if close:
         self.on_shutdown()
         return QDialog.accept(self)
     self.hide_plugin()
Exemplo n.º 22
0
 def get_plugins(self):
     from calibre.gui2.dialogs.plugin_updater import (PluginUpdaterDialog,
         FILTER_UPDATE_AVAILABLE)
     d = PluginUpdaterDialog(self.parent(),
             initial_filter=FILTER_UPDATE_AVAILABLE)
     d.exec_()
     if d.do_restart:
         QDialog.accept(self)
         from calibre.gui2.ui import get_gui
         gui = get_gui()
         if gui is not None:
             gui.quit(restart=True)
Exemplo n.º 23
0
 def get_plugins(self):
     from calibre.gui2.dialogs.plugin_updater import (
         PluginUpdaterDialog, FILTER_UPDATE_AVAILABLE)
     d = PluginUpdaterDialog(self.parent(),
                             initial_filter=FILTER_UPDATE_AVAILABLE)
     d.exec_()
     if d.do_restart:
         QDialog.accept(self)
         from calibre.gui2.ui import get_gui
         gui = get_gui()
         if gui is not None:
             gui.quit(restart=True)
Exemplo n.º 24
0
 def accept(self):
     if self.stack.currentIndex() == 0:
         self.on_shutdown()
         return QDialog.accept(self)
     try:
         close = self.commit()
     except AbortCommit:
         return
     if close:
         self.on_shutdown()
         return QDialog.accept(self)
     self.hide_plugin()
Exemplo n.º 25
0
 def accept(self):
     if len(self.key_name) == 0 or len(self.user_name) == 0 or len(self.cc_number) == 0 or self.key_name.isspace() or self.user_name.isspace() or self.cc_number.isspace():
         errmsg = "All fields are required!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_name) < 4:
         errmsg = "Key name must be at <i>least</i> 4 characters long!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), errmsg, show=True, show_copy_button=False)
     if len(self.key_value) == 0:
         self.retrieve_key()
         if len(self.key_value) == 0:
             return
     QDialog.accept(self)
Exemplo n.º 26
0
 def accept(self):
     if self.treat_as_image.isChecked():
         url = self.url.text()
         if url.lower().split(':', 1)[0] in ('http', 'https'):
             error_dialog(
                 self,
                 _('Remote images not supported'),
                 _('You must download the image to your computer, URLs pointing'
                   ' to remote images are not supported.'),
                 show=True)
             return
     QDialog.accept(self)
Exemplo n.º 27
0
 def ok_clicked(self, *args):
     self.cover_pixmap = self.covers_widget.cover_pixmap()
     if self.stack.currentIndex() == 0:
         self.next_clicked()
         return
     if DEBUG_DIALOG:
         if self.cover_pixmap is not None:
             self.w = QLabel()
             self.w.setPixmap(self.cover_pixmap)
             self.stack.addWidget(self.w)
             self.stack.setCurrentIndex(2)
     else:
         QDialog.accept(self)
Exemplo n.º 28
0
    def accept(self):
        path = unicode(self.path.text())
        if not path:
            return error_dialog(self, _('Path not specified'), _(
                'You must specify the path to the OPML file to import'), show=True)
        with open(path, 'rb') as f:
            raw = f.read()
        self.recipes = tuple(import_opml(raw, self.preserve_groups.isChecked()))
        if len(self.recipes) == 0:
            return error_dialog(self, _('No feeds found'), _(
                'No importable RSS feeds found in the OPML file'), show=True)

        QDialog.accept(self)
Exemplo n.º 29
0
 def ok_clicked(self, *args):
     self.cover_pixmap = self.covers_widget.cover_pixmap()
     if self.stack.currentIndex() == 0:
         self.next_clicked()
         return
     if DEBUG_DIALOG:
         if self.cover_pixmap is not None:
             self.w = QLabel()
             self.w.setPixmap(self.cover_pixmap)
             self.stack.addWidget(self.w)
             self.stack.setCurrentIndex(2)
     else:
         QDialog.accept(self)
Exemplo n.º 30
0
 def accept(self):
     recs = GuiRecommendations()
     for w in self._groups_model.widgets:
         if not w.pre_commit_check():
             return
         x = w.commit(save_defaults=False)
         recs.update(x)
     self.opf_file, self.cover_file = self.mw.opf_file, self.mw.cover_file
     self._recommendations = recs
     if self.db is not None:
         recs['gui_preferred_input_format'] = self.input_format
         save_specifics(self.db, self.book_id, recs)
     self.break_cycles()
     QDialog.accept(self)
Exemplo n.º 31
0
    def accept(self):
        port = unicode_type(self.fixed_port.text())
        if not port:
            error_dialog(self,
                         _('Invalid port number'),
                         _('You must provide a port number.'),
                         show=True)
            return
        try:
            port = int(port)
        except:
            error_dialog(
                self,
                _('Invalid port number'),
                _('The port must be a number between 8000 and 65535.'),
                show=True)
            return

        if port < 8000 or port > 65535:
            error_dialog(
                self,
                _('Invalid port number'),
                _('The port must be a number between 8000 and 65535.'),
                show=True)
            return

        self.device_manager.set_option('smartdevice', 'password',
                                       unicode_type(self.password_box.text()))
        self.device_manager.set_option('smartdevice', 'autostart',
                                       self.autostart_box.isChecked())
        self.device_manager.set_option('smartdevice', 'use_fixed_port',
                                       self.use_fixed_port.isChecked())
        self.device_manager.set_option('smartdevice', 'port_number',
                                       unicode_type(self.fixed_port.text()))

        message = self.device_manager.start_plugin('smartdevice')

        if not self.device_manager.is_running('smartdevice'):
            error_dialog(
                self,
                _('Problem starting the wireless device'),
                _('The wireless device driver had problems starting. It said "%s"'
                  ) % message,
                show=True)
            self.device_manager.set_option('smartdevice', 'use_fixed_port',
                                           self.orig_fixed_port)
            self.device_manager.set_option('smartdevice', 'port_number',
                                           self.orig_port_number)
        else:
            QDialog.accept(self)
Exemplo n.º 32
0
 def accept(self):
     recs = GuiRecommendations()
     for w in self._groups_model.widgets:
         if not w.pre_commit_check():
             return
         x = w.commit(save_defaults=False)
         recs.update(x)
     self.opf_file, self.cover_file = self.mw.opf_file, self.mw.cover_file
     self._recommendations = recs
     if self.db is not None:
         recs['gui_preferred_input_format'] = self.input_format
         save_specifics(self.db, self.book_id, recs)
     self.break_cycles()
     QDialog.accept(self)
Exemplo n.º 33
0
 def accept(self, *args):
     tags = unicode(self.add_tags.text()).strip().split(",")
     tags = list(filter(None, [x.strip() for x in tags]))
     gprefs["add from ISBN tags"] = tags
     self.set_tags = tags
     bad = set()
     for line in unicode(self.isbn_box.toPlainText()).strip().splitlines():
         line = line.strip()
         if not line:
             continue
         parts = line.split(">>")
         if len(parts) > 2:
             parts = [parts[0] + ">>".join(parts[1:])]
         parts = [x.strip() for x in parts]
         if not parts[0]:
             continue
         isbn = check_isbn(parts[0])
         if isbn is not None:
             isbn = isbn.upper()
             if isbn not in self.isbns:
                 self.isbns.append(isbn)
                 book = {"isbn": isbn, "path": None}
                 if len(parts) > 1 and parts[1] and os.access(parts[1], os.R_OK) and os.path.isfile(parts[1]):
                     book["path"] = parts[1]
                 self.books.append(book)
         else:
             bad.add(parts[0])
     if bad:
         if self.books:
             if not question_dialog(
                 self,
                 _("Some invalid ISBNs"),
                 _(
                     "Some of the ISBNs you entered were invalid. They will"
                     " be ignored. Click Show Details to see which ones."
                     " Do you want to proceed?"
                 ),
                 det_msg="\n".join(bad),
                 show_copy_button=True,
             ):
                 return
         else:
             return error_dialog(
                 self,
                 _("All invalid ISBNs"),
                 _("All the ISBNs you entered were invalid. No books" " can be added."),
                 show=True,
             )
     QDialog.accept(self, *args)
Exemplo n.º 34
0
 def accept(self, *args):
     tags = unicode_type(self.add_tags.text()).strip().split(',')
     tags = list(filter(None, [x.strip() for x in tags]))
     gprefs['add from ISBN tags'] = tags
     self.set_tags = tags
     bad = set()
     for line in unicode_type(
             self.isbn_box.toPlainText()).strip().splitlines():
         line = line.strip()
         if not line:
             continue
         parts = line.split('>>')
         if len(parts) > 2:
             parts = [parts[0] + '>>'.join(parts[1:])]
         parts = [x.strip() for x in parts]
         if not parts[0]:
             continue
         isbn = check_isbn(parts[0])
         if isbn is not None:
             isbn = isbn.upper()
             if isbn not in self.isbns:
                 self.isbns.append(isbn)
                 book = {'isbn': isbn, 'path': None}
                 if len(parts) > 1 and parts[1] and \
                     os.access(parts[1], os.R_OK) and os.path.isfile(parts[1]):
                     book['path'] = parts[1]
                 self.books.append(book)
         else:
             bad.add(parts[0])
     if bad:
         if self.books:
             if not question_dialog(
                     self,
                     _('Some invalid ISBNs'),
                     _('Some of the ISBNs you entered were invalid. They will'
                       ' be ignored. Click Show Details to see which ones.'
                       ' Do you want to proceed?'),
                     det_msg='\n'.join(bad),
                     show_copy_button=True):
                 return
         else:
             return error_dialog(
                 self,
                 _('All invalid ISBNs'),
                 _('All the ISBNs you entered were invalid. No books'
                   ' can be added.'),
                 show=True)
     QDialog.accept(self, *args)
Exemplo n.º 35
0
 def accept(self):
     if self.atype.currentIndex() != 0 and not self.items:
         return error_dialog(self,
                             _('No libraries specified'),
                             _('You have not specified any libraries'),
                             show=True)
     return QDialog.accept(self)
Exemplo n.º 36
0
 def accept(self):
     # Any accept actions which need to be done before returning to caller
     savedir = self.choose_save_dir(self.dirout)
     if savedir is not None:
         self.buttonBox.button(QDialogButtonBox.Save).setText('Saving ...')
         self.buttonBox.button(QDialogButtonBox.Save).setEnabled(False)
         msg = ''
         if self.ebook.book_type.lower() == 'azw3':
             msg = '\n   ... please note, rebuilding an AZW3 may take a little longer ...'
         self.log.append('\nSaving now ... %s' % msg)
         self.viewlog()
         path_to_scrambled_ebook = os.path.join(savedir,
                                                self.fname_scrambled_ebook)
         self.ebook.commit(path_to_scrambled_ebook)
         self.cleanup()
         QDialog.accept(self)
Exemplo n.º 37
0
    def accept(self):
        n = unicode(self.vl_name.currentText()).strip()
        if not n:
            error_dialog(self.gui, _('No name'),
                         _('You must provide a name for the new virtual library'),
                         show=True)
            return

        if n.startswith('*'):
            error_dialog(self.gui, _('Invalid name'),
                         _('A virtual library name cannot begin with "*"'),
                         show=True)
            return

        if n in self.existing_names and n != self.editing:
            if not question_dialog(self.gui, _('Name already in use'),
                         _('That name is already in use. Do you want to replace it '
                           'with the new search?'),
                            default_yes=False):
                return

        v = unicode(self.vl_text.text()).strip()
        if not v:
            error_dialog(self.gui, _('No search string'),
                         _('You must provide a search to define the new virtual library'),
                         show=True)
            return

        try:
            db = self.gui.library_view.model().db
            recs = db.data.search_getting_ids('', v, use_virtual_library=False, sort_results=False)
        except ParseException as e:
            error_dialog(self.gui, _('Invalid search'),
                         _('The search in the search box is not valid'),
                         det_msg=e.msg, show=True)
            return

        if not recs and not question_dialog(
                self.gui, _('Search found no books'),
                _('The search found no books, so the virtual library '
                'will be empty. Do you really want to use that search?'),
                default_yes=False):
                return

        self.library_name = n
        self.library_search = v
        QDialog.accept(self)
Exemplo n.º 38
0
    def accept(self):
        n = unicode(self.vl_name.currentText()).strip()
        if not n:
            error_dialog(self.gui, _('No name'),
                         _('You must provide a name for the new virtual library'),
                         show=True)
            return

        if n.startswith('*'):
            error_dialog(self.gui, _('Invalid name'),
                         _('A virtual library name cannot begin with "*"'),
                         show=True)
            return

        if n in self.existing_names and n != self.editing:
            if not question_dialog(self.gui, _('Name already in use'),
                         _('That name is already in use. Do you want to replace it '
                           'with the new search?'),
                            default_yes=False):
                return

        v = unicode(self.vl_text.text()).strip()
        if not v:
            error_dialog(self.gui, _('No search string'),
                         _('You must provide a search to define the new virtual library'),
                         show=True)
            return

        try:
            db = self.gui.library_view.model().db
            recs = db.data.search_getting_ids('', v, use_virtual_library=False, sort_results=False)
        except ParseException as e:
            error_dialog(self.gui, _('Invalid search'),
                         _('The search in the search box is not valid'),
                         det_msg=e.msg, show=True)
            return

        if not recs and not question_dialog(
                self.gui, _('Search found no books'),
                _('The search found no books, so the virtual library '
                'will be empty. Do you really want to use that search?'),
                default_yes=False):
                return

        self.library_name = n
        self.library_search = v
        QDialog.accept(self)
Exemplo n.º 39
0
    def add_builtin_recipe(self):
        from calibre.web.feeds.recipes.collection import \
            get_builtin_recipe_collection, get_builtin_recipe_by_id
        from PyQt5.Qt import QDialog, QVBoxLayout, QListWidgetItem, \
                QListWidget, QDialogButtonBox, QSize

        d = QDialog(self)
        d.l = QVBoxLayout()
        d.setLayout(d.l)
        d.list = QListWidget(d)
        d.list.doubleClicked.connect(lambda x: d.accept())
        d.l.addWidget(d.list)
        d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel,
                Qt.Horizontal, d)
        d.bb.accepted.connect(d.accept)
        d.bb.rejected.connect(d.reject)
        d.l.addWidget(d.bb)
        d.setWindowTitle(_('Choose builtin recipe'))
        items = []
        for r in get_builtin_recipe_collection():
            id_ = r.get('id', '')
            title = r.get('title', '')
            lang = r.get('language', '')
            if id_ and title:
                items.append((title + ' [%s]'%lang, id_))

        items.sort(key=lambda x:sort_key(x[0]))
        for title, id_ in items:
            item = QListWidgetItem(title)
            item.setData(Qt.UserRole, id_)
            d.list.addItem(item)

        d.resize(QSize(450, 400))
        ret = d.exec_()
        d.list.doubleClicked.disconnect()
        if ret != d.Accepted:
            return

        items = list(d.list.selectedItems())
        if not items:
            return
        item = items[-1]
        id_ = unicode(item.data(Qt.UserRole) or '')
        title = unicode(item.data(Qt.DisplayRole) or '').rpartition(' [')[0]
        profile = get_builtin_recipe_by_id(id_, download_recipe=True)
        if profile is None:
            raise Exception('Something weird happened')

        if self._model.has_title(title):
            if question_dialog(self, _('Replace recipe?'),
                _('A custom recipe named %s already exists. Do you want to '
                    'replace it?')%title):
                self._model.replace_by_title(title, profile)
            else:
                return
        else:
            self.model.add(title, profile)

        self.clear()
Exemplo n.º 40
0
 def accept(self):
     if len(self.key_name) == 0 or self.key_name.isspace():
         errmsg = "Please enter an eInk Kobo Serial Number or click Cancel in the dialog."
         return error_dialog(None,
                             "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                             errmsg,
                             show=True,
                             show_copy_button=False)
     if len(self.key_name) != 13:
         errmsg = "EInk Kobo Serial Numbers must be 13 characters long. This is {0:d} characters long.".format(
             len(self.key_name))
         return error_dialog(None,
                             "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                             errmsg,
                             show=True,
                             show_copy_button=False)
     QDialog.accept(self)
Exemplo n.º 41
0
 def accept(self):
     if not self.current_library_book_id:
         d = error_dialog(self.gui, _('Match books'),
                  _('You must select a matching book'))
         d.exec_()
         return
     mi = self.library_db.get_metadata(self.current_library_book_id,
                           index_is_id=True, get_user_categories=False,
                           get_cover=True)
     book = self.device_db[self.current_device_book_id]
     book.smart_update(mi, replace_metadata=True)
     self.gui.update_thumbnail(book)
     book.in_library_waiting = True
     self.view.model().current_changed(self.current_device_book_index,
                                       self.current_device_book_index)
     self.save_state()
     QDialog.accept(self)
Exemplo n.º 42
0
 def accept(self):
     if not self.current_library_book_id:
         d = error_dialog(self.gui, _('Match books'),
                  _('You must select a matching book'))
         d.exec_()
         return
     mi = self.library_db.get_metadata(self.current_library_book_id,
                           index_is_id=True, get_user_categories=False,
                           get_cover=True)
     book = self.device_db[self.current_device_book_id]
     book.smart_update(mi, replace_metadata=True)
     self.gui.update_thumbnail(book)
     book.in_library_waiting = True
     self.view.model().current_changed(self.current_device_book_index,
                                       self.current_device_book_index)
     self.save_state()
     QDialog.accept(self)
Exemplo n.º 43
0
 def accept(self):
     if not self.name_is_ok:
         return error_dialog(self, _('No name specified'), _(
             'You must specify a name for the new file, with an extension, for example, chapter1.html'), show=True)
     name = unicode(self.name.text())
     name, ext = name.rpartition('.')[0::2]
     name = (name + '.' + ext.lower()).replace('\\', '/')
     mt = guess_type(name)
     if not self.file_data:
         if mt in OEB_DOCS:
             self.file_data = template_for('html').encode('utf-8')
             self.using_template = True
         elif mt in OEB_STYLES:
             self.file_data = template_for('css').encode('utf-8')
             self.using_template = True
     self.file_name = name
     QDialog.accept(self)
Exemplo n.º 44
0
 def accept(self):
     self.save_state()
     if not self.apply_changes():
         return
     if self.editing_multiple and self.current_row != len(self.row_list) - 1:
         num = len(self.row_list) - 1 - self.current_row
         from calibre.gui2 import question_dialog
         if not question_dialog(
                 self, _('Are you sure?'),
                 _('There are still %d more books to edit in this set.'
                   ' Are you sure you want to stop? Use the Next button'
                   ' instead of the OK button to move through books in the set.') % num,
                 yes_text=_('&Stop editing'), no_text=_('&Continue editing'),
                 yes_icon='dot_red.png', no_icon='dot_green.png',
                 default_yes=False, skip_dialog_name='edit-metadata-single-confirm-ok-on-multiple'):
             return self.do_one(delta=1, apply_changes=False)
     QDialog.accept(self)
Exemplo n.º 45
0
 def accept(self):
     """Tries to restore the image, and closes the dialog if successful."""
     # get list of sources to restore
     sources = self.model.sources
     sel_sources = [src for src in sources if src.selected]
     if len(sel_sources) > 0 and len(sel_sources) < len(
             sources) and self.wselonly.isChecked():
         sources = sel_sources
     if not sources:
         self.qerrmsg.showMessage("No sources to restore.")
         return
     busy = BusyIndicator()
     # get filenames
     infile = self.wfile_in.filename()
     outfile = self.wfile_out.filename()
     self.parent().showMessage(
         "Restoring %d model sources to image %s, writing to %s" %
         (len(sources), infile, outfile))
     # read fits file
     try:
         input_hdu = pyfits.open(infile)[0]
     except Exception as err:
         busy.reset_cursor()
         self.qerrmsg.showMessage("Error reading FITS file %s: %s" %
                                  (infile, str(err)))
         return
     # get beam sizes
     try:
         bmaj = float(str(self.wbmaj.text()))
         bmin = float(str(self.wbmin.text()))
         pa = float(str(self.wbpa.text()) or "0")
     except Exception as err:
         busy.reset_cursor()
         self.qerrmsg.showMessage("Invalid beam size specified")
         return
     bmaj = bmaj / (Imaging.FWHM * 3600) * DEG
     bmin = bmin / (Imaging.FWHM * 3600) * DEG
     pa = pa * DEG
     # restore
     try:
         Imaging.restoreSources(input_hdu, sources, bmaj, bmin, pa)
     except Exception as err:
         busy.reset_cursor()
         self.qerrmsg.showMessage("Error restoring model into image: %s" %
                                  str(err))
         return
     # save fits file
     try:
         input_hdu.writeto(outfile, overwrite=True)
     except Exception as err:
         busy.reset_cursor()
         self.qerrmsg.showMessage("Error writing FITS file %s: %s" %
                                  (outfile, str(err)))
         return
     self.parent().loadImage(outfile)
     busy.reset_cursor()
     return QDialog.accept(self)
Exemplo n.º 46
0
 def accept(self):
     name = self.name.text()
     if not name or len(name) < 2 or not name.startswith('#'):
         return error_dialog(
             self,
             _('Invalid name'),
             _('The color scheme name "%s" is invalid. It must start with a # and be at least two characters long.'
               ) % name,
             show=True)
     if name in self.existing_names:
         if not self.is_editing or name != self.scheme_name:
             return error_dialog(
                 self,
                 _('Invalid name'),
                 _('A color scheme with the name "%s" already exists.') %
                 name,
                 show=True)
     QDialog.accept(self)
Exemplo n.º 47
0
 def accept(self):
     if not str(self.key_ledit.text()) or str(self.key_ledit.text()).isspace():
         errmsg = "Key name field cannot be empty!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                 _(errmsg), show=True, show_copy_button=False)
     if len(self.key_ledit.text()) < 4:
         errmsg = "Key name must be at <i>least</i> 4 characters long!"
         return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                 _(errmsg), show=True, show_copy_button=False)
     if uStrCmp(self.key_ledit.text(), self.parent.listy.currentItem().text()):
             # Same exact name ... do nothing.
             return QDialog.reject(self)
     for k in self.parent.plugin_keys.keys():
         if (uStrCmp(self.key_ledit.text(), k, True) and
                     not uStrCmp(k, self.parent.listy.currentItem().text(), True)):
             errmsg = "The key name <strong>{0}</strong> is already being used.".format(self.key_ledit.text())
             return error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                 _(errmsg), show=True, show_copy_button=False)
     QDialog.accept(self)
Exemplo n.º 48
0
 def accept(self, *args):
     if self.shortcut_config.is_editing:
         from calibre.gui2 import info_dialog
         info_dialog(self, _('Still editing'),
                 _('You are in the middle of editing a keyboard shortcut'
                     ' first complete that, by clicking outside the '
                     ' shortcut editing box.'), show=True)
         return
     self.save_options(config())
     return QDialog.accept(self, *args)
Exemplo n.º 49
0
    def accept(self):
        path = unicode(self.path.text())
        if not path:
            return error_dialog(
                self,
                _('Path not specified'),
                _('You must specify the path to the OPML file to import'),
                show=True)
        with open(path, 'rb') as f:
            raw = f.read()
        self.recipes = tuple(import_opml(raw,
                                         self.preserve_groups.isChecked()))
        if len(self.recipes) == 0:
            return error_dialog(
                self,
                _('No feeds found'),
                _('No importable RSS feeds found in the OPML file'),
                show=True)

        QDialog.accept(self)
Exemplo n.º 50
0
 def accept(self):
     if not self.name_is_ok:
         return error_dialog(self, _('No name specified'), _(
             'You must specify a name for the new file, with an extension, for example, chapter1.html'), show=True)
     tprefs['auto_link_stylesheets'] = self.link_css.isChecked()
     name = unicode(self.name.text())
     name, ext = name.rpartition('.')[0::2]
     name = (name + '.' + ext.lower()).replace('\\', '/')
     mt = guess_type(name)
     if not self.file_data:
         if mt in OEB_DOCS:
             self.file_data = template_for('html').encode('utf-8')
             if tprefs['auto_link_stylesheets']:
                 data = add_stylesheet_links(current_container(), name, self.file_data)
                 if data is not None:
                     self.file_data = data
             self.using_template = True
         elif mt in OEB_STYLES:
             self.file_data = template_for('css').encode('utf-8')
             self.using_template = True
     self.file_name = name
     QDialog.accept(self)
Exemplo n.º 51
0
 def accept(self):
     action = 'move'
     if self.existing_library.isChecked():
         action = 'existing'
     elif self.empty_library.isChecked():
         action = 'new'
     text = unicode(self.location.text()).strip()
     if not text:
         return error_dialog(self,
                             _('No location'),
                             _('No location selected'),
                             show=True)
     loc = os.path.abspath(text)
     if not loc or not os.path.exists(loc) or not os.path.isdir(loc):
         return error_dialog(self,
                             _('Bad location'),
                             _('%s is not an existing folder') % loc,
                             show=True)
     if not self.check_action(action, loc):
         return
     QDialog.accept(self)
     self.location.save_history()
     self.perform_action(action, loc)
Exemplo n.º 52
0
    def accept(self):
        txt = unicode(self.textbox.toPlainText()).rstrip()
        if self.coloring:
            if self.colored_field.currentIndex() == -1:
                error_dialog(self, _('No column chosen'),
                    _('You must specify a column to be colored'), show=True)
                return
            if not txt:
                error_dialog(self, _('No template provided'),
                    _('The template box cannot be empty'), show=True)
                return

            self.rule = (unicode(self.colored_field.itemData(
                                self.colored_field.currentIndex()) or ''), txt)
        elif self.iconing:
            rt = unicode(self.icon_kind.itemData(self.icon_kind.currentIndex()) or '')
            self.rule = (rt,
                         unicode(self.icon_field.itemData(
                                self.icon_field.currentIndex()) or ''),
                         txt)
        else:
            self.rule = ('', txt)
        QDialog.accept(self)
Exemplo n.º 53
0
    def accept(self, *args, **kwargs):
        self.accepted = True
        self.dir_arrel = self.dlg_ui.lineEditrootdir.text()
        #        self.database_path=self.dlg_ui.l
        self.excludedirs = self.dlg_ui.lineEditexcldirs.text()
        self.includefiles = self.dlg_ui.lineEditincfiles.text()
        self.Startfrom0 = self.dlg_ui.checkBox.checkState()
        ObjSav.ObjS.OWrite(
            'createdbdlg', CreatedbDlg, 'createdbdlg', self.varsread, [
                self.dir_arrel, self.database_path, self.Startfrom0,
                self.excludedirs, self.includefiles
            ])
        #self.excludedirs=self.excludedirs#.split(",")
        #self.includefiles=self.includefiles#.split(",")

        return QDialog.accept(self, *args, **kwargs)
Exemplo n.º 54
0
 def accept(self):
     """When dialog is accepted with a default (bool) tag type,
     check if the user hasn't entered a name=value entry in the tag name field.
     This is a common mistake, and should be treated as a shortcut for setting string tags."""
     if isinstance(self.valedit.getValue(), bool):
         tagval = str(self.wtagsel.currentText()).split("=", 1)
         if len(tagval) > 1:
             #        print tagval
             if QMessageBox.warning(self,
                                    "Set a string tag instead?", """<P>You have included an "=" sign in the tag name.
         Perhaps you actually mean to set tag "%s" to the string value "%s"?</P>""" % tuple(tagval),
                                    QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) == QMessageBox.No:
                 return
             self.wtagsel.setEditText(tagval[0])
             self.valedit.setValue(tagval[1])
     return QDialog.accept(self)
Exemplo n.º 55
0
 def accept(self):
     for opt in self.config.option_set.preferences:
         g = getattr(self, 'opt_' + opt.name, False)
         if not g or not g.isVisible(): continue
         if hasattr(g, 'isChecked'):
             val = bool(g.isChecked())
         elif hasattr(g, 'value'):
             val = g.value()
         elif hasattr(g, 'itemText'):
             val = unicode(g.itemText(g.currentIndex()))
         elif hasattr(g, 'text'):
             val = unicode(g.text())
         else:
             raise Exception('Bad coding')
         self.config.set(opt.name, val)
     return QDialog.accept(self)
Exemplo n.º 56
0
    def customize_recipe(self):
        d = QDialog(self)
        d.l = QVBoxLayout()
        d.setLayout(d.l)
        d.list = QListWidget(d)
        connect_lambda(d.list.doubleClicked, d, lambda d: d.accept())
        d.l.addWidget(d.list)
        d.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
                                Qt.Horizontal, d)
        d.bb.accepted.connect(d.accept)
        d.bb.rejected.connect(d.reject)
        d.l.addWidget(d.bb)
        d.setWindowTitle(_('Choose builtin recipe'))
        items = []
        for r in get_builtin_recipe_collection():
            id_ = r.get('id', '')
            title = r.get('title', '')
            lang = r.get('language', '')
            if id_ and title:
                items.append((title + ' [%s]' % lang, id_))

        items.sort(key=lambda x: sort_key(x[0]))
        for title, id_ in items:
            item = QListWidgetItem(title)
            item.setData(Qt.UserRole, id_)
            d.list.addItem(item)

        d.resize(QSize(450, 400))
        ret = d.exec_()
        d.list.doubleClicked.disconnect()
        if ret != d.Accepted:
            return

        items = list(d.list.selectedItems())
        if not items:
            return
        item = items[-1]
        id_ = unicode_type(item.data(Qt.UserRole) or '')
        title = unicode_type(item.data(Qt.DisplayRole)
                             or '').rpartition(' [')[0]
        src = get_builtin_recipe_by_id(id_, download_recipe=True)
        if src is None:
            raise Exception('Something weird happened')
        src = as_unicode(src)

        self.edit_recipe(None, src)
Exemplo n.º 57
0
    def accept(self):
        disp = self.fm['display']
        values = []
        colors = []
        for i in range(0, self.table.rowCount()):
            v = unicode_type(self.table.item(i, 0).text())
            if not v:
                error_dialog(self,
                             _('Empty value'),
                             _('Empty values are not allowed'),
                             show=True)
                return
            values.append(v)
            c = unicode_type(self.table.cellWidget(i, 1).currentText())
            if c:
                colors.append(c)

        l_lower = [v.lower() for v in values]
        for i, v in enumerate(l_lower):
            if v in l_lower[i + 1:]:
                error_dialog(self,
                             _('Duplicate value'),
                             _('The value "{0}" is in the list more than '
                               'once, perhaps with different case').format(
                                   values[i]),
                             show=True)
                return

        if colors and len(colors) != len(values):
            error_dialog(self,
                         _('Invalid colors specification'),
                         _('Either all values or no values must have colors'),
                         show=True)
            return

        disp['enum_values'] = values
        disp['enum_colors'] = colors
        self.db.set_custom_column_metadata(self.fm['colnum'],
                                           display=disp,
                                           update_last_modified=True)
        self.save_geometry()
        return QDialog.accept(self)
Exemplo n.º 58
0
 def accept(self):
     if not self.uw.isReadOnly():
         un = self.username
         if not un:
             return error_dialog(
                 self,
                 _('Empty username'),
                 _('You must enter a username'),
                 show=True
             )
         if un in self.user_data:
             return error_dialog(
                 self,
                 _('Username already exists'),
                 _(
                     'A user with the username {} already exists. Please choose a different username.'
                 ).format(un),
                 show=True
             )
         err = validate_username(un)
         if err:
             return error_dialog(self, _('Username is not valid'), err, show=True)
     p1, p2 = self.password, self.p2.text()
     if p1 != p2:
         return error_dialog(
             self,
             _('Password do not match'),
             _('The two passwords you entered do not match!'),
             show=True
         )
     if not p1:
         return error_dialog(
             self,
             _('Empty password'),
             _('You must enter a password for this user'),
             show=True
         )
     err = validate_password(p1)
     if err:
         return error_dialog(self, _('Invalid password'), err, show=True)
     return QDialog.accept(self)