Skip to content
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

ViewPage: show @conf in tooltip #39

Merged
merged 28 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e3e519f
Don't show default features if no features are selected
hnesk Dec 13, 2021
6ea449d
remove redundant import
hnesk Dec 13, 2021
3421a72
ImageVersionSelector: show only images that exist in the FS
bertsky Jan 18, 2022
a253954
page_xml_renderer: expose confidence
bertsky Jan 20, 2022
958a43d
ViewPage: show @conf in tooltip if available
bertsky Jan 20, 2022
956e210
fix typo
bertsky Apr 2, 2022
1910bbf
add screenshot button to PageView
bertsky Apr 12, 2022
5a0b0e1
Allow flake8 violations in third-party code
hnesk Apr 14, 2022
4810a95
Disable time-sensitive test
hnesk Apr 14, 2022
e5f2c96
Merge pull request #38 from bertsky/check-altimg-exists
hnesk Apr 14, 2022
0471f7d
Merge branch 'add-screenshot' of https://github.com/bertsky/browse-oc…
hnesk Apr 14, 2022
93675c7
Allow flake8 violations in third-party code
hnesk Apr 14, 2022
cda12f9
Disable time-sensitive test
hnesk Apr 14, 2022
5f5dfa6
Allow closing "save screenshot" by any means (like ESC)
hnesk Apr 14, 2022
ac20301
New icon
hnesk Apr 14, 2022
afaba5f
Merge branch 'master' into add-screenshot
hnesk Apr 14, 2022
2180988
Merge branch 'check-altimg-exists' into add-screenshot
hnesk Apr 14, 2022
1e3bde6
Merge branch 'bertsky-add-screenshot' into add-screenshot
hnesk Apr 14, 2022
0ec5cf8
Merge branch 'add-screenshot'
hnesk Apr 14, 2022
2871056
Merge branch 'master' of github.com:hnesk/browse-ocrd
hnesk Apr 14, 2022
5d8e9d3
Aletheia examples as tests for old namespaces
hnesk Apr 14, 2022
7174636
add current namespace aletheia example
hnesk Apr 14, 2022
fee8d1c
Use PAGE-XML Namespace from current document
hnesk Apr 14, 2022
2dd621c
page_xml_renderer: expose confidence
bertsky Jan 20, 2022
4463255
ViewPage: show @conf in tooltip if available
bertsky Jan 20, 2022
2b8de13
fix typo
bertsky Apr 2, 2022
1953bea
Also show TextEqiv/@conf if available
hnesk Apr 14, 2022
ad6734e
Merge branch 'patch-1' of https://github.com/bertsky/browse-ocrd into…
hnesk Apr 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ocrd_browser/model/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def meta(self) -> MetadataType:
return self.pc_gts.get_Metadata()

def xpath(self, xpath: str) -> List[Element]:
return cast(List[Element], self.xml_root.xpath(xpath, namespaces=NAMESPACES))
page_namespace = {'page': ns for ns in self.xml_root.nsmap.values() if ns.startswith('http://schema.primaresearch.org/PAGE/gts/pagecontent/')}
return cast(List[Element], self.xml_root.xpath(xpath, namespaces=dict(NAMESPACES, **page_namespace)))

@property
def xml_root(self) -> Element:
if self.pc_gts.gds_elementtree_node_ is None:
from ocrd_models.constants import NAMESPACES
from ocrd_models.ocrd_page_generateds import parsexmlstring_
from io import StringIO
sio = StringIO()
Expand Down
11 changes: 11 additions & 0 deletions ocrd_browser/model/page_xml_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ def __init__(self, region: RegionWithCoords) -> None:
self._prep_poly: Optional[prepared.PreparedGeometry] = None
self.warnings: List[str] = []

@property
def coords_conf(self) -> Optional[float]:
return cast(float, self.region.Coords.conf) if hasattr(self.region, 'Coords') else None

@property
def text_conf(self) -> Optional[float]:
if isinstance(self.region, (TextRegionType, TextLineType, WordType, GlyphType)):
if self.region.get_TextEquiv() and self.region.get_TextEquiv()[0].conf:
return cast(float, self.region.get_TextEquiv()[0].conf)
return None

@property
def poly(self) -> Polygon:
return self._poly
Expand Down
39 changes: 38 additions & 1 deletion ocrd_browser/view/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def set_page(self, page: Page) -> None:
versions.append(ImageVersion.from_page(self.document, page))
alts: List[AlternativeImageType] = page.page.get_AlternativeImage()
for alt in alts:
versions.append(ImageVersion.from_alternative_image(self.document, alt))
if self.document.path(alt.filename).exists():
versions.append(ImageVersion.from_alternative_image(self.document, alt))

with self.version_box.handler_block(self._change_handler):
self.versions.clear()
Expand Down Expand Up @@ -255,6 +256,10 @@ def build(self) -> None:
self.add_configurator('scale', ImageZoomSelector(2.0, 0.05, -4.0, 2.0))
self.add_configurator('image_version', ImageVersionSelector())
self.add_configurator('features', PageFeaturesSelector())
icon = Gtk.Image.new_from_icon_name('camera-photo', Gtk.IconSize.SMALL_TOOLBAR)
button = Gtk.Button(image=icon, visible=True, always_show_image=True, tooltip_text='Saves a screenshot of the current view')
button.connect('clicked', self.open_screenshotdialog)
self.action_bar.pack_start(button)

actions = ActionRegistry()
actions.create(name='zoom_by', param_type=GLib.VariantType('i'), callback=self._on_zoom_by)
Expand Down Expand Up @@ -412,6 +417,11 @@ def _query_tooltip(self, _image: Gtk.Image, x: int, y: int, _keyboard_mode: bool
if region:
content += '\n<tt><big>{}</big></tt>\n\n{}\n'.format(str(region), escape(region.text))

if region.text_conf:
content += '\n<tt>@text.conf=</tt>{}'.format(region.text_conf)

if region.coords_conf:
content += '\n<tt>@coords.conf=</tt>{}'.format(region.coords_conf)
if region.region_subtype:
content += '\n<tt>@type:</tt> {}'.format(region.region_subtype)
for attribute in [
Expand Down Expand Up @@ -530,3 +540,30 @@ def update_transformation(self) -> None:
self.page_image.height
)
self.highlight.queue_draw()

def open_screenshotdialog(self, button: Gtk.Button) -> None:
if self.page_image is None:
return

dialog = Gtk.FileChooserDialog(title="Save image under...",
parent=self.window,
action=Gtk.FileChooserAction.SAVE)
dialog.add_buttons(Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE,
Gtk.ResponseType.OK)
filter_png = Gtk.FileFilter()
filter_png.set_name("PNG image files")
filter_png.add_mime_type("image/png")
dialog.add_filter(filter_png)
dialog.set_current_name("untitled.png")

response = dialog.run()
if response == Gtk.ResponseType.OK:
filename = dialog.get_filename()
else:
filename = ''

dialog.destroy()
if filename:
self.page_image.save(filename)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[flake8]
ignore=E501
exclude=tests/assets/__init__.py

[mypy]
warn_return_any = True
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,252 changes: 3,252 additions & 0 deletions tests/example/workspaces/aletheiaexamplepage/OCR-D-GT-PAGE/PAGE_2017.xml

Large diffs are not rendered by default.

3,252 changes: 3,252 additions & 0 deletions tests/example/workspaces/aletheiaexamplepage/OCR-D-GT-PAGE/PAGE_2018.xml

Large diffs are not rendered by default.

3,252 changes: 3,252 additions & 0 deletions tests/example/workspaces/aletheiaexamplepage/OCR-D-GT-PAGE/PAGE_2019.xml

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions tests/example/workspaces/aletheiaexamplepage/mets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<mets:mets xmlns:mets="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd http://www.loc.gov/mix/v10 http://www.loc.gov/standards/mix/mix10/mix10.xsd">
<mets:metsHdr CREATEDATE="2021-12-08T20:20:46.339296">
<mets:agent TYPE="OTHER" OTHERTYPE="SOFTWARE" ROLE="CREATOR">
<mets:name>ocrd/core v2.26.1</mets:name>
</mets:agent>
</mets:metsHdr>
<mets:dmdSec ID="DMDLOG_0001">
<mets:mdWrap MDTYPE="MODS">
<mets:xmlData>
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3">
</mods:mods>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:amdSec ID="AMD">
</mets:amdSec>
<mets:fileSec>
<mets:fileGrp USE="OCR-D-GT-PAGE">
<mets:file ID="PAGE_2017_XML" MIMETYPE="application/vnd.prima.page+xml">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-PAGE/PAGE_2017.xml"/>
</mets:file>
<mets:file ID="PAGE_2018_XML" MIMETYPE="application/vnd.prima.page+xml">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-PAGE/PAGE_2018.xml"/>
</mets:file>
<mets:file ID="PAGE_2019_XML" MIMETYPE="application/vnd.prima.page+xml">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-PAGE/PAGE_2019.xml"/>
</mets:file>
</mets:fileGrp>
<mets:fileGrp USE="OCR-D-GT-IMG">
<mets:file ID="PAGE_2017_IMG" MIMETYPE="image/jpeg">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-IMG/PAGE_2017.jpg"/>
</mets:file>
<mets:file ID="PAGE_2018_IMG" MIMETYPE="image/jpeg">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-IMG/PAGE_2018.jpg"/>
</mets:file>
<mets:file ID="PAGE_2019_IMG" MIMETYPE="image/jpeg">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-IMG/PAGE_2019.jpg"/>
</mets:file>
</mets:fileGrp>
<mets:fileGrp USE="OCR-D-GT-IMG-BIN">
<mets:file ID="PAGE_2017_BIN" MIMETYPE="image/tiff">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-IMG-BIN/PAGE_2017.tif"/>
</mets:file>
<mets:file ID="PAGE_2018_BIN" MIMETYPE="image/tiff">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-IMG-BIN/PAGE_2018.tif"/>
</mets:file>
<mets:file ID="PAGE_2019_BIN" MIMETYPE="image/tiff">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="OCR-D-GT-IMG-BIN/PAGE_2019.tif"/>
</mets:file>
</mets:fileGrp>
</mets:fileSec>
<mets:structMap TYPE="PHYSICAL">
<mets:div TYPE="physSequence">
<mets:div TYPE="page" ID="PAGE_2017">
<mets:fptr FILEID="PAGE_2017_XML"/>
<mets:fptr FILEID="PAGE_2017_IMG"/>
<mets:fptr FILEID="PAGE_2017_BIN"/>
</mets:div>
<mets:div TYPE="page" ID="PAGE_2018">
<mets:fptr FILEID="PAGE_2018_XML"/>
<mets:fptr FILEID="PAGE_2018_IMG"/>
<mets:fptr FILEID="PAGE_2018_BIN"/>
</mets:div>
<mets:div TYPE="page" ID="PAGE_2019">
<mets:fptr FILEID="PAGE_2019_XML"/>
<mets:fptr FILEID="PAGE_2019_IMG"/>
<mets:fptr FILEID="PAGE_2019_BIN"/>
</mets:div>

</mets:div>
</mets:structMap>
</mets:mets>
14 changes: 14 additions & 0 deletions tests/model/test_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tests import TestCase, TEST_BASE_PATH
from ocrd_browser.model import Document


class PageTestCase(TestCase):

def setUp(self):
self.doc = Document.load(TEST_BASE_PATH / 'example/workspaces/aletheiaexamplepage/mets.xml')

def test_xpath_works_with_different_namespaces(self):
for page_id in ['PAGE_2017', 'PAGE_2018', 'PAGE_2019']:
page = self.doc.page_for_id(page_id, 'OCR-D-GT-PAGE')
xpath_result = page.xpath('/page:PcGts/page:Page/@imageFilename')
self.assertGreater(len(xpath_result), 0)
2 changes: 1 addition & 1 deletion tests/util/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _image_modes():
class ImageUtilTestCase(TestCase):

def test_pil_to_pixbuf_is_faster_via_opencv(self):
# self.skipTest('Slow test')
self.skipTest('Slow test')
files = [
ASSETS_PATH / 'kant_aufklaerung_1784-binarized/data/OCR-D-IMG/OCR-D-IMG_0017.tif',
ASSETS_PATH / 'kant_aufklaerung_1784-binarized/data/OCR-D-IMG-1BIT/OCR-D-IMG-1BIT_0017.png',
Expand Down