Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/journal/sugarbin.py
blob: cae7c9cb7a05eb9b5d4c115f032e21a852d14a9d (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
130
131
132
133
134
135
136
137
138
139
140
141
# 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

    def get_padding_left(self):
        return self._padding_left

    def set_padding_left(self, value):
        if value == self._padding_left:
            return
        self._padding_left = value
        self.queue_resize()

    padding_left = gobject.property(
            getter=get_padding_left, setter=set_padding_left)

    def get_padding_right(self):
        return self._padding_right

    def set_padding_right(self, value):
        if value == self._padding_right:
            return
        self._padding_right = value
        self.queue_resize()

    padding_right = gobject.property(
            getter=get_padding_right, setter=set_padding_right)

    def get_padding_top(self):
        return self._padding_top

    def set_padding_top(self, value):
        if value == self._padding_top:
            return
        self._padding_top = value
        self.queue_resize()

    padding_top = gobject.property(
            getter=get_padding_top, setter=set_padding_top)

    def get_padding_bottom(self):
        return self._padding_bottom

    def set_padding_bottom(self, value):
        if value == self._padding_bottom:
            return
        self._padding_bottom = value
        self.queue_resize()

    padding_bottom = gobject.property(
            getter=get_padding_bottom, setter=set_padding_bottom)

    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 = gobject.property(setter=set_padding)

    # TODO later props are intended only only padding* but
    # for future border* as well

    def get_x(self):
        return self._padding_left

    x = gobject.property(getter=get_x)

    def get_y(self):
        return self._padding_top

    y = gobject.property(getter=get_y)

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

    width = gobject.property(getter=get_width)

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

    height = gobject.property(getter=get_height)

    # 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)
            child_allocation.width = max(0, child_allocation.width)
            child_allocation.height = max(0, child_allocation.height)
            self.child.size_allocate(child_allocation)

gobject.type_register(SugarBin)