diff options
Diffstat (limited to 'cardlist.py')
-rw-r--r-- | cardlist.py | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/cardlist.py b/cardlist.py index ba126b9..6bc781c 100644 --- a/cardlist.py +++ b/cardlist.py @@ -46,6 +46,8 @@ class CardList(gtk.EventBox): self.current_pair = None self.current_game_key = None self.model = None + self.pair_list_modified = False + self.game_loaded = False self.vbox = gtk.VBox(False) @@ -64,8 +66,13 @@ class CardList(gtk.EventBox): self.show_all() def load_game(self, game): + if self.game_loaded: + return + self.get_window().freeze_updates() self.model = game.model self.current_game_key = self.model.data['game_file'] + font_name1 = self.model.data['font_name1'] + font_name2 = self.model.data['font_name2'] game_pairs = self.model.pairs game_data = self.model.data self.clean_list(load=True) @@ -99,10 +106,12 @@ class CardList(gtk.EventBox): self.add_pair(None, game_pairs[key].props.achar, game_pairs[key].props.bchar, aimg, bimg, asnd, bsnd, game_pairs[key].props.aspeak, game_pairs[key].props.bspeak, - False, load=True) + font_name1, font_name2, False, load=True) + self.get_window().thaw_updates() self.emit('update-create-toolbar', self.model.data['name'], self.model.data['equal_pairs'], self.model.data['divided']) + self.game_loaded = True def update_model(self, game_model): game_model.pairs = {} @@ -164,6 +173,7 @@ class CardList(gtk.EventBox): pair_card.set_property('bsnd', basename(bsnd)) game_model.pairs[pair] = pair_card + self.pair_list_modified = False def clean_list(self, button=None, load=False): if button != None: @@ -172,20 +182,32 @@ class CardList(gtk.EventBox): del self.pairs self.pairs = [] if not load: + self.pair_list_modified = True self.model.mark_modified() def add_pair(self, widget, achar, bchar, aimg, bimg, asnd, bsnd, - aspeak, bspeak, show=True, load=False): - pair = CardPair(achar, bchar, aimg, bimg, asnd, bsnd, aspeak, bspeak) + aspeak, bspeak, font_name1, font_name2, show=True, load=False): + pair = CardPair(achar, bchar, aimg, bimg, asnd, bsnd, aspeak, bspeak, + font_name1, font_name2) self.vbox.pack_end(pair, False, True) self.pairs.append(pair) pair.connect('pair-selected', self.set_selected) pair.connect('pair-closed', self.rem_pair) if not load: self.model.mark_modified() + self.pair_list_modified = True if show: self.show_all() + def change_font(self, widget, group, font_name): + for pair in self.pairs: + pair.change_font(group, font_name) + if group == 1: + self.model.data['font_name1'] = font_name + if group == 2: + self.model.data['font_name2'] = font_name + self.model.mark_modified() + def rem_pair(self, widget, event): self.vbox.remove(widget) self.pairs.remove(widget) @@ -217,6 +239,7 @@ class CardList(gtk.EventBox): self.current_pair.change_sound(asnd, bsnd) self.current_pair.change_speak(aspeak, bspeak) self.model.mark_modified() + self.pair_list_modified = False class CardPair(gtk.EventBox): @@ -227,7 +250,8 @@ class CardPair(gtk.EventBox): } def __init__(self, text1, text2=None, aimg=None, bimg=None, - asnd=None, bsnd=None, aspeak=None, bspeak=None): + asnd=None, bsnd=None, aspeak=None, bspeak=None, + font_name1=None, font_name2=None): gtk.EventBox.__init__(self) self.bg_color = '#000000' @@ -247,7 +271,7 @@ class CardPair(gtk.EventBox): 'front': {'fill_color': '#4c4d4f', 'stroke_color': '#ffffff', 'opacity': '1'}}, - None, theme.PAIR_SIZE, 1, self.bg_color) + None, theme.PAIR_SIZE, 1, self.bg_color, font_name1) self.bcard1.flip() self.bcard1.set_pixbuf(aimg) align = gtk.Alignment(.5, .5, 0, 0) @@ -261,7 +285,7 @@ class CardPair(gtk.EventBox): 'front': {'fill_color': '#4c4d4f', 'stroke_color': '#ffffff', 'opacity': '1'}}, - None, theme.PAIR_SIZE, 1, self.bg_color) + None, theme.PAIR_SIZE, 1, self.bg_color, font_name2) self.bcard2.flip() self.bcard2.set_pixbuf(bimg) align = gtk.Alignment(.5, .5, 0, 0) @@ -315,6 +339,12 @@ class CardPair(gtk.EventBox): self.asnd = asnd self.bsnd = bsnd + def change_font(self, card, font_name): + if card == 1: + self.bcard1.change_font(font_name) + else: + self.bcard2.change_font(font_name) + def get_text(self, card): if card == 1: return self.bcard1.get_text() |