Tix hlist and item_exists

2005-05-12 Thread theoryboy
I can't seem to get this function to work. If the item does not exist I
get an exception, rather than a return value of false. Here's an
example:


#!/usr/bin/python

from Tix import *

root = Tk()
listBox = HList(root)
item = "some item"
if not listBox.item_exists(item, 0):
listBox.add(item, itemtype=TEXT, text=item)


Any ideas?

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Multiple selections in Tix Hlist

2005-05-18 Thread theoryboy
I'm trying to implement multiple selection functionality in a Tix Hlist
using a control-click. I've bound control-click to a function that uses
selection_set to add to the selection, but it doesn't seem to work.
Only the last clicked item appears selected (highlighted) in the
display and the return from info_selection only ever contains the last
2 items, rather than all the items I have control-clicked.

It's odd, because if I set up the list and then set up a breakpoint, I
can set multiple selections at the debug command line and it works as I
would expect.

My other problem is that there is no "selection_unset()" method, for
using a control click to individually unselect one item from the list.
There is only selection_clear(), which clears all selections. Am I
missing something?

Below is some sample code:

#!/usr/bin/python

from Tix import *

class ControlClickTest:

def __init__(self, master):
root = master
modalPane = Toplevel(root)
self.listBox = HList(modalPane)
self.listBox.pack()
items = ['1','2','4','6','8']
for item in items:
self.listBox.add(item, itemtype=TEXT, text=item)
self.listBox.bind('', self.ctrlClick)
root.wait_window(modalPane)

def ctrlClick(self, event):
print "control click!"
index = self.listBox.nearest(event.y)
self.listBox.selection_set(index)
print self.listBox.info_selection()

if __name__ == "__main__":
ControlClickTest(Tk())


Any ideas?

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list