Implement icon resizing.
[drlaunch] / src / icons.py
index 72812de..8f2c189 100755 (executable)
@@ -22,7 +22,7 @@
 
 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
 
-import config
+#import config
 import apps
 import icon
 from icon import getIcon, Icon
@@ -42,24 +42,59 @@ class IconIter:
        return(ret)
 
 class Icons(gobject.GObject):
-    def __init__(self, isconfig):
+    def __init__(self, isconfig, config):
        self.__gobject_init__()
        self.icons={}
        self.allicons={}
        self.size=0
        self.isconfig=isconfig
+       self.config=config
 
        # signal handlers
        self.h={}
 
+       self.maxsz=(0,0)
+
        # 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)
+       self.resizeMax()
+
+    def resizeMax(self):
+       sz=self.maxsz
+       maxsz=self.config.getMaxSize()
+
+       # Create new entries in x
+       if maxsz[0]>sz[0]:
+           for x in xrange(maxsz[0]-sz[0]):
+               for y in xrange(sz[1]):
+                   k=(x+sz[0],y)
+                   ico=Icon(self.isconfig, self.config)
+                   self.allicons[k]=ico
+                   self.connect_one(ico)
+           sz=(maxsz[0], sz[1])
+       elif maxsz[0]<sz[0]:
+           for x in xrange(sz[0]-maxsz[0]):
+               for y in xrange(sz[1]):
+                   k=(maxsz[0]+x,y)
+                   self.allicons.pop(k)
+           sz=(maxsz[0], sz[1])
+
+       # Create new entries in y
+       if maxsz[1]>sz[1]:
+           for y in xrange(maxsz[1]-sz[1]):
+               for x in xrange(sz[0]):
+                   k=(x,y+sz[1])
+                   ico=Icon(self.isconfig, self.config)
+                   self.allicons[k]=ico
+                   self.connect_one(ico)
+           sz=(sz[0], maxsz[1])
+       elif maxsz[1]<sz[1]:
+           for y in xrange(sz[1]-maxsz[1]):
+               for x in xrange(sz[0]):
+                   k=(x,y+maxsz[1])
+                   self.allicons.pop(k)
+           sz=(sz[0], maxsz[1])
+
+       self.maxsz=sz
 
     @classmethod
     def register_signals(cls):
@@ -96,8 +131,8 @@ class Icons(gobject.GObject):
        old=self.icons
        self.icons={}
 
-       for x in xrange(sz):
-           for y in xrange(sz):
+       for x in xrange(sz[0]):
+           for y in xrange(sz[1]):
                k=(x,y)
                ico=self.allicons[k]
                self.icons[k]=ico
@@ -112,16 +147,26 @@ class Icons(gobject.GObject):
 
        self.size=sz
 
+    def getSize(self):
+       return(self.size)
+
+    def setWindow(self, win):
+       """ Set the window for all icons """
+
+       for i in self.icons:
+           ic=self.icons[i]
+           ic.setWindow(win)
+
     def signalLongpress(self, icon):
-       print "signalLongpress()", icon
+       #print "signalLongpress()", icon
        self.emit('long-press', icon)
 
     def signalClick(self, icon):
-       print "signalClick()", icon
+       #print "signalClick()", icon
        self.emit('click', icon)
 
     def signalTrippleClick(self, icon):
-       print "signalTrippleClick()", icon
+       #print "signalTrippleClick()", icon
        self.emit('tripple-click', icon)
 
     def get(self, x, y):
@@ -140,8 +185,9 @@ class Icons(gobject.GObject):
 #          'tecnoballz', 'ncalc', 'rtcom-call-ui', 'rtcom-messaging-ui',
 #          'extcalllog', 'browser', 'modest', 'osso-addressbook']
 
-       wapps=config.getApps()
-       sz=config.getSize()
+       wapps=self.config.getApps()
+       #sz=self.config.getSize()
+       sz=self.getSize()
 
        for k in wapps:
            x,y=k
@@ -151,8 +197,19 @@ class Icons(gobject.GObject):
            appname=wapps[k]
            if appname!=None:
                app=apps.readOne(appname)
-               app['icon2']=getIcon(app['icon'])
-               self.get(x,y).setApp(app)
+               if app!=None:
+                   app['icon2']=getIcon(app['icon'], self.config.getIconSize())
+                   self.get(x,y).setApp(app)
+           else:
+               ic=self.get(x,y)
+               ic.setApp(None)
+
+       # Reload icons to make sure backgrounds, etc are valid
+       for x in xrange(sz[0]):
+           for y in xrange(sz[1]):
+               ic=self.get(x,y)
+               ic.reload()
+
 
 #      for f in fn:
 #          dt=apps.readOne(f)
@@ -165,9 +222,6 @@ class Icons(gobject.GObject):
 #              y+=1
 ##         self.icons.append(p)
 
-       print "end of Icons init"
-
-
 gobject.type_register(Icons)
 Icons.register_signals()