Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

wxPython: need return value from wxFrame

Yametazamwa mara 358
Ruka hadi kwenye ujumbe wa kwanza ambao haujasomwa

Mirko Koenig

hayajasomwa,
21 Ago 2003, 18:17:2221/08/2003
kwa
Hi

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.

I need something like a function that starts the frame and after i quited
the frame the function returns the last address (self.lastAddress).

Or are there any other ideas. Like saving the address in a global list
(But thats not OO style i think)

Mirko Koenig

Cliff Wells

hayajasomwa,
21 Ago 2003, 18:28:2321/08/2003
kwa
On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote:
> Hi
>
> 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.

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


Mirko Koenig

hayajasomwa,
22 Ago 2003, 15:27:1322/08/2003
kwa
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

Bob Parnes

hayajasomwa,
22 Ago 2003, 18:31:2922/08/2003
kwa

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
rpa...@megalink.net

Jarek Zgoda

hayajasomwa,
22 Ago 2003, 18:39:4322/08/2003
kwa
Bob Parnes <rpa...@megalink.net> 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:zg...@chrome.pl http://zgoda.jogger.pl/

Cliff Wells

hayajasomwa,
22 Ago 2003, 16:56:3622/08/2003
kwa

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

Mirko Koenig

hayajasomwa,
26 Ago 2003, 14:00:2726/08/2003
kwa
On Fri, 22 Aug 2003 22:56:36 +0200, Cliff Wells wrote:

> 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 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:

> ....


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

I tried but couldn't find a solution.
As i said before, i have a wxframe derivered class for my addressbook to
have a stand-alone addressbook. Stand-alone in my case means that it is a
app for itself. Not only a extra windows in the invoice application.

It contains wxFrame specific things like status bar etc.
Therefore i could not deriver it from wxDialog.

I can't place a wxFrame in a sizer of a dialog. That would solve my
problem.

Are there any other ideas?

Mirko Koenig

Cliff Wells

hayajasomwa,
26 Ago 2003, 17:02:2326/08/2003
kwa
On Tue, 2003-08-26 at 11:00, Mirko Koenig wrote:
> On Fri, 22 Aug 2003 22:56:36 +0200, Cliff Wells wrote:
> >
> > app = wx.PySimpleApp()
> > dlg = MyDialog(None, -1)
> > retval = dlg.ShowModal()
> > if retval == wx.ID_OK:
> > print dlg.GetValue()
> > dlg.Destroy()
> > app.MainLoop()
> >
>
> I tried but couldn't find a solution.
> As i said before, i have a wxframe derivered class for my addressbook to
> have a stand-alone addressbook. Stand-alone in my case means that it is a
> app for itself. Not only a extra windows in the invoice application.
>
> It contains wxFrame specific things like status bar etc.
> Therefore i could not deriver it from wxDialog.

That isn't a problem in and of itself. The code above could be used
with a wxFrame instead (with minor modifications).

> I can't place a wxFrame in a sizer of a dialog. That would solve my
> problem.
>
> Are there any other ideas?

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.

Regards,

Mirko Koenig

hayajasomwa,
27 Ago 2003, 12:46:1627/08/2003
kwa
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

Ujumbe 0 mpya