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)
85 def setMode(self, mode):
87 if isinstance(self, gtk.Widget):
90 def iconAt(self, x, y):
91 """ Get icon at coordinates x,y. X and Y are in pixels """
93 w=config.iconsize + config.iconspace
99 x2=self.size - int(y/w) - 1
107 ret=self.icons.get(x,y)
111 def _draw(self, cr, event):
112 w=config.iconsize + config.iconspace
113 for x,y in self.icons:
115 x2=x * (config.iconsize + config.iconspace)
116 y2=y * (config.iconsize + config.iconspace)
118 x2=y * (config.iconsize + config.iconspace)
119 y2=(self.size-x-1) * (config.iconsize + config.iconspace)
121 # Only repaint the needed icons
122 rect=gdk.Rectangle(x2, y2, w, w)
123 t=rect.intersect(event.area)
124 if t.width==0 and t.height==0:
127 ico=self.icons.get(x,y)
128 ico.draw(cr, x2, y2, self.mode)
130 def do_expose_event(self, event):
131 cr=self.window.cairo_create()
133 cr.rectangle(event.area.x, event.area.y,
134 event.area.width, event.area.height)
138 self._draw(cr, event)
140 def setLastIcon(self, icon):
141 if icon==self.lasticon:
144 if self.lasticon!=None:
145 self.lasticon.doCancel()
146 self.lasticon.invalidate(self.window)
149 def do_button_press_event(self, event):
150 icon=self.iconAt(event.x, event.y)
153 # rect=gdk.Rectangle(event.x,event.y,1,1)
154 # rect=gdk.Rectangle(0, 0, 100, 100)
156 icon.invalidate(self.window)
157 self.setLastIcon(icon)
159 # gdk.Window.invalidate_rect(self.window, rect, True)
163 def do_button_release_event(self, event):
164 if self.lasticon!=None:
165 self.lasticon.invalidate(self.window)
166 self.lasticon.doRelease()
168 self.setLastIcon(None)
172 def do_leave_notify_event(self, event):
173 self.setLastIcon(None)
176 def do_pproperty_notify_event(self, event):
177 icon=self.iconAt(event.x, event.y)
181 icon.invalidate(self.window)
184 def do_motion_notify_event(self, event):
185 icon=self.iconAt(event.x, event.y)
186 if self.lasticon==icon:
189 self.setLastIcon(None)
191 icon.invalidate(self.window)
194 def do_button_press_event_old(self, event):
195 if event.type==gdk.BUTTON_PRESS:
204 def do_event1(self, event):
205 print "event:", event, event.type
207 def reloadIcons(self):
210 # def on_orientation_changed(self, orientation):
211 # print "orch:", orientation
215 class IconGridWidget(IconGrid, gtk.Widget):
216 def __init__(self, isconfig):
217 IconGrid.__init__(self, isconfig)
218 gtk.Widget.__init__(self)
221 w=4 * (config.iconsize + config.iconspace)
223 w=self.size * (config.iconsize + config.iconspace)
225 self.set_size_request(w, w)
227 def do_realize(self):
228 screen=self.get_screen()
229 self.set_colormap(screen.get_rgba_colormap())
230 self.set_app_paintable(True)
232 self.set_flags(self.flags() | gtk.REALIZED)
234 self.window=gdk.Window(
235 self.get_parent_window(),
236 width=self.allocation.width,
237 height=self.allocation.height,
238 window_type=gdk.WINDOW_CHILD,
239 wclass=gdk.INPUT_OUTPUT,
240 event_mask=self.get_events() | gdk.EXPOSURE_MASK
241 | gdk.BUTTON_PRESS_MASK
242 | gdk.BUTTON_RELEASE_MASK
243 | gdk.BUTTON_MOTION_MASK
244 | gdk.POINTER_MOTION_MASK
245 | gdk.POINTER_MOTION_HINT_MASK
246 | gdk.ENTER_NOTIFY_MASK
247 | gdk.LEAVE_NOTIFY_MASK )
249 self.window.set_user_data(self)
250 self.style.attach(self.window)
252 # self.style.set_background(self.window, gtk.STATE_NORMAL)
253 self.window.move_resize(*self.allocation)
255 # self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
256 # self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
258 # self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
260 #gtk.Widget.do_realize(self)
261 #HomePluginItem.do_realize(self)
263 # screen=self.get_screen()
264 # self.set_colormap(screen.get_rgba_colormap())
265 # self.set_app_paintable(True)
267 def do_unrealize(self):
268 #self.window.set_user_data(None)
269 self.window.destroy()
271 #gobject.type_register(IconGrid)
272 gobject.type_register(IconGridWidget)
275 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: