Rich, I don't know any examples offhand, but you might have success
Googling around for it, but I sort of doubt you will, but who knows.
That said, possibly what Nathan was suggesting, and something that seems
reasonable to me, though you should test it to see this works, is this:
1. Start the main frame (MainFrame) as the top level app, but don't yet
call .Show() on it. It now exists, but is not shown
2. In the MainFrame's __init__ method you would call the LoginDialog and
show it modally. When you do that, you will should pass in "self" as the
parent for the LoginDialog; this will mean parent = MainFrame in the
LoginDialog.
3. You can also make a class-wide reference to the MainFrame within
LoginDialog's init method by doing:
self.mainFrame = parent
And now you can refer to the MainFrame from any method within LoginDialog.
(that is just one way to do this. You could also use .GetTopLevelWindow(),
or GetParent(), etc.)
At this point the user should just see the LoginDialog shown (modally)..
4. On the LoginDialog's OK handler, if the password/etc are correct, then
you can call self.mainFrame.Show(), and then, voila, the MainFrame will be
visible. You can then also Destroy() the dialog.
The basic idea here, to refresh you memory, is that windows on screen often
need to refer to or affect other windows on screen, but if they are in
different classes there needs to be some way to do that, to "refer to" each
other. Ways I've seen are:
1. Pass in "self" as an argument such as suggested above, when creating a
new instance of a window.
2. Go right to the top: use .GetParent() or wx.GetTopLevelParent() or
maybe GetApp()
3. Use the PubSub module to "broadcast" messages into the air for other
objects to "listen for".
I get the sense that (3) is the most decoupled and therefore most correct,
good coding practices-wise, but I often find it easier to use something
more like (1) or (2), though you don't want to ever get into anything that
looks like:
target_object = self.GetParent().GetParent().GetParent().GetParent()
(though I may have a few almost that bad in some of my code, but it's not
good).
Che
···
On Thu, Jul 10, 2014 at 7:26 PM, Rich Shepard <rshepard@appl-ecosys.com> wrote:
On Thu, 10 Jul 2014, Nathan McCorkle wrote:
Either provide a callback function to LoginDialog that will be run on
successful user/password entry... or pass a MainFrame object (that hasn't
been shown) to LoginDialog init... then save that as a class variable, and
call Show on that class variable in the Login method in login.py
Nathan/Che:
Previous applications I wrote with wxPython did not require user access
control; the main frames were wx.Notebooks and each tab was imported from
an
external module.
So, adding the access control dialog is a learning experience for me.
I've
been looking for examples but have not found any. The demo, Main.py, is
great; I'm learning a lot from it. But, it does not provide me with an
example of how to invoke the application with a login dialog which then
opens the MainFrame upon success. (The login 'OK' method is empty now and
will have the access control code added after I get the display working
correctly.)
Pointers to code examples would be much appreciated.