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
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import GLib, Gio, Gtk, GObject
|
||||
|
||||
gi.require_foreign("cairo")
|
||||
import cairo
|
||||
|
||||
|
@ -14,41 +16,46 @@ TEST_FILENAME = "/home/luna/Documents/Resources/Praca Licencjacka/sources/2018_T
|
|||
|
||||
Coords: TypeAlias = Tuple[float, float]
|
||||
|
||||
|
||||
class Selection:
|
||||
def __init__(self, bounds: Tuple[Coords, Coords], columns: Optional[Sequence[float]] = None):
|
||||
self.bounds = bounds
|
||||
self.columns = columns
|
||||
|
||||
|
||||
class Document:
|
||||
def __init__(self, filename: str):
|
||||
self.filename = filename
|
||||
self.document = fitz.Document(filename)
|
||||
self.selections: Dict[int, List[Selection]] = {}
|
||||
|
||||
|
||||
class State():
|
||||
pass
|
||||
|
||||
|
||||
class PdfPage(Gtk.DrawingArea):
|
||||
def __init__(self, page, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
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)
|
||||
print(f"w: {pix.width}, h: {pix.height}")
|
||||
self.set_app_paintable(True) # type: ignore
|
||||
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
|
||||
width = self.get_allocated_width()
|
||||
height = self.get_allocated_height()
|
||||
width = widget.get_allocated_width()
|
||||
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)
|
||||
|
||||
pix = self.page.get_pixmap(dpi=300) # type: ignore
|
||||
png = pix.tobytes("png")
|
||||
ims = cairo.ImageSurface.create_from_png(png)
|
||||
pix = self.page.get_pixmap(dpi=96, alpha=True) # type: ignore
|
||||
mv: memoryview = pix.samples_mv
|
||||
ims = cairo.ImageSurface.create_for_data(mv, cairo.Format.RGB24, pix.width, pix.height)
|
||||
cr.set_source_surface(ims, 0, 0)
|
||||
cr.paint()
|
||||
|
||||
|
@ -81,7 +88,6 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
|
||||
# self.pdf_list_box.add(PdfPage())
|
||||
|
||||
|
||||
# @Gtk.Template.Callback()
|
||||
# def example_button_released_cb(self, widget: Gtk.Button, **kwargs):
|
||||
# assert self.example_button == widget
|
||||
|
@ -127,10 +133,12 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
self.header_bar.set_subtitle(document.filename) # type: ignore
|
||||
|
||||
for i in document.document.pages(): # type: ignore
|
||||
row = Gtk.ListBoxRow()
|
||||
page = PdfPage(i)
|
||||
box = Gtk.Box()
|
||||
box.pack_start(page, True, True, 20)
|
||||
self.pdf_list_box.add(box) # type: ignore
|
||||
row.add(page)
|
||||
self.pdf_list_box.add(row) # type: ignore
|
||||
|
||||
self.pdf_list_box.show_all()
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_open_button_small_clicked(self, widget, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue