[Sync] Sync with trunk. Revision 7231

This commit is contained in:
Li Fanxi 2010-12-16 00:45:44 +08:00
commit c46a9c1926
3 changed files with 42 additions and 8 deletions

View File

@ -80,6 +80,34 @@ class Plugin(object): # {{{
'''
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):
'''
Return a string giving help on how to customize this plugin.

View File

@ -109,7 +109,7 @@ class InterfaceAction(QObject):
setattr(self, attr, 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
will allow you to load resources from the ZIP file.
@ -117,20 +117,24 @@ class InterfaceAction(QObject):
For example to load an image::
pixmap = QPixmap()
pixmap.loadFromData(self.load_resource('images/icon.png'))
pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues().next())
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:
raise ValueError('This plugin was not loaded from a ZIP file')
ans = {}
with ZipFile(self.plugin_path, 'r') as zf:
for candidate in zf.namelist():
if candidate == name:
return zf.read(name)
raise ValueError('The name %r was not found in the plugin zip'
' file'%name)
if candidate in names:
ans[candidate] = zf.read(candidate)
return ans
def genesis(self):

View File

@ -166,7 +166,9 @@ class DeviceManager(Thread): # {{{
report_progress=self.report_progress)
dev.open()
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
except:
tb = traceback.format_exc()