Is there any reason for this or am I doing something wrong?
The moment I put a class that inherits eg.PluginClass or something similar in a different file it breaks eventghost completely. The downside of this is that it's quite hard to create a single reusable base class for plugins which makes handling a bit easier. I've currently written this snippet which allows me to test locally as well but I have to keep it within the __init__.py for it to work right now:
Code: Select all
from __future__ import print_function
import wx
import abc
import sys
try:
TESTING = False
import eg
_Panel = eg.ConfigPanel
try:
_Plugin = eg.PluginClass
except ImportError:
_Plugin = object
try:
_Action = eg.ActionBase
except ImportError:
_Action = object
print_error = eg.PrintError
except ImportError:
TESTING = True
_Panel = wx.Dialog
_Plugin = object
_Action = object
def print_error(message):
print(message, file=sys.stderr)
class Panel(_Panel):
if TESTING:
def __init__(self, executable=None, resizable=True, showLine=True):
_Panel.__init__(self, None, wx.ID_ANY,
'%s Test' % self.__class__.__name__,
style=wx.DEFAULT_DIALOG_STYLE | wx.THICK_FRAME
| wx.RESIZE_BORDER | wx.TAB_TRAVERSAL)
main_sizer = wx.BoxSizer(wx.VERTICAL)
button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL)
self.sizer = wx.BoxSizer()
self.SetSizer(main_sizer)
main_sizer.Add(self.sizer, 1, wx.EXPAND)
main_sizer.Add(button_sizer, 0, wx.ALIGN_CENTER | wx.BOTTOM)
def Affirmed(self):
self.resultCode = self.ShowModal()
if self.resultCode == wx.ID_CANCEL:
return
return self.resultCode
def SetResult(self, *args):
import pprint
print('Set results to:')
pprint.pprint(args)
class Base(object):
__metaclass__ = abc.ABCMeta
def __init__(self, *args, **kwargs):
self.sizer = wx.FlexGridSizer(0, 2)
self.sizer.AddGrowableCol(1)
self.widgets = dict()
def add_field(self, label, key=None, widget=wx.TextCtrl, **kwargs):
key = key or label
self.widgets['label_%s' % key] = wx.StaticText(self.panel, wx.ID_ANY, label)
self.widgets[key] = widget(self.panel, wx.ID_ANY, self.config.get(key, ''), **kwargs)
self.sizer.Add(self.widgets['label_%s' % key], flag=wx.EXPAND)
self.sizer.Add(self.widgets[key], proportion=1, flag=wx.CENTER | wx.EXPAND)
return self.widgets[key]
def Configure(self, config=None, *args):
self.panel = Panel()
self.config = config or {}
return self.panel, self.config
class Action(Base, _Action):
@abc.abstractmethod
def __call__(self):
raise NotImplementedError()
class Plugin(Base, _Plugin):
def __start__(self, *args, **kwargs):
pass
def __stop__(self):
pass
def __close__(self):
pass
if __name__ == '__main__':
app = wx.App()
plugin = YourPlugin()
plugin.Configure()