Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: wxPython: need return value from wxFrame

Reply
Thread Tools

Re: wxPython: need return value from wxFrame

 
 
Mirko Koenig
Guest
Posts: n/a
 
      08-22-2003
On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote:

> On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote:
>> I have a frame where you can select/add/delte etc a customer address.
>> It is included in an wxApp to have a stand alone customer addressbook.
>>
>> Now i wrote a invoice application. I added a button to add a address to
>> the invoice. I want the customer addressbook to be open by clicking on
>> that button. No problem. So far so good.
>>
>> But i want the addressbook frame to return the selected address as a
>> tuple, list or dict. I don't have any idea how to do that.
>>
>> I can show() the frame from within the invoice code but show doesn't
>> return a value.

>
> Use a wxDialog instead.
>


But how to return a list or tuple. All i can see is that a dialog returns
a int value

Mirko Koenig
 
Reply With Quote
 
 
 
 
Cliff Wells
Guest
Posts: n/a
 
      08-22-2003
On Fri, 2003-08-22 at 12:27, Mirko Koenig wrote:
> On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote:
>
> > On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote:
> >> I have a frame where you can select/add/delte etc a customer address.
> >> It is included in an wxApp to have a stand alone customer addressbook.
> >>
> >> Now i wrote a invoice application. I added a button to add a address to
> >> the invoice. I want the customer addressbook to be open by clicking on
> >> that button. No problem. So far so good.
> >>
> >> But i want the addressbook frame to return the selected address as a
> >> tuple, list or dict. I don't have any idea how to do that.
> >>
> >> I can show() the frame from within the invoice code but show doesn't
> >> return a value.

> >
> > Use a wxDialog instead.
> >

>
> But how to return a list or tuple. All i can see is that a dialog returns
> a int value


Try something like this:

import wx

class MyDialog(wx.Dialog):
def __init__(self, parent, id, title = "Test"):
wx.Dialog.__init__(self, parent, id, title)
sizer = wx.BoxSizer(wx.VERTICAL)

self.text = {}
for t in ['1', '2', '3']:
self.text[t] = wx.TextCtrl(self, -1, "")
sizer.Add(self.text[t], 1, wx.ALIGN_CENTRE|wx.ALL, 5)

btn = wx.Button(self, wx.ID_OK, " OK ")

sizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

btn = wx.Button(self, wx.ID_CANCEL, " Cancel ")
sizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

self.SetSizer(sizer)
self.SetAutoLayout(True)
sizer.Fit(self)


def GetValue(self):
retval = {}
for t in self.text:
retval[t] = self.text[t].GetValue()
return retval


app = wx.PySimpleApp()
dlg = MyDialog(None, -1)
retval = dlg.ShowModal()
if retval == wx.ID_OK:
print dlg.GetValue()
dlg.Destroy()
app.MainLoop()




>
> Mirko Koenig

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 (800) 735-0555


 
Reply With Quote
 
 
 
 
Bob Parnes
Guest
Posts: n/a
 
      08-22-2003
On Fri, 22 Aug 2003 21:27:13 +0200, Mirko Koenig <(E-Mail Removed)> wrote:
> On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote:
>
>> On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote:
>>> I have a frame where you can select/add/delte etc a customer address.
>>> It is included in an wxApp to have a stand alone customer addressbook.
>>>
>>> Now i wrote a invoice application. I added a button to add a address to
>>> the invoice. I want the customer addressbook to be open by clicking on
>>> that button. No problem. So far so good.
>>>
>>> But i want the addressbook frame to return the selected address as a
>>> tuple, list or dict. I don't have any idea how to do that.
>>>
>>> I can show() the frame from within the invoice code but show doesn't
>>> return a value.

>>
>> Use a wxDialog instead.
>>

>
> But how to return a list or tuple. All i can see is that a dialog returns
> a int value
>
> Mirko Koenig


The dialog returns an integer depending upon which button the user
presses to close it. But you can still access the setting in a widget
after the dialog closes.

--
Bob Parnes
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Jarek Zgoda
Guest
Posts: n/a
 
      08-22-2003
Bob Parnes <(E-Mail Removed)> pisze:

> The dialog returns an integer depending upon which button the user
> presses to close it. But you can still access the setting in a widget
> after the dialog closes.


....until you Destroy() the dialog instance. I came from ObjectPascal and
this language teached me that things exist until they are destroyed.

--
Jarek Zgoda
Registered Linux User #-1
http://www.zgoda.biz/ JID:(E-Mail Removed) http://zgoda.jogger.pl/
 
Reply With Quote
 
Mirko Koenig
Guest
Posts: n/a
 
      08-27-2003
Hi

On Tue, 26 Aug 2003 23:02:23 +0200, Cliff Wells wrote:

> Maybe a better idea of exactly what you want would help. Your app has
> only a single wxFrame? You want that frame to return something? To
> what? I would think when the frame "returns" the app would exit if it's
> the only frame.


OK. I try again to explain:
I have two stand-alone apps:
1) customer addressbook
2) invoice

Both made with wxpython.
Both contain:
class cabGui( wxApp ):
def OnInit( self ):
self.frame = cabMainFrame( NULL )
self.frame.Show()
self.SetTopWindow( self.frame )

return true
....
if __name__ == '__main__':
app = cabGui(0)
b = app.MainLoop()

In the customer addressbook the cabMainFrame is the addressbook frame.
In the invoice app the cabMainFrame is the frame containing invoice
specific buttons/field etc.

The cabMainFrame is a wxFrame derivered class. it contains other frames
and a status bar and so on.

What i want is to call the customeraddressbook from within the invoice
app. To give the user the chance to select an address from the
addressbook. That address should then be inserted into the invoice Gui.

I thought this is perhaps possible, so i don't have to write the
addressbokk code twice. I thought i can just use the addressbook and give
back the selected address. So that i can use it in the invoice Gui.

The only solution i found until now is to set an variable in the
customer addressbook that points to one from the invoice Gui if i want to
set it. If not it points to None.

customerFrame.setAddrVar( invoiceAddr )
customerFrame.Show()


Mirko Koenig
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[wxPython] wxFrame don't have Bind attribute ?? Jia Lu Python 8 11-17-2006 08:02 AM
[wxPython] Many wxPanel forms in 1 wxFrame CYBER Python 2 05-02-2005 11:59 PM
wxPython: accessing wxFrame methods in __del__ fails Alex VanderWoude Python 2 03-25-2005 05:59 AM
How to set the size of wxFrame Austin Python 1 10-28-2004 03:26 PM
wxPython: Fit() works on wxPanel, but not on surrounding wxFrame Piet Python 1 05-20-2004 05:34 PM



Advertisments