From 6555962bb655617f92030c960fb7e39dc3b100a3 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Fri, 15 Apr 2011 13:51:33 +0000 Subject: Start implementation de new toolbars I have not moved the record buttons yet. The general design of the UI is discussed in http://wiki.laptop.org/go/User:Godiard/Record/NewToolbar#Ideas_to_discuss_the_UI_for_Record --- diff --git a/record.py b/record.py index d957421..c19fb02 100644 --- a/record.py +++ b/record.py @@ -43,10 +43,17 @@ import constants from instance import Instance import utils from tray import HTray -from toolbarcombobox import ToolComboBox +from sugar.graphics.toolcombobox import ToolComboBox from mediaview import MediaView import hw +from sugar.graphics.toolbarbox import ToolbarBox +from sugar.graphics.toolbarbox import ToolbarButton +from sugar.graphics.toolbutton import ToolButton +from sugar.activity.widgets import StopButton +from sugar.activity.widgets import ActivityToolbarButton +from sugar.activity.widgets import CopyButton + logger = logging.getLogger('record.py') COLOR_BLACK = gdk.color_parse('#000000') COLOR_WHITE = gdk.color_parse('#ffffff') @@ -81,7 +88,7 @@ class Record(activity.Activity): self._media_view.realize_video() # Changing to the first toolbar kicks off the rest of the setup - self._toolbox.set_current_toolbar(1) + self.model.change_mode(constants.MODE_PHOTO) def read_file(self, path): self.model.read_file(path) @@ -111,31 +118,81 @@ class Record(activity.Activity): self.connect_after('key-press-event', self._key_pressed) self._active_toolbar_idx = 0 - self._toolbox = activity.ActivityToolbox(self) - self.set_toolbox(self._toolbox) - self._toolbar_modes = [None] - # remove Toolbox's hardcoded grey separator - self._toolbox.remove(self._toolbox._separator) + self._toolbar_box = ToolbarBox() + self.activity_button = ActivityToolbarButton(self) + self._toolbar_box.toolbar.insert(self.activity_button, 0) + self.set_toolbar_box(self._toolbar_box) + self._toolbar = self.get_toolbar_box().toolbar + + edit_button = ToolbarButton() + self._edit_toolbar = EditToolbar(self) + edit_button.set_page(self._edit_toolbar) + edit_button.props.icon_name = 'toolbar-edit' + edit_button.props.label = _('Edit') + self._toolbar.insert(edit_button, -1) + + view_button = ToolbarButton() + self._view_toolbar = ViewToolbar(self) + view_button.set_page(self._view_toolbar) + view_button.props.icon_name = 'toolbar-view' + view_button.props.label = _('View') + self._toolbar.insert(view_button, -1) + + self._toolbar.insert(gtk.SeparatorToolItem(), -1) + + self._toolbar_modes = [None] if self.model.get_has_camera(): self._photo_toolbar = PhotoToolbar() - self._toolbox.add_toolbar(_('Photo'), self._photo_toolbar) - self._toolbar_modes.append(constants.MODE_PHOTO) + photo_button = ToolbarButton() + photo_button.set_page(self._photo_toolbar) + photo_button.props.icon_name = 'camera-external' + photo_button.props.label = _('Photo') + photo_button.mode = constants.MODE_PHOTO + photo_button.connect('clicked', self.__mode_button_clicked) + # disable auto popup + photo_button.get_child().disconnect( + photo_button._palette_invoker._enter_hid) + self._toolbar.insert(photo_button, -1) self._video_toolbar = VideoToolbar() - self._toolbox.add_toolbar(_('Video'), self._video_toolbar) + video_button = ToolbarButton() + video_button.set_page(self._video_toolbar) + video_button.props.icon_name = 'media-video' + video_button.props.label = _('Video') + video_button.mode = constants.MODE_VIDEO + video_button.connect('clicked', self.__mode_button_clicked) + # disable auto popup + video_button.get_child().disconnect( + video_button._palette_invoker._enter_hid) + self._toolbar.insert(video_button, -1) + + self._toolbar_modes.append(constants.MODE_PHOTO) self._toolbar_modes.append(constants.MODE_VIDEO) else: self._photo_toolbar = None self._video_toolbar = None self._audio_toolbar = AudioToolbar() - self._toolbox.add_toolbar(_('Audio'), self._audio_toolbar) + audio_button = ToolbarButton() + audio_button.set_page(self._audio_toolbar) + audio_button.props.icon_name = 'media-audio' + audio_button.props.label = _('Audio') + audio_button.mode = constants.MODE_AUDIO + audio_button.connect('clicked', self.__mode_button_clicked) + # disable auto popup + audio_button.get_child().disconnect( + audio_button._palette_invoker._enter_hid) + self._toolbar.insert(audio_button, -1) self._toolbar_modes.append(constants.MODE_AUDIO) - self._toolbox.show_all() - self._toolbox.connect("current-toolbar-changed", self._toolbar_changed) + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + self._toolbar.insert(separator, -1) + self._toolbar.insert(StopButton(self), -1) + self.get_toolbar_box().show_all() main_box = gtk.VBox() self.set_canvas(main_box) @@ -330,27 +387,29 @@ class Record(activity.Activity): def _toggle_fullscreen(self): if not self._fullscreen: - self._toolbox.hide() + self._toolbar_box.hide() self._thumb_tray.hide() else: - self._toolbox.show() + self._toolbar_box.show() self._thumb_tray.show() self._fullscreen = not self._fullscreen self._media_view.set_fullscreen(self._fullscreen) - def _toolbar_changed(self, toolbox, num): - if num == 0: # Activity tab - return + def __mode_button_clicked(self, button): # Prevent mode/tab changing under certain conditions by immediately # changing back to the previously-selected toolbar + """ if self.model.ui_frozen(): self._toolbox.set_current_toolbar(self._active_toolbar_idx) return self._active_toolbar_idx = num self.model.change_mode(self._toolbar_modes[num]) + """ + if not self.model.ui_frozen(): + self.model.change_mode(button.mode) def _shutter_clicked(self, arg): self.model.do_shutter() @@ -816,19 +875,6 @@ class RecordToolbar(gtk.Toolbar): def __init__(self, icon_name, with_quality, with_timer, with_duration): super(RecordToolbar, self).__init__() - img = Icon(icon_name=icon_name) - color = sugar.profile.get_color() - img.set_property('fill-color', color.get_fill_color()) - img.set_property('stroke-color', color.get_stroke_color()) - toolitem = gtk.ToolItem() - toolitem.add(img) - self.insert(toolitem, -1) - - separator = gtk.SeparatorToolItem() - separator.set_draw(False) - separator.set_expand(True) - self.insert(separator, -1) - if with_quality: combo = gtk.combo_box_new_text() self.quality = ToolComboBox(combo=combo, label_text=_('Quality:')) @@ -847,6 +893,7 @@ class RecordToolbar(gtk.Toolbar): if with_duration: self._duration_combo = DurationCombo() self.insert(self._duration_combo, -1) + self.show_all() def get_timer(self): return self._timer_combo.get_value() @@ -941,3 +988,46 @@ class DurationCombo(ToolComboBox): def _minutes_string(x): return ngettext('%s minute', '%s minutes', x) % x +class EditToolbar(gtk.Toolbar): + + def __init__(self, record_activity): + gtk.Toolbar.__init__(self) + self._activity = record_activity + self.copy = CopyButton() + self.insert(self.copy, -1) + self.copy.show() + self.copy.connect('clicked', self.__copy_clicked) + + def __copy_clicked(self, button): + self._activity._copy_to_clipboard(self._activity._active_recd) + +class ViewToolbar(gtk.Toolbar): + + def __init__(self, record_activity): + gtk.Toolbar.__init__(self) + self._activity = record_activity + + full_screen_button = ToolButton('view-fullscreen') + full_screen_button.props.label = _('Fullscreen') + self.insert(full_screen_button, -1) + full_screen_button.connect('clicked', self.__fullscreen_clicked) + + tray_button = ToolButton('tray-hide') + tray_button.props.label = _('Hide tray') + tray_button.connect('clicked', self.__tray_clicked_cb) + self.insert(tray_button, -1) + + self.show_all() + + def __fullscreen_clicked(self, button): + self._activity._toggle_fullscreen() + + def __tray_clicked_cb(self, button): + if self._activity._thumb_tray.props.visible is False: + self._activity._thumb_tray.show() + button.set_icon('tray-hide') + button.set_tooltip(_('Hide Tray')) + else: + self._activity._thumb_tray.hide() + button.set_icon('tray-show') + button.set_tooltip(_('Show Tray')) diff --git a/toolbarcombobox.py b/toolbarcombobox.py deleted file mode 100644 index e455414..0000000 --- a/toolbarcombobox.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (C) 2007, Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -import gtk -import gobject - -from sugar.graphics.combobox import ComboBox -from sugar.graphics import style - -class ToolComboBox(gtk.ToolItem): - __gproperties__ = { - 'label-text' : (str, None, None, None, - gobject.PARAM_WRITABLE), - } - - def __init__(self, combo=None, **kwargs): - self.label = None - self._label_text = '' - - gobject.GObject.__init__(self, **kwargs) - - self.set_border_width(int(style.DEFAULT_PADDING*3.5)) - - hbox = gtk.HBox(False, style.DEFAULT_SPACING) - - self.label = gtk.Label(self._label_text) - hbox.pack_start(self.label, False) - self.label.show() - - if combo: - self.combo = combo - else: - self.combo = ComboBox() - - hbox.pack_start(self.combo) - self.combo.show() - - self.add(hbox) - hbox.show() - - def do_set_property(self, pspec, value): - if pspec.name == 'label-text': - self._label_text = value - if self.label: - self.label.set_text(self._label_text) -- cgit v0.9.1