[sugar] New version of piemenu.py, and some cairo questions

Don Hopkins dhopkins
Mon Feb 26 21:36:07 EST 2007


I've uploaded a new version of piemenu.py with some bug fixes, submenu 
support, title headers, and a better demo!
The new demo you get when you run "python piemenu.py" has submenus with 
a few different layouts including a pure pie menu, a regular linear 
menu, and a hybrid pie with linear overflow items.

http://www.donhopkins.com/home/piemenu.py

I could use some tips about measuring the bounding box of fonts and text 
in cairo, please.
The numbers I was getting back when measuring the font_extent were too 
tall, and left a lot of vertical space on the top, so instead I just 
measured some actual text instead.
I ended up measuring the vertical extents of the string "My(" to include 
tall letters and descenders, and using that as the font extent height, 
instead of using the official font_extent height.
Does the font height include some extra leading? Summing the 
font_extents ascent and descent got the same thing as the font_extents 
height, which was too tall, and I don't know how much leading to 
subtract to get a nice tight bounding box around the labels. (Note that 
I want the same height for all labels in the same font, so I measure the 
font height not the text height, so I don't get shorter labels for 
shorter text). To tweak the text into the nicest looking place, I added 
a label_x_adjust=0 and label_y_adjust=2 parameters that fudge the label 
positions so they look better. Kind of gross but it works.

I'd like to figure out a nice api for pie menus with rings, that doesn't 
complicate the more common use cases without any rings.
How about generalizing the "max_pie_items" limit (which defines the 
limit of pie items before it starts overflowing to linear items) from a 
number to an array of numbers, which specify the maximum number of items 
in each ring, and after all the pie rings are filled up only then does 
it start using linear overflow items.
The default max_pie_items would then be [8] instead of 8 as it is now, 
and you could set it to [4, 8, 12] to get a three ring pie menu with 4 
on the inside, 8 in the middle ring, and 12 in the outer ring, and the 
rest of the items linear. Or you could change the last number 12 to 100 
to make the outer ring accommodate up to 100 items.

The highlighting code makes sure to draw the selected item on the top, 
so if you do have 100 overlapping labels, you will still be able to read 
the selected one because the unselected ones will never overlap it.
I'd like to implement label scaling during tracking, to shrink or elide 
some of the unselected labels, while drawing the selected label large 
and on top, so you can put lots of items into the pie menu (and use them 
like linear dials, like a light dimmer), without taking up too much 
screen space.

Another feature I'd like to add is associating icons with the labels 
(and making the labels optional, or only shown as a tooltip when the 
item is selected).

So here is a naive resource management question:
What is the best way to configure and pass icons and graphical resources 
into cairo based widgets, measure and draw them on the screen efficiently?
(It would be nice if the same icon is used in a lot of places, it only 
got loaded once, and stuff like that...)

    -Don



More information about the Sugar-devel mailing list