diff options
Diffstat (limited to 'activity.py')
-rw-r--r-- | activity.py | 138 |
1 files changed, 24 insertions, 114 deletions
diff --git a/activity.py b/activity.py index d4f0e2a..b973ca9 100644 --- a/activity.py +++ b/activity.py @@ -31,17 +31,16 @@ import pango import cjson from gettext import gettext as _ -from sugar.graphics.toolbarbox import ToolbarButton +from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toggletoolbutton import ToggleToolButton from sugar.graphics.radiotoolbutton import RadioToolButton -from combobox import ComboBox -from sugar.graphics.toolbarbox import ToolbarBox -from shared_activity import SharedActivity -from sugar.activity.widgets import ActivityToolbarButton -from sugar.activity.widgets import StopButton +from toolkit.toolitem import ToolWidget +from toolkit.combobox import ComboBox +from toolkit.toolbarbox import ToolbarBox +from toolkit.activity import SharedActivity +from toolkit.activity_widgets import * -from toolitem import ToolWidget import eye import glasses import mouth @@ -60,39 +59,13 @@ MODE_TYPE = 1 MODE_BOT = 2 MODE_CHAT = 3 -_NEW_INSTANCE = 0 -_NEW_INSTANCE = 1 -_PRE_INSTANCE = 2 -_POST_INSTANCE = 3 - - -class CursorFactory: - - __shared_state = {"cursors": {}} - - def __init__(self): - self.__dict__ = self.__shared_state - - def get_cursor(self, cur_type): - if not cur_type in self.cursors: - cur = gtk.gdk.Cursor(cur_type) - self.cursors[cur_type] = cur - return self.cursors[cur_type] - class SpeakActivity(SharedActivity): def __init__(self, handle): self.notebook = gtk.Notebook() - self.notebook.connect_after('map', self.__map_canvasactivity_cb) SharedActivity.__init__(self, self.notebook, SERVICE, handle) - self._cursor = None - self.set_cursor(gtk.gdk.LEFT_PTR) - self.__resume_filename = None - self.__postponed_share = [] - self.__on_save_instance = [] - self.__state = _NEW_INSTANCE self._mode = MODE_TYPE self.numeyesadj = None @@ -126,8 +99,8 @@ class SpeakActivity(SharedActivity): # desktop self.notebook.show() - self.notebook.props.show_border = False - self.notebook.props.show_tabs = False + self.notebook.props.show_border=False + self.notebook.props.show_tabs=False box.show_all() self.notebook.append_page(box) @@ -150,7 +123,7 @@ class SpeakActivity(SharedActivity): self.voices = ComboBox() for name in sorted(voice.allVoices().keys()): vn = voice.allVoices()[name] - n = name[:26] + ".." + n = name [ : 26 ] + ".." self.voices.append_item(vn, n) self.voices.select(voice.defaultVoice()) @@ -203,71 +176,10 @@ class SpeakActivity(SharedActivity): toolbox.show_all() self.toolbar_box = toolbox - def _share(self, tube_conn, initiator): - logging.debug('Activity._share state=%s' % self.__state) - - if self.__state == _NEW_INSTANCE: - self.__postponed_share.append((tube_conn, initiator)) - self.__state = _PRE_INSTANCE - elif self.__state == _PRE_INSTANCE: - self.__postponed_share.append((tube_conn, initiator)) - self.__instance() - elif self.__state == _POST_INSTANCE: - self.share_instance(tube_conn, initiator) - - def set_cursor(self, cursor): - if not isinstance(cursor, gtk.gdk.Cursor): - cursor = CursorFactory().get_cursor(cursor) - - if self._cursor != cursor: - self._cursor = cursor - self.window.set_cursor(self._cursor) - - def __map_canvasactivity_cb(self, widget): - logging.debug('Activity.__map_canvasactivity_cb state=%s' % \ - self.__state) - - if self.__state == _NEW_INSTANCE: - self.__instance() - elif self.__state == _NEW_INSTANCE: - self.__state = _PRE_INSTANCE - elif self.__state == _PRE_INSTANCE: - self.__instance() - - return False - - def __instance(self): - logging.debug('Activity.__instance') - - if self.__resume_filename: - self.resume_instance(self.__resume_filename) - else: - self.new_instance() - - for i in self.__postponed_share: - self.share_instance(*i) - self.__postponed_share = [] - - self.__state = _POST_INSTANCE - - def read_file(self, file_path): - self.__resume_filename = file_path - if self.__state == _NEW_INSTANCE: - self.__state = _PRE_INSTANCE - elif self.__state == _PRE_INSTANCE: - self.__instance() - - def write_file(self, file_path): - for cb, args in self.__on_save_instance: - cb(*args) - self.save_instance(file_path) - def new_instance(self): self.voices.connect('changed', self.__changed_voices_cb) - self.pitchadj.connect("value_changed", self.pitch_adjusted_cb, - self.pitchadj) - self.rateadj.connect("value_changed", self.rate_adjusted_cb, - self.rateadj) + self.pitchadj.connect("value_changed", self.pitch_adjusted_cb, self.pitchadj) + self.rateadj.connect("value_changed", self.rate_adjusted_cb, self.rateadj) self.mouth_shape_combo.connect('changed', self.mouth_changed_cb, False) self.mouth_changed_cb(self.mouth_shape_combo, True) self.numeyesadj.connect("value_changed", self.eyes_changed_cb, False) @@ -336,7 +248,7 @@ class SpeakActivity(SharedActivity): voicebar = gtk.Toolbar() self.pitchadj = gtk.Adjustment(self.face.status.pitch, 0, - espeak.PITCH_MAX, 1, espeak.PITCH_MAX / 10, 0) + espeak.PITCH_MAX, 1, espeak.PITCH_MAX/10, 0) pitchbar = gtk.HScale(self.pitchadj) pitchbar.set_draw_value(False) # pitchbar.set_inverted(True) @@ -348,8 +260,8 @@ class SpeakActivity(SharedActivity): label_text=_('Pitch:')) voicebar.insert(pitchbar_toolitem, -1) - self.rateadj = gtk.Adjustment(self.face.status.rate, 0, - espeak.RATE_MAX, 1, espeak.RATE_MAX / 10, 0) + self.rateadj = gtk.Adjustment(self.face.status.rate, 0, espeak.RATE_MAX, + 1, espeak.RATE_MAX / 10, 0) ratebar = gtk.HScale(self.rateadj) ratebar.set_draw_value(False) # ratebar.set_inverted(True) @@ -377,8 +289,7 @@ class SpeakActivity(SharedActivity): self.mouth_shape_combo = ComboBox() self.mouth_shape_combo.append_item(mouth.Mouth, _("Simple")) - self.mouth_shape_combo.append_item(waveform_mouth.WaveformMouth, - _("Waveform")) + self.mouth_shape_combo.append_item(waveform_mouth.WaveformMouth, _("Waveform")) self.mouth_shape_combo.append_item(fft_mouth.FFTMouth, _("Frequency")) self.mouth_shape_combo.set_active(0) @@ -446,15 +357,15 @@ class SpeakActivity(SharedActivity): keyname = gtk.gdk.keyval_name(event.keyval) if keyname == "Up": index = self.entrycombo.get_active() - if index > 0: - index -= 1 + if index>0: + index-=1 self.entrycombo.set_active(index) - self.entry.select_region(0, -1) + self.entry.select_region(0,-1) return True elif keyname == "Down": index = self.entrycombo.get_active() - if index < len(self.entrycombo.get_model()) - 1: - index += 1 + if index<len(self.entrycombo.get_model())-1: + index+=1 self.entrycombo.set_active(index) self.entry.select_region(0, -1) return True @@ -473,16 +384,15 @@ class SpeakActivity(SharedActivity): else: self.face.say(text) - # add this text to our history unless - # it is the same as the last item + # add this text to our history unless it is the same as the last item history = self.entrycombo.get_model() - if len(history) == 0 or history[-1][0] != text: + if len(history)==0 or history[-1][0] != text: self.entrycombo.append_text(text) # don't let the history get too big - while len(history) > 20: + while len(history)>20: self.entrycombo.remove_text(0) # select the new item - self.entrycombo.set_active(len(history) - 1) + self.entrycombo.set_active(len(history)-1) # select the whole text entry.select_region(0, -1) |