def _add_search_controls(self, toolbar): book_search_item = Gtk.ToolItem() toolbar.search_entry = iconentry.IconEntry() toolbar.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY, 'system-search') toolbar.search_entry.add_clear_button() toolbar.search_entry.connect('activate', self.__search_entry_activate_cb) width = int(Gdk.Screen.width() / 4) toolbar.search_entry.set_size_request(width, -1) book_search_item.add(toolbar.search_entry) toolbar.search_entry.show() toolbar.insert(book_search_item, -1) book_search_item.show() toolbar.source_combo = ComboBox() toolbar.source_combo.props.sensitive = True toolbar.source_changed_cb_id = \ toolbar.source_combo.connect('changed', self.__source_changed_cb) combotool = ToolComboBox(toolbar.source_combo) toolbar.insert(combotool, -1) combotool.show() self.bt_catalogs = ToggleToolButton('books') self.bt_catalogs.set_tooltip(_('Catalogs')) toolbar.insert(self.bt_catalogs, -1) self.bt_catalogs.connect('toggled', self.__toggle_cats_cb) if len(self.catalogs) > 0: self.bt_catalogs.show() if len(self.languages) > 0: toolbar.config_toolbarbutton = ToolbarButton() toolbar.config_toolbarbutton.props.icon_name = 'preferences-system' toolbar.config_toolbarbox = Gtk.Toolbar() toolbar.config_toolbarbutton.props.page = toolbar.config_toolbarbox toolbar.language_combo = ComboBox() toolbar.language_combo.props.sensitive = True combotool = ToolComboBox(toolbar.language_combo) toolbar.language_combo.append_item('all', _('Any language')) for key in self.languages.keys(): toolbar.language_combo.append_item(key, self.languages[key]) toolbar.language_combo.set_active(0) toolbar.config_toolbarbutton.props.page.insert(combotool, -1) toolbar.insert(toolbar.config_toolbarbutton, -1) toolbar.config_toolbarbutton.show() combotool.show() toolbar.language_changed_cb_id = \ toolbar.language_combo.connect('changed', self.__language_changed_cb) self._device_manager = devicemanager.DeviceManager() self._refresh_sources(toolbar) self._device_manager.connect('device-changed', self.__device_changed_cb) toolbar.search_entry.grab_focus() return toolbar
def combo_factory(combo_array, toolbar, callback, cb_arg=None, tooltip=None, default=None): '''Factory for making a toolbar combo box''' combo = ComboBox() if tooltip is not None and hasattr(combo, 'set_tooltip_text'): combo.set_tooltip_text(tooltip) if cb_arg is not None: combo.connect('changed', callback, cb_arg) else: combo.connect('changed', callback) for i, selection in enumerate(combo_array): combo.append_item(i, selection, None) combo.show() toolitem = Gtk.ToolItem() toolitem.add(combo) if hasattr(toolbar, 'insert'): # the main toolbar toolbar.insert(toolitem, -1) else: # or a secondary toolbar toolbar.props.page.insert(toolitem, -1) toolitem.show() if default is not None: combo.set_active(combo_array.index(default)) return combo
def __init__(self, activity): Gtk.Toolbar.__init__(self) self._activity = activity self._speech = SpeechManager() self._is_paused = False self.load_speech_parameters() self._voices = self._speech.get_all_voices() # a dictionary locale = os.environ.get('LANG', '') language_location = locale.split('.', 1)[0].lower() language = language_location.split('_')[0] # 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' self._voice = 'en_us' if language_location in self._voices: self._voice = language_location elif language in self._voices: self._voice = language voice_names = [] for language, name in self._voices.iteritems(): voice_names.append((language, name)) voice_names.sort(self._compare_voice) # Play button self._play_button = ToggleToolButton('media-playback-start') self._play_button.show() self._play_button.connect('toggled', self._play_toggled_cb) self.insert(self._play_button, -1) self._play_button.set_tooltip(_('Play / Pause')) # Stop button self._stop_button = ToolButton('media-playback-stop') self._stop_button.show() self._stop_button.connect('clicked', self._stop_clicked_cb) self._stop_button.set_sensitive(False) self.insert(self._stop_button, -1) self._stop_button.set_tooltip(_('Stop')) # Language list combo = ComboBox() which = 0 for pair in voice_names: language, name = pair combo.append_item(language, name) if language == self._voice: combo.set_active(which) which += 1 combo.connect('changed', self._voice_changed_cb) combotool = ToolComboBox(combo) self.insert(combotool, -1) combotool.show() self._speech.connect('stop', self._reset_buttons_cb)
def __init__(self, activity): Gtk.Toolbar.__init__(self) voicebar = Gtk.Toolbar() self._activity = activity if not speech.supported: return 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')) 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() self.pitchadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0) pitchbar = Gtk.HScale(self.pitchadj) pitchbar.set_draw_value(False) pitchbar.set_update_policy(Gtk.UPDATE_DISCONTINUOUS) pitchbar.set_size_request(150, 15) self.pitchadj.set_value(speech.pitch) pitchtool = Gtk.ToolItem() pitchtool.add(pitchbar) pitchtool.show() self.insert(pitchtool, -1) pitchbar.show() self.rateadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0) ratebar = Gtk.HScale(self.rateadj) ratebar.set_draw_value(False) ratebar.set_update_policy(Gtk.UPDATE_DISCONTINUOUS) ratebar.set_size_request(150, 15) self.rateadj.set_value(speech.rate) ratetool = Gtk.ToolItem() ratetool.add(ratebar) ratetool.show() self.insert(ratetool, -1) ratebar.show() self.pitchadj.connect("value_changed", self.pitch_adjusted_cb) self.rateadj.connect("value_changed", self.rate_adjusted_cb)
def __init__(self, icon_name, **kwargs): Gtk.ToolItem.__init__(self, **kwargs) self.icon_name = icon_name self.set_border_width(style.DEFAULT_PADDING) self.combo = ComboBox() self.combo.set_focus_on_click(False) self.combo.show() self.add(self.combo)
def __init__(self): ToolbarBox.__init__(self) self._mount_point = None self._filter_type = None self._what_filter = None self.search_entry = iconentry.IconEntry() self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY, 'entry-search') text = _('Search in %s') % _('Journal') self.search_entry.set_placeholder_text(text) self.search_entry.connect('activate', self._search_entry_activated_cb) self.search_entry.connect('changed', self._search_entry_changed_cb) self.search_entry.add_clear_button() self._autosearch_timer = None self._add_widget(self.search_entry, expand=True) self._favorite_button = ToggleToolButton('emblem-favorite') self._favorite_button.set_tooltip(_('Favorite entries')) self._favorite_button.connect('toggled', self.__favorite_button_toggled_cb) self.toolbar.insert(self._favorite_button, -1) self._favorite_button.show() self._what_search_combo = ComboBox() self._what_combo_changed_sid = self._what_search_combo.connect( 'changed', self._combo_changed_cb) tool_item = ToolComboBox(self._what_search_combo) self.toolbar.insert(tool_item, -1) tool_item.show() self._when_search_combo = self._get_when_search_combo() tool_item = ToolComboBox(self._when_search_combo) self.toolbar.insert(tool_item, -1) tool_item.show() self._sorting_button = SortingButton() self.toolbar.insert(self._sorting_button, -1) self._sorting_button.connect('sort-property-changed', self.__sort_changed_cb) self._sorting_button.show() # TODO: enable it when the DS supports saving the buddies. # self._with_search_combo = self._get_with_search_combo() # tool_item = ToolComboBox(self._with_search_combo) # self.insert(tool_item, -1) # tool_item.show() self._query = self._build_query() self.refresh_filters()
def create_new_toolbar(self): toolbar_box = ToolbarBox() book_search_item = Gtk.ToolItem() self.search_entry = Gtk.Entry() self.search_entry.connect('activate', self.search_entry_activate_cb) width = int(Gdk.Screen.width() / 2.1) self.search_entry.set_size_request(width, -1) book_search_item.add(self.search_entry) self.search_entry.show() toolbar_box.toolbar.insert(book_search_item, -1) book_search_item.show() self._download = ToolButton('go-down') self._download.set_tooltip(_('Get Book')) self._download.props.sensitive = False self._download.connect('clicked', self._get_book_cb) toolbar_box.toolbar.insert(self._download, -1) self._download.show() self.format_combo = ComboBox() self.format_combo.connect('changed', self.format_changed_cb) self.format_combo.append_item('.djvu', 'Deja Vu') self.format_combo.append_item('_bw.pdf', 'B/W PDF') self.format_combo.append_item('.pdf', 'Color PDF') self.format_combo.append_item('.epub', 'EPUB') self.format_combo.set_active(0) self.format_combo.props.sensitive = False combotool = ToolComboBox(self.format_combo) toolbar_box.toolbar.insert(combotool, -1) combotool.show() self.search_entry.grab_focus() separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) separator.show() stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl><Shift>Q' toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show()
def _get_with_search_combo(self): with_search = ComboBox() with_search.append_item(_ACTION_EVERYBODY, _('Anyone')) with_search.append_separator() with_search.append_item(_ACTION_MY_FRIENDS, _('My friends')) with_search.append_item(_ACTION_MY_CLASS, _('My class')) with_search.append_separator() # TODO: Ask the model for buddies. with_search.append_item(3, 'Dan', 'theme:xo') with_search.set_active(0) with_search.connect('changed', self._combo_changed_cb) return with_search
def _combo_factory(combo_array, default, tooltip, toolbar): '''Factory for making a toolbar combo box''' my_combo = ComboBox() if hasattr(my_combo, 'set_tooltip_text'): my_combo.set_tooltip_text(tooltip) for i, s in enumerate(combo_array): my_combo.append_item(i, _(s), None) toolbar.insert(ToolComboBox(my_combo), -1) my_combo.set_active(default) return my_combo
def __init__(self, owner): GObject.GObject.__init__(self) self.owner = owner self.toolItem = {} self.blockBeat = False self.beatWheel = [] btn = RadioToolButton(group=None) btn.set_icon_name('beats') btn.connect('toggled', self.setBeat, 0) btn.set_tooltip(_('Jump To Beat')) self.insert(btn, -1) self.beatWheel.append(btn) for i in range(1, 12): btn = RadioToolButton(group=self.beatWheel[0]) btn.set_icon_name('beats') btn.connect('toggled', self.setBeat, i) btn.set_tooltip(_('Jump To Beat')) self.insert(btn, -1) self.beatWheel.append(btn) label = Gtk.Label(label=_("Synch to:")) self.syncLabel = Gtk.ToolItem() self.syncLabel.add(label) self.insert(self.syncLabel, 0) self.comboBox = ComboBox() self.comboBox.append_item(1, _("1 Beat")) self.comboBox.append_item(2, _("2 Beats")) self.comboBox.append_item(3, _("3 Beats")) self.comboBox.append_item(4, _("4 Beats")) self.comboBox.append_item(5, _("5 Beats")) self.comboBox.append_item(6, _("6 Beats")) self.comboBox.append_item(7, _("7 Beats")) self.comboBox.append_item(8, _("8 Beats")) self.comboBox.append_item(9, _("9 Beats")) self.comboBox.append_item(10, _("10 Beats")) self.comboBox.append_item(11, _("11 Beats")) self.comboBox.append_item(12, _("12 Beats")) self.comboBox.set_active(4 - 1) # default 4 beats self.comboBox.connect("changed", self.changeSync) self.syncBox = ToolComboBox(self.comboBox) self.insert(self.syncBox, 1) self.show_all()
def _get_when_search_combo(self): when_search = ComboBox() when_search.append_item(_ACTION_ANYTIME, _('Anytime')) when_search.append_separator() when_search.append_item(_ACTION_TODAY, _('Today')) when_search.append_item(_ACTION_SINCE_YESTERDAY, _('Since yesterday')) # TRANS: Filter entries modified during the last 7 days. when_search.append_item(_ACTION_PAST_WEEK, _('Past week')) # TRANS: Filter entries modified during the last 30 days. when_search.append_item(_ACTION_PAST_MONTH, _('Past month')) # TRANS: Filter entries modified during the last 356 days. when_search.append_item(_ACTION_PAST_YEAR, _('Past year')) when_search.set_active(0) when_search.connect('changed', self._combo_changed_cb) return when_search
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 __init__(self): Gtk.Toolbar.__init__(self) book_search_item = Gtk.ToolItem() self.search_entry = Gtk.Entry() self.search_entry.connect('activate', self.search_entry_activate_cb) width = int(Gdk.Screen.width() / 2) self.search_entry.set_size_request(width, -1) book_search_item.add(self.search_entry) self.search_entry.show() self.insert(book_search_item, -1) book_search_item.show() self._download = ToolButton('go-down') self._download.set_tooltip(_('Get Book')) self._download.props.sensitive = False self._download.connect('clicked', self._get_book_cb) self.insert(self._download, -1) self._download.show() self.format_combo = ComboBox() self.format_combo.connect('changed', self.format_changed_cb) self.format_combo.append_item('.djvu', 'Deja Vu') self.format_combo.append_item('_bw.pdf', 'B/W PDF') self.format_combo.append_item('.pdf', 'Color PDF') self.format_combo.append_item('.epub', 'EPUB') self.format_combo.set_active(0) self.format_combo.props.sensitive = False combotool = ToolComboBox(self.format_combo) self.insert(combotool, -1) combotool.show() self.search_entry.grab_focus()
def __init__(self, combo=None, **kwargs): self.label = None self._label_text = '' GObject.GObject.__init__(self, **kwargs) self.set_border_width(style.DEFAULT_PADDING) hbox = Gtk.HBox(False, style.DEFAULT_SPACING) self.label = Gtk.Label(label=self._label_text) hbox.pack_start(self.label, False, False, 0) self.label.show() if combo: self.combo = combo else: self.combo = ComboBox() hbox.pack_start(self.combo, True, True, 0) self.combo.show() self.add(hbox) hbox.show()
def __init__(self, handle): activity.Activity.__init__(self, handle) # No sharing (Future Improvement) self.max_participants = 1 # Build the activity toolbar. toolbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbox.toolbar.insert(activity_button, 0) activity_button.show() comboLabel1 = Gtk.ToolItem() label1 = Gtk.Label() label1.set_text(_('Level:') + ' ') comboLabel1.add(label1) toolbox.toolbar.insert(comboLabel1, -1) comboLabel1.show() label1.show() comboField = Gtk.ToolItem() combo = ComboBox() combo.set_wrap_width(3) combo.append_item(0, _('Easy')) combo.append_item(1, _('Moderate')) combo.append_item(2, _('Hard')) combo.set_active(0) comboField.add(combo) combo.connect('changed', self.change_combo) toolbox.toolbar.insert(comboField, -1) comboField.show() combo.show() separator = Gtk.SeparatorToolItem() separator.props.draw = True separator.set_expand(False) toolbox.toolbar.insert(separator, -1) separator.show() restart = ToolButton('new-game') toolbox.toolbar.insert(restart, -1) restart.set_tooltip(_('Restart')) restart.connect('clicked', self._restart_button_cb) restart.show() next_bt = ToolButton('next') toolbox.toolbar.insert(next_bt, -1) next_bt.set_tooltip(_('Next Number')) next_bt.connect('clicked', self._next_button_cb) next_bt.set_sensitive(False) next_bt.show() separator2 = Gtk.SeparatorToolItem() separator2.props.draw = True separator2.set_expand(False) toolbox.toolbar.insert(separator2, -1) separator2.show() comboLabel2 = Gtk.ToolItem() label1 = Gtk.Label() label1.set_text(_('Score:') + ' ') comboLabel2.add(label1) toolbox.toolbar.insert(comboLabel2, -1) comboLabel2.show() label1.show() self._score_image = Gtk.Image() item = Gtk.ToolItem() item.add(self._score_image) toolbox.toolbar.insert(item, -1) item.show() separator2 = Gtk.SeparatorToolItem() separator2.props.draw = False separator2.set_expand(True) toolbox.toolbar.insert(separator2, -1) separator2.show() stop_button = StopButton(self) toolbox.toolbar.insert(stop_button, -1) stop_button.show() stop_button.connect('clicked', self._stop_cb) toolbox.show() self.set_toolbar_box(toolbox) # Create the game instance. self.game = CowBulls.CowBulls(parent=self) # Build the Pygame canvas. self.game.canvas = self._pygamecanvas = sugargame.canvas.PygameCanvas( self, main=self.game.run, modules=[pygame.display, pygame.font]) # Note that set_canvas implicitly calls # read_file when resuming from the Journal. self.game.set_next_button(next_bt) self.set_canvas(self._pygamecanvas) Gdk.Screen.get_default().connect('size-changed', self.__configure_cb)
def __init__(self): Gtk.Toolbar.__init__(self) self.activity = None self._speech = SpeechManager() self._voices = self._speech.get_all_voices() # a dictionary locale = os.environ.get('LANG', '') language_location = locale.split('.', 1)[0].lower() language = language_location.split('_')[0] # 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' self._voice = 'en_us' if language_location in self._voices: self._voice = language_location elif language in self._voices: self._voice = language voice_names = [] for language, name in self._voices.items(): voice_names.append((language, name)) voice_names.sort() # Play button Image play_img = Gtk.Image() play_img.show() play_img.set_from_icon_name('media-playback-start', Gtk.IconSize.LARGE_TOOLBAR) # Pause button Image pause_img = Gtk.Image() pause_img.show() pause_img.set_from_icon_name('media-playback-pause', Gtk.IconSize.LARGE_TOOLBAR) # Play button self.play_button = ToggleToolButton('media-playback-start') self.play_button.show() self.play_button.connect('toggled', self._play_toggled_cb, [play_img, pause_img]) self.insert(self.play_button, -1) self.play_button.set_tooltip(_('Play / Pause')) combo = ComboBox() which = 0 for pair in voice_names: language, name = pair combo.append_item(language, name) if language == self._voice: combo.set_active(which) which += 1 combo.connect('changed', self._voice_changed_cb) combotool = ToolComboBox(combo) self.insert(combotool, -1) combotool.show() self.pitchadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0) pitchbar = Gtk.HScale() pitchbar.set_adjustment(self.pitchadj) pitchbar.set_draw_value(False) # pitchbar.set_update_policy(Gtk.UpdatePolicy.ALWAYS) pitchbar.set_size_request(150, 15) pitchtool = Gtk.ToolItem() pitchtool.add(pitchbar) pitchtool.show() self.insert(pitchtool, -1) pitchbar.show() self.rateadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0) ratebar = Gtk.HScale() ratebar.set_adjustment(self.rateadj) ratebar.set_draw_value(False) # ratebar.set_update_policy(Gtk.UpdatePolicy.ALWAYS) ratebar.set_size_request(150, 15) ratetool = Gtk.ToolItem() ratetool.add(ratebar) ratetool.show() self.insert(ratetool, -1) ratebar.show()
def create_dialog(self): """Setup most of the dialog.""" # Toolbar self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self._parent) self._toolbar_box.toolbar.insert(activity_button, 0) def append(icon_name, label, page, position): toolbar_button = ToolbarButton() toolbar_button.props.page = page toolbar_button.props.icon_name = icon_name toolbar_button.props.label = label self._toolbar_box.toolbar.insert(toolbar_button, position) append('toolbar-edit', _('Edit'), EditToolbar(self._parent), -1) append('toolbar-algebra', _('Algebra'), AlgebraToolbar(self._parent), -1) append('toolbar-trigonometry', _('Trigonometry'), TrigonometryToolbar(self._parent), -1) append('toolbar-boolean', _('Boolean'), BooleanToolbar(self._parent), -1) self._misc_toolbar = MiscToolbar( self._parent, target_toolbar=self._toolbar_box.toolbar) append('toolbar-constants', _('Miscellaneous'), self._misc_toolbar, 5) self._stop_separator = Gtk.SeparatorToolItem() self._stop_separator.props.draw = False self._stop_separator.set_expand(True) self._stop_separator.show() self._toolbar_box.toolbar.insert(self._stop_separator, -1) self._stop = StopButton(self._parent) self._toolbar_box.toolbar.insert(self._stop, -1) self._toolbar_box.show_all() self._parent.set_toolbar_box(self._toolbar_box) # Some layout constants self.input_font = Pango.FontDescription('sans bold 12') self.button_font = Pango.FontDescription('sans bold 16') self.col_white = self.create_color(1.00, 1.00, 1.00) self.col_gray1 = self.create_color(0.76, 0.76, 0.76) self.col_gray2 = self.create_color(0.50, 0.50, 0.50) self.col_gray3 = self.create_color(0.25, 0.25, 0.25) self.col_black = self.create_color(0.00, 0.00, 0.00) self.col_red = self.create_color(1.00, 0.00, 0.00) # Big - Table, 16 rows, 10 columns, homogeneously divided self.grid = Gtk.Grid() self.grid.set_column_homogeneous(True) self.grid.set_row_spacing(0) self.grid.set_column_spacing(4) # Left part: container and input vc1 = Gtk.VBox(False, 0) hc1 = Gtk.HBox(False, 10) eb = Gtk.EventBox() eb.add(hc1) eb.modify_bg(Gtk.StateType.NORMAL, self.col_black) eb.set_border_width(12) eb2 = Gtk.EventBox() eb2.add(eb) eb2.modify_bg(Gtk.StateType.NORMAL, self.col_black) label1 = Gtk.Label(label=_('Label:')) label1.modify_fg(Gtk.StateType.NORMAL, self.col_white) label1.set_alignment(1, 0.5) hc1.pack_start(label1, expand=False, fill=False, padding=10) self.label_entry = Gtk.Entry() self.label_entry.modify_bg(Gtk.StateType.INSENSITIVE, self.col_black) hc1.pack_start(self.label_entry, expand=True, fill=True, padding=0) vc1.pack_start(eb2, False, True, 0) self.text_entry = Gtk.Entry() try: self.text_entry.props.im_module = 'gtk-im-context-simple' except AttributeError: pass self.text_entry.set_size_request(-1, 75) self.text_entry.connect('key_press_event', self._parent.ignore_key_cb) self.text_entry.modify_font(self.input_font) self.text_entry.modify_bg(Gtk.StateType.INSENSITIVE, self.col_black) eb = Gtk.EventBox() eb.add(self.text_entry) eb.modify_bg(Gtk.StateType.NORMAL, self.col_black) eb.set_border_width(12) eb2 = Gtk.EventBox() eb2.add(eb) eb2.modify_bg(Gtk.StateType.NORMAL, self.col_black) vc1.pack_start(eb2, expand=True, fill=True, padding=0) self.grid.attach(vc1, 0, 0, 7, 6) # Left part: buttons self.pad = Gtk.Grid() self.pad.set_column_homogeneous(True) self.pad.set_row_spacing(6) self.pad.set_column_spacing(6) self.create_button_data() self.buttons = {} for x, y, w, h, cap, bgcol, cb in self.button_data: button = self.create_button(_(cap), cb, self.col_white, bgcol, w, h) self.buttons[cap] = button self.pad.attach(button, x, y, w, h) eb = Gtk.EventBox() eb.add(self.pad) eb.modify_bg(Gtk.StateType.NORMAL, self.col_black) self.grid.attach(eb, 0, 6, 7, 20) # Right part: container and equation button hc2 = Gtk.HBox() combo = ComboBox() combo.append_item(0, _('All equations')) combo.append_item(1, _('My equations')) combo.append_item(2, _('Show variables')) combo.set_active(0) combo.connect('changed', self._history_filter_cb) hc2.pack_start(combo, True, True, 0) hc2.set_border_width(6) self.grid.attach(hc2, 7, 0, 4, 2) # Right part: last equation self.last_eq = Gtk.TextView() self.last_eq.set_editable(False) self.last_eq.set_wrap_mode(Gtk.WrapMode.WORD_CHAR) self.last_eq.connect('realize', self._textview_realize_cb) self.last_eq.modify_base( Gtk.StateType.NORMAL, Gdk.color_parse(sugar3.profile.get_color().get_fill_color())) self.last_eq.modify_bg( Gtk.StateType.NORMAL, Gdk.color_parse(sugar3.profile.get_color().get_stroke_color())) self.last_eq.set_border_window_size(Gtk.TextWindowType.LEFT, 4) self.last_eq.set_border_window_size(Gtk.TextWindowType.RIGHT, 4) self.last_eq.set_border_window_size(Gtk.TextWindowType.TOP, 4) self.last_eq.set_border_window_size(Gtk.TextWindowType.BOTTOM, 4) # TODO Fix for old Sugar 0.82 builds, red_float not available xo_color = sugar3.profile.get_color() bright = (Gdk.color_parse(xo_color.get_fill_color()).red_float + Gdk.color_parse(xo_color.get_fill_color()).green_float + Gdk.color_parse(xo_color.get_fill_color()).blue_float) / 3.0 if bright < 0.5: self.last_eq.modify_text(Gtk.StateType.NORMAL, self.col_white) else: self.last_eq.modify_text(Gtk.StateType.NORMAL, self.col_black) self.grid.attach(self.last_eq, 7, 2, 4, 5) # Right part: history scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.history_vbox = Gtk.VBox() self.history_vbox.set_homogeneous(False) self.history_vbox.set_border_width(0) self.history_vbox.set_spacing(4) self.variable_vbox = Gtk.VBox() self.variable_vbox.set_homogeneous(False) self.variable_vbox.set_border_width(0) self.variable_vbox.set_spacing(4) vbox = Gtk.VBox() vbox.pack_start(self.history_vbox, True, True, 0) vbox.pack_start(self.variable_vbox, True, True, 0) scrolled_window.add_with_viewport(vbox) self.grid.attach(scrolled_window, 7, 7, 4, 19) Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
def __init__(self): Gtk.EventBox.__init__(self) vbox_outer = Gtk.VBox() vbox = Gtk.VBox() edit_label = Gtk.Label( _('<span weight="bold" size="larger">' 'Edit an installed activity</span>\n\n' 'You can modify an activity, and if there are errors the ' 'activity can stop working. If you are not sure, clone the ' 'activity to have a backup.')) edit_label.set_use_markup(True) edit_label.set_line_wrap(True) vbox.pack_start(edit_label, expand=False, fill=True, padding=10) hbox_edit = Gtk.HBox() hbox_edit.pack_start(Gtk.Label(_('Select the activity')), True, True, 10) activity_name_combo = ComboBox() self._load_activities_installed_combo(activity_name_combo) hbox_edit.pack_start(activity_name_combo, expand=False, fill=False, padding=10) edit_btn = Gtk.Button(_('Start')) edit_btn.connect('clicked', self._pick_existing_activity, activity_name_combo) hbox_edit.pack_start(edit_btn, expand=False, fill=False, padding=10) align = Gtk.Alignment.new(0.5, 0.5, 0, 0) align.add(hbox_edit) vbox.pack_start(align, expand=False, fill=False, padding=10) new_project_label = Gtk.Label( _('<span weight="bold" size="larger">' 'Create a new activity</span>\n\n' 'You can create something new, ' 'just select the type of project.')) new_project_label.set_use_markup(True) new_project_label.set_line_wrap(True) vbox.pack_start(new_project_label, expand=False, fill=True, padding=10) hbox_create = Gtk.HBox() hbox_create.pack_start(Gtk.Label(_('Select the type')), expand=False, fill=False, padding=10) project_type_combo = ComboBox() self._load_skeletons_combo(project_type_combo) hbox_create.pack_start(project_type_combo, expand=False, fill=False, padding=10) align = Gtk.Alignment.new(0.5, 0.5, 0, 0) align.add(hbox_create) vbox.pack_start(align, expand=False, fill=False, padding=10) hbox_name = Gtk.HBox() hbox_name.pack_start(Gtk.Label(_('Name the activity')), True, True, 0) activity_name_entry = Gtk.Entry() hbox_name.pack_start(activity_name_entry, expand=True, fill=True, padding=10) create_btn = Gtk.Button(_('Start')) create_btn.connect('clicked', self._create_new_activity, activity_name_entry, project_type_combo) hbox_name.pack_start(create_btn, expand=True, fill=True, padding=10) align = Gtk.Alignment.new(0.5, 0.5, 0, 0) align.add(hbox_name) vbox.pack_start(align, expand=False, fill=False, padding=10) self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color()) vbox_outer.pack_start(vbox, expand=True, fill=False, padding=0) self.add(vbox_outer) self.show_all()
def __init__(self): Gtk.Toolbar.__init__(self) voicebar = Gtk.Toolbar() self.activity = None 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] == 'default': break default = default + 1 # Play button Image play_img = Gtk.Image() play_img.show() play_img.set_from_icon_name('media-playback-start', Gtk.IconSize.LARGE_TOOLBAR) # Pause button Image pause_img = Gtk.Image() pause_img.show() pause_img.set_from_icon_name('media-playback-pause', Gtk.IconSize.LARGE_TOOLBAR) # Play button self.play_btn = ToggleToolButton('media-playback-start') self.play_btn.show() self.play_btn.connect('toggled', self.play_cb, [play_img, pause_img]) self.insert(self.play_btn, -1) self.play_btn.set_tooltip(_('Play / Pause')) self.voice_combo = ComboBox() self.voice_combo.connect('changed', self.voice_changed_cb) for voice in self.sorted_voices: self.voice_combo.append_item(voice, voice[0]) self.voice_combo.set_active(default) combotool = ToolComboBox(self.voice_combo) self.insert(combotool, -1) combotool.show() self.pitchadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0) pitchbar = Gtk.HScale() pitchbar.set_adjustment(self.pitchadj) pitchbar.set_draw_value(False) # pitchbar.set_update_policy(Gtk.UpdatePolicy.ALWAYS) pitchbar.set_size_request(150,15) pitchtool = Gtk.ToolItem() pitchtool.add(pitchbar) pitchtool.show() self.insert(pitchtool, -1) pitchbar.show() self.rateadj = Gtk.Adjustment(0, -100, 100, 1, 10, 0) ratebar = Gtk.HScale() ratebar.set_adjustment(self.rateadj) ratebar.set_draw_value(False) #ratebar.set_update_policy(Gtk.UpdatePolicy.ALWAYS) ratebar.set_size_request(150,15) ratetool = Gtk.ToolItem() ratetool.add(ratebar) ratetool.show() self.insert(ratetool, -1) ratebar.show()
def _create_controls(self): self._download_content_length = 0 self._download_content_type = None self.msg_label = Gtk.Label() self.list_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) # Catalogs treeview self.catalog_listview = Gtk.TreeView() self.catalog_listview.headers_clickble = True self.catalog_listview.hover_expand = True self.catalog_listview.rules_hint = True self._catalog_changed_id = self.catalog_listview.connect( 'row-activated', self.move_down_catalog) self.catalog_listview.set_activate_on_single_click(True) self.catalog_listview.set_enable_search(False) self.treemodel = Gtk.ListStore(str) self.treemodel.set_sort_column_id(0, Gtk.SortType.ASCENDING) self.catalog_listview.set_model(self.treemodel) renderer = Gtk.CellRendererText() renderer.set_property('wrap-mode', Pango.WrapMode.WORD) self.treecol = Gtk.TreeViewColumn(_('Catalogs'), renderer, text=0) self.treecol.set_property('clickable', True) self.treecol.connect('clicked', self.move_up_catalog) self.catalog_listview.append_column(self.treecol) self.bt_move_up_catalog = ButtonWithImage(_('Catalogs')) self.bt_move_up_catalog.hide_image() self.treecol.set_widget(self.bt_move_up_catalog) self.load_source_catalogs() self.tree_scroller = Gtk.ScrolledWindow(hadjustment=None, vadjustment=None) self.tree_scroller.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.tree_scroller.add(self.catalog_listview) self.list_box.pack_start(self.tree_scroller, expand=False, fill=False, padding=0) self.separa = Gtk.VSeparator() self.list_box.pack_start(self.separa, expand=False, fill=False, padding=0) # books listview self.listview = ListView(self._lang_code_handler) self.selection_cb_id = self.listview.connect('selection-changed', self.selection_cb) self.listview.set_enable_search(False) self.list_scroller = Gtk.ScrolledWindow(hadjustment=None, vadjustment=None) self.list_scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) vadjustment = self.list_scroller.get_vadjustment() vadjustment.connect('value-changed', self.__vadjustment_value_changed_cb) self.list_scroller.add(self.listview) self.list_box.pack_start(self.list_scroller, expand=True, fill=True, padding=0) self.scrolled = Gtk.ScrolledWindow() self.scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.scrolled.props.shadow_type = Gtk.ShadowType.NONE self.textview = Gtk.TextView() self.textview.set_editable(False) self.textview.set_cursor_visible(False) self.textview.set_wrap_mode(Gtk.WrapMode.WORD) self.textview.set_justification(Gtk.Justification.LEFT) self.textview.set_left_margin(20) self.textview.set_right_margin(20) self.scrolled.add(self.textview) self.list_box.show_all() self.separa.hide() self.tree_scroller.hide() vbox_download = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) hbox_format = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) format_label = Gtk.Label(label=_('Format:')) self.format_combo = ComboBox() for key in _MIMETYPES.keys(): self.format_combo.append_item(_MIMETYPES[key], key) self.format_combo.set_active(0) self.format_combo.props.sensitive = False self.__format_changed_cb_id = \ self.format_combo.connect('changed', self.__format_changed_cb) hbox_format.pack_start(format_label, False, False, 10) hbox_format.pack_start(self.format_combo, False, False, 10) vbox_download.pack_start(hbox_format, False, False, 10) self._download = Gtk.Button(_('Get Book')) self._download.set_image(Icon(icon_name='data-download')) self._download.props.sensitive = False self._download.connect('clicked', self.__get_book_cb) vbox_download.pack_start(self._download, False, False, 10) self.progressbox = Gtk.Box(spacing=20, orientation=Gtk.Orientation.HORIZONTAL) self.progressbar = Gtk.ProgressBar() self.progressbar.set_fraction(0.0) self.progressbox.pack_start(self.progressbar, expand=True, fill=True, padding=0) self.cancel_btn = Gtk.Button(stock=Gtk.STOCK_CANCEL) self.cancel_btn.set_image(Icon(icon_name='dialog-cancel')) self.cancel_btn.connect('clicked', self.__cancel_btn_clicked_cb) self.progressbox.pack_start(self.cancel_btn, expand=False, fill=False, padding=0) vbox_download.pack_start(self.progressbox, False, False, 10) bottom_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) if self.show_images: self.__image_downloader = None self.image = Gtk.Image() self.add_default_image() bottom_hbox.pack_start(self.image, False, False, 10) bottom_hbox.pack_start(self.scrolled, True, True, 10) bottom_hbox.pack_start(vbox_download, False, False, 10) bottom_hbox.show_all() vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(self.msg_label, False, False, 10) vbox.pack_start(self.list_box, True, True, 0) vbox.pack_start(bottom_hbox, False, False, 10) self.set_canvas(vbox) self.listview.show() vbox.show() self.list_scroller.show() self.progress_hide() self.show_message( _('Enter words from the Author or Title to begin search.')) self._books_toolbar.search_entry.grab_focus() if len(self.catalogs) > 0: self.bt_catalogs.set_active(True)
from gi.repository import Gtk from sugar3.graphics.combobox import ComboBox def _destroy_cb(widget, data=None): Gtk.main_quit() def __combo_changed_cb(widget, data=None): print 'combo-changed' w = Gtk.Window() w.connect("destroy", _destroy_cb) box = Gtk.VBox() w.add(box) combo = ComboBox() combo.append_item(0, 'one') combo.append_item(1, 'two', 'go-next') combo.append_item(2, 'three') combo.set_active(1) combo.connect('changed', __combo_changed_cb) box.pack_start(combo, False, False, 0) w.show_all() Gtk.main()