Work on native gui. Display records and add missing tasks and measurements.
This commit is contained in:
+75
-2
@@ -1,7 +1,8 @@
|
||||
# SPDX-License-Identifier: WTFPL
|
||||
|
||||
import os
|
||||
from gi.repository import GLib, Gtk, Gdk
|
||||
from gi.repository import GLib, Gtk, Gdk, GdkPixbuf, Rsvg
|
||||
import fitz
|
||||
|
||||
from .view import View
|
||||
from yms import gtkutils, combobox, treeview
|
||||
@@ -11,6 +12,7 @@ class DocumentsView(View):
|
||||
|
||||
def __init__(self, context):
|
||||
super().__init__(context, _("Documents"), "documents.ui")
|
||||
self.context = context
|
||||
|
||||
self.doc = document.Document(context.db) # current record
|
||||
self.newrecord = False
|
||||
@@ -41,7 +43,18 @@ class DocumentsView(View):
|
||||
self.topwidget.set_visible_child(self.box['doc_edit'])
|
||||
|
||||
def on_but_detail_clicked(self, widget):
|
||||
docid = treeview.get_value(self.tree['documents'], 0)
|
||||
self.doc.load(docid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
def on_tvw_documents_row_activated(self, widget, path, column):
|
||||
docid = treeview.get_value(widget, 0)
|
||||
self.doc.load(docid)
|
||||
self.display_record()
|
||||
self.topwidget.set_visible_child(self.box['doc_detail'])
|
||||
self.button['close'].grab_focus()
|
||||
|
||||
# buttons on detail page
|
||||
# edit2 uses edit callback
|
||||
@@ -58,8 +71,68 @@ class DocumentsView(View):
|
||||
def on_but_cancel_clicked(self, widget):
|
||||
self.topwidget.set_visible_child(self.box['documents'])
|
||||
|
||||
def pdf_to_pixbuf(self, filename, max_width=400, max_height=400):
|
||||
doc = fitz.open(filename)
|
||||
page = doc[0]
|
||||
rect = page.rect
|
||||
scale = min(max_width / rect.width, max_height / rect.height)
|
||||
matrix = fitz.Matrix(scale, scale)
|
||||
pix = page.get_pixmap(matrix=matrix, alpha=False)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_data(
|
||||
pix.samples,
|
||||
GdkPixbuf.Colorspace.RGB,
|
||||
pix.alpha,
|
||||
8,
|
||||
pix.width,
|
||||
pix.height,
|
||||
pix.stride,
|
||||
None,
|
||||
None
|
||||
)
|
||||
return pixbuf
|
||||
|
||||
def display_record(self):
|
||||
pass
|
||||
print(self.doc)
|
||||
self.label['title'].set_text(self.doc.title or '')
|
||||
self.label['filename'].set_text(self.doc.filename)
|
||||
# self.label['extents'] -> see below
|
||||
self.label['mimetype'].set_text(self.doc.mimetype)
|
||||
self.label['filesize'].set_text(self.format_int(self.doc.docsize, suffix="Byte"))
|
||||
self.label['date'].set_text(self.format_date(self.doc.docdate))
|
||||
self.label['doctype'].set_text(self.doc.doctype)
|
||||
self.label['roleaccess'].set_text(self.doc.roleaccess)
|
||||
self.label['doctype'].set_text(self.doc.remarks or '')
|
||||
|
||||
# image preview
|
||||
if self.doc.doctype == 'picture':
|
||||
filename = f"pic-{self.doc.pk_value:06d}.{self.doc.extension}"
|
||||
imgpath = os.path.join(self.context.cfg['docpath'], filename)
|
||||
info = GdkPixbuf.Pixbuf.get_file_info(imgpath)
|
||||
if info:
|
||||
imgformat, imgwidth, imgheight = info
|
||||
self.label['extents'].set_text(f"{imgwidth}x{imgheight} Pixel")
|
||||
if imgwidth > 400 or imgheight > 400:
|
||||
print("loading scaled")
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(imgpath, 400, 400, True)
|
||||
else:
|
||||
print("loading")
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(imgpath)
|
||||
else:
|
||||
print("cannot get image info")
|
||||
self.image['preview'].set_from_pixbuf(pixbuf)
|
||||
elif self.doc.doctype == 'drawing':
|
||||
filename = f"drw-{self.doc.pk_value:06d}.{self.doc.extension}"
|
||||
imgpath = os.path.join(self.context.cfg['docpath'], filename)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(imgpath, 400, 400, True)
|
||||
self.image['preview'].set_from_pixbuf(pixbuf)
|
||||
elif self.doc.mimetype == "application/pdf":
|
||||
filename = f"doc-{self.doc.pk_value:06d}.{self.doc.extension}"
|
||||
imgpath = os.path.join(self.context.cfg['docpath'], filename)
|
||||
print(imgpath)
|
||||
pixbuf = self.pdf_to_pixbuf(imgpath)
|
||||
self.image['preview'].set_from_pixbuf(pixbuf)
|
||||
else:
|
||||
self.image['preview'].clear()
|
||||
|
||||
def edit_record(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user