AutofillDialog.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """
  2. ***************************************************************************
  3. AutofillDialog.py
  4. ---------------------
  5. Date : August 2012
  6. Copyright : (C) 2012 by Victor Olaya
  7. Email : volayaf at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Victor Olaya'
  18. __date__ = 'August 2012'
  19. __copyright__ = '(C) 2012, Victor Olaya'
  20. import os
  21. import warnings
  22. from qgis.PyQt import uic
  23. from qgis.PyQt.QtWidgets import QDialog
  24. pluginPath = os.path.split(os.path.dirname(__file__))[0]
  25. with warnings.catch_warnings():
  26. warnings.filterwarnings("ignore", category=DeprecationWarning)
  27. WIDGET, BASE = uic.loadUiType(
  28. os.path.join(pluginPath, 'ui', 'DlgAutofill.ui'))
  29. class AutofillDialog(BASE, WIDGET):
  30. DO_NOT_AUTOFILL = 0
  31. FILL_WITH_NUMBERS = 1
  32. FILL_WITH_PARAMETER = 2
  33. def __init__(self, alg):
  34. super().__init__(None)
  35. self.setupUi(self)
  36. self.mode = None
  37. self.param_name = None
  38. self.alg = alg
  39. self.cmbFillType.currentIndexChanged.connect(self.toggleParameters)
  40. for param in self.alg.parameterDefinitions():
  41. self.cmbParameters.addItem(param.description(), param.name())
  42. def toggleParameters(self, index):
  43. if index == self.FILL_WITH_PARAMETER:
  44. self.lblParameters.setEnabled(True)
  45. self.cmbParameters.setEnabled(True)
  46. else:
  47. self.lblParameters.setEnabled(False)
  48. self.cmbParameters.setEnabled(False)
  49. def accept(self):
  50. self.mode = self.cmbFillType.currentIndex()
  51. self.param_name = self.cmbParameters.currentData()
  52. QDialog.accept(self)
  53. def reject(self):
  54. self.mode = None
  55. self.param_name = None
  56. QDialog.reject(self)