4 # Copyright (C) 2010 Stefanos Harhalakis
6 # This file is part of wifieye.
8 # wifieye is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # wifieye is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with wifieye. If not, see <http://www.gnu.org/licenses/>.
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
28 from hildondesktop import *
34 from portrait import FremantleRotation
36 from xdg.IconTheme import getIconPath
43 ico=getIconPath(name, config.iconsize)
44 ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, config.iconsize,
49 class Icon(gobject.GObject):
50 def __init__(self, isconfig):
51 self.__gobject_init__()
53 self.isconfig=isconfig
72 def timePressed(self):
73 """ return how much time a button is pressed """
74 dt=time.time() - self.lastpress
84 return(config.iconsize+config.iconspace)
86 def draw(self, cr, x, y, mode):
87 #print "draw", x, y, mode
91 if self.icon==None and not self.isconfig:
95 cr.set_source_rgba(0.1, 0.1, 0.1, 1)
99 t=1.0 * min(self.timePressed(), self.presstime) / self.presstime
102 cr.set_source_rgba(0, g, b, 0.7)
104 cr.set_source_rgba(0.3, 0.3, 0.3, 0.7)
106 x3=x + (config.iconspace/6)
107 y3=y + (config.iconspace/6)
110 w=config.iconsize+(config.iconspace*2/3)
113 cr.arc(x3+w-r, y3+r, r, pi*1.5, pi*2)
114 cr.arc(x3+w-r, y3+w-r, r, 0, pi*0.5)
115 cr.arc(x3+r, y3+w-r, r, pi*0.5, pi)
116 cr.arc(x3+r, y3+r, r, pi, pi*1.5)
132 icon2=icon.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
135 x3=x + (config.iconspace/2)
136 y3=y + (config.iconspace/2)
137 cr.set_source_pixbuf(icon2, x3, y3)
143 def timerPressed(self):
146 if not self.ispressed:
151 if self.timePressed()>self.presstime:
160 # Double-time: time for pressed and time for not-pressed
161 if time.time() - self.lastpress > self.presstime*2:
164 self.lastpress=time.time()
166 gobject.timeout_add(20, self.timerPressed)
167 #print "doPress() end"
171 dt=time.time() - self.lastpress
174 if dt<=self.presstime:
176 if self.clickcount==1:
179 elif self.clickcount==2:
181 self.emit('double-click')
182 if self.clickcount==3:
183 print "tripple-click"
184 self.emit('tripple-click')
186 elif dt>self.presstime and dt<2:
188 self.emit('long-press')
194 def invalidate(self, window=None):
203 w=config.iconsize + config.iconspace
204 rect=gdk.Rectangle(self.x, self.y, w, w)
205 #print "rect", self.x, self.y, w, w
206 gdk.Window.invalidate_rect(window, rect, True)
208 gobject.type_register(Icon)
209 signals=['click', 'double-click', 'tripple-click', 'long-press']
211 gobject.signal_new(s, Icon, gobject.SIGNAL_RUN_FIRST,
212 gobject.TYPE_NONE, ())
214 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: