~ubuntu-branches/ubuntu/trusty/sugar-sliderpuzzle-activity/trusty

« back to all changes in this revision

Viewing changes to SliderPuzzle.activity/mmm_modules/borderframe.py

  • Committer: Bazaar Package Importer
  • Author(s): Jani Monoses
  • Date: 2008-02-16 20:54:56 UTC
  • Revision ID: james.westby@ubuntu.com-20080216205456-yrap5ajfu0qyadf2
Tags: upstream-5
ImportĀ upstreamĀ versionĀ 5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2007 World Wide Workshop Foundation
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
#
 
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 !
 
19
#
 
20
 
 
21
import pygtk
 
22
pygtk.require('2.0')
 
23
import gtk, gobject, pango
 
24
 
 
25
BORDER_LEFT = 1
 
26
BORDER_RIGHT = 2
 
27
BORDER_TOP = 4
 
28
BORDER_BOTTOM = 8
 
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
 
35
 
 
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)
 
55
        align.add(self.inner)
 
56
        align.show()
 
57
        self.inner.show()
 
58
        gtk.EventBox.add(self, align)
 
59
        self.stack = []
 
60
 
 
61
    def set_border_color (self, color):
 
62
        gtk.EventBox.modify_bg(self, gtk.STATE_NORMAL, color)
 
63
 
 
64
    def modify_bg (self, state, color):
 
65
        self.inner.modify_bg(state, color)
 
66
 
 
67
    def add (self, widget):
 
68
        self.stack.append(widget)
 
69
        self.inner.add(widget)
 
70
        self.inner.child.show_now()
 
71
 
 
72
    def push (self, widget):
 
73
        widget.set_size_request(*self.inner.child.get_size_request())
 
74
        self.inner.remove(self.inner.child)
 
75
        self.add(widget)
 
76
 
 
77
    def pop (self):
 
78
        if len(self.stack) > 1:
 
79
            self.inner.remove(self.inner.child)
 
80
            del self.stack[-1]
 
81
            self.inner.add(self.stack[-1])
 
82
 
 
83
    def get_child (self):
 
84
        return self.inner.child
 
85
 
 
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])
 
89
 
 
90
    def show (self):
 
91
        self.show_all()
 
92
 
 
93
#    def get_allocation (self):
 
94
#        return self.inner.get_allocation()
 
95