GUI problem while using wxCheckListBox

Shine Anne m2ids2005 at gmail.com
Mon Jul 17 06:27:23 PDT 2006


Skipped content of type multipart/alternative-------------- next part -----=
---------
import wx
import OpenDialog

ID_OPEN =3D 101
ID_REMOVE =3D 102

   =

class BtnPanel(wx.Panel):
    def __init__(self, parent,log):
        self.parent =3D parent
        wx.Panel.__init__(self, parent, -1)
        self.index =3D 0
        self.sampleList =3D ['zero', 'one', 'two', 'three', 'four', 'five'] =

        =

        sizer =3D wx.BoxSizer(wx.VERTICAL)
        =

        mainSizer  =3D wx.BoxSizer(wx.HORIZONTAL)
        self.openBtn =3D wx.Button(self,ID_OPEN,label=3D"Open",size=3D(70,2=
1),)
        self.removeBtn =3D wx.Button(self,ID_REMOVE,label=3D"Remove",size=
=3D(70,21) )
        mainSizer.Add(self.openBtn,0,wx.TOP|wx.ALIGN_RIGHT|wx.ALL,2)
        mainSizer.Add(self.removeBtn,0,wx.TOP|wx.ALIGN_RIGHT|wx.ALL,2)
        sizer.Add(mainSizer,0,wx.TOP|wx.ALIGN_RIGHT|wx.ALL,5)
        =

        mainSizer  =3D wx.BoxSizer(wx.HORIZONTAL)
        #lb =3D wx.CheckListBox(self, -1,(0,40),(855,500), self.sampleList)
        lb =3D wx.CheckListBox(self, -1,(0,30),(785,400), self.sampleList)
        self.lb =3D lb
        mainSizer.Add(self.lb,0,wx.TOP|wx.ALIGN_LEFT|wx.ALL,5)
        #mainSizer.Add(self.txtVal,0,wx.TOP|wx.ALIGN_LEFT|wx.ALL,5)
        sizer.Add(mainSizer,0,wx.TOP|wx.ALIGN_LEFT|wx.ALL,5)
        =

        self.SetSizer(sizer)

        self.Bind(wx.EVT_BUTTON,self.OnOpen,id=3DID_OPEN)
        self.Bind(wx.EVT_BUTTON,self.OnRemove,id=3DID_REMOVE)
        self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, lb)
        =

    def EvtCheckListBox(self, event):
        self.index =3D event.GetSelection()
        label =3D self.lb.GetString(self.index)
        status =3D 'un'
        if self.lb.IsChecked(self.index):
            status =3D ''
        #print 'Box %s is %schecked \n' % (label, status)
        self.lb.SetSelection(self.index) =

        =

    def OnOpen(self,evt):
        self.mibDialog =3D OpenDialog.MList(self,-1)
        =

    def OnRemove(self,evt):
        self.lb.Delete(self.index)

    def OnOk(self,lst):
        #self.txtVal =3D wx.TextCtrl(self, -1,"0", size=3D(100,-1),style=3D=
wx.TE_READONLY|wx.TE_RICH2)
        for i in range(len(lst)):
            self.lb.Append(lst[i])
    =

        =

if __name__=3D=3D'__main__':
    app =3D wx.PySimpleApp()
    frame =3D wx.Frame(None,-1,"HEY",size=3D(480,650),pos=3D(0,0),style=3Dw=
x.ALIGN_TOP|wx.DEFAULT_FRAME_STYLE)
    n =3D BtnPanel(frame,-1)
    frame.Show(1)
    app.MainLoop()

-------------- next part --------------
import wx

class MList(wx.Panel):
    def __init__(self, parent, log):
        self.log =3D log
        self.parent =3D parent
        wx.Panel.__init__(self, parent, -1)
        self.changedValues =3D []

        lst =3D [ 'apple ', 'orange', 'mango',
                'pear', 'Banana', 'pineapple',
                'strawberry','pine ', 'lemon', 'coconut',
                'grape']

        dlg =3D wx.MultiChoiceDialog( self, =

                                   "Select the fruit",
                                   "List of fruits", lst)

        if (dlg.ShowModal() =3D=3D wx.ID_OK):
            selections =3D dlg.GetSelections()
            strings =3D [lst[x] for x in selections]
            #print "Selections: %s -> %s\n" % (selections, strings)
            for i in range(len(strings)):
                if not strings[i] in self.parent.sampleList:
                    self.changedValues.append(strings[i])#self.changedValue=
s.append(strings[i])
                    self.parent.sampleList.append(strings[i])
                else:
                    msgBox =3D wx.MessageDialog(self,"The value selected is=
 already present ",caption=3D"Warning",style =3D wx.OK|wx.ICON_EXCLAMATION )
                    msgBox.ShowModal()

        dlg.Destroy()
        self.parent.OnOk(self.changedValues)
     =




More information about the wxpython-users mailing list