class _Dialog(Dialog): _title = property(lambda self: utils.name_from_class(self, drop='Dialog')) def __init__(self, controller, item=None, plugin=None): # TODO: Get rid of item, everything should be in controller Dialog.__init__(self, self._title) # set Left to Right direction (while we don't have localization) self.SetLayoutDirection(wx.Layout_LeftToRight) self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY) self._controller = controller self.plugin = plugin self._sizer = wx.BoxSizer(wx.VERTICAL) self._editors = self._get_editors(item) for editor in self._editors: self._sizer.Add(editor, editor.expand_factor, wx.EXPAND) self._add_comment_editor(item) self._create_help() self._create_line() self._create_buttons() self.SetSizer(self._sizer) self._sizer.Fit(self) self._editors[0].set_focus() def _add_comment_editor(self, item): comment = ListToStringFormatter(item.comment).value if item else '' self._comment_editor = ValueEditor(self, comment, 'Comment') self._sizer.Add(self._comment_editor) def _create_line(self): line = wx.StaticLine(self, size=(20, -1), style=wx.LI_HORIZONTAL) if wx.VERSION < (4, 1, 0): self._sizer.Add( line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5) else: self._sizer.Add(line, 0, wx.GROW | wx.RIGHT | wx.TOP, 5) def _create_help(self): self._sizer.Add(HelpLabel(self, label=get_help(self._title)), flag=wx.ALL, border=2) def _create_buttons(self, **kwargs): buttons = self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL) self._sizer.Add(buttons, 0, wx.ALIGN_CENTER | wx.ALL, 5) def get_value(self): return [e.get_value() for e in self._editors] def get_comment(self): return self._comment_editor.get_value() def setFocusToOK(self): self.FindWindowById(wx.ID_OK).SetFocus() def _execute(self): pass
def __init__(self, application, name=None, doc=None, metadata=None, default_settings=None, initially_enabled=True): """Initialize the plugin with the provided data. The provided information is mainly used by the plugin manager. Simple plugins are often fine with the defaults. If this method is overridden, the plugin must call it explicitly:: from robotide.pluginapi import Plugin class MyCoolPluginExample(Plugin): \"\"\"This extra cool docstring is used as the plugin doc.\"\"\" def __init__(self, application): Plugin.__init__(self, application, metadata={'version': '0.1'}, default_settings={'color': 'red', 'x': 42}) Plugins should not create any user interface elements at this point but wait until the `enable` method is called. :Parameters: application RIDE application reference. name Name of the plugin. If not specified, the name is got from the plugin class name dropping possible ``Plugin`` from the end. doc Plugin documentation. If not specified, the doc is got from the plugin class docstring. metadata A dictionary of free metadata shown on the plugin manager. Values containing URLs will be shown as links. default_settings A dictionary of settings and their default values. Settings are automatically stored onto RIDE configuration file, can be accessed using direct attribute access via `__getattr__`, and new settings can be saved using `save_setting`. initially_enabled Specifies should the plugin be enabled when loaded for the first time. Users can change the status later from the plugin manager. """ self.name = name or utils.name_from_class(self, drop='Plugin') self.doc = self._get_doc(doc) self.metadata = metadata or {} self.initially_enabled = initially_enabled self._save_timer = None self.__app = application self.__frame = application.frame self.__namespace = application.namespace self.__settings = application.settings['Plugins'].add_section( self.name) self.__settings.set_defaults(default_settings) self.__actions = []
def __init__(self, application, name=None, doc=None, metadata=None, default_settings=None, initially_enabled=True): """Initialize the plugin with the provided data. The provided information is mainly used by the plugin manager. Simple plugins are often fine with the defaults. If this method is overridden, the plugin must call it explicitly:: from robotide.pluginapi import Plugin class MyCoolPluginExample(Plugin): \"\"\"This extra cool docstring is used as the plugin doc.\"\"\" def __init__(self, application): Plugin.__init__(self, application, metadata={'version': '0.1'}, default_settings={'color': 'red', 'x': 42}) Plugins should not create any user interface elements at this point but wait until the `enable` method is called. :Parameters: application RIDE application reference. name Name of the plugin. If not specified, the name is got from the plugin class name dropping possible ``Plugin`` from the end. doc Plugin documentation. If not specified, the doc is got from the plugin class docstring. metadata A dictionary of free metadata shown on the plugin manager. Values containing URLs will be shown as links. default_settings A dictionary of settings and their default values. Settings are automatically stored onto RIDE configuration file, can be accessed using direct attribute access via `__getattr__`, and new settings can be saved using `save_setting`. initially_enabled Specifies should the plugin be enabled when loaded for the first time. Users can change the status later from the plugin manager. """ self.name = name or utils.name_from_class(self, drop='Plugin') self.doc = self._get_doc(doc) self.metadata = metadata or {} self.initially_enabled = initially_enabled self._save_timer = None self.__app = application self.__frame = application.frame self.__namespace = application.namespace self.__settings = application.settings['Plugins'].add_section(self.name) self.__settings.set_defaults(default_settings) self.__actions = []
class TestPluginLoader(unittest.TestCase): used_plugin_class = LogPlugin expected_plugins = [ 'Example Plugin 1', 'Example Plugin 2', 'Example Plugin 3', utils.name_from_class(used_plugin_class, drop='Plugin') ] def setUp(self): plugins_dir = [ os.path.join(os.path.dirname(__file__), 'plugins_for_loader') ] app = FakeApplication() self.loader = PluginLoader(app, plugins_dir, [self.used_plugin_class]) app.get_plugins = lambda: self.loader.plugins def tearDown(self): for p in self.loader.plugins: p.disable() def test_plugin_loading(self): for name in self.expected_plugins: self._assert_plugin_loaded(name) assert_false(LOGGER.log) def _assert_plugin_loaded(self, name): for p in self.loader.plugins: if p.name == name: return raise AssertionError("Plugin '%s' not loaded" % name) def test_plugins_are_not_enabled_when_loaded(self): for p in self.loader.plugins: assert_false(p.enabled) def test_plugins_can_be_enabled(self): self.loader.enable_plugins() for p in self.loader.plugins: assert_true(p.enabled, 'Plugin %s was not enabled' % p.name) def test_plugins_can_disable_other_plugins(self): self.loader.enable_plugins() self._get_plugin_by_name('Example Plugin 2')._plugin.turn_off( 'Example Plugin 1') assert_false(self._get_plugin_by_name('Example Plugin 1').enabled) def _get_plugin_by_name(self, name): for p in self.loader.plugins: if p.name == name: return p return None
def __init__(self, error_msg, traceback, plugin_class): name = utils.name_from_class(plugin_class, 'Plugin') doc = 'This plugin is disabled because it failed to load properly.\n' \ + 'Error: ' + error_msg + '\n' + traceback _PluginConnector.__init__(self, name, doc=doc, error=error_msg) LOG.error("Taking %s plugin into use failed:\n%s" % (name, error_msg))
def __init__(self, error, plugin_class): name = utils.name_from_class(plugin_class, 'Plugin') doc = 'This plugin is disabled because it failed to load properly.\n' \ + 'Error: ' + error _PluginConnector.__init__(self, name, doc=doc, error=error) LOG.error("Taking %s plugin into use failed:\n%s" % (name, error))