本文整理汇总了Python中sugar3.graphics.toggletoolbutton.ToggleToolButton.set_icon_name方法的典型用法代码示例。如果您正苦于以下问题:Python ToggleToolButton.set_icon_name方法的具体用法?Python ToggleToolButton.set_icon_name怎么用?Python ToggleToolButton.set_icon_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.toggletoolbutton.ToggleToolButton
的用法示例。
在下文中一共展示了ToggleToolButton.set_icon_name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CreateToolbarBuilder
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import set_icon_name [as 别名]
class CreateToolbarBuilder(GObject.GObject):
__gtype_name__ = 'CreateToolbar'
__gsignals__ = {
'create_new_game': (GObject.SignalFlags.RUN_FIRST, None, []),
'create_equal_pairs': (GObject.SignalFlags.RUN_FIRST,
None, [GObject.TYPE_PYOBJECT]),
}
def __init__(self, activity):
GObject.GObject.__init__(self)
self.activity = activity
self.toolbar = self.activity.get_toolbar_box().toolbar
self._equal_pairs = ToggleToolButton('pair-non-equals')
self._equal_pairs.set_tooltip(_('Match different tiles'))
self._equal_pairs.connect('toggled', self._emit_equal_pairs)
self.toolbar.insert(self._equal_pairs, -1)
self._grouped = ToggleToolButton('grouped_game1')
self._grouped.set_tooltip(_('Mixed tiles game'))
self._grouped.connect('toggled', self._grouped_cb)
self.toolbar.insert(self._grouped, -1)
self._clear_button = ToolButton('edit-clear')
self._clear_button.set_tooltip(_('Clear all tiles'))
self._clear_button.connect('clicked', self._clear_game_bt)
self.toolbar.insert(self._clear_button, -1)
self.toolbar.show_all()
def _add_widget(self, widget, expand=False):
tool_item = Gtk.ToolItem()
tool_item.set_expand(expand)
tool_item.add(widget)
widget.show()
self.toolbar.insert(tool_item, -1)
tool_item.show()
def _clear_game_bt(self, button):
if self.activity.game.model.is_demo or \
len(self.activity.cardlist.pairs) == 0:
self.clear_game()
else:
alert = Alert()
alert.props.title = _('Clear all the tiles from the game?')
icon = Icon(icon_name='dialog-ok')
alert.add_button(1, _('Clear'), icon)
icon = Icon(icon_name='dialog-cancel')
alert.add_button(0, _('Do not clear'), icon)
alert.connect('response', self._clear_game_alert_cb)
self.activity.add_alert(alert)
def _clear_game_alert_cb(self, alert, response_id):
self.activity.remove_alert(alert)
if response_id == 1:
self.clear_game()
def clear_game(self):
self._equal_pairs.set_active(False)
self._grouped.set_active(False)
self.emit('create_new_game')
def update_controls(self, active):
self._equal_pairs.set_sensitive(active)
self._grouped.set_sensitive(active)
self._clear_button.set_sensitive(active)
def _emit_equal_pairs(self, widget):
if self._equal_pairs.get_active():
self._equal_pairs.set_icon_name('pair-equals')
self._equal_pairs.set_tooltip(_('Match identical tiles'))
equal_pairs = '1'
else:
self._equal_pairs.set_icon_name('pair-non-equals')
self._equal_pairs.set_tooltip(_('Match different tiles'))
equal_pairs = '0'
self.emit('create_equal_pairs', self._equal_pairs.get_active())
logging.debug('createtoolbar._emit_equal_pairs')
if self.activity.game.model.data['equal_pairs'] != equal_pairs:
self.activity.game.model.data['equal_pairs'] = equal_pairs
self.activity.game.model.mark_modified()
def _grouped_cb(self, widget):
if self._grouped.get_active():
self._grouped.set_icon_name('grouped_game2')
self._grouped.set_tooltip(_('Grouped tiles game'))
divided = '1'
else:
self._grouped.set_icon_name('grouped_game1')
self._grouped.set_tooltip(_('Mixed tiles game'))
divided = '0'
logging.debug('createtoolbar._grouped_cb')
if self.activity.game.model.data['divided'] != divided:
self.activity.game.model.data['divided'] = divided
self.activity.game.model.mark_modified()
#.........这里部分代码省略.........
示例2: SpeechToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import set_icon_name [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()
示例3: ViewToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import set_icon_name [as 别名]
class ViewToolbar(Gtk.Toolbar):
__gtype_name__ = 'ViewToolbar'
__gsignals__ = {
'go-fullscreen': (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE,
([])),
'toggle-index-show': (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE,
([bool])),
'toggle-tray-show': (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE,
([bool])), }
def __init__(self):
Gtk.Toolbar.__init__(self)
self._view = None
self._navigator_button = ToggleToolButton('view-list')
self._navigator_button.set_tooltip(_('Table of contents'))
self._navigator_button.connect('toggled', self.__navigator_toggled_cb)
self.insert(self._navigator_button, -1)
self._spacer_navigator = Gtk.SeparatorToolItem()
self._spacer_navigator.props.draw = False
self.insert(self._spacer_navigator, -1)
self._zoom_out = ToolButton('zoom-out')
self._zoom_out.set_tooltip(_('Zoom out'))
self._zoom_out.connect('clicked', self._zoom_out_cb)
self.insert(self._zoom_out, -1)
self._zoom_out.show()
self._zoom_in = ToolButton('zoom-in')
self._zoom_in.set_tooltip(_('Zoom in'))
self._zoom_in.connect('clicked', self._zoom_in_cb)
self.insert(self._zoom_in, -1)
self._zoom_in.show()
self._zoom_to_width = ToolButton('zoom-to-width')
self._zoom_to_width.set_tooltip(_('Zoom to width'))
self._zoom_to_width.connect('clicked', self._zoom_to_width_cb)
self.insert(self._zoom_to_width, -1)
self._zoom_to_width.show()
self._zoom_to_fit = ToolButton('zoom-best-fit')
self._zoom_to_fit.set_tooltip(_('Zoom to fit'))
self._zoom_to_fit.connect('clicked', self._zoom_to_fit_cb)
self.insert(self._zoom_to_fit, -1)
self._zoom_to_fit.show()
self._zoom_to_original = ToolButton('zoom-original')
self._zoom_to_original.set_tooltip(_('Actual size'))
self._zoom_to_original.connect('clicked', self._actual_size_cb)
self.insert(self._zoom_to_original, -1)
self._zoom_to_original.show()
spacer = Gtk.SeparatorToolItem()
spacer.props.draw = True
self.insert(spacer, -1)
spacer.show()
self._fullscreen = ToolButton('view-fullscreen')
self._fullscreen.set_tooltip(_('Fullscreen'))
self._fullscreen.connect('clicked', self._fullscreen_cb)
self.insert(self._fullscreen, -1)
self._fullscreen.show()
self.traybutton = ToggleToolButton('tray-show')
self.traybutton.set_icon_name('tray-favourite')
self.traybutton.connect('toggled', self.__tray_toggled_cb)
#self.traybutton.props.sensitive = False
self.traybutton.props.active = False
self.insert(self.traybutton, -1)
self.traybutton.show()
self._view_notify_zoom_handler = None
spacer = Gtk.SeparatorToolItem()
spacer.props.draw = True
self.insert(spacer, -1)
spacer.show()
self._rotate_left = ToolButton('rotate_anticlockwise')
self._rotate_left.set_tooltip(_('Rotate left'))
self._rotate_left.connect('clicked', self._rotate_left_cb)
self.insert(self._rotate_left, -1)
self._rotate_left.show()
self._rotate_right = ToolButton('rotate_clockwise')
self._rotate_right.set_tooltip(_('Rotate right'))
self._rotate_right.connect('clicked', self._rotate_right_cb)
self.insert(self._rotate_right, -1)
self._rotate_right.show()
def set_view(self, view):
self._view = view
self._update_zoom_buttons()
def show_nav_button(self):
self._navigator_button.show()
self._spacer_navigator.show()
#.........这里部分代码省略.........
示例4: SpeechToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import set_icon_name [as 别名]
#.........这里部分代码省略.........
self.play_btn.connect('toggled', self.play_cb)
self.insert(self.play_btn, -1)
self.play_btn.set_tooltip(_('Play / Pause'))
# Stop button
self.stop_btn = ToolButton('media-playback-stop')
self.stop_btn.show()
self.stop_btn.connect('clicked', self.stop_cb)
self.stop_btn.set_sensitive(False)
self.insert(self.stop_btn, -1)
self.stop_btn.set_tooltip(_('Stop'))
self.voice_combo = ComboBox()
for voice in self.sorted_voices:
self.voice_combo.append_item(voice, voice[0])
self.voice_combo.set_active(default)
self.voice_combo.connect('changed', self.voice_changed_cb)
combotool = ToolComboBox(self.voice_combo)
self.insert(combotool, -1)
combotool.show()
speech.reset_buttons_cb = self.reset_buttons_cb
def compare_voices(self, a, b):
if a[0].lower() == b[0].lower():
return 0
if a[0] .lower() < b[0].lower():
return -1
if a[0] .lower() > b[0].lower():
return 1
def voice_changed_cb(self, combo):
speech.voice = combo.props.value
speech.say(speech.voice[0])
self.save_speech_parameters()
def load_speech_parameters(self):
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()
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 __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):
self.play_btn.set_icon_name('media-playback-start')
self.stop_btn.set_sensitive(False)
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')
if not self.is_paused:
speech.play(self._activity._view.get_marked_words())
else:
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()
示例5: ViewToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import set_icon_name [as 别名]
class ViewToolbar(Gtk.Toolbar):
def __init__(self, activity):
GObject.GObject.__init__(self)
self._browser = None
self._activity = activity
self.zoomout = ToolButton('zoom-out')
self.zoomout.set_tooltip(_('Zoom out'))
self.zoomout.connect('clicked', self.__zoomout_clicked_cb)
self.insert(self.zoomout, -1)
self.zoomout.show()
self.zoomin = ToolButton('zoom-in')
self.zoomin.set_tooltip(_('Zoom in'))
self.zoomin.connect('clicked', self.__zoomin_clicked_cb)
self.insert(self.zoomin, -1)
self.zoomin.show()
self.zoom_original = ToolButton('zoom-original')
self.zoom_original.set_tooltip(_('Actual size'))
self.zoom_original.connect('clicked', self.__zoom_original_clicked_cb)
self.insert(self.zoom_original, -1)
self.zoom_original.show()
self.separator = Gtk.SeparatorToolItem()
self.separator.set_draw(True)
self.insert(self.separator, -1)
self.separator.show()
self.fullscreen = ToolButton('view-fullscreen')
self.fullscreen.set_tooltip(_('Fullscreen'))
self.fullscreen.connect('clicked', self.__fullscreen_clicked_cb)
self.insert(self.fullscreen, -1)
self.fullscreen.show()
self.traybutton = ToggleToolButton('tray-show')
self.traybutton.set_icon_name('tray-favourite')
self.traybutton.connect('toggled', self.__tray_toggled_cb)
self.traybutton.props.sensitive = False
self.traybutton.props.active = False
self.insert(self.traybutton, -1)
self.traybutton.show()
tabbed_view = self._activity.get_canvas()
if tabbed_view.get_n_pages():
self._connect_to_browser(tabbed_view.props.current_browser)
tabbed_view.connect_after('switch-page', self.__switch_page_cb)
def __switch_page_cb(self, tabbed_view, page, page_num):
self._connect_to_browser(tabbed_view.props.current_browser)
def _connect_to_browser(self, browser):
self._browser = browser
self._update_zoom_buttons()
def _update_zoom_buttons(self):
is_webkit_browser = isinstance(self._browser, Browser)
self.zoomin.set_sensitive(is_webkit_browser)
self.zoomout.set_sensitive(is_webkit_browser)
self.zoom_original.set_sensitive(is_webkit_browser)
def __zoom_original_clicked_cb(self, button):
tabbed_view = self._activity.get_canvas()
tabbed_view.props.current_browser.set_zoom_level(ZOOM_ORIGINAL)
def __zoomin_clicked_cb(self, button):
tabbed_view = self._activity.get_canvas()
tabbed_view.props.current_browser.zoom_in()
def __zoomout_clicked_cb(self, button):
tabbed_view = self._activity.get_canvas()
tabbed_view.props.current_browser.zoom_out()
def __fullscreen_clicked_cb(self, button):
self._activity.fullscreen()
def __tray_toggled_cb(self, button):
if button.props.active:
self._activity.tray.show()
else:
self._activity.tray.hide()
self.update_traybutton_tooltip()
def update_traybutton_tooltip(self):
if not self.traybutton.props.active:
self.traybutton.set_tooltip(_('Show Tray'))
else:
self.traybutton.set_tooltip(_('Hide Tray'))
示例6: SpeechToolbar
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import set_icon_name [as 别名]
#.........这里部分代码省略.........
combo.append_item(language, name)
if language == self._voice:
combo.set_active(which)
which += 1
combo.connect('changed', self._voice_changed_cb)
combotool = ToolComboBox(combo)
self.insert(combotool, -1)
combotool.show()
self.pitchadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0)
pitchbar = Gtk.HScale()
pitchbar.set_adjustment(self.pitchadj)
pitchbar.set_draw_value(False)
# pitchbar.set_update_policy(Gtk.UpdatePolicy.ALWAYS)
pitchbar.set_size_request(150,15)
pitchtool = Gtk.ToolItem()
pitchtool.add(pitchbar)
pitchtool.show()
self.insert(pitchtool, -1)
pitchbar.show()
self.rateadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0)
ratebar = Gtk.HScale()
ratebar.set_adjustment(self.rateadj)
ratebar.set_draw_value(False)
#ratebar.set_update_policy(Gtk.UpdatePolicy.ALWAYS)
ratebar.set_size_request(150,15)
ratetool = Gtk.ToolItem()
ratetool.add(ratebar)
ratetool.show()
self.insert(ratetool, -1)
ratebar.show()
def _compare_voices(self, a, b):
if a[1].lower() == b[1].lower():
return 0
if a[1].lower() < b[1].lower():
return -1
if a[1].lower() > b[1].lower():
return 1
def _voice_changed_cb(self, combo):
self._voice = combo.props.value
self._speech.say_text(self._voices[self._voice])
def pitch_adjusted_cb(self, get):
self._speech.set_pitch(int(get.get_value()))
self._speech.say_text(_("pitch adjusted"))
f = open(os.path.join(self.activity.get_activity_root(), 'instance', 'pitch.txt'), 'w')
try:
f.write(str(self._speech.get_pitch()))
finally:
f.close()
def rate_adjusted_cb(self, get):
self._speech.set_rate(int(get.get_value()))
self._speech.say_text(_("rate adjusted"))
f = open(os.path.join(self.activity.get_activity_root(), 'instance', 'rate.txt'), 'w')
try:
f.write(str(self._speech.get_rate()))
finally:
f.close()
def set_activity(self, activity):
self.activity = activity
if os.path.exists(os.path.join(activity.get_activity_root(), 'instance', 'pitch.txt')):
f = open(os.path.join(activity.get_activity_root(), 'instance', 'pitch.txt'), 'r')
line = f.readline()
pitch = int(line.strip())
self.pitchadj.set_value(pitch)
self._speech.set_pitch(pitch)
f.close()
if os.path.exists(os.path.join(activity.get_activity_root(), 'instance', 'rate.txt')):
f = open(os.path.join(activity.get_activity_root(), 'instance', 'rate.txt'), 'r')
line = f.readline()
rate = int(line.strip())
self.rateadj.set_value(rate)
self._speech.set_rate(rate)
f.close()
self.pitchadj.connect("value_changed", self.pitch_adjusted_cb)
self.rateadj.connect("value_changed", self.rate_adjusted_cb)
def _play_toggled_cb(self, widget, images):
widget.set_icon_widget(images[int(widget.get_active())])
if widget.get_active():
self.play_button.set_icon_name('media-playback-pause')
self._speech.say_text(
self.activity.add_word_marks(),
lang_code=self._voice)
else:
self.play_button.set_icon_name('media-playback-start')
self._speech.pause()
def is_playing(self):
self._speech.get_is_playing()
def stop(self):
self._speech.stop()