Fixes for sane module and scanner feature

This commit is contained in:
thooge committed 2026-10-30 09:43:45 +01:00
1 parent 7aa5d2af3b
commit dacf32b401
7 files changed
+52 -4

No files matched your search

+2 -1
View File
@@ -2,7 +2,8 @@ YMS - Open Source Yacht Management System
Preview Version Preview Version
Free, self-hosted software for managing your boat's equipment, Free, self-hosted software for managing your boat's equipment,
inventory, documents, maintenance and tasks. inventory, documents, maintenance, projects, tasks and some
other things.
Your boat. Your data. Your software. Your boat. Your data. Your software.
+2
View File
@@ -26,6 +26,8 @@ Depends:
php-xml, php-xml,
gettext, gettext,
mupdf-tools mupdf-tools
Suggests:
python3-sane
Description: Yacht Management Software Description: Yacht Management Software
Yacht Management Software (YMS) is an application for managing yachts and Yacht Management Software (YMS) is an application for managing yachts and
sailboats. It provides a native GTK desktop interface and a web interface. sailboats. It provides a native GTK desktop interface and a web interface.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

+13 -1
View File
@@ -3,7 +3,6 @@
import os import os
from gi.repository import GLib, Gtk, Gdk, GdkPixbuf, Rsvg from gi.repository import GLib, Gtk, Gdk, GdkPixbuf, Rsvg
import fitz import fitz
import sane
from .view import View from .view import View
from yms import gtkutils, combobox, treeview from yms import gtkutils, combobox, treeview
@@ -18,8 +17,21 @@ class DocumentsView(View):
self.doc = document.Document(context.db) # current record self.doc = document.Document(context.db) # current record
self.newrecord = False self.newrecord = False
# init scan feature
if context.scan_enabled:
# checks have been done by context initialization
import sane
# TODO
# multiple scanner?
# open scanner
self.scandialog = self.builder.get_object("dlg_scanner") self.scandialog = self.builder.get_object("dlg_scanner")
self.scandialog.set_title("Scan new document") self.scandialog.set_title("Scan new document")
else:
# if deactivated from config hide otherwise disable
if self.context.cfg['scanner'] == 'off':
self.button['scan'].set_visible(False)
else:
self.button['scan'].set_sensitive(False)
self.uploaddialog = self.builder.get_object("dlg_upload") self.uploaddialog = self.builder.get_object("dlg_upload")
self.uploaddialog.set_title("Upload new document") self.uploaddialog.set_title("Upload new document")
+35 -2
View File
@@ -71,7 +71,7 @@ class AppContext:
'user': 'yms', 'user': 'yms',
'docpath': '/var/local/lib/yms', 'docpath': '/var/local/lib/yms',
'shapedir': '/usr/local/share/yms/shapes', 'shapedir': '/usr/local/share/yms/shapes',
'scanner': 'off' 'scanner': False
} }
# mapping between PHP and Python # mapping between PHP and Python
@@ -95,6 +95,7 @@ class AppContext:
self.textdomain = "ymsgui" # static here for early initialization self.textdomain = "ymsgui" # static here for early initialization
self.localedir = "locale" self.localedir = "locale"
self.datefmt = '%d.%m.%Y' self.datefmt = '%d.%m.%Y'
self.scan_enabled = False
# system settings stored in database # system settings stored in database
self.curr_sym = '€' self.curr_sym = '€'
self.img_max_width = 1024 self.img_max_width = 1024
@@ -122,6 +123,32 @@ class AppContext:
# perhaps create missing record here? # perhaps create missing record here?
pass pass
self.lookup.load() self.lookup.load()
self.init_scanner()
def init_scanner(self):
self.scan_enabled = False
if not self.cfg['scanner']:
return
try:
import sane
except ImportError:
print("Module python3-sane not found. Scanning disabled!")
return
print("Initializing sane document scanning...")
try:
version = sane.init()
print(f"Found sane version {version[1]}.{version[2]}.{version[3]}")
except sane._sane.error as e:
print("Error initializing sane")
return
devices = sane.get_devices(localOnly=True) # this will take a while
if not devices:
return
# TODO cameras may be also detected
for dev in devices:
print(f"Found scanner {dev[2]}")
self.scan_enabled = True
print("Done.")
def get_sharepath(self): def get_sharepath(self):
path = os.path.realpath(__file__) path = os.path.realpath(__file__)
@@ -280,8 +307,14 @@ if __name__ == "__main__":
# TODO check database schema version # TODO check database schema version
schema_required = 1 schema_required = 1
context.load() context.load()
# check if shapedir exists context.cfg['scanner'] = config.getboolean('Documents', 'scanner')
context.cfg['shapedir'] = config.get('Data', 'shapedir') context.cfg['shapedir'] = config.get('Data', 'shapedir')
if not os.path.isdir(context.cfg['shapedir']):
gtkutils.messagebox(
_("Directory with deck plan files not found.\n\n"
"Please check your configuration file!",
title="YMS")
sys.exit(1)
# everything seems to be fine: continue to start frontend # everything seems to be fine: continue to start frontend
app = Frontend(context) app = Frontend(context)
app.run() app.run()