dlg_main.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # -*- coding: utf-8 -*-
  2. """
  3. /***************************************************************************
  4. MnCheckDialog
  5. A QGIS plugin
  6. Contrôle des données FTTH format MN
  7. Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
  8. -------------------
  9. begin : 2018-12-07
  10. git sha : $Format:%H$
  11. copyright : (C) 2018 by Manche Numérique 2019
  12. email : olivier.massot@manchenumerique.fr
  13. ***************************************************************************/
  14. /***************************************************************************
  15. * *
  16. * This program is free software; you can redistribute it and/or modify *
  17. * it under the terms of the GNU General Public License as published by *
  18. * the Free Software Foundation; either version 2 of the License, or *
  19. * (at your option) any later version. *
  20. * *
  21. ***************************************************************************/
  22. """
  23. import importlib
  24. import logging
  25. from PyQt5 import QtWidgets
  26. from PyQt5 import uic
  27. from PyQt5.Qt import QIcon, QPixmap
  28. from core.constants import MAIN, RSCDIR
  29. logger = logging.getLogger("mncheck")
  30. Ui_Main, _ = uic.loadUiType(MAIN / 'ui'/ 'dlg_main.ui')
  31. SCHEMAS = ["mn1_rec", "mn2_rec", "mn3_pro", "mn3_exe", "mn3_rec"]
  32. class DlgMain(QtWidgets.QDialog):
  33. def __init__(self, parent=None):
  34. super(DlgMain, self).__init__(parent)
  35. self.createWidgets()
  36. def createWidgets(self):
  37. """ set up the interface """
  38. self.ui = Ui_Main()
  39. self.ui.setupUi(self)
  40. self.ui.stack.setCurrentIndex(0)
  41. self.ui.btn_play.setIcon(QIcon(RSCDIR / "play.png"))
  42. self.ui.btn_play.clicked.connect(self.run)
  43. self.ui.btn_help.setIcon(QIcon(RSCDIR / "question.png"))
  44. self.ui.btn_help.clicked.connect(self.show_help)
  45. self.ui.btn_settings.setIcon(QIcon(RSCDIR / "settings.png"))
  46. self.ui.btn_settings.clicked.connect(self.show_settings)
  47. self.ui.lbl_hourglass.setPixmap(QPixmap(RSCDIR / "hourglass.png"))
  48. self.ui.lbl_ok.setPixmap(QPixmap(RSCDIR / "ok_32.png"))
  49. self.ui.cbb_schemas.addItem("Schéma MN v1", 0)
  50. self.ui.cbb_schemas.addItem("Schéma MN v2", 1)
  51. self.ui.cbb_schemas.addItem("Schéma MN v3 PRO", 2)
  52. self.ui.cbb_schemas.addItem("Schéma MN v3 EXE", 3)
  53. self.ui.cbb_schemas.addItem("Schéma MN v3 REC", 4)
  54. # self.ui.cbb_schemas.addItem("GraceTHD v2.1", 5)
  55. self.ui.cbb_schemas.currentIndexChanged.connect(self.update_layers_list)
  56. self.update_layers_list()
  57. def update_layers_list(self):
  58. schema_lib_name = SCHEMAS[int(self.ui.cbb_schemas.itemData(self.ui.cbb_schemas.currentIndex()))]
  59. schema_lib = importlib.import_module("schemas." + schema_lib_name)
  60. logger.info("Selection du schema '{%s}'", schema_lib)
  61. def run(self):
  62. pass
  63. # try:
  64. # f = request.FILES['dossier']
  65. # except KeyError:
  66. # return render(request, "index.html", {"validation_error": "Aucun fichier sélectionné"})
  67. #
  68. # filename = secure_filename(f.name)
  69. #
  70. # if Path(filename).ext != ".zip":
  71. # return render(request, "index.html", {"validation_error": "Le fichier doit être un fichier .ZIP ({})".format(Path(filename).ext)})
  72. #
  73. # schema_lib_name = request.POST['schema']
  74. # schema_lib = importlib.import_module("schemas." + schema_lib_name)
  75. #
  76. # # try:
  77. # with TemporaryDirectory(dir=MAIN / "upload") as d:
  78. # filename = Path(d) / filename
  79. # with open(filename, 'wb+') as destination:
  80. # for chunk in f.chunks():
  81. # destination.write(chunk)
  82. # report = schema_lib.validator.submit(filename)
  83. # # except Exception as e:
  84. # # return render_template("index.html", validation_error=str(e))
  85. #
  86. # return render(request, "report.html", {"report": report})
  87. def show_help(self):
  88. pass
  89. def show_settings(self):
  90. pass