I want to know how to organize the files holding the my wx.App-derived
application class and my wx.Frame-derived MainWindow-GUI class.
My app-class does create an instance of the main window in its OnInit()
and manage the loading and storing of the config-file-object.
And because it is the application it hold informations about the
version and things like that.
So the MainWindow ask the app object for the version string to display
it. It is just an example of a lot of other cases. So please don't
focus on the version string.
That is why the MainWindow need to know the App-Object. And the App
need to know the MainWindow to create an instance of it and call Show().
That causes recursive import problems.
And currently I ran into a horrible misstake about it. The file with
the App in it is imported too times which is no problem. But global
object instances (for example the Config-object) are overridden because
of that.
So I see I have to reorganize the current situation. But how?
Where do you "store" your App and MainWindow class?
How do they know each other?
Are you interested in my recursive import. This is pseudo-code
[APP-file]
from GUI-file import MainWindow
class Config:
pass
c = Config()
class App:
def OnInit(self):
self.LoadConfigFromFile()
MainWindow().Show()
return True
if __name__ == '__main__':
App().MainLoop()
[/APP-file]
[GUI-file]
# NO import of the APP-file here!
class MainWindow:
def DoSomething(self):
# access the module-global-config object
App.config.DoSomething()
# HERE come the import
import App
#...
[/GUI-file]
Put your config into an extra module, like so:
[configmodule]
class _config(object):
def __init__(self):
pass
config=_config()
and then import in your other modules:
from configmodule import config
Works for me. Void where prohibited ...
Michael
···
On Sun, 22 Feb 2015 19:03:37 +0100, <moonkid@posteo.org> wrote:
I want to know how to organize the files holding the my wx.App-derived
application class and my wx.Frame-derived MainWindow-GUI class.
My app-class does create an instance of the main window in its OnInit()
and manage the loading and storing of the config-file-object.
And because it is the application it hold informations about the
version and things like that.
So the MainWindow ask the app object for the version string to display
it. It is just an example of a lot of other cases. So please don't
focus on the version string.
That is why the MainWindow need to know the App-Object. And the App
need to know the MainWindow to create an instance of it and call Show().
That causes recursive import problems.
And currently I ran into a horrible misstake about it. The file with
the App in it is imported too times which is no problem. But global
object instances (for example the Config-object) are overridden because
of that.
So I see I have to reorganize the current situation. But how?
def DoSomething(self):
# access the module-global-config object
wx.GetApp().config.DoSomething()
# or more robustly
app = wx.GetApp()
if app and hasattr(app, 'config.DoSomething') and callable(app.config.DoSomething):
result = app.config.DoSomething()
[\mainframe.py]
···
On Sun, Feb 22, 2015 at 1:59 PM, Michael Ross gmx@ross.cx wrote:
I want to know how to organize the files holding the my wx.App-derived
application class and my wx.Frame-derived MainWindow-GUI class.
My app-class does create an instance of the main window in its OnInit()
and manage the loading and storing of the config-file-object.
And because it is the application it hold informations about the
version and things like that.
So the MainWindow ask the app object for the version string to display
it. It is just an example of a lot of other cases. So please don’t
focus on the version string.
That is why the MainWindow need to know the App-Object. And the App
need to know the MainWindow to create an instance of it and call Show().
That causes recursive import problems.
And currently I ran into a horrible misstake about it. The file with
the App in it is imported too times which is no problem. But global
object instances (for example the Config-object) are overridden because
of that.
So I see I have to reorganize the current situation. But how?
On Sun, 22 Feb 2015 19:03:37 +0100, moonkid@posteo.org wrote:
Try this:
Put your config into an extra module, like so:
[configmodule]
class _config(object):
def __init__(self):
pass
config=_config()
and then import in your other modules:
from configmodule import config
Works for me. Void where prohibited …
Michael
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
I for one don’t use an App class. I just create an app instance in my main function. Then you instantiate your main window and show it, start your app main loop – but App doesn’t need to know about the top level window.
And any code that needs to access the app, I use wx.GetApp()
···
On Sunday, February 22, 2015 at 10:04:37 AM UTC-8, moo...@posteo.org wrote:
I want to know how to organize the files holding the my wx.App-derived
application class and my wx.Frame-derived MainWindow-GUI class.
My app-class does create an instance of the main window in its OnInit()
and manage the loading and storing of the config-file-object.
And because it is the application it hold informations about the
version and things like that.
So the MainWindow ask the app object for the version string to display
it. It is just an example of a lot of other cases. So please don’t
focus on the version string.
That is why the MainWindow need to know the App-Object. And the App
need to know the MainWindow to create an instance of it and call Show().
That causes recursive import problems.
And currently I ran into a horrible misstake about it. The file with
the App in it is imported too times which is no problem. But global
object instances (for example the Config-object) are overridden because
of that.
So I see I have to reorganize the current situation. But how?
Where do you “store” your App and MainWindow class?
How do they know each other?
Are you interested in my recursive import. This is pseudo-code