CSSU's portrait mode support - WIP
[drlaunch] / drlaunch / src / icongrid.py
index 96588d5..a803fa8 100755 (executable)
@@ -54,7 +54,7 @@ from icons import Icons
 # for the config widget)
 
 #class IconGrid(gtk.Widget, FremantleRotation):
-class IconGrid:        #(gobject.GObject):
+class IconGrid:
     def __init__(self, isconfig=False):
 #      self.__gobject_init__()
 #      gtk.Widget.__init__(self)
@@ -80,6 +80,12 @@ class IconGrid:      #(gobject.GObject):
        # Duration of the rotation effect
        self.rotation_time=0.8
 
+       # Whether we're in CSSU's h-d portrait mode
+       self.cssuportrait=False
+
+       # Force modechange, even when mode doesn't change
+       self.force_modechange=False
+
 #      print "ig-init"
 
 #    def __del__(self):
@@ -129,12 +135,23 @@ class IconGrid:   #(gobject.GObject):
        ret=self.icons.getSize()
        return(ret)
 
+    def setCSSUPortrait(self, cssuportrait):
+       if self.cssuportrait==cssuportrait:
+           # print "same portrait"
+           return
+
+       self.cssuportrait=cssuportrait
+       self.force_modechange=True
+
+    # TODO: Remove default value from cssuportrait
     def setMode(self, mode):
-       if self.mode==mode:
-#          print "same mode"
+       if self.mode==mode and not self.force_modechange:
+           # print "same mode"
            return
 
        self.mode=mode
+       self.force_modechange=False
+
        if not isinstance(self, gtk.Widget):
            return
 
@@ -149,7 +166,8 @@ class IconGrid:     #(gobject.GObject):
        except TypeError:
            do_draw=True
 
-       if do_draw and self.config.getAnimate() and self.do_animations:
+       if do_draw and self.config.getAnimate() and self.do_animations \
+           and not self.cssuportrait:
            #self.queue_draw()
            # Don't start another timer
            # Instead adjust the time start to produce a nice effect ;-)
@@ -164,7 +182,7 @@ class IconGrid:     #(gobject.GObject):
                dt2=da2*self.rotation_time/90.0
                self.angle_timer_start=time.time()-dt2
         else:
-            if self.mode=='l':
+            if self.mode=='l' or self.cssuportrait:
                 self.setAngle(0)
             else:
                 self.setAngle(90)
@@ -219,13 +237,18 @@ class IconGrid:   #(gobject.GObject):
 
        w=self.config.getIconSizeFull()
 
-       if self.mode=='l' or self.config.getIndiv():
+       if self.cssuportrait:
+           x2=int(y / w)
+           y2=self.size[1] - int(x/w) - 1
+       elif self.mode=='l' or self.config.getIndiv():
            x2=int(x / w)
            y2=int(y / w)
        else:
            x2=self.size[1] - int(y/w) - 1
            y2=int(x/w)
 
+#      print "%d,%d -> %d,%d" % (int(x/w), int(y/w), x2, y2), \
+#          self.cssuportrait, self.mode
        ret=self.get(x2,y2)
 
        return(ret)
@@ -240,7 +263,20 @@ class IconGrid:    #(gobject.GObject):
 
        w=self.config.getIconSizeFull()
        for x,y in self.icons:
-           if self.mode=='l' or self.config.getIndiv():
+           x2=(self.size[1]-y-1) * self.config.getIconSizeFull()
+           y2=x * self.config.getIconSizeFull()
+           if self.cssuportrait:
+               # What we do here is:
+               # We map the x,y of icons to x,y on the screen.
+               # x,y of icons is the x,y as if there is no desktop rotation
+               # and we're in landscape mode
+               #
+               # After that, iconAt() will work properly. It's a kind of
+               # double effort but it works nice
+               x2=(self.size[1]-y-1) * self.config.getIconSizeFull()
+               y2=x * self.config.getIconSizeFull()
+           elif not self.cssuportrait and \
+               (self.mode=='l' or self.config.getIndiv()):
                #x2=x * (self.config.iconsize + self.config.iconspace)
                #y2=y * (self.config.iconsize + self.config.iconspace)
                x2=x * self.config.getIconSizeFull()
@@ -255,17 +291,24 @@ class IconGrid:   #(gobject.GObject):
            # 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:
+           if t.width==0 and t.height==0 and False:
                continue
 
            ico=self.icons.get(x,y)
-           ico.draw(cr, x2, y2)
+           if ico!=None:
+               ico.draw(cr, x2, y2)
+           else:
+               print "No icon for %d, %d (%d, %d)!" % (x,y, x2, y2)
 
     def setAngle(self, angle):
        """ Return True/False indicating that angle has changed """
        ret=False
+
+       #print "angle:", angle, self.mode
+
        for x,y in self.icons:
            ic=self.icons.get(x,y)
+           #ic=self.iconAt(x,y)
            if ic.setAngle(angle):
                ret=True
 
@@ -275,12 +318,14 @@ class IconGrid:   #(gobject.GObject):
        """ Clear animation cache, freeing memory """
        for x,y in self.icons:
            ic=self.icons.get(x,y)
+           #ic=self.iconAt(x,y)
            ic.clearAnimationCache()
 
     def clearBgCache(self):
        """ Clear backgrounds cache """
        for x,y in self.icons:
            ic=self.icons.get(x,y)
+           #ic=self.iconAt(x,y)
            ic.clearBgCache()
 
     def do_expose_event(self, event):
@@ -295,6 +340,9 @@ class IconGrid:     #(gobject.GObject):
            self.icons.setWindow(self.window)
            self.init_done=True
 
+#      print "expose:", event.area.x, event.area.y, event.area.width, \
+#          event.area.height
+
        self._draw(cr, event)
 
     def setLastIcon(self, icon):