本文整理汇总了Python中sugar3.graphics.toggletoolbutton.ToggleToolButton.handler_block方法的典型用法代码示例。如果您正苦于以下问题:Python ToggleToolButton.handler_block方法的具体用法?Python ToggleToolButton.handler_block怎么用?Python ToggleToolButton.handler_block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.toggletoolbutton.ToggleToolButton
的用法示例。
在下文中一共展示了ToggleToolButton.handler_block方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpeechToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import handler_block [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()
示例2: PrimaryToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import handler_block [as 别名]
#.........这里部分代码省略.........
if self._loading:
self._show_stop_icon()
else:
if not self._tabbed_view.is_current_page_pdf():
self._show_reload_icon()
def _show_no_icon(self):
self.entry.remove_icon(iconentry.ICON_ENTRY_SECONDARY)
def _show_stop_icon(self):
self.entry.set_icon_from_name(iconentry.ICON_ENTRY_SECONDARY,
'entry-stop')
def _show_reload_icon(self):
self.entry.set_icon_from_name(iconentry.ICON_ENTRY_SECONDARY,
'entry-refresh')
def _show_clear_icon(self):
self.entry.set_icon_from_name(iconentry.ICON_ENTRY_SECONDARY,
'entry-cancel')
def _update_navigation_buttons(self):
can_go_back = self._browser.can_go_back()
self._back.props.sensitive = can_go_back
can_go_forward = self._browser.can_go_forward()
self._forward.props.sensitive = can_go_forward
is_webkit_browser = isinstance(self._browser, Browser)
self._go_home.props.sensitive = is_webkit_browser
if is_webkit_browser:
self._reload_session_history()
with self._link_add.handler_block(self._link_add_toggled_hid):
uri = self._browser.get_uri()
self._link_add.props.active = self.model.has_link(uri)
def __link_removed_cb(self, model):
self._update_navigation_buttons()
def _entry_activate_cb(self, entry):
url = entry.props.text
effective_url = self._tabbed_view.normalize_or_autosearch_url(url)
self._browser.load_uri(effective_url)
self._browser.loading_uri = effective_url
self.entry.props.address = effective_url
self._browser.grab_focus()
def _go_home_cb(self, button):
self.emit('go-home')
def _go_library_cb(self, button):
self.emit('go-library')
def _set_home_cb(self, button):
self._reset_home_menu.set_visible(True)
self.emit('set-home')
def _reset_home_cb(self, button):
self._reset_home_menu.set_visible(False)
self.emit('reset-home')
def _go_back_cb(self, button):
self._browser.go_back()
def _go_forward_cb(self, button):