A Discrete-Event Network Simulator
API
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 ## HIGContainer class
11 class HIGContainer(gtk.Bin):
12  ## @var __title_text
13  # title
14  ## @var __title
15  # title
16  ## @var __indent
17  # indent
18  ## @var title_req
19  # title request
20  ## @var indent_req
21  # indent request
22  ## @var child
23  # child
24  ## @var child_req
25  # child request
26  ## @var requisition
27  # reqisition
28  ## @var allocation
29  # allocation
30  ## @var title_alloc
31  # title allocation
32  ## @var child_alloc
33  # child allocation
34  ## @var title_alloc.x
35  # allocation x
36  ## @var title_alloc.y
37  # allocation y
38  ## @var title_alloc.width
39  # allocation width
40  ## @var title_alloc.height
41  # allocation height
42  ## @var __gtype_name__
43  # global type name
44  __gtype_name__ = 'HIGContainer'
45  ## @var __gproperties__
46  # global properties
47  __gproperties__ = {
48  'title': (str, 'Group Title', 'the group title',
49  '', gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT),
50  }
51 
52  def __init__(self, title=None):
53  """ Initializer
54 
55  @param self: this object
56  @param title: title
57  """
58  self.__title_text = None
59  gtk.widget_push_composite_child()
60  self.__title = gobject.new(gtk.Label, visible=True, xalign=0, yalign=0.5)
61  self.__indent = gobject.new(gtk.Label, visible=True, label=' ')
62  gtk.widget_pop_composite_child()
63  gtk.Bin.__init__(self)
64  self.__title.set_parent(self)
65  self.__indent.set_parent(self)
66  if title is not None:
67  self.props.title = title
68 
69  def do_size_request(self, requisition):
70  """!
71  Size request function
72 
73  @param self: this object
74  @param requisition: requisition
75  @return none
76  """
77  title_req = gtk.gdk.Rectangle(0, 0, *self.__title.size_request())
78  indent_req = gtk.gdk.Rectangle(0, 0, *self.__indent.size_request())
79  if self.child is None:
80  child_req = gtk.gdk.Rectangle()
81  else:
82  child_req = gtk.gdk.Rectangle(0, 0, *self.child.size_request())
83  requisition.height = (title_req.height + 6 +
84  max(child_req.height, indent_req.height))
85  requisition.width = max(title_req.width, indent_req.width + child_req.width)
86 
87  def do_size_allocate(self, allocation):
88  """!
89  Allocate size function
90 
91  @param self: this object
92  @param allocation: allocation
93  @return none
94  """
95  self.allocation = allocation
96 
97  ## title
98  title_req = gtk.gdk.Rectangle(0, 0, *self.__title.get_child_requisition())
99  title_alloc = gtk.gdk.Rectangle()
100  title_alloc.x = allocation.x
101  title_alloc.y = allocation.y
102  title_alloc.width = min(title_req.width, allocation.width)
103  title_alloc.height = min(title_req.height, allocation.height)
104  self.__title.size_allocate(title_alloc)
105 
106  ## child
107  if self.child is None:
108  return
109  indent_req = gtk.gdk.Rectangle(0, 0, *self.__indent.get_child_requisition())
110  child_req = gtk.gdk.Rectangle(0, 0, *self.child.get_child_requisition())
111  child_alloc = gtk.gdk.Rectangle()
112  child_alloc.x = allocation.x + indent_req.width
113  child_alloc.y = allocation.y + title_alloc.height + 6
114  child_alloc.width = allocation.width - indent_req.width
115  child_alloc.height = allocation.height - 6 - title_alloc.height
116  self.child.size_allocate(child_alloc)
117 
118  def do_forall(self, internal, callback, data):
119  """!
120  For all function
121 
122  @param self: this object
123  @param internal: internal
124  @param callback: callback
125  @param data: data
126  @return none
127  """
128  if internal:
129  callback(self.__title, data)
130  callback(self.__indent, data)
131  if self.child is not None:
132  callback(self.child, data)
133 
134  def do_set_property(self, pspec, value):
135  """!
136  Set property function
137 
138  @param self: this object
139  @param pspec: internal
140  @param value: callback
141  @return AttributeError if unknown property
142  """
143  if pspec.name == 'title':
144  self.__title.set_markup('<span weight="bold">%s</span>' %
145  gobject.markup_escape_text(value))
146  self.__title_text = value
147  else:
148  raise AttributeError, 'unknown property %s' % pspec.name
149 
150  def do_get_property(self, pspec):
151  """!
152  Set property function
153 
154  @param self: this object
155  @param pspec: internal
156  @return title text
157  """
158  if pspec.name == 'title':
159  return self.__title_text
160  else:
161  raise AttributeError, 'unknown property %s' % pspec.name
162 
163 if __name__ == '__main__':
164  frame = gtk.Frame()
165  group = gobject.new(HIGContainer, title="Hello")
166  frame.add(group)
167  check = gtk.CheckButton("foobar")
168  group.add(check)
169  w = gtk.Window()
170  w.add(frame)
171  w.show_all()
172  w.connect("destroy", lambda w: gtk.main_quit())
173  gtk.main()
174 
#define min(a, b)
Definition: 80211b.c:44
def do_size_request(self, requisition)
Size request function.
Definition: higcontainer.py:69
#define max(a, b)
Definition: 80211b.c:45
def do_forall(self, internal, callback, data)
For all function.
def do_get_property(self, pspec)
Set property function.
def do_set_property(self, pspec, value)
Set property function.
def do_size_allocate(self, allocation)
Allocate size function.
Definition: higcontainer.py:87