Multiple selections in Tix Hlist

T

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('<Control-Button-1>', 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
 
P

Peter Saffrey

To answer my own question:

HList(selectmode="extended")

does all the work for you.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,037
Messages
2,570,371
Members
47,013
Latest member
JewellChes

Latest Threads

Top