It works! :-)
authorStefanos Harhalakis <v13@v13.gr>
Thu, 24 Jun 2010 15:31:33 +0000 (15:31 +0000)
committerStefanos Harhalakis <v13@v13.gr>
Thu, 24 Jun 2010 15:31:33 +0000 (15:31 +0000)
apps.py
config.py
icon.py
icongrid.py
icons.py
widget.py
win_config.py

diff --git a/apps.py b/apps.py
index 13c745e..28673cd 100755 (executable)
--- a/apps.py
+++ b/apps.py
@@ -25,6 +25,7 @@ __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
 import os
 
 from gettext import translation
+#import locale
 
 #from xdg.IconTheme import getIconPath
 
@@ -111,6 +112,7 @@ def scan():
     return(ret)
 
 if __name__=="__main__":
+    #locale.setlocale(locale.LC_ALL, '')
     print scan()
 
 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
index 005de06..36a33be 100755 (executable)
--- a/config.py
+++ b/config.py
 
 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
 
-size = 4
+import os
+import pickle
+
+try:
+    from glib import get_user_config_dir
+except:
+    def get_user_config_dir():
+       home=os.environ['HOME']
+       if home=='':
+           home="/home/user"
+       cfg="%s/.config" % (home)
+
+       return(cfg)
+
+size = 2
 iconsize = 64
 iconspace = 42
+apps=None
+
+def setSize(sz):
+    global size
+
+    size=sz
+
+def getSize():
+    global size
+
+    return(size)
+
+def setApps(aps):
+    """ apps is a dictionary of (x,y)=>appname """
+    global apps
+
+    apps=aps
+
+def getApps():
+    global apps
+
+    if apps==None:
+       tmp={
+           (0,0):  'rtcom-call-ui',
+           (0,1):  'rtcom-messaging-ui',
+           (1,0):  'browser',
+           (1,1):  'osso-addressbook',
+           }
+       setApps(tmp)
+
+    return(apps)
+
+def ensure_dir():
+    dir0=get_user_config_dir()
+    dir=dir0+'/drlaunch'
+    if not os.path.exists(dir):
+       os.mkdir(dir)
+    if not os.path.isdir(dir):
+       raise Exception('Failed to ensure directory' + dir)
+
+    return(dir)
+
+def get_config_fn():
+    dir=ensure_dir()
+    ret=dir + '/config'
+
+    return(ret)
+
+def save():
+    fn=get_config_fn()
+    print "save", fn
+
+    dt={
+       'version':  1,
+       'size':     getSize(),
+       'apps':     getApps()
+       }
+
+    print "save:", dt
+
+    st=pickle.dumps(dt)
+    f=file(fn, 'w')
+    f.write(st)
+    f.close()
+
+def load():
+    fn=get_config_fn()
+    print "load", fn
+
+    try:
+       f=file(fn, 'r')
+       st=f.read()
+       f.close()
+       dt=pickle.loads(st)
+    except:
+       return
+
+    print "load:", dt
+
+    setSize(dt['size'])
+    setApps(dt['apps'])
 
 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
 
diff --git a/icon.py b/icon.py
index e3e639e..f050463 100755 (executable)
--- a/icon.py
+++ b/icon.py
@@ -66,6 +66,9 @@ class Icon(gobject.GObject):
 
        self.clickcount=0
 
+    def __del__(self):
+       print "del"
+
     def timePressed(self):
        """ return how much time a button is pressed """
        dt=time.time() - self.lastpress
index 4502207..1308bb0 100755 (executable)
@@ -52,6 +52,8 @@ class IconGrid(object):       #(gobject.GObject):
     def __init__(self, isconfig=False):
 #      self.__gobject_init__()
 
+       self.size=0
+
        self.isconfig=isconfig
 
        self.icons=Icons(isconfig)
@@ -59,14 +61,16 @@ class IconGrid(object):     #(gobject.GObject):
        self.setMode('l')
 
        # Maybe fix those:
-       w=config.size * config.iconsize + (config.size) * config.iconspace
+#      w=(config.getSize() * config.iconsize) + \
+#          (config.getSize()) * config.iconspace
        #self.set_size_request(w, w)
 
-       self.icons.setSize(config.size)
+#      self.setSize(config.getSize())
+       self.setSize(4)
 
        self.lasticon=None  # The last icon that got selected
 
-       self.icons.load()
+       self.reloadIcons()
 
     def connect(self, what, *args):
        if what in icon.signals:
@@ -74,9 +78,16 @@ class IconGrid(object):      #(gobject.GObject):
        else:
            super(IconGrid, self).connect(what, *args)
 
+    def setSize(self, size):
+       print "igw::setSize", size
+#      config.setSize(size)
+       self.size=size
+       self.icons.setSize(size)
+
     def setMode(self, mode):
        self.mode=mode
-       self.queue_draw()
+       if isinstance(self, gtk.Widget):
+           self.queue_draw()
 
     def iconAt(self, x, y):
        """ Get icon at coordinates x,y. X and Y are in pixels """
@@ -87,11 +98,16 @@ class IconGrid(object):     #(gobject.GObject):
            x2=int(x / w)
            y2=int(y / w)
        else:
-           x2=config.size - int(y/w) - 1
+           x2=self.size - int(y/w) - 1
            y2=int(x/w)
 
        print "x2,y2", x2, y2
-       ret=self.icons.get(x2,y2)
+       ret=self.get(x2,y2)
+
+       return(ret)
+
+    def get(self, x, y):
+       ret=self.icons.get(x,y)
 
        return(ret)
 
@@ -108,7 +124,7 @@ class IconGrid(object):     #(gobject.GObject):
                y2=y * (config.iconsize + config.iconspace)
            else:
                x2=y * (config.iconsize + config.iconspace)
-               y2=(config.size-x-1) * (config.iconsize + config.iconspace)
+               y2=(self.size-x-1) * (config.iconsize + config.iconspace)
 
            # Only repaint the needed icons
            rect=gdk.Rectangle(x2, y2, w, w)
@@ -208,6 +224,9 @@ class IconGrid(object):     #(gobject.GObject):
     def butTest(self, arg):
        print "but", arg
 
+    def reloadIcons(self):
+       self.icons.load()
+
 #    def on_orientation_changed(self, orientation):
 #      print "orch:", orientation
 #      o=orientation[0]
@@ -218,6 +237,13 @@ class IconGridWidget(IconGrid, gtk.Widget):
        IconGrid.__init__(self, isconfig)
        gtk.Widget.__init__(self)
 
+       if isconfig:
+           w=4 * (config.iconsize + config.iconspace)
+       else:
+           w=self.size * (config.iconsize + config.iconspace)
+
+       self.set_size_request(w, w)
+
     def do_realize(self):
        screen=self.get_screen()
        self.set_colormap(screen.get_rgba_colormap())
index 7846958..72812de 100755 (executable)
--- a/icons.py
+++ b/icons.py
@@ -45,9 +45,22 @@ class Icons(gobject.GObject):
     def __init__(self, isconfig):
        self.__gobject_init__()
        self.icons={}
+       self.allicons={}
        self.size=0
        self.isconfig=isconfig
 
+       # signal handlers
+       self.h={}
+
+       # setup allicons
+       maxsz=4
+       for x in xrange(maxsz):
+           for y in xrange(maxsz):
+               k=(x,y)
+               ico=Icon(self.isconfig)
+               self.allicons[k]=ico
+               self.connect_one(ico)
+
     @classmethod
     def register_signals(cls):
        signals=icon.signals
@@ -59,16 +72,24 @@ class Icons(gobject.GObject):
        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)
+       self.h[which]={
+           'longpress':    which.connect('long-press', self.signalLongpress),
+           'click':        which.connect('click', self.signalClick),
+           'tripple':      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)
+       for i in self.h[which]:
+           which.disconnect(self.h[which][i])
+       self.h.pop(which)
+#      which.disconnect(self.h[which]_longpress)
+#      which.disconnect(self.h_click)
+#      which.disconnect(self.h_tripple)
 
     def setSize(self, sz):
+#      print "sz:", sz, self.size
+
        if sz==self.size:
            return
 
@@ -78,17 +99,16 @@ class Icons(gobject.GObject):
        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)
+               ico=self.allicons[k]
+               self.icons[k]=ico
+#              if old.has_key(k):
+#                  old.pop(k)  # Re-used
+#              else:
+#                  self.connect_one(ico)
 
        # Disconnect signals
-       for i in old:
-           self.disconnect_one(old[i])
+#      for i in old:
+#          self.disconnect_one(old[i])
 
        self.size=sz
 
@@ -114,21 +134,36 @@ class Icons(gobject.GObject):
        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)
+#      x=0
+#      y=0
+#      fn=["maegirls", "wifieye", 'battery-eye', 'image-viewer',
+#          'tecnoballz', 'ncalc', 'rtcom-call-ui', 'rtcom-messaging-ui',
+#          'extcalllog', 'browser', 'modest', 'osso-addressbook']
+
+       wapps=config.getApps()
+       sz=config.getSize()
+
+       for k in wapps:
+           x,y=k
+           if x>=sz or y>=sz:
+               continue
+
+           appname=wapps[k]
+           if appname!=None:
+               app=apps.readOne(appname)
+               app['icon2']=getIcon(app['icon'])
+               self.get(x,y).setApp(app)
+
+#      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.getSize(getSize()):
+#              x=0
+#              y+=1
+##         self.icons.append(p)
 
        print "end of Icons init"
 
index bca73b1..34e73c7 100755 (executable)
--- a/widget.py
+++ b/widget.py
@@ -34,7 +34,7 @@ import time
 from portrait import FremantleRotation
 import launcher
 from xdg.IconTheme import getIconPath
-
+from win_config import WinConfig
 
 import config
 import apps
@@ -50,15 +50,12 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
        FremantleRotation.__init__(self, 'DrlaunchPlugin')
 
        launcher.init()
+       config.load()
+       self.setSize(config.getSize())
+       self.reloadIcons()
 
        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)
-
        self.connect('long-press', self.signalLongpress)
 
     def do_realize(self):
@@ -83,11 +80,37 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
 
     def slot_show_settings(self, dt):
        print "settings", dt
+       s=WinConfig()
+       s.show_all()
+       s.connect('destroy', self.slotConfigDestroy)
+
+    def slotConfigDestroy(self, sender):
+       print "destroy", sender
+       dt=sender.getData()
+       print "dt:", dt
+       config.setSize(dt['size'])
+       config.setApps(dt['apps'])
+       config.save()
+       
+       # Resize widget
+       self.setSize(dt['size'])
+       self.reloadIcons()
+
+#      self.queue_draw()
 
     def signalLongpress(self, sender, icon):
        print "launch:", icon.name
        launcher.launch(icon.name)
 
+    def resize(self):
+       w=(self.size * config.iconsize) + \
+           (self.size * config.iconspace)
+       self.set_size_request(w, w)
+
+    def setSize(self, size):
+       IconGrid.setSize(self, size)
+       self.resize()
+
 hd_plugin_type = DrlaunchPlugin
 
 def do1():
index ee42083..47b7436 100755 (executable)
@@ -37,22 +37,81 @@ from icon import Icon, getIcon
 from icongrid import IconGridWidget
 
 class WinConfig(StackableWindow):
-    def __init__(self):
+    def __init__(self, *args):
        StackableWindow.__init__(self)
 
        self.setupUi()
 
     def setupUi(self):
        self.igw=IconGridWidget(True)
+#      self.igw.setSize(config.getSize())
 
-       self.add(self.igw)
+       hbox=gtk.HBox()
+       self.add(hbox)
 
-       self.igw.connect('long-press', self.signalLongpress)
+       # Add the icongrid
+       hbox.add(self.igw)
 
-    def signalLongpress(self, sender, icon):
+       # Now go for the right side
+       al=gtk.Alignment(yscale=0)
+       hbox.add(al)
+
+       vbox=gtk.VBox()
+#      hbox.add(vbox)
+       al.add(vbox)
+
+       vbox.add(gtk.Label('Grid size:'))
+
+       self.butsSize=[]
+       for i in xrange(4):
+           but=gtk.ToggleButton("%sx%s" % (i+1,i+1))
+           but.set_size_request(160, 90)
+           self.butsSize.append(but)
+           but.connect('toggled', self.slotButtonSize, i)
+
+       hbox2=gtk.HBox()
+       vbox.add(hbox2)
+       hbox2.add(self.butsSize[0])
+       hbox2.add(self.butsSize[1])
+       hbox2=gtk.HBox()
+       vbox.add(hbox2)
+       hbox2.add(self.butsSize[2])
+       hbox2.add(self.butsSize[3])
+
+       self.igw.connect('long-press', self.slotLongpress)
+
+       self.ignore_toggle=False
+
+       self.setSize(config.getSize())
+
+    def slotLongpress(self, sender, icon):
        print "slp", icon
        self.doConfig(icon)
 
+    def slotButtonSize(self, sender, id):
+       print "size:", id
+
+       self.setSize(id+1)
+       
+    def setSize(self, sz):
+       if self.ignore_toggle:
+           return
+
+       self.ignore_toggle=True
+
+       id=sz-1
+
+       for i in xrange(4):
+           but=self.butsSize[i]
+           but.set_active(i==id)
+
+       self.ignore_toggle=False
+
+       self.igw.setSize(sz)
+
+       self.igw.queue_draw()
+
+
     def doConfig(self, icon):
        aps=apps.scan()
 
@@ -111,6 +170,31 @@ class WinConfig(StackableWindow):
 
        dialog.destroy()
 
+    def getData(self):
+       sz=0
+       for but in self.butsSize:
+           sz+=1
+           if but.get_active()==True:
+               break
+
+       print "conf: sz=", sz
+
+       wapps={}
+
+       for x in xrange(sz):
+           for y in xrange(sz):
+               ico=self.igw.get(x,y)
+               k=(x,y)
+               wapps[k]=ico.name
+
+       ret={
+           'size':     sz,
+           'apps':     wapps
+           }
+
+       print "ret:", ret
+
+       return(ret)
 
 if __name__=="__main__":
     win=WinConfig()