diff options
author | Walter Bender <walter.bender@gmail.com> | 2013-04-01 11:55:34 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2013-04-01 11:55:34 (GMT) |
commit | b7e312ed802634ced4cb48d6fa3f86d6dd91e37c (patch) | |
tree | 11cec1fe203927b61be29b24875c99c508f7acaa | |
parent | 1bd49ae339dab5f4ef7b712071f2fad1be481996 (diff) |
gtk2 backportgtk2
-rw-r--r-- | activity.py | 147 | ||||
-rw-r--r-- | book.py | 26 | ||||
-rw-r--r-- | bookview.py | 139 | ||||
-rw-r--r-- | edit.py | 48 | ||||
-rw-r--r-- | infoslicer/processing/Article.py | 22 | ||||
-rw-r--r-- | infoslicer/processing/Sentence.py | 15 | ||||
-rw-r--r-- | infoslicer/widgets/Edit_Pane.py | 38 | ||||
-rw-r--r-- | infoslicer/widgets/Editable_Textbox.py | 48 | ||||
-rw-r--r-- | infoslicer/widgets/Editing_View.py | 26 | ||||
-rw-r--r-- | infoslicer/widgets/Format_Pane.py | 14 | ||||
-rw-r--r-- | infoslicer/widgets/Gallery_View.py | 102 | ||||
-rw-r--r-- | infoslicer/widgets/Image_Pane.py | 30 | ||||
-rw-r--r-- | infoslicer/widgets/Journal_Gallery_View.py | 60 | ||||
-rw-r--r-- | infoslicer/widgets/Journal_Image_Pane.py | 23 | ||||
-rw-r--r-- | infoslicer/widgets/Reading_View.py | 17 | ||||
-rw-r--r-- | infoslicer/widgets/Readonly_Textbox.py | 39 | ||||
-rw-r--r-- | infoslicer/widgets/Textbox.py | 23 | ||||
-rw-r--r-- | infoslicer/widgets/__init__.py | 22 | ||||
-rw-r--r-- | library.py | 133 | ||||
-rw-r--r-- | net.py | 2 | ||||
-rw-r--r-- | toolbar.py | 26 | ||||
-rw-r--r-- | xol.py | 62 |
22 files changed, 479 insertions, 583 deletions
diff --git a/activity.py b/activity.py index fa94eab..126d4c7 100644 --- a/activity.py +++ b/activity.py @@ -12,37 +12,37 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from gi.repository import Gtk -from gi.repository import GObject +import gtk from gettext import gettext as _ -GObject.threads_init() - -from sugar3.graphics.toolbutton import ToolButton -from sugar3.graphics.toggletoolbutton import ToggleToolButton -from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton -from sugar3.activity.widgets import StopButton -from sugar3.activity import activity -from sugar3.graphics.radiotoolbutton import RadioToolButton -from sugar3.activity.widgets import ActivityToolbarButton +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 import edit import book -class InfoslicerActivity(activity.Activity): +gtk.gdk.threads_init() +gtk.gdk.threads_enter() + +class InfoslicerActivity(SharedActivity): def __init__(self, handle): - self.notebook = Gtk.Notebook() + self.notebook = gtk.Notebook() self.notebook.show() self.notebook.props.show_border = False self.notebook.props.show_tabs = False - activity.Activity.__init__(self, handle) - - self.max_participants = 1 - - self.set_canvas(self.notebook) - self.instance() + SharedActivity.__init__(self, self.notebook, 'SERVICE', handle) def instance(self): book.wiki = book.WikiBook() @@ -53,52 +53,71 @@ class InfoslicerActivity(activity.Activity): self.edit = edit.View() self.library = library.View(self) - 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, - activity_button) - self.library_bar.publish.show() - - edit_fake = Gtk.EventBox() - - self.notebook.append_page(self.library, None) - self.notebook.append_page(self.edit, None) - self.notebook.append_page(edit_fake, None) + 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, + activity_button) + self.library_bar.publish.show() + + 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() - 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) + 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() @@ -112,7 +131,9 @@ class InfoslicerActivity(activity.Activity): book.custom.sync(filepath) def set_edit_sensitive(self, enable): - pass + 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: @@ -13,15 +13,17 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os +import gtk import uuid import logging -from gi.repository import GObject -import json +import gobject +import cjson import shutil import zipfile +from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT from gettext import gettext as _ -from sugar3.activity.activity import get_bundle_path, get_activity_root +from sugar.activity.activity import get_bundle_path, get_activity_root import net from infoslicer.processing.Article import Article @@ -34,11 +36,11 @@ custom = None image_root = os.path.join(get_activity_root(), 'data', 'book') -class Book(GObject.GObject): +class Book(gobject.GObject): __gsignals__ = { - 'article-selected' : (GObject.SignalFlags.RUN_FIRST, None, [object]), - 'article-added' : (GObject.SignalFlags.RUN_FIRST, None, [object]), - 'article-deleted' : (GObject.SignalFlags.RUN_FIRST, None, [object])} + 'article-selected' : (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]), + 'article-added' : (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]), + 'article-deleted' : (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]) } def get_article(self): return self._article @@ -69,9 +71,9 @@ class Book(GObject.GObject): self._article.uid = entry['uid'] self._article.article_title = title - GObject.idle_add(self._emit_article_selected) + gobject.idle_add(self._emit_article_selected) - article = GObject.property(type=object, + article = gobject.property(type=object, getter=get_article, setter=set_article) def _emit_article_selected(self): @@ -122,7 +124,7 @@ class Book(GObject.GObject): 'revision' : self.revision } index = file(os.path.join(self.root, 'index'), 'w') - index.write(json.dumps(data)) + index.write(cjson.encode(data)) index.close() def sync(self): @@ -130,7 +132,7 @@ class Book(GObject.GObject): self.sync_index() def __init__(self, preinstalled, root): - GObject.GObject.__init__(self) + gobject.GObject.__init__(self) self.root = root self.index = [] self.uid = None @@ -140,7 +142,7 @@ class Book(GObject.GObject): if os.path.exists(self.root): try: index = file(os.path.join(self.root, 'index'), 'r') - data = json.loads(index.read()) + data = cjson.decode(index.read()) self.uid = data['uid'] self.index = data['index'] self.revision = data['revision'] diff --git a/bookview.py b/bookview.py index 197b2a3..8b049d6 100644 --- a/bookview.py +++ b/bookview.py @@ -13,74 +13,65 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os -from gi.repository import Gtk +import gtk import logging -from gi.repository import GObject +import gobject from gettext import gettext as _ -from sugar3.graphics.toolbutton import ToolButton -from sugar3.activity.activity import get_bundle_path, get_activity_root -from sugar3.graphics.style import * +from sugar.graphics.toolbutton import ToolButton +from sugar.activity.activity import get_bundle_path, get_activity_root +from sugar.graphics.style import * +from port.widgets import ToolWidget, ToolButton logger = logging.getLogger('infoslicer') PUBLISH = 0 TITLE = 1 -class BookView(Gtk.VBox): +class BookView(gtk.VBox): def sync(self): if not self._changing: return - GObject.source_remove(self._changing) + gobject.source_remove(self._changing) index, column = self.tree.get_cursor() self._cursor_changed(index) def __init__(self, book, name, tooltip, custom): - GObject.GObject.__init__(self) + gtk.VBox.__init__(self) self.book = book self._changing = None self._check = None - title = Gtk.Toolbar() + title = gtk.Toolbar() # title checkbox if custom: - self._check = Gtk.CheckButton() + self._check = gtk.CheckButton() self._check.props.can_focus = False self._check.props.tooltip_text = \ _('Articles are ready to be published') self._check.connect('toggled', self._check_toggled_cb) - check_box = Gtk.HBox() + check_box = gtk.HBox() check_box.set_size_request(50, -1) - check_box.pack_start(self._check, True, False, 0) - tool_item = Gtk.ToolItem() - tool_item.add(check_box) - tool_item.show() - title.insert(tool_item, -1) + check_box.pack_start(self._check, True, False) + title.insert(ToolWidget(check_box), -1) else: - tool_item = Gtk.ToolItem() - tool_item.add(Gtk.Label(label=' ')) - tool_item.show() - title.insert(tool_item, -1) + title.insert(ToolWidget(gtk.Label(' ')), -1) # title caption - caption_label = Gtk.Label(label=name) + caption_label = gtk.Label(name) caption_label.props.tooltip_text = tooltip - caption_label.modify_fg(Gtk.StateType.NORMAL, COLOR_WHITE.get_gdk_color()) - caption_box = Gtk.HBox() - caption_box.pack_start(caption_label, False, False, 0) - caption = Gtk.EventBox() + caption_label.modify_fg(gtk.STATE_NORMAL, COLOR_WHITE.get_gdk_color()) + caption_box = gtk.HBox() + caption_box.pack_start(caption_label, False) + caption = gtk.EventBox() caption.add(caption_box) - caption.modify_bg(Gtk.StateType.NORMAL, COLOR_TOOLBAR_GREY.get_gdk_color()) + caption.modify_bg(gtk.STATE_NORMAL, COLOR_TOOLBAR_GREY.get_gdk_color()) + title.insert(ToolWidget(caption), -1) - tool_item = Gtk.ToolItem() - tool_item.add(caption) - tool_item.show() - title.insert(tool_item, -1) - - separator = Gtk.SeparatorToolItem() + separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) title.insert(separator, -1) @@ -88,8 +79,9 @@ class BookView(Gtk.VBox): # create article button if custom: - create = ToolButton('add') - create.set_tooltip(_('Create new article')) + create = ToolButton('add', + padding=0, + tooltip=_('Create new article')) create.connect('clicked', self._create_cb) title.insert(create, -1) else: @@ -98,71 +90,57 @@ class BookView(Gtk.VBox): # delete article button - delete = ToolButton('edit-delete') - delete.set_tooltip(_('Delete current article')) + delete = ToolButton('edit-delete', + padding=0, + tooltip=_('Delete current article')) delete.connect('clicked', self._delete_cb) title.insert(delete, -1) # move buttons - downward = ToolButton('down') - downward.set_tooltip(_('Move article downward')) + downward = ToolButton('down', + padding=0, + tooltip=_('Move article downward')) downward.connect('clicked', self._swap_cb, +1) title.insert(downward, -1) - - upward = ToolButton('up') - upward.set_tooltip(_('Move article upward')) + upward = ToolButton('up', + padding=0, + tooltip=_('Move article upward')) upward.connect('clicked', self._swap_cb, -1) title.insert(upward, -1) # tree - self.store = Gtk.ListStore(bool, str) - self.tree = Gtk.TreeView(self.store) + self.store = gtk.ListStore(bool, str) + self.tree = gtk.TreeView(self.store) self.tree.props.headers_visible = False self.tree.connect('cursor-changed', self._cursor_changed_cb) - cell = Gtk.CellRendererToggle() + cell = gtk.CellRendererToggle() cell.connect('toggled', self._cell_toggled_cb) cell.props.activatable = True - # FIXME: insert_column_with_attributes does not exist on pygobject - # column = self.tree.insert_column_with_attributes(0, '', cell, active=0) - - logging.debug('TODO: this is a workaround due ' - 'https://bugzilla.gnome.org/show_bug.cgi?id=679415') - - column = Gtk.TreeViewColumn('Wiki', cell) - column.props.sizing = Gtk.TreeViewColumnSizing.FIXED + column = self.tree.insert_column_with_attributes(0, '', cell, active=0) + column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED column.props.fixed_width = 50 column.props.visible = custom - self.tree.insert_column(column, 0) - - cell = Gtk.CellRendererText() + cell = gtk.CellRendererText() cell.connect('edited', self._cell_edited_cb) cell.props.editable = True - - # FIXME: insert_column_with_attributes does not exist on pygobject - # self.tree.insert_column_with_attributes(1, '', cell, text=1) - - logging.debug('TODO: this is a workaround due ' - 'https://bugzilla.gnome.org/show_bug.cgi?id=679415') - - column = Gtk.TreeViewColumn('Custom', cell, text=1) - self.tree.insert_column(column, 1) + self.tree.insert_column_with_attributes(1, '', cell, text=1) for i in self.book.index: self.store.append((i['ready'], i['title'])) # scrolled tree - tree_scroll = Gtk.ScrolledWindow() - tree_scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + tree_scroll = gtk.ScrolledWindow() + tree_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) tree_scroll.add(self.tree) - self.pack_start(title, False, False, 0) - self.pack_start(tree_scroll, True, True, 0) + self.pack_start(title, False) + self.pack_start(tree_scroll) if len(self.store): self.tree.set_cursor(0, self.tree.get_column(1), False) @@ -185,7 +163,7 @@ class BookView(Gtk.VBox): return find_name(list, prefix, uniq+1) if self._changing: - GObject.source_remove(self._changing) + gobject.source_remove(self._changing) self._changing = None name = find_name(self.store, _('New article'), 0) @@ -195,17 +173,15 @@ class BookView(Gtk.VBox): self._update_check(self.store[-1][PUBLISH]) def _delete_cb(self, widget): - path, focus_column = self.tree.get_cursor() - - if not path: + index, column = self.tree.get_cursor() + if not index: return + index = index[0] if self._changing: - GObject.source_remove(self._changing) + gobject.source_remove(self._changing) self._changing = None - index = path.get_indices()[0] - self.book.remove(self.store[index][TITLE]) self.store.remove(self.tree.props.model.get_iter(index)) @@ -216,16 +192,15 @@ class BookView(Gtk.VBox): self._update_check(self.store[index][PUBLISH]) def _swap_cb(self, widget, delta): - path, focus_column = self.tree.get_cursor() - - if not path: + old_index, column = self.tree.get_cursor() + if not old_index: return - old_index = path.get_indices()[0] + old_index = old_index[0] new_index = old_index + delta if new_index < 0: - new_index = len(self.store) - 1 + new_index = len(self.store)-1 elif new_index >= len(self.store): new_index = 0 @@ -259,12 +234,12 @@ class BookView(Gtk.VBox): def _cursor_changed_cb(self, widget): if self._changing: - GObject.source_remove(self._changing) + gobject.source_remove(self._changing) index, column = self.tree.get_cursor() if index != None: - self._changing = GObject.timeout_add(500, self._cursor_changed, + self._changing = gobject.timeout_add(500, self._cursor_changed, index) def _cursor_changed(self, index): @@ -12,16 +12,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GObject +import gtk +import gobject from gettext import gettext as _ -from sugar3.graphics.toolbutton import ToolButton -from sugar3.graphics.toggletoolbutton import ToggleToolButton - -from sugar3 import mime -from sugar3.graphics.objectchooser import ObjectChooser +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.toggletoolbutton import ToggleToolButton +from sugar.activity.activity import ActivityToolbox +from sugar.graphics.objectchooser import ObjectChooser +from sugar import mime from infoslicer.widgets.Edit_Pane import Edit_Pane from infoslicer.widgets.Format_Pane import Format_Pane @@ -32,8 +31,6 @@ from infoslicer.processing.Article import Article import book -import logging - TABS = (Edit_Pane(), Image_Pane(), @@ -41,14 +38,14 @@ TABS = (Edit_Pane(), Format_Pane()) -class View(Gtk.Notebook): +class View(gtk.Notebook): def __init__(self): - GObject.GObject.__init__(self) + gtk.Notebook.__init__(self) self.props.show_border = False self.props.show_tabs = False for i in TABS: - self.append_page(i, None) + self.append_page(i) i.show() self.connect('map', self._map_cb) @@ -64,8 +61,6 @@ class View(Gtk.Notebook): class ToolbarBuilder(): def __init__(self, edit, toolbar): self.edit = edit - logging.debug('init edit toolbar') - logging.debug(self.edit) self.txt_toggle = ToggleToolButton('ascii') self.img_toggle = ToggleToolButton('image') @@ -75,12 +70,12 @@ class ToolbarBuilder(): self.txt_toggle.set_tooltip(_('Text')) self.txt_toggle.connect('toggled', self._toggle_cb, - [self.txt_toggle, self.img_toggle, self.jimg_toggle]) + [self.txt_toggle, self.img_toggle]) toolbar.insert(self.txt_toggle, -1) self.img_toggle.set_tooltip(_('Images')) self.img_toggle.connect('toggled', self._toggle_cb, - [self.txt_toggle, self.img_toggle, self.jimg_toggle]) + [self.txt_toggle, self.img_toggle]) toolbar.insert(self.img_toggle, -1) self.jimg_toggle.set_tooltip(_('Journal Images')) @@ -105,38 +100,25 @@ class ToolbarBuilder(): def sensitize_all(self): self.txt_toggle.set_sensitive(True) self.img_toggle.set_sensitive(True) - self.jimg_toggle.set_sensitive(True) def unsensitize_all(self): self.txt_toggle.set_sensitive(False) self.img_toggle.set_sensitive(False) - self.jimg_toggle.set_sensitive(False) def _toggle_image_chooser(self, widget): - # self._old_cursor = self.edit.get_window().get_cursor() - # self.edit.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) - GObject.idle_add(self.__image_chooser) - - def __image_chooser(self): chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_IMAGE) result = chooser.run() - if result == Gtk.ResponseType.ACCEPT: + if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: title = str(jobject.metadata['title']) path = str(jobject.file_path) TABS[2].gallery.add_image(path, title) - # self.edit.get_window().set_cursor(self._old_cursor) def _toggle_text_chooser(self, widget): - # self._old_cursor = self.edit.get_window().get_cursor() - # self.edit.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) - GObject.idle_add(self.__text_chooser) - - def __text_chooser(self): chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_TEXT) result = chooser.run() - if result == Gtk.ResponseType.ACCEPT: + if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() if jobject and jobject.file_path: title = str(jobject.metadata['title']) @@ -146,7 +128,6 @@ class ToolbarBuilder(): fp.close() article_data = dehtml(text, title) TABS[0].set_source_article(Article(article_data)) - # self.edit.get_window().set_cursor(self._old_cursor) def _toggle_cb(self, widget, toggles): for tab in TABS: @@ -165,7 +146,6 @@ class ToolbarBuilder(): for i in TABS[index].toolitems: i.show() - # We don't require any article data to display jounal images if book.wiki.article and index != 2: TABS[index].set_source_article(book.wiki.article) if book.custom.article: diff --git a/infoslicer/processing/Article.py b/infoslicer/processing/Article.py index b3311b0..157b3c8 100644 --- a/infoslicer/processing/Article.py +++ b/infoslicer/processing/Article.py @@ -1,8 +1,8 @@ # Copyright (C) IBM Corporation 2008
-from gi.repository import Gtk
-from gi.repository import GdkPixbuf
-
+import pygtk
+pygtk.require('2.0')
+import gtk
from random import Random
from Article_Data import *
from Section import *
@@ -35,9 +35,9 @@ class Article: """
Created by Jonathan Mace
- The Article class maintains a concrete representation of the article, in the form of a Gtk.TextBuffer
+ The Article class maintains a concrete representation of the article, in the form of a gtk.TextBuffer
- Positions within the text are represented by Gtk.TextIter
+ Positions within the text are represented by gtk.TextIter
The class contains methods for inserting and deleting new sentences, paragraphs and sections.
@@ -56,7 +56,7 @@ class Article: """
Create default text buffer and set to empty
"""
- self.__buf = Gtk.TextBuffer()
+ self.__buf = gtk.TextBuffer()
self.__buf.set_text("")
insertionpoint = self.__buf.get_end_iter()
insertionmark = self.__buf.create_mark(None, insertionpoint, False)
@@ -149,7 +149,7 @@ class Article: nextsection = self.__sections[i+1]
if section.getStart().compare(nextsection.getStart()) == -1:
- text = self.__buf.get_slice(section.getStart(), nextsection.getStart(), True)
+ text = self.__buf.get_slice(section.getStart(), nextsection.getStart())
if len(text) > 2 and text[-2] != "\n":
nextsection.paragraphs = section.paragraphs + nextsection.paragraphs
else:
@@ -468,7 +468,7 @@ class Article: def getBuffer(self):
"""
- This method simply returns the Gtk.TextBuffer being maintained by this instance of the Article class.
+ This method simply returns the gtk.TextBuffer being maintained by this instance of the Article class.
"""
return self.__buf
@@ -638,10 +638,8 @@ class Article: self.markmark = self.__buf.create_mark(None, lociter, True)
self.__buf.insert(lociter, " ")
lociter = self.__buf.get_iter_at_mark(self.markmark)
- # FIXME: I don't know what the arrow_xpm type should be
- # https://bugzilla.gnome.org/show_bug.cgi?id=651962
- # arrow = GdkPixbuf.Pixbuf.new_from_xpm_data(arrow_xpm)
- # self.__buf.insert_pixbuf(lociter, arrow)
+ arrow = gtk.gdk.pixbuf_new_from_xpm_data(arrow_xpm)
+ self.__buf.insert_pixbuf(lociter, arrow)
def clearArrow(self):
diff --git a/infoslicer/processing/Sentence.py b/infoslicer/processing/Sentence.py index 9659dbb..09c31f4 100644 --- a/infoslicer/processing/Sentence.py +++ b/infoslicer/processing/Sentence.py @@ -1,10 +1,9 @@ # Copyright (C) IBM Corporation 2008
-import gi
-gi.require_version('Gtk', '3.0')
+import pygtk
+pygtk.require('2.0')
import os
-from gi.repository import Gtk
-from gi.repository import GdkPixbuf
+import gtk
import logging
from Article_Data import *
@@ -84,10 +83,10 @@ class RawSentence: return data
def getText(self):
- return self.buf.get_slice(self.getStart(), self.getEnd(), True)
+ return self.buf.get_slice(self.getStart(), self.getEnd())
def checkIntegrity(self, nextiter):
- text = self.buf.get_slice(self.getStart(), nextiter, True)
+ text = unicode(self.buf.get_slice(self.getStart(), nextiter))
lines = text.splitlines(True)
sentencestartoffset = self.getStart().get_offset()
sentences = []
@@ -135,7 +134,7 @@ class Sentence( RawSentence ): rightmark = buf.create_mark(None, insertioniter, True)
leftmark = buf.create_mark(None, insertioniter, False)
- buf.insert(insertioniter, sentence_data.text)
+ buf.insert(insertioniter, unicode(sentence_data.text))
left = buf.get_iter_at_mark(rightmark)
right = buf.get_iter_at_mark(leftmark)
buf.move_mark(leftmark, left)
@@ -160,7 +159,7 @@ class Picture( RawSentence ): leftmark = buf.create_mark(None, insertioniter, False)
if os.path.isfile(picture_data.text):
- pixbuf = GdkPixbuf.Pixbuf.new_from_file(picture_data.text)
+ pixbuf = gtk.gdk.pixbuf_new_from_file(picture_data.text)
buf.insert_pixbuf(insertioniter, pixbuf)
else:
logger.warning('cannot open image %s' % picture_data.text)
diff --git a/infoslicer/widgets/Edit_Pane.py b/infoslicer/widgets/Edit_Pane.py index d7ab056..8da2ad9 100644 --- a/infoslicer/widgets/Edit_Pane.py +++ b/infoslicer/widgets/Edit_Pane.py @@ -1,13 +1,11 @@ # Copyright (C) IBM Corporation 2008 -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GObject +import pygtk +pygtk.require('2.0') +import gtk import logging from gettext import gettext as _ -from sugar3.graphics.toolcombobox import ToolComboBox +from sugar.graphics.toolcombobox import ToolComboBox from Reading_View import Reading_View from Editing_View import Editing_View @@ -15,7 +13,7 @@ from infoslicer.processing.Article import Article logger = logging.getLogger('infoslicer') -class Edit_Pane(Gtk.HBox): +class Edit_Pane(gtk.HBox): """ Created by Jonathan Mace @@ -32,23 +30,23 @@ class Edit_Pane(Gtk.HBox): """ def __init__(self): - GObject.GObject.__init__(self) + gtk.HBox.__init__(self) self.toolitems = [] - readarticle_box = Gtk.VBox() + readarticle_box = gtk.VBox() readarticle_box.show() - labeleb = Gtk.EventBox() - labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE")) + labeleb = gtk.EventBox() + labeleb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#EEEEEE")) readarticle_box.pack_start(labeleb, False, False, 0) labeleb.show() - self.articletitle = Gtk.Label() - self.articletitle.set_justify(Gtk.Justification.CENTER) + self.articletitle = gtk.Label() + self.articletitle.set_justify(gtk.JUSTIFY_CENTER) labeleb.add(self.articletitle) self.articletitle.show() - vbox = Gtk.VBox() + vbox = gtk.VBox() snap = ToolComboBox(label_text=_('Snap selection to:')) snap.combo.append_item(0, _("Nothing")) @@ -56,21 +54,21 @@ class Edit_Pane(Gtk.HBox): snap.combo.append_item(2, _("Paragraphs")) snap.combo.append_item(3, _("Sections")) snap.combo.set_active(1) - vbox.pack_start(snap, False, False, 0) + vbox.pack_start(snap, False) """ Create reading and editing panels """ self.readarticle = Reading_View() - self.readarticle.set_size_request(Gdk.Screen.width()/2, -1) + self.readarticle.set_size_request(gtk.gdk.screen_width()/2, -1) self.readarticle.show() - readarticle_box.pack_start(self.readarticle, True, True, 0) - vbox.pack_start(readarticle_box, True, True, 0) + readarticle_box.pack_start(self.readarticle) + vbox.pack_start(readarticle_box) - self.pack_start(vbox, False, False, 0) + self.pack_start(vbox, False) self.editarticle = Editing_View() - self.pack_start(self.editarticle, True, True, 0) + self.pack_start(self.editarticle) self.editarticle.show() snap.combo.connect("changed", self.selection_mode_changed, None) diff --git a/infoslicer/widgets/Editable_Textbox.py b/infoslicer/widgets/Editable_Textbox.py index 14d65c1..fd8711f 100644 --- a/infoslicer/widgets/Editable_Textbox.py +++ b/infoslicer/widgets/Editable_Textbox.py @@ -1,16 +1,12 @@ # Copyright (C) IBM Corporation 2008
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import Gdk
-from gi.repository import GObject
-from gi.repository import Pango
+import pygtk
+pygtk.require('2.0')
+import gtk
import cPickle
+import pango
import copy
from Textbox import Textbox
-import logging
-
SNAP_SENTENCE, SNAP_PARAGRAPH, SNAP_SECTION, SNAP_NONE = range(4)
class Editable_Textbox( Textbox ):
@@ -22,11 +18,11 @@ class Editable_Textbox( Textbox ): """
def __init__(self):
- GObject.GObject.__init__(self)
+ gtk.TextView.__init__(self)
self.set_border_width(1)
self.set_cursor_visible(True)
self.set_editable(True)
- self.set_wrap_mode(Gtk.WrapMode.WORD)
+ self.set_wrap_mode(gtk.WRAP_WORD)
self.article = None
self.set_mode(SNAP_SENTENCE)
self.changed = False
@@ -34,17 +30,12 @@ class Editable_Textbox( Textbox ): self.selecting = False
self.handlers = []
- self.modify_font(Pango.FontDescription('arial 9'))
+ self.modify_font(pango.FontDescription('arial 9'))
self.ignore_snap_self = True
self.drag_source = False
self.edited = False
self.set_property("left-margin", 5)
- logging.debug('########### Editable_Textbox.drag_dest_set')
- self.drag_dest_set_target_list(None)
- self.drag_dest_add_text_targets()
- self.drag_dest_add_image_targets()
-
def set_article(self, article):
self.article = article
self.set_buffer(article.getBuffer())
@@ -56,7 +47,7 @@ class Editable_Textbox( Textbox ): self.article.delete()
def get_mouse_iter(self, x, y):
- click_coords = self.window_to_buffer_coords(Gtk.TextWindowType.TEXT, x, y)
+ click_coords = self.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
mouseClickPositionIter = self.get_iter_at_location(click_coords[0], click_coords[1])
return mouseClickPositionIter
@@ -68,19 +59,19 @@ class Editable_Textbox( Textbox ): self.disconnect(handler)
buffer.connect("changed", self.text_changed, None)
- Gtk.TextView.set_buffer(self, buffer)
+ gtk.TextView.set_buffer(self, buffer)
self.handlers = []
self.handlers.append(self.connect("button-press-event", self.clicked_event, None))
self.handlers.append(self.connect("button-release-event", self.unclicked_event, None))
- self.handlers.append(self.connect("drag-data-get", self.drag_data_get_event, None))
- self.handlers.append(self.connect("drag-begin", self.drag_begin_event, None))
+ self.handlers.append(self.connect("drag_data_get", self.drag_data_get_event, None))
+ self.handlers.append(self.connect("drag_begin", self.drag_begin_event, None))
self.handlers.append(self.connect("drag-motion", self.drag_motion_event, None))
self.handlers.append(self.connect("drag-drop", self.drag_drop_event, None))
self.handlers.append(self.connect("drag-leave", self.drag_leave_event, None))
self.handlers.append(self.connect("drag-data-delete", self.drag_data_delete_event, None))
- self.handlers.append(self.connect("drag-data-received", self.drag_data_received_event, None))
+ self.handlers.append(self.connect("drag_data_received", self.drag_data_received_event, None))
self.handlers.append(self.connect("drag-end", self.drag_end_event, None))
self.handlers.append(self.connect("motion-notify-event", self.motion_notify, None))
self.handlers.append(self.connect("focus-out-event", self.leave_notify, None))
@@ -152,7 +143,7 @@ class Editable_Textbox( Textbox ): self.block = True
def clicked_event(self, widget, event, data):
- if event.type == Gdk.EventType._2BUTTON_PRESS or event.type == Gdk.EventType._3BUTTON_PRESS:
+ if event.type == gtk.gdk._2BUTTON_PRESS or event.type == gtk.gdk._3BUTTON_PRESS:
self.stop_emission("button_press_event")
return
if event.button == 3:
@@ -211,7 +202,6 @@ class Editable_Textbox( Textbox ): return False
def drag_begin_event(self, widget, context, data):
- logging.debug('############ Editable_Textbox.drag_begin_event')
self.grab_focus()
if self.snapto != SNAP_NONE:
a = self.article
@@ -266,12 +256,11 @@ class Editable_Textbox( Textbox ): self.changed = False
def drag_data_received_event(self, widget, context, x, y, selection_data, info, time, data):
- logging.debug('################ Editable_Textbox.drag_data_received_event')
if self.snapto != SNAP_NONE and not self.ignore_snap_self or (not self.drag_source and self.ignore_snap_self):
a = self.article
insert_loc = self.get_mouse_iter(x, y)
- data_received_type = str(selection_data.get_data_type())
- data = cPickle.loads(str(selection_data.get_data()))
+ data_received_type = str(selection_data.type)
+ data = cPickle.loads(str(selection_data.data))
if data_received_type == "sentence":
bestpoint = insert_loc
@@ -287,16 +276,15 @@ class Editable_Textbox( Textbox ): self.grab_focus()
def drag_data_get_event(self, widget, context, selection_data, info, time, data):
- logging.debug('############### Editable_Textbox.drag_data_get_event')
if not self.ignore_snap_self and self.snapto != SNAP_NONE:
a = self.article
if self.snapto == SNAP_SENTENCE:
- atom = Gdk.atom_intern("sentence", only_if_exists=False)
+ atom = gtk.gdk.atom_intern("sentence")
if self.snapto == SNAP_PARAGRAPH:
- atom = Gdk.atom_intern("paragraph", only_if_exists=False)
+ atom = gtk.gdk.atom_intern("paragraph")
if self.snapto == SNAP_SECTION:
- atom = Gdk.atom_intern("section", only_if_exists=False)
+ atom = gtk.gdk.atom_intern("section")
string = cPickle.dumps(a.getSelection())
selection_data.set(atom, 8, string)
diff --git a/infoslicer/widgets/Editing_View.py b/infoslicer/widgets/Editing_View.py index 3f9ecdc..5506a7f 100644 --- a/infoslicer/widgets/Editing_View.py +++ b/infoslicer/widgets/Editing_View.py @@ -1,35 +1,33 @@ # Copyright (C) IBM Corporation 2008
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import Gdk
-from gi.repository import GObject
+import pygtk
+pygtk.require('2.0')
+import gtk
from Editable_Textbox import Editable_Textbox
-class Editing_View( Gtk.VBox ):
+class Editing_View( gtk.VBox ):
"""
Created by Jonathan Mace
This class wraps an editable textbox into a scrollable window and
gives it a title.
"""
def __init__(self):
- GObject.GObject.__init__(self)
+ gtk.VBox.__init__(self)
self.set_border_width(0)
self.set_spacing(2)
- labeleb = Gtk.EventBox()
- labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE"))
+ labeleb = gtk.EventBox()
+ labeleb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#EEEEEE"))
self.pack_start(labeleb, False, False, 0)
labeleb.show()
- self.articletitle = Gtk.Label()
- self.articletitle.set_justify(Gtk.Justification.CENTER)
+ self.articletitle = gtk.Label()
+ self.articletitle.set_justify(gtk.JUSTIFY_CENTER)
labeleb.add(self.articletitle)
self.articletitle.show()
- self.textwindow = Gtk.ScrolledWindow()
- self.textwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
- self.pack_start(self.textwindow, True, True, 0)
+ self.textwindow = gtk.ScrolledWindow()
+ self.textwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ self.pack_start(self.textwindow)
self.textwindow.show()
self.textbox = Editable_Textbox()
diff --git a/infoslicer/widgets/Format_Pane.py b/infoslicer/widgets/Format_Pane.py index 1be64f2..ef8c2f5 100644 --- a/infoslicer/widgets/Format_Pane.py +++ b/infoslicer/widgets/Format_Pane.py @@ -1,7 +1,7 @@ # Copyright (C) IBM Corporation 2008 -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk +import pygtk +pygtk.require('2.0') +import gtk from gettext import gettext as _ from Editing_View import Editing_View @@ -22,22 +22,22 @@ class Format_Pane(Editing_View): self.toolitems = [] """ - self.combocontainer = Gtk.ToolItem() + 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 = gtk.ToolButton(gtk.STOCK_BOLD) self.boldbutton.set_expand(False) self.toolbar.insert(self.boldbutton, -1) self.boldbutton.show() - self.italicbutton = Gtk.ToolButton(Gtk.STOCK_ITALIC) + self.italicbutton = gtk.ToolButton(gtk.STOCK_ITALIC) self.italicbutton.set_expand(False) self.toolbar.insert(self.italicbutton, -1) self.italicbutton.show() - self.underlinebutton = Gtk.ToolButton(Gtk.STOCK_UNDERLINE) + self.underlinebutton = gtk.ToolButton(gtk.STOCK_UNDERLINE) self.underlinebutton.set_expand(False) self.toolbar.insert(self.underlinebutton, -1) self.underlinebutton.show() diff --git a/infoslicer/widgets/Gallery_View.py b/infoslicer/widgets/Gallery_View.py index 7cd3ce8..6ca0720 100644 --- a/infoslicer/widgets/Gallery_View.py +++ b/infoslicer/widgets/Gallery_View.py @@ -1,8 +1,7 @@ # Copyright (C) IBM Corporation 2008
-from gi.repository import Gtk
-from gi.repository import Gdk
-from gi.repository import GObject
-from gi.repository import GdkPixbuf
+import pygtk
+pygtk.require('2.0')
+import gtk
import os
import cPickle
import logging
@@ -14,7 +13,7 @@ import book logger = logging.getLogger('infoslicer')
-class Gallery_View( Gtk.HBox ):
+class Gallery_View( gtk.HBox ):
"""
Created by Christopher Leonard
Drag-and-drop methods added by Jonathan Mace
@@ -24,67 +23,63 @@ class Gallery_View( Gtk.HBox ): displays the images associated with that article, in a scrollable display.
- Drag-and-drop methods have been added to set up the images as a
- drag source. The data returned by drag-data-get will be a list
- containing an Image_Data object and a Sentence_Data object. These
- correspond to the image and caption respectively.
+ Drag-and-drop methods have been added to set up the images as a drag
+ source.
+ The data returned by drag-data-get will be a list containing
+ an Image_Data object and a Sentence_Data object.
+ These correspond to the image
+ and caption respectively.
"""
def __init__(self):
self.image_list = []
- GObject.GObject.__init__(self)
- self.set_size_request(int(Gdk.Screen.width() / 2), -1)
+ gtk.HBox.__init__(self)
+
self.current_index = -1
- left_button = Gtk.Button(label="\n\n << \n\n")
+ left_button = gtk.Button(label="\n\n << \n\n")
- right_button = Gtk.Button(label="\n\n >> \n\n")
+ right_button = gtk.Button(label="\n\n >> \n\n")
- self.imagenumberlabel = Gtk.Label()
+ self.imagenumberlabel = gtk.Label()
- self.image = Gtk.Image()
+ self.image = gtk.Image()
- self.imagebox = Gtk.EventBox()
+ self.imagebox = gtk.EventBox()
self.imagebox.add(self.image)
- self.imagebox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
- [],
- Gdk.DragAction.COPY)
- self.imagebox.drag_source_add_image_targets()
+ self.imagebox.drag_source_set(gtk.gdk.BUTTON1_MASK, [("text/plain", gtk.TARGET_SAME_APP, 80)], gtk.gdk.ACTION_COPY)
self.imagebox.connect("drag-begin", self.drag_begin_event, None)
- logging.debug('##################### Gallery_View.connect')
self.imagebox.connect("drag-data-get", self.drag_data_get_event, None)
- self.caption = Gtk.Label(label="")
- self.caption.set_size_request(int(Gdk.Screen.width() / 3), -1)
+ self.caption = gtk.Label("")
self.caption.set_line_wrap(True)
- self.caption.set_max_width_chars(40)
-
- self.image_drag_container = Gtk.VBox()
- self.image_drag_container.pack_start(self.imagenumberlabel, expand=False,
- fill=False, padding=0)
- self.image_drag_container.pack_start(self.imagebox, False, False, 0)
- self.image_drag_container.pack_start(self.caption, False, False, 0)
-
- image_container = Gtk.VBox()
- image_container.pack_start(Gtk.Label(" "), True, True, 0)
- image_container.pack_start(self.image_drag_container, False, True, 0)
- image_container.pack_start(Gtk.Label(" "), True, True, 0)
-
- left_button_container = Gtk.VBox()
- left_button_container.pack_start(Gtk.Label(" "), True, True, 0)
- left_button_container.pack_start(left_button, False, True, 0)
- left_button_container.pack_start(Gtk.Label(" "), True, True, 0)
-
- right_button_container = Gtk.VBox()
- right_button_container.pack_start(Gtk.Label(" "), True, True, 0)
- right_button_container.pack_start(right_button, False, True, 0)
- right_button_container.pack_start(Gtk.Label(" "), True, True, 0)
+ self.caption.set_width_chars(40)
+
+ self.image_drag_container = gtk.VBox()
+ self.image_drag_container.pack_start(self.imagenumberlabel, expand = False)
+ self.image_drag_container.pack_start(self.imagebox, expand=False)
+ self.image_drag_container.pack_start(self.caption, expand=False)
+
+ image_container = gtk.VBox()
+ image_container.pack_start(gtk.Label(" "))
+ image_container.pack_start(self.image_drag_container, expand=False)
+ image_container.pack_start(gtk.Label(" "))
+
+ left_button_container = gtk.VBox()
+ left_button_container.pack_start(gtk.Label(" "))
+ left_button_container.pack_start(left_button, expand=False)
+ left_button_container.pack_start(gtk.Label(" "))
+
+ right_button_container = gtk.VBox()
+ right_button_container.pack_start(gtk.Label(" "))
+ right_button_container.pack_start(right_button, expand=False)
+ right_button_container.pack_start(gtk.Label(" "))
- self.pack_start(left_button_container, False, True, 0)
- self.pack_start(image_container, True, True, 0)
- self.pack_start(right_button_container, False, True, 0)
+ self.pack_start(left_button_container, expand=False)
+ self.pack_start(image_container)
+ self.pack_start(right_button_container, expand=False)
self._source_article = None
self.show_all()
@@ -105,7 +100,7 @@ class Gallery_View( Gtk.HBox ): self.current_index += 1
if self.current_index == len(self.image_list):
self.current_index = 0
- self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
+ self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0])
self.image.set_from_pixbuf(self.imagebuf)
self.caption.set_text("\n" + self.image_list[self.current_index][1])
self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list)))
@@ -121,7 +116,7 @@ class Gallery_View( Gtk.HBox ): if self.current_index == 0:
self.current_index = len(self.image_list)
self.current_index -= 1
- self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
+ self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0])
self.image.set_from_pixbuf(self.imagebuf)
self.caption.set_text("\n" + self.image_list[self.current_index][1])
self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list)))
@@ -135,7 +130,7 @@ class Gallery_View( Gtk.HBox ): self.image.clear()
return
self.current_index = 0
- self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
+ self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0])
self.image.set_from_pixbuf(self.imagebuf)
self.caption.set_text("\n" + self.image_list[self.current_index][1])
logger.debug("setting text to:")
@@ -149,12 +144,11 @@ class Gallery_View( Gtk.HBox ): logger.debug(self.image_list)
def drag_begin_event(self, widget, context, data):
- logging.debug('########### Gallery_View.drag_begin_event called')
self.imagebox.drag_source_set_icon_pixbuf(self.imagebuf)
def drag_data_get_event(self, widget, context, selection_data, info, timestamp, data):
- logger.debug('############# Gallery_View.drag_data_get_event')
- atom = Gdk.atom_intern("section", only_if_exists=False)
+ logger.debug("getting data")
+ atom = gtk.gdk.atom_intern("section")
imagedata = Picture_Data(self.source_article_id,
self.image_list[self.current_index][0],
self.image_list[self.current_index][2])
diff --git a/infoslicer/widgets/Image_Pane.py b/infoslicer/widgets/Image_Pane.py index 473253c..99026f0 100644 --- a/infoslicer/widgets/Image_Pane.py +++ b/infoslicer/widgets/Image_Pane.py @@ -1,9 +1,7 @@ # Copyright (C) IBM Corporation 2008 -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GObject +import pygtk +pygtk.require('2.0') +import gtk import logging from gettext import gettext as _ @@ -13,7 +11,7 @@ from infoslicer.processing.Article import Article logger = logging.getLogger('infoslicer') -class Image_Pane(Gtk.HBox): +class Image_Pane(gtk.HBox): """ Created by Christopher Leonard @@ -25,29 +23,29 @@ class Image_Pane(Gtk.HBox): """ def __init__(self): - GObject.GObject.__init__(self) + gtk.HBox.__init__(self) self.toolitems = [] - gallery_box = Gtk.VBox() + gallery_box = gtk.VBox() gallery_box.show() - labeleb = Gtk.EventBox() - labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE")) + labeleb = gtk.EventBox() + labeleb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#EEEEEE")) gallery_box.pack_start(labeleb, False, False, 0) labeleb.show() - self.articletitle = Gtk.Label() - self.articletitle.set_justify(Gtk.Justification.CENTER) + self.articletitle = gtk.Label() + self.articletitle.set_justify(gtk.JUSTIFY_CENTER) labeleb.add(self.articletitle) self.articletitle.show() self.gallery = Gallery_View() - self.gallery.set_size_request(Gdk.Screen.width()/2, -1) - gallery_box.pack_start(self.gallery, True, True, 0) + self.gallery.set_size_request(gtk.gdk.screen_width()/2, -1) + gallery_box.pack_start(self.gallery) - self.pack_start(gallery_box, False, False, 0) + self.pack_start(gallery_box, False) self.editarticle = Editing_View() - self.pack_start(self.editarticle, True, True, 0) + self.pack_start(self.editarticle) self.editarticle.show_all() self.gallery._source_article = None diff --git a/infoslicer/widgets/Journal_Gallery_View.py b/infoslicer/widgets/Journal_Gallery_View.py index 5358d05..022cb6e 100644 --- a/infoslicer/widgets/Journal_Gallery_View.py +++ b/infoslicer/widgets/Journal_Gallery_View.py @@ -10,10 +10,8 @@ # along with this library; if not, write to the Free Software # Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GObject -from gi.repository import GdkPixbuf +import gtk +import gobject import os import cPickle import pickle @@ -31,7 +29,7 @@ logger = logging.getLogger('infoslicer') IMG_WIDTH = 400 IMG_HEIGHT = 300 -class Journal_Gallery_View( Gtk.HBox ): +class Journal_Gallery_View( gtk.HBox ): """ Created by Aneesh Dogra Journal Gallery View @@ -48,47 +46,47 @@ class Journal_Gallery_View( Gtk.HBox ): def __init__(self): self.image_list = [] - GObject.GObject.__init__(self) + gtk.HBox.__init__(self) + self.current_index = -1 self.source_article_id = -1 - left_button = Gtk.Button(label="\n\n << \n\n") - right_button = Gtk.Button(label="\n\n >> \n\n") - self.imagenumberlabel = Gtk.Label() - self.image = Gtk.Image() - self.imagebox = Gtk.EventBox() + left_button = gtk.Button("\n\n << \n\n") + right_button = gtk.Button("\n\n >> \n\n") + self.imagenumberlabel = gtk.Label() + self.image = gtk.Image() + self.imagebox = gtk.EventBox() self.imagebox.add(self.image) - self.imagebox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, + self.imagebox.drag_source_set(gtk.gdk.BUTTON1_MASK, [], - Gdk.DragAction.COPY) + gtk.gdk.ACTION_COPY) self.imagebox.drag_source_add_image_targets() self.imagebox.connect("drag-begin", self.drag_begin_event, None) logging.debug('##################### Galler_View.connect') self.imagebox.connect("drag-data-get", self.drag_data_get_event, None) - self.caption = Gtk.Label(label="") + self.caption = gtk.Label("") self.caption.set_line_wrap(True) - self.image_drag_container = Gtk.VBox() + self.image_drag_container = gtk.VBox() self.image_drag_container.pack_start(self.imagenumberlabel, expand=False, fill=False, padding=0) self.image_drag_container.pack_start(self.imagebox, False, True, 0) self.image_drag_container.pack_start(self.caption, False, True, 0) - image_container = Gtk.VBox() - image_container.pack_start(Gtk.Label(" "), True, True, 0) + image_container = gtk.VBox() + image_container.pack_start(gtk.Label(" "), True, True, 0) image_container.pack_start(self.image_drag_container, False, True, 0) - image_container.pack_start(Gtk.Label(" "), True, True, 0) + image_container.pack_start(gtk.Label(" "), True, True, 0) - left_button_container = Gtk.VBox() - left_button_container.pack_start(Gtk.Label(" "), True, True, 0) + left_button_container = gtk.VBox() + left_button_container.pack_start(gtk.Label(" "), True, True, 0) left_button_container.pack_start(left_button, False, True, 0) - left_button_container.pack_start(Gtk.Label(" "), True, True, 0) + left_button_container.pack_start(gtk.Label(" "), True, True, 0) - right_button_container = Gtk.VBox() - right_button_container.pack_start(Gtk.Label(" "), True, True, 0) + right_button_container = gtk.VBox() + right_button_container.pack_start(gtk.Label(" "), True, True, 0) right_button_container.pack_start(right_button, False, True, 0) - right_button_container.pack_start(Gtk.Label(" "), True, True, 0) - + right_button_container.pack_start(gtk.Label(" "), True, True, 0) self.pack_start(left_button_container, False, True, 0) self.pack_start(image_container, True, True, 0) @@ -107,9 +105,9 @@ class Journal_Gallery_View( Gtk.HBox ): self.current_index += 1 if self.current_index == len(self.image_list): self.current_index = 0 - self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0]) + self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0]) self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT, - GdkPixbuf.InterpType.BILINEAR) + gtk.gdk.INTERP_BILINEAR) self.image.set_from_pixbuf(self.imagebuf) self.caption.set_text("\n" + self.image_list[self.current_index][1]) self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list))) @@ -122,9 +120,9 @@ class Journal_Gallery_View( Gtk.HBox ): if self.current_index == 0: self.current_index = len(self.image_list) self.current_index -= 1 - self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0]) + self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0]) self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT, - GdkPixbuf.InterpType.BILINEAR) + gtk.gdk.INTERP_BILINEAR) self.image.set_from_pixbuf(self.imagebuf) self.caption.set_text("\n" + self.image_list[self.current_index][1]) self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list))) @@ -135,9 +133,9 @@ class Journal_Gallery_View( Gtk.HBox ): self.image.clear() return self.current_index = 0 - self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0]) + self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0]) self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT, - GdkPixbuf.InterpType.BILINEAR) + gtk.gdk.INTERP_BILINEAR) self.image.set_from_pixbuf(self.imagebuf) self.caption.set_text("\n" + self.image_list[self.current_index][1]) logger.debug("setting text to:") diff --git a/infoslicer/widgets/Journal_Image_Pane.py b/infoslicer/widgets/Journal_Image_Pane.py index 38c1c23..723389b 100644 --- a/infoslicer/widgets/Journal_Image_Pane.py +++ b/infoslicer/widgets/Journal_Image_Pane.py @@ -1,9 +1,6 @@ # Copyright (C) IBM Corporation 2008 -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GObject +import gtk +import gobject import logging from gettext import gettext as _ @@ -13,7 +10,7 @@ from infoslicer.processing.Article import Article logger = logging.getLogger('infoslicer') -class Journal_Image_Pane(Gtk.HBox): +class Journal_Image_Pane(gtk.HBox): """ Created by Aneesh Dogra @@ -25,24 +22,24 @@ class Journal_Image_Pane(Gtk.HBox): """ def __init__(self): - GObject.GObject.__init__(self) + gtk.HBox.__init__(self) self.toolitems = [] - gallery_box = Gtk.VBox() + gallery_box = gtk.VBox() gallery_box.show() - labeleb = Gtk.EventBox() - labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE")) + labeleb = gtk.EventBox() + labeleb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#EEEEEE")) gallery_box.pack_start(labeleb, False, False, 0) labeleb.show() - self.articletitle = Gtk.Label() - self.articletitle.set_justify(Gtk.Justification.CENTER) + self.articletitle = gtk.Label() + self.articletitle.set_justify(gtk.JUSTIFY_CENTER) labeleb.add(self.articletitle) self.articletitle.show() self.gallery = Journal_Gallery_View() - self.gallery.set_size_request(Gdk.Screen.width()/2, -1) + self.gallery.set_size_request(int(gtk.gdk.screen_width() / 2), -1) gallery_box.pack_start(self.gallery, True, True, 0) self.pack_start(gallery_box, False, False, 0) diff --git a/infoslicer/widgets/Reading_View.py b/infoslicer/widgets/Reading_View.py index 3c40757..55609c9 100644 --- a/infoslicer/widgets/Reading_View.py +++ b/infoslicer/widgets/Reading_View.py @@ -1,15 +1,14 @@ # Copyright (C) IBM Corporation 2008
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import GObject
+import pygtk
+pygtk.require('2.0')
+import gtk
from Readonly_Textbox import Readonly_Textbox
import logging
logger = logging.getLogger('infoslicer')
elogger = logging.getLogger('infoslicer::except')
-class Reading_View( Gtk.VBox ):
+class Reading_View( gtk.VBox ):
"""
Created by Jonathan Mace
@@ -22,11 +21,11 @@ class Reading_View( Gtk.VBox ): """
def __init__(self):
- GObject.GObject.__init__(self)
+ gtk.VBox.__init__(self)
- self.articlewindow = Gtk.ScrolledWindow()
- self.articlewindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
- self.pack_start(self.articlewindow, True, True, 0)
+ self.articlewindow = gtk.ScrolledWindow()
+ self.articlewindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ self.pack_start(self.articlewindow)
self.articlewindow.show()
self.textbox = Readonly_Textbox()
diff --git a/infoslicer/widgets/Readonly_Textbox.py b/infoslicer/widgets/Readonly_Textbox.py index 3d8e40f..958cfcd 100644 --- a/infoslicer/widgets/Readonly_Textbox.py +++ b/infoslicer/widgets/Readonly_Textbox.py @@ -1,9 +1,9 @@ # Copyright (C) IBM Corporation 2008
-from gi.repository import Gtk
-from gi.repository import Gdk
-from gi.repository import Pango
+import pygtk
+pygtk.require('2.0')
+import gtk
+import pango
import cPickle
-import logging
from Textbox import Textbox
SELECT_SENTENCE, SELECT_PARAGRAPH, SELECT_SECTION, FULL_EDIT = range(4)
@@ -24,8 +24,7 @@ class Readonly_Textbox( Textbox ): self.use_as_drag_source = use_as_drag_source
self.set_mode(SELECT_SENTENCE)
self.block = True
- self.modify_font(Pango.FontDescription('arial 9'))
- self.MANUEL = 0
+ self.modify_font(pango.FontDescription('arial 9'))
def set_mode(self, mode):
@@ -42,17 +41,15 @@ class Readonly_Textbox( Textbox ): self.event_handlers.append(self.connect("motion-notify-event", self.motion_notify, None))
self.event_handlers.append(self.connect("move-cursor", self.move_cursor, None))
self.event_handlers.append(self.connect("button-release-event", self.unclicked_event, None))
- self.event_handlers.append(self.connect("drag-data-get", self.drag_data_get_event, None))
- logging.debug('------------------------ SIGNALS ; %s', id(self))
+ self.event_handlers.append(self.connect("drag_data_get", self.drag_data_get_event, None))
self.event_handlers.append(self.connect("drag-motion", self.drag_motion, None))
def drag_motion(self, widget, context, x, y, timestamp, data):
- logging.debug('############ Readonly_Textbox.drag_motion')
- Gdk.drag_status(context, Gdk.DragAction.COPY, timestamp)
+ context.drag_status(gtk.gdk.ACTION_COPY, timestamp)
return True
def clicked_event(self, widget, event, data):
- if event.type == Gdk.EventType._2BUTTON_PRESS or event.type == Gdk.EventType._3BUTTON_PRESS:
+ if event.type == gtk.gdk._2BUTTON_PRESS or event.type == gtk.gdk._3BUTTON_PRESS:
self.stop_emission("button_press_event")
return
if event.button == 3:
@@ -117,13 +114,7 @@ class Readonly_Textbox( Textbox ): if self.block == True:
self.stop_emission("motion-notify-event")
self.block = False
- logging.debug('FIXME: this is a workaround due '
- 'https://bugzilla.gnome.org/show_bug.cgi?id=679795')
- # I was getting this error:
- # TypeError: could not convert type EventMotion
- # to GdkEvent required for parameter 0
- # self.emit("motion-notify-event", event)
- self.emit("motion-notify-event", Gdk.Event())
+ self.emit("motion-notify-event", event)
buf = self.get_buffer()
mouseiter = self.get_mouse_iter(int(event.x), int(event.y))
@@ -148,7 +139,7 @@ class Readonly_Textbox( Textbox ): if self.selectionmode == SELECT_SECTION:
selectionstart = article.getSection(mouseiter).getStart()
selectionend = article.getSection(self.selectionstart).getEnd()
- self.scroll_to_iter(mouseiter, 0, False, 0.5, 0.5)
+ self.scroll_to_iter(mouseiter, 0)
article.highlight(selectionstart, selectionend)
else:
@@ -161,20 +152,18 @@ class Readonly_Textbox( Textbox ): self.stop_emission("button-release-event")
def drag_data_get_event(self, widget, context, selection_data, info, time, data):
- logging.debug('######## Readonly_Textbox.drag_data_get_event')
- logging.debug('############################## %s', self.MANUEL)
+
a = self.article
if self.selectionmode == SELECT_SENTENCE:
- atom = Gdk.atom_intern("sentence", only_if_exists=False)
+ atom = gtk.gdk.atom_intern("sentence")
if self.selectionmode == SELECT_PARAGRAPH:
- atom = Gdk.atom_intern("paragraph", only_if_exists=False)
+ atom = gtk.gdk.atom_intern("paragraph")
if self.selectionmode == SELECT_SECTION:
- atom = Gdk.atom_intern("section", only_if_exists=False)
+ atom = gtk.gdk.atom_intern("section")
string = cPickle.dumps(a.getSelection())
selection_data.set(atom, 8, string)
self.stop_emission("drag-data-get")
self.set_editable(False)
- self.MANUEL += 1
diff --git a/infoslicer/widgets/Textbox.py b/infoslicer/widgets/Textbox.py index 0e586ad..95f0681 100644 --- a/infoslicer/widgets/Textbox.py +++ b/infoslicer/widgets/Textbox.py @@ -1,14 +1,13 @@ # Copyright (C) IBM Corporation 2008
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import GObject
-from gi.repository import Pango
+import pygtk
+pygtk.require('2.0')
+import gtk
import cPickle
+import pango
SELECT_SENTENCE, SELECT_PARAGRAPH, SELECT_SECTION, FULL_EDIT = range(4)
-class Textbox( Gtk.TextView ):
+class Textbox( gtk.TextView ):
"""
Created by Jonathan Mace
The Textbox class is the base class for our own custom textboxes which implement
@@ -20,13 +19,13 @@ class Textbox( Gtk.TextView ): def __init__(self):
- GObject.GObject.__init__(self)
+ gtk.TextView.__init__(self)
self.set_border_width(1)
self.event_handlers = []
- self.set_wrap_mode(Gtk.WrapMode.WORD)
+ self.set_wrap_mode(gtk.WRAP_WORD)
self.set_cursor_visible(False)
self.set_editable(False)
- self.modify_font(Pango.FontDescription('arial 9'))
+ self.modify_font(pango.FontDescription('arial 9'))
self.article = None
self.set_property("left-margin", 5)
@@ -38,7 +37,7 @@ class Textbox( Gtk.TextView ): return self.article
def show(self):
- Gtk.TextView.show(self)
+ gtk.TextView.show(self)
def clear(self):
self.article.delete()
@@ -52,6 +51,6 @@ class Textbox( Gtk.TextView ): def get_mouse_iter(self, x, y):
# Convenience method to get the iter in the buffer of x, y coords.
- click_coords = self.window_to_buffer_coords(Gtk.TextWindowType.TEXT, x, y)
+ click_coords = self.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
mouseClickPositionIter = self.get_iter_at_location(click_coords[0], click_coords[1])
- return mouseClickPositionIter
+ return mouseClickPositionIter
\ No newline at end of file diff --git a/infoslicer/widgets/__init__.py b/infoslicer/widgets/__init__.py index 533d012..1bc63d4 100644 --- a/infoslicer/widgets/__init__.py +++ b/infoslicer/widgets/__init__.py @@ -1,21 +1,3 @@ -# Copyright (C) IBM Corporation 2008 -""" -Every class of type *_Pane has the following. -Thank python for not having interfaces. +# Copyright (C) IBM Corporation 2008 -pane.panel -pane.toolbar - -These correspond to the main view and toolbar associated with this pane. - -set_source_article -get_source_article -set_working_article -get_working_article - -The GUI passes the currently selected source and working articles between panes -when panes are switched. The pane will always be given an article using -set_source_article before the get_source_article method is called. Thus it is -feasible to just save the article argument and return it in the get method. - -""" +# This file should exist, despite having no code in it @@ -12,22 +12,21 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GObject +import gtk import logging from threading import Timer from datetime import datetime from gettext import gettext as _ import locale -from sugar3.graphics.toolbutton import ToolButton -from sugar3.graphics.toggletoolbutton import ToggleToolButton -from sugar3.graphics.toolcombobox import ToolComboBox -from sugar3.graphics.icon import Icon -from sugar3.datastore import datastore -from sugar3.graphics.alert import Alert -import sugar3.graphics.style as style +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 sugar.graphics.icon import Icon +from sugar.datastore import datastore +import sugar.graphics.style as style +from port.widgets import ToolWidget import xol import net @@ -37,13 +36,13 @@ from infoslicer.widgets.Reading_View import Reading_View logger = logging.getLogger('infoslicer') -class View(Gtk.EventBox): +class View(gtk.EventBox): def sync(self): self.wiki.sync() self.custom.sync() def __init__(self, activity): - GObject.GObject.__init__(self) + gtk.EventBox.__init__(self) self.activity = activity self.wiki = BookView(book.wiki, @@ -54,18 +53,18 @@ class View(Gtk.EventBox): # stubs for empty articles def create_stub(icon_name, head_text, tail_text): - head_label = Gtk.Label(label=head_text) - head_label_a = Gtk.Alignment.new(0.5, 1, 0, 0) + head_label = gtk.Label(head_text) + head_label_a = gtk.Alignment(0.5, 1, 0, 0) head_label_a.add(head_label) icon = Icon(icon_name=icon_name, - icon_size=Gtk.IconSize.LARGE_TOOLBAR) - tail_label = Gtk.Label(label=tail_text) - tail_label_a = Gtk.Alignment.new(0.5, 0, 0, 0) + icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) + tail_label = gtk.Label(tail_text) + tail_label_a = gtk.Alignment(0.5, 0, 0, 0) tail_label_a.add(tail_label) - stub = Gtk.VBox() - stub.pack_start(head_label_a, True, True, 0) - stub.pack_start(icon, False, False, 0) - stub.pack_start(tail_label_a, True, True, 0) + stub = gtk.VBox() + stub.pack_start(head_label_a) + stub.pack_start(icon, False) + stub.pack_start(tail_label_a) return stub wiki_stub = create_stub('white-search', @@ -80,7 +79,7 @@ class View(Gtk.EventBox): wiki_prefix = lang_code[0:2] + '.' language_order = 0 order = 0 - search_box = Gtk.HBox() + 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) @@ -88,69 +87,64 @@ class View(Gtk.EventBox): language_order = order order = order + 1 self.wikimenu.combo.set_active(language_order) - search_box.pack_start(self.wikimenu, False, False, 0) + search_box.pack_start(self.wikimenu, False) - self.searchentry = Gtk.Entry() - self.searchentry.set_size_request(int(Gdk.Screen.width() / 6), -1) + self.searchentry = gtk.Entry() + self.searchentry.set_size_request(int(gtk.gdk.screen_width() / 6), -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, True, True, 0) + search_box.pack_start(self.searchentry) search_box.show_all() - self.searchbutton = Gtk.Button(label=_('Search')) + self.searchbutton = gtk.Button(label=_('Search')) self.searchbutton.connect('clicked', self._search_clicked_cb) - search_box.pack_start(self.searchbutton, False, False, 0) + search_box.pack_start(self.searchbutton, False) wiki_widget = Reading_View() - wiki = Gtk.Notebook() + wiki = gtk.Notebook() wiki.props.show_border = False wiki.props.show_tabs = False - wiki.append_page(wiki_stub, None) - wiki.append_page(wiki_widget, None) + wiki.append_page(wiki_stub) + wiki.append_page(wiki_widget) - self.progress = Gtk.Label() + 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(, True, True, 0), False) + #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, False, 0) - wiki_box.pack_start(wiki, True, True, 0) - wiki_box.pack_start(self.progress, False, False, 0) - logging.debug(int(Gdk.Screen.width() * 3 / 4.)) - wiki_box.set_size_request(int(Gdk.Screen.width() * 3 / 4.), - int((Gdk.Screen.height() - \ - style.GRID_CELL_SIZE) / 2)) + 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 - style.GRID_CELL_SIZE / 2) custom_widget = Reading_View() - custom = Gtk.Notebook() + custom = gtk.Notebook() custom.props.show_border = False custom.props.show_tabs = False - custom.append_page(custom_stub, None) - custom.append_page(custom_widget, None) - # custom.set_size_request(Gdk.Screen.width()/4*3, - # Gdk.Screen.height()/2 - 55) - custom.set_size_request(int(Gdk.Screen.width() * 3 / 4.), - int((Gdk.Screen.height() - \ - style.GRID_CELL_SIZE) / 2)) + custom.append_page(custom_stub) + custom.append_page(custom_widget) + custom.set_size_request(gtk.gdk.screen_width()/4*3, + gtk.gdk.screen_height()/2 - style.GRID_CELL_SIZE / 2) # workspace - articles_box = Gtk.HBox() - articles_box.pack_start(self.wiki, True, True, 0) - articles_box.pack_start(Gtk.VSeparator(), False, False, 0) - articles_box.pack_start(wiki_box, False, False, 0) + articles_box = gtk.HBox() + articles_box.pack_start(self.wiki) + articles_box.pack_start(gtk.VSeparator(), False) + articles_box.pack_start(wiki_box, False) - custom_box = Gtk.HBox() - custom_box.pack_start(self.custom, True, True, 0) - custom_box.pack_start(Gtk.VSeparator(), False, False, 0) - custom_box.pack_start(custom, False, False, 0) + 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, False, 0) - workspace.pack_start(custom_box, False, False, 0) + workspace = gtk.VBox() + workspace.pack_start(articles_box, False) + workspace.pack_start(custom_box, False) workspace.show_all() self.add(workspace) @@ -204,10 +198,9 @@ class View(Gtk.EventBox): return if book.wiki.find('%s (from %s)' % (title, wiki))[0]: - alert = Alert() - alert.props.title = _('Exists') - alert.props.msg = _('"%s" article already exists' % title) - alert.show() + self.activity.notify_alert( + _('Exists'), + _('"%s" article already exists') % title) else: Timer(0, self._download, [title, wiki]).start() @@ -239,9 +232,9 @@ class ToolbarBuilder(): def _publish_clicked_cb(self, widget): xol.publish(self.activity) -WIKI = { _('English Wikipedia') : 'en.wikipedia.org', - _('Simple English Wikipedia') : 'simple.wikipedia.org', - _('French Wikipedia') : 'fr.wikipedia.org', - _('German Wikipedia') : 'de.wikipedia.org', +WIKI = { _("English Wikipedia") : "en.wikipedia.org", + _("Simple English Wikipedia") : "simple.wikipedia.org", + _("German Wikipedia") : "de.wikipedia.org", + _("Spanish Wikipedia") : "es.wikipedia.org", _('Polish Wikipedia') : 'pl.wikipedia.org', - _('Spanish Wikipedia') : 'es.wikipedia.org'} + _("French Wikipedia") : "fr.wikipedia.org" } @@ -18,7 +18,7 @@ import urllib import logging from gettext import gettext as _ -from sugar3.activity.activity import get_bundle_path +from sugar.activity.activity import get_bundle_path import book from infoslicer.processing.NewtifulSoup import NewtifulStoneSoup \ @@ -12,29 +12,29 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from gi.repository import Gtk -from gi.repository import GObject +import gtk +import gobject -from sugar3.graphics.icon import Icon -import sugar3.graphics.style as style +from sugar.graphics.icon import Icon +import sugar.graphics.style as style -class WidgetItem(Gtk.ToolItem): +class WidgetItem(gtk.ToolItem): def __init__(self, widget): - GObject.GObject.__init__(self) + gtk.ToolItem.__init__(self) self.add(widget) widget.show() -class ButtonItem(Gtk.ToolButton): - def __init__(self, icon_name, size=Gtk.IconSize.SMALL_TOOLBAR, **kwargs): - GObject.GObject.__init__(self, **kwargs) +class ButtonItem(gtk.ToolButton): + def __init__(self, icon_name, size=gtk.ICON_SIZE_SMALL_TOOLBAR, **kwargs): + gobject.GObject.__init__(self, **kwargs) icon = Icon(icon_name=icon_name, icon_size=size) - # The alignment is a hack to work around Gtk.ToolButton code - # that sets the icon_size when the icon_widget is a Gtk.Image - alignment = Gtk.Alignment.new(0.5, 0.5) + # The alignment is a hack to work around gtk.ToolButton code + # that sets the icon_size when the icon_widget is a gtk.Image + alignment = gtk.Alignment(0.5, 0.5) alignment.add(icon) self.set_icon_widget(alignment) - if size == Gtk.IconSize.SMALL_TOOLBAR: + if size == gtk.ICON_SIZE_SMALL_TOOLBAR: button_size = style.SMALL_ICON_SIZE + 8 self.set_size_request(button_size, button_size) @@ -15,7 +15,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os -from gi.repository import Gtk +import gtk import zipfile import uuid import logging @@ -23,10 +23,9 @@ import parse from glob import glob from gettext import gettext as _ -from sugar3.activity.activity import get_bundle_path, get_activity_root, get_bundle_name -from sugar3.datastore import datastore -from sugar3 import activity -from sugar3.graphics.alert import NotifyAlert, ConfirmationAlert +from sugar.activity.activity import get_bundle_path, get_activity_root, get_bundle_name +from sugar.datastore import datastore +from sugar import activity from infoslicer.processing.NewtifulSoup import NewtifulStoneSoup \ as BeautifulStoneSoup @@ -34,25 +33,11 @@ import book logger = logging.getLogger('infoslicer') - -def __alert_notify_response_cb(alert, response_id, activity): - activity.remove_alert(alert) - - -def __alert_response_cb(alert, response_id, activity, force): - activity.remove_alert(alert) - publish(activity, force) - - def publish(activity, force=False): if not [i for i in book.custom.index if i['ready']]: - alert = NotifyAlert(5) - alert.props.title = _('Nothing to publish') - alert.props.msg = _('Mark arcticles from "Custom" ' - 'panel and try again.') - alert.connect('response', __alert_notify_response_cb, activity) - activity.add_alert(alert) - alert.show() + activity.notify_alert( + _('Nothing to publish'), + _('Mark arcticles from "Custom" panel and try again.')) return title = activity.metadata['title'] @@ -67,13 +52,24 @@ def publish(activity, force=False): if force: jobject = jobject[0] else: - alert = ConfirmationAlert() - alert.props.title = _('Overwrite existed bundle?') - alert.props.msg = _('A bundle for current object was already created. ' - 'Click "OK" to overwrite it.') - alert.connect('response', __alert_response_cb, activity, True) - activity.add_alert(alert) - alert.show() + try: + # check for 0.84 code + from jarabe import config + except: + # 0.82 couldn't override .xol bundles + activity.notify_alert( + _('Bundle exists'), + _('A bundle by "%s" name already exists. Please ' \ + 'click "Erase" in the Journal. You can click ' \ + '"Publish" again afterwards.') % \ + jobject[0].metadata['title']) + return + + activity.confirmation_alert( + _('Overwrite existed bundle?'), + _('A bundle for current object was already created. ' \ + 'Click "OK" to overwrite it.'), + publish, activity, True) jobject[0].destroy() return else: @@ -95,14 +91,6 @@ def publish(activity, force=False): book.custom.sync_index() - alert = NotifyAlert() - alert.props.title = _('Book published to your Journal') - alert.props.msg = _('You can read the book in Browse or ' - 'access the .xol file from your Journal') - alert.connect('response', __alert_notify_response_cb, activity) - activity.add_alert(alert) - alert.show() - """ @author: Matthew Bailey |