nattyfix
This commit is contained in:
parent
00828d4c08
commit
e526de786e
|
@ -3,8 +3,10 @@ import traceback
|
||||||
from typing import Dict, List, Optional, Sequence, Tuple, TypeAlias
|
from typing import Dict, List, Optional, Sequence, Tuple, TypeAlias
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import GLib, Gio, Gtk, GObject
|
from gi.repository import GLib, Gio, Gtk, GObject
|
||||||
|
|
||||||
gi.require_foreign("cairo")
|
gi.require_foreign("cairo")
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
|
@ -14,41 +16,46 @@ TEST_FILENAME = "/home/luna/Documents/Resources/Praca Licencjacka/sources/2018_T
|
||||||
|
|
||||||
Coords: TypeAlias = Tuple[float, float]
|
Coords: TypeAlias = Tuple[float, float]
|
||||||
|
|
||||||
|
|
||||||
class Selection:
|
class Selection:
|
||||||
def __init__(self, bounds: Tuple[Coords, Coords], columns: Optional[Sequence[float]] = None):
|
def __init__(self, bounds: Tuple[Coords, Coords], columns: Optional[Sequence[float]] = None):
|
||||||
self.bounds = bounds
|
self.bounds = bounds
|
||||||
self.columns = columns
|
self.columns = columns
|
||||||
|
|
||||||
|
|
||||||
class Document:
|
class Document:
|
||||||
def __init__(self, filename: str):
|
def __init__(self, filename: str):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.document = fitz.Document(filename)
|
self.document = fitz.Document(filename)
|
||||||
self.selections: Dict[int, List[Selection]] = {}
|
self.selections: Dict[int, List[Selection]] = {}
|
||||||
|
|
||||||
|
|
||||||
class State():
|
class State():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PdfPage(Gtk.DrawingArea):
|
class PdfPage(Gtk.DrawingArea):
|
||||||
def __init__(self, page, *args, **kwargs):
|
def __init__(self, page, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.page: fitz.Page = page
|
self.page: fitz.Page = page
|
||||||
pix = self.page.get_pixmap(dpi=300) # type: ignore
|
pix = self.page.get_pixmap(dpi=96) # type: ignore
|
||||||
self.set_size_request(pix.width, pix.height)
|
self.set_size_request(pix.width, pix.height)
|
||||||
|
print(f"w: {pix.width}, h: {pix.height}")
|
||||||
self.set_app_paintable(True) # type: ignore
|
self.set_app_paintable(True) # type: ignore
|
||||||
self.connect("draw", self.on_draw, {})
|
self.connect("draw", self.on_draw, {})
|
||||||
|
|
||||||
def on_draw(self, widget, cr: cairo.Context, data: GObject.GPointer):
|
def on_draw(self, widget: Gtk.DrawingArea, cr: cairo.Context, data: GObject.GPointer):
|
||||||
#app: Application = widget.get_window().get_application() # type: ignore
|
# app: Application = widget.get_window().get_application() # type: ignore
|
||||||
width = self.get_allocated_width()
|
width = widget.get_allocated_width()
|
||||||
height = self.get_allocated_height()
|
height = widget.get_allocated_height()
|
||||||
|
print(f"alloc w: {width}, h: {height}")
|
||||||
|
|
||||||
sctx = self.get_style_context()
|
sctx = widget.get_style_context()
|
||||||
Gtk.render_background(sctx, cr, 0, 0, width, height)
|
Gtk.render_background(sctx, cr, 0, 0, width, height)
|
||||||
|
pix = self.page.get_pixmap(dpi=96, alpha=True) # type: ignore
|
||||||
pix = self.page.get_pixmap(dpi=300) # type: ignore
|
mv: memoryview = pix.samples_mv
|
||||||
png = pix.tobytes("png")
|
ims = cairo.ImageSurface.create_for_data(mv, cairo.Format.RGB24, pix.width, pix.height)
|
||||||
ims = cairo.ImageSurface.create_from_png(png)
|
|
||||||
cr.set_source_surface(ims, 0, 0)
|
cr.set_source_surface(ims, 0, 0)
|
||||||
cr.paint()
|
cr.paint()
|
||||||
|
|
||||||
|
@ -79,11 +86,10 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
|
|
||||||
self.app.connect("notify::document", self.on_document_updated)
|
self.app.connect("notify::document", self.on_document_updated)
|
||||||
|
|
||||||
#self.pdf_list_box.add(PdfPage())
|
# self.pdf_list_box.add(PdfPage())
|
||||||
|
|
||||||
|
# @Gtk.Template.Callback()
|
||||||
#@Gtk.Template.Callback()
|
# def example_button_released_cb(self, widget: Gtk.Button, **kwargs):
|
||||||
#def example_button_released_cb(self, widget: Gtk.Button, **kwargs):
|
|
||||||
# assert self.example_button == widget
|
# assert self.example_button == widget
|
||||||
# print(widget.get_label())
|
# print(widget.get_label())
|
||||||
# widget.set_label("woah")
|
# widget.set_label("woah")
|
||||||
|
@ -127,10 +133,12 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
self.header_bar.set_subtitle(document.filename) # type: ignore
|
self.header_bar.set_subtitle(document.filename) # type: ignore
|
||||||
|
|
||||||
for i in document.document.pages(): # type: ignore
|
for i in document.document.pages(): # type: ignore
|
||||||
|
row = Gtk.ListBoxRow()
|
||||||
page = PdfPage(i)
|
page = PdfPage(i)
|
||||||
box = Gtk.Box()
|
row.add(page)
|
||||||
box.pack_start(page, True, True, 20)
|
self.pdf_list_box.add(row) # type: ignore
|
||||||
self.pdf_list_box.add(box) # type: ignore
|
|
||||||
|
self.pdf_list_box.show_all()
|
||||||
|
|
||||||
@Gtk.Template.Callback()
|
@Gtk.Template.Callback()
|
||||||
def on_open_button_small_clicked(self, widget, **kwargs):
|
def on_open_button_small_clicked(self, widget, **kwargs):
|
||||||
|
@ -145,7 +153,7 @@ class Application(Gtk.Application):
|
||||||
*args,
|
*args,
|
||||||
application_id="zone.lunareclipse.pdf_table_extractor",
|
application_id="zone.lunareclipse.pdf_table_extractor",
|
||||||
flags=Gio.ApplicationFlags.FLAGS_NONE,
|
flags=Gio.ApplicationFlags.FLAGS_NONE,
|
||||||
#flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE, # TODO
|
# flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE, # TODO
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
self.window = None
|
self.window = None
|
||||||
|
|
Loading…
Reference in New Issue