A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
higcontainer.py
Go to the documentation of this file.
1 import gtk
2 import gobject
3 try:
4  from gazpacho.widgets.base.base import SimpleContainerAdaptor
5 except ImportError:
6  pass
7 
8 #root_library = 'hig'
9 
10 
11 class HIGContainer(gtk.Bin):
12  __gtype_name__ = 'HIGContainer'
13  __gproperties__ = {
14  'title': (str, 'Group Title', 'the group title',
15  '', gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT),
16  }
17 
18  def __init__(self, title=None):
19  self.__title_text = None
20  gtk.widget_push_composite_child()
21  self.__title = gobject.new(gtk.Label, visible=True, xalign=0, yalign=0.5)
22  self.__indent = gobject.new(gtk.Label, visible=True, label=' ')
23  gtk.widget_pop_composite_child()
24  gtk.Bin.__init__(self)
25  self.__title.set_parent(self)
26  self.__indent.set_parent(self)
27  if title is not None:
28  self.props.title = title
29 
30  def do_size_request(self, requisition):
31  title_req = gtk.gdk.Rectangle(0, 0, *self.__title.size_request())
32  indent_req = gtk.gdk.Rectangle(0, 0, *self.__indent.size_request())
33  if self.child is None:
34  child_req = gtk.gdk.Rectangle()
35  else:
36  child_req = gtk.gdk.Rectangle(0, 0, *self.child.size_request())
37  requisition.height = (title_req.height + 6 +
38  max(child_req.height, indent_req.height))
39  requisition.width = max(title_req.width, indent_req.width + child_req.width)
40 
41  def do_size_allocate(self, allocation):
42  self.allocation = allocation
43 
44  ## title
45  title_req = gtk.gdk.Rectangle(0, 0, *self.__title.get_child_requisition())
46  title_alloc = gtk.gdk.Rectangle()
47  title_alloc.x = allocation.x
48  title_alloc.y = allocation.y
49  title_alloc.width = min(title_req.width, allocation.width)
50  title_alloc.height = min(title_req.height, allocation.height)
51  self.__title.size_allocate(title_alloc)
52 
53  ## child
54  if self.child is None:
55  return
56  indent_req = gtk.gdk.Rectangle(0, 0, *self.__indent.get_child_requisition())
57  child_req = gtk.gdk.Rectangle(0, 0, *self.child.get_child_requisition())
58  child_alloc = gtk.gdk.Rectangle()
59  child_alloc.x = allocation.x + indent_req.width
60  child_alloc.y = allocation.y + title_alloc.height + 6
61  child_alloc.width = allocation.width - indent_req.width
62  child_alloc.height = allocation.height - 6 - title_alloc.height
63  self.child.size_allocate(child_alloc)
64 
65  def do_forall(self, internal, callback, data):
66  if internal:
67  callback(self.__title, data)
68  callback(self.__indent, data)
69  if self.child is not None:
70  callback(self.child, data)
71 
72  def do_set_property(self, pspec, value):
73  if pspec.name == 'title':
74  self.__title.set_markup('<span weight="bold">%s</span>' %
75  gobject.markup_escape_text(value))
76  self.__title_text = value
77  else:
78  raise AttributeError, 'unknown property %s' % pspec.name
79 
80  def do_get_property(self, pspec):
81  if pspec.name == 'title':
82  return self.__title_text
83  else:
84  raise AttributeError, 'unknown property %s' % pspec.name
85 
86 if __name__ == '__main__':
87  frame = gtk.Frame()
88  group = gobject.new(HIGContainer, title="Hello")
89  frame.add(group)
90  check = gtk.CheckButton("foobar")
91  group.add(check)
92  w = gtk.Window()
93  w.add(frame)
94  w.show_all()
95  w.connect("destroy", lambda w: gtk.main_quit())
96  gtk.main()
97