CSSU's portrait mode support - WIP master
authoruser <user@Nokia-N900-42-11.(none)>
Mon, 21 Nov 2011 20:18:43 +0000 (20:18 +0000)
committeruser <user@Nokia-N900-42-11.(none)>
Mon, 21 Nov 2011 20:18:43 +0000 (20:18 +0000)
drlaunch/src/icongrid.py
drlaunch/src/icons.py
drlaunch/src/portrait.py
drlaunch/src/widget.py
drlaunch/src/win_config.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):
index 808d922..b8bd183 100755 (executable)
@@ -43,13 +43,14 @@ class IconIter:
        ret=self.iter.next()
        return(ret)
 
-class Icons(gobject.GObject, Disconnector):
+class Icons(Disconnector, gobject.GObject):
 #class Icons(gtk.Widget, Disconnector):
+    __gtype_name__ = "DrlaunchIcons"
 
     #__gsignals__=Icon.gsignals
     def __init__(self, isconfig, config):
-       self.__gobject_init__()
-       #gobject.GObject.__init__(self)
+       #self.__gobject_init__()
+       gobject.GObject.__init__(self)
        #gtk.Widget.__init__(self)
        Disconnector.__init__(self)
 
@@ -247,8 +248,14 @@ class Icons(gobject.GObject, Disconnector):
 #              y+=1
 ##         self.icons.append(p)
 
-gobject.type_register(Icons)
-Icons.register_signals()
+icons_type=Icons
+
+def init_icons():
+    #gobject.type_register(icons_type)
+    print "bbbbbbbbbbbbbbBB"
+#    Icons.register_signals()
+    print "bbbbbbbbbbbbbbBB222222222"
 
+Icons.register_signals()
 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
 
index 7ea8b09..928db02 100644 (file)
@@ -28,7 +28,7 @@ import osso
 _ = str
 
 
-class FremantleRotation(object):
+class FremantleRotation:
     """thp's screen rotation for Maemo 5
 
     Simply instantiate an object of this class and let it auto-rotate
index 35141bb..cff7575 100755 (executable)
@@ -29,6 +29,7 @@ __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
 import sys
 import os
 
+import gobject
 orig_path=sys.path[:]
 tmp_path=os.path.dirname( os.path.realpath( __file__ ) )
 sys.path.append(tmp_path)
@@ -36,8 +37,6 @@ sys.path.append(tmp_path)
 # End of hack
 
 import gtk
-import gobject
-import hildon
 from hildondesktop import *
 from gtk import gdk
 from math import pi
@@ -58,12 +57,16 @@ from icon import Icon
 from icongrid import IconGrid
 from sig import Disconnector
 
+import icons
+
 # Restore path
 sys.path=orig_path
 
 # IconGrid must be before HomePluginItem for its connect()
 # and do_button_*() to override those of HomePluginItem
 class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation, Disconnector):
+    __gtype_name__ = "DrlaunchPlugin"
+
     def __init__(self):
        IconGrid.__init__(self)
        HomePluginItem.__init__(self)
@@ -189,9 +192,21 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation, Disconnector):
        # In case of a rotating desktop, force orientation to be
        # 'landscape'
        if rd:
+           # CSSU Portrait mode?
+           if o=='p':
+               csp=True
+           else:
+               csp=False
+
            o='l'
 
+       self.setCSSUPortrait(csp)
+
+       if rd:
+           self.resize2()
+
        self.setMode(o)
+
 #      self.queue_draw()
 
     def do_expose_event(self, event):
@@ -282,8 +297,14 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation, Disconnector):
            (self.size[0] * config.getIconSpace())
        h=(self.size[1] * config.iconsize) + \
            (self.size[1] * config.getIconSpace())
+
+       if self.cssuportrait:
+           (w,h)=(h,w)
+
+       #print "w,h:", w, h
        self.set_size_request(w, h)
        self.resize(w, h)
+       self.queue_draw()
 
     def setSize(self, size):
        IconGrid.setSize(self, size)
@@ -292,7 +313,10 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation, Disconnector):
 hd_plugin_type = DrlaunchPlugin
 
 if __name__=="__main__":
-    gobject.type_register(hd_plugin_type)
+
+    icons.init_icons()
+
+    #gobject.type_register(hd_plugin_type)
     obj=gobject.new(hd_plugin_type, plugin_id="plugin_id")
     obj.show_all()
     gtk.main()
index 4639e2b..2d09a16 100755 (executable)
@@ -41,6 +41,7 @@ from about import DlgAbout
 from portrait import FremantleRotation
 from sig import Disconnector
 
+
 class DialogIconSize(gtk.Dialog):
     def __init__(self, config):
        gtk.Dialog.__init__(self, "Adjust icon size")