Re: wxPython: need return value from wxFrame

Discussion in 'Python' started by Mirko Koenig, Aug 22, 2003.

  1. Mirko Koenig

    Mirko Koenig Guest

    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
     
    Mirko Koenig, Aug 22, 2003
    #1
    1. Advertising

  2. Mirko Koenig

    Cliff Wells Guest

    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
     
    Cliff Wells, Aug 22, 2003
    #2
    1. Advertising

  3. Mirko Koenig

    Bob Parnes Guest

    On Fri, 22 Aug 2003 21:27:13 +0200, 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
    >
    > 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
     
    Bob Parnes, Aug 22, 2003
    #3
  4. Mirko Koenig

    Jarek Zgoda Guest

    Bob Parnes <> 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: http://zgoda.jogger.pl/
     
    Jarek Zgoda, Aug 22, 2003
    #4
  5. Mirko Koenig

    Mirko Koenig Guest

    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
     
    Mirko Koenig, Aug 27, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Piet
    Replies:
    1
    Views:
    604
  2. Austin

    How to set the size of wxFrame

    Austin, Oct 28, 2004, in forum: Python
    Replies:
    1
    Views:
    440
    Sion Arrowsmith
    Oct 28, 2004
  3. Alex VanderWoude
    Replies:
    2
    Views:
    835
    Alex VanderWoude
    Mar 25, 2005
  4. CYBER
    Replies:
    2
    Views:
    699
    Ed Leafe
    May 3, 2005
  5. Jia Lu
    Replies:
    8
    Views:
    428
    Jia Lu
    Nov 17, 2006
Loading...

Share This Page