Restore portrait.py's abilities to rotate windows.
[drlaunch] / src / win_config.py
index 124dbe8..0d98eaa 100755 (executable)
@@ -31,37 +31,46 @@ from hildon import StackableWindow
 #from portrait import FremantleRotation
 #from xdg.IconTheme import getIconPath
 
-#import config
+import config
 import apps
 from icon import Icon, getIcon
 from icongrid import IconGridWidget
+from about import DlgAbout
+from portrait import FremantleRotation
 
-class WinConfig(StackableWindow):
+class WinConfig(StackableWindow): #, FremantleRotation):
     def __init__(self, config, *args):
        StackableWindow.__init__(self)
+#      FremantleRotation.__init__(self, "DrlaunchPlugin",
+#          mode=FremantleRotation.AUTOMATIC)
 
        self.config=config
 
        self.setupUi()
 
     def setupUi(self):
-       self.igw=IconGridWidget(True, self.config)
-#      self.igw.do_realize()
-#      self.igw.setSize(config.getSize())
-
-       hbox=gtk.HBox()
-       self.add(hbox)
-
-       # Add the icongrid
-       hbox.add(self.igw)
-
-       # Now go for the right side
+       """
+       self.pa         Main Pannable Area
+       self.col1       A VBox for the first column
+       self.col2       A VBox for the second column
+       self.w_igw      The IGW in an alignment
+       """
+       self.set_title("DrLaunch v" + config.version)
+
+       self.pa=hildon.PannableArea()
+#      self.add(self.pa)
+       self.pa.set_property('mov-mode', hildon.MOVEMENT_MODE_HORIZ)
+
+#1     hbox=gtk.HBox()
+#1     self.pa.add_with_viewport(hbox)
+
+       # Add the first column of options
        al=gtk.Alignment(yscale=0)
-       hbox.add(al)
+#1     hbox.add(al)
 
        vbox=gtk.VBox()
-#      hbox.add(vbox)
        al.add(vbox)
+       self.col1=al
 
        maxsz=self.config.getMaxSize()
 
@@ -112,6 +121,38 @@ class WinConfig(StackableWindow):
        self.buttonRequireLongpress=but
        vbox.add(but)
 
+       but=hildon.CheckButton(
+               gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
+       but.set_label("Animate rotation")
+       self.buttonAnimateRotation=but
+       vbox.add(but)
+
+       # -----------------------------------------------
+       # Second column of options
+       vbox=gtk.VBox()
+       al=gtk.Alignment(xalign=0, yalign=1, xscale=1)
+       al.add(vbox)
+       self.col2=al
+#1     hbox.add(al)
+       but=hildon.Button(
+               gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
+               hildon.BUTTON_ARRANGEMENT_VERTICAL)
+       but.set_title("About")
+       but.connect("clicked", self.slotButtonAbout)
+       vbox.add(but)
+       self.buttonAbout=but
+
+       # -----------------------------------------------
+       # Add the icongrid
+       self.igw=IconGridWidget(True, self.config, False)
+#      self.igw.do_realize()
+#      self.igw.setSize(config.getSize())
+       al=gtk.Alignment(xalign=0, xscale=0)
+       al.add(self.igw)
+       al.set_padding(0, 0, 20, 0)
+       self.w_igw=al
+#1     hbox.add(al)
+
        self.igw.connect('long-press', self.slotLongpress)
        self.igw.connect('click', self.slotLongpress)
 
@@ -120,6 +161,82 @@ class WinConfig(StackableWindow):
        self.setSize(self.config.getSize())
        self.setIndiv(self.config.getIndiv())
        self.setLongpress(self.config.getLongpress())
+       self.setAnimate(self.config.getAnimate())
+
+       hbox=gtk.HBox()
+       hbox.add(self.col1)
+       hbox.add(self.col2)
+       hbox.add(self.w_igw)
+       self.pa.add_with_viewport(hbox)
+
+       self.add(self.pa)
+
+#    def setupUi(self, orientation):
+#
+#      self.setupUi0()
+#
+#      hbox=gtk.HBox()
+#
+#      if orientation=='l':
+#          hbox.add(self.col1)
+#          hbox.add(self.col2)
+#          hbox.add(self.w_igw)
+#      else:
+#          vbox=gtk.VBox()
+#          hbox.add(vbox)
+#          vbox.add(self.col1)
+#          vbox.add(self.col2)
+#          hbox.add(self.w_igw)
+#
+#      self.pa.add_with_viewport(hbox)
+#
+#      if self.get_child()!=None:
+#          self.remove(self.get_child())
+#      self.add(self.pa)
+#      self.pa.show_all()
+
+    def setLayoutPortrait(self):
+       print "lo: p"
+       hbox=gtk.HBox()
+       
+       vbox=gtk.VBox()
+       hbox.add(vbox)
+       self.col1.reparent(vbox)
+       self.col2.reparent(vbox)
+       self.w_igw.reparent(hbox)
+
+       r=self.pa.get_children()[0]
+       self.pa.remove(r)
+       r.destroy()
+       self.pa.add_with_viewport(hbox)
+
+       self.pa.show_all()
+
+    def setLayoutLandscape(self):
+       print "lo: l"
+       hbox=gtk.HBox()
+       
+       self.col1.reparent(hbox)
+       self.col2.reparent(hbox)
+       self.w_igw.reparent(hbox)
+
+       r=self.pa.get_children()[0]
+       self.pa.remove(r)
+       r.destroy()
+       self.pa.add_with_viewport(hbox)
+
+       self.pa.show_all()
+
+    def on_orientation_changed(self, orientation):
+       # This is disabled for now since I've not found any reliable
+       # way for supporting orientation changes (#$#%$#*&% GTK)
+       return
+
+       print "orch:", orientation
+       if orientation=='portrait':
+           self.setLayoutPortrait()
+       else:
+           self.setLayoutLandscape()
 
     def slotLongpress(self, sender, icon):
        self.doConfig(icon)
@@ -142,6 +259,12 @@ class WinConfig(StackableWindow):
        but=self.buttonRotateIndividually
        self.setIndiv(but.get_active())
 
+    def slotButtonAbout(self, sender):
+       print "about"
+       #dlg=DlgAbout()
+       #dlg.run()
+       DlgAbout.present2(self)
+
 #    def slotButtonLongpress(self, sender):
 #      but=self.buttonRequireLongpress
 #      self.set
@@ -184,9 +307,19 @@ class WinConfig(StackableWindow):
        if indiv:
            for i in self.butsSizeY:
                i.set_sensitive(True)
+           for i in self.butsSizeX:
+               i.set_sensitive(True)
+
        else:
            for i in self.butsSizeY:
                i.set_sensitive(False)
+
+           cnt=0
+           for i in self.butsSizeX:
+               cnt+=1
+               if cnt>4:
+                   i.set_sensitive(False)
+
            sz=self.getSize()
            szx=sz[0]
            if szx>4:
@@ -198,6 +331,9 @@ class WinConfig(StackableWindow):
     def setLongpress(self, lp):
        self.buttonRequireLongpress.set_active(lp)
 
+    def setAnimate(self, ar):
+       self.buttonAnimateRotation.set_active(ar)
+
     def doConfig(self, icon):
        aps=apps.scan()
 
@@ -237,10 +373,11 @@ class WinConfig(StackableWindow):
        r=dialog.run()
 
        if r==gtk.RESPONSE_OK:
-           cur=selector.get_current_text()
-           if cur=='None':
+           idx2=selector.get_active(0)
+           if idx2<1:
                app=None
            else:
+               cur=lst[idx2-1]
                for i in aps:
                    if aps[i]['name']==cur:
                        app=aps[i]
@@ -284,12 +421,14 @@ class WinConfig(StackableWindow):
 
        indiv=self.buttonRotateIndividually.get_active()
        lp=self.buttonRequireLongpress.get_active()
+       ar=self.buttonAnimateRotation.get_active()
 
        ret={
            'size':         sz,
            'apps':         wapps,
            'indiv':        indiv,
            'longpress':    lp,
+           'animate':      ar,
            }
 
        return(ret)