Re: [pygtk] VBox in a treeview?

2004-02-09 Thread Graham Ashton
On Fri, 2004-01-30 at 15:26, Graham Ashton wrote:
 Hi. I'm trying to put an arbitrary GTK widget inside a treeview cell,
 and am having difficulty finding out how to do it.

Apologies for responding to my own message, but I found a way to achieve
the same result (multi-line text inside a cell) by drawing a pango
layout directly onto the treeview widget. I started from code from Johan
Dahlin;

  http://www.mail-archive.com/[EMAIL PROTECTED]/msg05242.html

and Austin Henry:

  http://www.daa.com.au/pipermail/pygtk/2003-June/005351.html

Thanks very much guys, I'd never have worked it out without that code.

-- 
Graham Ashton

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] VBox in a treeview?

2004-02-09 Thread Graham Ashton
On Mon, 2004-02-09 at 11:33, Graham Ashton wrote:

 Apologies for responding to my own message, but I found a way to achieve
 the same result...

Just to continue this monologue for a little longer, somebody requested
the code, so here it is...

-- 
Graham Ashton
class ChangeCellRenderer(gtk.GenericCellRenderer):

__gproperties__ = {
'variable': (gobject.TYPE_STRING, 'text', 'variable changed',
 '', gobject.PARAM_READWRITE),
'reason': (gobject.TYPE_STRING, 'reason', 'reason for this change',
   '', gobject.PARAM_READWRITE),
}
property_names = __gproperties__.keys()

def __init__(self):
self.__gobject_init__()

self.xpad = 3
self.ypad = 3

self.xalign = 0.0
self.yalign = 0.5

def __getattr__(self, name):
try:
return self.get_property(name)
except TypeError:
raise AttributeError

def __setattr__(self, name, value):
try:
self.set_property(name, value)
except TypeError:
self.__dict__[name] = value

def do_get_property(self, property):
if property.name not in self.property_names:
raise TypeError('No property named %s' % (property.name,))
return self.__dict__[property.name]

def do_set_property(self, property, value):
if property.name not in self.property_names:
raise TypeError('No property named %s' % (property.name,))
self.__dict__[property.name] = value

def on_render(self, window, widget, background_area,
  cell_area, expose_area, flags):
x_offset, y_offset, width, height = self.on_get_size(widget, cell_area)
width -= self.xpad * 2
height -= self.ypad * 2

layout = pango.Layout(widget.get_pango_context())
list_store = widget.get_model()

if self.reason:
reason = ('span size=smaller%s/span' % self.reason)
else:
reason = ('span size=smaller foreground=#cc'
  'lt;%sgt;'
  '/span' % 'Please assign a reason')

layout.set_markup('span size=smaller weight=bold%s/span\n%s' %
  (self.variable, reason))
layout.set_width(-1)  # turn off wrapping
widget.style.paint_layout(window, gtk.STATE_NORMAL, gtk.TRUE,
  cell_area, widget, 'dummy',
  cell_area.x + x_offset,
  cell_area.y + y_offset,
  layout)

def _get_row_height(self, widget):
layout = pango.Layout(widget.get_pango_context())
layout.set_markup('span size=smallerLine 1\nLine2/span')
pango_scale = 1024  # available as pango.SCALE in more recent pygtk
return (layout.get_size()[1] / pango_scale) + (self.ypad * 2)

def on_get_size(self, widget, cell_area):
calc_width = 200  # randomly picked to be less than treeview width
calc_height = self._get_row_height(widget)

if cell_area:
y_offset = self.yalign * (cell_area.height - calc_height)
y_offset = max(y_offset, 0)
else:
y_offset = self.ypad

x_offset = self.xpad
y_offset = self.ypad
return x_offset, y_offset, calc_width, calc_height


gobject.type_register(ChangeCellRenderer)
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk