当前位置: 首页>>代码示例>>Python>>正文


Python PaletteMenuItem.set_sensitive方法代码示例

本文整理汇总了Python中sugar3.graphics.palettemenu.PaletteMenuItem.set_sensitive方法的典型用法代码示例。如果您正苦于以下问题:Python PaletteMenuItem.set_sensitive方法的具体用法?Python PaletteMenuItem.set_sensitive怎么用?Python PaletteMenuItem.set_sensitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sugar3.graphics.palettemenu.PaletteMenuItem的用法示例。


在下文中一共展示了PaletteMenuItem.set_sensitive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SpeechPalette

# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_sensitive [as 别名]
class SpeechPalette(Palette):

    def __init__(self, primary_text, manager):
        Palette.__init__(self, label=primary_text)

        self._manager = manager
        self._manager.connect('play', self._set_menu_state, 'play')
        self._manager.connect('stop', self._set_menu_state, 'stop')
        self._manager.connect('pause', self._set_menu_state, 'pause')

        box = PaletteMenuBox()
        self.set_content(box)
        box.show()

        self._play_icon = Icon(icon_name='player_play')
        self._pause_icon = Icon(icon_name='player_pause')
        self._play_pause_menu = PaletteMenuItem(
            icon_name='player_play',
            text_label=_('Say selected text'))
        self._play_pause_menu.set_image(self._play_icon)
        self._play_pause_menu.connect('activate', self.__play_activated_cb)
        box.append_item(self._play_pause_menu)
        self._play_pause_menu.show()

        self._stop_menu = PaletteMenuItem(icon_name='player_stop',
                                          text_label=_('Stop playback'))
        self._stop_menu.connect('activate', self.__stop_activated_cb)
        self._stop_menu.set_sensitive(False)
        box.append_item(self._stop_menu)

        separator = PaletteMenuItemSeparator()
        box.append_item(separator)
        separator.show()

        pitch_label = Gtk.Label(_('Pitch'))
        box.append_item(pitch_label, vertical_padding=0)
        pitch_label.show()

        self._adj_pitch = Gtk.Adjustment(value=self._manager.get_pitch(),
                                         lower=self._manager.MIN_PITCH,
                                         upper=self._manager.MAX_PITCH)

        hscale_pitch = Gtk.HScale()
        hscale_pitch.set_adjustment(self._adj_pitch)
        hscale_pitch.set_draw_value(False)

        box.append_item(hscale_pitch, vertical_padding=0)
        hscale_pitch.show()

        rate_label = Gtk.Label(_('Rate'))
        box.append_item(rate_label, vertical_padding=0)
        rate_label.show()

        self._adj_rate = Gtk.Adjustment(value=self._manager.get_rate(),
                                        lower=self._manager.MIN_RATE,
                                        upper=self._manager.MAX_RATE)

        hscale_rate = Gtk.HScale()
        hscale_rate.set_adjustment(self._adj_rate)
        hscale_rate.set_draw_value(False)

        box.append_item(hscale_rate, vertical_padding=0)
        hscale_rate.show()

        self._adj_pitch.connect('value_changed', self.__adj_pitch_changed_cb)
        self._adj_rate.connect('value_changed', self.__adj_rate_changed_cb)

    def __adj_pitch_changed_cb(self, adjustment):
        self._manager.set_pitch(int(adjustment.get_value()))

    def __adj_rate_changed_cb(self, adjustment):
        self._manager.set_rate(int(adjustment.get_value()))

    def __play_activated_cb(self, widget):
        if self._manager.is_paused:
            self._manager.restart()
        elif not self._manager.is_playing:
            self._manager.say_selected_text()
        else:
            self._manager.pause()

    def __stop_activated_cb(self, widget):
        self._manager.stop()

    def _set_menu_state(self, manager, signal):
        if signal == 'play':
            self._play_pause_menu.set_image(self._pause_icon)
            self._play_pause_menu.set_label(_('Pause playback'))
            self._stop_menu.set_sensitive(True)

        elif signal == 'pause':
            self._play_pause_menu.set_image(self._play_icon)
            self._play_pause_menu.set_label(_('Say selected text'))
            self._stop_menu.set_sensitive(True)

        elif signal == 'stop':
            self._play_pause_menu.set_image(self._play_icon)
            self._play_pause_menu.set_label(_('Say selected text'))
            self._stop_menu.set_sensitive(False)
开发者ID:ChristoferR,项目名称:sugar,代码行数:101,代码来源:speech.py


注:本文中的sugar3.graphics.palettemenu.PaletteMenuItem.set_sensitive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。