Re: [Deskbar] cuemiac



On Fri, 2005-10-21 at 15:44 +0200, Mikkel Kamstrup Erlandsen wrote:
> Here's what I have so far about the CuemiacWidget... Not anywhere near
> completion yet. Just though I'd share.
> 
> Just run "python cuemiac.py" to see it in action.
> 
> If you edit it please keep it clean from deskbar imports so far. It
> eases debugging wuite a bit. Ie. just copy-paste the bits in you need.

After some IRC discussion with people who Know how to do things, i
created the cuemiac-reloaded.py file (author is tko on IRC).

This file demonstrate how to really do the widget properly, with one
single treeview, easy keyboard navigation, and custom action widgets on
the left.

I also attach a diff for your old cuemiac widget to fix some style
issues. see screenshot http://raphael.slinckx.net/cuemiac.png

So now, you should merge the two, to have an uber model reflecting the
new way of displaying it, if it's possible..
#!/usr/bin/env python
import gtk
import gobject

# The window
win = gtk.Window()

# The Box separating the tree on the right and the categories on the left
hbox = gtk.HBox()
win.add(hbox)

# The layout will allow to position the action widgets as we want
layout = gtk.Fixed()
hbox.pack_start(layout, expand=False)

# The treeview contains every match
treeview = gtk.TreeView()
hbox.pack_start(treeview, expand=True)
treeview.set_property("headers-visible", False)

# We store here tuples (iter, widget) meaning we align widget on iter
align_widgets = []

store = gtk.TreeStore(gobject.TYPE_STRING)

# First category
catlabel = gtk.Label("Actions")
iter1 = store.append(None, ["Open foo"])
store.append(None, ["Execute Bar"])
store.append(None, ["View baz"])
# More matches from category 'Actions'
i = store.append(None, ["More Items..."])
store.append(i, ["No more idea"])
store.append(i, ["Do this, that"])
# Store the relation actionlabel-iter
align_widgets.append( (iter1,catlabel) )

# Here we go again
catlabel = gtk.Label("Documents")
iter2 = store.append(None, ["ChangeLog"])
store.append(None, ["README"])
store.append(None, ["AUTHORS"])
align_widgets.append( (iter2,catlabel) )

# Some crap to get the treeview show something
treeview.set_model(store)
#treeview.expand_all()
treeview.insert_column_with_attributes(-1, "", gtk.CellRendererText(), text=0)
column = treeview.get_column(0)

# Now here is the best bit
def do_align_widgets(treeview, allocation, column, layout, widgets):
    if treeview.window is None:
		return
		
    model = treeview.get_model()
    for iter,widget in widgets:
		# We retreive the position of the row pointed by iter (that's the row beside the action label)
		path = model.get_path(iter)
		area = treeview.get_background_area(path, column)
		
		# Now we have the coords of the row, let's move it in the layout
		x,y = treeview.tree_to_widget_coords(area.x, area.y)
		# Warning ! the widget has to take account of the 'vertical-separator' style property.
		# the problem is that i don't know how to access such properties
		# I workaround this by retreiving the difference between cell's height and background's height (that is, magically, the vertical-separator value)
		# Try this (from IRC): treeview.style_get_property("vertical-separator")
		if widget.parent:
			layout.move(widget, 0, y + (treeview.get_background_area(path, column).height - treeview.get_cell_area(path, column).height)*2)
		else:
			layout.put(widget, 0, y + (treeview.get_background_area(path, column).height - treeview.get_cell_area(path, column).height)*2)
			widget.show()

treeview.connect_after('size-allocate', do_align_widgets, column, layout, align_widgets)

# Hope everything's fine..
win.show_all()
win.connect("destroy", gtk.main_quit)
gtk.main()
--- cuemiac.py	2005-10-21 20:18:01.000000000 +0200
+++ cuemiac-k.py	2005-10-21 16:50:29.000000000 +0200
@@ -125,7 +125,7 @@
 		self.hits = gtk.TreeViewColumn ("Hits")
 		hit_icon = gtk.CellRendererPixbuf ()
 		hit_title = gtk.CellRendererText ()
-		self.hits.pack_start (hit_icon)
+		self.hits.pack_start (hit_icon, False)
 		self.hits.pack_start (hit_title)
 		self.hits.set_cell_data_func(hit_icon, self.__get_match_icon_for_cell)
 		self.hits.set_cell_data_func(hit_title, self.__get_match_title_for_cell)
@@ -220,8 +220,8 @@
 		self.categories.append (category)
 		count = len(self.categories)
 		self.resize (count, 2)
-		self.attach (category.get_name_label(), 0,1, count-1,count)
-		self.attach (category.get_view(), 1,2, count-1,count)
+		self.attach (category.get_name_label(), 0,1, count-1,count, xoptions=gtk.EXPAND|gtk.FILL, yoptions=0)
+		self.attach (category.get_view(), 1,2, count-1,count, xoptions=gtk.EXPAND|gtk.FILL, yoptions=0)
 		
 		return category
 	

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]