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 def do_realize(self, config):
70 self.icons=Icons(self.isconfig, self.config)
75 def connect(self, what, *args):
76 if what in icon.signals:
77 self.icons.connect(what, *args)
79 super(IconGrid, self).connect(what, *args)
81 def setSize(self, size):
83 self.icons.setSize(size)
86 ret=self.icons.getSize()
89 def setMode(self, mode):
95 if not isinstance(self, gtk.Widget):
101 v=self.get_property('is-on-current-desktop')
105 self.draw_pending=True
109 if do_draw and self.config.getAnimate():
111 self.angle_timer_start=time.time()
112 gobject.timeout_add(20, self.timerAngle)
122 def timerAngle(self):
123 if self.angle_timer_start==0:
124 self.angle_timer_start=time.time()-0.05
126 dt=time.time()-self.angle_timer_start
128 # Duration of the rotation effect
131 da=90.0*dt/rotation_time
147 if self.setAngle(angle):
151 self.angle_timer_start=0
155 def iconAt(self, x, y):
156 """ Get icon at coordinates x,y. X and Y are in pixels """
158 w=self.config.iconsize + self.config.iconspace
160 if self.mode=='l' or self.config.getIndiv():
164 x2=self.size[1] - int(y/w) - 1
172 ret=self.icons.get(x,y)
176 def _draw(self, cr, event):
177 self.draw_pending=False
179 w=self.config.iconsize + self.config.iconspace
180 for x,y in self.icons:
181 if self.mode=='l' or self.config.getIndiv():
182 x2=x * (self.config.iconsize + self.config.iconspace)
183 y2=y * (self.config.iconsize + self.config.iconspace)
185 x2=y * (self.config.iconsize + self.config.iconspace)
186 y2=(self.size[1]-x-1) * \
187 (self.config.iconsize + self.config.iconspace)
189 # Only repaint the needed icons
190 rect=gdk.Rectangle(x2, y2, w, w)
191 t=rect.intersect(event.area)
192 if t.width==0 and t.height==0:
195 ico=self.icons.get(x,y)
198 def setAngle(self, angle):
199 """ Return True/False indicating that angle has changed """
201 for x,y in self.icons:
202 ic=self.icons.get(x,y)
203 if ic.setAngle(angle):
208 def do_expose_event(self, event):
209 cr=self.window.cairo_create()
211 cr.rectangle(event.area.x, event.area.y,
212 event.area.width, event.area.height)
216 if not self.init_done:
217 self.icons.setWindow(self.window)
220 self._draw(cr, event)
222 def setLastIcon(self, icon):
223 if icon==self.lasticon:
226 if self.lasticon!=None:
227 self.lasticon.doCancel()
228 self.lasticon.invalidate(self.window)
231 def do_button_press_event(self, event):
232 icon=self.iconAt(event.x, event.y)
235 # rect=gdk.Rectangle(event.x,event.y,1,1)
236 # rect=gdk.Rectangle(0, 0, 100, 100)
238 icon.invalidate(self.window)
239 self.setLastIcon(icon)
241 # gdk.Window.invalidate_rect(self.window, rect, True)
245 def do_button_release_event(self, event):
246 if self.lasticon!=None:
247 self.lasticon.invalidate(self.window)
248 self.lasticon.doRelease()
250 self.setLastIcon(None)
254 def do_leave_notify_event(self, event):
255 self.setLastIcon(None)
258 def do_pproperty_notify_event(self, event):
259 icon=self.iconAt(event.x, event.y)
263 icon.invalidate(self.window)
266 def do_motion_notify_event(self, event):
267 icon=self.iconAt(event.x, event.y)
268 if self.lasticon==icon:
271 self.setLastIcon(None)
273 icon.invalidate(self.window)
276 def do_button_press_event_old(self, event):
277 if event.type==gdk.BUTTON_PRESS:
286 def do_event1(self, event):
287 print "event:", event, event.type
289 def reloadIcons(self):
292 # def on_orientation_changed(self, orientation):
293 # print "orch:", orientation
297 class IconGridWidget(IconGrid, gtk.Widget):
298 def __init__(self, isconfig, config):
299 IconGrid.__init__(self, isconfig)
300 gtk.Widget.__init__(self)
304 IconGrid.do_realize(self, self.config)
306 self.setSize(self.size)
308 def setSize(self, size):
309 IconGrid.setSize(self, size)
311 w=self.size[0] * (self.config.iconsize + self.config.iconspace)
312 h=self.size[1] * (self.config.iconsize + self.config.iconspace)
314 self.set_size_request(w, h)
316 def do_realize(self):
317 screen=self.get_screen()
318 self.set_colormap(screen.get_rgba_colormap())
319 self.set_app_paintable(True)
321 self.set_flags(self.flags() | gtk.REALIZED)
323 self.window=gdk.Window(
324 self.get_parent_window(),
325 width=self.allocation.width,
326 height=self.allocation.height,
327 window_type=gdk.WINDOW_CHILD,
328 wclass=gdk.INPUT_OUTPUT,
329 event_mask=self.get_events() | gdk.EXPOSURE_MASK
330 | gdk.BUTTON_PRESS_MASK
331 | gdk.BUTTON_RELEASE_MASK
332 | gdk.BUTTON_MOTION_MASK
333 | gdk.POINTER_MOTION_MASK
334 | gdk.POINTER_MOTION_HINT_MASK
335 | gdk.ENTER_NOTIFY_MASK
336 | gdk.LEAVE_NOTIFY_MASK )
338 self.window.set_user_data(self)
339 self.style.attach(self.window)
341 # self.style.set_background(self.window, gtk.STATE_NORMAL)
342 self.window.move_resize(*self.allocation)
344 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
345 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
347 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
349 #gtk.Widget.do_realize(self)
350 #HomePluginItem.do_realize(self)
352 # screen=self.get_screen()
353 # self.set_colormap(screen.get_rgba_colormap())
354 # self.set_app_paintable(True)
356 def do_unrealize(self):
357 #self.window.set_user_data(None)
358 self.window.destroy()
360 #gobject.type_register(IconGrid)
361 gobject.type_register(IconGridWidget)
364 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: