(no commit message)
authorStefanos Harhalakis <v13@v13.gr>
Mon, 21 Jun 2010 17:54:49 +0000 (17:54 +0000)
committerStefanos Harhalakis <v13@v13.gr>
Mon, 21 Jun 2010 17:54:49 +0000 (17:54 +0000)
apps.py
icon.py [new file with mode: 0755]
icongrid.py [new file with mode: 0755]
icons.py [new file with mode: 0755]
widget.py
win_config.py [new file with mode: 0755]

diff --git a/apps.py b/apps.py
index 8b0f9a8..13c745e 100755 (executable)
--- a/apps.py
+++ b/apps.py
@@ -24,6 +24,8 @@ __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
 
 import os
 
+from gettext import translation
+
 #from xdg.IconTheme import getIconPath
 
 appdir="/usr/share/applications/hildon"
@@ -41,10 +43,23 @@ def readOneFn(fn):
        'exec':     None,
        'icon':     None,
        'iconpath': None,
+       'domain':   None,
        }
+    inde=False
     for line in f:
        line=line.strip()
-       if line.startswith('Name='):
+       if line=='[Desktop Entry]':
+           inde=True
+           continue
+
+       if inde==False:
+           continue
+
+       # Reached another block
+       if line.startswith('[') and inde:
+           break
+
+       elif line.startswith('Name='):
            l=line[5:]
            ret['name']=l
        elif line.startswith('Exec='):
@@ -54,6 +69,19 @@ def readOneFn(fn):
            l=line[5:]
            ret['icon']=l
            # ret['iconpath']=getIconPath(l)
+       elif line.startswith('X-Text-Domain='):
+           l=line[14:]
+           ret['domain']=l
+
+    if ret['domain']!=None:
+       try:
+           c=translation(ret['domain'])
+       except IOError, e:
+           c=None
+
+       if c!=None:
+           ret['name0']=ret['name']
+           ret['name']=c.gettext(ret['name0'])
 
     return(ret)
 
@@ -74,6 +102,8 @@ def scan():
     for f in files:
        if not f.endswith('.desktop'):
            continue
+       if f.startswith('catorise-'):
+           continue
        dt=readOneFn(f)
        t=f[:-8]
        ret[t]=dt
diff --git a/icon.py b/icon.py
new file mode 100755 (executable)
index 0000000..e3e639e
--- /dev/null
+++ b/icon.py
@@ -0,0 +1,212 @@
+#!/usr/bin/env python
+# coding=UTF-8
+# 
+# Copyright (C) 2010 Stefanos Harhalakis
+#
+# This file is part of wifieye.
+#
+# wifieye is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wifieye is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with wifieye.  If not, see <http://www.gnu.org/licenses/>.
+#
+# $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
+
+__version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
+
+import gtk
+import gobject
+import hildon
+from hildondesktop import *
+from gtk import gdk
+from math import pi
+import cairo
+import time
+
+from portrait import FremantleRotation
+import launcher
+from xdg.IconTheme import getIconPath
+
+
+import config
+import apps
+
+def getIcon(name):
+    ico=getIconPath(name, config.iconsize)
+    ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, config.iconsize,
+       config.iconsize)
+
+    return(ret)
+
+class Icon(gobject.GObject):
+    def __init__(self, isconfig):
+       self.__gobject_init__()
+
+       self.isconfig=isconfig
+
+       self.name=None
+       self.icon=None
+       self.lastpress=0
+       self.ispressed=False
+
+       self.x=0
+       self.y=0
+
+       self.presstime=0.25
+
+       self.window=None
+
+       self.clickcount=0
+
+    def timePressed(self):
+       """ return how much time a button is pressed """
+       dt=time.time() - self.lastpress
+
+       return(dt)
+
+    def setApp(self, dt):
+       self.name=dt['id']
+       self.icon=dt['icon2']
+       self.invalidate()
+
+    def getSize(self):
+       return(config.iconsize+config.iconspace)
+
+    def draw(self, cr, x, y, mode):
+       #print "draw", x, y, mode
+       self.x=x
+       self.y=y
+
+       if self.icon==None and not self.isconfig:
+           return
+
+       cr.save()
+       cr.set_source_rgba(0.1, 0.1, 0.1, 1)
+       cr.set_line_width(5)
+
+       if self.ispressed:
+           t=1.0 * min(self.timePressed(), self.presstime) / self.presstime
+           g=0.3+0.5*t
+           b=0.3+0.7*t
+           cr.set_source_rgba(0, g, b, 0.7)
+       else:
+           cr.set_source_rgba(0.3, 0.3, 0.3, 0.7)
+
+       x3=x + (config.iconspace/6)
+       y3=y + (config.iconspace/6)
+
+       r=10    # Radius
+       w=config.iconsize+(config.iconspace*2/3)
+
+       cr.move_to(x3+r, y3)
+       cr.arc(x3+w-r,  y3+r,   r,          pi*1.5, pi*2)
+       cr.arc(x3+w-r,  y3+w-r, r,          0,      pi*0.5)
+       cr.arc(x3+r,    y3+w-r, r,          pi*0.5, pi)
+       cr.arc(x3+r,    y3+r,   r,          pi,     pi*1.5)
+
+       cr.stroke_preserve()
+       cr.fill()
+       cr.clip()
+       cr.paint()
+       cr.restore()
+
+       if self.icon==None:
+           return
+
+       icon=self.icon
+
+       if mode=='l':
+           icon2=icon
+       else:
+           icon2=icon.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
+
+       cr.save()
+       x3=x + (config.iconspace/2)
+       y3=y + (config.iconspace/2)
+       cr.set_source_pixbuf(icon2, x3, y3)
+       cr.paint()
+       cr.restore()
+
+       return(False)
+
+    def timerPressed(self):
+       #print "timer"
+
+       if not self.ispressed:
+           return(False)
+
+       self.invalidate()
+
+       if self.timePressed()>self.presstime:
+           ret=False
+       else:
+           ret=True
+
+       return(ret)
+
+    def doPress(self):
+       #print "doPress()"
+       # Double-time: time for pressed and time for not-pressed
+       if time.time() - self.lastpress > self.presstime*2:
+           self.clickcount=0
+
+       self.lastpress=time.time()
+       self.ispressed=True
+       gobject.timeout_add(20, self.timerPressed)
+       #print "doPress() end"
+
+    def doRelease(self):
+       print "doRelease()"
+       dt=time.time() - self.lastpress
+       self.ispressed=False
+       self.invalidate()
+       if dt<=self.presstime:
+           self.clickcount+=1
+           if self.clickcount==1:
+               print "click"
+               self.emit('click')
+           elif self.clickcount==2:
+               print "double-click"
+               self.emit('double-click')
+           if self.clickcount==3:
+               print "tripple-click"
+               self.emit('tripple-click')
+               self.clickcount=0
+       elif dt>self.presstime and dt<2:
+           print "long-press"
+           self.emit('long-press')
+
+    def doCancel(self):
+       print "doCancel()"
+       self.ispressed=False
+
+    def invalidate(self, window=None):
+       if window==None:
+           window=self.window
+       else:
+           self.window=window
+       
+       if window==None:
+           return
+
+       w=config.iconsize + config.iconspace
+       rect=gdk.Rectangle(self.x, self.y, w, w)
+       #print "rect", self.x, self.y, w, w
+       gdk.Window.invalidate_rect(window, rect, True)
+
+gobject.type_register(Icon)
+signals=['click', 'double-click', 'tripple-click', 'long-press']
+for s in signals:
+    gobject.signal_new(s, Icon, gobject.SIGNAL_RUN_FIRST,
+       gobject.TYPE_NONE, ())
+
+# vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
+
diff --git a/icongrid.py b/icongrid.py
new file mode 100755 (executable)
index 0000000..4502207
--- /dev/null
@@ -0,0 +1,270 @@
+#!/usr/bin/env python
+# coding=UTF-8
+# 
+# Copyright (C) 2010 Stefanos Harhalakis
+#
+# This file is part of wifieye.
+#
+# wifieye is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wifieye is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with wifieye.  If not, see <http://www.gnu.org/licenses/>.
+#
+# $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
+
+__version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
+
+import gtk
+import gobject
+import hildon
+from hildondesktop import *
+from gtk import gdk
+from math import pi
+import cairo
+import time
+
+from portrait import FremantleRotation
+from xdg.IconTheme import getIconPath
+
+import config
+import apps
+import icon
+from icon import Icon
+from icons import Icons
+
+def getIcon(name):
+    ico=getIconPath(name, config.iconsize)
+    ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, config.iconsize,
+       config.iconsize)
+
+    return(ret)
+
+#class IconGrid(gtk.Widget, FremantleRotation):
+class IconGrid(object):        #(gobject.GObject):
+    def __init__(self, isconfig=False):
+#      self.__gobject_init__()
+
+       self.isconfig=isconfig
+
+       self.icons=Icons(isconfig)
+
+       self.setMode('l')
+
+       # Maybe fix those:
+       w=config.size * config.iconsize + (config.size) * config.iconspace
+       #self.set_size_request(w, w)
+
+       self.icons.setSize(config.size)
+
+       self.lasticon=None  # The last icon that got selected
+
+       self.icons.load()
+
+    def connect(self, what, *args):
+       if what in icon.signals:
+           self.icons.connect(what, *args)
+       else:
+           super(IconGrid, self).connect(what, *args)
+
+    def setMode(self, mode):
+       self.mode=mode
+       self.queue_draw()
+
+    def iconAt(self, x, y):
+       """ Get icon at coordinates x,y. X and Y are in pixels """
+
+       w=config.iconsize + config.iconspace
+
+       if self.mode=='l':
+           x2=int(x / w)
+           y2=int(y / w)
+       else:
+           x2=config.size - int(y/w) - 1
+           y2=int(x/w)
+
+       print "x2,y2", x2, y2
+       ret=self.icons.get(x2,y2)
+
+       return(ret)
+
+    def _draw(self, cr, event):
+#      print "mode:", self.mode
+#      print "icons", len(self.icons)
+
+       w=config.iconsize + config.iconspace
+       for x,y in self.icons:
+#          print x, y
+
+           if self.mode=='l':
+               x2=x * (config.iconsize + config.iconspace)
+               y2=y * (config.iconsize + config.iconspace)
+           else:
+               x2=y * (config.iconsize + config.iconspace)
+               y2=(config.size-x-1) * (config.iconsize + config.iconspace)
+
+           # Only repaint the needed icons
+           rect=gdk.Rectangle(x2, y2, w, w)
+           t=rect.intersect(event.area)
+           if t.width==0 and t.height==0:
+               continue
+
+#          print "draw:", x, y
+           ico=self.icons.get(x,y)
+           ico.draw(cr, x2, y2, self.mode)
+
+    def do_expose_event(self, event):
+       cr=self.window.cairo_create()
+
+       cr.rectangle(event.area.x, event.area.y,
+           event.area.width, event.area.height)
+
+       cr.clip()
+
+       self._draw(cr, event)
+
+    def setLastIcon(self, icon):
+       if icon==self.lasticon:
+           return
+
+       if self.lasticon!=None:
+           self.lasticon.doCancel()
+           self.lasticon.invalidate(self.window)
+       self.lasticon=icon
+
+    def do_button_press_event(self, event):
+       print "press", event.type
+       icon=self.iconAt(event.x, event.y)
+       if icon==None:
+           return
+#      rect=gdk.Rectangle(event.x,event.y,1,1)
+#      rect=gdk.Rectangle(0, 0, 100, 100)
+       icon.doPress()
+       icon.invalidate(self.window)
+       self.setLastIcon(icon)
+
+#      gdk.Window.invalidate_rect(self.window, rect, True)
+
+       return(True)
+
+    def do_button_release_event(self, event):
+       print "release"
+       if self.lasticon!=None:
+           self.lasticon.invalidate(self.window)
+           self.lasticon.doRelease()
+
+       self.setLastIcon(None)
+
+       return(True)
+
+    def do_leave_notify_event(self, event):
+       print "leave"
+       #print "leave", event.x, event.y
+       self.setLastIcon(None)
+       return(True)
+
+    def do_pproperty_notify_event(self, event):
+       print "property"
+       icon=self.iconAt(event.x, event.y)
+       if icon==None:
+           return
+       icon.doCancel()
+       icon.invalidate(self.window)
+       return(True)
+
+    def do_motion_notify_event(self, event):
+       print "motion"
+       icon=self.iconAt(event.x, event.y)
+       if self.lasticon==icon:
+           return(True)
+
+       self.setLastIcon(None)
+       icon.doCancel()
+       icon.invalidate(self.window)
+       return(True)
+
+    def do_button_press_event_old(self, event):
+       #print "press"
+       if event.type==gdk.BUTTON_PRESS:
+           print "press", event.type
+           if self.mode=='p':
+               self.setMode('l')
+           else:
+               self.setMode('p')
+           self.queue_draw()
+       return True
+
+    # For debugging
+    def do_event1(self, event):
+       print "event:", event, event.type
+
+    def butTest(self, arg):
+       print "but", arg
+
+#    def on_orientation_changed(self, orientation):
+#      print "orch:", orientation
+#      o=orientation[0]
+#      self.setMode(o)
+
+class IconGridWidget(IconGrid, gtk.Widget):
+    def __init__(self, isconfig):
+       IconGrid.__init__(self, isconfig)
+       gtk.Widget.__init__(self)
+
+    def do_realize(self):
+       screen=self.get_screen()
+       self.set_colormap(screen.get_rgba_colormap())
+       self.set_app_paintable(True)
+
+       self.set_flags(self.flags() | gtk.REALIZED)
+
+       self.window=gdk.Window(
+           self.get_parent_window(),
+           width=self.allocation.width,
+           height=self.allocation.height,
+           window_type=gdk.WINDOW_CHILD,
+           wclass=gdk.INPUT_OUTPUT,
+           event_mask=self.get_events() | gdk.EXPOSURE_MASK
+               | gdk.BUTTON_PRESS_MASK 
+               | gdk.BUTTON_RELEASE_MASK 
+               | gdk.BUTTON_MOTION_MASK
+               | gdk.POINTER_MOTION_MASK
+               | gdk.POINTER_MOTION_HINT_MASK 
+               | gdk.ENTER_NOTIFY_MASK
+               | gdk.LEAVE_NOTIFY_MASK )
+
+       self.window.set_user_data(self)
+       self.style.attach(self.window)
+
+#      self.style.set_background(self.window, gtk.STATE_NORMAL)
+       self.window.move_resize(*self.allocation)
+
+#      self.pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
+#            self.window, self.style.bg[gtk.STATE_NORMAL], STAR_PIXMAP)
+       
+#      self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
+
+       #gtk.Widget.do_realize(self)
+       #HomePluginItem.do_realize(self)
+
+#      screen=self.get_screen()
+#      self.set_colormap(screen.get_rgba_colormap())
+#      self.set_app_paintable(True)
+
+    def do_unrealize(self):
+       #self.window.set_user_data(None)
+       self.window.destroy()
+
+#gobject.type_register(IconGrid)
+gobject.type_register(IconGridWidget)
+
+
+# vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
+
diff --git a/icons.py b/icons.py
new file mode 100755 (executable)
index 0000000..7846958
--- /dev/null
+++ b/icons.py
@@ -0,0 +1,140 @@
+#!/usr/bin/env python
+# coding=UTF-8
+# 
+# Copyright (C) 2010 Stefanos Harhalakis
+#
+# This file is part of wifieye.
+#
+# wifieye is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wifieye is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with wifieye.  If not, see <http://www.gnu.org/licenses/>.
+#
+# $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
+
+__version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
+
+import config
+import apps
+import icon
+from icon import getIcon, Icon
+
+import gobject
+
+class IconIter:
+    def __init__(self, items):
+       self.iter=items.__iter__()
+
+    def __iter__(self):
+       ret=self.iter.__iter__()
+       return(ret)
+
+    def next(self):
+       ret=self.iter.next()
+       return(ret)
+
+class Icons(gobject.GObject):
+    def __init__(self, isconfig):
+       self.__gobject_init__()
+       self.icons={}
+       self.size=0
+       self.isconfig=isconfig
+
+    @classmethod
+    def register_signals(cls):
+       signals=icon.signals
+       for s in signals:
+           gobject.signal_new(s, cls, gobject.SIGNAL_RUN_FIRST,
+               gobject.TYPE_NONE, (Icon,))
+
+    def __iter__(self):
+       return(IconIter(self.icons))
+
+    def connect_one(self, which):
+       which.connect('long-press', self.signalLongpress)
+       which.connect('click', self.signalClick)
+       which.connect('tripple-click', self.signalTrippleClick)
+
+    def disconnect_one(self, which):
+       which.disconnect('long-press', self.signalLongpress)
+       which.disconnect('click', self.signalClick)
+       which.disconnect('tripple-click', self.signalTrippleClick)
+
+    def setSize(self, sz):
+       if sz==self.size:
+           return
+
+       old=self.icons
+       self.icons={}
+
+       for x in xrange(sz):
+           for y in xrange(sz):
+               k=(x,y)
+               if old.has_key(k):
+                   self.icons[k]=old[k]
+                   old.pop(k)
+               else:
+                   ico=Icon(self.isconfig)
+                   self.icons[k]=ico
+                   self.connect_one(ico)
+
+       # Disconnect signals
+       for i in old:
+           self.disconnect_one(old[i])
+
+       self.size=sz
+
+    def signalLongpress(self, icon):
+       print "signalLongpress()", icon
+       self.emit('long-press', icon)
+
+    def signalClick(self, icon):
+       print "signalClick()", icon
+       self.emit('click', icon)
+
+    def signalTrippleClick(self, icon):
+       print "signalTrippleClick()", icon
+       self.emit('tripple-click', icon)
+
+    def get(self, x, y):
+       k=(x,y)
+       if self.icons.has_key(k):
+           ret=self.icons[k]
+       else:
+           ret=None
+
+       return(ret)
+
+    def load(self):
+       x=0
+       y=0
+       fn=["maegirls", "wifieye", 'battery-eye', 'image-viewer',
+           'tecnoballz', 'ncalc', 'rtcom-call-ui', 'rtcom-messaging-ui',
+           'extcalllog', 'browser', 'modest', 'osso-addressbook']
+       for f in fn:
+           dt=apps.readOne(f)
+           dt['icon2']=getIcon(dt['icon'])
+           print x, y, dt
+           self.get(x,y).setApp(dt)
+           x+=1
+           if x>=config.size:
+               x=0
+               y+=1
+#          self.icons.append(p)
+
+       print "end of Icons init"
+
+
+gobject.type_register(Icons)
+Icons.register_signals()
+
+# vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
+
index 0a7573d..bca73b1 100755 (executable)
--- a/widget.py
+++ b/widget.py
@@ -38,287 +38,28 @@ from xdg.IconTheme import getIconPath
 
 import config
 import apps
+from icon import Icon
+from icongrid import IconGrid
 
-
-class Icons:
-    def __init__(self):
-       self.mode='l'
-
-
-    def load(self):
-       x=0
-       y=0
-       fn=["maegirls", "wifieye"]*3
-       for f in fn:
-           dt=apps.readOne(f)
-           ico=getIconPath(dt['icon'], config.iconsize)
-           print "ico:", ico
-           p=gtk.gdk.pixbuf_new_from_file_at_size(ico, config.iconsize,
-               config.iconsize)
-           print x, y
-           #dt={'icon2': p}
-           dt['icon2']=p
-           print x, y, dt
-           self.icons[x][y].setApp(dt)
-           x+=1
-           if x>=config.size:
-               x=0
-               y+=1
-#          self.icons.append(p)
-
-       print "end of Icons init"
-
-    def setMode(self, mode):
-       self.mode=mode
-
-class Icon:
-    def __init__(self):
-       self.icon=None
-       self.lastpress=0
-       self.ispressed=False
-
-       self.x=0
-       self.y=0
-
-       self.presstime=0.25
-
-       self.window=None
-
-       self.clickcount=0
-
-    def timePressed(self):
-       """ return how much time a button is pressed """
-       dt=time.time() - self.lastpress
-
-       return(dt)
-
-    def setApp(self, dt):
-       self.name=dt['id']
-       self.icon=dt['icon2']
-
-    def draw(self, cr, x, y, mode):
-       self.x=x
-       self.y=y
-
-       if self.icon==None:
-           return
-
-       cr.save()
-       cr.set_source_rgba(0.1, 0.1, 0.1, 1)
-       cr.set_line_width(5)
-
-       if self.ispressed:
-           t=1.0 * min(self.timePressed(), self.presstime) / self.presstime
-           g=0.3+0.5*t
-           b=0.3+0.7*t
-           cr.set_source_rgba(0, g, b, 0.7)
-       else:
-           cr.set_source_rgba(0.3, 0.3, 0.3, 0.7)
-       x3=x + (config.iconspace/6)
-       y3=y + (config.iconspace/6)
-
-       r=10    # Radius
-       w=config.iconsize+(config.iconspace*2/3)
-
-       cr.move_to(x3+r, y3)
-       cr.arc(x3+w-r,  y3+r,   r,          pi*1.5, pi*2)
-       cr.arc(x3+w-r,  y3+w-r, r,          0,      pi*0.5)
-       cr.arc(x3+r,    y3+w-r, r,          pi*0.5, pi)
-       cr.arc(x3+r,    y3+r,   r,          pi,     pi*1.5)
-
-       cr.stroke_preserve()
-       cr.fill()
-#          cr.paint()
-       cr.restore()
-
-       icon=self.icon
-
-       if mode=='l':
-           icon2=icon
-       else:
-           icon2=icon.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
-
-       cr.save()
-       x3=x + (config.iconspace/2)
-       y3=y + (config.iconspace/2)
-       cr.set_source_pixbuf(icon2, x3, y3)
-       cr.paint()
-       cr.restore()
-
-    def timerPressed(self):
-       #print "timer"
-       if not self.ispressed:
-           return(False)
-
-       self.invalidate()
-
-       if self.timePressed()>self.presstime:
-           ret=False
-       else:
-           ret=True
-       return(ret)
-
-    def doPress(self):
-       # Double-time: time for pressed and time for not-pressed
-       if time.time() - self.lastpress > self.presstime*2:
-           self.clickcount=0
-
-       self.lastpress=time.time()
-       self.ispressed=True
-       gobject.timeout_add(20, self.timerPressed)
-
-    def doLaunch(self):
-       print "launch:", self.name
-       launcher.launch(self.name)
-
-    def doTrippleClick(self):
-       print "tripple"
-       aps=apps.scan()
-       
-       lst=[aps[x]['name'] for x in aps]
-       lst.sort()
-
-       # TODO: EDO EDO EDO
-       # Na doylevei o selector, na dialegei efarmogi kai na
-       # efarmozetai sto sygkekrimeno eikonidio
-       #
-       # Na brethei lysh kai gia ta kena
-       dialog=gtk.Dialog('App select', None,
-           gtk.DIALOG_DESTROY_WITH_PARENT, buttons=())
-
-       selector=hildon.TouchSelectorEntry(text=True)
-       selector.set_column_selection_mode(
-           hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
-       dialog.vbox.pack_start(selector, True, True, 0)
-       dialog.set_size_request(0,900)
-
-       for app in lst:
-           if app==None:
-               continue
-           selector.append_text(app)
-
-       dialog.show_all()
-
-       r=dialog.run()
-       print "r:", r
-#      prog=hildon.Program.get_instance()
-
-       print lst
-
-    def doRelease(self):
-       dt=time.time() - self.lastpress
-       self.ispressed=False
-       if dt>self.presstime and dt<2:
-           self.doLaunch()
-       elif dt<self.presstime:
-           self.clickcount+=1
-           if self.clickcount==3:
-               self.doTrippleClick()
-               self.clickcount=0
-    
-    def doCancel(self):
-       self.ispressed=False
-
-    def invalidate(self, window=None):
-       if window==None:
-           window=self.window
-       else:
-           self.window=window
-       w=config.iconsize + config.iconspace
-       rect=gdk.Rectangle(self.x, self.y, w, w)
-       gdk.Window.invalidate_rect(window, rect, True)
-
-class DrlaunchPlugin(HomePluginItem, Icons, FremantleRotation):
+# IconGrid must be before HomePluginItem for its connect()
+# and do_button_*() to override those of HomePluginItem
+class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
     def __init__(self):
+       IconGrid.__init__(self)
        HomePluginItem.__init__(self)
-       Icons.__init__(self)
        FremantleRotation.__init__(self, 'DrlaunchPlugin')
 
        launcher.init()
 
-       self.setMode('l')
+       self.set_settings(True)
+       self.connect('show-settings', self.slot_show_settings)
+
+       launcher.init()
 
        w=config.size * config.iconsize + (config.size) * config.iconspace
        self.set_size_request(w, w)
 
-       sz=config.size
-       icons=[]
-       for x in xrange(sz):
-           icons.append([])
-           for y in xrange(config.size):
-               icons[x].append(Icon())
-
-       self.icons=icons
-
-       self.lasticon=None  # The last icon that got selected
-
-       self.load()
-
-    def iconAt(self, x, y):
-       """ Get icon at coordinates x,y. X and Y are in pixels """
-
-       w=config.iconsize + config.iconspace
-
-       if self.mode=='l':
-           x2=int(x / w)
-           y2=int(y / w)
-       else:
-           x2=config.size - int(y/w) - 1
-           y2=int(x/w)
-
-       #print x2, y2
-       ret=self.icons[x2][y2]
-
-       return(ret)
-
-    def _draw(self, cr):
-       x=0
-       y=0
-
-#      print "mode:", self.mode
-#      print "icons", len(self.icons)
-       for l in self.icons:
-           for i in l:
-#              print x, y
-
-               if self.mode=='l':
-                   x2=x * (config.iconsize + config.iconspace)
-                   y2=y * (config.iconsize + config.iconspace)
-               else:
-                   x2=y * (config.iconsize + config.iconspace)
-                   y2=(config.size-x-1) * (config.iconsize + config.iconspace)
-
-#              print "draw:", x, y
-               ico=self.icons[x][y]
-               ico.draw(cr, x2, y2, self.mode)
-
-               x+=1
-               if x>=config.size:
-                   x=0
-                   y+=1
-
-    def do_expose_event(self, event):
-       #print "do_expose"
-
-       cr=self.window.cairo_create()
-
-       cr.rectangle(event.area.x, event.area.y,
-           event.area.width, event.area.height)
-
-       cr.clip()
-
-       self._draw(cr)
-
-#      HomePluginItem.do_expose_event(self, event)
-
-    def setLastIcon(self, icon):
-       if icon==self.lasticon:
-           return
-
-       if self.lasticon!=None:
-           self.lasticon.doCancel()
-           self.lasticon.invalidate(self.window)
-       self.lasticon=icon
+       self.connect('long-press', self.signalLongpress)
 
     def do_realize(self):
        screen=self.get_screen()
@@ -327,70 +68,25 @@ class DrlaunchPlugin(HomePluginItem, Icons, FremantleRotation):
 
        HomePluginItem.do_realize(self)
 
-    def do_button_press_event(self, event):
-       #print "press", event.type
-       icon=self.iconAt(event.x, event.y)
-#      rect=gdk.Rectangle(event.x,event.y,1,1)
-#      rect=gdk.Rectangle(0, 0, 100, 100)
-       icon.doPress()
-       icon.invalidate(self.window)
-       self.setLastIcon(icon)
-
-#      gdk.Window.invalidate_rect(self.window, rect, True)
-
-       return(True)
-
-    def do_button_release_event(self, event):
-       #print "release"
-       icon=self.iconAt(event.x, event.y)
-       icon.doRelease()
-       icon.invalidate(self.window)
-       self.setLastIcon(None)
-       return(True)
-
-    def do_leave_notify_event(self, event):
-       #print "leave", event.x, event.y
-       self.setLastIcon(None)
-       return(True)
-
-    def do_pproperty_notify_event(self, event):
-       #print "property"
-       icon=self.iconAt(event.x, event.y)
-       icon.doCancel()
-       icon.invalidate(self.window)
-       return(True)
-
-    def do_motion_notify_event(self, event):
-       #print "motion"
-       self.setLastIcon(None)
-#      icon=self.iconAt(event.x, event.y)
-#      icon.doCancel()
-#      icon.invalidate(self.window)
-       return(True)
-
-    def do_button_press_event_old(self, event):
-       #print "press"
-       if event.type==gdk.BUTTON_PRESS:
-           print "press", event.type
-           if self.mode=='p':
-               self.setMode('l')
-           else:
-               self.setMode('p')
-           self.queue_draw()
-       return True
-
-    # For debugging
-    def do_event1(self, event):
-       print "event:", event, event.type
-
-    def butTest(self, arg):
-       print "but", arg
-
     def on_orientation_changed(self, orientation):
        print "orch:", orientation
        o=orientation[0]
        self.setMode(o)
-       self.queue_draw()
+#      self.queue_draw()
+
+    def do_expose_event(self, event):
+       IconGrid.do_expose_event(self, event)
+       HomePluginItem.do_expose_event(self, event)
+
+    def do_buttonn_press_event(self, event):
+       print "press0"
+
+    def slot_show_settings(self, dt):
+       print "settings", dt
+
+    def signalLongpress(self, sender, icon):
+       print "launch:", icon.name
+       launcher.launch(icon.name)
 
 hd_plugin_type = DrlaunchPlugin
 
diff --git a/win_config.py b/win_config.py
new file mode 100755 (executable)
index 0000000..ee42083
--- /dev/null
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+# coding=UTF-8
+# 
+# Copyright (C) 2010 Stefanos Harhalakis
+#
+# This file is part of wifieye.
+#
+# wifieye is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wifieye is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with wifieye.  If not, see <http://www.gnu.org/licenses/>.
+#
+# $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
+
+__version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
+
+import gtk
+import gobject
+import hildon
+import time
+
+from hildon import StackableWindow
+#from portrait import FremantleRotation
+#from xdg.IconTheme import getIconPath
+
+import config
+import apps
+from icon import Icon, getIcon
+from icongrid import IconGridWidget
+
+class WinConfig(StackableWindow):
+    def __init__(self):
+       StackableWindow.__init__(self)
+
+       self.setupUi()
+
+    def setupUi(self):
+       self.igw=IconGridWidget(True)
+
+       self.add(self.igw)
+
+       self.igw.connect('long-press', self.signalLongpress)
+
+    def signalLongpress(self, sender, icon):
+       print "slp", icon
+       self.doConfig(icon)
+
+    def doConfig(self, icon):
+       aps=apps.scan()
+
+       lst=[aps[x]['name'] for x in aps]
+       lst.sort()
+
+       dialog=gtk.Dialog('App select', None,
+           gtk.DIALOG_DESTROY_WITH_PARENT, buttons=())
+
+       selector=hildon.TouchSelectorEntry(text=True)
+       selector.set_column_selection_mode(
+           hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
+
+       dialog.vbox.pack_start(selector, True, True, 0)
+       dialog.set_size_request(0,900)
+       dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+       dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+
+       selector.append_text('None')
+
+       idx=0
+       cnt=1
+       for app in lst:
+           if app==None:
+               continue
+           selector.append_text(app)
+           if icon.name!=None and aps[icon.name]['name']==app:
+               idx=cnt
+           cnt+=1
+
+       selector.set_active(0, idx)
+
+       dialog.show_all()
+
+       app=None
+
+       r=dialog.run()
+
+       if r==gtk.RESPONSE_OK:
+           cur=selector.get_current_text()
+           if cur=='None':
+               app=None
+           else:
+               for i in aps:
+                   if aps[i]['name']==cur:
+                       app=aps[i]
+                       break
+           if app!=None:
+               app['icon2']=getIcon(app['icon'])
+           else:
+               app={
+                   'id':       None,
+                   'icon2':    None,
+                   }
+           icon.setApp(app)
+
+       dialog.destroy()
+
+
+if __name__=="__main__":
+    win=WinConfig()
+    win.connect('delete-event', gtk.main_quit)
+
+    win.show_all()
+    gtk.main()
+
+
+
+# vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
+