Hi,
>
> I would like to be able to use the Editor within my wxPython
> application, i.e. open a wx.Frame which contains the editor.
>
> I don't think this is possible the way things are structured at the
> moment, am I correct or am I missing something?
>
> If above is correct, what about moving all the non wx methods from
> EditorApplication to EditorForm? So, EditorApplication would be used in
> "stand alone" mode and EditorForm would be used if one wants to use it
> from within another wxPython application.
>
EditorApplication is used as global environment for now, because of
1) All editor elements are not completely independent one from each
other according editor's logic. However, in my opinion they shouldn't
be linked directly between modules, because of it makes code
unreadable and hardly debuggable. EditorApplication is such bridge,
that knows about any editor part and control them.
2) Such bridge must be accessible from any part of editor, so the best
way to do this is to use wx mechanism for such global things - wx.App
and wx.GetApp().
EditorForm isn't accessible from any part of editor. And I don't think
we should pass it to all modules. I see two variants to solve your
problem:
1) You can try to inherit your wx.App class from EditorApplication and
override __init__ and OnInit methods, according your needs.
2) More clear way. Split EditorApplication to two classes.
EditorEnvironment(object):
def _init_(self, frame):
self.frame = frame
self.last_focus = None
self.last_directory = None
..... #all methods from EditorApplication except __init__ and OnInit
EditorApplication(wx.App):
def __init__(self):
wx.App.__init__(self, *args, **kwargs)
#disable logs to prevent automatic error windows
wx.Log.EnableLogging(False)
def OnInit(self):
self.env = EditorEnvironment(EditorForm(None))
self.SetTopWindow(self.env.frame)
self.env.frame.Show()
self.env.frame.Maximize(True)
return True
@property
def editor_env(self):
return self.env
And then fix all calls of wx.GetApp().something to
wx.GetApp().editor_env.something in editor.
Then you can create EditorEnvironment in your application where you
want, and then just put such property in your app
@property
def editor_env(self):
return my_created_environment
However, both solutions won't work, if you want to be able to create
many forms of an editor. Anyway, EditorForm, and EditorEnvironment are
different things that perform different tasks. We souldn't mix them.
Den
|