|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
wxPython : Returning values from frames
Hi.
I need some help please. I am writing wxPython app, that must have some initialization values. In the beginning of the main frame(frame1), it checkes whether those values exist, if not it should run a separate process (frame2), that its end result is a returned value to the main frame(frame1). I am having problems achieving that. I was able to run frame2 from frame1, but I couldn't returned any results to frame 1 and also frame1 didn't stop, it continued executing in parallel to frame2. I attched some code that might explain the problem more clearly ,as you can see in the attached code, frame1 has a function "GetClientID" that suppose to execute frame2, until a valid value is returned ( or until the user chooses to exit) Thank you very much for the help. Roy frame 1 is: from wxPython.wx import * class MyWin(wxFrame): def __init__(self): # frame initialization wxFrame.__init__(self, NULL, -1, "dc", wxDefaultPosition, wxSize(480,400)) # get client ID self.ClientID = self.GetClientID() def GetClientID(self): # Supposed to run frame 2 , and continue running it until a valid value is returned class MyApp(wxApp): def OnInit(self): frame = MyWin() return true if __name__ == '__main__': app = MyApp(0) app.MainLoop() frame2 is: class MainWindow(wxPanel): def __init__(self, parent, id): wxPanel.__init__(self, parent, id) l1 = wxStaticText(self, -1, "Please enter your email:",(20, 20)) self.t1 = wxTextCtrl(self, 1, "",(150, 20), size=(125, -1)) l2 = wxStaticText(self, -1, "Please enter password:",(20, 70)) self.t2 = wxTextCtrl(self, 2, "",(150, 70), size=(125, -1)) btn = wxButton(self, -1, "Click here", (170, 150)) self.Bind(EVT_BUTTON, self.OnClick, btn) def OnClick(self, evt): # Read input values, # do some validation # and some processing and return result return res if __name__=="__main__": app = wxPySimpleApp() frame = wxFrame(None,-1,"TITLE",wxDefaultPosition, wxSize(480,280)) x = MainWindow(frame, -1) frame.Show(1) app.MainLoop() |
|
#2
|
||||
|
||||
|
The simple solution is to withdraw the main application window Show(false) and and make your second frame a wxDialog derived window. If you make it a modal dialog you can create the dialog and query its values before destroying it.
Maybe the standard dialog is enough: Code:
dlg = wxTextEntryDialog(self, 'EMAIL','Please enter your email address', 'python@rules.com')
dlg.SetValue("")
if dlg.ShowModal() == wxID_OK:
email= dlg.GetValue()
dlg.Destroy()
grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
|||
|
|||
|
Thank you for your quick reply.
Well, this is what I did, but since I want the user to type in more then 1 field, i'll need more then one wxDialog. so input form is a great choice, but as I mentioned before, when i'm calling the input form from within the main program, the main program doesn't stop and wait for the returned values from the input form, Quote:
|
|
#4
|
||||
|
||||
|
It is not difficult to create your own dialogs with as many fields as you like. Simply create a class based on wxDialog then in it's __init__ create as many entry widgets as you need.
Then you define a method that returns the values of the fields. Are you using BOA? That has the ability to design new dialogs with your assistance. (The constructor anyway). The only bit you need to do by hand is to define the "get values" method. I am not sure what you mean by the program not waiting - if you use the ShowModal then any other window will not get focus. IM/PM if you need more info. Grim ![]() |
|
#5
|
|||
|
|||
|
Thanks
Thank you Grim.
I did as you suggested and it's working great. Roy ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > wxPython : Returning values from frames |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|