In case anyone is wondering I made a triState control button. But I am still wondering
how to put it in a listControl...
matt
from wxPython.wx import *
wxInitAllImageHandlers()
class wxTriStateButton( wxBitmapButton ):
"""A button that provides three states:
1.Checked
2.Unchecked
3.Unsure
"""
def __init__( self, parent, id, bitmap=None ):
self.unselected = self.getBitmapImage("unchecked.bmp")
self.selected = self.getBitmapImage("checked.bmp")
self.unsure = self.getBitmapImage("unsure.bmp")
wxBitmapButton.__init__( self, parent, id, self.unselected )
self.state = 0 #state can be 0-2
EVT_BUTTON( parent, id, self.click )
self.setStateForNextClick()
def getBitmapImage( self, name ):
image = wxBitmap(name,wxBITMAP_TYPE_BMP)
return image
def getImageForState( self, useNextState=0 ):
if useNextState:
state = (self.state+1)%3
else:
state = self.state
if state == 0:
image = self.unselected
elif state == 1:
image = self.selected
else:
image = self.unsure
return image
def printState( self ):
if self.state == 0:
print "\nunselected"
elif self.state == 1:
print "\nselected"
else:
print "\nunsure"
print " state:"+str(self.state)
def setStateForNextClick( self ):
"""Since we have 3 states we need to set the bitmap
every time the button is clicked"""
self.SetBitmapFocus( self.getImageForState( ))
self.SetBitmapLabel( self.getImageForState( ))
self.SetBitmapSelected( self.getImageForState( useNextState=1 ))
def click( self, event ):
self.state = (self.state + 1)%3
self.setStateForNextClick()
self.Refresh() #redraw to make sure button is in correct state
event.Skip()
···
-----Original Message-----
From: Harrison, Matthew
Sent: Monday, December 17, 2001 10:33 AM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] Tri-state check box, and modified list control
Hi all-
I'm working on an app that classifies words. This might be a little confusing but I'll try to explain:
There are three states for word foo
1. Word foo can belong to bin a,b,c or d.
2. Foo might possibly belong(maybe you are not sure if it belongs) to bin a,b,c or d.
3. Foo does not belong to any of them.
In our design spec we said it would be nice to have a list control that contains a 4 checkboxes
(for bin a,b,c,d) and the word. We want a special feature for the checkboxes, namely it
should be tri-state.
The checkbox should cycle from nothing to a check to a question mark to nothing, when clicked.
Is this possible?
We are fine with implementing a control but should it be subclassed off of wxControl?
Any other hints?
The other question is how do I put these controls in a listControl? We want to be
able to sort by word and also by state of any of the 4 checkboxes? Again it doesn't
seem like I can do this natively, I just asking for hints here.
thanks for your time
matt
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users