-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhigbuttons.py
183 lines (145 loc) · 5.5 KB
/
higbuttons.py
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2006 Insecure.Com LLC.
# Copyright (C) 2007-2008 Adriano Monteiro Marques
#
# Author: Adriano Monteiro Marques <[email protected]>
# Cleber Rodrigues <[email protected]>
# João Paulo de Souza Medeiros <[email protected]>
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This library 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 Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""
higwidgets/higbuttons.py
button related classes
"""
__all__ = ['HIGMixButton', 'HIGButton', 'HIGArrowButton', 'MiniButton', 'HIGStockButton',
'HIGToggleButton', 'HIGToggleStockButton']
import gtk
import gobject
class HIGMixButton (gtk.HBox):
def __init__(self, title, stock):
gtk.HBox.__init__(self, False, 4)
self.img = gtk.Image()
self.img.set_from_stock(stock, gtk.ICON_SIZE_BUTTON)
self.lbl = gtk.Label(title)
self.hbox1 = gtk.HBox(False, 2)
self.hbox1.pack_start(self.img, False, False, 0)
self.hbox1.pack_start(self.lbl, False, False, 0)
self.align = gtk.Alignment(0.5, 0.5, 0, 0)
self.pack_start(self.align)
self.pack_start(self.hbox1)
class HIGButton (gtk.Button):
def __init__ (self, title="", stock=None):
if title and stock:
gtk.Button.__init__(self)
content = HIGMixButton(title, stock)
self.add(content)
elif title and not stock:
gtk.Button.__init__(self, title)
elif stock:
gtk.Button.__init__(self, stock=stock)
else:
gtk.Button.__init__(self)
class HIGToggleButton(gtk.ToggleButton):
def __init__(self, title="", stock=None):
if title and stock:
gtk.ToggleButton.__init__(self)
content = HIGMixButton(title, stock)
self.add(content)
elif title and not stock:
gtk.ToggleButton.__init__(self, title)
elif stock:
gtk.ToggleButton.__init__(self, stock)
self.set_use_stock(True)
else:
gtk.ToggleButton.__init__(self)
class HIGStockButton(gtk.Button):
"""
"""
def __init__(self, stock, text=None, size=gtk.ICON_SIZE_BUTTON):
"""
"""
gtk.Button.__init__(self, text)
self.__size = size
self.__image = gtk.Image()
self.__image.set_from_stock(stock, self.__size)
self.set_image(self.__image)
class HIGToggleStockButton(gtk.ToggleButton):
"""
"""
def __init__(self, stock, text=None, size=gtk.ICON_SIZE_BUTTON):
"""
"""
gtk.ToggleButton.__init__(self, text)
self.__size = size
self.__image = gtk.Image()
self.__image.set_from_stock(stock, self.__size)
self.set_image(self.__image)
class MiniButton(gtk.Button):
def __init__(self, stock, size=gtk.ICON_SIZE_MENU):
super(MiniButton, self).__init__()
self.img = gtk.image_new_from_stock(stock, size)
hbox = gtk.HBox(False, 2)
hbox.pack_start(self.img)
hbox.show_all()
self.add(hbox)
self.set_size_request(*self.img.size_request())
class HIGArrowButton(gtk.Button):
__gsignals__ = {
'force-clicked' : (gobject.SIGNAL_RUN_LAST, None, ())
}
def __init__(self, orient):
super(HIGArrowButton, self).__init__()
# Fascist mode!
self.arrow = gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_ETCHED_IN)
# No genocide yet :)
self._active = False
self.orientation = orient
self.add(self.arrow)
def set_orientation(self, orient):
shadow = self.arrow.get_property("shadow-type")
if orient == gtk.ORIENTATION_HORIZONTAL:
self.orient = gtk.ORIENTATION_HORIZONTAL
if self.get_active():
self.arrow.set(gtk.ARROW_LEFT, shadow)
else:
self.arrow.set(gtk.ARROW_RIGHT, shadow)
else:
self.orient = gtk.ORIENTATION_VERTICAL
if self.get_active():
self.arrow.set(gtk.ARROW_UP, shadow)
else:
self.arrow.set(gtk.ARROW_DOWN, shadow)
def do_button_press_event(self, event):
if event.button == 3:
self.emit('force-clicked')
return gtk.Button.do_button_press_event(self, event)
def get_orientation(self):
return self.orient
def set_shadow(self, value):
direction = self.arrow.get_property("arrow-type")
self.arrow.set(direction, value)
def get_shadow(self, value):
return self.arrow.get_property("shadow-type")
def get_active(self):
return self._active
def set_active(self, val):
self._active = val
self.orientation = self.orientation
orientation = property(get_orientation, set_orientation)
shadow_type = property(get_shadow, set_shadow)
active = property(get_active, set_active)
gobject.type_register(HIGArrowButton)