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


Python ToolButton.set_sensitive方法代码示例

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


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

示例1: QrReader

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class QrReader(activity.Activity):
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        self.realize()
        self.qr_window = Gtk.DrawingArea()
        self.qr_window.set_double_buffered(False)
        self.qr_window.set_app_paintable(True)

        self.image = Gtk.Image()

        self.box = Gtk.VBox()
        self.box.pack_start(self.qr_window, True, True, 0)
        self.box.pack_end(self.image, True, True, 0)

        self.set_canvas(self.box)

        self.build_toolbar()
        self.show_all()
        self.image.hide()
        GObject.idle_add(self.setup_init)

    def build_toolbar(self):
        toolbox = ToolbarBox()
        toolbar = toolbox.toolbar

        activity_button = ActivityButton(self)
        toolbar.insert(activity_button, -1)
        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        self.stop_play = ToogleButton('media-playback-start')
        self.stop_play.set_tooltip(_("Turn on/off the camera"))
        self.stop_play.props.active = True

        self.copylink = ToolButton('text-uri-list')
        self.copylink.set_tooltip(_("Copy link to clipboard"))
        self.copylink.set_sensitive(False)

        toolbar.insert(self.stop_play, -1)
        toolbar.insert(self.copylink, -1)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbar.insert(stopbtn, -1)
        toolbar.show_all()

        self.set_toolbar_box(toolbox)

    def setup_init(self):
        xid = self.qr_window.get_property('window').get_xid()
        visor = QrVisor(xid, self.stop_play, self, self.qr_window,
                self.copylink, self.image)
        visor.play()
开发者ID:i5o,项目名称:qr-reader,代码行数:59,代码来源:activity.py

示例2: EditToolbar

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class EditToolbar(SugarEditToolbar):
    def __init__(self, _parent):
        SugarEditToolbar.__init__(self)

        self._parent = _parent

        self.undo.connect('clicked', self.__undo_cb)
        self.redo.connect('clicked', self.__redo_cb)
        self.copy.connect('clicked', self.__copy_cb)
        self.paste.connect('clicked', self.__paste_cb)

        menu_item = MenuItem(_('Cut'))
        menu_item.connect('activate', self.__cut_cb)
        menu_item.show()
        self.copy.get_palette().menu.append(menu_item)

        self.insert(Gtk.SeparatorToolItem(), -1)

        self.erase_button = ToolButton('edit-delete')
        self.erase_button.set_tooltip(_('Erase selected thought(s)'))
        self.erase_button.connect('clicked', self.__delete_cb)
        self.insert(self.erase_button, -1)

        self.show_all()
        self.clipboard = Gtk.Clipboard()

        self.copy.set_sensitive(False)
        self.paste.set_sensitive(False)
        self.erase_button.set_sensitive(False)

    def __undo_cb(self, button):
        self._parent._undo.undo_action(None)

    def __redo_cb(self, button):
        self._parent._undo.redo_action(None)

    def __cut_cb(self, event):
        self._parent._main_area.cut_clipboard(self.clipboard)

    def __copy_cb(self, event):
        self._parent._main_area.copy_clipboard(self.clipboard)

    def __paste_cb(self, event):
        self._parent._main_area.paste_clipboard(self.clipboard)

    def __delete_cb(self, widget):
        self._stop_moving()
        self.stop_dragging()
        self._parent._main_area.delete_selected_elements()

    def stop_dragging(self):
        if self._parent._main_area.is_dragging():
            self._parent._main_area.drag_menu_cb(self._sw, False)

    def _stop_moving(self):
        self._parent._main_area.move_mode = False
开发者ID:sugarlabs,项目名称:laybrinth-activity,代码行数:58,代码来源:labyrinthactivity.py

示例3: __init__

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
    def __init__(self, handle):
        super(PeterActivity, self).__init__(handle)

        # Get user's Sugar colors
        sugarcolors = profile.get_color().to_string().split(',')
        colors = [[int(sugarcolors[0][1:3], 16),
                   int(sugarcolors[0][3:5], 16),
                   int(sugarcolors[0][5:7], 16)],
                  [int(sugarcolors[1][1:3], 16),
                   int(sugarcolors[1][3:5], 16),
                   int(sugarcolors[1][5:7], 16)]]

        # No sharing
        self.max_participants = 1

        # Build the activity toolbar.
        toolbox = ToolbarBox()

        activity_button = ActivityToolbarButton(self)
        toolbox.toolbar.insert(activity_button, 0)
        activity_button.show()

        self._add_speed_slider(toolbox.toolbar)

        cyan = ToolButton('cyan')
        toolbox.toolbar.insert(cyan, -1)
        cyan.set_tooltip(_('Next pattern'))
        cyan.connect('clicked', self._button_cb, 'cyan')
        cyan.set_sensitive(False)
        cyan.show()

        green = ToolButton('green')
        toolbox.toolbar.insert(green, -1)
        green.set_tooltip(_('Draw'))
        green.connect('clicked', self._button_cb, 'green')
        green.show()

        red = ToolButton('red')
        toolbox.toolbar.insert(red, -1)
        red.set_tooltip(_('Stop'))
        red.connect('clicked', self._button_cb, 'red')
        red.show()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = True
        toolbox.toolbar.insert(separator, -1)
        separator.show()

        label = Gtk.Label('')
        label.set_use_markup(True)
        label.show()
        labelitem = Gtk.ToolItem()
        labelitem.add(label)
        toolbox.toolbar.insert(labelitem, -1)
        labelitem.show()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbox.toolbar.insert(separator, -1)
        separator.show()

        stop_button = StopButton(self)
        stop_button.props.accelerator = _('<Ctrl>Q')
        toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()

        toolbox.show()
        self.set_toolbar_box(toolbox)

        # Create the game instance.
        self.game = Spirolaterals.Spirolaterals(colors)

        # Build the Pygame canvas.
        self._pygamecanvas = \
            sugargame.canvas.PygameCanvas(self)
        # Note that set_canvas implicitly calls
        # read_file when resuming from the Journal.
        self.set_canvas(self._pygamecanvas)
        self.game.canvas = self._pygamecanvas

        Gdk.Screen.get_default().connect('size-changed',
                                         self.__configure_cb)

        # Start the game running.
        self.game.set_cyan_button(cyan)
        self.game.set_label(label)
        self._speed_range.set_value(200)
        self._pygamecanvas.run_pygame(self.game.run)
开发者ID:i5o,项目名称:spirolaterals,代码行数:91,代码来源:activity.py

示例4: ImageViewerActivity

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]

#.........这里部分代码省略.........
            self.previous_image_button.connect('clicked',
                                               self.__previous_image_cb)
            toolbar_box.toolbar.insert(self.previous_image_button, -1)
            self.previous_image_button.show()

            self.next_image_button = ToolButton('go-next-paired')
            self.next_image_button.set_tooltip(_('Next Image'))
            self.next_image_button.props.sensitive = False
            self.next_image_button.connect('clicked', self.__next_image_cb)
            toolbar_box.toolbar.insert(self.next_image_button, -1)
            self.next_image_button.show()

            GObject.idle_add(self._get_image_list)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbar_box.toolbar.insert(separator, -1)
        separator.show()

        stop_button = StopButton(self)
        toolbar_box.toolbar.insert(stop_button, -1)
        stop_button.show()

    def _configure_cb(self, event=None):
        if Gdk.Screen.width() <= style.GRID_CELL_SIZE * 12:
            for sep in self._seps:
                sep.hide()
        else:
            for sep in self._seps:
                sep.show()

    def _update_zoom_buttons(self):
        self._zoom_in_button.set_sensitive(self.view.can_zoom_in())
        self._zoom_out_button.set_sensitive(self.view.can_zoom_out())

    def _change_image(self, delta):
        # boundary conditions
        if self.current_image_index == 0 and delta == -1:
            return
        if self.current_image_index == self.image_count - 1 and delta == 1:
            return

        self.current_image_index += delta
        self.make_button_sensitive()
        jobject = self.image_list[self.current_image_index]
        self._object_id = jobject.object_id
        if os.path.exists(self._tempfile):
            os.remove(self._tempfile)
        self.read_file(jobject.file_path)

    def __previous_image_cb(self, button):
        if self.current_image_index > 0:
            self._change_image(-1)

    def __next_image_cb(self, button):
        if self.current_image_index < self.image_count:
            self._change_image(1)

    def __zoom_in_cb(self, button):
        self.view.zoom_in()
        self._update_zoom_buttons()

    def __zoom_out_cb(self, button):
        self.view.zoom_out()
        self._update_zoom_buttons()
开发者ID:leonardcj,项目名称:imageviewer-activity,代码行数:70,代码来源:ImageViewerActivity.py

示例5: TextAttributesToolbar

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]

#.........这里部分代码省略.........
        context = self.get_pango_context()
        tmp_list = []
        for family in context.list_families():
            name = family.get_name()
            if name in self._font_white_list:
                tmp_list.append(name)
        for font in sorted(tmp_list):
            menu_item = MyMenuItem(image=FontImage(font.replace(' ', '-')),
                                   text_label=font)
            menu_item.connect('activate', self.__font_selected_cb, font)
            self._font_palette.menu.append(menu_item)
            menu_item.show()

        return False

    def _setup_font_palette(self):
        self._init_font_list()
        context = self._main_area.pango_context
        for family in context.list_families():
            name = Pango.FontDescription(family.get_name()).to_string()
            if name not in self._font_list and \
                    name in self._font_white_list:
                self._font_list.append(name)

        self._font_palette = self.font_button.get_palette()
        for font in sorted(self._font_list):
            menu_item = MyMenuItem(image=FontImage(font.replace(' ', '-')),
                                   text_label=font)
            menu_item.connect('activate', self.__font_selected_cb, font)
            self._font_palette.menu.append(menu_item)
            menu_item.show()

    def __font_selected_cb(self, widget, font_name):
        if not hasattr(self._main_area, 'font_name'):
            return
        if len(self._main_area.selected) > 0:
            font_size = self._main_area.font_size
        else:
            font_size = utils.default_font_size
        self._main_area.set_font(font_name, font_size)
        self._main_area.font_name = font_name
        self._main_area.font_size = font_size

    def __attribute_values(self):
        thought = self._main_area.selected[0]
        return thought.attributes.copy()

    def __font_sizes_cb(self, button, increase):
        if not hasattr(self._main_area, 'font_size'):
            return
        if len(self._main_area.selected) < 1:
            return
        font_size = self._main_area.font_size
        if font_size in self._font_sizes:
            i = self._font_sizes.index(font_size)
            if increase:
                if i < len(self._font_sizes) - 2:
                    i += 1
            else:
                if i > 0:
                    i -= 1
        else:
            i = self._font_sizes.index(utils.default_font_size)

        font_size = self._font_sizes[i]
        self.size_label.set_text(str(font_size))
        self.font_size_down.set_sensitive(i != 0)
        self.font_size_up.set_sensitive(i < len(self._font_sizes) - 2)
        self._main_area.set_font(self._main_area.font_name, font_size)

    def __bold_cb(self, button):
        if len(self._main_area.selected) < 1:
            return
        value = not self.__attribute_values()["bold"]
        self._main_area.set_bold(value)

    def __italics_cb(self, button):
        if len(self._main_area.selected) < 1:
            return

        value = not self.__attribute_values()["italic"]
        self._main_area.set_italics(value)

    def __underline_cb(self, button):
        if len(self._main_area.selected) < 1:
            return
        value = not self.__attribute_values()["underline"]
        self._main_area.set_underline(value)

    def __foreground_color_cb(self, button):
        color = button.get_color()
        self._main_area.set_foreground_color(color)

    def __background_color_cb(self, button):
        color = button.get_color()
        self._parent._main_area.set_background_color(color)

    def change_active_font(self):
        # TODO: update the toolbar
        return
开发者ID:sugarlabs,项目名称:laybrinth-activity,代码行数:104,代码来源:labyrinthactivity.py

示例6: build_toolbar

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
    def build_toolbar(self):
        self.max_participants = 4

        toolbar_box = ToolbarBox()
        activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(activity_button, 0)
        activity_button.show()

        create_toolbar = ToolbarButton()
        create_toolbar.props.page = Gtk.Toolbar()
        create_toolbar.props.icon_name = 'magicpen'
        create_toolbar.props.label = _('Create')
        toolbar_box.toolbar.insert(create_toolbar, -1)
        self._insert_create_tools(create_toolbar)

        self._insert_stop_play_button(toolbar_box.toolbar)

        clear_trace = ToolButton('clear-trace')
        clear_trace.set_tooltip(_('Clear Trace Marks'))
        clear_trace.set_accelerator(_('<ctrl>x'))
        clear_trace.connect('clicked', self.clear_trace_cb)
        clear_trace.set_sensitive(False)
        toolbar_box.toolbar.insert(clear_trace, -1)
        clear_trace.show()
        self.clear_trace = clear_trace

        self._insert_clear_all_button(toolbar_box.toolbar)

        load_example = ToolButton('load-sample')
        load_example.set_tooltip(_('Show sample projects'))
        load_example.connect('clicked', self._create_store)

        toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)
        toolbar_box.toolbar.insert(load_example, -1)
        load_example.show()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_size_request(0, -1)
        separator.set_expand(True)
        toolbar_box.toolbar.insert(separator, -1)
        separator.show()

        stop = StopButton(self)
        toolbar_box.toolbar.insert(stop, -1)
        stop.show()

        separator = Gtk.SeparatorToolItem()
        activity_button.props.page.insert(separator, -1)
        separator.show()

        export_json = ToolButton('save-as-json')
        export_json.set_tooltip(_('Export tracked objects to journal'))
        export_json.connect('clicked', self._export_json_cb)
        activity_button.props.page.insert(export_json, -1)
        export_json.show()

        export_csv = ToolButton('save-as-csv')
        export_csv.set_tooltip(_('Export tracked objects to journal'))
        export_csv.connect('clicked', self._export_csv_cb)
        activity_button.props.page.insert(export_csv, -1)
        export_csv.show()

        load_project = ToolButton('load-project')
        load_project.set_tooltip(_('Load project from journal'))
        load_project.connect('clicked', self._load_project)
        activity_button.props.page.insert(load_project, -1)
        load_project.show()

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show_all()
        create_toolbar.set_expanded(True)
        return toolbar_box
开发者ID:godiard,项目名称:physics,代码行数:75,代码来源:activity.py

示例7: CreateToolbarBuilder

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [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()

#.........这里部分代码省略.........
开发者ID:godiard,项目名称:memorize-activity,代码行数:103,代码来源:createtoolbar.py

示例8: Finance

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]

#.........这里部分代码省略.........

        # Update Balance.
        if total >= 0.0:
            balancecolor = colors.CREDIT_COLOR
        else:
            balancecolor = colors.DEBIT_COLOR
        balance = \
            "<span size='xx-large' foreground='white'><b>%s %s</b></span>" % \
            (_('Balance: '), locale.currency(total))
        self.balancelabel.set_markup(balance)

        self.balance_evbox.modify_bg(
            Gtk.StateType.NORMAL, style.Color(balancecolor).get_gdk_color())

        self.startlabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            _('Starting Balance:'))
        self.startamountlabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            locale.currency(start))

        self.creditslabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            (_('%s in %d credits') % (locale.currency(credit_total),
                                      credit_count)))
        self.debitslabel.set_markup(
            "<span foreground='white'><b>%s</b></span>" %
            (_('%s in %d debits') % (locale.currency(debit_total),
                                     debit_count)))

    def update_toolbar(self):
        # Disable the navigation when Forever is selected.
        next_prev = self.period != FOREVER
        self.prevperiodbtn.set_sensitive(next_prev)
        self.thisperiodbtn.set_sensitive(next_prev)
        self.nextperiodbtn.set_sensitive(next_prev)

        # This is a HACK to translate the string properly
        # http://bugs.sugarlabs.org/ticket/3190
        if self.period == MONTH:
            text_previous_period = _('Previous Month')
            text_this_period = _('This Month')
            text_next_period = _('Next Month')
        elif self.period == WEEK:
            text_previous_period = _('Previous Week')
            text_this_period = _('This Week')
            text_next_period = _('Next Week')
        elif self.period == DAY:
            text_previous_period = _('Previous Day')
            text_this_period = _('This Day')
            text_next_period = _('Next Day')
        elif self.period == YEAR:
            text_previous_period = _('Previous Year')
            text_this_period = _('This Year')
            text_next_period = _('Next Year')

        # Update the label self.period to reflect the period.
        self.prevperiodbtn.set_tooltip(text_previous_period)
        self.thisperiodbtn.set_tooltip(text_this_period)
        self.nextperiodbtn.set_tooltip(text_next_period)

    def get_this_period(self):
        today = datetime.date.today()

        if self.period == DAY:
            return today
开发者ID:quozl,项目名称:finance-activity,代码行数:70,代码来源:finance.py

示例9: SpeechToolbar

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class SpeechToolbar(Gtk.Toolbar):
    def __init__(self, activity):
        GObject.GObject.__init__(self)
        self._activity = activity
        if not speech.supported:
            return
        self.is_paused = False
        self._cnf_client = GConf.Client.get_default()
        self.load_speech_parameters()

        self.sorted_voices = [i for i in speech.voices()]
        self.sorted_voices.sort(self.compare_voices)
        default = 0
        for voice in self.sorted_voices:
            if voice[0] == speech.voice[0]:
                break
            default = default + 1

        # Play button
        self.play_btn = ToggleToolButton("media-playback-start")
        self.play_btn.show()
        self.play_toggled_handler = 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_cb = self.reset_buttons_cb
        speech.end_text_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()
        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):
#.........这里部分代码省略.........
开发者ID:i5o,项目名称:write-activity,代码行数:103,代码来源:speechtoolbar.py

示例10: ClipArtActivity

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class ClipArtActivity(activity.Activity):

    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self._selected_image = None

        self.max_participants = 1

        toolbarbox = ToolbarBox()
        self.set_toolbar_box(toolbarbox)

        activity_button = ActivityToolbarButton(self)
        toolbarbox.toolbar.insert(activity_button, 0)
        activity_button.show()

        self.save_button = ToolButton('image-save')
        self.save_button.set_tooltip(_('Save to Journal'))
        self.save_button.connect('clicked', self._save_to_journal)
        self.save_button.set_sensitive(False)
        self.save_button.show()
        toolbarbox.toolbar.insert(self.save_button, -1)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbarbox.toolbar.insert(separator, -1)

        stop_button = StopButton(self)
        toolbarbox.toolbar.insert(stop_button, -1)
        stop_button.show()

        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        self.set_canvas(scrolled_window)
        scrolled_window.show()

        store = Gtk.ListStore(GdkPixbuf.Pixbuf, str)

        icon_view = Gtk.IconView.new_with_model(store)
        icon_view.set_selection_mode(Gtk.SelectionMode.SINGLE)
        icon_view.connect('selection-changed', self._clipart_selected, store)
        icon_view.set_pixbuf_column(0)
        rgba = Gdk.RGBA()
        rgba.red, rgba.green, rgba.blue, rgba.alpha = 0.67, 0.67, 0.67, 1.0
        icon_view.override_background_color(Gtk.StateFlags.NORMAL, rgba)
        icon_view.grab_focus()
        scrolled_window.add(icon_view)
        icon_view.show()

        toolbarbox.show_all()
        self.show_all()

        self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
        self._notify()

        GObject.idle_add(_fill_clipart_list, store)

    def _save_to_journal(self, widget):
        if self._selected_image is None:
            return

        basename = os.path.basename(self._selected_image)
        dsobject = datastore.create()
        dsobject.metadata['title'] = basename[:-4]
        dsobject.metadata['icon-color'] = profile.get_color().to_string()
        dsobject.metadata['mime_type'] = MIME_TYPES[basename.split('.')[-1]]
        dsobject.set_file_path(self._selected_image)
        datastore.write(dsobject)
        dsobject.destroy()

        self.save_button.set_sensitive(False)

    def _get_selected_path(self, widget, store):
        try:
            iter_ = store.get_iter(widget.get_selected_items()[0])
            image_path = store.get(iter_, 1)[0]

            return image_path, iter_
        except:
            return None

    def _clipart_selected(self, widget, store):
        selected = self._get_selected_path(widget, store)

        if selected is None:
            self._selected_image = None
            self.save_button.set_sensitive(False)
            return

        image_path, _iter = selected
        iter_ = store.get_iter(widget.get_selected_items()[0])
        image_path = store.get(iter_, 1)[0]

        self._selected_image = image_path
        self.save_button.set_sensitive(True)

    def _notify(self):
        alert = ErrorAlert()
#.........这里部分代码省略.........
开发者ID:leonardcj,项目名称:clipart,代码行数:103,代码来源:activity.py

示例11: ReflectActivity

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]

#.........这里部分代码省略.........
        view_toolbar = Gtk.Toolbar()
        self.view_toolbar_button = ToolbarButton(
            page=view_toolbar,
            label=_('View'),
            icon_name='toolbar-view')
        self.view_toolbar_button.connect('clicked', self._resize_canvas)
        self._toolbox.toolbar.insert(self.view_toolbar_button, 1)
        view_toolbar.show()
        self.view_toolbar_button.show()

        button = ToolButton('view-fullscreen')
        button.set_tooltip(_('Fullscreen'))
        button.props.accelerator = '<Alt>Return'
        view_toolbar.insert(button, -1)
        button.show()
        button.connect('clicked', self._fullscreen_cb)

        edit_toolbar = Gtk.Toolbar()
        self.edit_toolbar_button = ToolbarButton(
            page=edit_toolbar,
            label=_('Edit'),
            icon_name='toolbar-edit')
        self.edit_toolbar_button.connect('clicked', self._resize_canvas)
        self._toolbox.toolbar.insert(self.edit_toolbar_button, 1)
        edit_toolbar.show()
        self.edit_toolbar_button.show()

        self._copy_button = ToolButton('edit-copy')
        self._copy_button.set_tooltip(_('Copy'))
        self._copy_button.props.accelerator = '<Ctrl>C'
        edit_toolbar.insert(self._copy_button, -1)
        self._copy_button.show()
        self._copy_button.connect('clicked', self._copy_cb)
        self._copy_button.set_sensitive(False)

        self._paste_button = ToolButton('edit-paste')
        self._paste_button.set_tooltip(_('Paste'))
        self._paste_button.props.accelerator = '<Ctrl>V'
        edit_toolbar.insert(self._paste_button, -1)
        self._paste_button.show()
        self._paste_button.connect('clicked', self._paste_cb)
        self._paste_button.set_sensitive(False)

        button = ToolButton('list-add')
        button.set_tooltip(_('Add Item'))
        button.props.accelerator = '<Ctrl>+'
        self._toolbox.toolbar.insert(button, -1)
        button.show()
        button.connect('clicked', self.__add_item_cb)

        self._date_button = RadioToolButton('date-sort', group=None)
        self._date_button.set_tooltip(_('Sort by Date'))
        self._date_button.connect('clicked', self._date_button_cb)
        self._toolbox.toolbar.insert(self._date_button, -1)
        self._date_button.show()

        self._title_button = RadioToolButton('title-sort',
                                             group=self._date_button)
        self._title_button.set_tooltip(_('Sort by Title'))
        self._title_button.connect('clicked', self._title_button_cb)
        self._toolbox.toolbar.insert(self._title_button, -1)
        self._title_button.show()

        self._stars_button = RadioToolButton('stars-sort',
                                             group=self._date_button)
        self._stars_button.set_tooltip(_('Sort by Favourite'))
开发者ID:AbrahmAB,项目名称:reflect,代码行数:70,代码来源:activity.py

示例12: OneSupportActivity

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]

#.........这里部分代码省略.........
        self._zoom_in.show()
        self._zoom_in.connect('clicked', self._zoom_in_cb)

        self._zoom_out = ToolButton('zoom-out')
        self._zoom_out.set_tooltip(_('Decrease size'))
        view_toolbar.insert(self._zoom_out, -1)
        self._zoom_out.show()
        self._zoom_out.connect('clicked', self._zoom_out_cb)

        self._zoom_eq = ToolButton('zoom-original')
        self._zoom_eq.set_tooltip(_('Restore original size'))
        view_toolbar.insert(self._zoom_eq, -1)
        self._zoom_eq.show()
        self._zoom_eq.connect('clicked', self._zoom_eq_cb)

        self._set_zoom_buttons_sensitivity()

        edit_toolbar = Gtk.Toolbar()
        self.edit_toolbar_button = ToolbarButton(
            page=edit_toolbar,
            label=_('Edit'),
            icon_name='toolbar-edit')
        self.edit_toolbar_button.connect('clicked', self._resize_canvas)
        self._toolbox.toolbar.insert(self.edit_toolbar_button, 1)
        edit_toolbar.show()
        self.edit_toolbar_button.show()

        self._copy_button = ToolButton('edit-copy')
        self._copy_button.set_tooltip(_('Copy'))
        self._copy_button.props.accelerator = '<Ctrl>C'
        edit_toolbar.insert(self._copy_button, -1)
        self._copy_button.show()
        self._copy_button.connect('clicked', self._copy_cb)
        self._copy_button.set_sensitive(False)

        self._paste_button = ToolButton('edit-paste')
        self._paste_button.set_tooltip(_('Paste'))
        self._paste_button.props.accelerator = '<Ctrl>V'
        edit_toolbar.insert(self._paste_button, -1)
        self._paste_button.show()
        self._paste_button.connect('clicked', self._paste_cb)
        self._paste_button.set_sensitive(False)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        self._toolbox.toolbar.insert(separator, -1)
        separator.show()

        stop_button = StopButton(self)
        stop_button.props.accelerator = '<Ctrl>q'
        self._toolbox.toolbar.insert(stop_button, -1)
        stop_button.show()

    def __realize_cb(self, window):
        self.window_xid = window.get_window().get_xid()

    def set_copy_widget(self, webkit=None, text_entry=None):
        # Each task is responsible for setting a widget for copy
        if webkit is not None:
            self._webkit = webkit
        else:
            self._webkit = None
        if text_entry is not None:
            self._copy_entry = text_entry
        else:
开发者ID:cottonpaul,项目名称:OneSupport,代码行数:70,代码来源:activity.py

示例13: SpeechToolbar

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class SpeechToolbar(Gtk.Toolbar):

    def __init__(self, activity):
        Gtk.Toolbar.__init__(self)
        self._activity = activity
        if not speech.supported:
            return
        self.is_paused = False

        self._cnf_client = GConf.Client.get_default()
        self.load_speech_parameters()

        self.sorted_voices = [i for i in speech.voices()]
        self.sorted_voices.sort(self.compare_voices)
        default = 0
        for voice in self.sorted_voices:
            if voice[0] == speech.voice[0]:
                break
            default = default + 1

        # Play button
        self.play_btn = ToggleToolButton('media-playback-start')
        self.play_btn.show()
        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):
#.........这里部分代码省略.........
开发者ID:icarito,项目名称:read-activity,代码行数:103,代码来源:speechtoolbar.py

示例14: MemorizeToolbarBuilder

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class MemorizeToolbarBuilder(GObject.GObject):

    __gtype_name__ = 'MemoryToolbarBuilder'

    standard_game_names = ['addition',
                           'letters',
                           'sounds'
                           ]
    translated_game_names = [_('Addition'),
                             _('Letters'),
                             _('Sounds')
                             ]

    __gsignals__ = {
        'game_changed': (GObject.SignalFlags.RUN_FIRST, None,
                         5 * [GObject.TYPE_PYOBJECT])}

    def __init__(self, activity):
        GObject.GObject.__init__(self)
        self.activity = activity
        self.toolbar = self.activity.get_toolbar_box().toolbar
        self.jobject = None

        # Change demo games button
        self._demo_games = RadioMenuButton(icon_name='memorize-collection')
        self._demo_games.props.tooltip = _('Load demo games')

        for i, game in enumerate(self.translated_game_names):
            menu_item = MenuItem(game, icon_name=self.standard_game_names[i])
            menu_item.connect('activate', self.__activate_game_cb, i)
            self._demo_games.props.palette.menu.append(menu_item)
            menu_item.show()

        self.toolbar.insert(self._demo_games, -1)

        if USE_ART4APPS:
            for language in art4apps_data.get_languages():
                language_description = art4apps_data.get_language_name(
                    language)
                lang_menu_item = MenuItem(language_description,
                                          'activity-start')
                self._demo_games.props.palette.menu.append(lang_menu_item)
                lang_menu_item.show()
                categories_menu = Gtk.Menu()
                # create a submenu with the categories
                categories = {}
                for category in art4apps_data.get_categories():
                    if category in ['letters', 'other']:
                        continue
                    translated_category = art4apps_data.get_translation(
                        category, language)
                    if translated_category is not None:
                        label = translated_category
                    else:
                        label = category
                    categories[label] = category

                for label in sorted(categories):
                    cat_menu_item = MenuItem(label)
                    cat_menu_item.connect('activate',
                                          self.__activate_art4apps_game_cb,
                                          categories[label], language)
                    categories_menu.append(cat_menu_item)
                    cat_menu_item.show()
                lang_menu_item.set_submenu(categories_menu)

        self._selected_game = self.standard_game_names[0]

        # Change size combobox
        self._size_combo = RadioMenuButton(icon_name='change_size')
        self._size_combo.props.tooltip = _('Change size')
        self._sizes = ['4 X 4', '5 X 5', '6 X 6']

        for i, f in enumerate(self._sizes):
            menu_item = MenuItem(f, icon_name=self._sizes[i])
            menu_item.connect('activate', self._game_size_cb, i)
            self._size_combo.props.palette.menu.append(menu_item)
            menu_item.show()
        self.toolbar.insert(self._size_combo, -1)
        self._selected_game_size = self._sizes[0][0]

        # Reset Button
        self._restart_button = ToolButton('game-new')
        self._restart_button.connect('clicked', self._game_reset_cb)
        self._restart_button.set_tooltip(_('Restart Game'))
        self.toolbar.insert(self._restart_button, -1)
        self._restart_button.show()

    def _game_reset_cb(self, widget):
        self.activity.game.model.count = 0
        self.emit('game_changed', None, None, 'reset', None, None)

    def update_controls(self, active):
        self._size_combo.set_sensitive(active)
        self._demo_games.set_sensitive(active)
        self._restart_button.set_sensitive(active)

    def _game_size_cb(self, widget, i):
        self._selected_game_size = int(self._sizes[i][0])
        self._size_combo.props.icon_name = self._sizes[i]
#.........这里部分代码省略.........
开发者ID:godiard,项目名称:memorize-activity,代码行数:103,代码来源:memorizetoolbar.py

示例15: CreateCardPanel

# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_sensitive [as 别名]

#.........这里部分代码省略.........
            main_box_orientation = Gtk.Orientation.HORIZONTAL
        self._main_box = Gtk.Box(orientation=main_box_orientation)
        self._main_box.pack_start(self.card_box, True, True, 0)
        self._main_box.pack_start(self._buttons_bar, True, True, 0)
        self.add(self._main_box)
        self.connect('size-allocate', self._allocate_cb)

        self.show_all()

    def _allocate_cb(self, widget, allocation):
        GLib.idle_add(self.update_orientation)

    def update_orientation(self):
        self._portrait = Gdk.Screen.width() < Gdk.Screen.height()
        if self._portrait:
            self._buttons_bar.props.orientation = Gtk.Orientation.HORIZONTAL
            self._main_box.props.orientation = Gtk.Orientation.VERTICAL
        else:
            self._buttons_bar.props.orientation = Gtk.Orientation.VERTICAL
            self._main_box.props.orientation = Gtk.Orientation.HORIZONTAL

    def update_font_combos(self, widget, data, grid):
        if 'font_name1' in data:
            self.cardeditor1.set_font_name(data['font_name1'])
            self.cardeditor1.card.change_font(data['font_name1'])
        if 'font_name2' in data:
            self.cardeditor2.set_font_name(data['font_name2'])
            self.cardeditor2.card.change_font(data['font_name2'])

    def emit_close(self, widget):
        self.emit('pair-closed')

    def emit_add_pair(self, widget):
        self._addbutton.set_sensitive(False)
        if self.equal_pairs:
            self.emit('add-pair', self.cardeditor1.get_text(),
                      self.cardeditor1.get_text(),
                      self.cardeditor1.get_image_path(),
                      self.cardeditor1.get_image_path(),
                      self.cardeditor1.get_snd(),
                      self.cardeditor1.get_snd(),
                      self.cardeditor1.get_speak(),
                      self.cardeditor1.get_speak(),
                      self.cardeditor1.get_font_name(),
                      self.cardeditor1.get_font_name())
        else:
            self.emit('add-pair', self.cardeditor1.get_text(),
                      self.cardeditor2.get_text(),
                      self.cardeditor1.get_image_path(),
                      self.cardeditor2.get_image_path(),
                      self.cardeditor1.get_snd(),
                      self.cardeditor2.get_snd(),
                      self.cardeditor1.get_speak(),
                      self.cardeditor2.get_speak(),
                      self.cardeditor1.get_font_name(),
                      self.cardeditor2.get_font_name())
        self.clean(None)

    def emit_update_pair(self, widget):
        self._addbutton.set_sensitive(False)
        if self.equal_pairs:
            self.emit('update-pair', self.cardeditor1.get_text(),
                      self.cardeditor1.get_text(),
                      self.cardeditor1.get_image_path(),
                      self.cardeditor1.get_image_path(),
                      self.cardeditor1.get_snd(),
开发者ID:godiard,项目名称:memorize-activity,代码行数:70,代码来源:createcardpanel.py


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