This time I've included an example of what I'm trying to do. It serves to illustrate both my previous "double selection signal" issue as well as something different.
To watch the first one, make sure the checkbox isn't checked, then click load. Choose a row, say the 4th one, and you'll see the double signals. The second one seems to be that the treeview isn't capable of scrolling to a set position initially after it is loaded. Subsequent requests after reload work, but the first one never does. I'm guessing that it has to do with the "phantom" selection of row 0. To watch this one (unless it randomly selects 0 or something), run test2.py and click the checkbox before clicking load. Subsequent reloads always seem to work, but it is just the first one. Any ideas? Thanks in advance, ast versions: gtk2-2.0.6-8 ORBit2-2.4.4 pygtk2-1.99.12-7 orbit-python-1.99.0-4 gnome-python2-1.99.11-8 -- Andrew S. Townley <[EMAIL PROTECTED]>
PIX_WIDTH = 64
import gtk
import gobject
from gtk import TRUE, FALSE
class Test2:
def __init__(self, width=150):
self.width = width
self.tmodel = gtk.ListStore(gobject.TYPE_STRING,
gtk.gdk.Pixbuf)
self.tree = gtk.TreeView(self.tmodel)
self.widget = gtk.ScrolledWindow()
self.widget.set_policy(gtk.POLICY_NEVER,
gtk.POLICY_ALWAYS)
self.widget.add(self.tree)
self.widget.set_shadow_type(gtk.SHADOW_ETCHED_IN)
# load the image
image = gtk.Image()
image.set_from_file("/usr/share/pixmaps/gnome-home.png")
self.pix = image.get_pixbuf()
# configure the columns
col = gtk.TreeViewColumn("Name",
gtk.CellRendererText(),
text = 0)
col.set_min_width(self.width - PIX_WIDTH - 20)
col.set_max_width(self.width - PIX_WIDTH - 20)
col.set_fixed_width(self.width - PIX_WIDTH - 20)
self.tree.append_column(col)
renderer = gtk.CellRendererPixbuf()
renderer.set_property("xalign", 1)
col = gtk.TreeViewColumn("active",
renderer,
pixbuf = 1)
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
col.set_fixed_width(PIX_WIDTH)
col.set_max_width(PIX_WIDTH)
col.set_min_width(PIX_WIDTH)
self.tree.append_column(col)
# hide the headers
self.tree.set_headers_visible(FALSE)
# fix our max width
self.widget.set_size_request(self.width, -1)
# take care of all the signals
sel = self.tree.get_selection()
sel.connect("changed", self._sel_changed)
def clear(self):
self.tmodel.clear()
def showList(self, fils):
for f in fils:
iter = self.tmodel.append()
if f[1] < 3:
self.tmodel.set(iter, 0, f[0],
1, self.pix)
else:
self.tmodel.set(iter, 0, f[0])
# since we have to do a lot of work managing the
# selection ourselves, we need to determine what it is
# right now
sel = self.tree.get_selection()
sel.unselect_all()
sel.selected_foreach(self._sel_foreach)
self.widget.show_all()
def _sel_foreach(self, model, path, iter):
"""
This method is used to walk the selection.
"""
print "-------------------------------------------"
print "Selected idx = %d; val = '%s'" % (path[0],
model.get_value(iter, 0))
print "-------------------------------------------"
def _sel_changed(self, selection):
"""
This method is responsible for handling all selection
changed events and making some sort of intelligent
decision about what's really going on so that it can
propigate it to the appropriate listeners.
"""
selection.selected_foreach(self._sel_foreach)
from whrandom import randrange
if __name__ == "__main__":
scroll = FALSE
def doit(*args):
data = []
view.clear()
for i in range(200):
x = randrange(0, 32767)
data.append(("www.gnome.org " + str(i), x % 5))
view.showList(data)
if scroll:
sel = view.tree.get_selection()
col = view.tree.get_column(0)
idx = randrange(0, 200)
print "supposed to select row %d" % idx
sel.select_path(idx)
view.tree.scroll_to_cell(idx, col, TRUE, 1, 0)
def toggle(*args):
global scroll
if scroll:
scroll = FALSE
else:
scroll = TRUE
win = gtk.Window()
win.connect("destroy", lambda win: gtk.main_quit())
view = Test2(width=300)
box = gtk.VBox(FALSE, 5)
box.pack_start(view.widget, expand=TRUE, fill=TRUE)
box2 = gtk.HBox(FALSE, 5)
cb = gtk.CheckButton("select row")
cb.connect("toggled", toggle)
box2.pack_start(cb, expand=FALSE)
input = gtk.Button("load")
input.connect("clicked", doit)
box2.pack_start(input, expand=TRUE, fill=TRUE)
box.pack_start(box2, expand=FALSE, fill=TRUE)
win.set_default_size(-1, 400)
win.add(box)
win.show_all()
gtk.main()
signature.asc
Description: This is a digitally signed message part
