Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 28th, 2004, 05:16 AM
roypython roypython is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 71 roypython User rank is Lance Corporal (50 - 100 Reputation Level)roypython User rank is Lance Corporal (50 - 100 Reputation Level)roypython User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 h 20 m 49 sec
Reputation Power: 5
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()

Reply With Quote
  #2  
Old June 28th, 2004, 06:10 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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 ***

Reply With Quote
  #3  
Old June 28th, 2004, 04:10 PM
roypython roypython is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 71 roypython User rank is Lance Corporal (50 - 100 Reputation Level)roypython User rank is Lance Corporal (50 - 100 Reputation Level)roypython User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 h 20 m 49 sec
Reputation Power: 5
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:
Originally Posted by Grim Archon
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

Reply With Quote
  #4  
Old June 28th, 2004, 04:36 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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

Reply With Quote
  #5  
Old June 30th, 2004, 10:54 PM
roypython roypython is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 71 roypython User rank is Lance Corporal (50 - 100 Reputation Level)roypython User rank is Lance Corporal (50 - 100 Reputation Level)roypython User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 h 20 m 49 sec
Reputation Power: 5
Thanks

Thank you Grim.
I did as you suggested and it's working great.
Roy

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > wxPython : Returning values from frames


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT