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
44 ico=getIconPath(name, config.iconsize)
45 ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, config.iconsize,
50 #class IconGrid(gtk.Widget, FremantleRotation):
51 class IconGrid(object): #(gobject.GObject):
52 def __init__(self, isconfig=False):
53 # self.__gobject_init__()
57 self.isconfig=isconfig
59 self.icons=Icons(isconfig)
64 # w=(config.getSize() * config.iconsize) + \
65 # (config.getSize()) * config.iconspace
66 #self.set_size_request(w, w)
68 # self.setSize(config.getSize())
71 self.lasticon=None # The last icon that got selected
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):
91 if isinstance(self, gtk.Widget):
94 def iconAt(self, x, y):
95 """ Get icon at coordinates x,y. X and Y are in pixels """
97 w=config.iconsize + config.iconspace
99 if self.mode=='l' or config.getIndiv():
103 x2=self.size[1] - int(y/w) - 1
111 ret=self.icons.get(x,y)
115 def _draw(self, cr, event):
116 w=config.iconsize + config.iconspace
117 for x,y in self.icons:
118 if self.mode=='l' or config.getIndiv():
119 x2=x * (config.iconsize + config.iconspace)
120 y2=y * (config.iconsize + config.iconspace)
122 x2=y * (config.iconsize + config.iconspace)
123 y2=(self.size[1]-x-1) * (config.iconsize + config.iconspace)
125 # Only repaint the needed icons
126 rect=gdk.Rectangle(x2, y2, w, w)
127 t=rect.intersect(event.area)
128 if t.width==0 and t.height==0:
131 ico=self.icons.get(x,y)
132 ico.draw(cr, x2, y2, self.mode)
134 def do_expose_event(self, event):
135 cr=self.window.cairo_create()
137 cr.rectangle(event.area.x, event.area.y,
138 event.area.width, event.area.height)
142 self._draw(cr, event)
144 def setLastIcon(self, icon):
145 if icon==self.lasticon:
148 if self.lasticon!=None:
149 self.lasticon.doCancel()
150 self.lasticon.invalidate(self.window)
153 def do_button_press_event(self, event):
154 icon=self.iconAt(event.x, event.y)
157 # rect=gdk.Rectangle(event.x,event.y,1,1)
158 # rect=gdk.Rectangle(0, 0, 100, 100)
160 icon.invalidate(self.window)
161 self.setLastIcon(icon)
163 # gdk.Window.invalidate_rect(self.window, rect, True)
167 def do_button_release_event(self, event):
168 if self.lasticon!=None:
169 self.lasticon.invalidate(self.window)
170 self.lasticon.doRelease()
172 self.setLastIcon(None)
176 def do_leave_notify_event(self, event):
177 self.setLastIcon(None)
180 def do_pproperty_notify_event(self, event):
181 icon=self.iconAt(event.x, event.y)
185 icon.invalidate(self.window)
188 def do_motion_notify_event(self, event):
189 icon=self.iconAt(event.x, event.y)
190 if self.lasticon==icon:
193 self.setLastIcon(None)
195 icon.invalidate(self.window)
198 def do_button_press_event_old(self, event):
199 if event.type==gdk.BUTTON_PRESS:
208 def do_event1(self, event):
209 print "event:", event, event.type
211 def reloadIcons(self):
214 # def on_orientation_changed(self, orientation):
215 # print "orch:", orientation
219 class IconGridWidget(IconGrid, gtk.Widget):
220 def __init__(self, isconfig):
221 IconGrid.__init__(self, isconfig)
222 gtk.Widget.__init__(self)
225 maxsz=config.getMaxSize()
226 w=maxsz[0] * (config.iconsize + config.iconspace)
227 h=maxsz[1] * (config.iconsize + config.iconspace)
229 w=self.size[0] * (config.iconsize + config.iconspace)
230 h=self.size[1] * (config.iconsize + config.iconspace)
232 self.set_size_request(w, h)
234 def do_realize(self):
235 screen=self.get_screen()
236 self.set_colormap(screen.get_rgba_colormap())
237 self.set_app_paintable(True)
239 self.set_flags(self.flags() | gtk.REALIZED)
241 self.window=gdk.Window(
242 self.get_parent_window(),
243 width=self.allocation.width,
244 height=self.allocation.height,
245 window_type=gdk.WINDOW_CHILD,
246 wclass=gdk.INPUT_OUTPUT,
247 event_mask=self.get_events() | gdk.EXPOSURE_MASK
248 | gdk.BUTTON_PRESS_MASK
249 | gdk.BUTTON_RELEASE_MASK
250 | gdk.BUTTON_MOTION_MASK
251 | gdk.POINTER_MOTION_MASK
252 | gdk.POINTER_MOTION_HINT_MASK
253 | gdk.ENTER_NOTIFY_MASK
254 | gdk.LEAVE_NOTIFY_MASK )
256 self.window.set_user_data(self)
257 self.style.attach(self.window)
259 # self.style.set_background(self.window, gtk.STATE_NORMAL)
260 self.window.move_resize(*self.allocation)
262 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
263 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
265 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
267 #gtk.Widget.do_realize(self)
268 #HomePluginItem.do_realize(self)
270 # screen=self.get_screen()
271 # self.set_colormap(screen.get_rgba_colormap())
272 # self.set_app_paintable(True)
274 def do_unrealize(self):
275 #self.window.set_user_data(None)
276 self.window.destroy()
278 #gobject.type_register(IconGrid)
279 gobject.type_register(IconGridWidget)
282 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: