diff options
Diffstat (limited to 'library.py')
-rw-r--r-- | library.py | 133 |
1 files changed, 63 insertions, 70 deletions
@@ -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" } |