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 def do_realize(self, config):
64 self.icons=Icons(self.isconfig, self.config)
69 def connect(self, what, *args):
70 if what in icon.signals:
71 self.icons.connect(what, *args)
73 super(IconGrid, self).connect(what, *args)
75 def setSize(self, size):
77 self.icons.setSize(size)
80 ret=self.icons.getSize()
83 def setMode(self, mode):
85 if isinstance(self, gtk.Widget):
88 def iconAt(self, x, y):
89 """ Get icon at coordinates x,y. X and Y are in pixels """
91 w=self.config.iconsize + self.config.iconspace
93 if self.mode=='l' or self.config.getIndiv():
97 x2=self.size[1] - int(y/w) - 1
105 ret=self.icons.get(x,y)
109 def _draw(self, cr, event):
110 w=self.config.iconsize + self.config.iconspace
111 for x,y in self.icons:
112 if self.mode=='l' or self.config.getIndiv():
113 x2=x * (self.config.iconsize + self.config.iconspace)
114 y2=y * (self.config.iconsize + self.config.iconspace)
116 x2=y * (self.config.iconsize + self.config.iconspace)
117 y2=(self.size[1]-x-1) * \
118 (self.config.iconsize + self.config.iconspace)
120 # Only repaint the needed icons
121 rect=gdk.Rectangle(x2, y2, w, w)
122 t=rect.intersect(event.area)
123 if t.width==0 and t.height==0:
126 ico=self.icons.get(x,y)
127 ico.draw(cr, x2, y2, self.mode)
129 def do_expose_event(self, event):
130 cr=self.window.cairo_create()
132 cr.rectangle(event.area.x, event.area.y,
133 event.area.width, event.area.height)
137 self._draw(cr, event)
139 def setLastIcon(self, icon):
140 if icon==self.lasticon:
143 if self.lasticon!=None:
144 self.lasticon.doCancel()
145 self.lasticon.invalidate(self.window)
148 def do_button_press_event(self, event):
149 icon=self.iconAt(event.x, event.y)
152 # rect=gdk.Rectangle(event.x,event.y,1,1)
153 # rect=gdk.Rectangle(0, 0, 100, 100)
155 icon.invalidate(self.window)
156 self.setLastIcon(icon)
158 # gdk.Window.invalidate_rect(self.window, rect, True)
162 def do_button_release_event(self, event):
163 if self.lasticon!=None:
164 self.lasticon.invalidate(self.window)
165 self.lasticon.doRelease()
167 self.setLastIcon(None)
171 def do_leave_notify_event(self, event):
172 self.setLastIcon(None)
175 def do_pproperty_notify_event(self, event):
176 icon=self.iconAt(event.x, event.y)
180 icon.invalidate(self.window)
183 def do_motion_notify_event(self, event):
184 icon=self.iconAt(event.x, event.y)
185 if self.lasticon==icon:
188 self.setLastIcon(None)
190 icon.invalidate(self.window)
193 def do_button_press_event_old(self, event):
194 if event.type==gdk.BUTTON_PRESS:
203 def do_event1(self, event):
204 print "event:", event, event.type
206 def reloadIcons(self):
209 # def on_orientation_changed(self, orientation):
210 # print "orch:", orientation
214 class IconGridWidget(IconGrid, gtk.Widget):
215 def __init__(self, isconfig, config):
216 IconGrid.__init__(self, isconfig)
217 gtk.Widget.__init__(self)
221 IconGrid.do_realize(self, self.config)
224 maxsz=self.config.getMaxSize()
225 w=maxsz[0] * (self.config.iconsize + self.config.iconspace)
226 h=maxsz[1] * (self.config.iconsize + self.config.iconspace)
228 w=self.size[0] * (self.config.iconsize + self.config.iconspace)
229 h=self.size[1] * (self.config.iconsize + self.config.iconspace)
231 self.set_size_request(w, h)
233 def do_realize(self):
234 screen=self.get_screen()
235 self.set_colormap(screen.get_rgba_colormap())
236 self.set_app_paintable(True)
238 self.set_flags(self.flags() | gtk.REALIZED)
240 self.window=gdk.Window(
241 self.get_parent_window(),
242 width=self.allocation.width,
243 height=self.allocation.height,
244 window_type=gdk.WINDOW_CHILD,
245 wclass=gdk.INPUT_OUTPUT,
246 event_mask=self.get_events() | gdk.EXPOSURE_MASK
247 | gdk.BUTTON_PRESS_MASK
248 | gdk.BUTTON_RELEASE_MASK
249 | gdk.BUTTON_MOTION_MASK
250 | gdk.POINTER_MOTION_MASK
251 | gdk.POINTER_MOTION_HINT_MASK
252 | gdk.ENTER_NOTIFY_MASK
253 | gdk.LEAVE_NOTIFY_MASK )
255 self.window.set_user_data(self)
256 self.style.attach(self.window)
258 # self.style.set_background(self.window, gtk.STATE_NORMAL)
259 self.window.move_resize(*self.allocation)
261 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
262 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
264 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
266 #gtk.Widget.do_realize(self)
267 #HomePluginItem.do_realize(self)
269 # screen=self.get_screen()
270 # self.set_colormap(screen.get_rgba_colormap())
271 # self.set_app_paintable(True)
273 def do_unrealize(self):
274 #self.window.set_user_data(None)
275 self.window.destroy()
277 #gobject.type_register(IconGrid)
278 gobject.type_register(IconGridWidget)
281 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: