Trouble with wx.GridBagSizer

Hey all,
I’m using a gridbagsizer for a wx.Dialog, and i’m having some trouble.
When I try to initiate the dialog, my program just freezes up and does nothing, not even sending an error back to the error log.

Here’s the code for my dialog-

···

import wx

ID_FIND = 301
ID_FIND_B1 = 302
ID_FIND_B2 = 303
ID_FIND_TX = 304
ID_REPLACE = 351
ID_RPLC_B1 = 352
ID_RPLC_B2 = 353

class MainWin(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, title, size=(850, 450))
#Menubar

    menubar = wx.MenuBar()
    test = wx.Menu()
    find = wx.MenuItem(test, ID_FIND, 'Find', 'Find something.')
    test.AppendItem(find)
    replace = wx.MenuItem(test, ID_REPLACE, 'Replace', 'Replace something.')

    test.AppendItem(replace)
    menubar.Append(test, '&Test')
    self.SetMenuBar(menubar)
    [self.sb](http://self.sb) = self.CreateStatusBar()
    self.code = wx.TextCtrl(self, ID_TEXTBOX, size=(200, 130), style=wx.TE_MULTILINE)
    self.code.SetFont(wx.Font(11, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL))
    self.Bind(wx.EVT_MENU, self.OnFind, id=ID_FIND)
    self.Bind(wx.EVT_MENU, self.OnReplace, id=ID_REPLACE)
    self.SetMinSize((300, 150))
    self.Centre()
    self.Show(True)

def OnFind(self, event):
    class FindDialog(wx.Dialog):
        def __init__(self, parent):
            wx.Dialog.__init__(self, parent, title=("Find"))
            sizer = wx.GridBagSizer(hgap=5, vgap=5)
            #
            stat_text = wx.StaticText(self, 5000, "Enter text to find:")
            find_text = wx.TextCtrl(self)
            ok_find = wx.Button(self, ID_FIND_B1, 'Find')
            cancel_find = wx.Button

(self, ID_FIND_B2, ‘Cancel’)
#
self.Bind(wx.EVT_BUTTON, self.OnFind_F, id=ID_FIND_B1)
self.Bind(wx.EVT_BUTTON, self.OnCancel_F, id=ID_FIND_B2)
#

            sizer.Add(stat_text, (0,0), (0,2), wx.EXPAND)
            sizer.Add(find_text, (0,3), (0,4), wx.EXPAND)
            sizer.Add(ok_find, (0,8), (0,2), wx.EXPAND)
            sizer.Add

(cancel_find, (1,8), (1,2), wx.EXPAND)
#
sizer.AddGrowableCol(10)
sizer.AddGrowableRow(2)
#
self.SetSizerAndFit(sizer)
def OnFind_F(self, event):

            pass
        def OnCancel_F(self, event):
            dlg.Destroy()
    dlg = FindDialog(None)
    dlg.ShowModal()
    dlg.Destroy()

def OnReplace(self, event):

    class ReplaceDialog(wx.Dialog):
        def __init__(self, parent):
            wx.Dialog.__init__(self, parent, title=("Replace"))
            sizer = wx.BoxSizer(wx.HORIZONTAL)

            self.SetSizer(sizer)
    dlg = ReplaceDialog(None)
    dlg.ShowModal()
    dlg.Destroy()

class MyApp(wx.App):
def OnInit(self):
MainWin(None, -1, ‘Ephesus’).Show()

    return True

app = MyApp(redirect = True, filename = “error.log”)
app.MainLoop()

Does anybody know why my program is doing this?

Thanks,
Trey

I'm using a gridbagsizer for a wx.Dialog, and i'm having some trouble.
When I try to initiate the dialog, my program just freezes up and does
nothing, not even sending an error back to the error log. Here's the code
for my dialog-

ID_FIND = 301
ID_FIND_B1 = 302
ID_FIND_B2 = 303
ID_FIND_TX = 304
ID_REPLACE = 351
ID_RPLC_B1 = 352
ID_RPLC_B2 = 353

Trey,

   You'll end up tripping yourself doing this. Remove the above and use
wx.ID_ANY in all situations. Let the software track which ID belongs to
which widget.

   def OnFind(self, event):
       class FindDialog(wx.Dialog):
           def __init__(self, parent):
               wx.Dialog.__init__(self, parent, title=("Find"))
               sizer = wx.GridBagSizer(hgap=5, vgap=5)
               #
               stat_text = wx.StaticText(self, 5000, "Enter text to find:")
               find_text = wx.TextCtrl(self)
               ok_find = wx.Button(self, ID_FIND_B1, 'Find')
               cancel_find = wx.Button(self, ID_FIND_B2, 'Cancel')

   You're making more work for yourself this way. You don't need a grid bag
sizer, just a vertical sizer (top row for the label and text entry widget,
the other for the two buttons) and two horizontal sizers, one per row.

   You'll also want to initialize the wx.TextCtrl() fully. Look at the man
page on the web site, or the wxPython in Action book -- very highly
recommended.

class MyApp(wx.App):
   def OnInit(self):
       MainWin(None, -1, 'Ephesus').Show()
       return True

app = MyApp(redirect = True, filename = "error.log")
app.MainLoop()

   You need
if __name__ == "__main__":

in which you tell it to run pysimpleapp().

   Back to the books, Trey!

Rich

···

On Thu, 18 Oct 2007, Trey K wrote:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

If I use wx.ID_ANY, then what value should I use in self.Bind(wx.EVT_BUTTON, self.OnFind_F, id=THIS
) spot?

Alas, all the documentation I have for wxpython right now is the internet. I’m working on getting that book you recommended.

···

On 10/18/07, Rich Shepard rshepard@appl-ecosys.com wrote:

You’ll end up tripping yourself doing this. Remove the above and use
wx.ID_ANY in all situations. Let the software track which ID belongs to
which widget.

If I use wx.ID_ANY, then what value should I use in self.Bind(wx.EVT_BUTTON,
self.OnFind_F, id=THIS) spot?

   Nothing.

   Here's an example of a button from the module I'm now debugging:

     self.fsViewButton = wx.Button(self, wx.ID_ANY, label='View')
     self.Bind(wx.EVT_BUTTON, self.OnFzySetView, self.fsViewButton)

Alas, all the documentation I have for wxpython right now is the internet.
I'm working on getting that book you recommended.

   Look at the demos and examples as well as the pages for each widget. It
does take time, but the climb up the learning curve is worth it. The view
toward the top is extensive (unless the mental fog sets in, of course).

   Good luck, Trey, and don't hesitate to ask on the list. Lots of helpful
folks here. And patient, too.

Rich

···

On Thu, 18 Oct 2007, Trey K wrote:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Sorry. I should have been more explicit. The Bind() method is to the name
of the button (self.fsViewButton), not the ID.

Rich

···

On Thu, 18 Oct 2007, Rich Shepard wrote:

Here's an example of a button from the module I'm now debugging:

   self.fsViewButton = wx.Button(self, wx.ID_ANY, label='View')
   self.Bind(wx.EVT_BUTTON, self.OnFzySetView, self.fsViewButton)

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard wrote:

  Here's an example of a button from the module I'm now debugging:

    self.fsViewButton = wx.Button(self, wx.ID_ANY, label='View')
    self.Bind(wx.EVT_BUTTON, self.OnFzySetView, self.fsViewButton)

Or even better:
self.fsViewButton.Bind(wx.EVT_BUTTON, self.OnFzySetView)

See the wxPYthon style guide in the Wiki:

http://wiki.wxpython.org/wxPython_Style_Guide

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris,

   I was writing them that way, but read somewhere, perhaps in the wPIA book,
that there are benefits to the former syntax. I honestly don't recall the
discussion, but I went through all the modules and changed them.

Rich

···

On Thu, 18 Oct 2007, Christopher Barker wrote:

Or even better:
self.fsViewButton.Bind(wx.EVT_BUTTON, self.OnFzySetView)

See the wxPYthon style guide in the Wiki:
http://wiki.wxpython.org/wxPython_Style_Guide

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard wrote:

···

On Thu, 18 Oct 2007, Christopher Barker wrote:

Or even better:
self.fsViewButton.Bind(wx.EVT_BUTTON, self.OnFzySetView)

See the wxPYthon style guide in the Wiki:
http://wiki.wxpython.org/wxPython_Style_Guide

Chris,

  I was writing them that way, but read somewhere, perhaps in the wPIA book,
that there are benefits to the former syntax. I honestly don't recall the
discussion, but I went through all the modules and changed them.

http://wiki.wxpython.org/self.Bind_vs._self.button.Bind

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks, Robin! Not only is that an excellently written explanation, but my
understanding is more complete now that I have more wxPython experience.

Rich

···

On Thu, 18 Oct 2007, Robin Dunn wrote:

self.Bind vs. self.button.Bind - wxPyWiki

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863