-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
document.page_for_id: catch empty imageFilename case #25
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe we should add "text/html" to
ocrd_utils.constants.MIME_TO_EXT
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about that – not sure TBH. (Might have implications elsewhere.) @kba?