Display login window along with main GUI window

Hi all,

I am creating a GUI which first launches a login window.Upon providing correct credentials the complete GUI window should appear.

At the initial launch, along with the login window ,the main GUI window should also appear behind the login window but it should be blank. No controls for the main GUI window should be visible.

After the user types username and password correctly, the main GUI window should display the complete GUI with all the controls.

I am attaching snippet of the code herewith.

In the main function, I am calling the main GUI class ( **MainFrame **) and in the init of the main GUI class I am calling the login window class ( **AP_LoginPanel **) .Inside a function ( OnSubmit ( ) ) in the login window class, I am checking if username and password are correct. If yes, then I need to launch the complete GUI window with all the controls.

Kindly tell me how to do it.

Thanks in advance,

Spondita

class MainFrame(wx.Frame):

def init(self, *args, **kw):

super(MainFrame, self).init(*args, **kw)

AP_LoginPanel()

self.Centre()

self.Show(True)

**def InitUI(self):**

	self.panel = wx.Panel(self)

	self.st = wx.StaticText(self.panel, label="Welcome")

	self.button = wx.Button(self.panel1,label="click")
···
	-----

class AP_LoginPanel(wx.Frame):

def init(self):

wx.Frame.init(self,None,style=wx.SYSTEM_MENU | wx.CAPTION |wx.CLOSE_BOX)

self.panel = wx.Panel(self,-1)

self.SetSize((400,250))

self.showLoginBox()

def showLoginBox (self):

infolabel = wx.StaticText(self.panel,label=“Please enter your credentials below to proceed”,pos=(60,40))

self.txt_Username = wx.TextCtrl(self.panel, 1, size=(150, -1))

lbl_Username = wx.StaticText(self.panel, -1, “Username:”)

self.txt_Password = wx.TextCtrl(self.panel, 1, size=(150, -1), style=wx.TE_PASSWORD)

lbl_Password = wx.StaticText(self.panel, -1, “Password:”)

btn_Process = wx.Button(self.panel, -1, “&Login”)

self.panel.Bind(wx.EVT_BUTTON, self.OnSubmit, btn_Process)

sizer.Add(btn_Process,0, wx.LEFT | wx.BOTTOM, 70)

self.panel.SetSizer(sizer)

def OnSubmit(self, event):

UserText = self.txt_Username.GetValue()

PasswordText = self.txt_Password.GetValue()

if UserText == self.username:

if PasswordText == self.password:

self.Destroy()

	      **## need to call the InitUI() method of the main GUI class MainFrame to display the **

** ## complete UI**

##obj = MainFrame(None)

##obj.InitUI()

def main():

ex =wx.App(0)

mainframe = MainFrame(None)

ex.MainLoop()

Just hide all the controls on the main GUI and then Show them if the user logs in correctly.

  • Mike
···

On Wednesday, June 13, 2012 5:09:21 AM UTC-5, Spondita wrote:

Hi all,
I am creating a GUI which first launches a login window.Upon providing correct credentials the complete GUI window should appear.

At the initial launch, along with the login window ,the main GUI window should also appear behind the login window but it should be blank. No controls for the main GUI window should be visible.

After the user types username and password correctly, the main GUI window should display the complete GUI with all the controls.

I am attaching snippet of the code herewith.

In the main function, I am calling the main GUI class ( **MainFrame **) and in the init of the main GUI class I am calling the login window class ( **AP_LoginPanel **) .Inside a function ( OnSubmit ( ) ) in the login window class, I am checking if username and password are correct. If yes, then I need to launch the complete GUI window with all the controls.

Kindly tell me how to do it.

Thanks in advance,

Spondita

You need to give yourself a path back to the instance of the MainFrame class from within the AP_LoginPanel class. In this case a very easy way to do that is to set the MainFrame as the parent of the AP_LoginPanel (by passing self to its constructor, and using that parameter for the parent arg when calling wx.Frame.__init__). Then in OnSubmit you can do something like self.GetParent().OnInit()

···

On 6/13/12 3:09 AM, Spondita wrote:

Hi all,
I am creating a GUI which first launches a login window.Upon providing
correct credentials the complete GUI window should appear.

At the initial launch, along with the login window ,the main GUI window
should also appear behind the login window but it should be blank. No
controls for the main GUI window should be visible.
After the user types username and password correctly, the main GUI
window should display the complete GUI with all the controls.

I am attaching snippet of the code herewith.

In the main function, I am calling the main GUI class ( *MainFrame *)
and in the init of the main GUI class I am calling the login window
class ( *AP_LoginPanel *) .Inside a function ( *OnSubmit ( )* ) in the
login window class, I am checking if username and password are correct.
If yes, then I need to launch the complete GUI window with all the controls.
Kindly tell me how to do it.

--
Robin Dunn
Software Craftsman

Hi Robin,

As you suggested, I made the MainFrame class as the parent for the AP_LoginPanel class, but when I printed theself.GetParent( ) it showed as None. Hence in the OnSubmit( ) method, making this call self.GetParent( ).InitUI( ) gives an error saying

** AttributeError: ‘NoneType’ object has no attribute ‘InitUI’**

I have modified the AP_LoginPanel class as follows:

class AP_LoginPanel ( MainFrame ):

def init(self):

**wx.Frame.init(self,None,style=wx.SYSTEM_MENU | wx.CAPTION | **

wx.CLOSE_BOX)

self.panel = wx.Panel(self,-1)

self.showLoginBox()

print self.GetParent()

Can you please tell me where am I missing out on?

Thanks in advance

···

On Wed, Jun 13, 2012 at 11:09 PM, Robin Dunn robin@alldunn.com wrote:

On 6/13/12 3:09 AM, Spondita wrote:

Hi all,

I am creating a GUI which first launches a login window.Upon providing

correct credentials the complete GUI window should appear.

At the initial launch, along with the login window ,the main GUI window

should also appear behind the login window but it should be blank. No

controls for the main GUI window should be visible.

After the user types username and password correctly, the main GUI

window should display the complete GUI with all the controls.

I am attaching snippet of the code herewith.

In the main function, I am calling the main GUI class ( *MainFrame *)

and in the init of the main GUI class I am calling the login window

class ( *AP_LoginPanel *) .Inside a function ( OnSubmit ( ) ) in the

login window class, I am checking if username and password are correct.

If yes, then I need to launch the complete GUI window with all the controls.

Kindly tell me how to do it.

You need to give yourself a path back to the instance of the MainFrame class from within the AP_LoginPanel class. In this case a very easy way to do that is to set the MainFrame as the parent of the AP_LoginPanel (by passing self to its constructor, and using that parameter for the parent arg when calling wx.Frame.init). Then in OnSubmit you can do something like self.GetParent().OnInit()

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

You made AP_LoginPanel a class that is derived from the MainFrame class.

What I said was to use the instance of the MainFrame class as the parent window for the instance the AP_LoginPanel class that you create. In other words, change AP_LoginPanel.__init__ to take a parent parameter, pass that value to wx.Frame.__init__, and when you create the instance of AP_LoginPanel in the MainFrame.__init__ pass self to it for the parent parameter.

···

On 6/13/12 10:56 PM, Spondita Neog wrote:

Hi Robin,

As you suggested, I made the *MainFrame* class as the parent for the
*AP_LoginPanel* class, but when I printed the*self.GetParent( )* it
showed as None. Hence in the *OnSubmit( )* method, making this call
*self.GetParent( ).InitUI( )* gives an error saying

*AttributeError: 'NoneType' object has no attribute 'InitUI'*

I have modified the *AP_LoginPanel *class as follows:

*class AP_LoginPanel ( MainFrame ):*
* def __init__(self):*
* wx.Frame.__init__(self,None,style=wx.SYSTEM_MENU | wx.CAPTION | *
* wx.CLOSE_BOX)*
* self.panel = wx.Panel(self,-1)*
* self.showLoginBox()*
* print self.GetParent()*

Can you please tell me where am I missing out on?

--
Robin Dunn
Software Craftsman

Spondita Neog wrote:

Hi Robin,

As you suggested, I made the MainFrame
class as the parent for the AP_LoginPanel class, but when I printed theself.GetParent( ) it showed as
None. Hence in the OnSubmit( )
method, making this call ** self.GetParent(
).InitUI( )** gives an error saying

** AttributeError: ‘NoneType’
object has no attribute ‘InitUI’**

I have modified the **AP_LoginPanel
** class as follows:

class AP_LoginPanel ( MainFrame ):

def init(self):

** wx.Frame.init(self,None,style=wx.SYSTEM_MENU

wx.CAPTION | **

wx.CLOSE_BOX)

self.panel = wx.Panel(self,-1)

self.showLoginBox()

print self.GetParent()

Can you please tell me where am I missing out on?

That's does NOT do what you meant to do.  You don't want the

AP_LoginPanel class to derive from the MainFrame class. Instead,
both of them should derive from wx.Frame.

What you need to do is make one specific instance of MainFrame be

the parent of one specific instance of AP_LoginPanel. To do that,
you will have to pass the parent MainFrame to the constructor when
you create the AP_LoginPanel. That is exactly what the second
parameter to wx.Frame.init is for. Right now, you are passing
“None” as the parent.

So:

    class AP_LoginPanel( wx.Frame ):

        def __init__(self,parent):

            wx.Frame.__init__(self,parent,style=... )

Then, if you create the AP_LoginPanel from within the MainFrame,

pass the frame’s object to the constructor:

            panel = AP_LoginPanel( self )
···
-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

Thanks a lot Robin and Tim.

Its working now. I misinterpreted setting the parent parameter to be inheritance.

Regards,

Spondita

···

On Fri, Jun 15, 2012 at 1:03 AM, Tim Roberts timr@probo.com wrote:

Spondita Neog wrote:

Hi Robin,

As you suggested, I made the MainFrame
class as the parent for the AP_LoginPanel class, but when I printed theself.GetParent( ) it showed as
None. Hence in the OnSubmit( )
method, making this call ** self.GetParent(
).InitUI( )** gives an error saying

** AttributeError: ‘NoneType’
object has no attribute ‘InitUI’**

I have modified the **AP_LoginPanel
** class as follows:

class AP_LoginPanel ( MainFrame ):

def init(self):

** wx.Frame.init(self,None,style=wx.SYSTEM_MENU

wx.CAPTION | **

wx.CLOSE_BOX)

self.panel = wx.Panel(self,-1)

self.showLoginBox()

print self.GetParent()

Can you please tell me where am I missing out on?

-- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
That's does NOT do what you meant to do.  You don't want the

AP_LoginPanel class to derive from the MainFrame class. Instead,
both of them should derive from wx.Frame.

What you need to do is make one specific instance of MainFrame be

the parent of one specific instance of AP_LoginPanel. To do that,
you will have to pass the parent MainFrame to the constructor when
you create the AP_LoginPanel. That is exactly what the second
parameter to wx.Frame.init is for. Right now, you are passing
“None” as the parent.

So:

    class AP_LoginPanel( wx.Frame ):

        def __init__(self,parent):

            wx.Frame.__init__(self,parent,style=... )

Then, if you create the AP_LoginPanel from within the MainFrame,

pass the frame’s object to the constructor:

            panel = AP_LoginPanel( self )

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en