forked from GeODinTeam/GeODinQGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeODinQGIS_Settings.py
More file actions
159 lines (127 loc) · 5.42 KB
/
GeODinQGIS_Settings.py
File metadata and controls
159 lines (127 loc) · 5.42 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from pythonmodules.helpFunction import *
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
import smtplib, shutil, ConfigParser, win32api
from ui_Files.ui_GeODinQGIS_Settings import Ui_Settings
class Settings(QDialog, Ui_Settings):
def __init__(self, main):
# setup UI and connect the buttons
QDialog.__init__(self)
self.setupUi(self)
self.main = main
# connect buttons to their functions
QObject.connect(self.btn_del_tmp, SIGNAL("clicked()"), self.deleteTmp)
QObject.connect(self.btn_mail, SIGNAL("clicked()"), self.sendMail)
self.connect(self.btn_dir, SIGNAL("clicked()"), self.Tmp_Dir)
self.connect(self.btn_defdir, SIGNAL("clicked()"), self.Def_Dir)
self.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.okClick)
QObject.connect(self.btn_info, SIGNAL("clicked()"), self.openInfo)
# manage button icons
self.btn_info.setIcon(QIcon(":\plugins\GeODinQGIS\icons\info.png"))
self.btn_del_tmp.setIcon(QIcon(":\plugins\GeODinQGIS\icons\i_102F.png"))
self.btn_del_tmp.setIconSize(QSize(24, 24))
# path of tmp folder in home directory
self.tmpDirectory = main.tmpDirectory
self.dict = main.dictionary
self.lang = main.lang
self.errorLog = main.logDirectory+"\\error.log"
self.setWindowTitle(self.dict.getWord(self.lang,"Settings"))
self.lbl_del.setText(self.dict.getWord(self.lang,"Delete temporary files"))
self.lbl_surpress.setText(self.dict.getWord(self.lang,"Suppress attribute form pop-up after feature creation"))
self.btn_mail.setText(self.dict.getWord(self.lang,"Send Email"))
self.lbl_dir.setText(self.dict.getWord(self.lang,"Directory to save vector layers"))
self.lbl_lyr.setText(self.dict.getWord(self.lang,"Save Layer as"))
self.btn_defdir.setText(self.dict.getWord(self.lang,"Restore Default"))
self.logFile()
self.configFile = main.configFile
self.config = main.config
self.readConfigFile()
self.exec_()
def Tmp_Dir(self):
# enter custom directory for temporary files
tmpDirectory = QFileDialog.getExistingDirectory(self)
self.le_dir.setText(tmpDirectory)
def Def_Dir(self):
# restore default directory for temporary files
self.le_dir.setText(self.main.def_tmp_dir)
def readConfigFile(self):
self.le_dir.setText(self.config.get('Options', 'tmpdirectory'))
if self.config.get("Options", "suppressattribute") == "True":
self.checkBox.setChecked(True)
else:
self.checkBox.setChecked(False)
if self.config.get("Options", "savelayer") == "True":
self.rbtn_sql.setChecked(True)
# self.rbtn_sql.setChecked(False)
else:
self.rbtn_shp.setChecked(True)
# self.rbtn_shp.setChecked(False)
def okClick(self):
self.main.tmpDirectory = self.le_dir.text()
if self.checkBox.isChecked():
self.config.set('Options', "suppressattribute", "True")
QSettings().setValue( '/qgis/digitizing/disable_enter_attribute_values_dialog', True )
else:
self.config.set('Options', "suppressattribute", "False")
QSettings().setValue( '/qgis/digitizing/disable_enter_attribute_values_dialog', False )
if self.rbtn_sql.isChecked():
self.config.set('Options', "savelayer", "True")
else:
self.config.set('Options', "savelayer", "False")
self.config.set('Options', 'tmpdirectory', self.main.tmpDirectory)
self.saveConfig()
def saveConfig(self):
with open(self.configFile, 'wb') as configFile:
self.config.write(configFile)
def deleteTmp(self):
# delete files in tmp-directory
try:
for subFile in os.listdir(self.tmpDirectory):
subFilePath = os.path.join(self.tmpDirectory, subFile)
if os.path.isfile(subFilePath):
try:
os.unlink(subFilePath)
except:
pass
elif os.path.isdir(subFilePath):
try:
shutil.rmtree(subFilePath)
except:
pass
QMessageBox.information(None,self.dict.getWord(self.lang,"Deletion"),self.dict.getWord(self.lang,"Temporary files deleted successfully"))
except Exception,e:
print str(e)
return
def logFile(self):
# print size of error log file in kb
size = str(round(float(os.path.getsize(self.errorLog))/1000)) + " kb"
self.lbl_size.setText(size)
def sendMail(self):
# send email to GeODin support team
# email browser is automatically openend
# error log file must be attached manually
# text from error message is appreciated
email = "mailto:"
receiver = "support@geodin.com"
cc = [""]
bcc = [""]
subject = "Fehlermeldung GeODin QGIS"
body = "Es ist ein Fehler bei der Arbeit mit GeODinQGIS aufgetreten.\n\nDas Fehlerprotokoll befindet sich im Anhang."
body = body.replace(' ', '%20').replace('\n', '%0D%0A').replace('=',':').replace('"',"'")
email += receiver +'&SUBJECT='+subject+'&BODY='+body
win32api.ShellExecute(0, 'open', email, None, None, 0)
def attrsDialog(self):
# get user defined current setting
disableDialog = QSettings().value( '/qgis/digitizing/disable_enter_attribute_values_dialog')
# override setting
QSettings().setValue( '/qgis/digitizing/disable_enter_attribute_values_dialog', True )
# restore setting
QSettings().setValue( '/qgis/digitizing/disable_enter_attribute_values_dialog', disableDialog )
def openInfo(self):
# print "Info"
info = Info()