Added logging capability if /tmp/drlaunch.log is present.
[drlaunch] / src / win_config.py
index 47b7436..ba0eac2 100755 (executable)
@@ -35,74 +35,265 @@ import config
 import apps
 from icon import Icon, getIcon
 from icongrid import IconGridWidget
+from about import DlgAbout
+from portrait import FremantleRotation
 
-class WinConfig(StackableWindow):
-    def __init__(self, *args):
+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.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
 
-       vbox.add(gtk.Label('Grid size:'))
+       maxsz=self.config.getMaxSize()
 
-       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)
+       # ----------------------------------------------
+       vbox.add(gtk.Label('Width:'))
 
        hbox2=gtk.HBox()
        vbox.add(hbox2)
-       hbox2.add(self.butsSize[0])
-       hbox2.add(self.butsSize[1])
+
+       self.butsSizeX=[]
+       self.butsSize=self.butsSizeX # For now
+       for i in xrange(maxsz[0]):
+           but=hildon.GtkToggleButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+           but.set_label("%s" % (i+1,))
+           but.connect('toggled', self.slotButtonSizeX, i)
+
+           self.butsSizeX.append(but)
+
+           hbox2.add(but)
+
+       # ----------------------------------------------
+       vbox.add(gtk.Label('Height:'))
+
        hbox2=gtk.HBox()
        vbox.add(hbox2)
-       hbox2.add(self.butsSize[2])
-       hbox2.add(self.butsSize[3])
+
+       self.butsSizeY=[]
+       for i in xrange(maxsz[1]):
+           but=hildon.GtkToggleButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+           but.set_label("%s" % (i+1,))
+           but.connect('toggled', self.slotButtonSizeY, i)
+
+           self.butsSizeY.append(but)
+
+           hbox2.add(but)
+
+       but=hildon.CheckButton(
+               gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
+       but.set_label("Rotate icons individually")
+       but.connect('toggled', self.slotButtonRotateIndividually)
+       self.buttonRotateIndividually=but
+       vbox.add(but)
+
+       but=hildon.CheckButton(
+               gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
+       but.set_label("Require long press")
+#      but.connect('toggled', self.slotButtonLongpress)
+       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
+
+       but=hildon.CheckButton(
+               gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
+       but.set_label("No background")
+       #but.connect('toggled', self.slotButtonNoBackground)
+       self.buttonNoBackground=but
+       vbox.add(but)
+
+#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)
 
        self.ignore_toggle=False
 
-       self.setSize(config.getSize())
+       self.setSize(self.config.getSize())
+       self.setIndiv(self.config.getIndiv())
+       self.setLongpress(self.config.getLongpress())
+       self.setAnimate(self.config.getAnimate())
+       self.setNoBg(self.config.getNoBg())
+
+       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):
-       print "slp", icon
        self.doConfig(icon)
 
-    def slotButtonSize(self, sender, id):
-       print "size:", id
+    def slotButtonSizeX(self, sender, id):
+       if self.getIndiv():
+           old=self.getSize()
+           sz=(id+1, old[1])
+       else:
+           sz=(id+1, id+1)
 
-       self.setSize(id+1)
+       self.setSize(sz)
        
+    def slotButtonSizeY(self, sender, id):
+       old=self.getSize()
+       sz=(old[0], id+1)
+       self.setSize(sz)
+       
+    def slotButtonRotateIndividually(self, sender):
+       but=self.buttonRotateIndividually
+       self.setIndiv(but.get_active())
+
+    def slotButtonAbout(self, sender):
+       DlgAbout.present2(self)
+
+#    def slotButtonLongpress(self, sender):
+#      but=self.buttonRequireLongpress
+#      self.set
+
     def setSize(self, sz):
        if self.ignore_toggle:
            return
 
        self.ignore_toggle=True
 
-       id=sz-1
+       maxsz=self.config.getMaxSize()
+
+       id=sz[0]-1
+
+       for i in xrange(maxsz[0]):
+           but=self.butsSizeX[i]
+           but.set_active(i==id)
+
+       id=sz[1]-1
 
-       for i in xrange(4):
-           but=self.butsSize[i]
+       for i in xrange(maxsz[1]):
+           but=self.butsSizeY[i]
            but.set_active(i==id)
 
        self.ignore_toggle=False
@@ -111,6 +302,47 @@ class WinConfig(StackableWindow):
 
        self.igw.queue_draw()
 
+    def getSize(self):
+       return(self.igw.getSize())
+
+    def getIndiv(self):
+       ret=self.buttonRotateIndividually.get_active()
+
+       return(ret)
+
+    def setIndiv(self, indiv):
+       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:
+               szx=4
+           self.setSize((szx, szx))
+
+       self.buttonRotateIndividually.set_active(indiv)
+
+    def setLongpress(self, lp):
+       self.buttonRequireLongpress.set_active(lp)
+
+    def setAnimate(self, ar):
+       self.buttonAnimateRotation.set_active(ar)
+
+    def setNoBg(self, nobg):
+       self.buttonNoBackground.set_active(nobg)
 
     def doConfig(self, icon):
        aps=apps.scan()
@@ -151,16 +383,17 @@ 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]
                        break
            if app!=None:
-               app['icon2']=getIcon(app['icon'])
+               app['icon2']=getIcon(app['icon'], self.config.getIconSize())
            else:
                app={
                    'id':       None,
@@ -171,29 +404,45 @@ class WinConfig(StackableWindow):
        dialog.destroy()
 
     def getData(self):
-       sz=0
-       for but in self.butsSize:
-           sz+=1
+       szx=0
+       szy=0
+       for but in self.butsSizeX:
+           szx+=1
+           if but.get_active()==True:
+               break
+
+       for but in self.butsSizeY:
+           szy+=1
            if but.get_active()==True:
                break
 
-       print "conf: sz=", sz
+       if self.getIndiv():
+           sz=(szx, szy)
+       else:
+           sz=(szx, szx)
 
        wapps={}
 
-       for x in xrange(sz):
-           for y in xrange(sz):
+       for x in xrange(sz[0]):
+           for y in xrange(sz[1]):
                ico=self.igw.get(x,y)
                k=(x,y)
                wapps[k]=ico.name
 
+       indiv=self.buttonRotateIndividually.get_active()
+       lp=self.buttonRequireLongpress.get_active()
+       ar=self.buttonAnimateRotation.get_active()
+       nobg=self.buttonNoBackground.get_active()
+
        ret={
-           'size':     sz,
-           'apps':     wapps
+           'size':         sz,
+           'apps':         wapps,
+           'indiv':        indiv,
+           'longpress':    lp,
+           'animate':      ar,
+           'nobg':         nobg,
            }
 
-       print "ret:", ret
-
        return(ret)
 
 if __name__=="__main__":