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__()
56 self.isconfig=isconfig
59 self.lasticon=None # The last icon that got selected
61 self.draw_pending=False
63 def do_realize(self, config):
66 self.icons=Icons(self.isconfig, self.config)
71 def connect(self, what, *args):
72 if what in icon.signals:
73 self.icons.connect(what, *args)
75 super(IconGrid, self).connect(what, *args)
77 def setSize(self, size):
79 self.icons.setSize(size)
82 ret=self.icons.getSize()
85 def setMode(self, mode):
87 if not isinstance(self, gtk.Widget):
91 v=self.get_property('is-on-current-desktop')
95 self.draw_pending=True
99 def iconAt(self, x, y):
100 """ Get icon at coordinates x,y. X and Y are in pixels """
102 w=self.config.iconsize + self.config.iconspace
104 if self.mode=='l' or self.config.getIndiv():
108 x2=self.size[1] - int(y/w) - 1
116 ret=self.icons.get(x,y)
120 def _draw(self, cr, event):
121 self.draw_pending=False
123 w=self.config.iconsize + self.config.iconspace
124 for x,y in self.icons:
125 if self.mode=='l' or self.config.getIndiv():
126 x2=x * (self.config.iconsize + self.config.iconspace)
127 y2=y * (self.config.iconsize + self.config.iconspace)
129 x2=y * (self.config.iconsize + self.config.iconspace)
130 y2=(self.size[1]-x-1) * \
131 (self.config.iconsize + self.config.iconspace)
133 # Only repaint the needed icons
134 rect=gdk.Rectangle(x2, y2, w, w)
135 t=rect.intersect(event.area)
136 if t.width==0 and t.height==0:
139 ico=self.icons.get(x,y)
140 ico.draw(cr, x2, y2, self.mode)
142 def do_expose_event(self, event):
143 cr=self.window.cairo_create()
145 cr.rectangle(event.area.x, event.area.y,
146 event.area.width, event.area.height)
150 self._draw(cr, event)
152 def setLastIcon(self, icon):
153 if icon==self.lasticon:
156 if self.lasticon!=None:
157 self.lasticon.doCancel()
158 self.lasticon.invalidate(self.window)
161 def do_button_press_event(self, event):
162 icon=self.iconAt(event.x, event.y)
165 # rect=gdk.Rectangle(event.x,event.y,1,1)
166 # rect=gdk.Rectangle(0, 0, 100, 100)
168 icon.invalidate(self.window)
169 self.setLastIcon(icon)
171 # gdk.Window.invalidate_rect(self.window, rect, True)
175 def do_button_release_event(self, event):
176 if self.lasticon!=None:
177 self.lasticon.invalidate(self.window)
178 self.lasticon.doRelease()
180 self.setLastIcon(None)
184 def do_leave_notify_event(self, event):
185 self.setLastIcon(None)
188 def do_pproperty_notify_event(self, event):
189 icon=self.iconAt(event.x, event.y)
193 icon.invalidate(self.window)
196 def do_motion_notify_event(self, event):
197 icon=self.iconAt(event.x, event.y)
198 if self.lasticon==icon:
201 self.setLastIcon(None)
203 icon.invalidate(self.window)
206 def do_button_press_event_old(self, event):
207 if event.type==gdk.BUTTON_PRESS:
216 def do_event1(self, event):
217 print "event:", event, event.type
219 def reloadIcons(self):
222 # def on_orientation_changed(self, orientation):
223 # print "orch:", orientation
227 class IconGridWidget(IconGrid, gtk.Widget):
228 def __init__(self, isconfig, config):
229 IconGrid.__init__(self, isconfig)
230 gtk.Widget.__init__(self)
234 IconGrid.do_realize(self, self.config)
237 maxsz=self.config.getMaxSize()
238 w=maxsz[0] * (self.config.iconsize + self.config.iconspace)
239 h=maxsz[1] * (self.config.iconsize + self.config.iconspace)
241 w=self.size[0] * (self.config.iconsize + self.config.iconspace)
242 h=self.size[1] * (self.config.iconsize + self.config.iconspace)
244 self.set_size_request(w, h)
246 def do_realize(self):
247 screen=self.get_screen()
248 self.set_colormap(screen.get_rgba_colormap())
249 self.set_app_paintable(True)
251 self.set_flags(self.flags() | gtk.REALIZED)
253 self.window=gdk.Window(
254 self.get_parent_window(),
255 width=self.allocation.width,
256 height=self.allocation.height,
257 window_type=gdk.WINDOW_CHILD,
258 wclass=gdk.INPUT_OUTPUT,
259 event_mask=self.get_events() | gdk.EXPOSURE_MASK
260 | gdk.BUTTON_PRESS_MASK
261 | gdk.BUTTON_RELEASE_MASK
262 | gdk.BUTTON_MOTION_MASK
263 | gdk.POINTER_MOTION_MASK
264 | gdk.POINTER_MOTION_HINT_MASK
265 | gdk.ENTER_NOTIFY_MASK
266 | gdk.LEAVE_NOTIFY_MASK )
268 self.window.set_user_data(self)
269 self.style.attach(self.window)
271 # self.style.set_background(self.window, gtk.STATE_NORMAL)
272 self.window.move_resize(*self.allocation)
274 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
275 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
277 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
279 #gtk.Widget.do_realize(self)
280 #HomePluginItem.do_realize(self)
282 # screen=self.get_screen()
283 # self.set_colormap(screen.get_rgba_colormap())
284 # self.set_app_paintable(True)
286 def do_unrealize(self):
287 #self.window.set_user_data(None)
288 self.window.destroy()
290 #gobject.type_register(IconGrid)
291 gobject.type_register(IconGridWidget)
294 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: