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
35 #from xdg.IconTheme import getIconPath
41 from icons import Icons
43 #def getIcon(name, iconsize):
44 # ico=getIconPath(name, iconsize)
45 # ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, iconsize, iconsize)
49 #class IconGrid(gtk.Widget, FremantleRotation):
50 class IconGrid(object): #(gobject.GObject):
51 def __init__(self, isconfig=False):
52 # self.__gobject_init__()
58 self.isconfig=isconfig
61 self.lasticon=None # The last icon that got selected
63 self.draw_pending=False
67 # If this is False then animations are forcefully disabled
68 self.do_animations=True
70 def do_realize(self, config):
73 self.icons=Icons(self.isconfig, self.config)
78 def connect(self, what, *args):
79 if what in icon.signals:
80 self.icons.connect(what, *args)
82 super(IconGrid, self).connect(what, *args)
84 def setSize(self, size):
86 self.icons.setSize(size)
89 ret=self.icons.getSize()
92 def setMode(self, mode):
98 if not isinstance(self, gtk.Widget):
104 v=self.get_property('is-on-current-desktop')
108 self.draw_pending=True
112 if do_draw and self.config.getAnimate() and self.do_animations:
114 self.angle_timer_start=time.time()
115 gobject.timeout_add(20, self.timerAngle)
125 def disableAnimation(self):
126 self.do_animations=False
128 def enableAnimation(self):
129 self.do_animations=True
131 def setAnimationEnable(self, value):
133 self.enableAnimation()
135 self.disableAnimation()
137 def timerAngle(self):
138 if self.angle_timer_start==0:
139 self.angle_timer_start=time.time()-0.05
141 dt=time.time()-self.angle_timer_start
143 # Duration of the rotation effect
146 da=90.0*dt/rotation_time
162 if self.setAngle(angle):
166 self.angle_timer_start=0
170 def iconAt(self, x, y):
171 """ Get icon at coordinates x,y. X and Y are in pixels """
173 w=self.config.iconsize + self.config.iconspace
175 if self.mode=='l' or self.config.getIndiv():
179 x2=self.size[1] - int(y/w) - 1
187 ret=self.icons.get(x,y)
191 def _draw(self, cr, event):
192 self.draw_pending=False
194 w=self.config.iconsize + self.config.iconspace
195 for x,y in self.icons:
196 if self.mode=='l' or self.config.getIndiv():
197 x2=x * (self.config.iconsize + self.config.iconspace)
198 y2=y * (self.config.iconsize + self.config.iconspace)
200 x2=y * (self.config.iconsize + self.config.iconspace)
201 y2=(self.size[1]-x-1) * \
202 (self.config.iconsize + self.config.iconspace)
204 # Only repaint the needed icons
205 rect=gdk.Rectangle(x2, y2, w, w)
206 t=rect.intersect(event.area)
207 if t.width==0 and t.height==0:
210 ico=self.icons.get(x,y)
213 def setAngle(self, angle):
214 """ Return True/False indicating that angle has changed """
216 for x,y in self.icons:
217 ic=self.icons.get(x,y)
218 if ic.setAngle(angle):
223 def do_expose_event(self, event):
224 cr=self.window.cairo_create()
226 cr.rectangle(event.area.x, event.area.y,
227 event.area.width, event.area.height)
231 if not self.init_done:
232 self.icons.setWindow(self.window)
235 self._draw(cr, event)
237 def setLastIcon(self, icon):
238 if icon==self.lasticon:
241 if self.lasticon!=None:
242 self.lasticon.doCancel()
243 self.lasticon.invalidate(self.window)
246 def do_button_press_event(self, event):
247 icon=self.iconAt(event.x, event.y)
250 # rect=gdk.Rectangle(event.x,event.y,1,1)
251 # rect=gdk.Rectangle(0, 0, 100, 100)
253 icon.invalidate(self.window)
254 self.setLastIcon(icon)
256 # gdk.Window.invalidate_rect(self.window, rect, True)
260 def do_button_release_event(self, event):
261 if self.lasticon!=None:
262 self.lasticon.invalidate(self.window)
263 self.lasticon.doRelease()
265 self.setLastIcon(None)
269 def do_leave_notify_event(self, event):
270 self.setLastIcon(None)
273 def do_pproperty_notify_event(self, event):
274 icon=self.iconAt(event.x, event.y)
278 icon.invalidate(self.window)
281 def do_motion_notify_event(self, event):
282 icon=self.iconAt(event.x, event.y)
283 if self.lasticon==icon:
286 self.setLastIcon(None)
288 icon.invalidate(self.window)
291 def do_button_press_event_old(self, event):
292 if event.type==gdk.BUTTON_PRESS:
301 def do_event1(self, event):
302 print "event:", event, event.type
304 def reloadIcons(self):
307 # def on_orientation_changed(self, orientation):
308 # print "orch:", orientation
312 class IconGridWidget(IconGrid, gtk.Widget):
313 def __init__(self, isconfig, config, animation=True):
314 IconGrid.__init__(self, isconfig)
315 gtk.Widget.__init__(self)
317 # This must be called before do_realize
318 self.setAnimationEnable(animation)
322 IconGrid.do_realize(self, self.config)
324 self.setSize(self.size)
326 def setSize(self, size):
327 IconGrid.setSize(self, size)
329 w=self.size[0] * (self.config.iconsize + self.config.iconspace)
330 h=self.size[1] * (self.config.iconsize + self.config.iconspace)
332 self.set_size_request(w, h)
334 def do_realize(self):
335 screen=self.get_screen()
336 self.set_colormap(screen.get_rgba_colormap())
337 self.set_app_paintable(True)
339 self.set_flags(self.flags() | gtk.REALIZED)
341 self.window=gdk.Window(
342 self.get_parent_window(),
343 width=self.allocation.width,
344 height=self.allocation.height,
345 window_type=gdk.WINDOW_CHILD,
346 wclass=gdk.INPUT_OUTPUT,
347 event_mask=self.get_events() | gdk.EXPOSURE_MASK
348 | gdk.BUTTON_PRESS_MASK
349 | gdk.BUTTON_RELEASE_MASK
350 | gdk.BUTTON_MOTION_MASK
351 | gdk.POINTER_MOTION_MASK
352 | gdk.POINTER_MOTION_HINT_MASK
353 | gdk.ENTER_NOTIFY_MASK
354 | gdk.LEAVE_NOTIFY_MASK )
356 self.window.set_user_data(self)
357 self.style.attach(self.window)
359 # self.style.set_background(self.window, gtk.STATE_NORMAL)
360 self.window.move_resize(*self.allocation)
362 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
363 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
365 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
367 #gtk.Widget.do_realize(self)
368 #HomePluginItem.do_realize(self)
370 # screen=self.get_screen()
371 # self.set_colormap(screen.get_rgba_colormap())
372 # self.set_app_paintable(True)
374 def do_unrealize(self):
375 #self.window.set_user_data(None)
376 self.window.destroy()
378 #gobject.type_register(IconGrid)
379 gobject.type_register(IconGridWidget)
382 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: