diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-03-12 17:36:23 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-03-12 17:36:23 (GMT) |
commit | 5adf1244f105b1aa240a046e5c7451e4dc83b638 (patch) | |
tree | fb185698a2ce69311f790c2d28fc321d93107f05 /page.py | |
parent | cc0c9211d868b28d520e68cd044ca6615d0fd75f (diff) |
added highlights to card pages
Diffstat (limited to 'page.py')
-rw-r--r-- | page.py | 162 |
1 files changed, 94 insertions, 68 deletions
@@ -33,8 +33,8 @@ from sprites import Sprites, Sprite CARDS = [['a', _('pat')], ['u', _('up')], - ['i', _('it')], - ['e', _('pet')], + ['I', _('It')], + ['E', _('pEt')], ['o', _('pot')], ['y', _('tummy')], ['p', _('pat')], @@ -44,7 +44,7 @@ CARDS = [['a', _('pat')], ['s', _('is, as, was, says')], ['m', _('mom')], ['s', _("sam, stop, it's")], - ['A', _('read a book')]] + ['A', _('read A book')]] COLORS = [['#FFB0B0', _('light pink')], ['#FFFF80', _('yellow')], @@ -80,8 +80,8 @@ SOUNDS = [['a-as-in-pat.ogg', 'ah'], WORDS = ['a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a', 'a u a a a a a u a a u a a u a u a a a u u a u a a a a a u a a a a a', - 'a i u a i a i a i i i i a a i u i a a u a i i u a i a u a i a a i a', - 'a i u a i a i e a i i e i i a a i u i a a u a i i u a a i e a e a a', + 'a I u a I a I a I I I I a a I u I a a u a I I u a I a u a I a a I a', + 'a i u a i a i E a i i E i i a a i u i a a u a i i u a a i E a E a a', 'a i u a i o a i e a i o a i e o o i i a e i u e a o e i i o a o a o', 'a i u a i o a i e a i o u i e o e i i a a i u i o a a o u y a i i u y o y a a y i o a a o i u y u y a i u o a e a o u u a a i i a e o', # i o e a o i a i o o a o a o', 'pa i up a i o pa i e a i o u i e o e i a a i up i op a a o u y a i i u y o y a a y ip pop a a po u y puppy a i up o a e a op up u', # a a i i a e po i o pe a o i a i o op a op a op', @@ -96,19 +96,19 @@ WORDS = ['a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a', STROKES = [1, 4, 13] # TRANS: e.g., This yellow sign is said u as in up. -MSGS = [_('This %s sign is said\n%s like %s.'), - _('This %s sign is said\ntogether with other sounds\nas in: %s'), - _('This %s sign is\nlightly said\n%s like %s.'), - _('When it looks like this,\nwe read it the same way.')] +MSGS = [[_('This %s sign is said\n'), _('%s like %s.')], + [_('This %s sign is said\ntogether with other sounds\nas in:\n'), + _('%s')], + [_('This %s sign is\nlightly said\n'), _('%s like %s.')], + [_('When it looks like this,\nwe read it the same way.'), '']] MSG_INDEX = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2] -KERN = {'i':0.6, 't':0.8, 'm':1.6, "'":0.4} - +KERN = {'i':0.6, 'I':0.6, 'l':0.6, 't':0.8, 'r':0.8, 'm':1.6, 'w':1.3, "'":0.4} +ALPHABET = "abcdefghijklmnopqrstuvwxyz.,'" ALIGN = 11 -# TODO: add color to a like pat -# finish sound stuff +# TODO: finish sound stuff class Page(): @@ -139,32 +139,43 @@ class Page(): self.left = int((self.width - self.scale * 60) / 2.) self.sprites = Sprites(self.canvas) self.page_index = 0 - self.background = Sprite(self.sprites, 0, 0, svg_str_to_pixbuf( - generate_card(string='', colors=['#FFFFFF', '#FFFFFF'], - scale=self.scale*4))) - self.background.set_layer(1) - self.background.set_label_attributes(40) self.cards = [] self.letters = [] self.colored_letters = [] self.press = None self.release = None self.gplay = None + self.x = 10 + self.y = 10 + self.final_x = 0 + self.offset = int(self.width / 30.) + self.background = Sprite(self.sprites, 0, 0, svg_str_to_pixbuf( + generate_card(string='', colors=['#FFFFFF', '#FFFFFF'], + scale=self.scale*4))) + self.background.set_layer(1) + self.background.set_label_attributes(32) + self.like_card = Sprite(self.sprites, 0, int(self.height * 4 / 5.0), + gtk.gdk.Pixmap(self.canvas.window, self.width, + int(self.height / 5.0), -1)) + self.like_card.set_layer(2) + self.like_gc = self.like_card.images[0].new_gc() + self.like_cm = self.like_gc.get_colormap() + self.bgcolor = self.like_cm.alloc_color('#FFFFFF') self.my_canvas = Sprite(self.sprites, 0, 0, - gtk.gdk.Pixmap(self.canvas.window, self.width, - self.height, -1)) + gtk.gdk.Pixmap(self.canvas.window, self.width, + self.height, -1)) self.my_canvas.set_layer(0) - self.gc = self.my_canvas.images[0].new_gc() - self.cm = self.gc.get_colormap() + self.my_gc = self.my_canvas.images[0].new_gc() + self.cm = self.my_gc.get_colormap() self.bgcolor = self.cm.alloc_color('#FFFFFF') - self.gc.set_foreground(self.bgcolor) - - self.punctuation = Sprite(self.sprites, 0, 0, - svg_str_to_pixbuf(generate_card( - string="'", colors=['#000000', '#000000'], - background=False))) + self.my_gc.set_foreground(self.bgcolor) + for c in ALPHABET: + self.letters.append(Sprite(self.sprites, 0, 0, + svg_str_to_pixbuf(generate_card(string=c, + colors=['#000000', '#000000'], + background=False)))) self.new_page() def new_page(self, saved_state=None, deck_index=0): @@ -184,11 +195,6 @@ class Page(): stroke = True else: stroke = False - self.letters.append(Sprite(self.sprites, 0, 0, - svg_str_to_pixbuf(generate_card( - string=CARDS[self.page_index][0].lower(), - colors=['#000000', '#000000'], - background=False)))) self.colored_letters.append(Sprite(self.sprites, 0, 0, svg_str_to_pixbuf(generate_card( string=CARDS[self.page_index][0].lower(), @@ -201,21 +207,38 @@ class Page(): def _load_card(self): self.cards[self.page_index].set_layer(2) + if MSG_INDEX[self.page_index] == 1: - self.background.set_label(MSGS[1] % (COLORS[self.page_index][1], - CARDS[self.page_index][1])) + self.background.set_label(MSGS[1][0] % (COLORS[self.page_index][1])) else: - self.background.set_label(MSGS[MSG_INDEX[self.page_index]] % \ - (COLORS[self.page_index][1], - CARDS[self.page_index][0].lower(), - CARDS[self.page_index][1])) - + self.background.set_label(MSGS[MSG_INDEX[self.page_index]][0] % \ + (COLORS[self.page_index][1])) self.background.set_layer(1) + + rect = gtk.gdk.Rectangle(0, 0, self.width, int(self.height / 5.0)) + self.like_card.images[0].draw_rectangle(self.my_gc, True, *rect) + self.invalt(0, 0, self.width, int(self.height / 5.0)) + self.x = 0 + self.y = 0 + if MSG_INDEX[self.page_index] == 1: + self._render_phrase(MSGS[1][1] % (CARDS[self.page_index][1]), + self.like_card, self.like_gc) + self.like_card.move((int((self.width - self.final_x) / 2.0), + int(4 * self.height / 5.0))) + else: + self._render_phrase(MSGS[MSG_INDEX[self.page_index]][1] % \ + (CARDS[self.page_index][0], + CARDS[self.page_index][1]), + self.like_card, self.like_gc) + self.like_card.move((int((self.width - self.final_x) / 2.0), + int(3 * self.height / 5.0))) + self.like_card.set_layer(1) + + # Hide all the letter sprites for l in self.letters: l.set_layer(0) for l in self.colored_letters: l.set_layer(0) - self.punctuation.set_layer(0) self.my_canvas.set_layer(0) def reload(self): @@ -227,64 +250,67 @@ class Page(): c.set_layer(0) self.background.set_label('') self.background.set_layer(0) + self.like_card.set_layer(0) + self.activity.status.set_label(_('Read the sounds one at a time.')) rect = gtk.gdk.Rectangle(0, 0, self.width, self.height) - self.my_canvas.images[0].draw_rectangle(self.gc, True, *rect) + self.my_canvas.images[0].draw_rectangle(self.my_gc, True, *rect) self.invalt(0, 0, self.width, self.height) self.my_canvas.set_layer(1) p = 0 - offset = self.width/30 my_list = WORDS[self.page_index].split(' ') # Some pages are aligned left if self.page_index > ALIGN: - x, y = 10, 10 + self.x, self.y = 10, 10 else: - x, y = self._xy(0) + self.x, self.y = self._xy(0) # Each list is a collection of phrases, separated by spaces for phrase in my_list: + self._render_phrase(phrase, self.my_canvas, self.my_gc) + + # Put a long space between each phrase + if self.page_index > ALIGN: + self.x += self.offset + else: + self.x += int(uniform(30, self.width/8)) + if self.x > self.width * 7 / 8.0: + self.x, self.y = self._xy(self.y) + + def _render_phrase(self, phrase, canvas, gc): # The words in the list are separated by dashes words = phrase.split('-') for word in words: # Will word run off the right edge? - if x + len(word) * offset > self.width: - x, y = self._xy(y) + if self.x + len(word) * self.offset > self.width: + self.x, self.y = self._xy(self.y) # Process each character in the word for c in range(len(word)): if word[c] == CARDS[self.page_index][0]: self._draw_pixbuf( self.colored_letters[self.page_index].images[0], - x, y) - elif word[c] == "'": - self._draw_pixbuf(self.punctuation.images[0], x, y) + self.x, self.y, canvas, gc) else: - for j in range(self.page_index): - if CARDS[j][0] == word[c]: - self._draw_pixbuf(self.letters[j].images[0], - x, y) + if word[c] in ALPHABET: + i = ALPHABET.index(word[c]) + self._draw_pixbuf(self.letters[i].images[0], + self.x, self.y, canvas, gc) if word[c] in KERN: - x += offset * KERN[word[c]] + self.x += self.offset * KERN[word[c]] else: - x += offset + self.x += self.offset + self.final_x = self.x # Put a space after each word - if x > 10: - x += int(offset / 1.6) - - # Put a long space between each phrase - if self.page_index > ALIGN: - x += offset - else: - x += int(uniform(30, self.width/8)) - if x > self.width * 7 / 8.0: - x, y = self._xy(y) + if self.x > 10: + self.x += int(self.offset / 1.6) - def _draw_pixbuf(self, pixbuf, x, y): + def _draw_pixbuf(self, pixbuf, x, y, canvas, gc): w = pixbuf.get_width() h = pixbuf.get_height() - self.my_canvas.images[0].draw_pixbuf(self.gc, pixbuf, 0, 0, + canvas.images[0].draw_pixbuf(gc, pixbuf, 0, 0, int(x), int(y)) self.invalt(x, y, w, h) |