-
Notifications
You must be signed in to change notification settings - Fork 9
/
plugin_settings_dialog.py
147 lines (133 loc) · 6.87 KB
/
plugin_settings_dialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -*- coding: utf-8 -*-
"""
.. module:: plugin_settings_dialog
:platform: Linux, Windows
:synopsis: GUI for SurveyingCalculation plugin settings
.. moduleauthor: Zoltan Siki <[email protected]>
"""
from PyQt4.QtGui import QDialog, QFileDialog, QMessageBox
from PyQt4.QtCore import Qt, QSettings, QDir, QFileInfo
# plugin specific python modules
import config
from plugin_settings import Ui_PluginSettingsDialog
from base_classes import tr
class PluginSettingsDialog(QDialog):
""" Class for plugin settings dialog
"""
def __init__(self):
""" Initialize dialog data and event handlers
"""
super(PluginSettingsDialog, self).__init__()
self.ui = Ui_PluginSettingsDialog()
self.ui.setupUi(self)
self.setWindowModality(Qt.ApplicationModal)
# event handlers
self.ui.HomeDirButton.clicked.connect(self.onHomeDirButton)
self.ui.LogPathButton.clicked.connect(self.onLogPathButton)
self.ui.GamaPathButton.clicked.connect(self.onGamaPathButton)
self.ui.PlotTemplateDirButton.clicked.connect(self.onPlotTemplateDirButton)
self.ui.OKButton.clicked.connect(self.onOKButton)
self.ui.CancelButton.clicked.connect(self.onCancelButton)
self.fillWidgets()
def fillWidgets(self):
""" Fill all widgets of Plugins Settings dialog.
"""
for i in range(8,20):
self.ui.FontSizeCombo.addItem("%d"%i)
fontname = QSettings().value("SurveyingCalculation/fontname",config.fontname)
fontsize = int(QSettings().value("SurveyingCalculation/fontsize",config.fontsize))
self.ui.FontNameCombo.setCurrentIndex(self.ui.FontNameCombo.findText( fontname ))
self.ui.FontSizeCombo.setCurrentIndex(self.ui.FontSizeCombo.findText( "%d"%fontsize ))
self.ui.HomeDirEdit.setText(QSettings().value("SurveyingCalculation/homedir",config.homedir))
self.ui.LogPathEdit.setText(QSettings().value("SurveyingCalculation/log_path",config.log_path))
self.ui.GamaPathEdit.setText(QSettings().value("SurveyingCalculation/gama_path",config.gama_path))
self.ui.PlotTemplateDirEdit.setText(QSettings().value("SurveyingCalculation/template_dir",config.template_dir))
self.ui.LineToleranceEdit.setText("%f"%float( QSettings().value("SurveyingCalculation/line_tolerance",config.line_tolerance) ))
self.ui.AreaToleranceEdit.setText("%f"%float( QSettings().value("SurveyingCalculation/area_tolerance",config.area_tolerance) ))
self.ui.MaxIterationEdit.setText("%d"%int( QSettings().value("SurveyingCalculation/max_iteration",config.max_iteration) ))
def onHomeDirButton(self):
""" Change the home directory where fieldbooks are stored.
"""
path = QFileDialog.getExistingDirectory(self,
tr("Select Home Directory"),
self.ui.HomeDirEdit.text(),
QFileDialog.ShowDirsOnly)
if path!="":
self.ui.HomeDirEdit.setText(path)
def onLogPathButton(self):
""" Change the directory of the log file.
"""
path = QFileDialog.getSaveFileName(self,
tr("Select Log File Path"),
self.ui.LogPathEdit.text(), "",
QFileDialog.DontConfirmOverwrite)
if path!="":
self.ui.LogPathEdit.setText(path)
def onGamaPathButton(self):
""" Change the directory of the gama-local executable.
"""
path = QFileDialog.getOpenFileName(self,
tr("Select Path to GNU Gama Executable"),
self.ui.GamaPathEdit.text())
if path!="":
self.ui.GamaPathEdit.setText(path)
def onPlotTemplateDirButton(self):
""" Change the directory of the plot template files.
"""
path = QFileDialog.getExistingDirectory(self,
tr("Select Plot Template Directory"),
self.ui.PlotTemplateDirEdit.text(),
QFileDialog.ShowDirsOnly)
if path!="":
self.ui.PlotTemplateDirEdit.setText(path)
def onOKButton(self):
""" Close dialog. The changes will be saved.
"""
# check values in widgets
try:
line_tolerance = float(self.ui.LineToleranceEdit.text())
except (ValueError):
QMessageBox.warning(self, tr("Warning"), tr("Snap tolerance must be a positive float value in layer units!"))
self.ui.LineToleranceEdit.setFocus()
return
if line_tolerance<=0.0:
QMessageBox.warning(self, tr("Warning"), tr("Snap tolerance must be a positive float value in layer units!"))
self.ui.LineToleranceEdit.setFocus()
return
try:
area_tolerance = float(self.ui.AreaToleranceEdit.text())
except (ValueError):
QMessageBox.warning(self, tr("Warning"), tr("Area tolerance must be a positive float value in layer units!"))
self.ui.AreaToleranceEdit.setFocus()
return
if area_tolerance<=0.0:
QMessageBox.warning(self, tr("Warning"), tr("Area tolerance must be a positive float value in layer units!"))
self.ui.AreaToleranceEdit.setFocus()
return
try:
max_iteration = int(self.ui.MaxIterationEdit.text())
except (ValueError):
QMessageBox.warning(self, tr("Warning"), tr("Maximum iteration must be a positive integer value!"))
self.ui.MaxIterationEdit.setFocus()
return
if max_iteration<=0:
QMessageBox.warning(self, tr("Warning"), tr("Maximum iteration must be a positive integer value!"))
self.ui.MaxIterationEdit.setFocus()
return
# store settings
# TODO store font setting from widgets
QSettings().setValue("SurveyingCalculation/fontname",self.ui.FontNameCombo.currentText())
QSettings().setValue("SurveyingCalculation/fontsize",self.ui.FontSizeCombo.currentText())
QSettings().setValue("SurveyingCalculation/homedir",self.ui.HomeDirEdit.text())
QSettings().setValue("SurveyingCalculation/log_path",self.ui.LogPathEdit.text())
QSettings().setValue("SurveyingCalculation/gama_path",self.ui.GamaPathEdit.text())
QSettings().setValue("SurveyingCalculation/template_dir",self.ui.PlotTemplateDirEdit.text())
QSettings().setValue("SurveyingCalculation/line_tolerance",line_tolerance)
QSettings().setValue("SurveyingCalculation/area_tolerance",area_tolerance)
QSettings().setValue("SurveyingCalculation/max_iteration",max_iteration)
QSettings().sync()
self.accept()
def onCancelButton(self):
""" Cancel dialog. The changes won't be saved.
"""
self.reject()