self.id=id
self.size = (2,2)
+ self.themebgsize = 96
self.iconsize = 64
# self.iconspace = 42 # For 4 icons (height)
self.iconspace = 36 # For 8 icons (width)
self.longpress=False
self.animate=True
self.nobg=False
+ self.themebg=False
self.maxsz=(8,4)
def getNoBg(self):
return(self.nobg)
+ def setThemeBg(self, themebg):
+ self.themebg=themebg
+
+ def getThemeBg(self):
+ return(self.themebg)
+
def setApps(self, aps):
""" apps is a dictionary of (x,y)=>appname """
self.apps=aps
'longpress': self.getLongpress(),
'animate': self.getAnimate(),
'nobg': self.getNoBg(),
+ 'themebg': self.getThemeBg(),
}
fn=get_config_fn()
return(dt)
+ def parse_v5(self, dt):
+ dt['version']=6
+
+ for i in dt['data']:
+ dt['data'][i]['themebg']=False
+
+ return(dt)
+
def load_all(self):
fn=get_config_fn()
if ret['version']==4:
ret=parse_v4(ret)
+
+ if ret['version']==5:
+ ret=parse_v5(ret)
except:
ret=None
self.setLongpress(dt['longpress'])
self.setAnimate(dt['animate'])
self.setNoBg(dt['nobg'])
+ self.setThemeBg(dt['themebg'])
def check_init(self):
if self.id==None:
if ico==None:
ico=getIconPath(idef, iconsize)
- ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, iconsize, iconsize)
+ try:
+ ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, iconsize, iconsize)
+ except:
+ # On error use the default icon
+ ico=getIconPath(idef, iconsize)
+ ret=gtk.gdk.pixbuf_new_from_file_at_size(ico, iconsize, iconsize)
+ print "Icon with unhandled format:", iname
return(ret)
self.name=None
self.icon=None
self.sicon=None
+ self.sthemebg1=None
+ self.sthemebg2=None
self.lastpress=0
self.ispressed=False
return(s)
+ def get_sthemebg(self, pressed):
+ """ Return the theme's background icon as a surface. Cache it. """
+ if not pressed and self.sthemebg1!=None:
+ return(self.sthemebg1)
+ if pressed and self.sthemebg2!=None:
+ return(self.sthemebg2)
+
+ fn="/etc/hildon/theme/images/"
+ if pressed:
+ fn+="ApplicationShortcutAppletPressed.png"
+ else:
+ fn+="ApplicationShortcutApplet.png"
+
+ w=self.config.themebgsize
+ buf=gtk.gdk.pixbuf_new_from_file_at_size(fn, w, w)
+ s=cairo.ImageSurface(cairo.FORMAT_ARGB32, w, w)
+ cr0=cairo.Context(s)
+ cr=gtk.gdk.CairoContext(cr0)
+
+ cr.set_source_pixbuf(buf, 0, 0)
+ cr.paint()
+
+ if not pressed:
+ self.sthemebg1=s
+ else:
+ self.sthemebg2=s
+
+ return(s)
+
def get_sicon(self):
""" Return the icon as a surface. Cache it. """
if self.sicon!=None:
cr=gtk.gdk.CairoContext(cr0)
# Paint the background
- if not self.config.getNoBg():
+ if self.config.getNoBg():
+ pass
+ elif self.config.getThemeBg(): # Use theme bg
+ s2=self.get_sthemebg(pressed)
+
+ # have in mind the size difference of iconsize+iconspace with
+ # the fixed themebgsize
+ xy0=int((w-self.config.themebgsize)/2)
+
+ cr.save()
+ cr.set_source_surface(s2, xy0, xy0)
+ cr.paint()
+ cr.restore()
+ else:
s2=self.mkbg(t)
cr.save()
cr.set_source_surface(s2, 0, 0)
config.setLongpress(dt['longpress'])
config.setAnimate(dt['animate'])
config.setNoBg(dt['nobg'])
+ config.setThemeBg(dt['themebg'])
config.save()
# Resize widget
#1 self.pa.add_with_viewport(hbox)
# Add the first column of options
- al=gtk.Alignment(yscale=0)
+ al=gtk.Alignment(yscale=1)
#1 hbox.add(al)
vbox=gtk.VBox()
hbox2.add(but)
+ vbox2=gtk.VBox()
+
+ al=gtk.Alignment(xalign=0, yalign=1, xscale=1)
+ al.add(vbox2)
+ self.col11=al
+
+ vbox.add(al)
+ vbox=vbox2
+
but=hildon.CheckButton(
gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
but.set_label("Rotate icons individually")
but=hildon.CheckButton(
gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
+ but.set_label("Theme background")
+ #but.connect('toggled', self.slotButtonNoBackground)
+ self.buttonThemeBackground=but
+ vbox.add(but)
+
+ 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
self.setLongpress(self.config.getLongpress())
self.setAnimate(self.config.getAnimate())
self.setNoBg(self.config.getNoBg())
+ self.setThemeBg(self.config.getThemeBg())
hbox=gtk.HBox()
hbox.add(self.col1)
def setNoBg(self, nobg):
self.buttonNoBackground.set_active(nobg)
+ def setThemeBg(self, themebg):
+ self.buttonThemeBackground.set_active(themebg)
+
def doConfig(self, icon):
aps=apps.scan()
lp=self.buttonRequireLongpress.get_active()
ar=self.buttonAnimateRotation.get_active()
nobg=self.buttonNoBackground.get_active()
+ themebg=self.buttonThemeBackground.get_active()
ret={
'size': sz,
'longpress': lp,
'animate': ar,
'nobg': nobg,
+ 'themebg': themebg,
}
return(ret)