Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/createcardpanel.py
diff options
context:
space:
mode:
Diffstat (limited to 'createcardpanel.py')
-rw-r--r--createcardpanel.py85
1 files changed, 68 insertions, 17 deletions
diff --git a/createcardpanel.py b/createcardpanel.py
index dcf2f19..e490f64 100644
--- a/createcardpanel.py
+++ b/createcardpanel.py
@@ -29,22 +29,26 @@ from sugar.graphics import style
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.icon import Icon
from sugar.graphics.palette import Palette
-from port.widgets import ToggleToolButton
-from port.widgets import ToolComboBox
+from sugar.graphics.toggletoolbutton import ToggleToolButton
+from sugar.graphics.toolcombobox import ToolComboBox
+from fontcombobox import FontComboBox
from port import chooser
import theme
import speak.espeak
import speak.widgets
import speak.face
+from port.roundbox import RoundBox
+import model
_logger = logging.getLogger('memorize-activity')
class CreateCardPanel(gtk.EventBox):
__gsignals__ = {
- 'add-pair': (SIGNAL_RUN_FIRST, None, 8 * [TYPE_PYOBJECT]),
+ 'add-pair': (SIGNAL_RUN_FIRST, None, 10 * [TYPE_PYOBJECT]),
'update-pair': (SIGNAL_RUN_FIRST, None, 8 * [TYPE_PYOBJECT]),
+ 'change-font': (SIGNAL_RUN_FIRST, None, 2 * [TYPE_PYOBJECT]),
}
def __init__(self):
@@ -91,8 +95,8 @@ class CreateCardPanel(gtk.EventBox):
# Set card editors
- self.cardeditor1 = CardEditor()
- self.cardeditor2 = CardEditor()
+ self.cardeditor1 = CardEditor(1)
+ self.cardeditor2 = CardEditor(2)
self.clean(None)
self.cardeditor1.connect('has-text', self.receive_text_signals)
self.cardeditor2.connect('has-text', self.receive_text_signals)
@@ -100,6 +104,8 @@ class CreateCardPanel(gtk.EventBox):
self.cardeditor2.connect('has-picture', self.receive_picture_signals)
self.cardeditor1.connect('has-sound', self.receive_sound_signals)
self.cardeditor2.connect('has-sound', self.receive_sound_signals)
+ self.cardeditor1.connect('change-font', self.receive_font_signals)
+ self.cardeditor2.connect('change-font', self.receive_font_signals)
# edit panel
@@ -114,6 +120,15 @@ class CreateCardPanel(gtk.EventBox):
self.show_all()
+ def update_font_combos(self, widget, data, grid):
+ logging.error('update font %s', data)
+ if 'font_name1' in data:
+ self.cardeditor1.set_font_name(data['font_name1'])
+ self.cardeditor1.card.change_font(data['font_name1'])
+ if 'font_name2' in data:
+ self.cardeditor2.set_font_name(data['font_name2'])
+ self.cardeditor2.card.change_font(data['font_name2'])
+
def emit_add_pair(self, widget):
self._addbutton.set_sensitive(False)
if self.equal_pairs:
@@ -124,7 +139,9 @@ class CreateCardPanel(gtk.EventBox):
self.cardeditor1.get_snd(),
self.cardeditor1.get_snd(),
self.cardeditor1.get_speak(),
- self.cardeditor1.get_speak())
+ self.cardeditor1.get_speak(),
+ self.cardeditor1.get_font_name(),
+ self.cardeditor1.get_font_name())
else:
self.emit('add-pair', self.cardeditor1.get_text(),
self.cardeditor2.get_text(),
@@ -133,7 +150,9 @@ class CreateCardPanel(gtk.EventBox):
self.cardeditor1.get_snd(),
self.cardeditor2.get_snd(),
self.cardeditor1.get_speak(),
- self.cardeditor2.get_speak())
+ self.cardeditor2.get_speak(),
+ self.cardeditor1.get_font_name(),
+ self.cardeditor2.get_font_name())
self.clean(None)
def emit_update_pair(self, widget):
@@ -214,6 +233,16 @@ class CreateCardPanel(gtk.EventBox):
self._card2_has_sound = has_sound
self._update_buttom_status()
+ def receive_font_signals(self, widget, font_name):
+ if self.equal_pairs:
+ self.emit('change-font', 1, font_name)
+ self.emit('change-font', 2, font_name)
+ else:
+ if widget == self.cardeditor1:
+ self.emit('change-font', 1, font_name)
+ if widget == self.cardeditor2:
+ self.emit('change-font', 2, font_name)
+
def _update_buttom_status(self):
if not self.equal_pairs:
if (self._card1_has_text or self._card1_has_picture \
@@ -245,13 +274,14 @@ class CardEditor(gtk.EventBox):
'has-text': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),
'has-picture': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),
'has-sound': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),
+ 'change-font': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),
}
- def __init__(self):
+ def __init__(self, editor_index):
gtk.EventBox.__init__(self)
self.snd = None
-
+ self.editor_index = editor_index
self.temp_folder = None
box = gtk.VBox()
@@ -282,34 +312,52 @@ class CardEditor(gtk.EventBox):
self.textentry.connect('changed', self.update_text)
box.pack_start(self.textentry, False)
- toolbar = gtk.HBox()
+ toolbar = RoundBox()
browsepicture = ToolButton(
icon_name='import_picture',
tooltip=_('Insert picture'))
- toolbar.pack_start(browsepicture, False)
+ toolbar.add(browsepicture)
browsesound = ToolButton(
icon_name='import_sound',
tooltip=_('Insert sound'))
- toolbar.pack_start(browsesound, False)
+ toolbar.add(browsesound)
browsepicture.connect('clicked', self._load_image)
browsesound.connect('clicked', self._load_audio)
if speak.espeak.supported:
self.usespeak = ToggleToolButton(
- named_icon='speak',
- palette=SpeakPalette(self))
- toolbar.pack_start(self.usespeak, False)
+ named_icon='speak')
+ self.usespeak.set_palette(SpeakPalette(self))
+ toolbar.add(self.usespeak)
self.usespeak.connect('toggled', self._usespeak_cb)
else:
self.usespeak = None
- box.pack_start(toolbar, False)
+ self.font_combo = FontComboBox()
+ self.id_font_changed = self.font_combo.connect("changed",
+ self.__font_changed_cb)
+ self.font_combo.set_font_name(model.DEFAULT_FONT)
+
+ box.pack_start(self.font_combo, True, True, 0)
+ box.pack_start(toolbar, True, True, 0)
self.add(box)
+ def __font_changed_cb(self, widget):
+ font = widget.get_font_name()
+ logging.error('Selected font %s', font)
+ if font:
+ self.card.change_font(font)
+ self.emit('change-font', font)
+
+ def set_font_name(self, font_name):
+ self.font_combo.handler_block(self.id_font_changed)
+ self.font_combo.set_font_name(font_name)
+ self.font_combo.handler_unblock(self.id_font_changed)
+
def update_text(self, entry):
self.card.change_text(entry.get_text())
if len(entry.get_text()) == 0:
@@ -415,6 +463,9 @@ class CardEditor(gtk.EventBox):
def get_snd(self):
return self.snd
+ def get_font_name(self):
+ return self.font_combo.get_font_name()
+
def clean(self):
self.textentry.set_text('')
self.card.set_pixbuf(None)
@@ -422,7 +473,7 @@ class CardEditor(gtk.EventBox):
self.emit('has-text', False)
self.emit('has-picture', False)
self.emit('has-sound', False)
- if self.usespeak is not None:
+ if self.usespeak is not None and self.usespeak.palette is not None:
self.usespeak.props.active = False
self.usespeak.palette.face.shut_up()