Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/journal/sugarbin.py
blob: 5596c679eb1e44eefeee311006de3832f78ce814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright (C) 2010, Aleksey Lim
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import gtk
import gobject


class SugarBin(gtk.EventBox):

    def __init__(self, **kwargs):
        gtk.EventBox.__init__(self, **kwargs)

        self._padding_left = 0
        self._padding_right = 0
        self._padding_top = 0
        self._padding_bottom = 0

    @property
    def padding_left(self):
        return self._padding_left

    @padding_left.setter
    def padding_left(self, value):
        if value == self._padding_left:
            return
        self._padding_left = value
        self.queue_resize()

    @property
    def padding_right(self):
        return self._padding_right

    @padding_right.setter
    def padding_right(self, value):
        if value == self._padding_right:
            return
        self._padding_right = value
        self.queue_resize()

    @property
    def padding_top(self):
        return self._padding_top

    @padding_top.setter
    def padding_top(self, value):
        if value == self._padding_top:
            return
        self._padding_top = value
        self.queue_resize()

    @property
    def padding_bottom(self):
        return self._padding_bottom

    @padding_bottom.setter
    def padding_bottom(self, value):
        if value == self._padding_bottom:
            return
        self._padding_bottom = value
        self.queue_resize()

    def set_padding(self, value):
        self._padding_left = value
        self._padding_right = value
        self._padding_top = value
        self._padding_bottom = value
        self.queue_resize()

    padding = property(None, set_padding)

    @property
    def x(self):
        return self._padding_left

    @property
    def y(self):
        return self._padding_top

    @property
    def width(self):
        return self.allocation.width - self._padding_left - self._padding_right

    @property
    def height(self):
        return self.allocation.height - self._padding_top - self._padding_bottom

    # gtk.Widget overrides

    def get_pointer(self):
        x, y = gtk.EventBox.get_pointer(self)
        return (x - self.x, y - self.y)

    def do_size_request(self, requisition):
        if self.child is not None:
            requisition.width, requisition.height = self.child.size_request()
        else:
            requisition.width, requisition.height = (0, 0)
        requisition.width += self._padding_left + self._padding_right
        requisition.height += self._padding_top + self._padding_bottom

    def do_size_allocate(self, allocation):
        self.allocation = allocation

        if self.flags() & gtk.REALIZED:
            self.window.move_resize(*allocation)

        if self.child is not None:
            __, __, width, height = allocation
            child_allocation = gtk.gdk.Rectangle(
                    x=self._padding_left, y=self._padding_top,
                    width=width - self._padding_left - self._padding_right,
                    height=height - self._padding_top - self._padding_bottom)
            self.child.size_allocate(child_allocation)


gobject.type_register(SugarBin)