forked from hnesk/browse-ocrd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add HTML view via WebKit (for ocrd-dinglehopper)
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from .base import View | ||
from .registry import ViewRegistry | ||
from .html import ViewHtml | ||
from .images import ViewImages | ||
from .text import ViewText | ||
from .xml import ViewXml | ||
|
||
__all__ = ['View', 'ViewRegistry', 'ViewImages', 'ViewText', 'ViewXml'] | ||
__all__ = ['View', 'ViewRegistry', 'ViewImages', 'ViewText', 'ViewXml', 'ViewHtml'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import gi | ||
gi.require_version('WebKit2', '4.0') | ||
from gi.repository import GObject, Gtk, WebKit2 | ||
|
||
from typing import Optional, Tuple, Any | ||
|
||
from ocrd_browser.view import View | ||
from ocrd_browser.view.base import FileGroupSelector, FileGroupFilter | ||
from ocrd_browser.model import Page | ||
|
||
GObject.type_register(WebKit2.WebView) | ||
|
||
|
||
class ViewHtml(View): | ||
""" | ||
A view of the HTML+CSS annotation (as produced by ocrd-dinglehopper reports). | ||
""" | ||
|
||
label = 'HTML' | ||
|
||
def __init__(self, name: str, window: Gtk.Window): | ||
super().__init__(name, window) | ||
self.file_group: Tuple[Optional[str], Optional[str]] = (None, 'text/html') | ||
# noinspection PyTypeChecker | ||
self.web_view: WebKit2.WebView = None | ||
|
||
def build(self) -> None: | ||
super().build() | ||
self.add_configurator('file_group', FileGroupSelector(FileGroupFilter.HTML)) | ||
|
||
self.web_view = WebKit2.WebView() | ||
|
||
self.scroller.add(self.web_view) | ||
|
||
@property | ||
def use_file_group(self) -> str: | ||
return self.file_group[0] | ||
|
||
def config_changed(self, name: str, value: Any) -> None: | ||
super().config_changed(name, value) | ||
self.reload() | ||
|
||
def reload(self) -> None: | ||
files = self.document.files_for_page_id(self.page_id, self.use_file_group, mimetype='text/html') | ||
if files: | ||
self.current = Page(self.page_id, files[0], None, [], [], None) | ||
self.redraw() | ||
|
||
def redraw(self) -> None: | ||
if self.current: | ||
self.web_view.set_tooltip_text(self.page_id) | ||
self.web_view.load_uri('file://' + str(self.document.path(self.current.file.local_filename))) | ||
self.web_view.show() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters