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 # Fall-back to default/blue if not found or name==None
44 def getIcon(name, iconsize):
46 idef='tasklaunch_default_application'
48 # If name==None then use the default icon
49 if name==None or name=='':
54 ico=getIconPath(iname, iconsize)
56 # If not found then use the default icon
58 ico=getIconPath(idef, iconsize)
60 ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, iconsize, iconsize)
64 class Icon(gobject.GObject):
65 def __init__(self, isconfig, config):
66 self.__gobject_init__()
68 self.isconfig=isconfig
85 def timePressed(self):
86 """ return how much time a button is pressed """
87 dt=time.time() - self.lastpress
101 return(self.config.iconsize+self.config.iconspace)
103 def draw(self, cr, x, y, mode):
107 if self.icon==None and not self.isconfig:
111 cr.set_source_rgba(0.1, 0.1, 0.1, 1)
115 if self.timePressed() <= self.presstime or self.ispressed:
116 t=1.0 * min(self.timePressed(), self.presstime) / self.presstime
119 cr.set_source_rgba(0, g, b, 0.7)
121 cr.set_source_rgba(0.3, 0.3, 0.3, 0.7)
123 x3=x + (self.config.iconspace/6)
124 y3=y + (self.config.iconspace/6)
127 w=self.config.iconsize+(self.config.iconspace*2/3)
130 cr.arc(x3+w-r, y3+r, r, pi*1.5, pi*2)
131 cr.arc(x3+w-r, y3+w-r, r, 0, pi*0.5)
132 cr.arc(x3+r, y3+w-r, r, pi*0.5, pi)
133 cr.arc(x3+r, y3+r, r, pi, pi*1.5)
149 icon2=icon.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
152 x3=x + (self.config.iconspace/2)
153 y3=y + (self.config.iconspace/2)
154 cr.set_source_pixbuf(icon2, x3, y3)
160 def timerPressed(self):
161 # if not self.ispressed:
166 if self.timePressed()>self.presstime:
174 # Double-time: time for pressed and time for not-pressed
175 if time.time() - self.lastpress > self.presstime*2:
178 self.lastpress=time.time()
180 gobject.timeout_add(20, self.timerPressed)
183 dt=time.time() - self.lastpress
186 if dt<=self.presstime:
188 if self.clickcount==1:
190 elif self.clickcount==2:
191 self.emit('double-click')
192 if self.clickcount==3:
193 self.emit('tripple-click')
195 elif dt>self.presstime and dt<2:
196 self.emit('long-press')
201 def invalidate(self, window=None):
210 w=self.config.iconsize + self.config.iconspace
211 rect=gdk.Rectangle(self.x, self.y, w, w)
212 gdk.Window.invalidate_rect(window, rect, True)
214 gobject.type_register(Icon)
215 signals=['click', 'double-click', 'tripple-click', 'long-press']
217 gobject.signal_new(s, Icon, gobject.SIGNAL_RUN_FIRST,
218 gobject.TYPE_NONE, ())
220 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: