本文整理汇总了Python中sugar3.graphics.toggletoolbutton.ToggleToolButton.handler_unblock方法的典型用法代码示例。如果您正苦于以下问题:Python ToggleToolButton.handler_unblock方法的具体用法?Python ToggleToolButton.handler_unblock怎么用?Python ToggleToolButton.handler_unblock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.toggletoolbutton.ToggleToolButton
的用法示例。
在下文中一共展示了ToggleToolButton.handler_unblock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpeechToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import handler_unblock [as 别名]
#.........这里部分代码省略.........
speech_parameters = {}
data_path = os.path.join(self._activity.get_activity_root(), "data")
data_file_name = os.path.join(data_path, "speech_params.json")
if os.path.exists(data_file_name):
f = open(data_file_name, "r")
try:
speech_parameters = json.load(f)
speech.voice = speech_parameters["voice"]
finally:
f.close()
else:
speech.voice = self.get_default_voice()
logging.error("Default voice %s", speech.voice)
self._cnf_client.add_dir("/desktop/sugar/speech", GConf.ClientPreloadType.PRELOAD_NONE)
speech.pitch = self._cnf_client.get_int("/desktop/sugar/speech/pitch")
speech.rate = self._cnf_client.get_int("/desktop/sugar/speech/rate")
self._cnf_client.notify_add("/desktop/sugar/speech/pitch", self.__conf_changed_cb, None)
self._cnf_client.notify_add("/desktop/sugar/speech/rate", self.__conf_changed_cb, None)
def get_default_voice(self):
"""Try to figure out the default voice, from the current locale
($LANG)
Fall back to espeak's voice called Default."""
voices = speech.get_all_voices()
locale = os.environ.get("LANG", "")
language_location = locale.split(".", 1)[0].lower()
language = language_location.split("_")[0]
variant = ""
if language_location.find("_") > -1:
variant = language_location.split("_")[1]
# if the language is es but not es_es default to es_la (latin voice)
if language == "es" and language_location != "es_es":
language_location = "es_la"
best = voices.get(language_location) or voices.get(language) or "default"
logging.debug("Best voice for LANG %s seems to be %s", locale, best)
return [best, language, variant]
def __conf_changed_cb(self, client, connection_id, entry, args):
key = entry.get_key()
value = client.get_int(key)
if key == "/desktop/sugar/speech/pitch":
speech.pitch = value
if key == "/desktop/sugar/speech/rate":
speech.rate = value
def save_speech_parameters(self):
speech_parameters = {}
speech_parameters["voice"] = speech.voice
data_path = os.path.join(self._activity.get_activity_root(), "data")
data_file_name = os.path.join(data_path, "speech_params.json")
f = open(data_file_name, "w")
try:
json.dump(speech_parameters, f)
finally:
f.close()
def reset_buttons_cb(self):
logging.error("reset buttons")
self.play_btn.set_icon_name("media-playback-start")
self.stop_btn.set_sensitive(False)
self.play_btn.handler_block(self.play_toggled_handler)
self.play_btn.set_active(False)
self.play_btn.handler_unblock(self.play_toggled_handler)
self.is_paused = False
def play_cb(self, widget):
self.stop_btn.set_sensitive(True)
if widget.get_active():
self.play_btn.set_icon_name("media-playback-pause")
logging.error("Paused %s", self.is_paused)
if not self.is_paused:
# get the text to speech, if there are a selection,
# play selected text, if not, play all
abi = self._activity.abiword_canvas
selection = abi.get_selection("text/plain")
if not selection or selection[0] is None or selection[1] == 0:
# nothing selected
abi.select_all()
text = abi.get_selection("text/plain")[0]
abi.moveto_bod()
else:
text = selection[0]
speech.play(text)
else:
logging.error("Continue play")
speech.continue_play()
else:
self.play_btn.set_icon_name("media-playback-start")
self.is_paused = True
speech.pause()
def stop_cb(self, widget):
self.stop_btn.set_sensitive(False)
self.play_btn.set_icon_name("media-playback-start")
self.play_btn.set_active(False)
self.is_paused = False
speech.stop()