Ticket #3742: backup-almost-working.diff
File backup-almost-working.diff, 65.8 KB (added by humitos, 12 years ago) |
---|
-
activity.py
diff --git a/activity.py b/activity.py index 46cf2ad..fa94eab 100644
a b 12 12 # along with this program; if not, write to the Free Software 13 13 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 14 15 import gtk 15 from gi.repository import Gtk 16 from gi.repository import GObject 16 17 from gettext import gettext as _ 17 18 18 from sugar.graphics.toolbutton import ToolButton 19 from sugar.graphics.toggletoolbutton import ToggleToolButton 20 from sugar.activity.activity import ActivityToolbox 21 from sugar.activity import activity 19 GObject.threads_init() 22 20 23 OLD_TOOLBAR = False 24 try: 25 from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton 26 from sugar.activity.widgets import StopButton 27 from sugar.graphics.radiotoolbutton import RadioToolButton 28 from sugar.activity.widgets import ActivityToolbarButton 29 except ImportError: 30 OLD_TOOLBAR = True 21 from sugar3.graphics.toolbutton import ToolButton 22 from sugar3.graphics.toggletoolbutton import ToggleToolButton 23 from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton 24 from sugar3.activity.widgets import StopButton 25 from sugar3.activity import activity 26 from sugar3.graphics.radiotoolbutton import RadioToolButton 27 from sugar3.activity.widgets import ActivityToolbarButton 31 28 32 29 import library 33 30 import edit 34 31 import book 35 32 36 gtk.gdk.threads_init()37 gtk.gdk.threads_enter()38 39 40 33 class InfoslicerActivity(activity.Activity): 41 34 def __init__(self, handle): 42 self.notebook = gtk.Notebook()35 self.notebook = Gtk.Notebook() 43 36 self.notebook.show() 44 37 self.notebook.props.show_border = False 45 38 self.notebook.props.show_tabs = False … … class InfoslicerActivity(activity.Activity): 60 53 self.edit = edit.View() 61 54 self.library = library.View(self) 62 55 63 if OLD_TOOLBAR: 64 self.edit_toolbar = gtk.Toolbar() 65 self.edit_bar = edit.ToolbarBuilder(self.edit, self.edit_toolbar) 66 self.edit_toolbar.show_all() 67 68 self.library_toolbar = gtk.Toolbar() 69 self.library_bar = library.ToolbarBuilder(self.library, 70 self.library_toolbar) 71 self.library_toolbar.show_all() 72 73 toolbox = ActivityToolbox(self) 74 toolbox.connect('current-toolbar-changed', 75 self._toolbar_changed_cb) 76 self.set_toolbox(toolbox) 77 toolbox.add_toolbar(_('Library'), self.library_toolbar) 78 toolbox.add_toolbar(_('Edit'), self.edit_toolbar) 79 toolbox.set_current_toolbar(1) 80 else: 81 toolbar_box = ToolbarBox() 82 activity_button = ActivityToolbarButton(self) 83 toolbar_box.toolbar.insert(activity_button, 0) 84 self.set_toolbar_box(toolbar_box) 85 self._toolbar = toolbar_box.toolbar 86 87 tool_group = None 88 search_button = RadioToolButton() 89 search_button.props.group = tool_group 90 tool_group = search_button 91 search_button.props.icon_name = 'white-search' 92 search_button.set_tooltip(_('Library')) 93 search_button.mode = 'search' 94 search_button.connect('clicked', self.__mode_button_clicked) 95 self._toolbar.insert(search_button, -1) 96 97 edit_button = RadioToolButton() 98 edit_button.props.group = tool_group 99 edit_button.props.icon_name = 'toolbar-edit' 100 edit_button.set_tooltip(_('Edit')) 101 edit_button.mode = 'edit' 102 edit_button.connect('clicked', self.__mode_button_clicked) 103 self._toolbar.insert(edit_button, -1) 104 self._toolbar.insert(gtk.SeparatorToolItem(), -1) 105 self.edit_bar = edit.ToolbarBuilder(self.edit, self._toolbar) 106 self.library_bar = library.ToolbarBuilder(self.library, 107 activity_button) 108 self.library_bar.publish.show() 109 110 edit_fake = gtk.EventBox() 111 112 self.notebook.append_page(self.library) 113 self.notebook.append_page(self.edit) 114 self.notebook.append_page(edit_fake) 56 toolbar_box = ToolbarBox() 57 activity_button = ActivityToolbarButton(self) 58 toolbar_box.toolbar.insert(activity_button, 0) 59 self.set_toolbar_box(toolbar_box) 60 self._toolbar = toolbar_box.toolbar 61 62 tool_group = None 63 search_button = RadioToolButton() 64 search_button.props.group = tool_group 65 tool_group = search_button 66 search_button.props.icon_name = 'white-search' 67 search_button.set_tooltip(_('Library')) 68 search_button.mode = 'search' 69 search_button.connect('clicked', self.__mode_button_clicked) 70 self._toolbar.insert(search_button, -1) 71 72 edit_button = RadioToolButton() 73 edit_button.props.group = tool_group 74 edit_button.props.icon_name = 'toolbar-edit' 75 edit_button.set_tooltip(_('Edit')) 76 edit_button.mode = 'edit' 77 edit_button.connect('clicked', self.__mode_button_clicked) 78 self._toolbar.insert(edit_button, -1) 79 self._toolbar.insert(Gtk.SeparatorToolItem(), -1) 80 self.edit_bar = edit.ToolbarBuilder(self.edit, self._toolbar) 81 self.library_bar = library.ToolbarBuilder(self.library, 82 activity_button) 83 self.library_bar.publish.show() 84 85 edit_fake = Gtk.EventBox() 86 87 self.notebook.append_page(self.library, None) 88 self.notebook.append_page(self.edit, None) 89 self.notebook.append_page(edit_fake, None) 115 90 116 91 self.show_all() 117 92 118 if not OLD_TOOLBAR: 119 self.__mode_button_clicked(search_button) 120 separator = gtk.SeparatorToolItem() 121 separator.props.draw = False 122 separator.set_expand(True) 123 separator.show() 124 self._toolbar.insert(separator, -1) 125 stop_button = StopButton(self) 126 stop_button.show() 127 self._toolbar.insert(stop_button, -1) 93 self.__mode_button_clicked(search_button) 94 separator = Gtk.SeparatorToolItem() 95 separator.props.draw = False 96 separator.set_expand(True) 97 separator.show() 98 self._toolbar.insert(separator, -1) 99 stop_button = StopButton(self) 100 stop_button.show() 101 self._toolbar.insert(stop_button, -1) 128 102 129 103 def new_instance(self): 130 104 self.instance() … … class InfoslicerActivity(activity.Activity): 138 112 book.custom.sync(filepath) 139 113 140 114 def set_edit_sensitive(self, enable): 141 if OLD_TOOLBAR: 142 #self.edit_toolbar.props.sensitive = enable 143 self.edit_page = (enable and 1 or 2) 115 pass 144 116 145 117 def _toolbar_changed_cb(self, widget, index): 146 118 if index > 0: -
book.py
diff --git a/book.py b/book.py index f28ff99..ea40951 100644
a b 13 13 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 14 15 15 import os 16 import gtk17 16 import uuid 18 17 import logging 19 import gobject18 from gi.repository import GObject 20 19 import cjson 21 20 import shutil 22 21 import zipfile 23 from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT24 22 from gettext import gettext as _ 25 23 26 from sugar .activity.activity import get_bundle_path, get_activity_root24 from sugar3.activity.activity import get_bundle_path, get_activity_root 27 25 28 26 import net 29 27 from infoslicer.processing.Article import Article … … custom = None 36 34 37 35 image_root = os.path.join(get_activity_root(), 'data', 'book') 38 36 39 class Book( gobject.GObject):37 class Book(GObject.GObject): 40 38 __gsignals__ = { 41 'article-selected' : ( SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),42 'article-added' : ( SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),43 'article-deleted' : ( SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]) }39 'article-selected' : (GObject.SignalFlags.RUN_FIRST, None, [object]), 40 'article-added' : (GObject.SignalFlags.RUN_FIRST, None, [object]), 41 'article-deleted' : (GObject.SignalFlags.RUN_FIRST, None, [object]) } 44 42 45 43 def get_article(self): 46 44 return self._article … … class Book(gobject.GObject): 71 69 72 70 self._article.uid = entry['uid'] 73 71 self._article.article_title = title 74 gobject.idle_add(self._emit_article_selected)72 GObject.idle_add(self._emit_article_selected) 75 73 76 article = gobject.property(type=object,74 article = GObject.property(type=object, 77 75 getter=get_article, setter=set_article) 78 76 79 77 def _emit_article_selected(self): … … class Book(gobject.GObject): 132 130 self.sync_index() 133 131 134 132 def __init__(self, preinstalled, root): 135 gobject.GObject.__init__(self)133 GObject.GObject.__init__(self) 136 134 self.root = root 137 135 self.index = [] 138 136 self.uid = None -
bookview.py
diff --git a/bookview.py b/bookview.py index e38662b..e84b6dc 100644
a b 13 13 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 14 15 15 import os 16 import gtk16 from gi.repository import Gtk 17 17 import logging 18 import gobject18 from gi.repository import GObject 19 19 from gettext import gettext as _ 20 20 21 from sugar .graphics.toolbutton import ToolButton22 from sugar .activity.activity import get_bundle_path, get_activity_root23 from sugar .graphics.style import *21 from sugar3.graphics.toolbutton import ToolButton 22 from sugar3.activity.activity import get_bundle_path, get_activity_root 23 from sugar3.graphics.style import * 24 24 25 25 logger = logging.getLogger('infoslicer') 26 26 27 27 PUBLISH = 0 28 28 TITLE = 1 29 29 30 class BookView( gtk.VBox):30 class BookView(Gtk.VBox): 31 31 def sync(self): 32 32 if not self._changing: 33 33 return 34 gobject.source_remove(self._changing)34 GObject.source_remove(self._changing) 35 35 index, column = self.tree.get_cursor() 36 36 self._cursor_changed(index) 37 37 38 38 def __init__(self, book, name, tooltip, custom): 39 gtk.VBox.__init__(self)39 GObject.GObject.__init__(self) 40 40 self.book = book 41 41 self._changing = None 42 42 self._check = None 43 43 44 title = gtk.Toolbar()44 title = Gtk.Toolbar() 45 45 46 46 # title checkbox 47 47 48 48 if custom: 49 self._check = gtk.CheckButton()49 self._check = Gtk.CheckButton() 50 50 self._check.props.can_focus = False 51 51 self._check.props.tooltip_text = \ 52 52 _('Articles are ready to be published') 53 53 self._check.connect('toggled', self._check_toggled_cb) 54 check_box = gtk.HBox()54 check_box = Gtk.HBox() 55 55 check_box.set_size_request(50, -1) 56 check_box.pack_start(self._check, True, False )57 tool_item = gtk.ToolItem()56 check_box.pack_start(self._check, True, False, 0) 57 tool_item = Gtk.ToolItem() 58 58 tool_item.add(check_box) 59 59 tool_item.show() 60 60 title.insert(tool_item, -1) 61 61 else: 62 tool_item = gtk.ToolItem()63 tool_item.add( gtk.Label(' '))62 tool_item = Gtk.ToolItem() 63 tool_item.add(Gtk.Label(label=' ')) 64 64 tool_item.show() 65 65 title.insert(tool_item, -1) 66 66 67 67 # title caption 68 68 69 caption_label = gtk.Label(name)69 caption_label = Gtk.Label(label=name) 70 70 caption_label.props.tooltip_text = tooltip 71 caption_label.modify_fg( gtk.STATE_NORMAL, COLOR_WHITE.get_gdk_color())72 caption_box = gtk.HBox()73 caption_box.pack_start(caption_label, False )74 caption = gtk.EventBox()71 caption_label.modify_fg(Gtk.StateType.NORMAL, COLOR_WHITE.get_gdk_color()) 72 caption_box = Gtk.HBox() 73 caption_box.pack_start(caption_label, False, False, 0) 74 caption = Gtk.EventBox() 75 75 caption.add(caption_box) 76 caption.modify_bg( gtk.STATE_NORMAL, COLOR_TOOLBAR_GREY.get_gdk_color())76 caption.modify_bg(Gtk.StateType.NORMAL, COLOR_TOOLBAR_GREY.get_gdk_color()) 77 77 78 tool_item = gtk.ToolItem()78 tool_item = Gtk.ToolItem() 79 79 tool_item.add(caption) 80 80 tool_item.show() 81 82 81 title.insert(tool_item, -1) 83 82 84 separator = gtk.SeparatorToolItem()83 separator = Gtk.SeparatorToolItem() 85 84 separator.props.draw = False 86 85 separator.set_expand(True) 87 86 title.insert(separator, -1) … … class BookView(gtk.VBox): 118 117 119 118 # tree 120 119 121 self.store = gtk.ListStore(bool, str)122 self.tree = gtk.TreeView(self.store)120 self.store = Gtk.ListStore(bool, str) 121 self.tree = Gtk.TreeView(self.store) 123 122 self.tree.props.headers_visible = False 124 123 self.tree.connect('cursor-changed', self._cursor_changed_cb) 125 124 126 cell = gtk.CellRendererToggle()125 cell = Gtk.CellRendererToggle() 127 126 cell.connect('toggled', self._cell_toggled_cb) 128 127 cell.props.activatable = True 129 128 130 column = self.tree.insert_column_with_attributes(0, '', cell, active=0) 131 column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED 129 # FIXME: insert_column_with_attributes does not exist on pygobject 130 # column = self.tree.insert_column_with_attributes(0, '', cell, active=0) 131 132 # TODO: this is a workaround due 133 # https://bugzilla.gnome.org/show_bug.cgi?id=679415 134 135 column = Gtk.TreeViewColumn('Wiki', cell) 136 column.props.sizing = Gtk.TreeViewColumnSizing.FIXED 132 137 column.props.fixed_width = 50 133 138 column.props.visible = custom 134 139 135 cell = gtk.CellRendererText() 140 self.tree.insert_column(column, 0) 141 142 cell = Gtk.CellRendererText() 136 143 cell.connect('edited', self._cell_edited_cb) 137 144 cell.props.editable = True 138 self.tree.insert_column_with_attributes(1, '', cell, text=1) 145 146 # FIXME: insert_column_with_attributes does not exist on pygobject 147 # self.tree.insert_column_with_attributes(1, '', cell, text=1) 148 149 # TODO: this is a workaround due 150 # https://bugzilla.gnome.org/show_bug.cgi?id=679415 151 column = Gtk.TreeViewColumn('Custom', cell, text=1) 152 self.tree.insert_column(column, 1) 139 153 140 154 for i in self.book.index: 141 155 self.store.append((i['ready'], i['title'])) 142 156 143 157 # scrolled tree 144 158 145 tree_scroll = gtk.ScrolledWindow()146 tree_scroll.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)159 tree_scroll = Gtk.ScrolledWindow() 160 tree_scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 147 161 tree_scroll.add(self.tree) 148 162 149 self.pack_start(title, False )150 self.pack_start(tree_scroll )163 self.pack_start(title, False, False, 0) 164 self.pack_start(tree_scroll, True, True, 0) 151 165 152 166 if len(self.store): 153 167 self.tree.set_cursor(0, self.tree.get_column(1), False) … … class BookView(gtk.VBox): 170 184 return find_name(list, prefix, uniq+1) 171 185 172 186 if self._changing: 173 gobject.source_remove(self._changing)187 GObject.source_remove(self._changing) 174 188 self._changing = None 175 189 176 190 name = find_name(self.store, _('New article'), 0) … … class BookView(gtk.VBox): 183 197 index, column = self.tree.get_cursor() 184 198 if not index: 185 199 return 186 index = index[0]187 200 188 if self._changing: 189 gobject.source_remove(self._changing) 190 self._changing = None 201 # TODO: This is not working because of the port to Gtk3 202 # 'TreePath' object does not support indexing 191 203 192 self.book.remove(self.store[index][TITLE]) 193 self.store.remove(self.tree.props.model.get_iter(index)) 204 # index = index[0] 194 205 195 if len(self.store): 196 if index >= len(self.store): 197 index -= 1 198 self.tree.set_cursor(index, self.tree.get_column(1), False) 199 self._update_check(self.store[index][PUBLISH]) 206 # if self._changing: 207 # GObject.source_remove(self._changing) 208 # self._changing = None 209 210 # self.book.remove(self.store[index][TITLE]) 211 # self.store.remove(self.tree.props.model.get_iter(index)) 212 213 # if len(self.store): 214 # if index >= len(self.store): 215 # index -= 1 216 # self.tree.set_cursor(index, self.tree.get_column(1), False) 217 # self._update_check(self.store[index][PUBLISH]) 200 218 201 219 def _swap_cb(self, widget, delta): 202 220 old_index, column = self.tree.get_cursor() 203 221 if not old_index: 204 222 return 205 223 206 old_index = old_index[0] 207 new_index = old_index + delta 224 # TODO: this is not working properly after Gtk3 port and 225 # should be fixed 226 227 # old_index = old_index[0] 228 # new_index = old_index + delta 208 229 209 if new_index < 0:210 new_index = len(self.store)-1211 elif new_index >= len(self.store):212 new_index = 0230 # if new_index < 0: 231 # new_index = len(self.store)-1 232 # elif new_index >= len(self.store): 233 # new_index = 0 213 234 214 self.book.index[old_index], self.book.index[new_index] = \215 self.book.index[new_index], self.book.index[old_index]216 self.store.swap(self.tree.props.model.get_iter(old_index),217 self.tree.props.model.get_iter(new_index))235 # self.book.index[old_index], self.book.index[new_index] = \ 236 # self.book.index[new_index], self.book.index[old_index] 237 # self.store.swap(self.tree.props.model.get_iter(old_index), 238 # self.tree.props.model.get_iter(new_index)) 218 239 219 240 def _check_toggled_cb(self, widget): 220 241 for i, entry in enumerate(self.store): … … class BookView(gtk.VBox): 241 262 242 263 def _cursor_changed_cb(self, widget): 243 264 if self._changing: 244 gobject.source_remove(self._changing)265 GObject.source_remove(self._changing) 245 266 246 267 index, column = self.tree.get_cursor() 247 268 248 269 if index != None: 249 self._changing = gobject.timeout_add(500, self._cursor_changed,270 self._changing = GObject.timeout_add(500, self._cursor_changed, 250 271 index) 251 272 252 273 def _cursor_changed(self, index): -
edit.py
diff --git a/edit.py b/edit.py index d21a989..e48509e 100644
a b 12 12 # along with this program; if not, write to the Free Software 13 13 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 14 15 import gtk 15 from gi.repository import Gtk 16 from gi.repository import GObject 16 17 from gettext import gettext as _ 17 18 18 from sugar.graphics.toolbutton import ToolButton 19 from sugar.graphics.toggletoolbutton import ToggleToolButton 20 from sugar.activity.activity import ActivityToolbox 19 from sugar3.graphics.toolbutton import ToolButton 20 from sugar3.graphics.toggletoolbutton import ToggleToolButton 21 21 22 22 from infoslicer.widgets.Edit_Pane import Edit_Pane 23 23 from infoslicer.widgets.Format_Pane import Format_Pane … … TABS = (Edit_Pane(), 28 28 Image_Pane(), 29 29 Format_Pane()) 30 30 31 class View( gtk.Notebook):31 class View(Gtk.Notebook): 32 32 def __init__(self): 33 gtk.Notebook.__init__(self)33 GObject.GObject.__init__(self) 34 34 self.props.show_border = False 35 35 self.props.show_tabs = False 36 36 37 37 for i in TABS: 38 self.append_page(i )38 self.append_page(i, None) 39 39 i.show() 40 40 41 41 self.connect('map', self._map_cb) -
infoslicer/processing/Article.py
diff --git a/infoslicer/processing/Article.py b/infoslicer/processing/Article.py index 157b3c8..b3311b0 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 2 3 import pygtk4 pygtk.require('2.0') 5 import gtk 3 from gi.repository import Gtk 4 from gi.repository import GdkPixbuf 5 6 6 from random import Random 7 7 from Article_Data import * 8 8 from Section import * … … class Article: 35 35 """ 36 36 Created by Jonathan Mace 37 37 38 The Article class maintains a concrete representation of the article, in the form of a gtk.TextBuffer38 The Article class maintains a concrete representation of the article, in the form of a Gtk.TextBuffer 39 39 40 Positions within the text are represented by gtk.TextIter40 Positions within the text are represented by Gtk.TextIter 41 41 42 42 The class contains methods for inserting and deleting new sentences, paragraphs and sections. 43 43 … … class Article: 56 56 """ 57 57 Create default text buffer and set to empty 58 58 """ 59 self.__buf = gtk.TextBuffer()59 self.__buf = Gtk.TextBuffer() 60 60 self.__buf.set_text("") 61 61 insertionpoint = self.__buf.get_end_iter() 62 62 insertionmark = self.__buf.create_mark(None, insertionpoint, False) … … class Article: 149 149 nextsection = self.__sections[i+1] 150 150 151 151 if section.getStart().compare(nextsection.getStart()) == -1: 152 text = self.__buf.get_slice(section.getStart(), nextsection.getStart() )152 text = self.__buf.get_slice(section.getStart(), nextsection.getStart(), True) 153 153 if len(text) > 2 and text[-2] != "\n": 154 154 nextsection.paragraphs = section.paragraphs + nextsection.paragraphs 155 155 else: … … class Article: 468 468 469 469 def getBuffer(self): 470 470 """ 471 This method simply returns the gtk.TextBuffer being maintained by this instance of the Article class.471 This method simply returns the Gtk.TextBuffer being maintained by this instance of the Article class. 472 472 """ 473 473 return self.__buf 474 474 … … class Article: 638 638 self.markmark = self.__buf.create_mark(None, lociter, True) 639 639 self.__buf.insert(lociter, " ") 640 640 lociter = self.__buf.get_iter_at_mark(self.markmark) 641 arrow = gtk.gdk.pixbuf_new_from_xpm_data(arrow_xpm) 642 self.__buf.insert_pixbuf(lociter, arrow) 641 # FIXME: I don't know what the arrow_xpm type should be 642 # https://bugzilla.gnome.org/show_bug.cgi?id=651962 643 # arrow = GdkPixbuf.Pixbuf.new_from_xpm_data(arrow_xpm) 644 # self.__buf.insert_pixbuf(lociter, arrow) 643 645 644 646 645 647 def clearArrow(self): -
infoslicer/processing/Paragraph.py
diff --git a/infoslicer/processing/Paragraph.py b/infoslicer/processing/Paragraph.py index 7c743c7..563fd16 100644
a b class RawParagraph: 152 152 def mark(self): 153 153 markiter = self.getStart() 154 154 self.markmark = self.buf.create_mark(None, markiter, True) 155 arrow = gtk.gdk.pixbuf_new_from_xpm_data(arrow_xpm)155 arrow = GdkPixbuf.Pixbuf.new_from_xpm_data(arrow_xpm) 156 156 self.buf.insert_pixbuf(markiter, arrow) 157 157 158 158 def unmark(self): … … class RawParagraph: 165 165 return self.sentences 166 166 167 167 def getText(self): 168 return self.buf.get_slice(self.getStart(), self.getEnd() )168 return self.buf.get_slice(self.getStart(), self.getEnd(), True) 169 169 170 170 def clean(self): 171 171 if len(self.sentences) > 1: -
infoslicer/processing/Section.py
diff --git a/infoslicer/processing/Section.py b/infoslicer/processing/Section.py index 30e3dad..bc5f847 100644
a b class RawSection: 214 214 def mark(self): 215 215 markiter = self.getStart() 216 216 self.markmark = self.buf.create_mark(None, markiter, True) 217 arrow = gtk.gdk.pixbuf_new_from_xpm_data(arrow_xpm)217 arrow = GdkPixbuf.Pixbuf.new_from_xpm_data(arrow_xpm) 218 218 self.buf.insert_pixbuf(markiter, arrow) 219 219 220 220 def unmark(self): … … class RawSection: 260 260 nextparagraph = self.paragraphs[i+1] 261 261 262 262 if paragraph.getStart().compare(nextparagraph.getStart()) == -1: 263 text = self.buf.get_slice(paragraph.getStart(), nextparagraph.getStart() )263 text = self.buf.get_slice(paragraph.getStart(), nextparagraph.getStart(), True) 264 264 if len(text) > 0 and text[-1] != "\n": 265 265 logger.debug("concatenating paragraphs") 266 266 nextparagraph.sentences = paragraph.sentences + nextparagraph.sentences -
infoslicer/processing/Sentence.py
diff --git a/infoslicer/processing/Sentence.py b/infoslicer/processing/Sentence.py index 09c31f4..1903a9c 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 2 3 import pygtk4 pygtk.require('2.0')3 import gi 4 gi.require_version('Gtk', '3.0') 5 5 import os 6 import gtk6 from gi.repository import Gtk 7 7 import logging 8 8 9 9 from Article_Data import * … … class RawSentence: 83 83 return data 84 84 85 85 def getText(self): 86 return self.buf.get_slice(self.getStart(), self.getEnd() )86 return self.buf.get_slice(self.getStart(), self.getEnd(), True) 87 87 88 88 def checkIntegrity(self, nextiter): 89 text = unicode(self.buf.get_slice(self.getStart(), nextiter ))89 text = unicode(self.buf.get_slice(self.getStart(), nextiter, True)) 90 90 lines = text.splitlines(True) 91 91 sentencestartoffset = self.getStart().get_offset() 92 92 sentences = [] … … class Picture( RawSentence ): 159 159 leftmark = buf.create_mark(None, insertioniter, False) 160 160 161 161 if os.path.isfile(picture_data.text): 162 pixbuf = gtk.gdk.pixbuf_new_from_file(picture_data.text)162 pixbuf = GdkPixbuf.Pixbuf.new_from_file(picture_data.text) 163 163 buf.insert_pixbuf(insertioniter, pixbuf) 164 164 else: 165 165 logger.warning('cannot open image %s' % picture_data.text) -
infoslicer/widgets/Edit_Pane.py
diff --git a/infoslicer/widgets/Edit_Pane.py b/infoslicer/widgets/Edit_Pane.py index 8da2ad9..d7ab056 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 2 import gi 3 gi.require_version('Gtk', '3.0') 4 from gi.repository import Gtk 5 from gi.repository import Gdk 6 from gi.repository import GObject 5 7 import logging 6 8 from gettext import gettext as _ 7 9 8 from sugar .graphics.toolcombobox import ToolComboBox10 from sugar3.graphics.toolcombobox import ToolComboBox 9 11 10 12 from Reading_View import Reading_View 11 13 from Editing_View import Editing_View … … from infoslicer.processing.Article import Article 13 15 14 16 logger = logging.getLogger('infoslicer') 15 17 16 class Edit_Pane( gtk.HBox):18 class Edit_Pane(Gtk.HBox): 17 19 """ 18 20 Created by Jonathan Mace 19 21 … … class Edit_Pane(gtk.HBox): 30 32 """ 31 33 32 34 def __init__(self): 33 gtk.HBox.__init__(self)35 GObject.GObject.__init__(self) 34 36 self.toolitems = [] 35 37 36 readarticle_box = gtk.VBox()38 readarticle_box = Gtk.VBox() 37 39 readarticle_box.show() 38 40 39 labeleb = gtk.EventBox()40 labeleb.modify_bg( gtk.STATE_NORMAL, gtk.gdk.color_parse("#EEEEEE"))41 labeleb = Gtk.EventBox() 42 labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE")) 41 43 readarticle_box.pack_start(labeleb, False, False, 0) 42 44 labeleb.show() 43 45 44 self.articletitle = gtk.Label()45 self.articletitle.set_justify( gtk.JUSTIFY_CENTER)46 self.articletitle = Gtk.Label() 47 self.articletitle.set_justify(Gtk.Justification.CENTER) 46 48 labeleb.add(self.articletitle) 47 49 self.articletitle.show() 48 50 49 vbox = gtk.VBox()51 vbox = Gtk.VBox() 50 52 51 53 snap = ToolComboBox(label_text=_('Snap selection to:')) 52 54 snap.combo.append_item(0, _("Nothing")) … … class Edit_Pane(gtk.HBox): 54 56 snap.combo.append_item(2, _("Paragraphs")) 55 57 snap.combo.append_item(3, _("Sections")) 56 58 snap.combo.set_active(1) 57 vbox.pack_start(snap, False )59 vbox.pack_start(snap, False, False, 0) 58 60 59 61 """ 60 62 Create reading and editing panels 61 63 """ 62 64 self.readarticle = Reading_View() 63 self.readarticle.set_size_request( gtk.gdk.screen_width()/2, -1)65 self.readarticle.set_size_request(Gdk.Screen.width()/2, -1) 64 66 self.readarticle.show() 65 readarticle_box.pack_start(self.readarticle )66 vbox.pack_start(readarticle_box )67 readarticle_box.pack_start(self.readarticle, True, True, 0) 68 vbox.pack_start(readarticle_box, True, True, 0) 67 69 68 self.pack_start(vbox, False )70 self.pack_start(vbox, False, False, 0) 69 71 70 72 self.editarticle = Editing_View() 71 self.pack_start(self.editarticle )73 self.pack_start(self.editarticle, True, True, 0) 72 74 self.editarticle.show() 73 75 74 76 snap.combo.connect("changed", self.selection_mode_changed, None) -
infoslicer/widgets/Editable_Textbox.py
diff --git a/infoslicer/widgets/Editable_Textbox.py b/infoslicer/widgets/Editable_Textbox.py index fd8711f..1673aa6 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 2 import gi 3 gi.require_version('Gtk', '3.0') 4 from gi.repository import Gtk 5 from gi.repository import Gdk 6 from gi.repository import GObject 7 from gi.repository import Pango 5 8 import cPickle 6 import pango7 9 import copy 8 10 from Textbox import Textbox 9 11 … … class Editable_Textbox( Textbox ): 18 20 """ 19 21 20 22 def __init__(self): 21 gtk.TextView.__init__(self)23 GObject.GObject.__init__(self) 22 24 self.set_border_width(1) 23 25 self.set_cursor_visible(True) 24 26 self.set_editable(True) 25 self.set_wrap_mode( gtk.WRAP_WORD)27 self.set_wrap_mode(Gtk.WrapMode.WORD) 26 28 self.article = None 27 29 self.set_mode(SNAP_SENTENCE) 28 30 self.changed = False … … class Editable_Textbox( Textbox ): 30 32 31 33 self.selecting = False 32 34 self.handlers = [] 33 self.modify_font( pango.FontDescription('arial 9'))35 self.modify_font(Pango.FontDescription('arial 9')) 34 36 self.ignore_snap_self = True 35 37 self.drag_source = False 36 38 self.edited = False … … class Editable_Textbox( Textbox ): 47 49 self.article.delete() 48 50 49 51 def get_mouse_iter(self, x, y): 50 click_coords = self.window_to_buffer_coords( gtk.TEXT_WINDOW_TEXT, x, y)52 click_coords = self.window_to_buffer_coords(Gtk.TextWindowType.TEXT, x, y) 51 53 mouseClickPositionIter = self.get_iter_at_location(click_coords[0], click_coords[1]) 52 54 return mouseClickPositionIter 53 55 … … class Editable_Textbox( Textbox ): 59 61 self.disconnect(handler) 60 62 61 63 buffer.connect("changed", self.text_changed, None) 62 gtk.TextView.set_buffer(self, buffer)64 Gtk.TextView.set_buffer(self, buffer) 63 65 64 66 self.handlers = [] 65 67 … … class Editable_Textbox( Textbox ): 143 145 self.block = True 144 146 145 147 def clicked_event(self, widget, event, data): 146 if event.type == gtk.gdk._2BUTTON_PRESS or event.type == gtk.gdk._3BUTTON_PRESS:148 if event.type == Gdk.EventType._2BUTTON_PRESS or event.type == Gdk.EventType._3BUTTON_PRESS: 147 149 self.stop_emission("button_press_event") 148 150 return 149 151 if event.button == 3: … … class Editable_Textbox( Textbox ): 259 261 if self.snapto != SNAP_NONE and not self.ignore_snap_self or (not self.drag_source and self.ignore_snap_self): 260 262 a = self.article 261 263 insert_loc = self.get_mouse_iter(x, y) 262 data_received_type = str(selection_data. type)263 data = cPickle.loads(str(selection_data. data))264 data_received_type = str(selection_data.get_data_type()) 265 data = cPickle.loads(str(selection_data.get_data())) 264 266 265 267 if data_received_type == "sentence": 266 268 bestpoint = insert_loc … … class Editable_Textbox( Textbox ): 280 282 a = self.article 281 283 282 284 if self.snapto == SNAP_SENTENCE: 283 atom = gtk.gdk.atom_intern("sentence")285 atom = Gdk.atom_intern("sentence") 284 286 if self.snapto == SNAP_PARAGRAPH: 285 atom = gtk.gdk.atom_intern("paragraph")287 atom = Gdk.atom_intern("paragraph") 286 288 if self.snapto == SNAP_SECTION: 287 atom = gtk.gdk.atom_intern("section")289 atom = Gdk.atom_intern("section") 288 290 289 291 string = cPickle.dumps(a.getSelection()) 290 292 selection_data.set(atom, 8, string) -
infoslicer/widgets/Editing_View.py
diff --git a/infoslicer/widgets/Editing_View.py b/infoslicer/widgets/Editing_View.py index 5506a7f..3f9ecdc 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 2 import gi 3 gi.require_version('Gtk', '3.0') 4 from gi.repository import Gtk 5 from gi.repository import Gdk 6 from gi.repository import GObject 5 7 from Editable_Textbox import Editable_Textbox 6 8 7 class Editing_View( gtk.VBox ):9 class Editing_View( Gtk.VBox ): 8 10 """ 9 11 Created by Jonathan Mace 10 12 This class wraps an editable textbox into a scrollable window and 11 13 gives it a title. 12 14 """ 13 15 def __init__(self): 14 gtk.VBox.__init__(self)16 GObject.GObject.__init__(self) 15 17 self.set_border_width(0) 16 18 self.set_spacing(2) 17 19 18 labeleb = gtk.EventBox()19 labeleb.modify_bg( gtk.STATE_NORMAL, gtk.gdk.color_parse("#EEEEEE"))20 labeleb = Gtk.EventBox() 21 labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE")) 20 22 self.pack_start(labeleb, False, False, 0) 21 23 labeleb.show() 22 24 23 self.articletitle = gtk.Label()24 self.articletitle.set_justify( gtk.JUSTIFY_CENTER)25 self.articletitle = Gtk.Label() 26 self.articletitle.set_justify(Gtk.Justification.CENTER) 25 27 labeleb.add(self.articletitle) 26 28 self.articletitle.show() 27 29 28 self.textwindow = gtk.ScrolledWindow()29 self.textwindow.set_policy( gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)30 self.pack_start(self.textwindow )30 self.textwindow = Gtk.ScrolledWindow() 31 self.textwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) 32 self.pack_start(self.textwindow, True, True, 0) 31 33 self.textwindow.show() 32 34 33 35 self.textbox = Editable_Textbox() -
infoslicer/widgets/Format_Pane.py
diff --git a/infoslicer/widgets/Format_Pane.py b/infoslicer/widgets/Format_Pane.py index ef8c2f5..1be64f2 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk3 pygtk.require('2.0')4 import gtk2 import gi 3 gi.require_version('Gtk', '3.0') 4 from gi.repository import Gtk 5 5 from gettext import gettext as _ 6 6 7 7 from Editing_View import Editing_View … … class Format_Pane(Editing_View): 22 22 self.toolitems = [] 23 23 24 24 """ 25 self.combocontainer = gtk.ToolItem()25 self.combocontainer = Gtk.ToolItem() 26 26 self.combocontainer.add(self.combobox) 27 27 self.toolbar.insert(self.combocontainer, -1) 28 28 self.combocontainer.show() 29 29 30 self.boldbutton = gtk.ToolButton(gtk.STOCK_BOLD)30 self.boldbutton = Gtk.ToolButton(Gtk.STOCK_BOLD) 31 31 self.boldbutton.set_expand(False) 32 32 self.toolbar.insert(self.boldbutton, -1) 33 33 self.boldbutton.show() 34 34 35 self.italicbutton = gtk.ToolButton(gtk.STOCK_ITALIC)35 self.italicbutton = Gtk.ToolButton(Gtk.STOCK_ITALIC) 36 36 self.italicbutton.set_expand(False) 37 37 self.toolbar.insert(self.italicbutton, -1) 38 38 self.italicbutton.show() 39 39 40 self.underlinebutton = gtk.ToolButton(gtk.STOCK_UNDERLINE)40 self.underlinebutton = Gtk.ToolButton(Gtk.STOCK_UNDERLINE) 41 41 self.underlinebutton.set_expand(False) 42 42 self.toolbar.insert(self.underlinebutton, -1) 43 43 self.underlinebutton.show() -
infoslicer/widgets/Gallery_View.py
diff --git a/infoslicer/widgets/Gallery_View.py b/infoslicer/widgets/Gallery_View.py index 4464088..88bf0de 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 2 from gi.repository import Gtk 3 from gi.repository import Gdk 4 from gi.repository import GObject 5 from gi.repository import GdkPixbuf 5 6 import os 6 7 import cPickle 7 8 import logging … … import book 13 14 14 15 logger = logging.getLogger('infoslicer') 15 16 16 class Gallery_View( gtk.HBox ):17 class Gallery_View( Gtk.HBox ): 17 18 """ 18 19 Created by Christopher Leonard 19 20 Drag-and-drop methods added by Jonathan Mace … … class Gallery_View( gtk.HBox ): 33 34 34 35 def __init__(self): 35 36 self.image_list = [] 36 gtk.HBox.__init__(self)37 GObject.GObject.__init__(self) 37 38 38 39 self.current_index = -1 39 40 40 left_button = gtk.Button(label="\n\n << \n\n")41 left_button = Gtk.Button(label="\n\n << \n\n") 41 42 42 right_button = gtk.Button(label="\n\n >> \n\n")43 right_button = Gtk.Button(label="\n\n >> \n\n") 43 44 44 self.imagenumberlabel = gtk.Label()45 self.imagenumberlabel = Gtk.Label() 45 46 46 self.image = gtk.Image()47 self.image = Gtk.Image() 47 48 48 self.imagebox = gtk.EventBox()49 self.imagebox = Gtk.EventBox() 49 50 self.imagebox.add(self.image) 50 51 51 self.imagebox.drag_source_set(gtk.gdk.BUTTON1_MASK, [("text/plain", gtk.TARGET_SAME_APP, 80)], gtk.gdk.ACTION_COPY) 52 # FIXME 53 # http://developer.gnome.org/gtk3/3.5/gtk3-Drag-and-Drop.html#gtk-drag-source-set 54 # self.imagebox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, ("text/plain", Gtk.TargetFlags.SAME_APP, 80), Gdk.DragAction.COPY) 55 self.imagebox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, None, Gdk.DragAction.COPY) 56 self.imagebox.drag_source_add_image_targets() 52 57 self.imagebox.connect("drag-begin", self.drag_begin_event, None) 53 58 self.imagebox.connect("drag-data-get", self.drag_data_get_event, None) 54 59 55 self.caption = gtk.Label("")60 self.caption = Gtk.Label(label="") 56 61 self.caption.set_line_wrap(True) 57 62 58 self.image_drag_container = gtk.VBox() 59 self.image_drag_container.pack_start(self.imagenumberlabel, expand = False) 60 self.image_drag_container.pack_start(self.imagebox, expand=False) 61 self.image_drag_container.pack_start(self.caption, expand=False) 62 63 image_container = gtk.VBox() 64 image_container.pack_start(gtk.Label(" ")) 65 image_container.pack_start(self.image_drag_container, expand=False) 66 image_container.pack_start(gtk.Label(" ")) 67 68 left_button_container = gtk.VBox() 69 left_button_container.pack_start(gtk.Label(" ")) 70 left_button_container.pack_start(left_button, expand=False) 71 left_button_container.pack_start(gtk.Label(" ")) 72 73 right_button_container = gtk.VBox() 74 right_button_container.pack_start(gtk.Label(" ")) 75 right_button_container.pack_start(right_button, expand=False) 76 right_button_container.pack_start(gtk.Label(" ")) 63 self.image_drag_container = Gtk.VBox() 64 self.image_drag_container.pack_start(self.imagenumberlabel, expand=False, 65 fill=False, padding=0) 66 self.image_drag_container.pack_start(self.imagebox, False, True, 0) 67 self.image_drag_container.pack_start(self.caption, False, True, 0) 68 69 image_container = Gtk.VBox() 70 image_container.pack_start(Gtk.Label(" "), True, True, 0) 71 image_container.pack_start(self.image_drag_container, False, True, 0) 72 image_container.pack_start(Gtk.Label(" "), True, True, 0) 73 74 left_button_container = Gtk.VBox() 75 left_button_container.pack_start(Gtk.Label(" "), True, True, 0) 76 left_button_container.pack_start(left_button, False, True, 0) 77 left_button_container.pack_start(Gtk.Label(" "), True, True, 0) 78 79 right_button_container = Gtk.VBox() 80 right_button_container.pack_start(Gtk.Label(" "), True, True, 0) 81 right_button_container.pack_start(right_button, False, True, 0) 82 right_button_container.pack_start(Gtk.Label(" "), True, True, 0) 77 83 78 84 79 self.pack_start(left_button_container, expand=False)80 self.pack_start(image_container )81 self.pack_start(right_button_container, expand=False)85 self.pack_start(left_button_container, False, True, 0) 86 self.pack_start(image_container, True, True, 0) 87 self.pack_start(right_button_container, False, True, 0) 82 88 83 89 self._source_article = None 84 90 self.show_all() … … class Gallery_View( gtk.HBox ): 99 105 self.current_index += 1 100 106 if self.current_index == len(self.image_list): 101 107 self.current_index = 0 102 self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0])108 self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0]) 103 109 self.image.set_from_pixbuf(self.imagebuf) 104 110 self.caption.set_text("\n" + self.image_list[self.current_index][1]) 105 111 self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list))) … … class Gallery_View( gtk.HBox ): 115 121 if self.current_index == 0: 116 122 self.current_index = len(self.image_list) 117 123 self.current_index -= 1 118 self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0])124 self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0]) 119 125 self.image.set_from_pixbuf(self.imagebuf) 120 126 self.caption.set_text("\n" + self.image_list[self.current_index][1]) 121 127 self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list))) … … class Gallery_View( gtk.HBox ): 129 135 self.image.clear() 130 136 return 131 137 self.current_index = 0 132 self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0])138 self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0]) 133 139 self.image.set_from_pixbuf(self.imagebuf) 134 140 self.caption.set_text("\n" + self.image_list[self.current_index][1]) 135 141 logger.debug("setting text to:") … … class Gallery_View( gtk.HBox ): 147 153 148 154 def drag_data_get_event(self, widget, context, selection_data, info, timestamp, data): 149 155 logger.debug("getting data") 150 atom = gtk.gdk.atom_intern("section")156 atom = Gdk.atom_intern("section") 151 157 imagedata = Picture_Data(self.source_article_id, 152 158 self.image_list[self.current_index][0], 153 159 self.image_list[self.current_index][2]) -
infoslicer/widgets/Image_Pane.py
diff --git a/infoslicer/widgets/Image_Pane.py b/infoslicer/widgets/Image_Pane.py index 99026f0..473253c 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 2 import gi 3 gi.require_version('Gtk', '3.0') 4 from gi.repository import Gtk 5 from gi.repository import Gdk 6 from gi.repository import GObject 5 7 import logging 6 8 from gettext import gettext as _ 7 9 … … from infoslicer.processing.Article import Article 11 13 12 14 logger = logging.getLogger('infoslicer') 13 15 14 class Image_Pane( gtk.HBox):16 class Image_Pane(Gtk.HBox): 15 17 """ 16 18 Created by Christopher Leonard 17 19 … … class Image_Pane(gtk.HBox): 23 25 """ 24 26 25 27 def __init__(self): 26 gtk.HBox.__init__(self)28 GObject.GObject.__init__(self) 27 29 self.toolitems = [] 28 30 29 gallery_box = gtk.VBox()31 gallery_box = Gtk.VBox() 30 32 gallery_box.show() 31 33 32 labeleb = gtk.EventBox()33 labeleb.modify_bg( gtk.STATE_NORMAL, gtk.gdk.color_parse("#EEEEEE"))34 labeleb = Gtk.EventBox() 35 labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE")) 34 36 gallery_box.pack_start(labeleb, False, False, 0) 35 37 labeleb.show() 36 38 37 self.articletitle = gtk.Label()38 self.articletitle.set_justify( gtk.JUSTIFY_CENTER)39 self.articletitle = Gtk.Label() 40 self.articletitle.set_justify(Gtk.Justification.CENTER) 39 41 labeleb.add(self.articletitle) 40 42 self.articletitle.show() 41 43 42 44 self.gallery = Gallery_View() 43 self.gallery.set_size_request( gtk.gdk.screen_width()/2, -1)44 gallery_box.pack_start(self.gallery )45 self.gallery.set_size_request(Gdk.Screen.width()/2, -1) 46 gallery_box.pack_start(self.gallery, True, True, 0) 45 47 46 self.pack_start(gallery_box, False )48 self.pack_start(gallery_box, False, False, 0) 47 49 self.editarticle = Editing_View() 48 self.pack_start(self.editarticle )50 self.pack_start(self.editarticle, True, True, 0) 49 51 self.editarticle.show_all() 50 52 51 53 self.gallery._source_article = None -
infoslicer/widgets/Reading_View.py
diff --git a/infoslicer/widgets/Reading_View.py b/infoslicer/widgets/Reading_View.py index 55609c9..3c40757 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 2 import gi 3 gi.require_version('Gtk', '3.0') 4 from gi.repository import Gtk 5 from gi.repository import GObject 5 6 from Readonly_Textbox import Readonly_Textbox 6 7 import logging 7 8 8 9 logger = logging.getLogger('infoslicer') 9 10 elogger = logging.getLogger('infoslicer::except') 10 11 11 class Reading_View( gtk.VBox ):12 class Reading_View( Gtk.VBox ): 12 13 """ 13 14 Created by Jonathan Mace 14 15 … … class Reading_View( gtk.VBox ): 21 22 """ 22 23 23 24 def __init__(self): 24 gtk.VBox.__init__(self)25 GObject.GObject.__init__(self) 25 26 26 self.articlewindow = gtk.ScrolledWindow()27 self.articlewindow.set_policy( gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)28 self.pack_start(self.articlewindow )27 self.articlewindow = Gtk.ScrolledWindow() 28 self.articlewindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) 29 self.pack_start(self.articlewindow, True, True, 0) 29 30 self.articlewindow.show() 30 31 31 32 self.textbox = Readonly_Textbox() -
infoslicer/widgets/Readonly_Textbox.py
diff --git a/infoslicer/widgets/Readonly_Textbox.py b/infoslicer/widgets/Readonly_Textbox.py index 958cfcd..fa87210 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 5 import pango 2 from gi.repository import Gtk 3 from gi.repository import Gdk 4 from gi.repository import Pango 6 5 import cPickle 7 6 from Textbox import Textbox 8 7 … … class Readonly_Textbox( Textbox ): 24 23 self.use_as_drag_source = use_as_drag_source 25 24 self.set_mode(SELECT_SENTENCE) 26 25 self.block = True 27 self.modify_font( pango.FontDescription('arial 9'))26 self.modify_font(Pango.FontDescription('arial 9')) 28 27 29 28 30 29 def set_mode(self, mode): … … class Readonly_Textbox( Textbox ): 45 44 self.event_handlers.append(self.connect("drag-motion", self.drag_motion, None)) 46 45 47 46 def drag_motion(self, widget, context, x, y, timestamp, data): 48 context.drag_status(gtk.gdk.ACTION_COPY, timestamp)47 Gdk.drag_status(context, Gdk.DragAction.COPY, timestamp) 49 48 return True 50 49 51 50 def clicked_event(self, widget, event, data): 52 if event.type == gtk.gdk._2BUTTON_PRESS or event.type == gtk.gdk._3BUTTON_PRESS:51 if event.type == Gdk.EventType._2BUTTON_PRESS or event.type == Gdk.EventType._3BUTTON_PRESS: 53 52 self.stop_emission("button_press_event") 54 53 return 55 54 if event.button == 3: … … class Readonly_Textbox( Textbox ): 156 155 a = self.article 157 156 158 157 if self.selectionmode == SELECT_SENTENCE: 159 atom = gtk.gdk.atom_intern("sentence")158 atom = Gdk.atom_intern("sentence", only_if_exists=False) 160 159 if self.selectionmode == SELECT_PARAGRAPH: 161 atom = gtk.gdk.atom_intern("paragraph")160 atom = Gdk.atom_intern("paragraph", only_if_exists=False) 162 161 if self.selectionmode == SELECT_SECTION: 163 atom = gtk.gdk.atom_intern("section")162 atom = Gdk.atom_intern("section", only_if_exists=False) 164 163 165 164 string = cPickle.dumps(a.getSelection()) 166 165 selection_data.set(atom, 8, string) -
infoslicer/widgets/Textbox.py
diff --git a/infoslicer/widgets/Textbox.py b/infoslicer/widgets/Textbox.py index 95f0681..634f967 100644
a b 1 1 # Copyright (C) IBM Corporation 2008 2 import pygtk 3 pygtk.require('2.0') 4 import gtk 2 import gi 3 gi.require_version('Gtk', '3.0') 4 from gi.repository import Gtk 5 from gi.repository import GObject 6 from gi.repository import Pango 5 7 import cPickle 6 8 import pango 7 9 8 10 SELECT_SENTENCE, SELECT_PARAGRAPH, SELECT_SECTION, FULL_EDIT = range(4) 9 11 10 class Textbox( gtk.TextView ):12 class Textbox( Gtk.TextView ): 11 13 """ 12 14 Created by Jonathan Mace 13 15 The Textbox class is the base class for our own custom textboxes which implement … … class Textbox( gtk.TextView ): 19 21 20 22 21 23 def __init__(self): 22 gtk.TextView.__init__(self)24 GObject.GObject.__init__(self) 23 25 self.set_border_width(1) 24 26 self.event_handlers = [] 25 self.set_wrap_mode( gtk.WRAP_WORD)27 self.set_wrap_mode(Gtk.WrapMode.WORD) 26 28 self.set_cursor_visible(False) 27 29 self.set_editable(False) 28 self.modify_font( pango.FontDescription('arial 9'))30 self.modify_font(Pango.FontDescription('arial 9')) 29 31 self.article = None 30 32 self.set_property("left-margin", 5) 31 33 … … class Textbox( gtk.TextView ): 37 39 return self.article 38 40 39 41 def show(self): 40 gtk.TextView.show(self)42 Gtk.TextView.show(self) 41 43 42 44 def clear(self): 43 45 self.article.delete() … … class Textbox( gtk.TextView ): 51 53 52 54 def get_mouse_iter(self, x, y): 53 55 # Convenience method to get the iter in the buffer of x, y coords. 54 click_coords = self.window_to_buffer_coords( gtk.TEXT_WINDOW_TEXT, x, y)56 click_coords = self.window_to_buffer_coords(Gtk.TextWindowType.TEXT, x, y) 55 57 mouseClickPositionIter = self.get_iter_at_location(click_coords[0], click_coords[1]) 56 return mouseClickPositionIter 57 No newline at end of file 58 return mouseClickPositionIter -
library.py
diff --git a/library.py b/library.py index 325ed49..3087072 100644
a b 12 12 # along with this program; if not, write to the Free Software 13 13 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 14 15 import gtk 15 from gi.repository import Gtk 16 from gi.repository import Gdk 17 from gi.repository import GObject 16 18 import logging 17 19 from threading import Timer 18 20 from datetime import datetime 19 21 from gettext import gettext as _ 20 22 import locale 21 23 22 from sugar .graphics.toolbutton import ToolButton23 from sugar .graphics.toggletoolbutton import ToggleToolButton24 from sugar .activity.activity import ActivityToolbox25 from sugar .graphics.toolcombobox import ToolComboBox26 from sugar .graphics.icon import Icon27 from sugar .datastore import datastore28 import sugar .graphics.style as style24 from sugar3.graphics.toolbutton import ToolButton 25 from sugar3.graphics.toggletoolbutton import ToggleToolButton 26 from sugar3.graphics.toolcombobox import ToolComboBox 27 from sugar3.graphics.icon import Icon 28 from sugar3.datastore import datastore 29 from sugar3.graphics.alert import Alert 30 import sugar3.graphics.style as style 29 31 30 32 import xol 31 33 import net … … from infoslicer.widgets.Reading_View import Reading_View 35 37 36 38 logger = logging.getLogger('infoslicer') 37 39 38 class View( gtk.EventBox):40 class View(Gtk.EventBox): 39 41 def sync(self): 40 42 self.wiki.sync() 41 43 self.custom.sync() 42 44 43 45 def __init__(self, activity): 44 gtk.EventBox.__init__(self)46 GObject.GObject.__init__(self) 45 47 self.activity = activity 46 48 47 49 self.wiki = BookView(book.wiki, … … class View(gtk.EventBox): 52 54 # stubs for empty articles 53 55 54 56 def create_stub(icon_name, head_text, tail_text): 55 head_label = gtk.Label(head_text)56 head_label_a = gtk.Alignment(0.5, 1, 0, 0)57 head_label = Gtk.Label(label=head_text) 58 head_label_a = Gtk.Alignment.new(0.5, 1, 0, 0) 57 59 head_label_a.add(head_label) 58 60 icon = Icon(icon_name=icon_name, 59 icon_size= gtk.ICON_SIZE_LARGE_TOOLBAR)60 tail_label = gtk.Label(tail_text)61 tail_label_a = gtk.Alignment(0.5, 0, 0, 0)61 icon_size=Gtk.IconSize.LARGE_TOOLBAR) 62 tail_label = Gtk.Label(label=tail_text) 63 tail_label_a = Gtk.Alignment.new(0.5, 0, 0, 0) 62 64 tail_label_a.add(tail_label) 63 stub = gtk.VBox()64 stub.pack_start(head_label_a )65 stub.pack_start(icon, False )66 stub.pack_start(tail_label_a )65 stub = Gtk.VBox() 66 stub.pack_start(head_label_a, True, True, 0) 67 stub.pack_start(icon, False, False, 0) 68 stub.pack_start(tail_label_a, True, True, 0) 67 69 return stub 68 70 69 71 wiki_stub = create_stub('white-search', … … class View(gtk.EventBox): 78 80 wiki_prefix = lang_code[0:2] + '.' 79 81 language_order = 0 80 82 order = 0 81 search_box = gtk.HBox()83 search_box = Gtk.HBox() 82 84 self.wikimenu = ToolComboBox(label_text=_('Get article from:')) 83 85 for i in sorted(WIKI.keys()): 84 86 self.wikimenu.combo.append_item(WIKI[i], i) … … class View(gtk.EventBox): 86 88 language_order = order 87 89 order = order + 1 88 90 self.wikimenu.combo.set_active(language_order) 89 search_box.pack_start(self.wikimenu, False )91 search_box.pack_start(self.wikimenu, False, False, 0) 90 92 91 self.searchentry = gtk.Entry()92 self.searchentry.set_size_request(int( gtk.gdk.screen_width() / 4), -1)93 self.searchentry = Gtk.Entry() 94 self.searchentry.set_size_request(int(Gdk.Screen.width() / 4), -1) 93 95 self.searchentry.set_text(_("Article name")) 94 96 self.searchentry.select_region(0, -1) 95 97 self.searchentry.connect('activate', self._search_activate_cb) 96 search_box.pack_start(self.searchentry )98 search_box.pack_start(self.searchentry, True, True, 0) 97 99 search_box.show_all() 98 100 99 self.searchbutton = gtk.Button(label=_('Search'))101 self.searchbutton = Gtk.Button(label=_('Search')) 100 102 self.searchbutton.connect('clicked', self._search_clicked_cb) 101 search_box.pack_start(self.searchbutton, False )103 search_box.pack_start(self.searchbutton, False, False, 0) 102 104 103 105 wiki_widget = Reading_View() 104 wiki = gtk.Notebook()106 wiki = Gtk.Notebook() 105 107 wiki.props.show_border = False 106 108 wiki.props.show_tabs = False 107 wiki.append_page(wiki_stub )108 wiki.append_page(wiki_widget )109 wiki.append_page(wiki_stub, None) 110 wiki.append_page(wiki_widget, None) 109 111 110 self.progress = gtk.Label()112 self.progress = Gtk.Label() 111 113 #self.progress.set_size_request(-1, style.SMALL_ICON_SIZE+4) 112 #progress_box = gtk.HBox()113 #progress_box.pack_start( gtk.HSeparator(), False)114 #progress_box = Gtk.HBox() 115 #progress_box.pack_start(Gtk.HSeparator(, True, True, 0), False) 114 116 #progress_box.pack_start(self.progress, False) 115 117 116 wiki_box = gtk.VBox()117 wiki_box.pack_start(search_box, False )118 wiki_box.pack_start(wiki )119 wiki_box.pack_start(self.progress, False )120 wiki_box.set_size_request( gtk.gdk.screen_width()/4*3,121 gtk.gdk.screen_height()/2 - style.GRID_CELL_SIZE / 2)118 wiki_box = Gtk.VBox() 119 wiki_box.pack_start(search_box, False, False, 0) 120 wiki_box.pack_start(wiki, True, True, 0) 121 wiki_box.pack_start(self.progress, False, False, 0) 122 wiki_box.set_size_request(Gdk.Screen.width()/4*3, 123 Gdk.Screen.height()/2 - style.GRID_CELL_SIZE / 2) 122 124 123 125 custom_widget = Reading_View() 124 custom = gtk.Notebook()126 custom = Gtk.Notebook() 125 127 custom.props.show_border = False 126 128 custom.props.show_tabs = False 127 custom.append_page(custom_stub )128 custom.append_page(custom_widget )129 # custom.set_size_request( gtk.gdk.screen_width()/4*3,130 # gtk.gdk.screen_height()/2 - 55)131 custom.set_size_request( gtk.gdk.screen_width()/4*3,132 gtk.gdk.screen_height()/2 - style.GRID_CELL_SIZE / 2)129 custom.append_page(custom_stub, None) 130 custom.append_page(custom_widget, None) 131 # custom.set_size_request(Gdk.Screen.width()/4*3, 132 # Gdk.Screen.height()/2 - 55) 133 custom.set_size_request(Gdk.Screen.width()/4*3, 134 Gdk.Screen.height()/2 - style.GRID_CELL_SIZE / 2) 133 135 134 136 # workspace 135 137 136 articles_box = gtk.HBox()137 articles_box.pack_start(self.wiki )138 articles_box.pack_start( gtk.VSeparator(), False)139 articles_box.pack_start(wiki_box, False )138 articles_box = Gtk.HBox() 139 articles_box.pack_start(self.wiki, True, True, 0) 140 articles_box.pack_start(Gtk.VSeparator(), False, False, 0) 141 articles_box.pack_start(wiki_box, False, False, 0) 140 142 141 custom_box = gtk.HBox()142 custom_box.pack_start(self.custom )143 custom_box.pack_start( gtk.VSeparator(), False)144 custom_box.pack_start(custom, False )143 custom_box = Gtk.HBox() 144 custom_box.pack_start(self.custom, True, True, 0) 145 custom_box.pack_start(Gtk.VSeparator(), False, False, 0) 146 custom_box.pack_start(custom, False, False, 0) 145 147 146 workspace = gtk.VBox()147 workspace.pack_start(articles_box, False )148 workspace.pack_start(custom_box, False )148 workspace = Gtk.VBox() 149 workspace.pack_start(articles_box, False, False, 0) 150 workspace.pack_start(custom_box, False, False, 0) 149 151 workspace.show_all() 150 152 151 153 self.add(workspace) … … class View(gtk.EventBox): 199 201 return 200 202 201 203 if book.wiki.find('%s (from %s)' % (title, wiki))[0]: 202 self.activity.notify_alert( 203 _('Exists'), 204 _('"%s" article already exists') % title) 204 alert = Alert() 205 alert.props.title = _('Exists') 206 alert.props.msg = _('"%s" article already exists' % title) 207 alert.show() 205 208 else: 206 209 Timer(0, self._download, [title, wiki]).start() 207 210 -
net.py
diff --git a/net.py b/net.py index e3a13cf..e4b6eac 100644
a b import urllib 18 18 import logging 19 19 from gettext import gettext as _ 20 20 21 from sugar .activity.activity import get_bundle_path21 from sugar3.activity.activity import get_bundle_path 22 22 23 23 import book 24 24 from infoslicer.processing.NewtifulSoup import NewtifulStoneSoup \ … … from infoslicer.processing.MediaWiki_Helper import PageNotFoundError 29 29 30 30 logger = logging.getLogger('infoslicer') 31 31 elogger = logging.getLogger('infoslicer::except') 32 elogger = logger 32 33 33 34 proxies = None 34 35 35 36 def download_wiki_article(title, wiki, progress): 36 37 try: 37 38 progress.set_label(_('"%s" download in progress...') % title) 39 logger.debug('START downloading') 38 40 article, url = MediaWiki_Helper().getArticleAsHTMLByTitle(title, wiki) 41 logger.debug('FINISH downloading') 39 42 40 43 progress.set_label(_('Processing "%s"...') % title) 41 44 parser = MediaWiki_Parser(article, title, url) -
setup.py
diff --git a/setup.py b/setup.py index bb74f5a..83abd2a 100755
a b 14 14 # along with this program; if not, write to the Free Software 15 15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 16 17 from sugar .activity import bundlebuilder17 from sugar3.activity import bundlebuilder 18 18 if __name__ == "__main__": 19 19 bundlebuilder.start() 20 20 -
toolbar.py
diff --git a/toolbar.py b/toolbar.py index 811f93a..dbb2101 100644
a b 12 12 # along with this program; if not, write to the Free Software 13 13 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 14 15 import gtk16 import gobject15 from gi.repository import Gtk 16 from gi.repository import GObject 17 17 18 from sugar .graphics.icon import Icon19 import sugar .graphics.style as style18 from sugar3.graphics.icon import Icon 19 import sugar3.graphics.style as style 20 20 21 class WidgetItem( gtk.ToolItem):21 class WidgetItem(Gtk.ToolItem): 22 22 def __init__(self, widget): 23 gtk.ToolItem.__init__(self)23 GObject.GObject.__init__(self) 24 24 self.add(widget) 25 25 widget.show() 26 26 27 class ButtonItem( gtk.ToolButton):28 def __init__(self, icon_name, size= gtk.ICON_SIZE_SMALL_TOOLBAR, **kwargs):29 gobject.GObject.__init__(self, **kwargs)27 class ButtonItem(Gtk.ToolButton): 28 def __init__(self, icon_name, size=Gtk.IconSize.SMALL_TOOLBAR, **kwargs): 29 GObject.GObject.__init__(self, **kwargs) 30 30 31 31 icon = Icon(icon_name=icon_name, icon_size=size) 32 # The alignment is a hack to work around gtk.ToolButton code33 # that sets the icon_size when the icon_widget is a gtk.Image34 alignment = gtk.Alignment(0.5, 0.5)32 # The alignment is a hack to work around Gtk.ToolButton code 33 # that sets the icon_size when the icon_widget is a Gtk.Image 34 alignment = Gtk.Alignment.new(0.5, 0.5) 35 35 alignment.add(icon) 36 36 self.set_icon_widget(alignment) 37 37 38 if size == gtk.ICON_SIZE_SMALL_TOOLBAR:38 if size == Gtk.IconSize.SMALL_TOOLBAR: 39 39 button_size = style.SMALL_ICON_SIZE + 8 40 40 self.set_size_request(button_size, button_size) -
xol.py
diff --git a/xol.py b/xol.py index f9eeb73..79763de 100644
a b 15 15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 16 17 17 import os 18 import gtk18 from gi.repository import Gtk 19 19 import zipfile 20 20 import uuid 21 21 import logging … … import parse 23 23 from glob import glob 24 24 from gettext import gettext as _ 25 25 26 from sugar.activity.activity import get_bundle_path, get_activity_root, get_bundle_name 27 from sugar.datastore import datastore 28 from sugar import activity 26 from sugar3.activity.activity import get_bundle_path, get_activity_root, get_bundle_name 27 from sugar3.datastore import datastore 28 from sugar3 import activity 29 from sugar3.graphics.alert import NotifyAlert, ConfirmationAlert 29 30 30 31 from infoslicer.processing.NewtifulSoup import NewtifulStoneSoup \ 31 32 as BeautifulStoneSoup … … import book 33 34 34 35 logger = logging.getLogger('infoslicer') 35 36 37 38 def __alert_notify_response_cb(alert, response_id, activity): 39 activity.remove_alert(alert) 40 41 42 def __alert_response_cb(alert, response_id, activity, force): 43 activity.remove_alert(alert) 44 publish(activity, force) 45 46 36 47 def publish(activity, force=False): 37 48 if not [i for i in book.custom.index if i['ready']]: 38 activity.notify_alert( 39 _('Nothing to publish'), 40 _('Mark arcticles from "Custom" panel and try again.')) 49 alert = NotifyAlert(5) 50 alert.props.title = _('Nothing to publish') 51 alert.props.msg = _('Mark arcticles from "Custom" ' 52 'panel and try again.') 53 alert.connect('response', __alert_notify_response_cb, activity) 54 activity.add_alert(alert) 55 alert.show() 41 56 return 42 57 43 58 title = activity.metadata['title'] … … def publish(activity, force=False): 52 67 if force: 53 68 jobject = jobject[0] 54 69 else: 55 try: 56 # check for 0.84 code 57 from jarabe import config 58 except: 59 # 0.82 couldn't override .xol bundles 60 activity.notify_alert( 61 _('Bundle exists'), 62 _('A bundle by "%s" name already exists. Please ' \ 63 'click "Erase" in the Journal. You can click ' \ 64 '"Publish" again afterwards.') % \ 65 jobject[0].metadata['title']) 66 return 67 68 activity.confirmation_alert( 69 _('Overwrite existed bundle?'), 70 _('A bundle for current object was already created. ' \ 71 'Click "OK" to overwrite it.'), 72 publish, activity, True) 70 alert = ConfirmationAlert() 71 alert.props.title = _('Overwrite existed bundle?') 72 alert.props.msg = _('A bundle for current object was already created. ' 73 'Click "OK" to overwrite it.') 74 alert.connect('response', __alert_response_cb, activity, True) 75 activity.add_alert(alert) 76 alert.show() 73 77 jobject[0].destroy() 74 78 return 75 79 else: … … def publish(activity, force=False): 91 95 92 96 book.custom.sync_index() 93 97 94 activity.notify_alert(_('Book published to your Journal'), 95 _('You can read the book in Browse or ' \ 96 'access the .xol file from your Journal')) 98 alert = NotifyAlert() 99 alert.props.title = _('Book published to your Journal') 100 alert.props.msg = _('You can read the book in Browse or ' 101 'access the .xol file from your Journal') 102 alert.connect('response', __alert_notify_response_cb, activity) 103 activity.add_alert(alert) 104 alert.show() 97 105 98 106 """ 99 107 @author: Matthew Bailey