Пример #1
0
 def select_cover(self, *args):
     files = choose_images(self, 'change cover dialog',
                          _('Choose cover for ') +
                          self.dialog.title.current_val)
     if not files:
         return
     _file = files[0]
     if _file:
         _file = os.path.abspath(_file)
         if not os.access(_file, os.R_OK):
             d = error_dialog(self, _('Cannot read'),
                     _('You do not have permission to read the file: ') + _file)
             d.exec_()
             return
         cf, cover = None, None
         try:
             cf = open(_file, "rb")
             cover = cf.read()
         except IOError as e:
             d = error_dialog(self, _('Error reading file'),
                     _("<p>There was an error reading from file: <br /><b>")
                     + _file + "</b></p><br />"+str(e))
             d.exec_()
         if cover:
             orig = self.current_val
             self.current_val = cover
             if self.current_val is None:
                 self.current_val = orig
                 error_dialog(self,
                     _("Not a valid picture"),
                         _file + _(" is not a valid picture"), show=True)
Пример #2
0
 def select_cover(self):
     files = choose_images(self, 'change cover dialog',
                          _('Choose cover for ') + unicode(self.title.text()))
     if not files:
         return
     _file = files[0]
     if _file:
         _file = os.path.abspath(_file)
         if not os.access(_file, os.R_OK):
             d = error_dialog(self.parent(), _('Cannot read'),
                     _('You do not have permission to read the file: ') + _file)
             d.exec_()
             return
         cf, cover = None, None
         try:
             cf = open(_file, "rb")
             cover = cf.read()
         except IOError as e:
             d = error_dialog(self.parent(), _('Error reading file'),
                     _("<p>There was an error reading from file: <br /><b>") + _file + "</b></p><br />"+str(e))
             d.exec_()
         if cover:
             pix = QPixmap()
             pix.loadFromData(cover)
             if pix.isNull():
                 d = error_dialog(self.parent(), _('Error reading file'),
                                   _file + _(" is not a valid picture"))
                 d.exec_()
             else:
                 self.cover_path.setText(_file)
                 self.set_cover_tooltip(pix)
                 self.cover.setPixmap(pix)
                 self.cover_changed = True
                 self.cpixmap = pix
                 self.cover_data = cover
Пример #3
0
 def select_cover(self):
     files = choose_images(self, 'change cover dialog',
                          _('Choose cover for ') + unicode(self.title.text()))
     if not files:
         return
     _file = files[0]
     if _file:
         _file = os.path.abspath(_file)
         if not os.access(_file, os.R_OK):
             d = error_dialog(self.parent(), _('Cannot read'),
                     _('You do not have permission to read the file: ') + _file)
             d.exec_()
             return
         cf, cover = None, None
         try:
             cf = open(_file, "rb")
             cover = cf.read()
         except IOError as e:
             d = error_dialog(self.parent(), _('Error reading file'),
                     _("<p>There was an error reading from file: <br /><b>") + _file + "</b></p><br />"+str(e))
             d.exec_()
         if cover:
             pix = QPixmap()
             pix.loadFromData(cover)
             if pix.isNull():
                 d = error_dialog(self.parent(), _('Error reading file'),
                                   _file + _(" is not a valid picture"))
                 d.exec_()
             else:
                 self.cover_path.setText(_file)
                 self.set_cover_tooltip(pix)
                 self.cover.setPixmap(pix)
                 self.cover_changed = True
                 self.cpixmap = pix
                 self.cover_data = cover
Пример #4
0
 def select_cover(self, *args):
     files = choose_images(
         self, 'change cover dialog',
         _('Choose cover for ') + self.dialog.title.current_val)
     if not files:
         return
     _file = files[0]
     if _file:
         _file = os.path.abspath(_file)
         if not os.access(_file, os.R_OK):
             d = error_dialog(
                 self, _('Cannot read'),
                 _('You do not have permission to read the file: ') + _file)
             d.exec_()
             return
         cf, cover = None, None
         try:
             cf = open(_file, "rb")
             cover = cf.read()
         except IOError as e:
             d = error_dialog(
                 self, _('Error reading file'),
                 _("<p>There was an error reading from file: <br /><b>") +
                 _file + "</b></p><br />" + str(e))
             d.exec_()
         if cover:
             orig = self.current_val
             self.current_val = cover
             if self.current_val is None:
                 self.current_val = orig
                 error_dialog(self,
                              _("Not a valid picture"),
                              _file + _(" is not a valid picture"),
                              show=True)
Пример #5
0
 def change_background_image(self, img_id):
     files = choose_images(self, 'viewer-background-image', _('Choose background image'), formats=['png', 'gif', 'jpg', 'jpeg'])
     if files:
         img = files[0]
         with open(img, 'rb') as src, open(os.path.join(viewer_config_dir, 'bg-image.data'), 'wb') as dest:
             dest.write(as_bytes(guess_type(img)[0] or 'image/jpeg') + b'|')
             shutil.copyfileobj(src, dest)
         background_image.ans = None
         self.execute_when_ready('background_image_changed', img_id)
Пример #6
0
 def import_image(self):
     ans = choose_images(self, 'add-cover-choose-image', _('Choose a cover image'), formats=(
         'jpg', 'jpeg', 'png', 'gif'))
     if ans:
         from calibre.gui2.tweak_book.file_list import NewFileDialog
         d = NewFileDialog(self)
         d.do_import_file(ans[0], hide_button=True)
         if d.exec_() == d.Accepted:
             self.import_requested.emit(d.file_name, d.file_data)
             self.container = current_container()
             self.names_filter.clear()
             self.names.model().set_names(sorted(self.image_names, key=sort_key))
             i = self.names.model().find_name(d.file_name)
             self.names.setCurrentIndex(self.names.model().index(i))
             self.current_image_changed()
Пример #7
0
 def get_library_icon(self):
     try:
         paths = choose_images(
             self.gui, 'choose_library_icon',
             _('Select icon for library "%s"') % current_library_name())
         if paths:
             path = paths[0]
             p = QIcon(path).pixmap(QSize(256, 256))
             icp = library_icon_path()
             os.makedirs(os.path.dirname(icp), exist_ok=True)
             with open(icp, 'wb') as f:
                 f.write(pixmap_to_data(p, format='PNG'))
             self.set_library_icon()
     except Exception:
         import traceback
         traceback.print_exc()
Пример #8
0
 def change_icon(self):
     ci = self.plist.currentItem()
     if ci is None:
         return error_dialog(self, _('No selection'), _(
             'No application selected'), show=True)
     paths = choose_images(self, 'choose-new-icon-for-open-with-program', _(
         'Choose new icon'))
     if paths:
         ic = QIcon(paths[0])
         if ic.isNull():
             return error_dialog(self, _('Invalid icon'), _(
                 'Could not load image from %s') % paths[0], show=True)
         pmap = ic.pixmap(48, 48)
         if not pmap.isNull():
             entry = ci.data(ENTRY_ROLE)
             entry['icon_data'] = pixmap_to_data(pmap)
             ci.setData(ENTRY_ROLE, entry)
             self.update_stored_config()
             ci.setIcon(ic)
Пример #9
0
 def change_icon(self):
     ci = self.plist.currentItem()
     if ci is None:
         return error_dialog(self, _('No selection'), _(
             'No application selected'), show=True)
     paths = choose_images(self, 'choose-new-icon-for-open-with-program', _(
         'Choose new icon'))
     if paths:
         ic = QIcon(paths[0])
         if ic.isNull():
             return error_dialog(self, _('Invalid icon'), _(
                 'Could not load image from %s') % paths[0], show=True)
         pmap = ic.pixmap(48, 48)
         if not pmap.isNull():
             entry = ci.data(ENTRY_ROLE)
             entry['icon_data'] = pixmap_to_data(pmap)
             ci.setData(ENTRY_ROLE, entry)
             self.update_stored_config()
             ci.setIcon(ic)