From 8eba08663961fef858b38aa83752d54acbe7a69e Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Mon, 23 May 2011 14:04:21 +0000 Subject: Reorganize UI and implement new toolbars --- diff --git a/activity.py b/activity.py index e402f1c..469207d 100644 --- a/activity.py +++ b/activity.py @@ -18,6 +18,14 @@ from gettext import gettext as _ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toggletoolbutton import ToggleToolButton from sugar.activity.activity import ActivityToolbox +OLD_TOOLBAR = False +try: + from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton + from sugar.activity.widgets import StopButton + from sugar.graphics.radiotoolbutton import RadioToolButton + from sugar.activity.widgets import ActivityToolbarButton +except ImportError: + OLD_TOOLBAR = True from port.activity import SharedActivity import library @@ -43,16 +51,52 @@ class InfoslicerActivity(SharedActivity): self.edit_page = 1 self.edit = edit.View() - self.edit_bar = edit.Toolbar(self.edit) - self.library = library.View(self) - library_bar = library.Toolbar(self.library) - toolbox = ActivityToolbox(self) - toolbox.connect('current-toolbar-changed', self._toolbar_changed_cb) - self.set_toolbox(toolbox) - toolbox.add_toolbar(_('Library'), library_bar) - toolbox.add_toolbar(_('Edit'), self.edit_bar) + 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() @@ -60,9 +104,19 @@ class InfoslicerActivity(SharedActivity): self.notebook.append_page(self.edit) self.notebook.append_page(edit_fake) - toolbox.set_current_toolbar(1) 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) + def new_instance(self): self.instance() @@ -75,8 +129,9 @@ class InfoslicerActivity(SharedActivity): book.custom.sync(filepath) def set_edit_sensitive(self, enable): - self.edit_bar.props.sensitive = enable - self.edit_page = (enable and 1 or 2) + if OLD_TOOLBAR: + #self.edit_toolbar.props.sensitive = enable + self.edit_page = (enable and 1 or 2) def _toolbar_changed_cb(self, widget, index): if index > 0: @@ -86,3 +141,11 @@ class InfoslicerActivity(SharedActivity): self.library.sync() index = self.edit_page self.notebook.set_current_page(index) + + def __mode_button_clicked(self, button): + if button.mode == 'search': + self.edit_bar.unsensitize_all() + self.notebook.set_current_page(0) + else: + self.edit_bar.sensitize_all() + self.notebook.set_current_page(1) diff --git a/edit.py b/edit.py index a2060d4..4fea931 100644 --- a/edit.py +++ b/edit.py @@ -48,33 +48,39 @@ class View(gtk.Notebook): if book.custom.article: TABS[index].set_working_article(book.custom.article) -class Toolbar(gtk.Toolbar): - def __init__(self, edit): - gtk.Toolbar.__init__(self) +class ToolbarBuilder(): + def __init__(self, edit, toolbar): self.edit = edit - txt_toggle = ToggleToolButton('ascii') - img_toggle = ToggleToolButton('image') + self.txt_toggle = ToggleToolButton('ascii') + self.img_toggle = ToggleToolButton('image') - txt_toggle.show() - txt_toggle.set_tooltip(_('Text')) - txt_toggle.connect('toggled', self._toggle_cb, [txt_toggle, img_toggle]) - self.insert(txt_toggle, -1) + self.txt_toggle.set_tooltip(_('Text')) + self.txt_toggle.connect('toggled', self._toggle_cb, + [self.txt_toggle, self.img_toggle]) + toolbar.insert(self.txt_toggle, -1) - img_toggle.show() - img_toggle.set_tooltip(_('Images')) - img_toggle.connect('toggled', self._toggle_cb, [txt_toggle, img_toggle]) - self.insert(img_toggle, -1) + self.img_toggle.set_tooltip(_('Images')) + self.img_toggle.connect('toggled', self._toggle_cb, + [self.txt_toggle, self.img_toggle]) + toolbar.insert(self.img_toggle, -1) - separator = gtk.SeparatorToolItem() - self.insert(separator, -1) - separator.show() + self.separator = gtk.SeparatorToolItem() + toolbar.insert(self.separator, -1) for tab in TABS: for i in tab.toolitems: - self.insert(i, -1) + toolbar.insert(i, -1) - txt_toggle.set_active(True) + self.txt_toggle.set_active(True) + + def sensitize_all(self): + self.txt_toggle.set_sensitive(True) + self.img_toggle.set_sensitive(True) + + def unsensitize_all(self): + self.txt_toggle.set_sensitive(False) + self.img_toggle.set_sensitive(False) def _toggle_cb(self, widget, toggles): for tab in TABS: diff --git a/infoslicer/widgets/Edit_Pane.py b/infoslicer/widgets/Edit_Pane.py index beff0f4..8da2ad9 100644 --- a/infoslicer/widgets/Edit_Pane.py +++ b/infoslicer/widgets/Edit_Pane.py @@ -19,9 +19,9 @@ class Edit_Pane(gtk.HBox): See __init__.py for overview of panes. - The Edit Pane gives a side-by-side view of the source article and edit article - and allows users to drag text selections from the left hand (source) to the right - hand side (edited version). + The Edit Pane gives a side-by-side view of the source article and edit + article and allows users to drag text selections from the left hand + (source) to the right hand side (edited version). The article displayed in the left hand side (source) can be changed by the drop-down menu (implemented in Compound_Widgets.Reading_View) @@ -45,7 +45,17 @@ class Edit_Pane(gtk.HBox): self.articletitle.set_justify(gtk.JUSTIFY_CENTER) labeleb.add(self.articletitle) self.articletitle.show() - + + vbox = gtk.VBox() + + snap = ToolComboBox(label_text=_('Snap selection to:')) + snap.combo.append_item(0, _("Nothing")) + snap.combo.append_item(1, _("Sentences")) + snap.combo.append_item(2, _("Paragraphs")) + snap.combo.append_item(3, _("Sections")) + snap.combo.set_active(1) + vbox.pack_start(snap, False) + """ Create reading and editing panels """ @@ -53,26 +63,21 @@ class Edit_Pane(gtk.HBox): self.readarticle.set_size_request(gtk.gdk.screen_width()/2, -1) self.readarticle.show() readarticle_box.pack_start(self.readarticle) - self.pack_start(readarticle_box, False) + vbox.pack_start(readarticle_box) + + self.pack_start(vbox, False) self.editarticle = Editing_View() self.pack_start(self.editarticle) self.editarticle.show() - - """ Snap selection box """ - snap = ToolComboBox(label_text=_('Snap selection to:')) - snap.combo.append_item(0, _("Nothing")) - snap.combo.append_item(1, _("Sentences")) - snap.combo.append_item(2, _("Paragraphs")) - snap.combo.append_item(3, _("Sections")) + snap.combo.connect("changed", self.selection_mode_changed, None) - snap.combo.set_active(1) - self.toolitems.append(snap) + """ When highlighting text, while editing, different selection snap methods - can be used (characters, sentences, paragraphs and sections). Change the selection - mode based on user request + can be used (characters, sentences, paragraphs and sections). Change the + selection mode based on user request """ def selection_mode_changed(self, widget, data): current_selection = widget.get_active() diff --git a/library.py b/library.py index 6061446..e5f1799 100644 --- a/library.py +++ b/library.py @@ -44,16 +44,10 @@ class View(gtk.EventBox): gtk.EventBox.__init__(self) self.activity = activity - # books - - books = gtk.VBox() - books.set_size_request(gtk.gdk.screen_width()/4, -1) self.wiki = BookView(book.wiki, _('Wiki'), _('Wiki articles'), False) - books.pack_start(self.wiki) self.custom = BookView(book.custom, _('Custom'), _('Custom articles'), True) - books.pack_start(self.custom) # stubs for empty articles @@ -80,6 +74,24 @@ class View(gtk.EventBox): _('button on the left "Custom" panel')) # articles viewers + search_box = gtk.HBox() + self.wikimenu = ToolComboBox(label_text=_('Get article from:')) + for i in sorted(WIKI.keys()): + self.wikimenu.combo.append_item(WIKI[i], i) + self.wikimenu.combo.set_active(0) + search_box.pack_start(self.wikimenu, False) + + self.searchentry = gtk.Entry() + self.searchentry.set_size_request(int(gtk.gdk.screen_width() / 4), -1) + self.searchentry.set_text(_("Article name")) + self.searchentry.select_region(0, -1) + self.searchentry.connect('activate', self._search_activate_cb) + search_box.pack_start(self.searchentry) + search_box.show_all() + + self.searchbutton = gtk.Button(label=_('Search')) + self.searchbutton.connect('clicked', self._search_clicked_cb) + search_box.pack_start(self.searchbutton, False) wiki_widget = Reading_View() wiki = gtk.Notebook() @@ -88,32 +100,43 @@ class View(gtk.EventBox): wiki.append_page(wiki_stub) wiki.append_page(wiki_widget) + self.progress = gtk.Label() + #self.progress.set_size_request(-1, style.SMALL_ICON_SIZE+4) + #progress_box = gtk.HBox() + #progress_box.pack_start(gtk.HSeparator(), False) + #progress_box.pack_start(self.progress, False) + + wiki_box = gtk.VBox() + wiki_box.pack_start(search_box, False) + wiki_box.pack_start(wiki) + wiki_box.pack_start(self.progress, False) + wiki_box.set_size_request(gtk.gdk.screen_width()/4*3, + gtk.gdk.screen_height()/2) + custom_widget = Reading_View() custom = gtk.Notebook() custom.props.show_border = False custom.props.show_tabs = False custom.append_page(custom_stub) custom.append_page(custom_widget) - custom.set_size_request(gtk.gdk.screen_width()/4*3/2, -1) + custom.set_size_request(gtk.gdk.screen_width()/4*3, + gtk.gdk.screen_height()/2) # workspace - articles = gtk.HBox() - articles.pack_start(wiki) - articles.pack_start(gtk.VSeparator(), False) - articles.pack_start(custom, False) + articles_box = gtk.HBox() + articles_box.pack_start(self.wiki) + articles_box.pack_start(gtk.VSeparator(), False) + articles_box.pack_start(wiki_box, False) - self.progress = gtk.Label() - self.progress.set_size_request(-1, style.SMALL_ICON_SIZE+4) - progress_box = gtk.VBox() - progress_box.pack_start(articles) - progress_box.pack_start(gtk.HSeparator(), False) - progress_box.pack_start(self.progress, False) - - workspace = gtk.HBox() - workspace.pack_start(books, False) - workspace.pack_start(gtk.VSeparator(), False) - workspace.pack_start(progress_box) + custom_box = gtk.HBox() + custom_box.pack_start(self.custom) + custom_box.pack_start(gtk.VSeparator(), False) + custom_box.pack_start(custom, False) + + workspace = gtk.VBox() + workspace.pack_start(articles_box, False) + workspace.pack_start(custom_box, False) workspace.show_all() self.add(workspace) @@ -129,13 +152,13 @@ class View(gtk.EventBox): book.custom.connect('article-deleted', self._article_deleted_cb, [custom, wiki]) - self.activity.set_edit_sensitive(False) - self._article_selected_cb(book.wiki, book.wiki.article, wiki_widget, [wiki, custom]) self._article_selected_cb(book.custom, book.custom.article, custom_widget, [custom, wiki]) + self.connect('map', self._map_cb) + def _article_selected_cb(self, abook, article, article_widget, notebooks): if not article: return @@ -156,51 +179,6 @@ class View(gtk.EventBox): notebooks[0].set_current_page(0) self.activity.set_edit_sensitive(False) -class Toolbar(gtk.Toolbar): - def __init__(self, library): - gtk.Toolbar.__init__(self) - self.library = library - self.activity = library.activity - - self.wikimenu = ToolComboBox(label_text=_('Get article from:')) - for i in sorted(WIKI.keys()): - self.wikimenu.combo.append_item(WIKI[i], i) - self.wikimenu.combo.set_active(0) - self.insert(self.wikimenu, -1) - self.wikimenu.show() - - self.searchentry = gtk.Entry() - self.searchentry.set_size_request(int(gtk.gdk.screen_width() / 4), -1) - self.searchentry.set_text(_("Article name")) - self.searchentry.select_region(0, -1) - self.searchentry.connect('activate', self._search_activate_cb) - searchentry_item = ToolWidget(self.searchentry) - self.insert(searchentry_item, -1) - searchentry_item.show() - - self.searchbutton = ToolButton('white-search', - tooltip=_('Find article')) - self.searchbutton.connect('clicked', self._search_clicked_cb) - self.insert(self.searchbutton, -1) - self.searchbutton.show() - - separator = gtk.SeparatorToolItem() - self.insert(separator, -1) - separator.show() - - publish = ToolButton('filesave', tooltip=_('Publish selected articles')) - publish.connect("clicked", self._publish_clicked_cb) - self.insert(publish, -1) - publish.show() - - self.connect('map', self._map_cb) - - def _publish_clicked_cb(self, widget): - xol.publish(self.activity) - - def _map_cb(self, widget): - self.searchentry.grab_focus() - def _search_activate_cb(self, widget): self.searchbutton.emit("clicked") @@ -219,11 +197,29 @@ class Toolbar(gtk.Toolbar): Timer(0, self._download, [title, wiki]).start() def _download(self, title, wiki): - net.download_wiki_article(title, wiki, self.library.progress) + net.download_wiki_article(title, wiki, self.progress) Timer(10, self._clear_progress).start() def _clear_progress(self): - self.library.progress.set_label('') + self.progress.set_label('') + + def _map_cb(self, widget): + self.searchentry.grab_focus() + + +class ToolbarBuilder(): + def __init__(self, library, toolbar): + self.library = library + self.activity = library.activity + + self.publish = ToolButton('filesave', + tooltip=_('Publish selected articles')) + self.publish.connect("clicked", self._publish_clicked_cb) + toolbar.insert(self.publish, -1) + + + def _publish_clicked_cb(self, widget): + xol.publish(self.activity) WIKI = { _("English Wikipedia") : "en.wikipedia.org", _("Simple English Wikipedia") : "simple.wikipedia.org", -- cgit v0.9.1