Hello, Ive been learning Python now for approx 7 weeks and have run
into a problem.
What I am trying to do is design a GUI that allows a user to log in,
be authenticated over a server, and then have a panel change depending
on who logs in.
The basis of my code is from this example, and it works:
http://www.blog.pythonlibrary.org/2010/06/16/wxpython-how-to-switch-between-panels/
I can then modify it to accept user login, and it continues to work.
When I introduce the twisted part though it ceases to work.
Due to the Asynchronous communications I have to stop the code from
running, and then try to pick it up again once the authentication
comes back. I have preloaded all of the username and passwords into
the code (Not in the final version) to save the user having to keep
typing it.
print wx.version() returns 2.8.11.0 (msw-unicode)
When I press login in this version of the code it swaps panels
perfectly.
[code]
import wx
print wx.version()
class LoginDialog(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(180, 210))
LoginPanel = wx.Panel(self, -1)
LoginVerSizer = wx.BoxSizer(wx.VERTICAL)
wx.StaticBox(LoginPanel, -1, 'User Name', (5, 5), (160, 50))
LoginDialog.Login = wx.TextCtrl(LoginPanel, -1, 'Admin', (15,
25), (140, -1))
wx.StaticBox(LoginPanel, -1, 'Password', (5, 65), (160, 50))
LoginDialog.Password = wx.TextCtrl(LoginPanel, -1, 'Support',
(15, 85), (140, -1), style=wx.TE_PASSWORD)
LoginButton = wx.Button(self, -1, 'Login', size=(70, 30))
self.Bind(wx.EVT_BUTTON, self.Button_Login(self), LoginButton)
LoginVerSizer.Add(LoginPanel)
LoginVerSizer.Add(LoginButton)
self.SetSizer(LoginVerSizer)
···
###############################################
def Button_Login(self, event):
Login_Auth = 'Admin'
Password_Auth = 'Support'
Login = self.Login.GetValue()
Password = self.Password.GetValue()
if Login == Login_Auth:
Login_True = 1
if Password == Password_Auth:
Password_True = 1
if Login_True == 1 & Password_True == 1:
Dialog = wx.MessageDialog(None, 'Successful')
MainFrame.SwitchPanel = 'Panel_Two'
self.Destroy()
else:
Dialog = wx.MessageDialog(None, 'Unknown Error Has
Occurred')
Dialog.ShowModal()
########################################################################
class PanelOne(wx.Panel):
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
SwapPanel = wx.StaticText(self, -1, 'Panel 1')
########################################################################
class PanelTwo(wx.Panel):
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
SwapPanel = wx.StaticText(self, -1, 'Panel 2')
########################################################################
class PanelThree(wx.Panel):
#----------------------------------------------------------------------
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
SwapPanel = wx.StaticText(self, -1, 'Panel 3')
########################################################################
class MainFrame(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Panel Switcher")
self.panel_one = PanelOne(self)
self.panel_two = PanelTwo(self)
self.panel_three = PanelThree(self)
self.panel_two.Hide()
self.panel_three.Hide()
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.panel_one, 1, wx.EXPAND)
self.sizer.Add(self.panel_two, 1, wx.EXPAND)
self.sizer.Add(self.panel_three, 1, wx.EXPAND)
self.SetSizer(self.sizer)
menubar = wx.MenuBar()
fileMenu = wx.Menu()
LoginDialogBox = fileMenu.Append(wx.ID_ANY, "Login", "Login")
self.Bind(wx.EVT_MENU, self.LoginBox, LoginDialogBox)
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)
#----------------------------------------------------------------------
def LoginBox(self, event):
LoginBoxDialog = LoginDialog(None, -1, 'Login')
LoginBoxDialog.ShowModal()
self.onSwitchPanels()
def onSwitchPanels(self):
FrameSwap = self.SwitchPanel
if FrameSwap == 'Panel_One':
self.SetTitle("Panel One")
self.panel_one.Show(True)
self.panel_two.Show(False)
self.panel_three.Show(False)
elif FrameSwap == 'Panel_Two':
self.SetTitle("Panel Two")
self.panel_one.Show(False)
self.panel_two.Show(True)
self.panel_three.Show(False)
elif FrameSwap == 'Panel_Three':
self.SetTitle("Panel Three")
self.panel_one.Show(False)
self.panel_two.Show(False)
self.panel_three.Show(True)
else:
Dialog = wx.MessageDialog(None, 'Unknown Error Has
Occurred')
Dialog.ShowModal()
self.Layout()
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()
[/code]