mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
[Sync] Sync with trunk. Revision 7231
This commit is contained in:
commit
c46a9c1926
@ -80,6 +80,34 @@ class Plugin(object): # {{{
|
|||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def load_resources(self, names):
|
||||||
|
'''
|
||||||
|
If this plugin comes in a ZIP file (user added plugin), this method
|
||||||
|
will allow you to load resources from the ZIP file.
|
||||||
|
|
||||||
|
For example to load an image::
|
||||||
|
|
||||||
|
pixmap = QPixmap()
|
||||||
|
pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues().next())
|
||||||
|
icon = QIcon(pixmap)
|
||||||
|
|
||||||
|
:param names: List of paths to resources in the zip file using / as separator
|
||||||
|
|
||||||
|
:return: A dictionary of the form ``{name : file_contents}``. Any names
|
||||||
|
that were not found in the zip file will not be present in the
|
||||||
|
dictionary.
|
||||||
|
|
||||||
|
'''
|
||||||
|
if self.plugin_path is None:
|
||||||
|
raise ValueError('This plugin was not loaded from a ZIP file')
|
||||||
|
ans = {}
|
||||||
|
with zipfile.ZipFile(self.plugin_path, 'r') as zf:
|
||||||
|
for candidate in zf.namelist():
|
||||||
|
if candidate in names:
|
||||||
|
ans[candidate] = zf.read(candidate)
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def customization_help(self, gui=False):
|
def customization_help(self, gui=False):
|
||||||
'''
|
'''
|
||||||
Return a string giving help on how to customize this plugin.
|
Return a string giving help on how to customize this plugin.
|
||||||
|
@ -109,7 +109,7 @@ class InterfaceAction(QObject):
|
|||||||
setattr(self, attr, action)
|
setattr(self, attr, action)
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def load_resource(self, name):
|
def load_resources(self, names):
|
||||||
'''
|
'''
|
||||||
If this plugin comes in a ZIP file (user added plugin), this method
|
If this plugin comes in a ZIP file (user added plugin), this method
|
||||||
will allow you to load resources from the ZIP file.
|
will allow you to load resources from the ZIP file.
|
||||||
@ -117,20 +117,24 @@ class InterfaceAction(QObject):
|
|||||||
For example to load an image::
|
For example to load an image::
|
||||||
|
|
||||||
pixmap = QPixmap()
|
pixmap = QPixmap()
|
||||||
pixmap.loadFromData(self.load_resource('images/icon.png'))
|
pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues().next())
|
||||||
icon = QIcon(pixmap)
|
icon = QIcon(pixmap)
|
||||||
|
|
||||||
:param name: Path to resource in zip file using / as separator
|
:param names: List of paths to resources in the zip file using / as separator
|
||||||
|
|
||||||
|
:return: A dictionary of the form ``{name : file_contents}``. Any names
|
||||||
|
that were not found in the zip file will not be present in the
|
||||||
|
dictionary.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if self.plugin_path is None:
|
if self.plugin_path is None:
|
||||||
raise ValueError('This plugin was not loaded from a ZIP file')
|
raise ValueError('This plugin was not loaded from a ZIP file')
|
||||||
|
ans = {}
|
||||||
with ZipFile(self.plugin_path, 'r') as zf:
|
with ZipFile(self.plugin_path, 'r') as zf:
|
||||||
for candidate in zf.namelist():
|
for candidate in zf.namelist():
|
||||||
if candidate == name:
|
if candidate in names:
|
||||||
return zf.read(name)
|
ans[candidate] = zf.read(candidate)
|
||||||
raise ValueError('The name %r was not found in the plugin zip'
|
return ans
|
||||||
' file'%name)
|
|
||||||
|
|
||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
|
@ -166,7 +166,9 @@ class DeviceManager(Thread): # {{{
|
|||||||
report_progress=self.report_progress)
|
report_progress=self.report_progress)
|
||||||
dev.open()
|
dev.open()
|
||||||
except OpenFeedback, e:
|
except OpenFeedback, e:
|
||||||
self.open_feedback_msg(dev.get_gui_name(), e.feedback_msg)
|
if dev not in self.ejected_devices:
|
||||||
|
self.open_feedback_msg(dev.get_gui_name(), e.feedback_msg)
|
||||||
|
self.ejected_devices.add(dev)
|
||||||
continue
|
continue
|
||||||
except:
|
except:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user