|
Passing value between frames
Python Version and Linux Version Here.
gokul@gokul-VirtualBox:~/python_scripts$ python -V
Python 2.7.3
gokul@gokul-VirtualBox:~/python_scripts$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
gokul@gokul-VirtualBox:~/python_scripts$
I have written a piece of GUI code to do the follows..
On click of New Connection button in the main frame, the user inputs the details in the second frame. On click on button Login in the second frame, I would like to pass the variable information from second frame to the first frame.
code run complains as follows..
gokul@gokul-VirtualBox:~/python_scripts$ python AWR.py
Traceback (most recent call last):
File "AWR.py", line 35, in OnConn
self.connstr=AP_LoginPanel(self.frame,-1,"Authentification required!").GetConnStr()
File "AWR.py", line 110, in GetConnStr
return self.connstr
AttributeError: 'AP_LoginPanel' object has no attribute 'connstr'
Don't understand why self.connstr is not recognized in AP_LoginPanel.
Here is the code..
Code:
import wx
import cx_Oracle
import wx.grid as gridlib
class PerfFrame(wx.Frame):
def __init__(self,parent,title):
frame = wx.Frame.__init__(self,parent,title=title)
panel = wx.Panel(self)
self.statusbar=self.CreateStatusBar()
self.statusbar.SetStatusText("Not Connected")
self.frame = frame
# Menu Details
perfmenu = wx.Menu()
newcon = wx.MenuItem(perfmenu,wx.NewId(),"&New Connection","Opening a new connection")
perfmenu.AppendItem(newcon)
perfmenu.AppendSeparator()
menuAbout = perfmenu.Append(wx.ID_ABOUT,"&About","Information about this program")
perfmenu.AppendSeparator()
menuExit = perfmenu.Append(wx.ID_EXIT,"E&xit","Exit the program")
mainmenu = wx.MenuBar()
mainmenu.Append(perfmenu,"Perf")
self.SetMenuBar(mainmenu)
self.Bind(wx.EVT_MENU, self.OnConn, newcon)
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
self.Show(True)
def OnCloseWindow (self, event):
self.Destroy()
def OnConn(self,event):
self.connstr=AP_LoginPanel(self.frame,-1,"Authentification required!").GetConnStr()
def OnAbout(self,event):
dlg=wx.MessageDialog(self,"Open Source AWR Viewer","About Performance Maintenance",wx.OK)
dlg.ShowModal()
dlg.Destroy()
def OnExit(self,event):
self.Close(True)
class AP_LoginPanel(wx.Frame):
def __init__(self, parent, id, title):
frame = wx.Frame.__init__(self,parent,id, title=title,size=(400,300))
self.frame = frame
self.panel = wx.Panel(frame)
self.showLoginBox()
self.Show(True)
def showLoginBox (self):
# Create the sizer
sizer = wx.FlexGridSizer(rows=6, cols=2, hgap=5, vgap=15)
# Username
self.txt_Username = wx.TextCtrl(self, 1, size=(150,-1), style=wx.TE_LEFT)
lbl_Username = wx.StaticText(self, -1, "Username:")
sizer.Add(lbl_Username,0, wx.LEFT|wx.TOP| wx.RIGHT, 50)
sizer.Add(self.txt_Username,0, wx.TOP| wx.RIGHT, 50)
# Password
self.txt_Password = wx.TextCtrl(self, 1, size=(150,-1), style=wx.TE_PASSWORD)
lbl_Password = wx.StaticText(self, -1, "Password:")
sizer.Add(lbl_Password,0, wx.LEFT|wx.RIGHT, 50)
sizer.Add(self.txt_Password,0, wx.RIGHT, 50)
# Host String
self.txt_hoststr = wx.TextCtrl(self, 1, size=(150,-1), style=wx.TE_LEFT)
lbl_HostStr = wx.StaticText(self, -1, "Host String:")
sizer.Add(lbl_HostStr,0, wx.LEFT|wx.RIGHT, 50)
sizer.Add(self.txt_hoststr,0, wx.RIGHT, 50)
# Port
self.txt_port = wx.TextCtrl(self, 1, size=(150,-1), style=wx.TE_LEFT)
lbl_port = wx.StaticText(self, -1, "Port:")
sizer.Add(lbl_port,0, wx.LEFT| wx.RIGHT, 50)
sizer.Add(self.txt_port,0, wx.RIGHT, 50)
# Service
self.txt_sid = wx.TextCtrl(self, 1, size=(150,-1), style=wx.TE_LEFT)
lbl_sid = wx.StaticText(self, -1, "SID/Service Name:")
sizer.Add(lbl_sid,0, wx.LEFT| wx.RIGHT, 50)
sizer.Add(self.txt_sid,0, wx.RIGHT, 50)
# Submit button
btn_Process = wx.Button(self, -1, "&Login")
self.Bind(wx.EVT_BUTTON, self.OnSubmit, btn_Process)
sizer.Add(btn_Process,0, wx.LEFT, 50)
self.SetSizer(sizer)
def OnSubmit(self, event):
UserText = self.txt_Username.GetValue()
PasswordText = self.txt_Password.GetValue()
HostText = self.txt_hoststr.GetValue()
PortText = self.txt_port.GetValue()
SIDText = self.txt_sid.GetValue()
self.connstr = UserText+"/"+PasswordText+"@"+HostText+":"+PortText+"/"+SIDText
self.TestConnection()
self.Close(True)
def TestConnection(self):
dlg = wx.MessageDialog(self,self.connstr,"You Entered",wx.OK | wx.CANCEL)
dlg.ShowModal()
dlg.Destroy()
#con= cx_Oracle.connect(self.connstr)
def GetConnStr(self):
return self.connstr
app=wx.App(False)
frame=PerfFrame(None,"Oracle Perf Maintenance")
app.SetTopWindow(frame)
app.MainLoop()
Can someone help identify the issue here ?
|