From eb72bc70f33bb4d7d031e8dfabcf216cbfc836ed Mon Sep 17 00:00:00 2001 From: Stefanos Harhalakis Date: Fri, 14 Jan 2011 00:08:06 +0000 Subject: [PATCH] Implemented theme-bg option. --- src/config.py | 21 +++++++++++++++++++++ src/icon.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/widget.py | 1 + src/win_config.py | 24 +++++++++++++++++++++++- 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/src/config.py b/src/config.py index 91e0a2e..c441d7e 100755 --- a/src/config.py +++ b/src/config.py @@ -59,6 +59,7 @@ class Config: 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) @@ -67,6 +68,7 @@ class Config: self.longpress=False self.animate=True self.nobg=False + self.themebg=False self.maxsz=(8,4) @@ -106,6 +108,12 @@ class Config: 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 @@ -140,6 +148,7 @@ class Config: 'longpress': self.getLongpress(), 'animate': self.getAnimate(), 'nobg': self.getNoBg(), + 'themebg': self.getThemeBg(), } fn=get_config_fn() @@ -191,6 +200,14 @@ class Config: 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() @@ -214,6 +231,9 @@ class Config: if ret['version']==4: ret=parse_v4(ret) + + if ret['version']==5: + ret=parse_v5(ret) except: ret=None @@ -237,6 +257,7 @@ class Config: self.setLongpress(dt['longpress']) self.setAnimate(dt['animate']) self.setNoBg(dt['nobg']) + self.setThemeBg(dt['themebg']) def check_init(self): if self.id==None: diff --git a/src/icon.py b/src/icon.py index 2982bf3..d88a119 100755 --- a/src/icon.py +++ b/src/icon.py @@ -60,7 +60,13 @@ def getIcon(name, iconsize): 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) @@ -74,6 +80,8 @@ class Icon(gobject.GObject): self.name=None self.icon=None self.sicon=None + self.sthemebg1=None + self.sthemebg2=None self.lastpress=0 self.ispressed=False @@ -186,6 +194,35 @@ class Icon(gobject.GObject): 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: @@ -224,7 +261,20 @@ class Icon(gobject.GObject): 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) diff --git a/src/widget.py b/src/widget.py index 8a8bd3c..1918367 100755 --- a/src/widget.py +++ b/src/widget.py @@ -162,6 +162,7 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation): config.setLongpress(dt['longpress']) config.setAnimate(dt['animate']) config.setNoBg(dt['nobg']) + config.setThemeBg(dt['themebg']) config.save() # Resize widget diff --git a/src/win_config.py b/src/win_config.py index ba0eac2..92ff48d 100755 --- a/src/win_config.py +++ b/src/win_config.py @@ -65,7 +65,7 @@ class WinConfig(StackableWindow): #, FremantleRotation): #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() @@ -107,6 +107,15 @@ class WinConfig(StackableWindow): #, FremantleRotation): 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") @@ -137,6 +146,13 @@ class WinConfig(StackableWindow): #, FremantleRotation): 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 @@ -172,6 +188,7 @@ class WinConfig(StackableWindow): #, FremantleRotation): 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) @@ -344,6 +361,9 @@ class WinConfig(StackableWindow): #, FremantleRotation): 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() @@ -433,6 +453,7 @@ class WinConfig(StackableWindow): #, FremantleRotation): lp=self.buttonRequireLongpress.get_active() ar=self.buttonAnimateRotation.get_active() nobg=self.buttonNoBackground.get_active() + themebg=self.buttonThemeBackground.get_active() ret={ 'size': sz, @@ -441,6 +462,7 @@ class WinConfig(StackableWindow): #, FremantleRotation): 'longpress': lp, 'animate': ar, 'nobg': nobg, + 'themebg': themebg, } return(ret) -- 1.7.9.5