diff options
author | Lucian Branescu Mihaila <lucian.branescu@gmail.com> | 2010-07-20 16:54:30 (GMT) |
---|---|---|
committer | Lucian Branescu Mihaila <lucian.branescu@gmail.com> | 2010-07-20 16:54:30 (GMT) |
commit | 1acc7ad954210db5b59cf66b98069c1d3ca8a7a1 (patch) | |
tree | 7c26e9302d249cb6b0966c9647d456a3526ec62c | |
parent | ab881c0f0b781e226b44d05d9a3c2ee8cd74fed8 (diff) |
Fix epub view. No toolbar features work for epub view.
-rw-r--r-- | epubadapter.py | 4 | ||||
-rw-r--r-- | epubview/epubview.py | 38 | ||||
-rw-r--r-- | readactivity.py | 42 | ||||
-rw-r--r-- | readtoolbar.py | 9 |
4 files changed, 43 insertions, 50 deletions
diff --git a/epubadapter.py b/epubadapter.py index a3cf280..db17cc2 100644 --- a/epubadapter.py +++ b/epubadapter.py @@ -41,15 +41,11 @@ class View(epubview.EpubView): def handle_link(self, link): self._load_file(link) - class EpubDocument(epubview.Epub): def __init__(self, view, docpath): epubview.Epub.__init__(self, docpath) self._page_cache = view - def get_page_cache(self): - return self._page_cache - def get_n_pages(self): return int(self._page_cache.get_pagecount()) diff --git a/epubview/epubview.py b/epubview/epubview.py index 595eb20..1ee5246 100644 --- a/epubview/epubview.py +++ b/epubview/epubview.py @@ -35,17 +35,17 @@ LOADING_HTML = ''' class _View(gtk.HBox): __gproperties__ = { - 'has-selection' : (gobject.TYPE_BOOLEAN, 'whether has selection', - 'whether the widget has selection or not', - 0, gobject.PARAM_READABLE), - 'zoom' : (gobject.TYPE_FLOAT, 'the zoom level', - 'the zoom level of the widget', - 0.5, 4.0, 1.0, gobject.PARAM_READWRITE) + 'scale' : (gobject.TYPE_FLOAT, 'the zoom level', + 'the zoom level of the widget', + 0.5, 4.0, 1.0, gobject.PARAM_READWRITE) } __gsignals__ = { 'page-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([])) + ([])), + 'selection-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([])), } def __init__(self): gobject.threads_init() @@ -62,8 +62,8 @@ class _View(gtk.HBox): self.__going_fwd = True self.__going_back = False self.__page_changed = False - self.has_selection = False - self.zoom = 1.0 + self._has_selection = False + self.scale = 1.0 self._epub = None self._findjob = None self.__in_search = False @@ -106,9 +106,9 @@ class _View(gtk.HBox): def do_get_property(self, property): if property.name == 'has-selection': - return self.has_selection + return self._has_selection elif property.name == 'zoom': - return self.zoom + return self.scale else: raise AttributeError, 'unknown property %s' % property.name @@ -122,7 +122,7 @@ class _View(gtk.HBox): ''' Returns True if any part of the content is selected ''' - return self.get_property('has-selection') + return self._has_selection def get_zoom(self): ''' @@ -160,7 +160,7 @@ class _View(gtk.HBox): ''' Returns True if it is possible to zoom in further ''' - if self.zoom < 4: + if self.scale < 4: return True else: return False @@ -169,7 +169,7 @@ class _View(gtk.HBox): ''' Returns True if it is possible to zoom out further ''' - if self.zoom > 0.5: + if self.scale > 0.5: return True else: return False @@ -292,12 +292,11 @@ class _View(gtk.HBox): def __set_zoom(self, value): self._view.set_zoom_level(value) - self.zoom = value + self.scale = value def __set_has_selection(self, value): - if value != self.has_selection: - self.has_selection = value - self.notify('has-selection') + if value != self._has_selection: + self._has_selection = value def _view_populate_popup_cb(self, view, menu): menu.destroy() #HACK @@ -307,6 +306,7 @@ class _View(gtk.HBox): # FIXME: This does not seem to be implemented in # webkitgtk yet print view.has_selection() + self.emit('selection-changed') def _view_buttonrelease_event_cb(self, view, event): # Ugly hack @@ -349,7 +349,6 @@ class _View(gtk.HBox): return False def _view_load_finished_cb(self, v, frame): - # Normally the line below would not be required - ugly workaround for # possible Webkit bug. See : https://bugs.launchpad.net/bugs/483231 self._sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER) @@ -560,4 +559,3 @@ class _View(gtk.HBox): def _destroy_cb(self, widget): self._epub.close() - diff --git a/readactivity.py b/readactivity.py index 20d8ec7..cc4a20b 100644 --- a/readactivity.py +++ b/readactivity.py @@ -54,8 +54,9 @@ from readtopbar import TopBar _EPUB_SUPPORT = True try: import epubadapter -except: +except ImportError, e: _EPUB_SUPPORT = False + logging.warning('Epub support disabled because: %s' % e) _HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager' @@ -508,7 +509,6 @@ class ReadActivity(activity.Activity): current_link = self._toc_model.get(iter, 1)[0] current_page = self._model.props.page - if not hasattr(current_link, 'get_page'): filepath = self._view.get_current_file() if filepath is None or filepath.endswith(current_link): @@ -753,16 +753,16 @@ class ReadActivity(activity.Activity): def _setup_epub_viewer(self): self._view = epubadapter.View() self._view.set_screen_dpi(_get_screen_dpi()) - self._view.connect('notify::has-selection', - self._view_notify_has_selection_cb) + self._view.connect('selection-changed', + self._view_selection_changed_cb) self._hbox.pack_start(self._view, expand=True, fill=True) self._view.show_all() def _setup_evince_viewer(self): self._view = evince.View() - self._view.connect('notify::has-selection', - self._view_notify_has_selection_cb) + self._view.connect('selection-changed', + self._view_selection_changed_cb) self._scrolled = gtk.ScrolledWindow() self._scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) @@ -785,9 +785,13 @@ class ReadActivity(activity.Activity): if mimetype == 'application/epub+zip': if not _EPUB_SUPPORT: self.close() + return self._epub = True self._setup_epub_viewer() self._document = epubadapter.EpubDocument(self._view, filepath.replace('file://', '')) + self._model = None + + self._view.set_document(self._document) else: self._setup_evince_viewer() try: @@ -795,19 +799,21 @@ class ReadActivity(activity.Activity): except GError, e: _logger.error('Can not load document: %s', e) return + else: + self._model = evince.DocumentModel() + self._model.set_document(self._document) + self._view.set_model(self._model) + + # set dpi + dpi = _get_screen_dpi() + min_scale = self._model.get_min_scale() + max_scale = self._model.get_max_scale() + self._model.set_min_scale(min_scale * dpi / 72.0) + self._model.set_max_scale(max_scale * dpi / 72.0) self._want_document = False - - self._model = evince.DocumentModel() - self._model.set_document(self._document) - self._view.set_model(self._model) - + # set dpi - dpi = _get_screen_dpi() - min_scale = self._model.get_min_scale() - max_scale = self._model.get_max_scale() - self._model.set_min_scale(min_scale * dpi / 72.0) - self._model.set_max_scale(max_scale * dpi / 72.0) self._view_toolbar.set_view(self._view, self._model) self._edit_toolbar.set_view(self._view) @@ -929,8 +935,8 @@ class ReadActivity(activity.Activity): self.watch_for_tubes() self._share_document() - def _view_notify_has_selection_cb(self, view, pspec): - self._edit_toolbar.copy.set_sensitive(self._view.props.has_selection) + def _view_selection_changed_cb(self, view): + self._edit_toolbar.copy.props.sensitive = view.get_has_selection() def _edit_toolbar_copy_cb(self, button): self._view.copy() diff --git a/readtoolbar.py b/readtoolbar.py index d91e73b..71bf564 100644 --- a/readtoolbar.py +++ b/readtoolbar.py @@ -23,7 +23,7 @@ import evince try: import epubadapter -except: +except ImportError: pass from sugar.graphics.toolbutton import ToolButton @@ -80,13 +80,6 @@ class EditToolbar(activity.EditToolbar): self._evince_view = view self._evince_view.find_set_highlight_search(True) - self._evince_view.connect('selection-changed', - self._selection_changed_cb) - - def _selection_changed_cb(self, evince_view): - logging.debug('Has selection: %s' % evince_view.get_has_selection()) - self.copy.props.sensitive = evince_view.get_has_selection() - def set_document(self, document): self._document = document |