mirror of https://gitlab.com/pamhyr/pamhyr2
95 lines
2.4 KiB
Python
Executable File
95 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# pamhyr.py -- Pamhyr entrypoint
|
|
# Copyright (C) 2023 INRAE
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys, os
|
|
import locale
|
|
import logging
|
|
|
|
from PyQt5.QtCore import QTranslator
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
from config import Config
|
|
from tools import (
|
|
reset_timers, display_timers, timer,
|
|
logger_color_blue, logger_color_red, logger_color_green, logger_color_reset
|
|
)
|
|
|
|
from View.MainWindow import ApplicationWindow
|
|
from Model.Study import Study
|
|
|
|
from Scripts.Hello import ScriptHello
|
|
|
|
from init import license, setup_lang
|
|
|
|
logger = logging.getLogger()
|
|
|
|
scripts = {
|
|
"gui" : None,
|
|
"hello": ScriptHello,
|
|
}
|
|
|
|
def usage(argv):
|
|
logger.error(f"{logger_color_red()}Invalid script name '{argv[1]}'{logger_color_reset()}")
|
|
logger.info(f"Usage: {argv[0]} <script> <args...>")
|
|
logger.info(f"")
|
|
logger.info(f"Valid scripts:")
|
|
for s in scripts:
|
|
logger.info(f"\t{s}\t\t{scripts[s].name}: {scripts[s].description}")
|
|
|
|
def gui(app:QApplication, conf:Config):
|
|
application = ApplicationWindow(conf=conf)
|
|
application.show()
|
|
|
|
return app.exec_()
|
|
|
|
def main():
|
|
conf = Config.load()
|
|
app = QApplication(sys.argv)
|
|
|
|
tr = setup_lang(app, conf)
|
|
app.installTranslator(tr)
|
|
|
|
license()
|
|
|
|
if len(sys.argv) > 1:
|
|
# Run a script
|
|
script = sys.argv[1]
|
|
|
|
if script == "gui":
|
|
ret = gui(app, conf)
|
|
else:
|
|
if script not in scripts:
|
|
usage(sys.argv)
|
|
sys.exit(-1)
|
|
|
|
application = scripts[script](conf, sys.argv)
|
|
ret = application.run()
|
|
if not ret:
|
|
application.usage()
|
|
else:
|
|
# No args, run Pamhyr2 interface
|
|
ret = gui(app, conf)
|
|
|
|
display_timers()
|
|
sys.exit(ret)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|