Fixes for sane module and scanner feature
This commit is contained in:
1 parent
7aa5d2af3b
commit
dacf32b401
7 files changed
+54
-6
No files matched your search
@@ -71,7 +71,7 @@ class AppContext:
|
||||
'user': 'yms',
|
||||
'docpath': '/var/local/lib/yms',
|
||||
'shapedir': '/usr/local/share/yms/shapes',
|
||||
'scanner': 'off'
|
||||
'scanner': False
|
||||
}
|
||||
|
||||
# mapping between PHP and Python
|
||||
@@ -95,6 +95,7 @@ class AppContext:
|
||||
self.textdomain = "ymsgui" # static here for early initialization
|
||||
self.localedir = "locale"
|
||||
self.datefmt = '%d.%m.%Y'
|
||||
self.scan_enabled = False
|
||||
# system settings stored in database
|
||||
self.curr_sym = '€'
|
||||
self.img_max_width = 1024
|
||||
@@ -122,6 +123,32 @@ class AppContext:
|
||||
# perhaps create missing record here?
|
||||
pass
|
||||
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):
|
||||
path = os.path.realpath(__file__)
|
||||
@@ -280,8 +307,14 @@ if __name__ == "__main__":
|
||||
# TODO check database schema version
|
||||
schema_required = 1
|
||||
context.load()
|
||||
# check if shapedir exists
|
||||
context.cfg['scanner'] = config.getboolean('Documents', 'scanner')
|
||||
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
|
||||
app = Frontend(context)
|
||||
app.run()
|
||||
|
||||
Reference in new issue
Block a user