Add user interface for removing custom plugins

This commit is contained in:
Kovid Goyal 2008-12-29 13:58:05 -08:00
parent 6551ac8b89
commit 9ecb530b7d
4 changed files with 39 additions and 3 deletions

View File

@ -185,6 +185,20 @@ def add_plugin(path_to_zip_file):
initialize_plugins() initialize_plugins()
return plugin return plugin
def remove_plugin(plugin_or_name):
name = getattr(plugin_or_name, 'name', plugin_or_name)
plugins = config['plugins']
removed = False
if name in plugins.keys():
removed = True
zfp = plugins[name]
if os.path.exists(zfp):
os.remove(zfp)
plugins.pop(name)
config['plugins'] = plugins
initialize_plugins()
return removed
def is_disabled(plugin): def is_disabled(plugin):
return plugin.name in config['disabled_plugins'] return plugin.name in config['disabled_plugins']
@ -237,6 +251,8 @@ def option_parser():
''')) '''))
parser.add_option('-a', '--add-plugin', default=None, parser.add_option('-a', '--add-plugin', default=None,
help=_('Add a plugin by specifying the path to the zip file containing it.')) help=_('Add a plugin by specifying the path to the zip file containing it.'))
parser.add_option('-r', '--remove-plugin', default=None,
help=_('Remove a custom plugin by name. Has no effect on builtin plugins'))
parser.add_option('--customize-plugin', default=None, parser.add_option('--customize-plugin', default=None,
help=_('Customize plugin. Specify name of plugin and customization string separated by a comma.')) help=_('Customize plugin. Specify name of plugin and customization string separated by a comma.'))
parser.add_option('-l', '--list-plugins', default=False, action='store_true', parser.add_option('-l', '--list-plugins', default=False, action='store_true',
@ -267,6 +283,11 @@ def main(args=sys.argv):
if opts.add_plugin is not None: if opts.add_plugin is not None:
plugin = add_plugin(opts.add_plugin) plugin = add_plugin(opts.add_plugin)
print 'Plugin added:', plugin.name, plugin.version print 'Plugin added:', plugin.name, plugin.version
if opts.remove_plugin is not None:
if remove_plugin(opts.remove_plugin):
print 'Plugin removed'
else:
print 'No custom pluginnamed', opts.remove_plugin
if opts.customize_plugin is not None: if opts.customize_plugin is not None:
name, custom = opts.customize_plugin.split(',') name, custom = opts.customize_plugin.split(',')
plugin = find_plugin(name.strip()) plugin = find_plugin(name.strip())

View File

@ -20,7 +20,7 @@ from calibre.ebooks.epub.iterator import is_supported
from calibre.library import server_config from calibre.library import server_config
from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \ from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \
disable_plugin, customize_plugin, \ disable_plugin, customize_plugin, \
plugin_customization, add_plugin plugin_customization, add_plugin, remove_plugin
class PluginModel(QAbstractItemModel): class PluginModel(QAbstractItemModel):
@ -242,6 +242,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
self.plugin_view.setModel(self._plugin_model) self.plugin_view.setModel(self._plugin_model)
self.connect(self.toggle_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='toggle')) self.connect(self.toggle_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='toggle'))
self.connect(self.customize_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='customize')) self.connect(self.customize_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='customize'))
self.connect(self.remove_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='remove'))
self.connect(self.button_plugin_browse, SIGNAL('clicked()'), self.find_plugin) self.connect(self.button_plugin_browse, SIGNAL('clicked()'), self.find_plugin)
self.connect(self.button_plugin_add, SIGNAL('clicked()'), self.add_plugin) self.connect(self.button_plugin_add, SIGNAL('clicked()'), self.add_plugin)
@ -287,6 +288,13 @@ class ConfigDialog(QDialog, Ui_Dialog):
if ok: if ok:
customize_plugin(plugin, unicode(text)) customize_plugin(plugin, unicode(text))
self._plugin_model.refresh_plugin(plugin) self._plugin_model.refresh_plugin(plugin)
if op == 'remove':
if remove_plugin(plugin):
self._plugin_model.populate()
self._plugin_model.reset()
else:
error_dialog(self, _('Cannot remove builtin plugin'),
plugin.name + _(' cannot be removed. It is a builtin plugin. Try disabling it instead.')).exec_()
def up_column(self): def up_column(self):

View File

@ -72,7 +72,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex" > <property name="currentIndex" >
<number>0</number> <number>4</number>
</property> </property>
<widget class="QWidget" name="page_3" > <widget class="QWidget" name="page_3" >
<layout class="QVBoxLayout" name="verticalLayout" > <layout class="QVBoxLayout" name="verticalLayout" >
@ -811,6 +811,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="remove_plugin" >
<property name="text" >
<string>&amp;Remove plugin</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View File

@ -199,7 +199,7 @@ class Server(object):
x = list(range(days-1, -1, -1)) x = list(range(days-1, -1, -1))
y = stats.daily_totals y = stats.daily_totals
ax.plot(x, y)#, align='center', width=20, color='g') ax.plot(x, y)#, align='center', width=20, color='g')
ax.set_xlabel('Day') ax.set_xlabel('Days ago')
ax.set_ylabel('Income ($)') ax.set_ylabel('Income ($)')
ax.hlines([stats.daily_average], 0, days-1) ax.hlines([stats.daily_average], 0, days-1)
ax.set_xlim([0, days-1]) ax.set_xlim([0, days-1])