def __init__(self, cb_object, group): RadioToolButton.__init__(self, group=group) self.props.palette_invoker = FrameWidgetInvoker(self) self._cb_object = cb_object self.owns_clipboard = False self.props.sensitive = False self.props.active = False self._notif_icon = None self._current_percent = None self._icon = Icon() client = gconf.client_get_default() color = XoColor(client.get_string('/desktop/sugar/user/color')) self._icon.props.xo_color = color self.set_icon_widget(self._icon) self._icon.show() cb_service = clipboard.get_instance() cb_service.connect('object-state-changed', self._object_state_changed_cb) cb_service.connect('object-selected', self._object_selected_cb) child = self.get_child() child.connect('drag_data_get', self._drag_data_get_cb) self.connect('notify::active', self._notify_active_cb)
def __init__(self, home_activity, group): RadioToolButton.__init__(self, group=group) self.set_palette_invoker(FrameWidgetInvoker(self)) self.palette_invoker.cache_palette = False self._home_activity = home_activity self._notify_launch_hid = None self._icon = PulsingIcon() self._icon.props.base_color = home_activity.get_icon_color() self._icon.props.pulse_color = \ XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(), style.COLOR_TOOLBAR_GREY.get_svg())) if home_activity.get_icon_path(): self._icon.props.file = home_activity.get_icon_path() else: self._icon.props.icon_name = 'image-missing' self.set_icon_widget(self._icon) self._icon.show() if home_activity.props.launch_status == shell.Activity.LAUNCHING: self._icon.props.pulsing = True self._notify_launch_hid = home_activity.connect( \ 'notify::launch-status', self.__notify_launch_status_cb) elif home_activity.props.launch_status == shell.Activity.LAUNCH_FAILED: self._on_failed_launch()
def __init__(self, abi, abi_signal, do_abi_cb, on_abi_cb=None, **kwargs): RadioToolButton.__init__(self, **kwargs) self._abi_handler = abi.connect(abi_signal, self.__abi_cb, abi_signal, on_abi_cb) self._toggled_handler = self.connect('toggled', self.__toggled_cb, abi, do_abi_cb)
def __init__(self, file_name, document_path, title): RadioToolButton.__init__(self) self._document_path = document_path self._title = title self._jobject = None self.props.tooltip = _('Instance Source') client = gconf.client_get_default() self._color = client.get_string('/desktop/sugar/user/color') icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, xo_color=XoColor(self._color)) self.set_icon_widget(icon) icon.show() menu_item = MenuItem(_('Keep')) icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU, xo_color=XoColor(self._color)) menu_item.set_image(icon) menu_item.connect('activate', self.__keep_in_journal_cb) self.props.palette.menu.append(menu_item) menu_item.show()
def __init__(self, file_name, document_path, title, bundle=False): RadioToolButton.__init__(self) self._document_path = document_path self._title = title self._jobject = None self.props.tooltip = _('Instance Source') client = gconf.client_get_default() self._color = client.get_string('/desktop/sugar/user/color') icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, xo_color=XoColor(self._color)) self.set_icon_widget(icon) icon.show() if bundle: menu_item = MenuItem(_('Duplicate')) icon = Icon(icon_name='edit-duplicate', icon_size=gtk.ICON_SIZE_MENU, xo_color=XoColor(self._color)) menu_item.connect('activate', self.__copy_to_home_cb) else: menu_item = MenuItem(_('Keep')) icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU, xo_color=XoColor(self._color)) menu_item.connect('activate', self.__keep_in_journal_cb) menu_item.set_image(icon) self.props.palette.menu.append(menu_item) menu_item.show()
def __init__(self, mount_point): RadioToolButton.__init__(self) self.mount_point = mount_point self.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('journal-object-id', 0, 0)], gtk.gdk.ACTION_COPY) self.connect('drag-data-received', self._drag_data_received_cb)
def get_tool_item(self): self.toolitem = RadioToolButton() if self.group: self.toolitem.set_group(self.group.toolitem) self.toolitem.set_named_icon( stock.icons[self._stock_id] if self._stock_id in stock.icons else self._stock_id) self.toolitem.set_active(self.default_value) self.toolitem.connect('toggled', self.toggled_cb) self.setup_tooltip() return self.toolitem
def _create_button(name): button = RadioToolButton() button.show() button.props.group = this.all button.set_label(name) button.connect('toggled', _query, len(this.path)) return button
def __init__(self, parent): self._main_toolbar = parent.get_toolbar_box().toolbar self._main_area = parent._main_area self._erase_button = parent.edit_toolbar.erase_button self._sw = parent._sw if HASTOOLBARBOX: target_toolbar = self._main_toolbar else: target_toolbar = self.parent.edit_toolbar self._mods = RadioToolButton(named_icon='select-mode') self._mods.set_tooltip(_('Select thoughts')) self._mods.set_group(parent.btn_group) self._mods.set_accelerator(_('<ctrl>e')) self._mods.connect('clicked', parent.mode_cb, MMapArea.MODE_NULL) target_toolbar.insert(self._mods, -1) self._link_button = RadioToolButton(named_icon='link') self._link_button.set_tooltip(_('Link/unlink two selected thoughts')) self._link_button.set_group(parent.btn_group) self._link_button.set_accelerator(_('<ctrl>l')) self._link_button.connect('clicked', self.__link_cb) target_toolbar.insert(self._link_button, -1) self.move_button = RadioToolButton(named_icon='move') self.move_button.set_tooltip(_('Move selected thoughs')) self.move_button.set_group(parent.btn_group) self.move_button.set_accelerator(_('<ctrl>m')) self.move_button.connect('clicked', self.__move_cb) target_toolbar.insert(self.move_button, -1) self.drag_button = RadioToolButton(named_icon='drag') self.drag_button.set_tooltip(_('Scroll the screen')) self.drag_button.set_group(parent.btn_group) self.drag_button.connect('clicked', self.__drag_cb) target_toolbar.insert(self.drag_button, -1) if HASTOOLBARBOX: self._separator_2 = gtk.SeparatorToolItem() self._separator_2.props.draw = False # self._separator_2.set_size_request(0, -1) self._separator_2.set_expand(True) self._separator_2.show() target_toolbar.insert(self._separator_2, -1) self._stop_button = StopButton(parent) target_toolbar.insert(self._stop_button, -1)
def __init__(self, view, name=None): """ Creates general toolbar where general map tools can be enabled. @param name: The name of the toolbar. """ gtk.Toolbar.__init__(self) self.set_property('can-focus', False) self.view = view if name: self.name = name self._logger = logging.getLogger(name) else: self._logger = logging.getLogger('geo.GeoToolbar') self._logger.setLevel(constants.LOG_LEVEL) # remove predefined key bindings gtk.binding_entry_remove(self, gtk.keysyms.Left, 0) gtk.binding_entry_remove(self, gtk.keysyms.Right, 0) gtk.binding_entry_remove(self, gtk.keysyms.Up, 0) gtk.binding_entry_remove(self, gtk.keysyms.Down, 0) gtk.binding_entry_remove(self, gtk.keysyms.plus, 0) gtk.binding_entry_remove(self, gtk.keysyms.minus, 0) self.callbacks = {} self.connect('key-press-event', self.key_pressed_cb, self.callbacks) self.show_no_positions = RadioToolButton() icon_name = os.path.join(constants.ICON_PATH, "show-no-positions.svg") icon = utils.load_svg_image(icon_name, None, None, BTN_ICON_SIZE) img = gtk.image_new_from_pixbuf(icon) self.show_no_positions.set_icon_widget(img) self.show_no_positions.set_tooltip(_('Show no players.'))
def _page_new(self, tag_type): def page_cb(widget, view_index, view): lists.props.page = view_index self._view_by_page[tag_type].freeze() self._view_by_page[tag_type] = view view.update() model.this['tag_sidebar'][`tag_type`]['cloud_active'] = \ view_index == 1 vbox = gtk.VBox() lists = gtk.Notebook() lists.props.show_border = False lists.props.show_tabs = False vbox.pack_start(lists) tree = Tree(tag_type) tree.props.hover_selection = True scrolled = gtk.ScrolledWindow() scrolled.set_shadow_type(gtk.SHADOW_OUT) scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled.add(tree) lists.append_page(scrolled) self._view_by_page[tag_type] = tree cloud = Cloud(tag_type) scrolled = gtk.ScrolledWindow() scrolled.set_shadow_type(gtk.SHADOW_OUT) scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled.add(cloud) lists.append_page(scrolled) toolbar = gtk.Toolbar() toolbar.modify_bg(gtk.STATE_NORMAL, style.COLOR_PANEL_GREY.get_gdk_color()) vbox.pack_end(toolbar, False) tree_button = RadioToolButton(named_icon='view-list', tooltip=_('Tree view'), group=None) tree_button.connect('toggled', page_cb, 0, tree) toolbar.insert(tree_button, -1) cloud_button = RadioToolButton(named_icon='view-cloud', group=tree_button, palette=CloudPalette( _('Cloud view'), tag_type, cloud)) cloud_button.connect('toggled', page_cb, 1, cloud) toolbar.insert(cloud_button, -1) vbox.show_all() if model.this['tag_sidebar'][ ` tag_type `]['cloud_active']: cloud_button.props.active = True
def __init__(self, parent, name, icon_name='', callback=None, tooltip=None, group=None): RadioToolButton.__init__(self) if icon_name == '': icon_name = 'computer-xo' icon = Icon(icon_name=icon_name, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) self.set_icon_widget(icon) icon.show() if tooltip is not None: self.set_tooltip(tooltip) self.props.sensitive = True self.connect('clicked', callback) self.set_group(group) self.show() parent.button_dict[name] = self parent.callback_dict[name] = callback
def __init__(self, activity, **kwargs): palette = RadioPalette() self.private = RadioToolButton(icon_name='zoom-home') palette.append(self.private, _('Private')) self.neighborhood = RadioToolButton(icon_name='zoom-neighborhood', group=self.private) self._neighborhood_handle = self.neighborhood.connect( 'clicked', self.__neighborhood_clicked_cb, activity) palette.append(self.neighborhood, _('My Neighborhood')) activity.connect('shared', self.__update_share_cb) activity.connect('joined', self.__update_share_cb) RadioMenuButton.__init__(self, **kwargs) self.props.palette = palette if activity.props.max_participants == 1: self.props.sensitive = False
class ShareButton(RadioMenuButton): def __init__(self, activity, **kwargs): palette = RadioPalette() self.private = RadioToolButton( icon_name='zoom-home') palette.append(self.private, _('Private')) self.neighborhood = RadioToolButton( icon_name='zoom-neighborhood', group=self.private) self._neighborhood_handle = self.neighborhood.connect( 'clicked', self.__neighborhood_clicked_cb, activity) palette.append(self.neighborhood, _('My Neighborhood')) activity.connect('shared', self.__update_share_cb) activity.connect('joined', self.__update_share_cb) RadioMenuButton.__init__(self, **kwargs) self.props.palette = palette if activity.max_participants == 1: self.props.sensitive = False def __neighborhood_clicked_cb(self, button, activity): activity.share() def __update_share_cb(self, activity): self.neighborhood.handler_block(self._neighborhood_handle) try: if activity.shared_activity is not None and \ not activity.shared_activity.props.private: self.private.props.sensitive = False self.neighborhood.props.sensitive = False self.neighborhood.props.active = True else: self.private.props.sensitive = True self.neighborhood.props.sensitive = True self.private.props.active = True finally: self.neighborhood.handler_unblock(self._neighborhood_handle)
def __init__(self): gtk.Toolbar.__init__(self) sidebar = ToggleToolButton(named_icon='sidebar', palette=TagPalette()) sidebar.connect('toggled', self._tags_cb) sidebar.props.active = this.config['sidebar_visible'] self.insert(sidebar, -1) separator = gtk.SeparatorToolItem() self.insert(separator, -1) objects = [None] * 3 objects[0] = RadioToolButton(named_icon='view-list', group=None, palette=ObjectPalette( _('Compact object list'), this.objects_compat)) objects[0].connect('toggled', self._objects_cb, 0, this.objects_compat) self.insert(objects[0], -1) objects[1] = RadioToolButton(named_icon='view-thumbs', tooltip=_('Thumbs object list'), group=objects[0]) objects[1].connect('toggled', self._objects_cb, 1, this.object_thumbs) self.insert(objects[1], -1) objects[this.config['objects_view']].props.active = True separator = gtk.SeparatorToolItem() separator.set_draw(False) self.insert(separator, -1) search = SearchEntry() search.connect('query-changed', self._search_changed_cb) search_toolitem = gtk.ToolItem() search_toolitem.add(search) search_toolitem.set_expand(True) self.insert(search_toolitem, -1) self.show_all()
def __init__(self): gtk.Toolbar.__init__(self) self._query = None self._autosearch_timer = None self._add_separator() tool_item = gtk.ToolItem() self.insert(tool_item, -1) tool_item.show() self.search_entry = iconentry.IconEntry() self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY, 'system-search') self.search_entry.add_clear_button() self.search_entry.set_width_chars(25) self.search_entry.connect('activate', self.__entry_activated_cb) self.search_entry.connect('changed', self.__entry_changed_cb) tool_item.add(self.search_entry) self.search_entry.show() self._add_separator(expand=True) favorites_button = FavoritesButton() favorites_button.connect('toggled', self.__view_button_toggled_cb, _FAVORITES_VIEW) self.insert(favorites_button, -1) favorites_button.show() self._list_button = RadioToolButton(named_icon='view-list') self._list_button.props.group = favorites_button self._list_button.props.tooltip = _('List view') self._list_button.props.accelerator = _('<Ctrl>2') self._list_button.connect('toggled', self.__view_button_toggled_cb, _LIST_VIEW) self.insert(self._list_button, -1) self._list_button.show() self._add_separator()
def add_level_button(icon_name, tooltip, signal_name): if levels: button = RadioToolButton(named_icon=icon_name, group=levels[0]) else: button = RadioToolButton(named_icon=icon_name) levels.append(button) toolbar.add(button) def callback(source): if source.get_active(): self.emit(signal_name) button.connect('clicked', callback) button.set_tooltip(tooltip)
class ShareButton(RadioMenuButton): def __init__(self, activity, **kwargs): palette = RadioPalette() self.private = RadioToolButton( icon_name='zoom-home') palette.append(self.private, _('Private')) self.neighborhood = RadioToolButton( icon_name='zoom-neighborhood', group=self.private) self._neighborhood_handle = self.neighborhood.connect( 'clicked', self.__neighborhood_clicked_cb, activity) palette.append(self.neighborhood, _('My Neighborhood')) activity.connect('shared', self.__update_share_cb) activity.connect('joined', self.__update_share_cb) RadioMenuButton.__init__(self, **kwargs) self.props.palette = palette if activity.props.max_participants == 1: self.props.sensitive = False def __neighborhood_clicked_cb(self, button, activity): activity.share() def __update_share_cb(self, activity): self.neighborhood.handler_block(self._neighborhood_handle) try: if activity.get_shared(): self.private.props.sensitive = False self.neighborhood.props.sensitive = False self.neighborhood.props.active = True else: self.private.props.sensitive = True self.neighborhood.props.sensitive = True self.private.props.active = True finally: self.neighborhood.handler_unblock(self._neighborhood_handle)
def __init__(self, parent): self._main_toolbar = parent.get_toolbar_box().toolbar self._main_area = parent._main_area self._erase_button = parent.edit_toolbar.erase_button self._sw = parent._sw if HASTOOLBARBOX: target_toolbar = self._main_toolbar else: target_toolbar = self.parent.edit_toolbar self._mods = RadioToolButton(named_icon='select-mode') self._mods.set_tooltip(_('Select thoughts')) self._mods.set_group(parent.btn_group) self._mods.set_accelerator(_('<ctrl>e')) self._mods.connect('clicked', parent.mode_cb, MMapArea.MODE_NULL) target_toolbar.insert(self._mods, -1) self._link_button = RadioToolButton(named_icon='link') self._link_button.set_tooltip(_('Link/unlink two selected thoughts')) self._link_button.set_group(parent.btn_group) self._link_button.set_accelerator(_('<ctrl>l')) self._link_button.connect('clicked', self.__link_cb) target_toolbar.insert(self._link_button, -1) self.move_button = RadioToolButton(named_icon='move') self.move_button.set_tooltip(_('Move selected thoughs')) self.move_button.set_group(parent.btn_group) self.move_button.set_accelerator(_('<ctrl>m')) self.move_button.connect('clicked', self.__move_cb) target_toolbar.insert(self.move_button, -1) self.drag_button = RadioToolButton(named_icon='drag') self.drag_button.set_tooltip(_('Scroll the screen')) self.drag_button.set_group(parent.btn_group) self.drag_button.connect('clicked', self.__drag_cb) target_toolbar.insert(self.drag_button, -1) if HASTOOLBARBOX: self._separator_2 = gtk.SeparatorToolItem() self._separator_2.props.draw = False #self._separator_2.set_size_request(0, -1) self._separator_2.set_expand(True) self._separator_2.show() target_toolbar.insert(self._separator_2, -1) self._stop_button = StopButton(parent) target_toolbar.insert(self._stop_button, -1)
def enable_show_own_position(self, view): """ Shows the only the own position on the map. """ self.radio_show_own_pos_btn = RadioToolButton(group=self.show_no_positions) (fill, stroke) = ('#ffffff', '#000000') # black/white explicit buddy_icon = utils.get_xo_icon(stroke, fill, BTN_ICON_SIZE) img = gtk.image_new_from_pixbuf(buddy_icon) self.radio_show_own_pos_btn.set_icon_widget(img) self.radio_show_own_pos_btn.set_tooltip(_('Show only me.')) self.radio_show_own_pos_btn.connect('clicked', view.radio_show_own_position_cb) self.insert(self.radio_show_own_pos_btn, -1) self.radio_show_own_pos_btn.show_all() if self.radio_show_all_pos_btn: self.show_no_positions.connect("clicked", view.radio_show_no_positions_cb) self.show_no_positions.show_all() self.insert(self.show_no_positions, -1)
def _add_button(self, icon_name, label, accelerator, zoom_level): if self.get_children(): group = self.get_children()[0] else: group = None button = RadioToolButton(named_icon=icon_name, group=group, accelerator=accelerator) button.connect('clicked', self.__level_clicked_cb, zoom_level) self.add(button) button.show() palette = Palette(glib.markup_escape_text(label)) palette.props.invoker = FrameWidgetInvoker(button) palette.set_group_id('frame') button.set_palette(palette) return button
def enable_show_all_positions(self, view): """ Shows the position of all players participating the game. """ self.radio_show_all_pos_btn = RadioToolButton(group=self.show_no_positions) icon_name = os.path.join(constants.ICON_PATH , 'show-all-players.svg') icon = utils.load_svg_image(icon_name, None, None, BTN_ICON_SIZE) img = gtk.image_new_from_pixbuf(icon) self.radio_show_all_pos_btn.set_icon_widget(img) self.radio_show_all_pos_btn.set_tooltip(_('Show all players.')) self.radio_show_all_pos_btn.connect('clicked', view.radio_show_all_position_cb) self.insert(self.radio_show_all_pos_btn, -1) self.radio_show_all_pos_btn.show_all() if self.radio_show_own_pos_btn: self.show_no_positions.connect("clicked", view.radio_show_no_positions_cb) self.show_no_positions.show_all() self.insert(self.show_no_positions, -1) self.radio_show_all_pos_btn.set_active(True)
def __init__(self, title, bundle_path, document_path): gtk.Toolbar.__init__(self) self._add_separator() activity_bundle = ActivityBundle(bundle_path) file_name = activity_bundle.get_icon() if document_path is not None and os.path.exists(document_path): document_button = DocumentButton(file_name, document_path, title) document_button.connect('toggled', self.__button_toggled_cb, document_path) self.insert(document_button, -1) document_button.show() self._add_separator() if bundle_path is not None and os.path.exists(bundle_path): activity_button = RadioToolButton() icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, fill_color=style.COLOR_TRANSPARENT.get_svg(), stroke_color=style.COLOR_WHITE.get_svg()) activity_button.set_icon_widget(icon) icon.show() if document_path is not None: activity_button.props.group = document_button activity_button.props.tooltip = _('Activity Bundle Source') activity_button.connect('toggled', self.__button_toggled_cb, bundle_path) self.insert(activity_button, -1) activity_button.show() self._add_separator() text = _('View source: %r') % title label = gtk.Label() label.set_markup('<b>%s</b>' % text) label.set_alignment(0, 0.5) self._add_widget(label) self._add_separator(True) stop = ToolButton(icon_name='dialog-cancel') stop.set_tooltip(_('Close')) stop.connect('clicked', self.__stop_clicked_cb) stop.show() self.insert(stop, -1) stop.show()
class RadioItem(ToggleItem): def __init__(self, group, default_value=True, stock_id=None, important=False): ToggleItem.__init__(self, default_value, stock_id, important) self.group = group def get_tool_item(self): self.toolitem = RadioToolButton() if self.group: self.toolitem.set_group(self.group.toolitem) self.toolitem.set_named_icon( stock.icons[self._stock_id] if self._stock_id in stock.icons else self._stock_id) self.toolitem.set_active(self.default_value) self.toolitem.connect('toggled', self.toggled_cb) self.setup_tooltip() return self.toolitem
def _add_button(self, icon_name, label, accelerator, zoom_level): if self.get_children(): group = self.get_children()[0] else: group = None button = RadioToolButton(named_icon=icon_name, group=group, accelerator=accelerator) button.connect("clicked", self.__level_clicked_cb, zoom_level) self.add(button) button.show() palette = Palette(glib.markup_escape_text(label)) palette.props.invoker = FrameWidgetInvoker(button) palette.set_group_id("frame") button.set_palette(palette) return button
def add_pathway_button(self): # get the hometoolbar toolbar = self.home_box._toolbar #add a new button, with a different icon toolbar._pathway_button = RadioToolButton( named_icon='media-playback-start') #TODO this icon fails on soas toolbar._pathway_button.props.group = toolbar._list_button toolbar._pathway_button.props.tooltip = _('Pathway view') toolbar._pathway_button.props.accelerator = _('<Ctrl>3') # toolbar._pathway_button.connect('toggled', toolbar.__view_button_toggled_cb, # _LIST_VIEW) toolbar._pathway_button.connect('toggled', self._show_pathway_button_cb, None) toolbar.insert(toolbar._pathway_button, toolbar.get_item_index(toolbar._list_button) + 1) toolbar._pathway_button.show()
def __init__(self, activity, **kwargs): palette = RadioPalette() self.private = RadioToolButton( icon_name='zoom-home') palette.append(self.private, _('Private')) self.neighborhood = RadioToolButton( icon_name='zoom-neighborhood', group=self.private) self._neighborhood_handle = self.neighborhood.connect( 'clicked', self.__neighborhood_clicked_cb, activity) palette.append(self.neighborhood, _('My Neighborhood')) activity.connect('shared', self.__update_share_cb) activity.connect('joined', self.__update_share_cb) RadioMenuButton.__init__(self, **kwargs) self.props.palette = palette if activity.max_participants == 1: self.props.sensitive = False
def __init__(self): RadioToolButton.__init__(self) self.props.tooltip = _('Favorites view') self.props.accelerator = _('<Ctrl>1') self.props.group = None favorites_settings = favoritesview.get_settings() self._layout = favorites_settings.layout self._update_icon() # someday, this will be a gtk.Table() layouts_grid = gtk.HBox() layout_item = None for layoutid, layoutclass in sorted(favoritesview.LAYOUT_MAP.items()): layout_item = RadioToolButton(icon_name=layoutclass.icon_name, group=layout_item, active=False) if layoutid == self._layout: layout_item.set_active(True) layouts_grid.pack_start(layout_item, fill=False) layout_item.connect('toggled', self.__layout_activate_cb, layoutid) layouts_grid.show_all() self.props.palette.set_content(layouts_grid)
def build_toolbar(self): # make a toolbox toolbox = activity.ActivityToolbox(self) # modify the Activity tab activity_toolbar = toolbox.get_activity_toolbar() activity_toolbar.share.props.visible = False self.blocklist = [] # make a 'create' toolbar create_toolbar = gtk.Toolbar() # make + add the component buttons self.radioList = {} for c in tools.allTools: button = RadioToolButton(named_icon=c.icon) button.set_tooltip(_(c.toolTip)) button.connect('clicked',self.radioClicked) create_toolbar.insert(button,-1) button.show() self.radioList[button] = c.name # add the toolbars to the toolbox toolbox.add_toolbar("Create",create_toolbar) create_toolbar.show() # add a ILF specific toolbar which gives feedback about problems #ilf_toolbar = gtk.Toolbar() #self.ilf_label = gtk.Label("test") #ilf_toolbar.insert_widget(self.ilf_label, "testlabel", None, -1) #self.ilf_label.show() #toolbox.add_toolbar("ILF", ilf_toolbar) #ilf_toolbar.show() toolbox.show() self.set_toolbox(toolbox) toolbox.set_current_toolbar(1) return activity_toolbar
def __init__(self): RadioToolButton.__init__(self) self.props.tooltip = _('Pathway view') self.props.accelerator = _('<Ctrl>3') self.props.group = None favorites_settings = favoritesview.get_settings() self._layout = favorites_settings.layout self._update_icon() # someday, this will be a gtk.Table() layouts_grid = gtk.HBox() layout_item = None for layoutid, layoutclass in sorted(favoritesview.LAYOUT_MAP.items()): layout_item = RadioToolButton(icon_name=layoutclass.icon_name, group=layout_item, active=False) if layoutid == self._layout: layout_item.set_active(True) layouts_grid.pack_start(layout_item, fill=False) layout_item.connect('toggled', self.__layout_activate_cb, layoutid) layouts_grid.show_all() self.props.palette.set_content(layouts_grid)
text_view = gtk.TextView() box.pack_start(text_view) def echo(button, label): if not button.props.active: return text_view.props.buffer.props.text += "\n" + label # RadioMenuButton palette = RadioPalette() group = RadioToolButton(icon_name="document-open") group.connect("clicked", lambda button: echo(button, "document-open")) palette.append(group, "menu.document-open") button = RadioToolButton(icon_name="document-save", group=group) button.connect("clicked", lambda button: echo(button, "document-save")) palette.append(button, "menu.document-save") button = RadioToolButton(icon_name="document-send", group=group) button.connect("clicked", lambda button: echo(button, "document-send")) palette.append(button, "menu.document-send") button = RadioMenuButton(palette=palette) toolbar.insert(button, -1) # RadioToolsButton
class Activity(sugar.activity.activity.Activity): def __init__(self, handle): super(Activity, self).__init__(handle) self.paused = False watch = gtk.gdk.Cursor(gtk.gdk.WATCH) self.window.set_cursor(watch) self.p = gtk.VPaned() self.p.connect("notify::position", self.redraw) self.box = gtk.Notebook() self.p.pack2(self.box) self.p.show() self.box.set_show_tabs(False) self.splash = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file("images/splash-colgadito.png") screen = self.window.get_screen() width, height = screen.get_width(), screen.get_height() - style.GRID_CELL_SIZE pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR) self.splash.set_from_pixbuf(pixbuf) self.splash.show() eb = gtk.EventBox() eb.add(self.splash) eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white")) eb.show() self.box.append_page(eb, gtk.Label("Inicio")) self._pygamecanvas = sugargame2.canvas.PygameCanvas(self) self._pygamecanvas.set_flags(gtk.EXPAND) self._pygamecanvas.set_flags(gtk.FILL) self.connect("visibility-notify-event", self.redraw) self._pygamecanvas.set_events(gtk.gdk.BUTTON_PRESS_MASK) self._pygamecanvas.connect("button-press-event", self._pygamecanvas.grab_focus) self.box.append_page(self._pygamecanvas, gtk.Label("Juego")) self.box.show() self.set_canvas(self.p) gobject.timeout_add(300, self.pump) gobject.timeout_add(2000, self.init_interpreter) #gobject.timeout_add(1000, self.build_editor) gobject.timeout_add(1500, self.check_modified) self.build_toolbar() self.credits = None self.editor = None self._pygamecanvas.run_pygame(self.run_game) def redraw(self, widget=None, b=None, c=None): scene = spyral.director.get_scene() if scene: scene.redraw() def alert(self, title=None, text=None, delay=5): alert = NotifyAlert(delay) alert.props.title = title alert.props.msg = text print text self.add_alert(alert) alert.connect('response', self._alert_ok) alert.show() def _alert_ok(self, alert, *args): self.remove_alert(alert) def check_modified(self): if self.box.current_page()==2: if not self.save_button.get_sensitive(): if self.editor.modificado(): self.save_button.set_sensitive(True) return False return True def pump(self): # Esto es necesario porque sino pygame acumula demasiados eventos. pygame.event.pump() def focus_interpreter(self, widget, event): self._interpreter.text.grab_focus() return True def init_interpreter(self): # diferido unos segundos para evitar ver errores superfluos al iniciar self._interpreter = GTKInterpreterConsole(self.redraw) self._interpreter.text.connect('button-press-event', self.focus_interpreter) self.p.pack1(self._interpreter) return False def open_file(self, widget, path): if path: if not os.path.isdir(path): self.editor.open_file(widget, path) def save_file(self, widget): if self.editor.modificado(): self.save_button.set_sensitive(False) self.editor.save_file() filename = self.editor.current_file() self.alert(filename, "Archivo guardado.") gobject.timeout_add(1500, self.check_modified) def build_editor(self): dir_real = os.getcwd() f = os.path.realpath(JUEGO.__file__) f = "." + f.replace(dir_real ,"") # todo esto para obtener una ruta relativa f = f.rstrip("c") # en caso que sea .pyc compilado self.h = gtk.HPaned() self.tree = FileViewer(".", os.path.basename(f)) self.tree.connect("file-selected", self.open_file) self.tree.show() self.h.pack1(self.tree) self.box.append_page(self.h, gtk.Label("Editor")) if False: #os.path.isfile("/usr/bin/gvim"): # Si podemos, lo hacemos self.socket = gtk.Socket() self.socket.show() self.h.pack2(self.socket) sock_id = str(self.socket.get_id()) self.editor = VimSourceView(sock_id) if not self.editor.bufInfo.bufferList: f = JUEGO.__file__ if f.endswith("pyc"): f = f[:-1] self.open_file(None, f) else: self.editor = SourceView() scroller = gtk.ScrolledWindow() scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroller.add(self.editor) scroller.show() self.h.pack2(scroller) self.editor.show() self.h.show() self.open_file(None, f) def build_toolbar(self): toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.show() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, -1) activity_button.show() tool_group = None self.game_button = RadioToolButton() self.game_button.props.icon_name = 'gamecanvas' self.game_button.set_tooltip(_('Juego')) self.game_button.accelerator = "<Ctrl>1" self.game_button.props.group = tool_group self.game_button.connect('clicked', self.show_game) toolbar_box.toolbar.insert(self.game_button, -1) self.game_button.show() tool_group = self.game_button button = RadioToolButton() button.props.icon_name = 'view-source' button.set_tooltip(_('Editor')) button.accelerator = "<Ctrl>2" button.props.group = tool_group button.connect('clicked', self.show_editor) toolbar_box.toolbar.insert(button, -1) button.show() self.save_button = ToolButton('dialog-ok') self.save_button.set_tooltip(_('Guardar')) self.save_button.accelerator = "<Ctrl>s" self.save_button.connect('clicked', self.save_file) self.save_button.set_sensitive(False) toolbar_box.toolbar.insert(self.save_button, -1) self.save_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() button = ToolButton('system-restart') button.set_tooltip(_('Reiniciar juego')) button.accelerator = "<Alt><Shift>r" button.connect('clicked', self.restart_game) toolbar_box.toolbar.insert(button, -1) button.show() self.editor_button = ToolButton('sources') self.editor_button.set_tooltip(_('Consola')) self.editor_button.accelerator = "<Ctrl>grave" self.editor_button.connect('clicked', self.toggle_console) toolbar_box.toolbar.insert(self.editor_button, -1) self.editor_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() button = helpbutton.HelpButton(self) toolbar_box.toolbar.insert(button, -1) button.show() button = ToolButton() button.props.icon_name = 'activity-about' button.set_tooltip(_('Acerca de')) button.accelerator = "<Ctrl>i" button.connect('clicked', self.run_credits) toolbar_box.toolbar.insert(button, -1) button.show() # Blank space (separator) and Stop button at the end: 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 run_game(self): spyral.director.init((0,0), fullscreen=False, max_fps=30) self.game = JUEGO.Game(activity=self) self.box.connect("switch-page", self.redraw) spyral.director.push(self.game) self.start() def run_credits(self, widget): if not (spyral.director.get_scene()==self.credits): self.credits = game.credits.Creditos(self.game.size) spyral.director.push(self.credits) def start(self): #try: spyral.director.run(sugar = True) #except AttributeError as detail: # detail2 = traceback.format_exc() # self.box.set_page(0) # self.alert( detail2, "Spyral se ha detenido abruptamente.", 60) def show_game(self, widget): self.box.set_page(1) self.redraw() def show_editor(self, widget): if not self.editor: self.build_editor() self.box.set_page(2) self.redraw() def restart_game(self, widget): global JUEGO import objetos try: objetos.reset() except AttributeError: pass self.show_game(None) watch = gtk.gdk.Cursor(gtk.gdk.WATCH) self.window.set_cursor(watch) JUEGO = reload(JUEGO) self.game = JUEGO.Game(activity=self) spyral.director.replace(self.game) self.start() def game_ready(self, widget = None): self.game_button.set_active(True) self.box.set_page(1) self._pygamecanvas.grab_focus() self.window.set_cursor(None) def read_file(self, file_path): pass def write_file(self, file_path): pass def can_close(self): if self.editor: self.editor.close() self.box.set_page(0) try: spyral.director.quit() except spyral.exceptions.GameEndException: pass finally: return True def toggle_console(self, e): if self._interpreter.props.visible: self._interpreter.hide() self._pygamecanvas.grab_focus() else: self.p.set_position(160) self._interpreter.show() self._interpreter.text.grab_focus() self.redraw() def animate_console(self): easing = spyral.easing.Linear(0,160) self.p.set_position(0)
class Activity(sugar.activity.activity.Activity): def __init__(self, handle): super(Activity, self).__init__(handle) self.build_toolbar() self.build_editor() self.p = gtk.VPaned() self.set_canvas(self.p) self.p.pack2(self.h) self.console = gtk.Notebook() self.init_interpreter() self.console.append_page(self.interpreter) self.p.pack1(self.console) self.fugit = Fugit(".") self.console.append_page(self.fugit.widget) self.show_all() def alert(self, title=None, text=None, delay=5): alert = NotifyAlert(delay) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_ok) alert.show() def _alert_ok(self, alert, *args): self.remove_alert(alert) def init_interpreter(self): frame = self.get_frame() self.interpreter = GTKInterpreterConsole(frame) self.interpreter.text.connect('button-press-event', self.focus_interpreter) return False def focus_interpreter(self, widget, event): self.interpreter.text.grab_focus() return True def get_frame(self): # esto es necesario para que la consola funcione try: raise None except: frame = sys.exc_info()[2].tb_frame return frame def open_file(self, widget, path): if path: if not os.path.isdir(path): self.editor.open_file(widget, path) def save_file(self, widget): if self.editor.modificado(): self.editor.save_file() filename = self.editor.current_file() self.alert(filename, "Archivo guardado.") def build_editor(self): self.h = gtk.HPaned() self.tree = FileViewer(".") self.tree.connect("file-selected", self.open_file) self.tree.show() self.h.pack1(self.tree) self.editor = SourceView() scroller = gtk.ScrolledWindow() scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroller.add(self.editor) self.h.pack2(scroller) self.h.show_all() def build_reader(self): self.reader = webkit.WebView() curdir = os.getcwd() self.reader.load_uri("file://%s/docs/index.html" % curdir) self.box.append_page(self.reader, gtk.Label("Lector")) self.reader.show() def build_toolbar(self): toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.show() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, -1) activity_button.show() tool_group = None self.game_button = RadioToolButton() self.game_button.props.icon_name = 'gamecanvas' self.game_button.set_tooltip(_('Juego')) self.game_button.accelerator = "<Ctrl>1" self.game_button.props.group = tool_group #self.game_button.connect('clicked', self.show_game) toolbar_box.toolbar.insert(self.game_button, -1) self.game_button.show() tool_group = self.game_button button = RadioToolButton() button.props.icon_name = 'view-source' button.set_tooltip(_('Editor')) button.accelerator = "<Ctrl>2" button.props.group = tool_group #button.connect('clicked', self.show_editor) toolbar_box.toolbar.insert(button, -1) button.show() self.save_button = ToolButton('dialog-ok') self.save_button.set_tooltip(_('Guardar')) self.save_button.accelerator = "<Ctrl>s" self.save_button.connect('clicked', self.save_file) toolbar_box.toolbar.insert(self.save_button, -1) self.save_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() self.editor_button = ToolButton('sources') self.editor_button.set_tooltip(_('Consola')) self.editor_button.accelerator = "<Ctrl>grave" self.editor_button.connect('clicked', self.toggle_console) toolbar_box.toolbar.insert(self.editor_button, -1) self.editor_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() button = helpbutton.HelpButton(self) toolbar_box.toolbar.insert(button, -1) button.show() # Blank space (separator) and Stop button at the end: 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 read_file(self, file_path): pass def write_file(self, file_path): pass def can_close(self): if self.editor: self.editor.close() return True def toggle_console(self, e): if self.console.props.visible: self.console.hide() else: self.p.set_position(160) self.console.show() self.console.text.grab_focus()
def __init__(self, owner): gtk.Toolbar.__init__(self) self.owner = owner self._insert_separator(True) self.desktop = [] btn = RadioToolButton(group=None) btn.set_named_icon('jam-preset1') btn.connect('toggled', self.setDesktop, 0) btn.set_tooltip(_('Desktop 1')) self.insert(btn, -1) self.desktop.append(btn) for i in range(2, 11): btn = RadioToolButton(group=self.desktop[0]) btn.set_named_icon('jam-preset%d' % i) btn.connect('toggled', self.setDesktop, i - 1) btn.set_tooltip(_('Desktop %d' % i)) self.insert(btn, -1) self.desktop.append(btn) self._insert_separator(True) self.show_all()
def build_toolbar(self): toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.show() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, -1) activity_button.show() tool_group = None self.game_button = RadioToolButton() self.game_button.props.icon_name = 'gamecanvas' self.game_button.set_tooltip(_('Juego')) self.game_button.accelerator = "<Ctrl>1" self.game_button.props.group = tool_group self.game_button.connect('clicked', self.show_game) toolbar_box.toolbar.insert(self.game_button, -1) self.game_button.show() tool_group = self.game_button button = RadioToolButton() button.props.icon_name = 'view-source' button.set_tooltip(_('Editor')) button.accelerator = "<Ctrl>2" button.props.group = tool_group button.connect('clicked', self.show_editor) toolbar_box.toolbar.insert(button, -1) button.show() self.save_button = ToolButton('dialog-ok') self.save_button.set_tooltip(_('Guardar')) self.save_button.accelerator = "<Ctrl>s" self.save_button.connect('clicked', self.save_file) self.save_button.set_sensitive(False) toolbar_box.toolbar.insert(self.save_button, -1) self.save_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() button = ToolButton('system-restart') button.set_tooltip(_('Reiniciar juego')) button.accelerator = "<Alt><Shift>r" button.connect('clicked', self.restart_game) toolbar_box.toolbar.insert(button, -1) button.show() self.editor_button = ToolButton('sources') self.editor_button.set_tooltip(_('Consola')) self.editor_button.accelerator = "<Ctrl>grave" self.editor_button.connect('clicked', self.toggle_console) toolbar_box.toolbar.insert(self.editor_button, -1) self.editor_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() button = helpbutton.HelpButton(self) toolbar_box.toolbar.insert(button, -1) button.show() button = ToolButton() button.props.icon_name = 'activity-about' button.set_tooltip(_('Acerca de')) button.accelerator = "<Ctrl>i" button.connect('clicked', self.run_credits) toolbar_box.toolbar.insert(button, -1) button.show() # Blank space (separator) and Stop button at the end: 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 instance(self): book.wiki = book.WikiBook() if not book.custom: book.custom = book.CustomBook() self.edit_page = 1 self.edit = edit.View() self.library = library.View(self) if OLD_TOOLBAR: self.edit_toolbar = gtk.Toolbar() self.edit_bar = edit.ToolbarBuilder(self.edit, self.edit_toolbar) self.edit_toolbar.show_all() self.library_toolbar = gtk.Toolbar() self.library_bar = library.ToolbarBuilder(self.library, self.library_toolbar) self.library_toolbar.show_all() toolbox = ActivityToolbox(self) toolbox.connect('current-toolbar-changed', self._toolbar_changed_cb) self.set_toolbox(toolbox) toolbox.add_toolbar(_('Library'), self.library_toolbar) toolbox.add_toolbar(_('Edit'), self.edit_toolbar) toolbox.set_current_toolbar(1) else: toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) self.set_toolbar_box(toolbar_box) self._toolbar = toolbar_box.toolbar tool_group = None search_button = RadioToolButton() search_button.props.group = tool_group tool_group = search_button search_button.props.icon_name = 'white-search' search_button.set_tooltip(_('Library')) search_button.mode = 'search' search_button.connect('clicked', self.__mode_button_clicked) self._toolbar.insert(search_button, -1) edit_button = RadioToolButton() edit_button.props.group = tool_group edit_button.props.icon_name = 'toolbar-edit' edit_button.set_tooltip(_('Edit')) edit_button.mode = 'edit' edit_button.connect('clicked', self.__mode_button_clicked) self._toolbar.insert(edit_button, -1) self._toolbar.insert(gtk.SeparatorToolItem(), -1) self.edit_bar = edit.ToolbarBuilder(self.edit, self._toolbar) self.library_bar = library.ToolbarBuilder(self.library, self._toolbar) edit_fake = gtk.EventBox() self.notebook.append_page(self.library) self.notebook.append_page(self.edit) self.notebook.append_page(edit_fake) self.show_all() if not OLD_TOOLBAR: self.__mode_button_clicked(search_button) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) separator.show() self._toolbar.insert(separator, -1) stop_button = StopButton(self) stop_button.show() self._toolbar.insert(stop_button, -1)
class Record(activity.Activity): def __init__(self, handle): super(Record, self).__init__(handle) self.props.enable_fullscreen_mode = False Instance(self) self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK) self.connect("visibility-notify-event", self._visibility_changed) #the main classes self.model = Model(self) self.ui_init() #CSCL self.connect("shared", self._shared_cb) if self.get_shared_activity(): #have you joined or shared this activity yourself? if self.get_shared(): self._joined_cb(self) else: self.connect("joined", self._joined_cb) # Realize the video view widget so that it knows its own window XID self._media_view.realize_video() # Changing to the first toolbar kicks off the rest of the setup if self.model.get_has_camera(): self.model.change_mode(constants.MODE_PHOTO) else: self.model.change_mode(constants.MODE_AUDIO) def read_file(self, path): self.model.read_file(path) def write_file(self, path): self.model.write_file(path) def close(self): self.model.gplay.stop() self.model.glive.stop() super(Record, self).close() def _visibility_changed(self, widget, event): self.model.set_visible(event.state != gtk.gdk.VISIBILITY_FULLY_OBSCURED) def _shared_cb(self, activity): self.model.collab.set_activity_shared() def _joined_cb(self, activity): self.model.collab.joined() def ui_init(self): self._fullscreen = False self._showing_info = False # FIXME: if _thumb_tray becomes some kind of button group, we wouldn't # have to track which recd is active self._active_recd = None self.connect_after('key-press-event', self._key_pressed) self._active_toolbar_idx = 0 self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) self._toolbar_box.toolbar.insert(activity_button, 0) self.set_toolbar_box(self._toolbar_box) self._toolbar = self.get_toolbar_box().toolbar tool_group = None if self.model.get_has_camera(): self._photo_button = RadioToolButton() self._photo_button.props.group = tool_group tool_group = self._photo_button self._photo_button.props.icon_name = 'camera-external' self._photo_button.props.label = _('Photo') self._photo_button.mode = constants.MODE_PHOTO self._photo_button.connect('clicked', self._mode_button_clicked) self._toolbar.insert(self._photo_button, -1) self._video_button = RadioToolButton() self._video_button.props.group = tool_group self._video_button.props.icon_name = 'media-video' self._video_button.props.label = _('Video') self._video_button.mode = constants.MODE_VIDEO self._video_button.connect('clicked', self._mode_button_clicked) self._toolbar.insert(self._video_button, -1) else: self._photo_button = None self._video_button = None self._audio_button = RadioToolButton() self._audio_button.props.group = tool_group self._audio_button.props.icon_name = 'media-audio' self._audio_button.props.label = _('Audio') self._audio_button.mode = constants.MODE_AUDIO self._audio_button.connect('clicked', self._mode_button_clicked) self._toolbar.insert(self._audio_button, -1) self._toolbar.insert(gtk.SeparatorToolItem(), -1) self._toolbar_controls = RecordControl(self._toolbar) 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) main_box.get_parent().modify_bg(gtk.STATE_NORMAL, COLOR_BLACK) main_box.show() self._media_view = MediaView() self._media_view.connect('media-clicked', self._media_view_media_clicked) self._media_view.connect('pip-clicked', self._media_view_pip_clicked) self._media_view.connect('info-clicked', self._media_view_info_clicked) self._media_view.connect('full-clicked', self._media_view_full_clicked) self._media_view.connect('tags-changed', self._media_view_tags_changed) self._media_view.show() self._controls_hbox = gtk.HBox() self._controls_hbox.show() self._shutter_button = ShutterButton() self._shutter_button.connect("clicked", self._shutter_clicked) self._controls_hbox.pack_start(self._shutter_button, expand=True, fill=False) self._countdown_image = CountdownImage() self._controls_hbox.pack_start(self._countdown_image, expand=True, fill=False) self._play_button = PlayButton() self._play_button.connect('clicked', self._play_pause_clicked) self._controls_hbox.pack_start(self._play_button, expand=False) self._playback_scale = PlaybackScale(self.model) self._controls_hbox.pack_start(self._playback_scale, expand=True, fill=True) self._progress = ProgressInfo() self._controls_hbox.pack_start(self._progress, expand=True, fill=True) self._title_label = gtk.Label() self._title_label.set_markup("<b><span foreground='white'>"+_('Title:')+'</span></b>') self._controls_hbox.pack_start(self._title_label, expand=False) self._title_entry = gtk.Entry() self._title_entry.modify_bg(gtk.STATE_INSENSITIVE, COLOR_BLACK) self._title_entry.connect('changed', self._title_changed) self._controls_hbox.pack_start(self._title_entry, expand=True, fill=True, padding=10) container = RecordContainer(self._media_view, self._controls_hbox) main_box.pack_start(container, expand=True, fill=True, padding=6) container.show() self._thumb_tray = HTray() self._thumb_tray.set_size_request(-1, 150) main_box.pack_end(self._thumb_tray, expand=False) self._thumb_tray.show_all() def serialize(self): data = {} data['timer'] = self._toolbar_controls.get_timer_idx() data['duration'] = self._toolbar_controls.get_duration_idx() data['quality'] = self._toolbar_controls.get_quality() return data def deserialize(self, data): self._toolbar_controls.set_timer_idx(data.get('timer', 0)) self._toolbar_controls.set_duration_idx(data.get('duration', 0)) self._toolbar_controls.set_quality(data.get('quality', 0)) def _key_pressed(self, widget, event): if self.model.ui_frozen(): return False key = event.keyval if key == gtk.keysyms.KP_Page_Up: # game key O if self._shutter_button.props.visible: if self._shutter_button.props.sensitive: self._shutter_button.clicked() else: # return to live mode self.model.set_state(constants.STATE_READY) elif key == gtk.keysyms.c and event.state == gdk.CONTROL_MASK: self._copy_to_clipboard(self._active_recd) elif key == gtk.keysyms.i: self._toggle_info() elif key == gtk.keysyms.Escape: if self._fullscreen: self._toggle_fullscreen() return False def _play_pause_clicked(self, widget): self.model.play_pause() def set_mode(self, mode): self._toolbar_controls.set_mode(mode) # can be called from gstreamer thread, so must not do any GTK+ stuff def set_glive_sink(self, sink): return self._media_view.set_video_sink(sink) # can be called from gstreamer thread, so must not do any GTK+ stuff def set_gplay_sink(self, sink): return self._media_view.set_video2_sink(sink) def get_selected_quality(self): return self._toolbar_controls.get_quality() def get_selected_timer(self): return self._toolbar_controls.get_timer() def get_selected_duration(self): return self._toolbar_controls.get_duration() def set_progress(self, value, text): self._progress.set_progress(value) self._progress.set_text(text) def set_countdown(self, value): if value == 0: self._shutter_button.show() self._countdown_image.hide() self._countdown_image.clear() return self._shutter_button.hide() self._countdown_image.show() self._countdown_image.set_value(value) def _title_changed(self, widget): self._active_recd.setTitle(self._title_entry.get_text()) def _media_view_media_clicked(self, widget): if self._play_button.props.visible and self._play_button.props.sensitive: self._play_button.clicked() def _media_view_pip_clicked(self, widget): # clicking on the PIP always returns to live mode self.model.set_state(constants.STATE_READY) def _media_view_info_clicked(self, widget): self._toggle_info() def _toggle_info(self): recd = self._active_recd if not recd: return if self._showing_info: self._show_recd(recd, play=False) return self._showing_info = True if self.model.get_mode() in (constants.MODE_PHOTO, constants.MODE_AUDIO): func = self._media_view.show_info_photo else: func = self._media_view.show_info_video self._play_button.hide() self._progress.hide() self._playback_scale.hide() self._title_entry.set_text(recd.title) self._title_entry.show() self._title_label.show() func(recd.recorderName, recd.colorStroke, recd.colorFill, utils.getDateString(recd.time), recd.tags) def _media_view_full_clicked(self, widget): self._toggle_fullscreen() def _media_view_tags_changed(self, widget, tbuffer): text = tbuffer.get_text(tbuffer.get_start_iter(), tbuffer.get_end_iter()) self._active_recd.setTags(text) def _toggle_fullscreen(self): if not self._fullscreen: self._toolbar_box.hide() self._thumb_tray.hide() else: self._toolbar_box.show() self._thumb_tray.show() self._fullscreen = not self._fullscreen self._media_view.set_fullscreen(self._fullscreen) def _mode_button_clicked(self, button): self.model.change_mode(button.mode) def _shutter_clicked(self, arg): self.model.do_shutter() def set_shutter_sensitive(self, value): self._shutter_button.set_sensitive(value) def set_state(self, state): radio_state = (state == constants.STATE_READY) for item in (self._photo_button, self._audio_button, self._video_button): if item: item.set_sensitive(radio_state) self._showing_info = False if state == constants.STATE_READY: self._set_cursor_default() self._active_recd = None self._title_entry.hide() self._title_label.hide() self._play_button.hide() self._playback_scale.hide() self._progress.hide() self._controls_hbox.set_child_packing(self._shutter_button, expand=True, fill=False, padding=0, pack_type=gtk.PACK_START) self._shutter_button.set_normal() self._shutter_button.set_sensitive(True) self._shutter_button.show() self._media_view.show_live() elif state == constants.STATE_RECORDING: self._shutter_button.set_recording() self._controls_hbox.set_child_packing(self._shutter_button, expand=False, fill=False, padding=0, pack_type=gtk.PACK_START) self._progress.show() elif state == constants.STATE_PROCESSING: self._set_cursor_busy() self._shutter_button.hide() self._progress.show() elif state == constants.STATE_DOWNLOADING: self._shutter_button.hide() self._progress.show() def set_paused(self, value): if value: self._play_button.set_play() else: self._play_button.set_pause() def _thumbnail_clicked(self, button, recd): if self.model.ui_frozen(): return self._active_recd = recd self._show_recd(recd) def add_thumbnail(self, recd, scroll_to_end): button = RecdButton(recd) clicked_handler = button.connect("clicked", self._thumbnail_clicked, recd) remove_handler = button.connect("remove-requested", self._remove_recd) clipboard_handler = button.connect("copy-clipboard-requested", self._thumbnail_copy_clipboard) button.set_data('handler-ids', (clicked_handler, remove_handler, clipboard_handler)) self._thumb_tray.add_item(button) button.show() if scroll_to_end: self._thumb_tray.scroll_to_end() def _copy_to_clipboard(self, recd): if recd == None: return if not recd.isClipboardCopyable(): return media_path = recd.getMediaFilepath() tmp_path = utils.getUniqueFilepath(media_path, 0) shutil.copyfile(media_path, tmp_path) gtk.Clipboard().set_with_data([('text/uri-list', 0, 0)], self._clipboard_get, self._clipboard_clear, tmp_path) def _clipboard_get(self, clipboard, selection_data, info, path): selection_data.set("text/uri-list", 8, "file://" + path) def _clipboard_clear(self, clipboard, path): if os.path.exists(path): os.unlink(path) def _thumbnail_copy_clipboard(self, recdbutton): self._copy_to_clipboard(recdbutton.get_recd()) def _remove_recd(self, recdbutton): recd = recdbutton.get_recd() self.model.delete_recd(recd) if self._active_recd == recd: self.model.set_state(constants.STATE_READY) self._remove_thumbnail(recdbutton) def _remove_thumbnail(self, recdbutton): handlers = recdbutton.get_data('handler-ids') for handler in handlers: recdbutton.disconnect(handler) self._thumb_tray.remove_item(recdbutton) recdbutton.cleanup() def remove_all_thumbnails(self): for child in self._thumb_tray.get_children(): self._remove_thumbnail(child) def show_still(self, pixbuf): self._media_view.show_still(pixbuf) def _show_photo(self, recd): path = self._get_photo_path(recd) self._media_view.show_photo(path) self._title_entry.set_text(recd.title) self._title_entry.show() self._title_label.show() self._shutter_button.hide() self._progress.hide() def _show_audio(self, recd, play): self._progress.hide() self._shutter_button.hide() self._title_entry.hide() self._title_label.hide() self._play_button.show() self._playback_scale.show() path = recd.getAudioImageFilepath() self._media_view.show_photo(path) if play: self.model.play_audio(recd) def _show_video(self, recd, play): self._progress.hide() self._shutter_button.hide() self._title_entry.hide() self._title_label.hide() self._play_button.show() self._playback_scale.show() self._media_view.show_video() if play: self.model.play_video(recd) def set_playback_scale(self, value): self._playback_scale.set_value(value) def _get_photo_path(self, recd): # FIXME should live (partially) in recd? #downloading = self.ca.requestMeshDownload(recd) #self.MESHING = downloading if True: #not downloading: #self.progressWindow.updateProgress(0, "") return recd.getMediaFilepath() #maybe it is not downloaded from the mesh yet... #but we can show the low res thumb in the interim return recd.getThumbFilepath() def _show_recd(self, recd, play=True): self._showing_info = False if recd.buddy and not recd.downloadedFromBuddy: self.model.request_download(recd) elif recd.type == constants.TYPE_PHOTO: self._show_photo(recd) elif recd.type == constants.TYPE_AUDIO: self._show_audio(recd, play) elif recd.type == constants.TYPE_VIDEO: self._show_video(recd, play) def remote_recd_available(self, recd): if recd == self._active_recd: self._show_recd(recd) def update_download_progress(self, recd): if recd != self._active_recd: return if not recd.meshDownloading: msg = _('Download failed.') elif recd.meshDownloadingProgress: msg = _('Downloading...') else: msg = _('Requesting...') self.set_progress(recd.meshDownlodingPercent, msg) def _set_cursor_busy(self): self.window.set_cursor(gdk.Cursor(gdk.WATCH)) def _set_cursor_default(self): self.window.set_cursor(None)
def get_toolbar(self): toolbar = gtk.Toolbar() radio_adv = RadioToolButton() radio_adv.set_active(True) radio_adv.set_label("Avanzada") radio_adv.set_tooltip("Mostrar biblioteca avanzada") radio_adv.connect("clicked", self.switch, "advanced") toolbar.insert(radio_adv, -1) radio_adv.show() radio_bas = RadioToolButton(group=radio_adv) radio_bas.set_label("Simple") radio_bas.set_tooltip("Mostrar biblioteca sencilla") radio_bas.connect("clicked", self.switch, "basic") toolbar.insert(radio_bas, -1) toolbar.show_all() return toolbar
def size_allocate_cb(self, widget, event): """ Builds the tag star around the center where the selected category is shown. """ self._logger.debug('size_allocate_cb()') x, y, width, height = self.fixed.get_allocation() self._logger.debug('x: %s, y: %s, w: %s, h: %s', x, y, width, height) self.set_size_request(width, height) ###################################################################### # place togglebuttons around the current position in a radio group color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() button_width, button_height = self.BUTTON_SIZE cat_names = get_categories() radius = 300 # px x_center = width / 2 - 40 y_center = height / 2 - 40 step_angle = math.radians(360 / (len(cat_names) + 1)) # plus reset btn # add a reset button self.reset_selected_btn = RadioToolButton() img_name = os.path.join(GeoTag.ICONS_PATH, 'reset.svg') icon = gtk.image_new_from_pixbuf(utils.load_svg_image(img_name, color_stroke, color_fill, self.IMG_SIZE)) self.reset_selected_btn.set_icon_widget(icon) self.reset_selected_btn.set_tooltip(_('Reset selected tag.')) self.reset_selected_btn.connect('clicked', self.reset_toggled) self.reset_selected_btn.show_all() self.reset_selected_btn.set_size_request(button_width, button_height) self.fixed.put(self.reset_selected_btn, x_center, # + int(radius * math.sin(i * step_angle)), y_center + radius) # + int(radius * math.cos(i * step_angle))) self.reset_selected_btn.set_active(False) # read all available categories dynamically for i, category in enumerate(cat_names): button = RadioToolButton(group=self.reset_selected_btn) img_name = os.path.join(GeoTag.ICONS_PATH, category) icon = get_gtkimage_from_plugin(img_name, color_stroke, color_fill, self.IMG_SIZE) button.set_icon_widget(icon) button.set_tooltip(_('Tag some %s.' % category)) # XXX check translation here!! button.connect('clicked', self.set_toggled, category) button.show_all() button.set_size_request(button_width, button_height) self.fixed.put(button, x_center + int(radius * math.sin((i + 1) * step_angle)), y_center + int(radius * math.cos((i + 1) * step_angle))) button.set_active(False) img_name = os.path.join(GeoTag.ICONS_PATH, NONE_CATEGORY) self._set_selected(get_gtkimage_from_plugin(img_name, color_stroke,color_fill, self.IMG_SIZE)) ################################################################### self._logger.debug("size_allocation done") self.disconnect(self.size_cb) ## use only once
class SensorToolbar(gtk.Toolbar): ''' The toolbar for specifiying the sensor: sound, resitance, or voltage ''' LOWER = 0.0 UPPER = 1.0 STR_DC_R = \ _("Resistive sensor (connect sensor to pink 'Mic In' on left side \ of XO)" ) + ' ' STR_DC_V = \ _("Voltage sensor (connect sensor to pink 'Mic In' on left side \ of XO)" ) + ' ' STR_AC = _('Sound') + ' ' STR_RESISTANCE = _('Resistance') + ' (' + _('Ohms') + ') ' STR_VOLTAGE = _('Voltage') + ' (' + _('Volts') + ') ' STR_TIME = _('Time Base') + ' ' STR_FREQUENCY = _('Frequency Base') + ' ' STR_INVERT = ' ' + _('Invert') + ' ' STR_XAXIS_TEXT = _('X Axis Scale: 1 division = %(division)s %(unit)s') # TRANSLATORS: This is milli seconds. MS = _('ms') # TRANSLATORS: This is Hertz, so 1/second. HZ = _('Hz') def __init__(self, activity, channels): ''' By default, start with resistance mode ''' gtk.Toolbar.__init__(self) self.activity = activity self._channels = channels self._lock_radio_buttons = False self._radio_button_pushed = False self.values = [] for i in range(self._channels): self.values.append('') self.string_for_textbox = '' self.gain = 1.0 self.y_mag = 3.0 self.capture_gain = CAPTURE_GAIN self.mic_boost = MIC_BOOST self.mode = 'sound' # Set up Time-domain Button self.time = RadioToolButton(group=None) self.time.set_named_icon('media-audio') self.insert(self.time, -1) self.time.set_tooltip(_('Sound')) self.time.connect('clicked', self.analog_resistance_voltage_mode_cb, 'sound') # Set up Resistance Button self.resistance = RadioToolButton(group=self.time) self.resistance.set_named_icon('resistance') if _is_xo(self.activity.hw): self.insert(self.resistance, -1) self.resistance.show() self.resistance.set_tooltip(_('Resistance Sensor')) self.resistance.connect('clicked', self.analog_resistance_voltage_mode_cb, 'resistance') # Set up Voltage Button self.voltage = RadioToolButton(group=self.time) self.voltage.set_named_icon('voltage') if _is_xo(self.activity.hw): self.insert(self.voltage, -1) self.voltage.set_tooltip(_('Voltage Sensor')) self.voltage.connect('clicked', self.analog_resistance_voltage_mode_cb, 'voltage') separator = gtk.SeparatorToolItem() separator.props.draw = True self.insert(separator, -1) self._log_interval_combo = ComboBox() self.interval = [ _('1/10 second'), _('1 second'), _('30 seconds'), _('5 minutes'), _('30 minutes') ] if hasattr(self._log_interval_combo, 'set_tooltip_text'): self._log_interval_combo.set_tooltip_text(_('Sampling interval')) self._interval_changed_id = self._log_interval_combo.connect( 'changed', self.log_interval_cb) for i, s in enumerate(self.interval): self._log_interval_combo.append_item(i, s, None) if s == _('1 second'): self._log_interval_combo.set_active(i) self._log_interval_tool = ToolComboBox(self._log_interval_combo) self.insert(self._log_interval_tool, -1) self.logging_interval_status = '1 second' # Set up Logging/Stop Logging Button self._record = ToolButton('media-record') self.insert(self._record, -1) self._record.set_tooltip(_('Start Recording')) self._record.connect('clicked', self.record_control_cb) if self.activity.has_toolbarbox: separator = gtk.SeparatorToolItem() separator.props.draw = True self.insert(separator, -1) # Set up Trigger Combo box self.trigger_combo = ComboBox() self.trigger = [_('None'), _('Rising Edge'), _('Falling Edge')] self.trigger_conf = [ self.activity.wave.TRIGGER_NONE, self.activity.wave.TRIGGER_POS, self.activity.wave.TRIGGER_NEG ] self._trigger_changed_id = self.trigger_combo.connect( 'changed', self.update_trigger_control) for i, s in enumerate(self.trigger): self.trigger_combo.append_item(i, s, None) self.trigger_combo.set_active(0) if hasattr(self.trigger_combo, 'set_tooltip_text'): self.trigger_combo.set_tooltip_text(_('Create a trigger')) self._trigger_tool = ToolComboBox(self.trigger_combo) self.insert(self._trigger_tool, -1) self.show_all() def add_frequency_slider(self, toolbar): ''' 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.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_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_range_tool = gtk.ToolItem() self._freq_range_tool.add(self._freq_range) toolbar.insert(self._freq_stepper_up, -1) toolbar.insert(self._freq_range_tool, -1) toolbar.insert(self._freq_stepper_down, -1) return def update_trigger_control(self, *args): ''' Callback for trigger control ''' if self.activity.wave.get_fft_mode(): self.trigger_combo.set_active(self.activity.wave.TRIGGER_NONE) active = self.trigger_combo.get_active() if active == -1: return self.activity.wave.set_trigger(self.trigger_conf[active]) return def analog_resistance_voltage_mode_cb(self, button=None, mode_to_set='sound'): ''' Callback for Analog/Resistance/Voltage Buttons ''' if self._lock_radio_buttons: logging.debug('mode selector locked') self._radio_button_pushed = True return if self.mode == mode_to_set: logging.debug('mode already set to %s' % mode_to_set) return self._lock_radio_buttons = True if self.activity.CONTEXT == 'sound': self.sound_context_off() else: self.sensor_context_off() # Force time domain when switching modes if self.activity.wave.get_fft_mode(): self.activity.timefreq_control() # Turn off logging when switching modes if self.activity.audiograb.we_are_logging: self.record_control_cb() self.set_mode(mode_to_set) if mode_to_set == 'sound': self.set_sound_context() elif mode_to_set == 'resistance': self.set_sensor_context() elif mode_to_set == 'voltage': self.set_sensor_context() self.update_string_for_textbox() return False def unlock_radio_buttons(self): ''' Enable radio button selection ''' logging.debug('unlocking radio buttons') if self._radio_button_pushed: if self.mode == 'sound': self.time.set_active(True) elif self.mode == 'resistance': self.resistance.set_active(True) elif self.mode == 'voltage': self.voltage.set_active(True) self._lock_radio_buttons = False self._radio_button_pushed = False def set_mode(self, mode='sound'): ''' Set the mixer settings to match the current mode. ''' self.mode = mode self.activity.audiograb.set_sensor_type(self.mode) for i in range(self._channels): self.values[i] = 0.0 return def get_mode(self): ''' Get the mixer settings. ''' return self.mode def _freq_stepper_up_cb(self, button=None): ''' Moves the horizontal zoom slider to the left one notch, where one notch is 1/100 of the total range. This correspond to zooming out as a larger number of Hertz or milliseconds will be represented by the same space on the screen. ''' new_value = self._freq_range.get_value() +\ (self.UPPER - self.LOWER) / 100.0 if new_value <= self.UPPER: self._freq_range.set_value(new_value) else: self._freq_range.set_value(self.UPPER) def _freq_stepper_down_cb(self, button=None): ''' Moves the horizontal zoom slider to the right one notch, where one notch is 1/100 of the total range. This corresponds to zooming in. ''' new_value = self._freq_range.get_value() -\ (self.UPPER - self.LOWER) / 100.0 if new_value >= self.LOWER: self._freq_range.set_value(new_value) else: self._freq_range.set_value(self.LOWER) def cb_page_sizef(self, button=None): ''' Callback to scale the frequency range (zoom in and out) ''' if self._update_page_size_id: gobject.source_remove(self._update_page_size_id) self._update_page_size_id =\ gobject.timeout_add(250, self.update_page_size) return True def update_page_size(self): ''' Set up the scaling of the display. ''' self._update_page_size_id = None new_value = round(self.activity.adjustmentf.value * 100.0) / 100.0 if self.activity.adjustmentf.value != new_value: self.activity.adjustmentf.value = new_value return False time_div = 0.001 * max(self.activity.adjustmentf.value, 0.05) freq_div = 1000 * max(self.activity.adjustmentf.value, 0.01) self.activity.wave.set_div(time_div, freq_div) self.update_string_for_textbox() return False def set_sound_context(self): ''' Called when analog sensing is selected ''' self.set_show_hide_windows(mode='sound') gobject.timeout_add(500, self.sound_context_on) self.activity.CONTEXT = 'sound' def set_sensor_context(self): ''' Called when digital sensing is selected ''' self.set_show_hide_windows(mode='sensor') gobject.timeout_add(500, self.sensor_context_on) self.activity.CONTEXT = 'sensor' def set_show_hide_windows(self, mode='sound'): ''' Shows the appropriate window identified by the mode ''' self.activity.wave.set_context_on() for i in range(self._channels): self.activity.side_toolbars[i].set_show_hide(True, mode) def sensor_context_off(self): ''' Called when a DC sensor is no longer selected ''' # self.activity.audiograb.pause_grabbing() self.activity.audiograb.stop_grabbing() def sensor_context_on(self): ''' Called when a DC sensor is selected ''' self.update_string_for_textbox() self.activity.wave.set_trigger(self.activity.wave.TRIGGER_NONE) # self.activity.audiograb.resume_grabbing() self.activity.audiograb.start_grabbing() return False def sound_context_off(self): ''' Called when an analog sensor is no longer selected ''' self.gain, self.y_mag = self.activity.wave.get_mag_params() self.capture_gain = self.activity.audiograb.get_capture_gain() self.mic_boost = self.activity.audiograb.get_mic_boost() self.activity.audiograb.stop_grabbing() def sound_context_on(self): ''' Called when an analog sensor is selected ''' self.activity.wave.set_mag_params(self.gain, self.y_mag) self.update_string_for_textbox() self.update_trigger_control() self.activity.audiograb.start_grabbing() return False def set_sample_value(self, value='', channel=0): ''' Write a sample value to the textbox. ''' gtk.threads_enter() self.values[channel] = value self.update_string_for_textbox() gtk.threads_leave() return def record_control_cb(self, button=None): ''' Depending upon the selected interval, does either a logging session, or just logs the current buffer. ''' if self.activity.audiograb.we_are_logging: self.activity.audiograb.set_logging_params(start_stop=False) self._record.set_icon('media-record') self._record.show() self._record.set_tooltip(_('Start Recording')) else: Xscale = (1.00 / self.activity.audiograb.get_sampling_rate()) Yscale = 0.0 interval = self.interval_convert() username = self.activity.nick if self.activity.wave.get_fft_mode(): self.activity.data_logger.start_new_session( username, Xscale, Yscale, _(self.logging_interval_status), channels=self._channels, mode='frequency') else: self.activity.data_logger.start_new_session( username, Xscale, Yscale, _(self.logging_interval_status), channels=self._channels, mode=self.mode) self.activity.audiograb.set_logging_params(start_stop=True, interval=interval, screenshot=False) self._record.set_icon('record-stop') self._record.show() self._record.set_tooltip(_('Stop Recording')) self.activity.new_recording = True def interval_convert(self): ''' Converts interval string to an integer that denotes the number of times the audiograb buffer must be called before a value is written. When set to 0, the whole of current buffer will be written. ''' interval_dictionary = { '1/10 second': 0.1, '1 second': 1, '30 seconds': 30, '5 minutes': 300, '30 minutes': 1800 } try: return interval_dictionary[self.logging_interval_status] except ValueError: logging.error('logging interval status = %s' %\ (str(self.logging_interval_status))) return 0 def log_interval_cb(self, combobox): ''' Callback from the Logging Interval Combo box: sets status ''' if self._log_interval_combo.get_active() != -1: intervals = [ '1/10 second', '1 second', '30 seconds', '5 minutes', '30 minutes' ] self.logging_interval_status = \ intervals[self._log_interval_combo.get_active()] def update_string_for_textbox(self): ''' Update the status field at the bottom of the canvas. ''' if self.activity.CONTEXT == 'butia': string_for_textbox = '' else: if self.mode == 'resistance': string_for_textbox = (self.STR_DC_R + '\n') string_for_textbox += self.STR_RESISTANCE elif self.mode == 'voltage': string_for_textbox = (self.STR_DC_V + '\n') string_for_textbox += self.STR_VOLTAGE else: string_for_textbox = (self.STR_AC + '\t') if self.activity.wave.get_fft_mode(): scalex = self.STR_XAXIS_TEXT % { 'unit': self.HZ, 'division': self.activity.wave.freq_div } string_for_textbox += self.STR_FREQUENCY string_for_textbox += ('\n' + scalex) elif self.mode == 'sound': scalex = self.STR_XAXIS_TEXT % { 'unit': self.MS, 'division': self.activity.wave.time_div * 1000 } string_for_textbox += self.STR_TIME string_for_textbox += ('\n' + scalex) else: for i in range(self._channels): string_for_textbox += '\t(%s)' % (self.values[i]) invert = False for i in range(self._channels): if self.activity.wave.get_invert_state(channel=i): invert = True if invert: string_for_textbox += self.STR_INVERT self.activity.text_box.set_label(string_for_textbox)
class TagStar(gtk.HBox): """ A L{gtk.HBox} which arranges togglebuttons around the current position within a L{gtk.Fixed} widget. This is the central tag element, where a user can either tag his current position with a category specified in L{geotagplugin.ECategory}. If one of the user's already tagged features is selected in the tree, the made change action will be handled as an edit. """ IMG_SIZE = (100, 100) BUTTON_SIZE = (100, 100) EMPTY_LIST_STORE = gtk.ListStore(gobject.TYPE_STRING) toggled = NONE_CATEGORY # selected category selected = None # gtk.Image displaying selected category def __init__(self, toolbar, control): gtk.HBox.__init__(self) self._logger = logging.getLogger('TagStar') self._logger.setLevel(constants.LOG_LEVEL) self.toolbar = toolbar self.control = control self.size_cb = self.connect('size_allocate', self.size_allocate_cb) self.fixed = gtk.Fixed() self.pack_start(self.fixed) self.show_all() def size_allocate_cb(self, widget, event): """ Builds the tag star around the center where the selected category is shown. """ self._logger.debug('size_allocate_cb()') x, y, width, height = self.fixed.get_allocation() self._logger.debug('x: %s, y: %s, w: %s, h: %s', x, y, width, height) self.set_size_request(width, height) ###################################################################### # place togglebuttons around the current position in a radio group color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() button_width, button_height = self.BUTTON_SIZE cat_names = get_categories() radius = 300 # px x_center = width / 2 - 40 y_center = height / 2 - 40 step_angle = math.radians(360 / (len(cat_names) + 1)) # plus reset btn # add a reset button self.reset_selected_btn = RadioToolButton() img_name = os.path.join(GeoTag.ICONS_PATH, 'reset.svg') icon = gtk.image_new_from_pixbuf(utils.load_svg_image(img_name, color_stroke, color_fill, self.IMG_SIZE)) self.reset_selected_btn.set_icon_widget(icon) self.reset_selected_btn.set_tooltip(_('Reset selected tag.')) self.reset_selected_btn.connect('clicked', self.reset_toggled) self.reset_selected_btn.show_all() self.reset_selected_btn.set_size_request(button_width, button_height) self.fixed.put(self.reset_selected_btn, x_center, # + int(radius * math.sin(i * step_angle)), y_center + radius) # + int(radius * math.cos(i * step_angle))) self.reset_selected_btn.set_active(False) # read all available categories dynamically for i, category in enumerate(cat_names): button = RadioToolButton(group=self.reset_selected_btn) img_name = os.path.join(GeoTag.ICONS_PATH, category) icon = get_gtkimage_from_plugin(img_name, color_stroke, color_fill, self.IMG_SIZE) button.set_icon_widget(icon) button.set_tooltip(_('Tag some %s.' % category)) # XXX check translation here!! button.connect('clicked', self.set_toggled, category) button.show_all() button.set_size_request(button_width, button_height) self.fixed.put(button, x_center + int(radius * math.sin((i + 1) * step_angle)), y_center + int(radius * math.cos((i + 1) * step_angle))) button.set_active(False) img_name = os.path.join(GeoTag.ICONS_PATH, NONE_CATEGORY) self._set_selected(get_gtkimage_from_plugin(img_name, color_stroke,color_fill, self.IMG_SIZE)) ################################################################### self._logger.debug("size_allocation done") self.disconnect(self.size_cb) ## use only once def reset_toggled(self, button): """ Resets toggled property and combobox liststore. @param button: The reset button (can be omitted by passing None). @note: If a tag was selected within the L{geotagmodel.GeotagModel}, the tag will be deleted. """ self.toggled = NONE_CATEGORY # reset liststore combo = self.toolbar.combobox combo.set_model(self.EMPTY_LIST_STORE) # reset selected widget color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() self._set_selected(get_gtkimage_from_plugin(NONE_CATEGORY, color_stroke, color_fill, self.IMG_SIZE)) self.reset_selected_btn.set_active(True) self.selected.queue_draw() combo.queue_draw() def set_toggled(self, button, category): """ Switches the empty Button and the tagged category button clicked. Also, sets the appropriate liststore for the combobox. @param button: Toggled button (can be omittted). @param category: The corresponding category to set. """ self._logger.debug("set_toggled()") self.toggled = category # set liststore combo = self.toolbar.combobox combo.set_model(self.toolbar.description_sets[category]) color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() # self._logger.debug("storage type: %s", self.selected.get_property("storage-type")) self._set_selected(get_gtkimage_from_plugin(category, color_stroke, color_fill, self.IMG_SIZE)) combo.queue_draw() def _set_selected(self, widget): """ Sets the widget as the currently selected tag category. @param widget: The L{gtk.Image} to set. """ x, y, width, height = self.fixed.get_allocation() x_center = width / 2 - 40 y_center = height / 2 - 40 if self.selected: self.selected.clear() button_width, button_height = self.BUTTON_SIZE widget.set_size_request(button_width, button_height) widget.show_all() self.selected = widget self.selected.queue_draw() self.fixed.put(self.selected, x_center, y_center)
def __init__(self, handle): activity.Activity.__init__(self, handle, True) self.max_participants = 1 # ****** Editor ****** self.editor = Editor() self.editor.connect("pep8-aviable", self.enable_pep8) self.editor.connect('language-changed', self.language_changed) self.editor.set_size_request(800, 790) scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll.add(self.editor) vbox = gtk.VBox() vpaned = gtk.VPaned() vbox.pack_start(vpaned, True, True, 0) vpaned.show() vpaned.pack1(scroll, resize=True) scroll.show_all() self.set_canvas(vbox) # ****** Toolbars ****** self.toolbar_box = options.OptionWidget(self, self.editor.get_pango_context()) self.toolbar_box.connect('open-from-journal', file_choosers.open_from_journal, None, self) self.toolbar_box.connect('open-file', self.open_file) self.toolbar_box.connect('save-file', self.save_file) self.toolbar_box.connect('save-as', self.save_file_as) self.toolbar_box.connect('new-file', self.new) self.toolbar_box.connect('pep8-check', self.pep8_check) self.toolbar_box.connect('insert-datetime', self.editor._insert_date_time) self.toolbar_box.connect('copy', self.editor._copy_cb) self.toolbar_box.connect('paste', self.editor._paste_cb) self.toolbar_box.connect('undo', self.editor._undo_cb) self.toolbar_box.connect('redo', self.editor._redo_cb) self.toolbar_box.connect('cut', self.editor._cut_cb) self.toolbar_box.connect('search-text', self._search_text) self.toolbar_box.connect('search-prev', self.editor._search_prev_cb) self.toolbar_box.connect('search-next', self.editor._search_next_cb) self.toolbar_box.connect('show-line-numbers', self.editor._set_show_line_numbers) self.toolbar_box.connect('language-changed', self.change_language) self.toolbar_box.connect('style-changed', self.change_style) self.toolbar_box.connect('font-changed', self.change_font) self.toolbar_box.show_all() self.set_toolbar_box(self.toolbar_box) # Barra de estado de PEP8 / PEP8 status bar self.pep8 = PEP8_Check() self.pep8_bar = gtk.Statusbar() self.pep8.connect("show-bar", (lambda w, bar: bar.show_all()), self.pep8_bar) self.pep8.connect("hide-bar", (lambda w, bar: bar.hide()), self.pep8_bar) self.pep8_bar.label = gtk.Label() self.pep8.connect("bar-text", (lambda w, t, l: l.set_text(t)), self.pep8_bar.label) self.pep8_bar.add(self.pep8_bar.label) vbox.pack_end(self.pep8_bar, False, True, 0) tray = VTray() self.test_notebook = gtk.Notebook() self.test_notebook.set_show_tabs(False) terminal = consoles.Terminal() terminal.show() terminal_item = RadioToolButton() terminal_item.set_named_icon("console-terminal") terminal_item.set_tooltip("Terminal") terminal_item.connect("toggled", self.page_changed, 0) terminal_item.show() self.test_notebook.append_page(terminal, None) tray.add_item(terminal_item) python_console = consoles.PythonConsole() python_console.show() python_item = RadioToolButton() python_item.set_named_icon("console-python") python_item.set_tooltip("Python Console") python_item.set_group(terminal_item) python_item.connect("toggled", self.page_changed, 1) python_item.show() self.test_notebook.append_page(python_console) tray.add_item(python_item) hbox = gtk.HBox() hbox.pack_start(tray, False, True, 0) hbox.pack_start(self.test_notebook) self.test_notebook.show() vpaned.pack2(hbox, resize=True) vpaned.show_all() tray.show() hbox.show() vbox.show_all()
def __init__(self, handle): activity.Activity.__init__(self, handle, True) self.max_participants = 1 # CHART_OPTIONS self.x_label = "" self.y_label = "" self.chart_color = utils.get_user_fill_color('str') self.chart_line_color = utils.get_user_stroke_color('str') self.current_chart = None self.charts_area = None self.chart_data = [] # TOOLBARS toolbarbox = ToolbarBox() activity_button = ActivityToolbarButton(self) activity_btn_toolbar = activity_button.page activity_btn_toolbar.title.connect('changed', self._set_chart_title) save_as_image = ToolButton("save-as-image") save_as_image.connect("clicked", self._save_as_image) save_as_image.set_tooltip(_("Save as image")) activity_btn_toolbar.insert(save_as_image, -1) save_as_image.show() toolbarbox.toolbar.insert(activity_button, 0) import_freespace = ToolButton("import-freespace") import_freespace.connect("clicked", self.__import_freespace_cb) import_freespace.set_tooltip(_("Read Freespace data")) toolbarbox.toolbar.insert(import_freespace, -1) import_freespace.show() import_journal = ToolButton('import-journal') import_journal.connect('clicked', self.__import_journal_cb) import_journal.set_tooltip(_('Read Journal data')) toolbarbox.toolbar.insert(import_journal, -1) import_journal.show() import_turtle = ToolButton('import-turtle') import_turtle.connect('clicked', self.__import_turtle_cb) import_turtle.set_tooltip(_('Read Turtle data')) toolbarbox.toolbar.insert(import_turtle, -1) import_turtle.show() separator = gtk.SeparatorToolItem() separator.set_draw(True) separator.set_expand(False) toolbarbox.toolbar.insert(separator, -1) add_vbar_chart = RadioToolButton() add_vbar_chart.connect("clicked", self._add_chart_cb, "vbar") add_vbar_chart.set_tooltip(_("Vertical Bar Chart")) add_vbar_chart.props.icon_name = "vbar" charts_group = add_vbar_chart toolbarbox.toolbar.insert(add_vbar_chart, -1) add_hbar_chart = RadioToolButton() add_hbar_chart.connect("clicked", self._add_chart_cb, "hbar") add_hbar_chart.set_tooltip(_("Horizontal Bar Chart")) add_hbar_chart.props.icon_name = "hbar" add_hbar_chart.props.group = charts_group toolbarbox.toolbar.insert(add_hbar_chart, -1) add_pie_chart = RadioToolButton() add_pie_chart.connect("clicked", self._add_chart_cb, "pie") add_pie_chart.set_tooltip(_("Pie Chart")) add_pie_chart.props.icon_name = "pie" add_pie_chart.props.group = charts_group add_pie_chart.set_active(True) toolbarbox.toolbar.insert(add_pie_chart, -1) self.chart_type_buttons = [ add_vbar_chart, add_hbar_chart, add_pie_chart ] separator = gtk.SeparatorToolItem() separator.set_draw(True) separator.set_expand(False) toolbarbox.toolbar.insert(separator, -1) fullscreen_btn = ToolButton('view-fullscreen') fullscreen_btn.set_tooltip(_('Fullscreen')) fullscreen_btn.connect("clicked", self.__fullscreen_cb) toolbarbox.toolbar.insert(fullscreen_btn, -1) charthelp.create_help(toolbarbox.toolbar) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) toolbarbox.toolbar.insert(separator, -1) stopbtn = StopButton(self) toolbarbox.toolbar.insert(stopbtn, -1) self.set_toolbar_box(toolbarbox) # CANVAS paned = gtk.HPaned() box = gtk.VBox() self.box = box # Set the info box width to 1/3 of the screen: def size_allocate_cb(widget, allocation): paned.disconnect(self._setup_handle) box_width = allocation.width / 3 box.set_size_request(box_width, -1) self._setup_handle = paned.connect('size_allocate', size_allocate_cb) scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.labels_and_values = ChartData(self) scroll.add(self.labels_and_values) self.labels_and_values.connect("label-changed", self._label_changed) self.labels_and_values.connect("value-changed", self._value_changed) box.pack_start(scroll, True, True, 0) paned.add1(box) # CHARTS AREA eventbox = gtk.EventBox() self.charts_area = ChartArea(self) self.charts_area.connect('size_allocate', self._chart_size_allocate) eventbox.modify_bg(gtk.STATE_NORMAL, _WHITE) eventbox.add(self.charts_area) paned.add2(eventbox) self.set_canvas(paned) self.show_all()
class SpeakActivity(activity.Activity): def __init__(self, handle): super(SpeakActivity, self).__init__(handle) self._notebook = gtk.Notebook() self.set_canvas(self._notebook) self._notebook.show() self._colors = profile.get_color().to_string().split(',') lighter = style.Color(self._colors[ _lighter_color(self._colors)]) self._mode = MODE_TYPE self._tablet_mode = _is_tablet_mode() self._robot_idle_id = None self._active_eyes = None self._active_number_of_eyes = None self._current_voice = None # make an audio device for playing back and rendering audio self.connect('notify::active', self._active_cb) self._cfg = {} # make a box to type into hbox = gtk.HBox() if self._tablet_mode: self._entry = gtk.Entry() hbox.pack_start(self._entry, expand=True) talk_button = ToolButton('microphone') talk_button.set_tooltip(_('Speak')) talk_button.connect('clicked', self._talk_cb) hbox.pack_end(talk_button, expand=False) else: self._entrycombo = gtk.combo_box_entry_new_text() self._entrycombo.connect('changed', self._combo_changed_cb) self._entry = self._entrycombo.child self._entry.set_size_request(-1, style.GRID_CELL_SIZE) hbox.pack_start(self._entrycombo, expand=True) self._entry.set_editable(True) self._entry.connect('activate', self._entry_activate_cb) self._entry.connect('key-press-event', self._entry_key_press_cb) self._entry.modify_font(pango.FontDescription(str='sans bold 24')) hbox.show() self.face = face.View(fill_color=lighter) self.face.set_size_request( -1, gtk.gdk.screen_height() - 2 * style.GRID_CELL_SIZE) self.face.show() # layout the screen box = gtk.VBox(homogeneous=False) if self._tablet_mode: box.pack_start(hbox, expand=False) box.pack_start(self.face) else: box.pack_start(self.face, expand=True) box.pack_start(hbox) self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.POINTER_MOTION_MASK) self.connect('motion_notify_event', self._mouse_moved_cb) box.add_events(gtk.gdk.BUTTON_PRESS_MASK) box.connect('button_press_event', self._mouse_clicked_cb) # desktop self._notebook.show() self._notebook.props.show_border = False self._notebook.props.show_tabs = False box.show_all() self._notebook.append_page(box) self._chat = chat.View() self._chat.show_all() self._notebook.append_page(self._chat) # make the text box active right away if not self._tablet_mode: self._entry.grab_focus() self._entry.connect('move-cursor', self._cursor_moved_cb) self._entry.connect('changed', self._cursor_moved_cb) toolbox = ToolbarBox() self._activity_button = ActivityToolbarButton(self) self._activity_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._activity_button, -1) mode_type = RadioToolButton( named_icon='mode-type', tooltip=_('Type something to hear it')) mode_type.connect('toggled', self.__toggled_mode_type_cb) toolbox.toolbar.insert(mode_type, -1) mode_robot = RadioToolButton( named_icon='mode-robot', group=mode_type, tooltip=_('Ask robot any question')) mode_robot.connect('toggled', self.__toggled_mode_robot_cb) toolbox.toolbar.insert(mode_robot, -1) self._mode_chat = RadioToolButton( named_icon='mode-chat', group=mode_type, tooltip=_('Voice chat')) self._mode_chat.connect('toggled', self.__toggled_mode_chat_cb) toolbox.toolbar.insert(self._mode_chat, -1) self._voice_button = ToolbarButton( page=self._make_voice_bar(), label=_('Voice'), icon_name='voice') self._voice_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._voice_button, -1) self._face_button = ToolbarButton( page=self._make_face_bar(), label=_('Face'), icon_name='face') self._face_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._face_button, -1) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) toolbox.toolbar.insert(separator, -1) toolbox.toolbar.insert(StopButton(self), -1) toolbox.show_all() self.toolbar_box = toolbox gtk.gdk.screen_get_default().connect('size-changed', self._configure_cb) self._first_time = True self._new_instance() self._configure_cb() self._poll_accelerometer() if self.shared_activity: # we are joining the activity self.connect('joined', self._joined_cb) if self.get_shared(): # we have already joined self._joined_cb(self) self._mode_chat.set_active(True) self._setup_chat_mode() elif handle.uri: # XMPP non-sugar3 incoming chat, not sharable self._activity_button.props.page.share.props.visible = \ False self._one_to_one_connection(handle.uri) else: # we are creating the activity self.connect('shared', self._shared_cb) def _toolbar_expanded(self): if self._activity_button.is_expanded(): return True if self._voice_button.is_expanded(): return True if self._face_button.is_expanded(): return True return False def _configure_cb(self, event=None): self._entry.set_size_request(-1, style.GRID_CELL_SIZE) if self._toolbar_expanded(): self.face.set_size_request( -1, gtk.gdk.screen_height() - 3 * style.GRID_CELL_SIZE) self._chat.resize_chat_box(expanded=True) self._chat.resize_buddy_list() else: self.face.set_size_request( -1, gtk.gdk.screen_height() - 2 * style.GRID_CELL_SIZE) self._chat.resize_chat_box() self._chat.resize_buddy_list() def _new_instance(self): if self._first_time: # self.voices.connect('changed', self.__changed_voices_cb) self.pitchadj.connect('value_changed', self._pitch_adjusted_cb, self.pitchadj) self.rateadj.connect('value_changed', self._rate_adjusted_cb, self.rateadj) if self._active_number_of_eyes is None: self._number_of_eyes_changed_event_cb(None, None, 'two', True) if self._active_eyes is None: self._eyes_changed_event_cb(None, None, 'eyes', True) self._mouth_changed_cb(None, True) self.face.look_ahead() presenceService = presenceservice.get_instance() self.owner = presenceService.get_owner() if self._first_time: # say hello to the user if self._tablet_mode: self._entry.props.text = _('Hello %s.') \ % self.owner.props.nick.encode('utf-8', 'ignore') self.face.say_notification(_('Hello %s. Please Type something.') % self.owner.props.nick) else: if self._tablet_mode: self._entry.props.text = _('Welcome back %s.') \ % self.owner.props.nick.encode('utf-8', 'ignore') self.face.say_notification(_('Welcome back %s.') % self.owner.props.nick) self._set_idle_phrase(speak=False) self._first_time = False def read_file(self, file_path): self._cfg = json.loads(file(file_path, 'r').read()) current_voice = self.face.status.voice status = self.face.status = \ face.Status().deserialize(self._cfg['status']) found_my_voice = False for name in self._voice_evboxes.keys(): if self._voice_evboxes[name][1] == current_voice: self._voice_evboxes[name][0].modify_bg( 0, style.COLOR_BLACK.get_gdk_color()) if self._voice_evboxes[name][1] == status.voice and \ not found_my_voice: self._voice_evboxes[name][0].modify_bg( 0, style.COLOR_BUTTON_GREY.get_gdk_color()) self.face.set_voice(status.voice) if self._mode == MODE_BOT: brain.load(self, status.voice) found_my_voice = True self.pitchadj.value = self.face.status.pitch self.rateadj.value = self.face.status.rate if status.mouth in MOUTHS: self._mouth_type[MOUTHS.index(status.mouth)].set_active(True) self._number_of_eyes_changed_event_cb( None, None, NUMBERS[len(status.eyes) - 1], True) for name in EYE_DICT.keys(): if status.eyes[0] == EYE_DICT[name]['widget']: self._eye_type[name].set_icon(name + '-selected') self._eyes_changed_event_cb(None, None, name, True) break self._entry.props.text = self._cfg['text'].encode('utf-8', 'ignore') if not self._tablet_mode: for i in self._cfg['history']: self._entrycombo.append_text(i.encode('utf-8', 'ignore')) self._new_instance() def write_file(self, file_path): if self._tablet_mode: if 'history' in self._cfg: history = self._cfg['history'] # retain old history else: history = [] else: history = [unicode(i[0], 'utf-8', 'ignore') for i in self._entrycombo.get_model()] cfg = {'status': self.face.status.serialize(), 'text': unicode(self._entry.props.text, 'utf-8', 'ignore'), 'history': history, } file(file_path, 'w').write(json.dumps(cfg)) def _cursor_moved_cb(self, entry, *ignored): # make the eyes track the motion of the text cursor index = entry.props.cursor_position layout = entry.get_layout() pos = layout.get_cursor_pos(index) x = pos[0][0] / pango.SCALE - entry.props.scroll_offset y = entry.get_allocation().y self.face.look_at(pos=(x, y)) def _poll_accelerometer(self): if _has_accelerometer(): idle_time = self._test_orientation() gobject.timeout_add(idle_time, self._poll_accelerometer) def _test_orientation(self): if _has_accelerometer(): fh = open(ACCELEROMETER_DEVICE) string = fh.read() fh.close() xyz = string[1:-2].split(',') x = int(xyz[0]) y = int(xyz[1]) # DO SOMETHING HERE if ((gtk.gdk.screen_width() > gtk.gdk.screen_height() and abs(x) > abs(y)) or (gtk.gdk.screen_width() < gtk.gdk.screen_height() and abs(x) < abs(y))): sideways_phrase = SIDEWAYS_PHRASES[ random.randint(0, len(SIDEWAYS_PHRASES) - 1)] self.face.say(SIDEWAYS_PHRASES[sideways_phrase]) return IDLE_DELAY # Don't repeat the message for a while return 1000 # Test again soon def get_mouse(self): display = gtk.gdk.display_get_default() screen, mouseX, mouseY, modifiers = display.get_pointer() return mouseX, mouseY def _mouse_moved_cb(self, widget, event): # make the eyes track the motion of the mouse cursor self.face.look_at() self._chat.look_at() def _mouse_clicked_cb(self, widget, event): pass 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) pitchbar = gtk.HScale(self.pitchadj) pitchbar.set_draw_value(False) # pitchbar.set_inverted(True) pitchbar.set_update_policy(gtk.UPDATE_DISCONTINUOUS) pitchbar.set_size_request(240, 15) pitchbar_toolitem = ToolWidget(widget=pitchbar, label_text=_('Pitch:')) voicebar.insert(pitchbar_toolitem, -1) self.rateadj = gtk.Adjustment(self.face.status.rate, 0, espeak.RATE_MAX, 1, espeak.RATE_MAX / 10, 0) ratebar = gtk.HScale(self.rateadj) ratebar.set_draw_value(False) # ratebar.set_inverted(True) ratebar.set_update_policy(gtk.UPDATE_DISCONTINUOUS) ratebar.set_size_request(240, 15) ratebar_toolitem = ToolWidget(widget=ratebar, label_text=_('Rate:')) voicebar.insert(ratebar_toolitem, -1) voicebar.show_all() return voicebar def _pitch_adjusted_cb(self, get, data=None): self.face.status.pitch = get.value self.face.say_notification(_('pitch adjusted')) def _rate_adjusted_cb(self, get, data=None): self.face.status.rate = get.value self.face.say_notification(_('rate adjusted')) 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 def _face_palette_cb(self, button): palette = button.get_palette() if palette: if not palette.is_up(): palette.popup(immediate=True, state=palette.SECONDARY) else: palette.popdown(immediate=True) def _get_active_mouth(self): for i, button in enumerate(self._mouth_type): if button.get_active(): return MOUTHS[i] def _mouth_changed_cb(self, ignored, quiet): value = self._get_active_mouth() if value is None: return self.face.status.mouth = value self._update_face() # this SegFaults: self.face.say(combo.get_active_text()) if not quiet: self.face.say_notification(_('mouth changed')) def _voices_changed_event_cb(self, widget, event, voice): logging.error('voices_changed_event_cb %r %s' % (voice[0], voice[1])) if self._mode == MODE_BOT: evboxes = self._brain_evboxes else: evboxes = self._voice_evboxes for old_voice in evboxes.keys(): if evboxes[old_voice][1] == self.face.status.voice: evboxes[old_voice][0].modify_bg( 0, style.COLOR_BLACK.get_gdk_color()) break evboxes[voice[1]][0].modify_bg( 0, style.COLOR_BUTTON_GREY.get_gdk_color()) self.face.set_voice(voice[0]) if self._mode == MODE_BOT: brain.load(self, voice[0]) else: self._current_voice = voice def _get_active_eyes(self): for name in EYE_DICT.keys(): if EYE_DICT[name]['index'] == self._active_eyes: return EYE_DICT[name]['widget'] return None def _eyes_changed_event_cb(self, widget, event, name, quiet): if self._active_eyes is not None: for old_name in EYE_DICT.keys(): if EYE_DICT[old_name]['index'] == self._active_eyes: self._eye_type[old_name].set_icon(old_name) break if self._active_number_of_eyes is None: self._active_number_of_eyes = 2 if name is not None: self._active_eyes = EYE_DICT[name]['index'] self._eye_type[name].set_icon(name + '-selected') value = EYE_DICT[name]['widget'] self.face.status.eyes = [value] * self._active_number_of_eyes self._update_face() if not quiet: self.face.say_notification(_('eyes changed')) def _number_of_eyes_changed_event_cb(self, widget, event, name, quiet): if self._active_number_of_eyes is not None: old_name = NUMBERS[self._active_number_of_eyes - 1] self._number_of_eyes_type[old_name].set_icon(old_name) if name in NUMBERS: self._active_number_of_eyes = NUMBERS.index(name) + 1 self._number_of_eyes_type[name].set_icon(name + '-selected') if self._active_eyes is not None: for eye_name in EYE_DICT.keys(): if EYE_DICT[eye_name]['index'] == self._active_eyes: value = EYE_DICT[eye_name]['widget'] self.face.status.eyes = \ [value] * self._active_number_of_eyes self._update_face() if not quiet: self.face.say_notification(_('eyes changed')) break def _update_face(self): self.face.update() self._chat.update(self.face.status) def _combo_changed_cb(self, combo): # when a new item is chosen, make sure the text is selected if not self._entry.is_focus(): if not self._tablet_mode: self._entry.grab_focus() self._entry.select_region(0, -1) def _entry_key_press_cb(self, combo, event): # make the up/down arrows navigate through our history if self._tablet_mode: return keyname = gtk.gdk.keyval_name(event.keyval) if keyname == 'Up': index = self._entrycombo.get_active() if index > 0: index -= 1 self._entrycombo.set_active(index) self._entry.select_region(0, -1) return True elif keyname == 'Down': index = self._entrycombo.get_active() if index < len(self._entrycombo.get_model()) - 1: index += 1 self._entrycombo.set_active(index) self._entry.select_region(0, -1) return True return False def _entry_activate_cb(self, entry): # the user pressed Return, say the text and clear it out text = entry.props.text if self._tablet_mode: self._dismiss_OSK(entry) timeout = DELAY_BEFORE_SPEAKING else: timeout = 100 gobject.timeout_add(timeout, self._speak_the_text, entry, text) def _dismiss_OSK(self, entry): entry.hide() entry.show() def _talk_cb(self, button): text = self._entry.props.text self._speak_the_text(self._entry, text) def _speak_the_text(self, entry, text): self._remove_idle() if text: self.face.look_ahead() # speak the text if self._mode == MODE_BOT: self.face.say(brain.respond(text)) else: self.face.say(text) if text and not self._tablet_mode: # add this text to our history unless it is the same as # the last item history = self._entrycombo.get_model() if len(history) == 0 or history[-1][0] != text: self._entrycombo.append_text(text) # don't let the history get too big while len(history) > 20: self._entrycombo.remove_text(0) # select the new item self._entrycombo.set_active(len(history) - 1) if text: # select the whole text entry.select_region(0, -1) # Launch an robot idle phase after 2 minutes self._robot_idle_id = gobject.timeout_add(IDLE_DELAY, self._set_idle_phrase) def _load_sleeping_face(self): current_eyes = self.face.status.eyes self.face.status.eyes = [SLEEPY_EYES] * self._active_number_of_eyes self._update_face() self.face.status.eyes = current_eyes def _set_idle_phrase(self, speak=True): if speak: self._load_sleeping_face() idle_phrase = IDLE_PHRASES[random.randint( 0, len(IDLE_PHRASES) - 1)] if self.props.active: self.face.say(idle_phrase) self._robot_idle_id = gobject.timeout_add(IDLE_DELAY, self._set_idle_phrase) def _active_cb(self, widget, pspec): # only generate sound when this activity is active if not self.props.active: self._load_sleeping_face() self.face.shut_up() self._chat.shut_up() def _set_voice(self, new_voice=None): if new_voice is not None: logging.error('set_voice %r' % new_voice) self.face.status.voice = new_voice else: logging.error('set_voice to current voice %s' % self._current_voice[1]) self.face.status.voice = self._current_voice[0] def __toggled_mode_type_cb(self, button): if not button.props.active: return self._mode = MODE_TYPE self._chat.shut_up() self.face.shut_up() self._notebook.set_current_page(0) self._voice_palette.set_content(self._voice_box) self._set_voice() def __toggled_mode_robot_cb(self, button): if not button.props.active: return self._remove_idle() self._mode = MODE_BOT self._chat.shut_up() self.face.shut_up() self._notebook.set_current_page(0) self._voice_palette.set_content(self._brain_box) new_voice = None for name in brain.BOTS.keys(): if self._current_voice[0].short_name == name: new_voice == self._current_voice[0] break if new_voice is None: new_voice = brain.get_default_voice() if new_voice.friendlyname in self._current_voice[0].friendlyname: logging.debug('skipping sorry message for %s %s' % (new_voice.friendlyname, self._current_voice[0].friendlyname)) sorry = None else: sorry = _("Sorry, I can't speak %(old_voice)s, " "let's talk %(new_voice)s instead.") % { 'old_voice': self._current_voice[0].friendlyname, 'new_voice': new_voice.friendlyname} else: new_voice = new_voice[0] sorry = None self._set_voice(new_voice) evboxes = self._brain_evboxes for old_voice in evboxes.keys(): evboxes[old_voice][0].modify_bg( 0, style.COLOR_BLACK.get_gdk_color()) if new_voice.short_name in evboxes: evboxes[new_voice.short_name][0].modify_bg( 0, style.COLOR_BUTTON_GREY.get_gdk_color()) if not brain.load(self, new_voice, sorry): if sorry: self.face.say_notification(sorry) def __toggled_mode_chat_cb(self, button): if not button.props.active: return self._remove_idle() is_first_session = not self.shared_activity self._setup_chat_mode() if is_first_session: self._chat.me.say_notification( _('You are in off-line mode, share and invite someone.')) def _remove_idle(self): if self._robot_idle_id is not None: gobject.source_remove(self._robot_idle_id) value = self._get_active_eyes() if value is not None: self.face.status.eyes = [value] * self._active_number_of_eyes self._update_face() def _setup_chat_mode(self): self._mode = MODE_CHAT self._remove_idle() self.face.shut_up() self._notebook.set_current_page(1) self._voice_palette.set_content(self._voice_box) self._set_voice() def _shared_cb(self, sender): logging.error('SHARED A CHAT') self._setup_text_channel() def _joined_cb(self, sender): '''Joined a shared activity.''' if not self.shared_activity: return logger.error('JOINED A SHARED CHAT') for buddy in self.shared_activity.get_joined_buddies(): self._buddy_already_exists(buddy) self._setup_text_channel() def _one_to_one_connection(self, tp_channel): '''Handle a private invite from a non-sugar3 XMPP client.''' if self.shared_activity or self.text_channel: return bus_name, connection, channel = json.loads(tp_channel) logger.debug('GOT XMPP: %s %s %s', bus_name, connection, channel) Connection(bus_name, connection, ready_handler=lambda conn: self._one_to_one_connection_ready_cb( bus_name, channel, conn)) def _one_to_one_connection_ready_cb(self, bus_name, channel, conn): '''Callback for Connection for one to one connection''' text_channel = Channel(bus_name, channel) self.text_channel = TextChannelWrapper(text_channel, conn) self.text_channel.set_received_callback(self._received_cb) self.text_channel.handle_pending_messages() self.text_channel.set_closed_callback( self._one_to_one_connection_closed_cb) # XXX How do we detect the sender going offline? self._chat.chat_post.set_sensitive(True) # self._chat.chat_post.props.placeholder_text = None self._chat.chat_post.grab_focus() def _one_to_one_connection_closed_cb(self): '''Callback for when the text channel closes.''' pass def _setup_text_channel(self): logging.error('_SETUP_TEXTCHANNEL') self.text_channel = TextChannelWrapper( self.shared_activity.telepathy_text_chan, self.shared_activity.telepathy_conn) self.text_channel.set_received_callback(self._received_cb) self.shared_activity.connect('buddy-joined', self._buddy_joined_cb) self.shared_activity.connect('buddy-left', self._buddy_left_cb) self._chat.messenger = self.text_channel self._chat.chat_post.set_sensitive(True) self._chat.chat_post.grab_focus() def _buddy_joined_cb(self, sender, buddy): '''Show a buddy who joined''' if buddy == self.owner: return logging.error('%s joined the chat (%r)' % (buddy.props.nick, buddy)) self._chat.post( buddy, _('%s joined the chat') % buddy.props.nick, status_message=True) def _buddy_left_cb(self, sender, buddy): '''Show a buddy who joined''' if buddy == self.owner: return logging.error('%s left the chat (%r)' % (buddy.props.nick, buddy)) self._chat.post( buddy, _('%s left the chat') % buddy.props.nick, status_message=True) self._chat.farewell(buddy) def _buddy_already_exists(self, buddy): '''Show a buddy already in the chat.''' if buddy == self.owner: return logging.error('%s is here (%r)' % (buddy.props.nick, buddy)) self._chat.post( buddy, _('%s is here') % buddy.props.nick, status_message=True) def _received_cb(self, buddy, text): '''Show message that was received.''' if buddy: if type(buddy) is dict: nick = buddy['nick'] else: nick = buddy.props.nick else: nick = '???' logger.debug('Received message from %s: %s', nick, text) self._chat.post(buddy, text)
def __init__(self, handle): super(SpeakActivity, self).__init__(handle) self._notebook = gtk.Notebook() self.set_canvas(self._notebook) self._notebook.show() self._colors = profile.get_color().to_string().split(',') lighter = style.Color(self._colors[ _lighter_color(self._colors)]) self._mode = MODE_TYPE self._tablet_mode = _is_tablet_mode() self._robot_idle_id = None self._active_eyes = None self._active_number_of_eyes = None self._current_voice = None # make an audio device for playing back and rendering audio self.connect('notify::active', self._active_cb) self._cfg = {} # make a box to type into hbox = gtk.HBox() if self._tablet_mode: self._entry = gtk.Entry() hbox.pack_start(self._entry, expand=True) talk_button = ToolButton('microphone') talk_button.set_tooltip(_('Speak')) talk_button.connect('clicked', self._talk_cb) hbox.pack_end(talk_button, expand=False) else: self._entrycombo = gtk.combo_box_entry_new_text() self._entrycombo.connect('changed', self._combo_changed_cb) self._entry = self._entrycombo.child self._entry.set_size_request(-1, style.GRID_CELL_SIZE) hbox.pack_start(self._entrycombo, expand=True) self._entry.set_editable(True) self._entry.connect('activate', self._entry_activate_cb) self._entry.connect('key-press-event', self._entry_key_press_cb) self._entry.modify_font(pango.FontDescription(str='sans bold 24')) hbox.show() self.face = face.View(fill_color=lighter) self.face.set_size_request( -1, gtk.gdk.screen_height() - 2 * style.GRID_CELL_SIZE) self.face.show() # layout the screen box = gtk.VBox(homogeneous=False) if self._tablet_mode: box.pack_start(hbox, expand=False) box.pack_start(self.face) else: box.pack_start(self.face, expand=True) box.pack_start(hbox) self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.POINTER_MOTION_MASK) self.connect('motion_notify_event', self._mouse_moved_cb) box.add_events(gtk.gdk.BUTTON_PRESS_MASK) box.connect('button_press_event', self._mouse_clicked_cb) # desktop self._notebook.show() self._notebook.props.show_border = False self._notebook.props.show_tabs = False box.show_all() self._notebook.append_page(box) self._chat = chat.View() self._chat.show_all() self._notebook.append_page(self._chat) # make the text box active right away if not self._tablet_mode: self._entry.grab_focus() self._entry.connect('move-cursor', self._cursor_moved_cb) self._entry.connect('changed', self._cursor_moved_cb) toolbox = ToolbarBox() self._activity_button = ActivityToolbarButton(self) self._activity_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._activity_button, -1) mode_type = RadioToolButton( named_icon='mode-type', tooltip=_('Type something to hear it')) mode_type.connect('toggled', self.__toggled_mode_type_cb) toolbox.toolbar.insert(mode_type, -1) mode_robot = RadioToolButton( named_icon='mode-robot', group=mode_type, tooltip=_('Ask robot any question')) mode_robot.connect('toggled', self.__toggled_mode_robot_cb) toolbox.toolbar.insert(mode_robot, -1) self._mode_chat = RadioToolButton( named_icon='mode-chat', group=mode_type, tooltip=_('Voice chat')) self._mode_chat.connect('toggled', self.__toggled_mode_chat_cb) toolbox.toolbar.insert(self._mode_chat, -1) self._voice_button = ToolbarButton( page=self._make_voice_bar(), label=_('Voice'), icon_name='voice') self._voice_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._voice_button, -1) self._face_button = ToolbarButton( page=self._make_face_bar(), label=_('Face'), icon_name='face') self._face_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._face_button, -1) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) toolbox.toolbar.insert(separator, -1) toolbox.toolbar.insert(StopButton(self), -1) toolbox.show_all() self.toolbar_box = toolbox gtk.gdk.screen_get_default().connect('size-changed', self._configure_cb) self._first_time = True self._new_instance() self._configure_cb() self._poll_accelerometer() if self.shared_activity: # we are joining the activity self.connect('joined', self._joined_cb) if self.get_shared(): # we have already joined self._joined_cb(self) self._mode_chat.set_active(True) self._setup_chat_mode() elif handle.uri: # XMPP non-sugar3 incoming chat, not sharable self._activity_button.props.page.share.props.visible = \ False self._one_to_one_connection(handle.uri) else: # we are creating the activity self.connect('shared', self._shared_cb)
class HomeToolbar(gtk.Toolbar): __gtype_name__ = 'SugarHomeToolbar' __gsignals__ = { 'query-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([str])), 'view-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object])), } def __init__(self): gtk.Toolbar.__init__(self) self._query = None self._autosearch_timer = None self._add_separator() tool_item = gtk.ToolItem() self.insert(tool_item, -1) tool_item.show() self.search_entry = iconentry.IconEntry() self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY, 'system-search') self.search_entry.add_clear_button() self.search_entry.set_width_chars(25) self.search_entry.connect('activate', self.__entry_activated_cb) self.search_entry.connect('changed', self.__entry_changed_cb) tool_item.add(self.search_entry) self.search_entry.show() self._add_separator(expand=True) favorites_button = FavoritesButton() favorites_button.connect('toggled', self.__view_button_toggled_cb, _FAVORITES_VIEW) self.insert(favorites_button, -1) favorites_button.show() self._list_button = RadioToolButton(named_icon='view-list') self._list_button.props.group = favorites_button self._list_button.props.tooltip = _('List view') self._list_button.props.accelerator = _('<Ctrl>2') self._list_button.connect('toggled', self.__view_button_toggled_cb, _LIST_VIEW) self.insert(self._list_button, -1) self._list_button.show() self._add_separator() def __view_button_toggled_cb(self, button, view): if button.props.active: self.search_entry.grab_focus() self.emit('view-changed', view) def _add_separator(self, expand=False): separator = gtk.SeparatorToolItem() separator.props.draw = False if expand: separator.set_expand(True) else: separator.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE) self.insert(separator, -1) separator.show() def __entry_activated_cb(self, entry): if self._autosearch_timer: gobject.source_remove(self._autosearch_timer) new_query = entry.props.text if self._query != new_query: self._query = new_query self.emit('query-changed', self._query) def __entry_changed_cb(self, entry): if not entry.props.text: entry.activate() return if self._autosearch_timer: gobject.source_remove(self._autosearch_timer) self._autosearch_timer = gobject.timeout_add( _AUTOSEARCH_TIMEOUT, self.__autosearch_timer_cb) def __autosearch_timer_cb(self): self._autosearch_timer = None self.search_entry.activate() return False
def __init__(self, owner): gtk.Toolbar.__init__(self) self.owner = owner self.toolItem = {} self.blockBeat = False self.beatWheel = [] btn = RadioToolButton(group=None) btn.set_named_icon('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_named_icon('beats') btn.connect('toggled', self.setBeat, i) btn.set_tooltip(_('Jump To Beat')) self.insert(btn, -1) self.beatWheel.append(btn) label = gtk.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 radio_factory(button_name, toolbar, callback, cb_arg=None, tooltip=None, group=None): ''' Add a radio button to a toolbar ''' button = RadioToolButton(group=group) button.set_named_icon(button_name) if callback is not None: if cb_arg is None: button.connect('clicked', callback) else: button.connect('clicked', callback, cb_arg) if hasattr(toolbar, 'insert'): # Add button to the main toolbar... toolbar.insert(button, -1) else: # ...or a secondary toolbar. toolbar.props.page.insert(button, -1) button.show() if tooltip is not None: button.set_tooltip(tooltip) return button
def ui_init(self): self._fullscreen = False self._showing_info = False # FIXME: if _thumb_tray becomes some kind of button group, we wouldn't # have to track which recd is active self._active_recd = None self.connect_after('key-press-event', self._key_pressed) self._active_toolbar_idx = 0 self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) self._toolbar_box.toolbar.insert(activity_button, 0) self.set_toolbar_box(self._toolbar_box) self._toolbar = self.get_toolbar_box().toolbar tool_group = None if self.model.get_has_camera(): self._photo_button = RadioToolButton() self._photo_button.props.group = tool_group tool_group = self._photo_button self._photo_button.props.icon_name = 'camera-external' self._photo_button.props.label = _('Photo') self._photo_button.mode = constants.MODE_PHOTO self._photo_button.connect('clicked', self._mode_button_clicked) self._toolbar.insert(self._photo_button, -1) self._video_button = RadioToolButton() self._video_button.props.group = tool_group self._video_button.props.icon_name = 'media-video' self._video_button.props.label = _('Video') self._video_button.mode = constants.MODE_VIDEO self._video_button.connect('clicked', self._mode_button_clicked) self._toolbar.insert(self._video_button, -1) else: self._photo_button = None self._video_button = None self._audio_button = RadioToolButton() self._audio_button.props.group = tool_group self._audio_button.props.icon_name = 'media-audio' self._audio_button.props.label = _('Audio') self._audio_button.mode = constants.MODE_AUDIO self._audio_button.connect('clicked', self._mode_button_clicked) self._toolbar.insert(self._audio_button, -1) self._toolbar.insert(gtk.SeparatorToolItem(), -1) self._toolbar_controls = RecordControl(self._toolbar) 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) main_box.get_parent().modify_bg(gtk.STATE_NORMAL, COLOR_BLACK) main_box.show() self._media_view = MediaView() self._media_view.connect('media-clicked', self._media_view_media_clicked) self._media_view.connect('pip-clicked', self._media_view_pip_clicked) self._media_view.connect('info-clicked', self._media_view_info_clicked) self._media_view.connect('full-clicked', self._media_view_full_clicked) self._media_view.connect('tags-changed', self._media_view_tags_changed) self._media_view.show() self._controls_hbox = gtk.HBox() self._controls_hbox.show() self._shutter_button = ShutterButton() self._shutter_button.connect("clicked", self._shutter_clicked) self._controls_hbox.pack_start(self._shutter_button, expand=True, fill=False) self._countdown_image = CountdownImage() self._controls_hbox.pack_start(self._countdown_image, expand=True, fill=False) self._play_button = PlayButton() self._play_button.connect('clicked', self._play_pause_clicked) self._controls_hbox.pack_start(self._play_button, expand=False) self._playback_scale = PlaybackScale(self.model) self._controls_hbox.pack_start(self._playback_scale, expand=True, fill=True) self._progress = ProgressInfo() self._controls_hbox.pack_start(self._progress, expand=True, fill=True) self._title_label = gtk.Label() self._title_label.set_markup("<b><span foreground='white'>"+_('Title:')+'</span></b>') self._controls_hbox.pack_start(self._title_label, expand=False) self._title_entry = gtk.Entry() self._title_entry.modify_bg(gtk.STATE_INSENSITIVE, COLOR_BLACK) self._title_entry.connect('changed', self._title_changed) self._controls_hbox.pack_start(self._title_entry, expand=True, fill=True, padding=10) container = RecordContainer(self._media_view, self._controls_hbox) main_box.pack_start(container, expand=True, fill=True, padding=6) container.show() self._thumb_tray = HTray() self._thumb_tray.set_size_request(-1, 150) main_box.pack_end(self._thumb_tray, expand=False) self._thumb_tray.show_all()
def __init__(self, activity, channels): ''' By default, start with resistance mode ''' gtk.Toolbar.__init__(self) self.activity = activity self._channels = channels self._lock_radio_buttons = False self._radio_button_pushed = False self.values = [] for i in range(self._channels): self.values.append('') self.string_for_textbox = '' self.gain = 1.0 self.y_mag = 3.0 self.capture_gain = CAPTURE_GAIN self.mic_boost = MIC_BOOST self.mode = 'sound' # Set up Time-domain Button self.time = RadioToolButton(group=None) self.time.set_named_icon('media-audio') self.insert(self.time, -1) self.time.set_tooltip(_('Sound')) self.time.connect('clicked', self.analog_resistance_voltage_mode_cb, 'sound') # Set up Resistance Button self.resistance = RadioToolButton(group=self.time) self.resistance.set_named_icon('resistance') if _is_xo(self.activity.hw): self.insert(self.resistance, -1) self.resistance.show() self.resistance.set_tooltip(_('Resistance Sensor')) self.resistance.connect('clicked', self.analog_resistance_voltage_mode_cb, 'resistance') # Set up Voltage Button self.voltage = RadioToolButton(group=self.time) self.voltage.set_named_icon('voltage') if _is_xo(self.activity.hw): self.insert(self.voltage, -1) self.voltage.set_tooltip(_('Voltage Sensor')) self.voltage.connect('clicked', self.analog_resistance_voltage_mode_cb, 'voltage') separator = gtk.SeparatorToolItem() separator.props.draw = True self.insert(separator, -1) self._log_interval_combo = ComboBox() self.interval = [ _('1/10 second'), _('1 second'), _('30 seconds'), _('5 minutes'), _('30 minutes') ] if hasattr(self._log_interval_combo, 'set_tooltip_text'): self._log_interval_combo.set_tooltip_text(_('Sampling interval')) self._interval_changed_id = self._log_interval_combo.connect( 'changed', self.log_interval_cb) for i, s in enumerate(self.interval): self._log_interval_combo.append_item(i, s, None) if s == _('1 second'): self._log_interval_combo.set_active(i) self._log_interval_tool = ToolComboBox(self._log_interval_combo) self.insert(self._log_interval_tool, -1) self.logging_interval_status = '1 second' # Set up Logging/Stop Logging Button self._record = ToolButton('media-record') self.insert(self._record, -1) self._record.set_tooltip(_('Start Recording')) self._record.connect('clicked', self.record_control_cb) if self.activity.has_toolbarbox: separator = gtk.SeparatorToolItem() separator.props.draw = True self.insert(separator, -1) # Set up Trigger Combo box self.trigger_combo = ComboBox() self.trigger = [_('None'), _('Rising Edge'), _('Falling Edge')] self.trigger_conf = [ self.activity.wave.TRIGGER_NONE, self.activity.wave.TRIGGER_POS, self.activity.wave.TRIGGER_NEG ] self._trigger_changed_id = self.trigger_combo.connect( 'changed', self.update_trigger_control) for i, s in enumerate(self.trigger): self.trigger_combo.append_item(i, s, None) self.trigger_combo.set_active(0) if hasattr(self.trigger_combo, 'set_tooltip_text'): self.trigger_combo.set_tooltip_text(_('Create a trigger')) self._trigger_tool = ToolComboBox(self.trigger_combo) self.insert(self._trigger_tool, -1) self.show_all()
def ui_init(self): self._fullscreen = False self._showing_info = False # FIXME: if _thumb_tray becomes some kind of button group, we wouldn't # have to track which recd is active self._active_recd = None self.connect_after("key-press-event", self._key_pressed) self._active_toolbar_idx = 0 self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) self._toolbar_box.toolbar.insert(activity_button, 0) self.set_toolbar_box(self._toolbar_box) self._toolbar = self.get_toolbar_box().toolbar tool_group = None if self.model.get_has_camera(): self._photo_button = RadioToolButton() self._photo_button.props.group = tool_group tool_group = self._photo_button self._photo_button.props.icon_name = "camera-external" self._photo_button.props.label = _("Photo") self._photo_button.mode = constants.MODE_PHOTO self._photo_button.connect("clicked", self._mode_button_clicked) self._toolbar.insert(self._photo_button, -1) self._video_button = RadioToolButton() self._video_button.props.group = tool_group self._video_button.props.icon_name = "media-video" self._video_button.props.label = _("Video") self._video_button.mode = constants.MODE_VIDEO self._video_button.connect("clicked", self._mode_button_clicked) self._toolbar.insert(self._video_button, -1) else: self._photo_button = None self._video_button = None self._audio_button = RadioToolButton() self._audio_button.props.group = tool_group self._audio_button.props.icon_name = "media-audio" self._audio_button.props.label = _("Audio") self._audio_button.mode = constants.MODE_AUDIO self._audio_button.connect("clicked", self._mode_button_clicked) self._toolbar.insert(self._audio_button, -1) self._toolbar.insert(gtk.SeparatorToolItem(), -1) self._toolbar_controls = RecordControl(self._toolbar) 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) main_box.get_parent().modify_bg(gtk.STATE_NORMAL, COLOR_BLACK) main_box.show() self._media_view = MediaView() self._media_view.connect("media-clicked", self._media_view_media_clicked) self._media_view.connect("pip-clicked", self._media_view_pip_clicked) self._media_view.connect("info-clicked", self._media_view_info_clicked) self._media_view.connect("full-clicked", self._media_view_full_clicked) self._media_view.connect("tags-changed", self._media_view_tags_changed) self._media_view.show() self._controls_hbox = gtk.HBox() self._controls_hbox.show() self._shutter_button = ShutterButton() self._shutter_button.connect("clicked", self._shutter_clicked) self._controls_hbox.pack_start(self._shutter_button, expand=True, fill=False) self._countdown_image = CountdownImage() self._controls_hbox.pack_start(self._countdown_image, expand=True, fill=False) self._play_button = PlayButton() self._play_button.connect("clicked", self._play_pause_clicked) self._controls_hbox.pack_start(self._play_button, expand=False) self._playback_scale = PlaybackScale(self.model) self._controls_hbox.pack_start(self._playback_scale, expand=True, fill=True) self._progress = ProgressInfo() self._controls_hbox.pack_start(self._progress, expand=True, fill=True) self._title_label = gtk.Label() self._title_label.set_markup("<b><span foreground='white'>" + _("Title:") + "</span></b>") self._controls_hbox.pack_start(self._title_label, expand=False) self._title_entry = gtk.Entry() self._title_entry.modify_bg(gtk.STATE_INSENSITIVE, COLOR_BLACK) self._title_entry.connect("changed", self._title_changed) self._controls_hbox.pack_start(self._title_entry, expand=True, fill=True, padding=10) self._record_container = RecordContainer(self._media_view, self._controls_hbox) main_box.pack_start(self._record_container, expand=True, fill=True, padding=6) self._record_container.show() self._thumb_tray = HTray() self._thumb_tray.set_size_request(-1, 150) main_box.pack_end(self._thumb_tray, expand=False) self._thumb_tray.show_all()
class Activity(sugar.activity.activity.Activity): def __init__(self, handle): super(Activity, self).__init__(handle) self.paused = False watch = gtk.gdk.Cursor(gtk.gdk.WATCH) self.window.set_cursor(watch) self.p = gtk.VPaned() self.p.connect("notify::position", self.redraw) self.box = gtk.Notebook() self.p.pack2(self.box) self.p.show() self.box.set_show_tabs(False) self.splash = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file("images/splash_comodo.png") screen = self.window.get_screen() width, height = screen.get_width(), screen.get_height() - style.GRID_CELL_SIZE pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR) self.splash.set_from_pixbuf(pixbuf) self.splash.show() eb = gtk.EventBox() eb.add(self.splash) eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white")) eb.show() self.box.append_page(eb, gtk.Label("Inicio")) self._pygamecanvas = sugargame2.canvas.PygameCanvas(self) self._pygamecanvas.set_flags(gtk.EXPAND) self._pygamecanvas.set_flags(gtk.FILL) self.connect("visibility-notify-event", self.redraw) self._pygamecanvas.set_events(gtk.gdk.BUTTON_PRESS_MASK) self._pygamecanvas.connect("button-press-event", self._pygamecanvas.grab_focus) self.box.append_page(self._pygamecanvas, gtk.Label("Juego")) self.box.show() self.set_canvas(self.p) gobject.timeout_add(300, self.pump) gobject.timeout_add(2000, self.init_interpreter) #gobject.timeout_add(1000, self.build_editor) gobject.timeout_add(1500, self.check_modified) self.build_toolbar() self.credits = None self.editor = None #self.reader = None self._pygamecanvas.run_pygame(self.run_game) def redraw(self, widget=None, b=None, c=None): scene = spyral.director.get_scene() if scene: scene.redraw() def alert(self, title=None, text=None, delay=5): alert = NotifyAlert(delay) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_ok) alert.show() def _alert_ok(self, alert, *args): self.remove_alert(alert) def check_modified(self): if self.box.current_page()==2: if not self.save_button.get_sensitive(): if self.editor.modificado(): self.save_button.set_sensitive(True) return False return True def pump(self): # Esto es necesario porque sino pygame acumula demasiados eventos. pygame.event.pump() def focus_interpreter(self, widget, event): self._interpreter.text.grab_focus() return True def init_interpreter(self): # diferido unos segundos para evitar ver errores superfluos al iniciar self._interpreter = GTKInterpreterConsole(self.redraw) self._interpreter.text.connect('button-press-event', self.focus_interpreter) self.p.pack1(self._interpreter) return False def open_file(self, widget, path): if path: if not os.path.isdir(path): self.editor.open_file(widget, path) def save_file(self, widget): if self.editor.modificado(): self.save_button.set_sensitive(False) self.editor.save_file() filename = self.editor.current_file() self.alert(filename, "Archivo guardado.") gobject.timeout_add(1500, self.check_modified) def build_editor(self): dir_real = os.getcwd() f = os.path.realpath(JUEGO.__file__) f = "." + f.replace(dir_real ,"") # todo esto para obtener una ruta relativa f = f.rstrip("c") # en caso que sea .pyc compilado self.h = gtk.HPaned() self.tree = FileViewer(".", os.path.basename(f)) self.tree.connect("file-selected", self.open_file) self.tree.show() self.h.pack1(self.tree) self.box.append_page(self.h, gtk.Label("Editor")) if False: #os.path.isfile("/usr/bin/gvim"): # Si podemos, lo hacemos self.socket = gtk.Socket() self.socket.show() self.h.pack2(self.socket) sock_id = str(self.socket.get_id()) self.editor = VimSourceView(sock_id) if not self.editor.bufInfo.bufferList: f = JUEGO.__file__ if f.endswith("pyc"): f = f[:-1] self.open_file(None, f) else: self.editor = SourceView() scroller = gtk.ScrolledWindow() scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroller.add(self.editor) scroller.show() self.h.pack2(scroller) self.editor.show() self.h.show() self.open_file(None, f) def build_reader(self): self.reader = webkit.WebView() curdir = os.getcwd() self.reader.load_uri("file://%s/docs/index.html" % curdir) self.box.append_page(self.reader, gtk.Label("Lector")) self.reader.show() def build_toolbar(self): toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.show() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, -1) activity_button.show() tool_group = None self.game_button = RadioToolButton() self.game_button.props.icon_name = 'gamecanvas' self.game_button.set_tooltip(_('Juego')) self.game_button.accelerator = "<Ctrl>1" self.game_button.props.group = tool_group self.game_button.connect('clicked', self.show_game) toolbar_box.toolbar.insert(self.game_button, -1) self.game_button.show() tool_group = self.game_button button = RadioToolButton() button.props.icon_name = 'view-source' button.set_tooltip(_('Editor')) button.accelerator = "<Ctrl>2" button.props.group = tool_group button.connect('clicked', self.show_editor) toolbar_box.toolbar.insert(button, -1) button.show() self.save_button = ToolButton('dialog-ok') self.save_button.set_tooltip(_('Guardar')) self.save_button.accelerator = "<Ctrl>s" self.save_button.connect('clicked', self.save_file) self.save_button.set_sensitive(False) toolbar_box.toolbar.insert(self.save_button, -1) self.save_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() button = ToolButton('system-restart') button.set_tooltip(_('Reiniciar juego')) button.accelerator = "<Alt><Shift>r" button.connect('clicked', self.restart_game) toolbar_box.toolbar.insert(button, -1) button.show() self.editor_button = ToolButton('sources') self.editor_button.set_tooltip(_('Consola')) self.editor_button.accelerator = "<Ctrl>grave" self.editor_button.connect('clicked', self.toggle_console) toolbar_box.toolbar.insert(self.editor_button, -1) self.editor_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() button = helpbutton.HelpButton(self) toolbar_box.toolbar.insert(button, -1) button.show() button = ToolButton() button.props.icon_name = 'activity-about' button.set_tooltip(_('Acerca de')) button.accelerator = "<Ctrl>i" button.connect('clicked', self.run_credits) toolbar_box.toolbar.insert(button, -1) button.show() # Blank space (separator) and Stop button at the end: 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 run_game(self): spyral.director.init((0,0), fullscreen=False, max_fps=30) self.game = JUEGO.Juego(self, callback=self.game_ready) self.box.connect("switch-page", self.redraw) spyral.director.push(self.game) self.start() def run_credits(self, widget): if not (spyral.director.get_scene()==self.credits): self.credits = game.credits.Creditos(self.game.size) spyral.director.push(self.credits) def start(self): try: spyral.director.run(sugar = True) except AttributeError as detail: detail2 = traceback.format_exc() self.box.set_page(0) self.alert( detail2, "Spyral se ha detenido abruptamente.", 60) def show_game(self, widget): self.box.set_page(1) self.redraw() def show_editor(self, widget): if not self.editor: self.build_editor() self.box.set_page(2) self.redraw() def show_reader(self, widget): if not self.reader: self.build_reader() self.box.set_page(3) self.redraw() def restart_game(self, widget): global JUEGO import objetos try: objetos.reset() except AttributeError: pass self.box.set_page(0) watch = gtk.gdk.Cursor(gtk.gdk.WATCH) self.window.set_cursor(watch) JUEGO = reload(JUEGO) self.game = JUEGO.Juego(self, callback=self.game_ready) spyral.director.replace(self.game) self.start() def game_ready(self, widget = None): self.game_button.set_active(True) self.box.set_page(1) self._pygamecanvas.grab_focus() self.window.set_cursor(None) def read_file(self, file_path): pass def write_file(self, file_path): pass def can_close(self): if self.editor: self.editor.close() self.box.set_page(0) try: spyral.director.quit() except spyral.exceptions.GameEndException: pass finally: return True def toggle_console(self, e): if self._interpreter.props.visible: self._interpreter.hide() self._pygamecanvas.grab_focus() else: self.p.set_position(160) self._interpreter.show() self._interpreter.text.grab_focus() self.redraw() def animate_console(self): easing = spyral.easing.Linear(0,160) self.p.set_position(0)
class Record(activity.Activity): def __init__(self, handle): super(Record, self).__init__(handle) self.props.enable_fullscreen_mode = False Instance(self) self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK) self.connect("visibility-notify-event", self._visibility_changed) # the main classes self.model = Model(self) self.ui_init() # CSCL self.connect("shared", self._shared_cb) if self.get_shared_activity(): # have you joined or shared this activity yourself? if self.get_shared(): self._joined_cb(self) else: self.connect("joined", self._joined_cb) # Realize the video view widget so that it knows its own window XID self._media_view.realize_video() # Changing to the first toolbar kicks off the rest of the setup if self.model.get_has_camera(): self.model.change_mode(constants.MODE_PHOTO) else: self.model.change_mode(constants.MODE_AUDIO) # Restore critical hidden mixer controls to default model = hw.get_xo_version() if model == 1.75 or model == 4: args = ["amixer", "set", "Analog Mic Boost", "100%"] try: subprocess.check_output(args) except: pass def read_file(self, path): self.model.read_file(path) def write_file(self, path): self.model.write_file(path) def close(self): self.model.gplay.stop() self.model.glive.stop() super(Record, self).close() def _visibility_changed(self, widget, event): self.model.set_visible(event.state != gtk.gdk.VISIBILITY_FULLY_OBSCURED) def _shared_cb(self, activity): self.model.collab.set_activity_shared() def _joined_cb(self, activity): self.model.collab.joined() def ui_init(self): self._fullscreen = False self._showing_info = False # FIXME: if _thumb_tray becomes some kind of button group, we wouldn't # have to track which recd is active self._active_recd = None self.connect_after("key-press-event", self._key_pressed) self._active_toolbar_idx = 0 self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) self._toolbar_box.toolbar.insert(activity_button, 0) self.set_toolbar_box(self._toolbar_box) self._toolbar = self.get_toolbar_box().toolbar tool_group = None if self.model.get_has_camera(): self._photo_button = RadioToolButton() self._photo_button.props.group = tool_group tool_group = self._photo_button self._photo_button.props.icon_name = "camera-external" self._photo_button.props.label = _("Photo") self._photo_button.mode = constants.MODE_PHOTO self._photo_button.connect("clicked", self._mode_button_clicked) self._toolbar.insert(self._photo_button, -1) self._video_button = RadioToolButton() self._video_button.props.group = tool_group self._video_button.props.icon_name = "media-video" self._video_button.props.label = _("Video") self._video_button.mode = constants.MODE_VIDEO self._video_button.connect("clicked", self._mode_button_clicked) self._toolbar.insert(self._video_button, -1) else: self._photo_button = None self._video_button = None self._audio_button = RadioToolButton() self._audio_button.props.group = tool_group self._audio_button.props.icon_name = "media-audio" self._audio_button.props.label = _("Audio") self._audio_button.mode = constants.MODE_AUDIO self._audio_button.connect("clicked", self._mode_button_clicked) self._toolbar.insert(self._audio_button, -1) self._toolbar.insert(gtk.SeparatorToolItem(), -1) self._toolbar_controls = RecordControl(self._toolbar) 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) main_box.get_parent().modify_bg(gtk.STATE_NORMAL, COLOR_BLACK) main_box.show() self._media_view = MediaView() self._media_view.connect("media-clicked", self._media_view_media_clicked) self._media_view.connect("pip-clicked", self._media_view_pip_clicked) self._media_view.connect("info-clicked", self._media_view_info_clicked) self._media_view.connect("full-clicked", self._media_view_full_clicked) self._media_view.connect("tags-changed", self._media_view_tags_changed) self._media_view.show() self._controls_hbox = gtk.HBox() self._controls_hbox.show() self._shutter_button = ShutterButton() self._shutter_button.connect("clicked", self._shutter_clicked) self._controls_hbox.pack_start(self._shutter_button, expand=True, fill=False) self._countdown_image = CountdownImage() self._controls_hbox.pack_start(self._countdown_image, expand=True, fill=False) self._play_button = PlayButton() self._play_button.connect("clicked", self._play_pause_clicked) self._controls_hbox.pack_start(self._play_button, expand=False) self._playback_scale = PlaybackScale(self.model) self._controls_hbox.pack_start(self._playback_scale, expand=True, fill=True) self._progress = ProgressInfo() self._controls_hbox.pack_start(self._progress, expand=True, fill=True) self._title_label = gtk.Label() self._title_label.set_markup("<b><span foreground='white'>" + _("Title:") + "</span></b>") self._controls_hbox.pack_start(self._title_label, expand=False) self._title_entry = gtk.Entry() self._title_entry.modify_bg(gtk.STATE_INSENSITIVE, COLOR_BLACK) self._title_entry.connect("changed", self._title_changed) self._controls_hbox.pack_start(self._title_entry, expand=True, fill=True, padding=10) self._record_container = RecordContainer(self._media_view, self._controls_hbox) main_box.pack_start(self._record_container, expand=True, fill=True, padding=6) self._record_container.show() self._thumb_tray = HTray() self._thumb_tray.set_size_request(-1, 150) main_box.pack_end(self._thumb_tray, expand=False) self._thumb_tray.show_all() def serialize(self): data = {} data["timer"] = self._toolbar_controls.get_timer_idx() data["duration"] = self._toolbar_controls.get_duration_idx() data["quality"] = self._toolbar_controls.get_quality() return data def deserialize(self, data): self._toolbar_controls.set_timer_idx(data.get("timer", 0)) self._toolbar_controls.set_duration_idx(data.get("duration", 0)) self._toolbar_controls.set_quality(data.get("quality", 0)) def _key_pressed(self, widget, event): key = event.keyval if key == gtk.keysyms.KP_Page_Up: # game key O if self._shutter_button.props.visible: if self._shutter_button.props.sensitive: self._shutter_button.clicked() else: # return to live mode self.model.set_state(constants.STATE_READY) if self.model.ui_frozen(): return False if key == gtk.keysyms.c and event.state == gdk.CONTROL_MASK: self._copy_to_clipboard(self._active_recd) elif key == gtk.keysyms.i: self._toggle_info() elif key == gtk.keysyms.Escape: if self._fullscreen: self._toggle_fullscreen() return False def _play_pause_clicked(self, widget): self.model.play_pause() def set_mode(self, mode): self._toolbar_controls.set_mode(mode) # can be called from gstreamer thread, so must not do any GTK+ stuff def set_glive_sink(self, sink): return self._media_view.set_video_sink(sink) # can be called from gstreamer thread, so must not do any GTK+ stuff def set_gplay_sink(self, sink): return self._media_view.set_video2_sink(sink) def get_selected_quality(self): return self._toolbar_controls.get_quality() def get_selected_timer(self): return self._toolbar_controls.get_timer() def get_selected_duration(self): return self._toolbar_controls.get_duration() * 60 # convert to secs def set_progress(self, value, text): self._progress.set_progress(value) self._progress.set_text(text) def set_countdown(self, value): if value == 0: self._shutter_button.show() self._countdown_image.hide() self._countdown_image.clear() return self._shutter_button.hide() self._countdown_image.show() self._countdown_image.set_value(value) def _title_changed(self, widget): self._active_recd.setTitle(self._title_entry.get_text()) def _media_view_media_clicked(self, widget): if self._play_button.props.visible and self._play_button.props.sensitive: self._play_button.clicked() def _media_view_pip_clicked(self, widget): # clicking on the PIP always returns to live mode self.model.set_state(constants.STATE_READY) def _media_view_info_clicked(self, widget): self._toggle_info() def _toggle_info(self): recd = self._active_recd if not recd: return if self._showing_info: self._show_recd(recd, play=False) return self._showing_info = True if self.model.get_mode() in (constants.MODE_PHOTO, constants.MODE_AUDIO): func = self._media_view.show_info_photo else: func = self._media_view.show_info_video self._play_button.hide() self._progress.hide() self._playback_scale.hide() self._title_entry.set_text(recd.title) self._title_entry.show() self._title_label.show() self._record_container.set_title_visible(True) func(recd.recorderName, recd.colorStroke, recd.colorFill, utils.getDateString(recd.time), recd.tags) def _media_view_full_clicked(self, widget): self._toggle_fullscreen() def _media_view_tags_changed(self, widget, tbuffer): text = tbuffer.get_text(tbuffer.get_start_iter(), tbuffer.get_end_iter()) self._active_recd.setTags(text) def _toggle_fullscreen(self): if not self._fullscreen: self._toolbar_box.hide() self._thumb_tray.hide() else: self._toolbar_box.show() self._thumb_tray.show() self._fullscreen = not self._fullscreen self._media_view.set_fullscreen(self._fullscreen) def _mode_button_clicked(self, button): self.model.change_mode(button.mode) def _shutter_clicked(self, arg): self.model.do_shutter() def set_shutter_sensitive(self, value): self._shutter_button.set_sensitive(value) def set_state(self, state): radio_state = state == constants.STATE_READY for item in (self._photo_button, self._audio_button, self._video_button): if item: item.set_sensitive(radio_state) self._showing_info = False if state == constants.STATE_READY: self._set_cursor_default() self._active_recd = None self._title_entry.hide() self._title_label.hide() self._record_container.set_title_visible(False) self._play_button.hide() self._playback_scale.hide() self._progress.hide() self._controls_hbox.set_child_packing( self._shutter_button, expand=True, fill=False, padding=0, pack_type=gtk.PACK_START ) self._shutter_button.set_normal() self._shutter_button.set_sensitive(True) self._shutter_button.show() self._media_view.show_live() elif state == constants.STATE_RECORDING: self._shutter_button.set_recording() self._controls_hbox.set_child_packing( self._shutter_button, expand=False, fill=False, padding=0, pack_type=gtk.PACK_START ) self._progress.show() elif state == constants.STATE_PROCESSING: self._set_cursor_busy() self._shutter_button.hide() self._progress.show() elif state == constants.STATE_DOWNLOADING: self._shutter_button.hide() self._progress.show() def set_paused(self, value): if value: self._play_button.set_play() else: self._play_button.set_pause() def _thumbnail_clicked(self, button, recd): if self.model.ui_frozen(): return self._active_recd = recd self._show_recd(recd) def add_thumbnail(self, recd, scroll_to_end): button = RecdButton(recd) clicked_handler = button.connect("clicked", self._thumbnail_clicked, recd) remove_handler = button.connect("remove-requested", self._remove_recd) clipboard_handler = button.connect("copy-clipboard-requested", self._thumbnail_copy_clipboard) button.set_data("handler-ids", (clicked_handler, remove_handler, clipboard_handler)) self._thumb_tray.add_item(button) button.show() if scroll_to_end: self._thumb_tray.scroll_to_end() def _copy_to_clipboard(self, recd): if recd == None: return if not recd.isClipboardCopyable(): return media_path = recd.getMediaFilepath() tmp_path = utils.getUniqueFilepath(media_path, 0) shutil.copyfile(media_path, tmp_path) gtk.Clipboard().set_with_data([("text/uri-list", 0, 0)], self._clipboard_get, self._clipboard_clear, tmp_path) def _clipboard_get(self, clipboard, selection_data, info, path): selection_data.set("text/uri-list", 8, "file://" + path) def _clipboard_clear(self, clipboard, path): if os.path.exists(path): os.unlink(path) def _thumbnail_copy_clipboard(self, recdbutton): self._copy_to_clipboard(recdbutton.get_recd()) def _remove_recd(self, recdbutton): recd = recdbutton.get_recd() self.model.delete_recd(recd) if self._active_recd == recd: self.model.set_state(constants.STATE_READY) self._remove_thumbnail(recdbutton) def _remove_thumbnail(self, recdbutton): handlers = recdbutton.get_data("handler-ids") for handler in handlers: recdbutton.disconnect(handler) self._thumb_tray.remove_item(recdbutton) recdbutton.cleanup() def remove_all_thumbnails(self): for child in self._thumb_tray.get_children(): self._remove_thumbnail(child) def show_still(self, pixbuf): self._media_view.show_still(pixbuf) def _show_photo(self, recd): path = self._get_photo_path(recd) self._media_view.show_photo(path) self._title_entry.set_text(recd.title) self._title_entry.show() self._title_label.show() self._record_container.set_title_visible(True) self._shutter_button.hide() self._progress.hide() def _show_audio(self, recd, play): self._progress.hide() self._shutter_button.hide() self._title_entry.hide() self._title_label.hide() self._record_container.set_title_visible(False) self._play_button.show() self._playback_scale.show() path = recd.getAudioImageFilepath() self._media_view.show_photo(path) if play: self.model.play_audio(recd) def _show_video(self, recd, play): self._progress.hide() self._shutter_button.hide() self._title_entry.hide() self._title_label.hide() self._record_container.set_title_visible(False) self._play_button.show() self._playback_scale.show() self._media_view.show_video() if play: self.model.play_video(recd) def set_playback_scale(self, value): self._playback_scale.set_value(value) def _get_photo_path(self, recd): # FIXME should live (partially) in recd? # downloading = self.ca.requestMeshDownload(recd) # self.MESHING = downloading if True: # not downloading: # self.progressWindow.updateProgress(0, "") return recd.getMediaFilepath() # maybe it is not downloaded from the mesh yet... # but we can show the low res thumb in the interim return recd.getThumbFilepath() def _show_recd(self, recd, play=True): self._showing_info = False if recd.buddy and not recd.downloadedFromBuddy: self.model.request_download(recd) elif recd.type == constants.TYPE_PHOTO: self._show_photo(recd) elif recd.type == constants.TYPE_AUDIO: self._show_audio(recd, play) elif recd.type == constants.TYPE_VIDEO: self._show_video(recd, play) def remote_recd_available(self, recd): if recd == self._active_recd: self._show_recd(recd) def update_download_progress(self, recd): if recd != self._active_recd: return if not recd.meshDownloading: msg = _("Download failed.") elif recd.meshDownloadingProgress: msg = _("Downloading...") else: msg = _("Requesting...") self.set_progress(recd.meshDownlodingPercent, msg) def _set_cursor_busy(self): self.window.set_cursor(gdk.Cursor(gdk.WATCH)) def _set_cursor_default(self): self.window.set_cursor(None)
def __init__(self, title, bundle_path, document_path, sugar_toolkit_path): gtk.Toolbar.__init__(self) document_button = None self.bundle_path = bundle_path self.sugar_toolkit_path = sugar_toolkit_path self._add_separator() activity_bundle = ActivityBundle(bundle_path) file_name = activity_bundle.get_icon() if document_path is not None and os.path.exists(document_path): document_button = DocumentButton(file_name, document_path, title) document_button.connect('toggled', self.__button_toggled_cb, document_path) self.insert(document_button, -1) document_button.show() self._add_separator() if bundle_path is not None and os.path.exists(bundle_path): activity_button = DocumentButton(file_name, bundle_path, title, bundle=True) icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, fill_color=style.COLOR_TRANSPARENT.get_svg(), stroke_color=style.COLOR_WHITE.get_svg()) activity_button.set_icon_widget(icon) icon.show() if document_button is not None: activity_button.props.group = document_button activity_button.props.tooltip = _('Activity Bundle Source') activity_button.connect('toggled', self.__button_toggled_cb, bundle_path) self.insert(activity_button, -1) activity_button.show() self._add_separator() if sugar_toolkit_path is not None: sugar_button = RadioToolButton() icon = Icon(icon_name='computer-xo', icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, fill_color=style.COLOR_TRANSPARENT.get_svg(), stroke_color=style.COLOR_WHITE.get_svg()) sugar_button.set_icon_widget(icon) icon.show() if document_button is not None: sugar_button.props.group = document_button else: sugar_button.props.group = activity_button sugar_button.props.tooltip = _('Sugar Toolkit Source') sugar_button.connect('toggled', self.__button_toggled_cb, sugar_toolkit_path) self.insert(sugar_button, -1) sugar_button.show() self._add_separator() self.activity_title_text = _('View source: %s') % title self.sugar_toolkit_title_text = _('View source: %r') % 'Sugar Toolkit' self.label = gtk.Label() self.label.set_markup('<b>%s</b>' % self.activity_title_text) self.label.set_alignment(0, 0.5) self._add_widget(self.label) self._add_separator(True) stop = ToolButton(icon_name='dialog-cancel') stop.set_tooltip(_('Close')) stop.connect('clicked', self.__stop_clicked_cb) self.insert(stop, -1) stop.show()