diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-02-25 04:55:49 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-03-02 06:32:18 (GMT) |
commit | 05419416978cd3115defbbda3118cb8444495f30 (patch) | |
tree | c48225360c48d73af8d772c916d231e77dcac72e | |
parent | a449baef2c29830e49ff0c040d011ce11478f455 (diff) |
Wind tabs
-rw-r--r-- | GUI_Components/Compound_Widgets/Editing_View.py | 2 | ||||
-rw-r--r-- | GUI_Components/Compound_Widgets/toolbar.py | 22 | ||||
-rw-r--r-- | GUI_Components/Edit_Pane.py | 77 | ||||
-rw-r--r-- | GUI_Components/Format_Pane.py | 68 | ||||
-rw-r--r-- | GUI_Components/Image_Pane.py | 66 | ||||
-rw-r--r-- | GUI_Components/Library_Pane.py | 107 | ||||
-rw-r--r-- | GUI_Components/Pane.py | 36 | ||||
-rw-r--r-- | activity/activity.info | 2 | ||||
-rw-r--r-- | edit.py | 54 | ||||
-rw-r--r-- | library.py | 89 |
10 files changed, 205 insertions, 318 deletions
diff --git a/GUI_Components/Compound_Widgets/Editing_View.py b/GUI_Components/Compound_Widgets/Editing_View.py index a8511ba..4f2f206 100644 --- a/GUI_Components/Compound_Widgets/Editing_View.py +++ b/GUI_Components/Compound_Widgets/Editing_View.py @@ -47,4 +47,4 @@ class Editing_View( gtk.VBox ): self.textbox.set_mode(3)
def clear_contents(self):
- self.textbox.clear()
\ No newline at end of file + self.textbox.clear()
diff --git a/GUI_Components/Compound_Widgets/toolbar.py b/GUI_Components/Compound_Widgets/toolbar.py new file mode 100644 index 0000000..7fc3bb9 --- /dev/null +++ b/GUI_Components/Compound_Widgets/toolbar.py @@ -0,0 +1,22 @@ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import gtk + +class WidgetItem(gtk.ToolItem): + def __init__(self, widget, expand=False): + gtk.ToolItem.__init__(self) + self.set_expand(expand) + self.add(widget) + widget.show() diff --git a/GUI_Components/Edit_Pane.py b/GUI_Components/Edit_Pane.py index ea23045..ead04b1 100644 --- a/GUI_Components/Edit_Pane.py +++ b/GUI_Components/Edit_Pane.py @@ -2,18 +2,19 @@ import pygtk pygtk.require('2.0') import gtk -from GUI_Components.Pane import Pane +import logging +from gettext import gettext as _ + +from sugar.graphics.toolcombobox import ToolComboBox + from GUI_Components.Compound_Widgets.Reading_View import Reading_View from GUI_Components.Compound_Widgets.Editing_View import Editing_View -from GUI_Components.Compound_Widgets.Library_View import Library_View from Processing.Article.Article import Article from Processing.IO_Manager import IO_Manager -import logging -from gettext import gettext as _ logger = logging.getLogger('infoslicer') -class Edit_Pane(Pane): +class Edit_Pane(gtk.HBox): """ Created by Jonathan Mace @@ -30,48 +31,29 @@ class Edit_Pane(Pane): """ def __init__(self): - Pane.__init__(self) - self.name = _("Edit") + gtk.HBox.__init__(self) + self.toolitems = [] """ Create reading and editing panels """ - self.panel = gtk.HBox() - self.panel.set_homogeneous(True) - self.panel.show() - self.readarticle = Reading_View() - self.panel.pack_start(self.readarticle) + self.pack_start(self.readarticle) self.readarticle.show() self.editarticle = Editing_View() - self.panel.pack_start(self.editarticle) + self.pack_start(self.editarticle) self.editarticle.show() - self.toolbar = gtk.Toolbar() - - self.label = gtk.Label(_("Snap selection to: ")) - self.label.show() - - self.labelcontainer = gtk.ToolItem() - self.labelcontainer.add(self.label) - self.toolbar.insert(self.labelcontainer, -1) - self.labelcontainer.show() - """ Snap selection box """ - self.combobox = gtk.combo_box_new_text() - self.combobox.append_text(_("Nothing")) - self.combobox.append_text(_("Sentences")) - self.combobox.append_text(_("Paragraphs")) - self.combobox.append_text(_("Sections")) - self.combobox.connect("changed", self.selection_mode_changed, None) - self.combobox.set_active(1) - self.combobox.show() - - self.combocontainer = gtk.ToolItem() - self.combocontainer.add(self.combobox) - self.toolbar.insert(self.combocontainer, -1) - self.combocontainer.show() + 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 @@ -79,28 +61,27 @@ class Edit_Pane(Pane): mode based on user request """ def selection_mode_changed(self, widget, data): - current_selection = widget.get_active_text() - if current_selection == _("Nothing"): + current_selection = widget.get_active() + if current_selection == 0: self.readarticle.set_full_edit_mode() self.editarticle.set_full_edit_mode() - elif current_selection == _("Sentences"): + elif current_selection == 1: self.readarticle.set_sentence_selection_mode() self.editarticle.set_sentence_selection_mode() - elif current_selection == _("Paragraphs"): + elif current_selection == 2: self.readarticle.set_paragraph_selection_mode() self.editarticle.set_paragraph_selection_mode() - elif current_selection == _("Sections"): + elif current_selection == 3: self.readarticle.set_section_selection_mode() self.editarticle.set_section_selection_mode() #logger.debug(current_selection) - def get_source_article(self): - return self.readarticle.textbox.get_article() - """ Grab source article from IO manager and set up as editing source. """ def set_source_article(self, article): + if self.readarticle.textbox.get_article() == article: + return # Populate the drop down menu with the articles in the current theme article_theme = article.article_theme article_title = article.article_title @@ -136,14 +117,10 @@ class Edit_Pane(Pane): # Set the read article as appropriate. self.readarticle.textbox.set_article(article) - - def get_working_article(self): - article = self.editarticle.textbox.get_article() - return article - def set_working_article(self, article): + if self.editarticle.textbox.get_article() == article: + return self.editarticle.articletitle.set_markup("<span size='medium'><b> %s </b> %s \n<b> %s </b> %s</span>" % \ (_("Theme:"), article.article_theme, _("Article:"), article.article_title)) self.editarticle.textbox.set_article(article) self.editarticle.article_theme = _("Wikipedia Articles") - diff --git a/GUI_Components/Format_Pane.py b/GUI_Components/Format_Pane.py index 92d887b..8ad43f3 100644 --- a/GUI_Components/Format_Pane.py +++ b/GUI_Components/Format_Pane.py @@ -2,11 +2,11 @@ import pygtk pygtk.require('2.0') import gtk -from GUI_Components.Pane import Pane -from GUI_Components.Compound_Widgets.Editing_View import Editing_View from gettext import gettext as _ -class Format_Pane(Pane): +from GUI_Components.Compound_Widgets.Editing_View import Editing_View + +class Format_Pane(Editing_View): """ Created by Jonathan Mace @@ -18,42 +18,14 @@ class Format_Pane(Pane): """ def __init__(self): - Pane.__init__(self) - self.name = _("Format") - - self.panel = Editing_View() - self.panel.show() - - self.toolbar = gtk.Toolbar() + Editing_View.__init__(self) + self.toolitems = [] """ - Snapping has been turned off in the Editable Textbox, so we no longer - make use of snapping. This has been left in case we turn it back on. - - self.label = gtk.Label("Snap selection to: ") - self.label.show() - - self.labelcontainer = gtk.ToolItem() - self.labelcontainer.add(self.label) - self.toolbar.insert(self.labelcontainer, -1) - self.labelcontainer.show() - - - self.combobox = gtk.combo_box_new_text() - self.combobox.append_text("Nothing") - self.combobox.append_text("Sentences") - self.combobox.append_text("Paragraphs") - self.combobox.append_text("Sections") - self.combobox.connect("changed", self.selection_mode_changed, None) - self.combobox.set_active(1) - self.combobox.show() - - self.combocontainer = gtk.ToolItem() self.combocontainer.add(self.combobox) self.toolbar.insert(self.combocontainer, -1) self.combocontainer.show() - """ self.boldbutton = gtk.ToolButton(gtk.STOCK_BOLD) self.boldbutton.set_expand(False) @@ -69,32 +41,14 @@ class Format_Pane(Pane): self.underlinebutton.set_expand(False) self.toolbar.insert(self.underlinebutton, -1) self.underlinebutton.show() - - """ - User wants to change the default snap selection method - """ - def selection_mode_changed(self, widget, data): - current_selection = widget.get_active_text() - if current_selection == _("Nothing"): - self.panel.set_full_edit_mode() - elif current_selection == _("Sentences"): - self.panel.set_sentence_selection_mode() - elif current_selection == _("Paragraphs"): - self.panel.set_paragraph_selection_mode() - elif current_selection == _("Sections"): - self.panel.set_section_selection_mode() - - def get_source_article(self): - return self.source - + """ + def set_source_article(self, article): self.source = article - def get_working_article(self): - article = self.panel.textbox.get_article() - return article - def set_working_article(self, article): - self.panel.articletitle.set_markup("<span size='medium'><b> %s </b> %s \n<b> %s </b> %s</span>" % \ + if self.textbox.get_article() == article: + return + self.articletitle.set_markup("<span size='medium'><b> %s </b> %s \n<b> %s </b> %s</span>" % \ (_("Theme:"), article.article_theme, _("Article:"), article.article_title)) - self.panel.textbox.set_article(article) + self.textbox.set_article(article) diff --git a/GUI_Components/Image_Pane.py b/GUI_Components/Image_Pane.py index 435d35c..9c45bce 100644 --- a/GUI_Components/Image_Pane.py +++ b/GUI_Components/Image_Pane.py @@ -2,17 +2,17 @@ import pygtk pygtk.require('2.0') import gtk -from GUI_Components.Pane import Pane +import logging +from gettext import gettext as _ + from GUI_Components.Compound_Widgets.Editing_View import Editing_View from GUI_Components.Compound_Widgets.Gallery_View import Gallery_View from Processing.Article.Article import Article from Processing.IO_Manager import IO_Manager -import logging -from gettext import gettext as _ logger = logging.getLogger('infoslicer') -class Image_Pane(Pane): +class Image_Pane(gtk.HBox): """ Created by Christopher Leonard @@ -24,54 +24,20 @@ class Image_Pane(Pane): """ def __init__(self): - Pane.__init__(self) - self.name = _("Images") + gtk.HBox.__init__(self) + self.toolitems = [] - self.panel = gtk.HBox() - self.panel.set_homogeneous(True) - self.panel.show() self.gallery = Gallery_View() - self.panel.pack_start(self.gallery) + self.pack_start(self.gallery) self.editarticle = Editing_View() - self.panel.pack_start(self.editarticle) + self.pack_start(self.editarticle) self.editarticle.show_all() self.gallery._source_article = None - self.toolbar = gtk.Toolbar() - """ - Snapping has been turned off in the Editable Textbox, so we no longer - make use of snapping. This has been left in case we turn it back on. - - - self.combobox = gtk.combo_box_new_text() - self.combobox.append_text("Nothing") - self.combobox.append_text("Sentences") - self.combobox.append_text("Paragraphs") - self.combobox.append_text("Sections") - self.combobox.connect("changed", self.selection_mode_changed, None) - self.combobox.set_active(1) - self.combobox.show() - - self.combocontainer = gtk.ToolItem() - self.combocontainer.add(self.combobox) - self.toolbar.insert(self.combocontainer, -1) - self.combocontainer.show() - """ - - def selection_mode_changed(self, widget, data): - current_selection = widget.get_active_text() - if current_selection == _("Nothing"): - self.editarticle.set_full_edit_mode() - elif current_selection == _("Sentences"): - self.editarticle.set_sentence_selection_mode() - elif current_selection == _("Paragraphs"): - self.editarticle.set_paragraph_selection_mode() - elif current_selection == _("Sections"): - self.editarticle.set_section_selection_mode() - - def set_source_article(self, source): + if self.gallery._source_article == source: + return logger.debug("source received. title: %s, theme: %s" % (source.article_title, source.article_theme)) current = self.gallery._source_article @@ -99,15 +65,9 @@ class Image_Pane(Pane): self.gallery.imagenumberlabel.set_label("") self.gallery.caption.set_text(_("Please select a Wikipedia article from the menu above")) - def get_source_article(self): - return self.gallery._source_article - - def get_working_article(self): - article = self.editarticle.textbox.get_article() - #data = article.getData() - return article - def set_working_article(self, article): + if self.editarticle.textbox.get_article() == article: + return logger.debug("working received, title %s theme %s " % (article.article_title, article.article_theme)) self.editarticle.articletitle.set_markup("<span size='medium'><b> %s </b> %s \n<b> %s </b> %s</span>"% \ @@ -127,5 +87,3 @@ class Image_Pane(Pane): self.gallery.articlemenu.append_text(item) if self.gallery._source_article != None and item == self.gallery._source_article.article_title: self.gallery.articlemenu.set_active(count) - - diff --git a/GUI_Components/Library_Pane.py b/GUI_Components/Library_Pane.py deleted file mode 100644 index 337efb9..0000000 --- a/GUI_Components/Library_Pane.py +++ /dev/null @@ -1,107 +0,0 @@ -# Copyright (C) IBM Corporation 2008 -import pygtk -pygtk.require('2.0') -import gtk -from GUI_Components.Pane import Pane -from GUI_Components.Compound_Widgets.Library_View import Library_View -from GUI_Components.Compound_Widgets.Reading_View import Reading_View -from Processing.IO_Manager import * -from gettext import gettext as _ - -class Library_Pane(Pane): - """ - Created by Jonathan Mace - - The Library Pane sets up a Library View and includes a toolbar which has - a text entry used for getting articles from Wikipedia. - - The Library View contains the entire sum of articles downloaded from Wikipedia. - These articles can then be added to themes, editing and bundled into content packages - """ - - def __init__(self): - Pane.__init__(self) - self.wikis = {_("English Wikipedia") : "en.wikipedia.org", - _("Simple English Wikipedia") : "simple.wikipedia.org", - _("German Wikipedia") : "de.wikipedia.org"} - self.toolbar = gtk.Toolbar() - - - self.panel = gtk.HBox() - self.panel.set_homogeneous(True) - self.panel.show() - - self.librarypanel = Library_View() - self.panel.pack_start(self.librarypanel) - self.librarypanel.show() - - statuslabel = self.librarypanel.statusbar - - # Set up the components of the toolbar - searchlabelitem = gtk.ToolItem() - self.toolbar.insert(searchlabelitem, -1) - searchlabelitem.show() - - """ - User search dialog - """ - searchlabel = gtk.Label(_("Get article from ")) - searchlabelitem.add(searchlabel) - searchlabel.show() - - wikitoolitem = gtk.ToolItem() - self.toolbar.insert(wikitoolitem, -1) - wikitoolitem.show() - - wikimenu = gtk.combo_box_new_text() - keys = self.wikis.keys() - keys.sort() - for wiki in keys: - wikimenu.append_text(wiki) - wikimenu.set_active(0) - wikitoolitem.add(wikimenu) - wikimenu.show() - - searchentryitem = gtk.ToolItem() - self.toolbar.insert(searchentryitem, -1) - searchentryitem.show() - - searchentry = gtk.Entry() - searchentry.set_text(_("Article name")) - searchentry.connect("activate", self.click_search_button, None) - searchentryitem.add(searchentry) - searchentry.show() - - self.searchbutton = gtk.ToolButton(gtk.STOCK_FIND) - self.searchbutton.connect("clicked", self.librarypanel.commence_retrieval, searchentry, statuslabel, wikimenu, self.wikis) - self.toolbar.insert(self.searchbutton, -1) - self.searchbutton.show() - - # Add some blank space - blanklabel = gtk.Label(" ") - blanklabel.show() - - blankitem = gtk.ToolItem() - blankitem.add(blanklabel) - self.toolbar.insert(blankitem, -1) - blankitem.show() - - - self.toolbar = self.toolbar - self.name = _("Library") - - def click_search_button(self, widget, data): - self.searchbutton.emit("clicked") - - def get_source_article(self): - return self.librarypanel.get_source() - - def set_source_article(self, article): - self.librarypanel.set_source(article) - - def get_working_article(self): - return self.librarypanel.get_working() - - def set_working_article(self, article): - self.librarypanel.set_working(article) - diff --git a/GUI_Components/Pane.py b/GUI_Components/Pane.py deleted file mode 100644 index 01e15fc..0000000 --- a/GUI_Components/Pane.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) IBM Corporation 2008 - -import pygtk -pygtk.require('2.0') -import gtk - -class Pane: - """ - An instance of the Pane class has a panel which is the main view, - a toolbar which interacts with the panel, - and methods for getting and setting the source and working articles. - - - name - - toolbar - - panel - - """ - - def __init__(self): - # Pane instances have a panel, which is the main view of the pane - self.panel = gtk.Label() - - # Pane instances have a toolbar - self.toolbar = gtk.Toolbar() - - def get_working_article(self): - return self.working - - def set_working_article(self, article): - self.working = article - - def get_source_article(self): - return self.source - - def set_source_article(self, article): - self.source = article diff --git a/activity/activity.info b/activity/activity.info index d975373..f6d1a4d 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -4,6 +4,6 @@ activity_version = 2 host_version = 1 icon = slicelogo bundle_id = org.sugarlabs.infoslicer -exec = sugar-activity sugaractivity.sugaractivity +exec = sugar-activity activity.InfoslicerActivity show_launcher = yes license = GPLv2+ @@ -23,15 +23,59 @@ from GUI_Components.Edit_Pane import Edit_Pane from GUI_Components.Format_Pane import Format_Pane from GUI_Components.Image_Pane import Image_Pane -class View(gtk.EventBox): +TABS = (Edit_Pane(), + Image_Pane(), + Format_Pane()) + +class View(gtk.Notebook): def __init__(self): - gtk.EventBox.__init__(self) + gtk.Notebook.__init__(self) + self.props.show_border = False + self.props.show_tabs = False - self.pane = Edit_Pane() - self.pane.panel.show() - self.add(self.pane.panel) + for i in TABS: + self.append_page(i) + i.show() class Toolbar(gtk.Toolbar): def __init__(self, edit): gtk.Toolbar.__init__(self) self.edit = edit + + txt_toggle = ToggleToolButton('ascii') + 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) + + img_toggle.show() + img_toggle.set_tooltip(_('Images')) + img_toggle.connect('toggled', self._toggle_cb, [txt_toggle, img_toggle]) + self.insert(img_toggle, -1) + + separator = gtk.SeparatorToolItem() + self.insert(separator, -1) + separator.show() + + for tab in TABS: + for i in tab.toolitems: + self.insert(i, -1) + + def _toggle_cb(self, widget, toggles): + for tab in TABS: + for i in tab.toolitems: + i.hide() + + if not widget.get_active(): + index = 2 + else: + another = toggles[0] == widget and 1 or 0 + toggles[another].set_active(False) + toggles[another].stop_emission('toggled') + index = int(not another) + + for i in TABS[index].toolitems: + i.show() + self.edit.set_current_page(index) @@ -18,18 +18,30 @@ from gettext import gettext as _ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toggletoolbutton import ToggleToolButton from sugar.activity.activity import ActivityToolbox +from sugar.graphics.toolcombobox import ToolComboBox -from GUI_Components.Library_Pane import Library_Pane +from GUI_Components.Compound_Widgets.Library_View import Library_View +from GUI_Components.Compound_Widgets.toolbar import WidgetItem -class View(gtk.EventBox): +class View(Library_View): def __init__(self): - gtk.EventBox.__init__(self) - - self.pane = Library_Pane() - self.pane.panel.show() - self.add(self.pane.panel) + Library_View.__init__(self) """ + + def get_source_article(self): + return self.librarypanel.get_source() + + def set_source_article(self, article): + self.librarypanel.set_source(article) + + def get_working_article(self): + return self.librarypanel.get_working() + + def set_working_article(self, article): + self.librarypanel.set_working(article) + + # Set up dummy library if appropriate IO_Manager().install_library() @@ -59,3 +71,66 @@ class Toolbar(gtk.Toolbar): def __init__(self, library): gtk.Toolbar.__init__(self) self.library = library + + wikimenu = ToolComboBox(label_text=_('Get article from:')) + wikimenu.combo.connect('changed', self._wikimenu_changed_cb) + for i in sorted(WIKI.keys()): + wikimenu.combo.append_item(WIKI[i], i) + self.insert(wikimenu, -1) + wikimenu.show() + + searchentry = gtk.Entry() + searchentry.set_size_request(int(gtk.gdk.screen_width() / 4), -1) + searchentry.set_text(_("Article name")) + searchentry.connect('changed', self._search_activate_cb) + searchentry_item = WidgetItem(searchentry) + self.insert(searchentry_item, -1) + searchentry_item.show() + + self.searchbutton = ToolButton('search', tooltip=_('Find article')) + self.searchbutton.connect("clicked", self.library.commence_retrieval, + searchentry, self.library.statusbar, wikimenu, WIKI) + self.insert(self.searchbutton, -1) + self.searchbutton.show() + + separator = gtk.SeparatorToolItem() + self.insert(separator, -1) + separator.show() + + new = ToolButton('add', tooltip=_('New article')) + new.connect("clicked", self._new_clicked_cb) + self.insert(new, -1) + new.show() + + erase = ToolButton('edit-delete', tooltip=_('Delete selected articles')) + erase.connect("clicked", self._erase_clicked_cb) + self.insert(erase, -1) + erase.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() + + def _publish_clicked_cb(self): + pass + + def _erase_clicked_cb(self): + pass + + def _new_clicked_cb(self): + pass + + def _search_activate_cb(self, widget): + self.searchbutton.emit("clicked") + + def _wikimenu_changed_cb(self, widget, data): + self.searchbutton.emit("clicked") + +WIKI = { _("English Wikipedia") : "en.wikipedia.org", + _("Simple English Wikipedia") : "simple.wikipedia.org", + _("German Wikipedia") : "de.wikipedia.org" } |