[wxPython] deleting a listbox item causes an application error

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] deleting a listbox item causes an application error

Gary Bankston
For some reason, I'm getting an application error when I attempt to
delete an item from a list box. I'm running windows NT 4.0 sp 5.

My code is below. Its a listbox with a button to add an item and a
button to delete the selected item. Pressing the delete button causes
the application error.

Have I just missed something really obvious?

--
from wxPython.wx import *

ID_ADDITEM_BUTTON = 111
ID_DELITEM_BUTTON = 112

class ClassFrame(wxFrame):
 def __init__( self, parent, ID ):
  wxFrame.__init__(self, parent, ID, "Net Item Editor" )

  sizer = wxBoxSizer( wxVERTICAL )

  # Class Widgets ---
  sizer.Add( wxButton(self, ID_ADDITEM_BUTTON, "Add"), 0, wxEXPAND )
  self.listbox = wxListBox(self, -1, style=wxLB_SINGLE )
  sizer.Add( self.listbox, 1, wxEXPAND )
  sizer.Add( wxButton(self, ID_DELITEM_BUTTON, "Delete"), 0, wxEXPAND )
  EVT_BUTTON( self,ID_ADDITEM_BUTTON , self.On_AddItem )
  EVT_BUTTON( self,ID_DELITEM_BUTTON , self.On_DelItem )

  self.SetAutoLayout( TRUE ) # tell frame to use sizer
  self.SetSizer( sizer )
  sizer.Fit( self )

  self.listbox.InsertItems( ['glip', 'glop', 'splack', 'splort',
'blop'], 0 )

 def On_AddItem( self, event):
  self.SetStatusText( "" )
  newitemname = ''
  prompt = 'Enter the name for the new item:'
  title = 'Add New Item'
  dlg = wxTextEntryDialog( self, prompt, title )
  dlg.CenterOnParent()
  if dlg.ShowModal() == wxID_OK:
   newitemname = dlg.GetValue()
   self.listbox.InsertItems( [newitemname], self.listbox.GetSelection()
)
  dlg.Destroy()

 def On_DelItem( self, event):
  print 'selection = %d' % self.listbox.GetSelection()
  self.listbox.Delete( self.listbox.GetSelection() )

class MyApp(wxApp):
 def __init__( self ):
  wxApp.__init__( self )

 def OnInit(self):
  self.frame = ClassFrame( NULL, -1 )
  self.frame.Show( true )
  self.SetTopWindow( self.frame )
  return true

app = MyApp()
app.MainLoop()
--
  __^__
/_______\  glary
\_______/  sandstorm
   /|\



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] deleting a listbox item causes an application error

Robin Dunn
> For some reason, I'm getting an application error when I attempt to
> delete an item from a list box. I'm running windows NT 4.0 sp 5.
>
> My code is below. Its a listbox with a button to add an item and a
> button to delete the selected item. Pressing the delete button causes
> the application error.
>
> Have I just missed something really obvious?
>

Are you using the released version or an interim build?  I think this was
something that was fixed shortly after 2.1.11 was released.  (And it doesn't
crash here...)

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] deleting a listbox item causes an application error

Gary Bankston
> Are you using the released version or an interim build?  I think this was
> something that was fixed shortly after 2.1.11 was released.  (And it doesn't
> crash here...)

Ah, that was it. I was using wxPython-2_1_11.EXE straight from the download
page. I ididn't even notice the interim release section. I downloaded the latest
interim release and that fixed it.

Problem solved


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users