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


Python ToolButton.get_palette方法代码示例

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


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

示例1: __init__

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
    def __init__(self, activity, **kwargs):
        gtk.ToolItem.__init__(self)

        description_button = ToolButton('edit-description')
        description_button.show()
        description_button.set_tooltip(_('Description'))
        self._palette = description_button.get_palette()

        description_box = gtk.HBox()
        sw = gtk.ScrolledWindow()
        sw.set_size_request(int(gtk.gdk.screen_width() / 2),
                            2 * style.GRID_CELL_SIZE)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._text_view = gtk.TextView()
        self._text_view.set_left_margin(style.DEFAULT_PADDING)
        self._text_view.set_right_margin(style.DEFAULT_PADDING)
        self._text_view.set_wrap_mode(gtk.WRAP_WORD_CHAR)
        text_buffer = gtk.TextBuffer()
        if 'description' in activity.metadata:
            text_buffer.set_text(activity.metadata['description'])
        self._text_view.set_buffer(text_buffer)
        self._text_view.connect('focus-out-event',
                                self.__description_changed_cb, activity)
        sw.add(self._text_view)
        description_box.pack_start(sw, False, True, 0)
        self._palette.set_content(description_box)
        description_box.show_all()

        self.add(description_button)
        description_button.connect('clicked',
                                   self.__description_button_clicked_cb)

        activity.metadata.connect('updated', self.__jobject_updated_cb)
开发者ID:Daksh,项目名称:sugar-toolkit,代码行数:35,代码来源:widgets.py

示例2: __init__

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
    def __init__(self, **kwargs):
        gtk.ToolItem.__init__(self)

        help_button = ToolButton('help-icon')
        help_button.set_tooltip(_('Help'))
        self.add(help_button)

        self._palette = help_button.get_palette()

        sw = gtk.ScrolledWindow()
        sw.set_size_request(int(gtk.gdk.screen_width() / 2.8),
            gtk.gdk.screen_height() - style.GRID_CELL_SIZE * 3)
        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)

        self._max_text_width = int(gtk.gdk.screen_width() / 3) - 20
        self._vbox = gtk.VBox()
        self._vbox.set_homogeneous(False)

        hbox = gtk.HBox()
        hbox.pack_start(self._vbox, False, True, 0)

        sw.add_with_viewport(hbox)

        self._palette.set_content(sw)
        sw.show_all()

        help_button.connect('clicked', self.__help_button_clicked_cb)
开发者ID:leonardcj,项目名称:AnalyzeJournal,代码行数:29,代码来源:helpbutton.py

示例3: __init__

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
    def __init__(self, activity):
        self._activity = activity

        gtk.ToolItem.__init__(self)

        help_button = ToolButton('toolbar-help')
        help_button.set_tooltip(_('Ayuda'))
        self.add(help_button)
        help_button.show()

        self._palette = help_button.get_palette()

        help_button.connect('clicked', self.__help_button_clicked_cb)
开发者ID:Daksh,项目名称:neko-activity,代码行数:15,代码来源:helpbutton.py

示例4: __init__

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
    def __init__(self, activity):
        self._activity = activity
        self._current_palette = 'turtle'

        gtk.ToolItem.__init__(self)

        help_button = ToolButton('help-toolbar')
        help_button.set_tooltip(_('Help'))
        self.add(help_button)
        help_button.show()

        self._palette = help_button.get_palette()

        help_button.connect('clicked', self.__help_button_clicked_cb)
开发者ID:sugarlabs,项目名称:activity-turtle-flags,代码行数:16,代码来源:helpbutton.py

示例5: __init__

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
class RecordControl:
    def __init__(self, toolbar):

        self._timer_value = TIMER_VALUES[0]
        self._timer_button = ToolButton("timer-0")
        self._timer_button.set_tooltip(_("Select timer"))
        self._timer_button.connect("clicked", self._timer_selection_cb)
        toolbar.insert(self._timer_button, -1)
        self._setup_timer_palette()

        self._duration_value = DURATION_VALUES[0]
        self._duration_button = ToolButton("duration-2")
        self._duration_button.set_tooltip(_("Select duration"))
        self._duration_button.connect("clicked", self._duration_selection_cb)
        toolbar.insert(self._duration_button, -1)
        self._setup_duration_palette()

        self._quality_value = 0
        self._quality_button = ToolButton("low-quality")
        self._quality_button.set_tooltip(_("Select quality"))
        self._quality_button.connect("clicked", self._quality_selection_cb)
        toolbar.insert(self._quality_button, -1)
        self._setup_quality_palette()

    def _timer_selection_cb(self, widget):
        if self._timer_palette:

            if not self._timer_palette.is_up():
                self._timer_palette.popup(immediate=True, state=self._timer_palette.SECONDARY)
            else:
                self._timer_palette.popdown(immediate=True)
            return

    def _setup_timer_palette(self):
        self._timer_palette = self._timer_button.get_palette()

        for seconds in TIMER_VALUES:
            if seconds == 0:
                text = _("Immediate")
            else:
                text = ngettext("%s second", "%s seconds", seconds) % seconds
            menu_item = MenuItem(icon_name="timer-%d" % (seconds), text_label=text)
            menu_item.connect("activate", self._timer_selected_cb, seconds)
            self._timer_palette.menu.append(menu_item)
            menu_item.show()

    def _timer_selected_cb(self, button, seconds):
        self.set_timer_idx(TIMER_VALUES.index(seconds))

    def _duration_selection_cb(self, widget):
        if self._duration_palette:
            if not self._duration_palette.is_up():
                self._duration_palette.popup(immediate=True, state=self._duration_palette.SECONDARY)
            else:
                self._duration_palette.popdown(immediate=True)
            return

    def _setup_duration_palette(self):
        self._duration_palette = self._duration_button.get_palette()
        for minutes in DURATION_VALUES:
            if minutes == 0:
                text = gtk.Label(_("Immediate"))
            else:
                text = ngettext("%s minute", "%s minutes", minutes) % minutes
            menu_item = MenuItem(icon_name="duration-%d" % (minutes), text_label=text)
            menu_item.connect("activate", self._duration_selected_cb, minutes)
            self._duration_palette.menu.append(menu_item)
            menu_item.show()

    def _duration_selected_cb(self, button, minutes):
        self.set_duration_idx(DURATION_VALUES.index(minutes))

    def _quality_selection_cb(self, widget):
        if self._quality_palette:
            if not self._quality_palette.is_up():
                self._quality_palette.popup(immediate=True, state=self._quality_palette.SECONDARY)
            else:
                self._quality_palette.popdown(immediate=True)
            return

    def _setup_quality_palette(self):
        self._quality_palette = self._quality_button.get_palette()
        for quality in QUALITY_VALUES:
            text = _("%s quality") % (quality)
            menu_item = MenuItem(icon_name=quality + "-quality", text_label=text)
            menu_item.connect("activate", self._quality_selected_cb, quality)
            self._quality_palette.menu.append(menu_item)
            menu_item.show()

    def _quality_selected_cb(self, button, quality):
        self.set_quality(QUALITY_VALUES.index(quality))

    def set_mode(self, mode):
        if mode == constants.MODE_PHOTO:
            self._quality_button.set_sensitive(False)
            self._timer_button.set_sensitive(True)
            self._duration_button.set_sensitive(False)
        if mode == constants.MODE_VIDEO:
            self._quality_button.set_sensitive(True)
            self._timer_button.set_sensitive(True)
#.........这里部分代码省略.........
开发者ID:quozl,项目名称:record-activity,代码行数:103,代码来源:record.py

示例6: TuningToolbar

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

#.........这里部分代码省略.........
    def _update_note(self):
        ''' Calculate the frequency based on note and octave '''
        if not hasattr(self, '_freq_entry'):  # Still setting up toolbar
            return
        i = self._octave * 12 + NOTES.index(self._note)
        freq = A0 * pow(TWELTHROOT2, i)
        self._updating_note = True
        self._freq_entry.set_text('%0.3f' % (freq))
        self.label.set_markup(SPAN % (style.COLOR_WHITE.get_html(),
                                      self._note + str(self._octave)))
        if self._show_tuning_line:
            self.activity.wave.tuning_line = freq
        return

    def _update_freq_entry(self, widget):
        # Calculate a note from a frequency
        if not self._updating_note:  # Only if user types in a freq.
            try:
                freq = float(self._freq_entry.get_text())
                # Only consider notes in piano range
                if freq < A0 * 0.97:
                    self.label.set_text('< A0')
                    return
                if freq > C8 * 1.03:
                    self.label.set_text('> C8')
                    return
                self.label.set_markup(freq_note(freq, flatsharp=True))
            except ValueError:
                return

        self._updating_note = False

    def _button_selection_cb(self, widget):
        palette = widget.get_palette()
        if palette:
            if not palette.is_up():
                palette.popup(immediate=True, state=palette.SECONDARY)
            else:
                palette.popdown(immediate=True)
            return

    def _setup_notes_palette(self):
        self._notes_palette = self._notes_button.get_palette()

        for note in NOTES:
            menu_item = MenuItem(icon_name='',
                                 text_label=note)
            menu_item.connect('activate', self._note_selected_cb, note)
            self._notes_palette.menu.append(menu_item)
            menu_item.show()

    def _note_selected_cb(self, widget, note):
        self._note = note
        self._update_note()

    def _setup_octaves_palette(self):
        self._octaves_palette = self._octaves_button.get_palette()

        for octave in range(9):
            menu_item = MenuItem(icon_name='',
                                 text_label=str(octave))
            menu_item.connect('activate', self._octave_selected_cb, octave)
            self._octaves_palette.menu.append(menu_item)
            menu_item.show()

    def _octave_selected_cb(self, widget, octave):
开发者ID:leonardcj,项目名称:Measure,代码行数:70,代码来源:tuning_toolbar.py

示例7: InstrumentToolbar

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
class InstrumentToolbar(gtk.Toolbar):
    ''' The toolbar for adding new instruments '''

    def __init__(self, activity):
        gtk.Toolbar.__init__(self)
        self.activity = activity
        self.new_instruments = []

        self._name_entry = gtk.Entry()
        self._name_entry.set_text(_('my instrument'))
        self._name_entry_changed_id = self._name_entry.connect(
            'changed', self.update_name_entry)
        if hasattr(self._name_entry, 'set_tooltip_text'):
            self._name_entry.set_tooltip_text(
                _('Enter instrument name.'))
        self._name_entry.set_width_chars(24)
        self._name_entry.show()
        toolitem = gtk.ToolItem()
        toolitem.add(self._name_entry)
        self.insert(toolitem, -1)
        toolitem.show()

        self._note = 'A'
        self._notes_button = ToolButton('notes')
        self._notes_button.set_tooltip(_('Notes'))
        self._notes_button.connect('clicked',
                                        self._button_selection_cb)
        self.insert(self._notes_button, -1)
        self._setup_notes_palette()
        self._notes_button.show()

        self._octave = 4
        self._octaves_button = ToolButton('octaves')
        self._octaves_button.set_tooltip(_('Octaves'))
        self._octaves_button.connect('clicked',
                                        self._button_selection_cb)
        self.insert(self._octaves_button, -1)
        self._setup_octaves_palette()
        self._octaves_button.show()

        self._new_note = ToolButton('list-add')
        self._new_note.show()
        self.insert(self._new_note, -1)
        self._new_note.set_tooltip(_('Add a new note.'))
        self._new_note.connect('clicked', self.new_note_cb)
        self._new_note.show()

    def _button_selection_cb(self, widget):
        palette = widget.get_palette()
        if palette:
            if not palette.is_up():
                palette.popup(immediate=True, state=palette.SECONDARY)
            else:
                palette.popdown(immediate=True)
            return

    def _setup_notes_palette(self):
        self._notes_palette = self._notes_button.get_palette()

        for note in NOTES:
            menu_item = MenuItem(icon_name='',
                                 text_label=note)
            menu_item.connect('activate', self._note_selected_cb, note)
            self._notes_palette.menu.append(menu_item)
            menu_item.show()

    def _note_selected_cb(self, widget, note):
        self._note = note

    def _setup_octaves_palette(self):
        self._octaves_palette = self._octaves_button.get_palette()

        for octave in range(9):
            menu_item = MenuItem(icon_name='',
                                 text_label=str(octave))
            menu_item.connect('activate', self._octave_selected_cb, octave)
            self._octaves_palette.menu.append(menu_item)
            menu_item.show()

    def _octave_selected_cb(self, widget, octave):
        self._octave = octave

    def update_name_entry(self, *args):
        ''' Add name to INSTRUMENT_DICT and combo box '''
        # Wait until a note has been added...
        return

    def new_note_cb(self, *args):
        ''' Add a new note to instrument tuning list '''
        name = self._name_entry.get_text()
        if name not in INSTRUMENT_DICT:
            INSTRUMENT_DICT[name] = []
            self.activity.tuning_toolbar.instrument.append(name)
            i = len(self.activity.tuning_toolbar.instrument)
            menu_item = MenuItem(icon_name='',
                                 text_label=name)
            menu_item.connect(
                'activate',
                self.activity.tuning_toolbar.instrument_selected_cb,
                name)
#.........这里部分代码省略.........
开发者ID:leonardcj,项目名称:Measure,代码行数:103,代码来源:tuning_toolbar.py

示例8: ReadSDComics

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

#.........这里部分代码省略.........
        file_chooser.set_preview_widget_active(have_preview)
        return

    def extract_image(self,  filename):
        zf = zipfile.ZipFile(filename, 'r')
        image_files = zf.namelist()
        image_files.sort()
        file_to_extract = image_files[0]
        extract_new_filename = self.make_new_filename(file_to_extract)
        if extract_new_filename is None or extract_new_filename == '':
            # skip over directory name if the images are in a subdirectory.
            file_to_extract = image_files[1]
            extract_new_filename = self.make_new_filename(file_to_extract)
            
        if len(image_files) > 0:
            if self.save_extracted_file(zf, file_to_extract):
                fname = os.path.join(self.get_activity_root(), 'instance',  
                                     extract_new_filename)
                return fname

    def create_new_toolbar(self):
        toolbar_box = ToolbarBox()

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

        self.connect('go-fullscreen', \
            self.__view_toolbar_go_fullscreen_cb)

        self.back = ToolButton('go-previous')
        self.back.set_tooltip(_('Back'))
        self.back.props.sensitive = False
        palette = self.back.get_palette()
        self.menu_prev_page = MenuItem(text_label= _("Previous page"))
        palette.menu.append(self.menu_prev_page) 
        self.menu_prev_page.show_all()        
        self.back.connect('clicked', self.go_back_cb)
        self.menu_prev_page.connect('activate', self.go_back_cb)
        toolbar_box.toolbar.insert(self.back, -1)
        self.back.show()

        self.forward = ToolButton('go-next')
        self.forward.set_tooltip(_('Forward'))
        self.forward.props.sensitive = False
        palette = self.forward.get_palette()
        self.menu_next_page = MenuItem(text_label= _("Next page"))
        palette.menu.append(self.menu_next_page) 
        self.menu_next_page.show_all()        
        self.forward.connect('clicked', self.go_forward_cb)
        self.menu_next_page.connect('activate', self.go_forward_cb)
        toolbar_box.toolbar.insert(self.forward, -1)
        self.forward.show()

        num_page_item = gtk.ToolItem()
        self.num_page_entry = gtk.Entry()
        self.num_page_entry.set_text('0')
        self.num_page_entry.set_alignment(1)
        self.num_page_entry.connect('insert-text',
                               self.__new_num_page_entry_insert_text_cb)
        self.num_page_entry.connect('activate',
                               self.__new_num_page_entry_activate_cb)
        self.num_page_entry.set_width_chars(4)
        num_page_item.add(self.num_page_entry)
        self.num_page_entry.show()
        toolbar_box.toolbar.insert(num_page_item, -1)
开发者ID:leonardcj,项目名称:read-sd-comics,代码行数:70,代码来源:readsdcomics.py

示例9: _make_face_bar

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
    def _make_face_bar(self):
        facebar = gtk.Toolbar()

        self._mouth_type = []
        self._mouth_type.append(RadioToolButton(
            named_icon='mouth',
            group=None,
            tooltip=_('Simple')))
        self._mouth_type[-1].connect('clicked', self._mouth_changed_cb, False)
        facebar.insert(self._mouth_type[-1], -1)

        self._mouth_type.append(RadioToolButton(
            named_icon='waveform',
            group=self._mouth_type[0],
            tooltip=_('Waveform')))
        self._mouth_type[-1].connect('clicked', self._mouth_changed_cb, False)
        facebar.insert(self._mouth_type[-1], -1)

        self._mouth_type.append(RadioToolButton(
            named_icon='frequency',
            group=self._mouth_type[0],
            tooltip=_('Frequency')))
        self._mouth_type[-1].connect('clicked', self._mouth_changed_cb, False)
        facebar.insert(self._mouth_type[-1], -1)

        separator = gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.set_expand(False)
        facebar.insert(separator, -1)

        eye_box = gtk.VBox()
        self._eye_type = {}
        for name in EYE_DICT.keys():
            self._eye_type[name] = ToolButton(name)
            self._eye_type[name].connect('clicked',
                                         self._eyes_changed_event_cb,
                                         None, name, False)
            label = gtk.Label(EYE_DICT[name]['label'])
            hbox = gtk.HBox()
            hbox.pack_start(self._eye_type[name])
            self._eye_type[name].show()
            hbox.pack_start(label)
            label.show()
            evbox = gtk.EventBox()
            evbox.connect('button-press-event', self._eyes_changed_event_cb,
                          name, False)
            evbox.add(hbox)
            hbox.show()
            eye_box.pack_start(evbox)

        eye_palette_button = ToolButton('eyes')
        eye_palette_button.set_tooltip(_('Choose eyes:'))
        palette = eye_palette_button.get_palette()
        palette.set_content(eye_box)
        eye_box.show_all()
        eye_palette_button.connect('clicked', self._face_palette_cb)
        facebar.insert(eye_palette_button, -1)
        eye_palette_button.show()

        number_of_eyes_box = gtk.VBox()
        self._number_of_eyes_type = {}
        for name in NUMBERS:
            self._number_of_eyes_type[name] = ToolButton(name)
            self._number_of_eyes_type[name].connect(
                'clicked', self._number_of_eyes_changed_event_cb,
                None, name, False)
            label = gtk.Label(name)
            hbox = gtk.HBox()
            hbox.pack_start(self._number_of_eyes_type[name])
            self._number_of_eyes_type[name].show()
            hbox.pack_start(label)
            label.show()
            evbox = gtk.EventBox()
            evbox.connect('button-press-event',
                          self._number_of_eyes_changed_event_cb,
                          name, False)
            evbox.add(hbox)
            hbox.show()
            number_of_eyes_box.pack_start(evbox)

        number_of_eyes_palette_button = ToolButton('number')
        number_of_eyes_palette_button.set_tooltip(_('Eyes number:'))
        palette = number_of_eyes_palette_button.get_palette()
        palette.set_content(number_of_eyes_box)
        number_of_eyes_box.show_all()
        number_of_eyes_palette_button.connect('clicked', self._face_palette_cb)
        facebar.insert(number_of_eyes_palette_button, -1)
        number_of_eyes_palette_button.show()

        facebar.show_all()
        return facebar
开发者ID:Akirato,项目名称:speak,代码行数:93,代码来源:activity.py

示例10: _make_voice_bar

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
    def _make_voice_bar(self):
        voicebar = gtk.Toolbar()

        all_voices = []
        for name in sorted(voice_model.allVoices().keys()):
            if len(name) < 26:
                friendly_name = name
            else:
                friendly_name = name[:26] + '...'
            all_voices.append([voice_model.allVoices()[name], friendly_name])

        # A palette for the voice selection
        logging.error(self.face.status.voice)

        self._voice_evboxes = {}
        self._voice_box = gtk.HBox()
        vboxes = [gtk.VBox(), gtk.VBox(), gtk.VBox()]
        count = len(voice_model.allVoices().keys())
        found_my_voice = False
        for i, voice in enumerate(sorted(all_voices)):
            label = gtk.Label()
            label.set_use_markup(True)
            label.set_justify(gtk.JUSTIFY_LEFT)
            label.set_markup('<span size="large">%s</span>' % voice[1])

            alignment = gtk.Alignment(0, 0, 0, 0)
            alignment.add(label)
            label.show()

            evbox = gtk.EventBox()
            self._voice_evboxes[voice[1]] = [evbox, voice[0]]
            self._voice_evboxes[voice[1]][0].connect(
                'button-press-event', self._voices_changed_event_cb, voice)
            if voice[0] == self.face.status.voice and not found_my_voice:
                self._current_voice = voice
                evbox.modify_bg(
                    0, style.COLOR_BUTTON_GREY.get_gdk_color())
                found_my_voice = True
            evbox.add(alignment)
            alignment.show()
            if i < count / 3:
                vboxes[0].pack_start(evbox)
            elif i < 2 * count / 3:
                vboxes[1].pack_start(evbox)
            else:
                vboxes[2].pack_start(evbox)
        self._voice_box.pack_start(vboxes[0], padding=style.DEFAULT_PADDING)
        self._voice_box.pack_start(vboxes[1], padding=style.DEFAULT_PADDING)
        self._voice_box.pack_start(vboxes[2], padding=style.DEFAULT_PADDING)

        voice_palette_button = ToolButton('module-language')
        voice_palette_button.set_tooltip(_('Choose voice:'))
        self._voice_palette = voice_palette_button.get_palette()
        self._voice_palette.set_content(self._voice_box)
        self._voice_box.show_all()
        voice_palette_button.connect('clicked', self._face_palette_cb)
        voicebar.insert(voice_palette_button, -1)
        voice_palette_button.show()

        brain_voices = []
        for name in sorted(brain.BOTS.keys()):
            brain_voices.append([voice_model.allVoices()[name], name])

        self._brain_evboxes = {}
        self._brain_box = gtk.HBox()
        vboxes = gtk.VBox()
        count = brain.BOTS.keys()
        found_my_voice = False
        for i, voice in enumerate(brain_voices):
            label = gtk.Label()
            label.set_use_markup(True)
            label.set_justify(gtk.JUSTIFY_LEFT)
            label.set_markup('<span size="large">%s</span>' % voice[1])

            alignment = gtk.Alignment(0, 0, 0, 0)
            alignment.add(label)
            label.show()

            evbox = gtk.EventBox()
            self._brain_evboxes[voice[1]] = [evbox, voice[0]]
            self._brain_evboxes[voice[1]][0].connect(
                'button-press-event', self._voices_changed_event_cb, voice)
            if voice[0] == self.face.status.voice and not found_my_voice:
                evbox.modify_bg(
                    0, style.COLOR_BUTTON_GREY.get_gdk_color())
                found_my_voice = True
            evbox.add(alignment)
            alignment.show()
            vboxes.pack_start(evbox)
        self._brain_box.pack_start(vboxes, padding=style.DEFAULT_PADDING)
        self._brain_box.show_all()

        separator = gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.set_expand(False)
        voicebar.insert(separator, -1)

        self.pitchadj = gtk.Adjustment(self.face.status.pitch, 0,
                                       espeak.PITCH_MAX, 1,
                                       espeak.PITCH_MAX/10, 0)
#.........这里部分代码省略.........
开发者ID:Akirato,项目名称:speak,代码行数:103,代码来源:activity.py

示例11: WebToolbar

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

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

    def _go_back_cb(self, button):
        self._browser.web_navigation.goBack()
    
    def _go_forward_cb(self, button):
        self._browser.web_navigation.goForward()

    def _title_changed_cb(self, embed, spec):
        self._set_title(embed.props.title)

    def _stop_and_reload_cb(self, button):
        if self._loading:
            self._browser.web_navigation.stop( \
                    interfaces.nsIWebNavigation.STOP_ALL)
        else:
            flags = interfaces.nsIWebNavigation.LOAD_FLAGS_NONE
            self._browser.web_navigation.reload(flags)

    def _set_loading(self, loading):
        self._loading = loading

        if self._loading:
            self._show_stop_icon()
            self._stop_and_reload.set_tooltip(_('Stop'))
        else:
            self._show_reload_icon()
            self._stop_and_reload.set_tooltip(_('Reload'))

    def _reload_session_history(self, current_page_index=None):
        session_history = self._browser.web_navigation.sessionHistory
        if current_page_index is None:
            current_page_index = session_history.index

        for palette in (self._back.get_palette(), self._forward.get_palette()):
            for menu_item in palette.menu.get_children():
                palette.menu.remove(menu_item)

        if current_page_index > _MAX_HISTORY_ENTRIES:
            bottom = current_page_index - _MAX_HISTORY_ENTRIES
        else:
            bottom = 0
        if  (session_history.count - current_page_index) > \
               _MAX_HISTORY_ENTRIES:
            top = current_page_index + _MAX_HISTORY_ENTRIES + 1
        else:
            top = session_history.count

        for i in range(bottom, top):
            if i == current_page_index:
                continue

            entry = session_history.getEntryAtIndex(i, False)
            menu_item = MenuItem(entry.title, text_maxlen=60)
            menu_item.connect('activate', self._history_item_activated_cb, i)

            if i < current_page_index:
                palette = self._back.get_palette()
                palette.menu.prepend(menu_item)
            elif i > current_page_index:
                palette = self._forward.get_palette()
                palette.menu.append(menu_item)

            menu_item.show()

    def _history_item_activated_cb(self, menu_item, index):
        self._browser.web_navigation.gotoIndex(index)
开发者ID:lucian1900,项目名称:Webified,代码行数:70,代码来源:webtoolbar.py

示例12: SensorToolbar

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

#.........这里部分代码省略.........
    def get_log(self):
        return self._log_value

    def get_log_idx(self):
        if self._log_value in LOG_TIMER_VALUES:
            return LOG_TIMER_VALUES.index(self._log_value)
        else:
            return LOG_TIMER_VALUES[0]

    def set_log_idx(self, idx):
        self._log_value = LOG_TIMER_VALUES[idx]
        self.log_label.set_text(self._log_to_string(self._log_value))
        if hasattr(self, "_log_button"):
            self._log_button.set_icon("timer-%d" % (self._log_value))

    def _log_selection_cb(self, widget):
        if self._log_palette:
            if not self._log_palette.is_up():
                self._log_palette.popup(immediate=True, state=self._log_palette.SECONDARY)
            else:
                self._log_palette.popdown(immediate=True)
            return

    def _log_to_seconds(self, tenth_seconds):
        return tenth_seconds / 10.0

    def _log_to_string(self, tenth_seconds):
        if tenth_seconds in LOG_TIMER_LABELS:
            return LOG_TIMER_LABELS[tenth_seconds]
        else:
            return _("1 second")

    def _setup_log_palette(self):
        self._log_palette = self._log_button.get_palette()

        for tenth_seconds in LOG_TIMER_VALUES:
            text = self._log_to_string(tenth_seconds)
            menu_item = MenuItem(icon_name="timer-%d" % (tenth_seconds), text_label=self._log_to_string(tenth_seconds))
            menu_item.connect("activate", self._log_selected_cb, tenth_seconds)
            self._log_palette.menu.append(menu_item)
            menu_item.show()

    def _log_selected_cb(self, button, seconds):
        self.set_log_idx(LOG_TIMER_VALUES.index(seconds))

    def add_frequency_slider(self, toolbox):
        """ Either on the Sound toolbar or the Main toolbar """
        self._freq_stepper_up = ToolButton("freq-high")
        self._freq_stepper_up.set_tooltip(_("Zoom out"))
        self._freq_stepper_up.connect("clicked", self._freq_stepper_up_cb)
        self._freq_stepper_up.show()

        self.activity.adjustmentf = gtk.Adjustment(0.5, self.LOWER, self.UPPER, 0.01, 0.1, 0)
        self.activity.adjustmentf.connect("value_changed", self.cb_page_sizef)

        self._freq_range = gtk.HScale(self.activity.adjustmentf)
        self._freq_range.set_inverted(True)
        self._freq_range.set_draw_value(False)
        self._freq_range.set_update_policy(gtk.UPDATE_CONTINUOUS)
        self._freq_range.set_size_request(120, 15)
        self._freq_range.show()

        self._freq_stepper_down = ToolButton("freq-low")
        self._freq_stepper_down.set_tooltip(_("Zoom in"))
        self._freq_stepper_down.connect("clicked", self._freq_stepper_down_cb)
        self._freq_stepper_down.show()
开发者ID:quozl,项目名称:Measure,代码行数:70,代码来源:sensor_toolbar.py

示例13: ReadToolbar

# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import get_palette [as 别名]
class ReadToolbar(gtk.Toolbar):
    __gtype_name__ = 'ReadToolbar'

    def __init__(self):
        gtk.Toolbar.__init__(self)
        self.back = ToolButton('go-previous')
        self.back.set_tooltip(_('Back'))
        self.back.props.sensitive = False
        palette = self.back.get_palette()
        self.prev_page = MenuItem(text_label= _("Previous page"))
        palette.menu.append(self.prev_page) 
        self.prev_page.show_all()        
        self.back.connect('clicked', self.go_back_cb)
        self.prev_page.connect('activate', self.go_back_cb)
        self.insert(self.back, -1)
        self.back.show()

        self.forward = ToolButton('go-next')
        self.forward.set_tooltip(_('Forward'))
        self.forward.props.sensitive = False
        palette = self.forward.get_palette()
        self.next_page = MenuItem(text_label= _("Next page"))
        palette.menu.append(self.next_page) 
        self.next_page.show_all()        
        self.forward.connect('clicked', self.go_forward_cb)
        self.next_page.connect('activate', self.go_forward_cb)
        self.insert(self.forward, -1)
        self.forward.show()

        num_page_item = gtk.ToolItem()

        self._num_page_entry = gtk.Entry()
        self._num_page_entry.set_text('0')
        self._num_page_entry.set_alignment(1)
        self._num_page_entry.connect('insert-text',
                                     self._num_page_entry_insert_text_cb)
        self._num_page_entry.connect('activate',
                                     self._num_page_entry_activate_cb)

        self._num_page_entry.set_width_chars(4)

        num_page_item.add(self._num_page_entry)
        self._num_page_entry.show()

        self.insert(num_page_item, -1)
        num_page_item.show()

        total_page_item = gtk.ToolItem()

        self._total_page_label = gtk.Label()

        label_attributes = pango.AttrList()
        label_attributes.insert(pango.AttrSize(14000, 0, -1))
        label_attributes.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1))
        self._total_page_label.set_attributes(label_attributes)

        self._total_page_label.set_text(' / 0')
        total_page_item.add(self._total_page_label)
        self._total_page_label.show()

        self.insert(total_page_item, -1)
        total_page_item.show()

    def _num_page_entry_insert_text_cb(self, entry, text, length, position):
        if not re.match('[0-9]', text):
            entry.emit_stop_by_name('insert-text')
            return True
        return False

    def _num_page_entry_activate_cb(self, entry):
        if entry.props.text:
            page = int(entry.props.text) - 1
        else:
            page = 0

        if page >= self.total_pages:
            page = self.total_pages - 1
        elif page < 0:
            page = 0

        self.current_page = page
        self.activity.set_current_page(page)
        self.activity.show_page(page)
        entry.props.text = str(page + 1)
        self._update_nav_buttons()
        
    def go_back_cb(self, button):
        self.activity.previous_page()
    
    def go_forward_cb(self, button):
        self.activity.next_page()
    
    def _update_nav_buttons(self):
        current_page = self.current_page
        self.back.props.sensitive = current_page > 0
        self.forward.props.sensitive = \
            current_page < self.total_pages - 1
        
        self._num_page_entry.props.text = str(current_page + 1)
        self._total_page_label.props.label = \
#.........这里部分代码省略.........
开发者ID:leonardcj,项目名称:read-sd-comics,代码行数:103,代码来源:readtoolbar.py

示例14: TextAttributesToolbar

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

#.........这里部分代码省略.........
        self._font_white_list = []
        self._font_white_list.extend(DEFAULT_FONTS)
        fonts_file = open(USER_FONTS_FILE_PATH)
        for line in fonts_file:
            self._font_white_list.append(line.strip())
        # update the menu
        for child in self._font_palette.menu.get_children():
            self._font_palette.menu.remove(child)
            child = None
        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):
        attributes = {"bold": True, "italics": True, "underline": True,
                      "font": ""}
        it = self._main_area.selected[0].attributes.get_iterator()
        start_index = self._main_area.selected[0].index
        end_index = self._main_area.selected[0].end_index
        while(1):
            found = False
            r = it.range()
            if start_index == end_index:
                if r[0] <= start_index and r[1] > start_index:
                    found = True
            elif start_index < end_index:
                if r[0] > end_index:
开发者ID:Daksh,项目名称:Labyrinth,代码行数:70,代码来源:labyrinthactivity.py


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