Exemplo n.º 1
0
 def ok_clicked(self):
     pb = []
     for i in range(0, len(self.source_widgets)):
         s = unicode(self.source_widgets[i].text())
         if s:
             d = self.dest_widgets[i].currentIndex()
             if d != 0:
                 try:
                     validation_formatter.validate(s)
                 except Exception as err:
                     error_dialog(self, _('Invalid template'),
                             '<p>'+_('The template %s is invalid:')%s +
                             '<br>'+str(err), show=True)
                     return
                 pb.append((s, self.dest_fields[d]))
             else:
                 error_dialog(self, _('Invalid destination'),
                         '<p>'+_('The destination field cannot be blank'),
                         show=True)
                 return
     if len(pb) == 0:
         if self.current_format in self.current_plugboards:
             fpb = self.current_plugboards[self.current_format]
             if self.current_device in fpb:
                 del fpb[self.current_device]
             if len(fpb) == 0:
                 del self.current_plugboards[self.current_format]
     else:
         if self.current_format not in self.current_plugboards:
             self.current_plugboards[self.current_format] = {}
         fpb = self.current_plugboards[self.current_format]
         fpb[self.current_device] = pb
     self.changed_signal.emit()
     self.refill_all_boxes()
    def validate(self):
        formats = set(self.format_map())
        extra = formats - set(self.calibre_known_formats)
        if extra:
            fmts = sorted((x.upper() for x in extra))
            if not question_dialog(
                    self, _('Unknown formats'),
                    _('You have enabled the <b>{0}</b> formats for'
                      ' your {1}. The {1} may not support them.'
                      ' If you send these formats to your {1} they '
                      'may not work. Are you sure?').format(
                          (', '.join(fmts)), self.device_name)):
                return False

        tmpl = unicode_type(self.opt_save_template.text())
        try:
            validation_formatter.validate(tmpl)
            return True
        except Exception as err:
            error_dialog(self,
                         _('Invalid template'),
                         '<p>' + _('The template %s is invalid:') % tmpl +
                         '<br>' + unicode_type(err),
                         show=True)

            return False
Exemplo n.º 3
0
 def ok_clicked(self):
     pb = []
     for i in range(0, len(self.source_widgets)):
         s = str(self.source_widgets[i].text())
         if s:
             d = self.dest_widgets[i].currentIndex()
             if d != 0:
                 try:
                     validation_formatter.validate(s)
                 except Exception as err:
                     error_dialog(self, _('Invalid template'),
                             '<p>'+_('The template %s is invalid:')%s +
                             '<br>'+str(err), show=True)
                     return
                 pb.append((s, self.dest_fields[d]))
             else:
                 error_dialog(self, _('Invalid destination'),
                         '<p>'+_('The destination field cannot be blank'),
                         show=True)
                 return
     if len(pb) == 0:
         if self.current_format in self.current_plugboards:
             fpb = self.current_plugboards[self.current_format]
             if self.current_device in fpb:
                 del fpb[self.current_device]
             if len(fpb) == 0:
                 del self.current_plugboards[self.current_format]
     else:
         if self.current_format not in self.current_plugboards:
             self.current_plugboards[self.current_format] = {}
         fpb = self.current_plugboards[self.current_format]
         fpb[self.current_device] = pb
     self.changed_signal.emit()
     self.refill_all_boxes()
Exemplo n.º 4
0
 def setModelData(self, editor, model, index):
     val = unicode(editor.textbox.toPlainText())
     try:
         validation_formatter.validate(val)
     except Exception as err:
         error_dialog(self.parent(), _('Invalid template'),
                 '<p>'+_('The template %s is invalid:')%val +
                 '<br>'+str(err), show=True)
     model.setData(index, (val), Qt.EditRole)
Exemplo n.º 5
0
 def setModelData(self, editor, model, index):
     val = unicode(editor.textbox.toPlainText())
     try:
         validation_formatter.validate(val)
     except Exception as err:
         error_dialog(self.parent(), _('Invalid template'),
                 '<p>'+_('The template %s is invalid:')%val +
                 '<br>'+str(err), show=True)
     model.setData(index, QVariant(val), Qt.EditRole)
Exemplo n.º 6
0
    def validate(self):
        from calibre.utils.formatter import validation_formatter
        tmpl = self.template
        try:
            validation_formatter.validate(tmpl)
            return True
        except Exception as err:
            error_dialog(self, _('Invalid template'),
                    '<p>'+_('The template %s is invalid:')%tmpl + \
                    '<br>'+unicode(err), show=True)

            return False
Exemplo n.º 7
0
    def validate(self):
        from calibre.utils.formatter import validation_formatter
        tmpl = self.template
        try:
            validation_formatter.validate(tmpl)
            return True
        except Exception as err:
            error_dialog(self, _('Invalid template'),
                    '<p>'+_('The template %s is invalid:')%tmpl + \
                    '<br>'+unicode(err), show=True)

            return False
Exemplo n.º 8
0
 def ok_clicked(self):
     pb = []
     comments_in_dests = False
     for i in range(0, len(self.source_widgets)):
         s = unicode_type(self.source_widgets[i].text())
         if s:
             d = self.dest_widgets[i].currentIndex()
             if d != 0:
                 try:
                     validation_formatter.validate(s)
                 except Exception as err:
                     error_dialog(self,
                                  _('Invalid template'),
                                  '<p>' +
                                  _('The template %s is invalid:') % s +
                                  '<br>' + unicode_type(err),
                                  show=True)
                     return
                 pb.append((s, self.dest_fields[d]))
                 comments_in_dests = comments_in_dests or self.dest_fields[
                     d] == 'comments'
             else:
                 error_dialog(self,
                              _('Invalid destination'),
                              '<p>' +
                              _('The destination field cannot be blank'),
                              show=True)
                 return
     if len(pb) == 0:
         if self.current_format in self.current_plugboards:
             fpb = self.current_plugboards[self.current_format]
             if self.current_device in fpb:
                 del fpb[self.current_device]
             if len(fpb) == 0:
                 del self.current_plugboards[self.current_format]
     else:
         if comments_in_dests and not question_dialog(
                 self.gui,
                 _('Plugboard modifies Comments'),
                 _('This plugboard modifies the Comments metadata. '
                   'If the Comments are set to invalid HTML, it could cause problems on the device. '
                   'Are you sure you wish to save this plugboard?'),
                 skip_dialog_name='plugboard_comments_in_dests'):
             return
         if self.current_format not in self.current_plugboards:
             self.current_plugboards[self.current_format] = {}
         fpb = self.current_plugboards[self.current_format]
         fpb[self.current_device] = pb
     self.changed_signal.emit()
     self.refill_all_boxes()
Exemplo n.º 9
0
    def validate(self):
        from calibre.utils.formatter import validation_formatter

        tmpl = self.template
        try:
            validation_formatter.validate(tmpl)
            return True
        except Exception as err:
            error_dialog(
                self,
                _("Invalid template"),
                "<p>" + _("The template %s is invalid:") % tmpl + "<br>" + unicode(err),
                show=True,
            )

            return False
Exemplo n.º 10
0
 def ok_clicked(self):
     pb = []
     comments_in_dests = False
     for i in range(0, len(self.source_widgets)):
         s = unicode_type(self.source_widgets[i].text())
         if s:
             d = self.dest_widgets[i].currentIndex()
             if d != 0:
                 try:
                     validation_formatter.validate(s)
                 except Exception as err:
                     error_dialog(self, _('Invalid template'),
                             '<p>'+_('The template %s is invalid:')%s +
                             '<br>'+str(err), show=True)
                     return
                 pb.append((s, self.dest_fields[d]))
                 comments_in_dests = comments_in_dests or self.dest_fields[d] == 'comments'
             else:
                 error_dialog(self, _('Invalid destination'),
                         '<p>'+_('The destination field cannot be blank'),
                         show=True)
                 return
     if len(pb) == 0:
         if self.current_format in self.current_plugboards:
             fpb = self.current_plugboards[self.current_format]
             if self.current_device in fpb:
                 del fpb[self.current_device]
             if len(fpb) == 0:
                 del self.current_plugboards[self.current_format]
     else:
         if comments_in_dests and not question_dialog(self.gui, _('Plugboard modifies Comments'),
                  _('This plugboard modifies the Comments metadata. '
                    'If the Comments are set to invalid HTML, it could cause problems on the device. '
                    'Are you sure you wish to save this plugboard?'
                    ),
                     skip_dialog_name='plugboard_comments_in_dests'
                     ):
             return
         if self.current_format not in self.current_plugboards:
             self.current_plugboards[self.current_format] = {}
         fpb = self.current_plugboards[self.current_format]
         fpb[self.current_device] = pb
     self.changed_signal.emit()
     self.refill_all_boxes()
Exemplo n.º 11
0
    def validate(self):
        formats = set(self.format_map())
        extra = formats - set(self.calibre_known_formats)
        if extra:
            fmts = sorted([x.upper() for x in extra])
            if not question_dialog(self, _('Unknown formats'),
                    _('You have enabled the <b>{0}</b> formats for'
                        ' your {1}. The {1} may not support them.'
                        ' If you send these formats to your {1} they '
                        'may not work. Are you sure?').format(
                            (', '.join(fmts)), self.device_name)):
                return False

        tmpl = unicode(self.opt_save_template.text())
        try:
            validation_formatter.validate(tmpl)
            return True
        except Exception as err:
            error_dialog(self, _('Invalid template'),
                    '<p>'+_('The template %s is invalid:')%tmpl +
                    '<br>'+unicode(err), show=True)

            return False
Exemplo n.º 12
0
 def validate(self):
     '''
     Do a syntax check on the format string. Doing a semantic check
     (verifying that the fields exist) is not useful in the presence of
     custom fields, because they may or may not exist.
     '''
     tmpl = preprocess_template(self.opt_template.text())
     try:
         t = validation_formatter.validate(tmpl)
         if t.find(validation_formatter._validation_string) < 0:
             return question_dialog(self, _('Constant template'),
                 _('The template contains no {fields}, so all '
                   'books will have the same name. Is this OK?'))
     except Exception as err:
         error_dialog(self, _('Invalid template'),
                 '<p>'+_('The template %s is invalid:')%tmpl +
                 '<br>'+str(err), show=True)
         return False
     return True