Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/svgcard.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-04-16 19:00:09 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-04-17 18:11:36 (GMT)
commit7ed15ed98ee5f2a53a5dac8a75381bac6196c19e (patch)
treeef01c2e006c97cd6ae4daac6004239aa1a6e7a6d /svgcard.py
parent862171dbe24dbf6e877a672b22c14ac493bb096a (diff)
Add combos to enable the user to change the font used in the cards. v2
This work is based in the contributions of Flavio Danesse <fdanesse@activitycentral.com> and Ariel Calzada <ariel.calzada@gmail.com> The fonts are saved in the game file. v2: Solve error in add-pair, and initialization of card font in the CardEditor Signed-of-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'svgcard.py')
-rw-r--r--svgcard.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/svgcard.py b/svgcard.py
index 7500f3f..631640e 100644
--- a/svgcard.py
+++ b/svgcard.py
@@ -29,6 +29,7 @@ from sugar.util import LRU
import theme
import face
import speak.voice
+import model
_logger = logging.getLogger('memorize-activity')
@@ -57,7 +58,7 @@ class SvgCard(gtk.EventBox):
cache = {}
def __init__(self, identifier, pprops, jpeg, size,
- align, bg_color='#000000'):
+ align, bg_color='#000000', font_name=model.DEFAULT_FONT):
gtk.EventBox.__init__(self)
self.bg_color = bg_color
@@ -70,6 +71,7 @@ class SvgCard(gtk.EventBox):
self.size = size
self.align = align
self.text_layouts = [None, None]
+ self.font_name = font_name
self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(bg_color))
self.set_size_request(size, size)
@@ -300,7 +302,7 @@ class SvgCard(gtk.EventBox):
layout = self.create_pango_layout(text)
layout.set_width(PIXELS_PANGO(card_size))
layout.set_wrap(pango.WRAP_WORD)
- desc = pango.FontDescription('Deja Vu Sans bold ' + str(size))
+ desc = pango.FontDescription(self.font_name + " " + str(size))
layout.set_font_description(desc)
if layout.get_line_count() <= max_lines_count and \
@@ -317,6 +319,17 @@ class SvgCard(gtk.EventBox):
return layout
+ def change_font(self, font_name):
+ # remove from local cache
+ self.text_layouts[self.flipped] = False
+ text = self.props['front_text']['card_text']
+ key = (self.size, text)
+ if key in _text_layout_cache:
+ del _text_layout_cache[key]
+
+ self.font_name = font_name
+ self.queue_draw()
+
def set_background(self, color):
self.bg_color = color
self.draw.modify_bg(gtk.STATE_NORMAL,