1
# Copyright 2007 World Wide Workshop Foundation
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
# If you find this activity useful or end up using parts of it in one of your
18
# own creations we would love to hear from you at info@WorldWideWorkshop.org !
23
import gtk, gobject, pango
29
BORDER_VERTICAL = BORDER_TOP | BORDER_BOTTOM
30
BORDER_HORIZONTAL = BORDER_LEFT | BORDER_RIGHT
31
BORDER_ALL = BORDER_VERTICAL | BORDER_HORIZONTAL
32
BORDER_ALL_BUT_BOTTOM = BORDER_HORIZONTAL | BORDER_TOP
33
BORDER_ALL_BUT_TOP = BORDER_HORIZONTAL | BORDER_BOTTOM
34
BORDER_ALL_BUT_LEFT = BORDER_VERTICAL | BORDER_RIGHT
36
class BorderFrame (gtk.EventBox):
37
def __init__ (self, border=BORDER_ALL, size=5, bg_color=None, border_color=None):
38
gtk.EventBox.__init__(self)
39
if border_color is not None:
40
self.set_border_color(gtk.gdk.color_parse(border_color))
41
self.inner = gtk.EventBox()
42
if bg_color is not None:
43
self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(bg_color))
44
align = gtk.Alignment(1.0,1.0,1.0,1.0)
45
self.padding = [0,0,0,0]
46
if (border & BORDER_TOP) != 0:
47
self.padding[0] = size
48
if (border & BORDER_BOTTOM) != 0:
49
self.padding[1] = size
50
if (border & BORDER_LEFT) != 0:
51
self.padding[2] = size
52
if (border & BORDER_RIGHT) != 0:
53
self.padding[3] = size
54
align.set_padding(*self.padding)
58
gtk.EventBox.add(self, align)
61
def set_border_color (self, color):
62
gtk.EventBox.modify_bg(self, gtk.STATE_NORMAL, color)
64
def modify_bg (self, state, color):
65
self.inner.modify_bg(state, color)
67
def add (self, widget):
68
self.stack.append(widget)
69
self.inner.add(widget)
70
self.inner.child.show_now()
72
def push (self, widget):
73
widget.set_size_request(*self.inner.child.get_size_request())
74
self.inner.remove(self.inner.child)
78
if len(self.stack) > 1:
79
self.inner.remove(self.inner.child)
81
self.inner.add(self.stack[-1])
84
return self.inner.child
86
def set_size_request (self, w, h):
87
self.inner.set_size_request(w,h)
88
super(BorderFrame, self).set_size_request(w+self.padding[0]+self.padding[2], h+self.padding[1]+self.padding[3])
93
# def get_allocation (self):
94
# return self.inner.get_allocation()