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):
82 print "igw::setSize", size
83 # config.setSize(size)
85 self.icons.setSize(size)
87 def setMode(self, mode):
89 if isinstance(self, gtk.Widget):
92 def iconAt(self, x, y):
93 """ Get icon at coordinates x,y. X and Y are in pixels """
95 w=config.iconsize + config.iconspace
101 x2=self.size - int(y/w) - 1
104 print "x2,y2", x2, y2
110 ret=self.icons.get(x,y)
114 def _draw(self, cr, event):
115 # print "mode:", self.mode
116 # print "icons", len(self.icons)
118 w=config.iconsize + config.iconspace
119 for x,y in self.icons:
123 x2=x * (config.iconsize + config.iconspace)
124 y2=y * (config.iconsize + config.iconspace)
126 x2=y * (config.iconsize + config.iconspace)
127 y2=(self.size-x-1) * (config.iconsize + config.iconspace)
129 # Only repaint the needed icons
130 rect=gdk.Rectangle(x2, y2, w, w)
131 t=rect.intersect(event.area)
132 if t.width==0 and t.height==0:
135 # print "draw:", x, y
136 ico=self.icons.get(x,y)
137 ico.draw(cr, x2, y2, self.mode)
139 def do_expose_event(self, event):
140 cr=self.window.cairo_create()
142 cr.rectangle(event.area.x, event.area.y,
143 event.area.width, event.area.height)
147 self._draw(cr, event)
149 def setLastIcon(self, icon):
150 if icon==self.lasticon:
153 if self.lasticon!=None:
154 self.lasticon.doCancel()
155 self.lasticon.invalidate(self.window)
158 def do_button_press_event(self, event):
159 print "press", event.type
160 icon=self.iconAt(event.x, event.y)
163 # rect=gdk.Rectangle(event.x,event.y,1,1)
164 # rect=gdk.Rectangle(0, 0, 100, 100)
166 icon.invalidate(self.window)
167 self.setLastIcon(icon)
169 # gdk.Window.invalidate_rect(self.window, rect, True)
173 def do_button_release_event(self, event):
175 if self.lasticon!=None:
176 self.lasticon.invalidate(self.window)
177 self.lasticon.doRelease()
179 self.setLastIcon(None)
183 def do_leave_notify_event(self, event):
185 #print "leave", event.x, event.y
186 self.setLastIcon(None)
189 def do_pproperty_notify_event(self, event):
191 icon=self.iconAt(event.x, event.y)
195 icon.invalidate(self.window)
198 def do_motion_notify_event(self, event):
200 icon=self.iconAt(event.x, event.y)
201 if self.lasticon==icon:
204 self.setLastIcon(None)
206 icon.invalidate(self.window)
209 def do_button_press_event_old(self, event):
211 if event.type==gdk.BUTTON_PRESS:
212 print "press", event.type
221 def do_event1(self, event):
222 print "event:", event, event.type
224 def butTest(self, arg):
227 def reloadIcons(self):
230 # def on_orientation_changed(self, orientation):
231 # print "orch:", orientation
235 class IconGridWidget(IconGrid, gtk.Widget):
236 def __init__(self, isconfig):
237 IconGrid.__init__(self, isconfig)
238 gtk.Widget.__init__(self)
241 w=4 * (config.iconsize + config.iconspace)
243 w=self.size * (config.iconsize + config.iconspace)
245 self.set_size_request(w, w)
247 def do_realize(self):
248 screen=self.get_screen()
249 self.set_colormap(screen.get_rgba_colormap())
250 self.set_app_paintable(True)
252 self.set_flags(self.flags() | gtk.REALIZED)
254 self.window=gdk.Window(
255 self.get_parent_window(),
256 width=self.allocation.width,
257 height=self.allocation.height,
258 window_type=gdk.WINDOW_CHILD,
259 wclass=gdk.INPUT_OUTPUT,
260 event_mask=self.get_events() | gdk.EXPOSURE_MASK
261 | gdk.BUTTON_PRESS_MASK
262 | gdk.BUTTON_RELEASE_MASK
263 | gdk.BUTTON_MOTION_MASK
264 | gdk.POINTER_MOTION_MASK
265 | gdk.POINTER_MOTION_HINT_MASK
266 | gdk.ENTER_NOTIFY_MASK
267 | gdk.LEAVE_NOTIFY_MASK )
269 self.window.set_user_data(self)
270 self.style.attach(self.window)
272 # self.style.set_background(self.window, gtk.STATE_NORMAL)
273 self.window.move_resize(*self.allocation)
275 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
276 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
278 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
280 #gtk.Widget.do_realize(self)
281 #HomePluginItem.do_realize(self)
283 # screen=self.get_screen()
284 # self.set_colormap(screen.get_rgba_colormap())
285 # self.set_app_paintable(True)
287 def do_unrealize(self):
288 #self.window.set_user_data(None)
289 self.window.destroy()
291 #gobject.type_register(IconGrid)
292 gobject.type_register(IconGridWidget)
295 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: