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__()
55 self.isconfig=isconfig
57 self.icons=Icons(isconfig)
62 w=config.size * config.iconsize + (config.size) * config.iconspace
63 #self.set_size_request(w, w)
65 self.icons.setSize(config.size)
67 self.lasticon=None # The last icon that got selected
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 setMode(self, mode):
81 def iconAt(self, x, y):
82 """ Get icon at coordinates x,y. X and Y are in pixels """
84 w=config.iconsize + config.iconspace
90 x2=config.size - int(y/w) - 1
94 ret=self.icons.get(x2,y2)
98 def _draw(self, cr, event):
99 # print "mode:", self.mode
100 # print "icons", len(self.icons)
102 w=config.iconsize + config.iconspace
103 for x,y in self.icons:
107 x2=x * (config.iconsize + config.iconspace)
108 y2=y * (config.iconsize + config.iconspace)
110 x2=y * (config.iconsize + config.iconspace)
111 y2=(config.size-x-1) * (config.iconsize + config.iconspace)
113 # Only repaint the needed icons
114 rect=gdk.Rectangle(x2, y2, w, w)
115 t=rect.intersect(event.area)
116 if t.width==0 and t.height==0:
119 # print "draw:", x, y
120 ico=self.icons.get(x,y)
121 ico.draw(cr, x2, y2, self.mode)
123 def do_expose_event(self, event):
124 cr=self.window.cairo_create()
126 cr.rectangle(event.area.x, event.area.y,
127 event.area.width, event.area.height)
131 self._draw(cr, event)
133 def setLastIcon(self, icon):
134 if icon==self.lasticon:
137 if self.lasticon!=None:
138 self.lasticon.doCancel()
139 self.lasticon.invalidate(self.window)
142 def do_button_press_event(self, event):
143 print "press", event.type
144 icon=self.iconAt(event.x, event.y)
147 # rect=gdk.Rectangle(event.x,event.y,1,1)
148 # rect=gdk.Rectangle(0, 0, 100, 100)
150 icon.invalidate(self.window)
151 self.setLastIcon(icon)
153 # gdk.Window.invalidate_rect(self.window, rect, True)
157 def do_button_release_event(self, event):
159 if self.lasticon!=None:
160 self.lasticon.invalidate(self.window)
161 self.lasticon.doRelease()
163 self.setLastIcon(None)
167 def do_leave_notify_event(self, event):
169 #print "leave", event.x, event.y
170 self.setLastIcon(None)
173 def do_pproperty_notify_event(self, event):
175 icon=self.iconAt(event.x, event.y)
179 icon.invalidate(self.window)
182 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):
195 if event.type==gdk.BUTTON_PRESS:
196 print "press", event.type
205 def do_event1(self, event):
206 print "event:", event, event.type
208 def butTest(self, arg):
211 # def on_orientation_changed(self, orientation):
212 # print "orch:", orientation
216 class IconGridWidget(IconGrid, gtk.Widget):
217 def __init__(self, isconfig):
218 IconGrid.__init__(self, isconfig)
219 gtk.Widget.__init__(self)
221 def do_realize(self):
222 screen=self.get_screen()
223 self.set_colormap(screen.get_rgba_colormap())
224 self.set_app_paintable(True)
226 self.set_flags(self.flags() | gtk.REALIZED)
228 self.window=gdk.Window(
229 self.get_parent_window(),
230 width=self.allocation.width,
231 height=self.allocation.height,
232 window_type=gdk.WINDOW_CHILD,
233 wclass=gdk.INPUT_OUTPUT,
234 event_mask=self.get_events() | gdk.EXPOSURE_MASK
235 | gdk.BUTTON_PRESS_MASK
236 | gdk.BUTTON_RELEASE_MASK
237 | gdk.BUTTON_MOTION_MASK
238 | gdk.POINTER_MOTION_MASK
239 | gdk.POINTER_MOTION_HINT_MASK
240 | gdk.ENTER_NOTIFY_MASK
241 | gdk.LEAVE_NOTIFY_MASK )
243 self.window.set_user_data(self)
244 self.style.attach(self.window)
246 # self.style.set_background(self.window, gtk.STATE_NORMAL)
247 self.window.move_resize(*self.allocation)
249 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
250 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
252 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
254 #gtk.Widget.do_realize(self)
255 #HomePluginItem.do_realize(self)
257 # screen=self.get_screen()
258 # self.set_colormap(screen.get_rgba_colormap())
259 # self.set_app_paintable(True)
261 def do_unrealize(self):
262 #self.window.set_user_data(None)
263 self.window.destroy()
265 #gobject.type_register(IconGrid)
266 gobject.type_register(IconGridWidget)
269 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: