-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDlgSceltaRilevatore.py
191 lines (143 loc) · 6.6 KB
/
DlgSceltaRilevatore.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : Omero RT
Description : Omero plugin
Date : August 15, 2010
copyright : (C) 2010 by Giuseppe Sucameli (Faunalia)
email : [email protected]
***************************************************************************/
Omero plugin
Works done from Faunalia (http://www.faunalia.it) with funding from Regione
Toscana - S.I.T.A. (http://www.regione.toscana.it/territorio/cartografia/index.html)
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ui.dlgSceltaRilevatore_ui import Ui_Dialog
from ConnectionManager import ConnectionManager
from AutomagicallyUpdater import *
from ManagerWindow import ManagerWindow
class DlgSceltaRilevatore(QDialog, MappingOne2One, Ui_Dialog):
def __init__(self, parent=None):
QDialog.__init__(self, parent)
MappingOne2One.__init__(self)
self.setupUi(self)
# carica i widget multivalore con i valori delle relative tabelle
tablesDict = {
self.comuneCombo: AutomagicallyUpdater.Query( "SELECT com.ISTATCOM, com.NOME || ' (' || prov.NOME || ')' FROM ZZ_PROVINCE AS prov JOIN ZZ_COMUNI AS com ON prov.ISTATPROV = com.ZZ_PROVINCEISTATPROV ORDER BY com.NOME, prov.NOME ASC" ),
self.rilevatoriTable: AutomagicallyUpdater.Query( "SELECT ID, COGNOME, NOME FROM RILEVATORE WHERE ID LIKE ? ORDER BY COGNOME, NOME ASC", [ None ], 0 )
}
self.setupTablesUpdater(tablesDict)
self.loadTables()
# connetti i segnali agli slot
self.connect(self.nomeEdit, SIGNAL("textChanged (const QString &)"), self.aggiornaPulsanti)
self.connect(self.cognomeEdit, SIGNAL("textChanged (const QString &)"), self.aggiornaPulsanti)
self.connect(self.addRilevatoreBtn, SIGNAL("clicked()"), self.aggiungiRilevatore)
self.connect(self.delRilevatoreBtn, SIGNAL("clicked()"), self.eliminaRilevatore)
self.connect(self.comuneCombo, SIGNAL("currentIndexChanged(int)"), self.aggiornaRilevatori)
self.connect(self.rilevatoriTable.selectionModel(), SIGNAL("selectionChanged(const QItemSelection &, const QItemSelection &)"), self.aggiornaPulsanti)
self.aggiornaPulsanti()
def aggiornaPulsanti(self):
enabler = self.getValue(self.comuneCombo) != None
self.nuovoRilevatoreGroup.setEnabled( enabler )
enabler = not self.nomeEdit.text() == "" and not self.cognomeEdit.text() == ""
self.addRilevatoreBtn.setEnabled( enabler )
enabler = self.getValue(self.rilevatoriTable) != None
self.delRilevatoreBtn.setEnabled( enabler )
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( self.isCompleted() )
def isCompleted(self):
return len(self.rilevatoriTable.selectedIndexes()) > 0 and self.comuneCombo.currentIndex() >= 0
def aggiornaRilevatori(self):
IDComune = self.getValue(self.comuneCombo)
params = [ IDComune+'%' ] if IDComune != None else None
self._widget2action[self.rilevatoriTable].setParams( params )
self.loadTables(self.rilevatoriTable)
self.aggiornaPulsanti()
def eliminaRilevatore(self):
ID = self.getValue(self.rilevatoriTable)
if ID == None:
return
# elimina il rilevatore
try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
ConnectionManager.startTransaction()
if not self._deleteValue( 'RILEVATORE', { 'ID' : ID } ):
return
except ConnectionManager.AbortedException, e:
QMessageBox.critical(self, "Errore", Porting.str(e))
return False
finally:
ConnectionManager.endTransaction()
QApplication.restoreOverrideCursor()
self.loadTables( self.rilevatoriTable )
def aggiungiRilevatore(self):
if self.nomeEdit.text() == "" or self.cognomeEdit.text() == "":
return
try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
ConnectionManager.startTransaction()
self._insertRilevatore(self.nomeEdit.text(), self.cognomeEdit.text(), self.getValue(self.comuneCombo))
except ConnectionManager.AbortedException, e:
QMessageBox.critical(self, "Errore", Porting.str(e))
return False
finally:
ConnectionManager.endTransaction()
QApplication.restoreOverrideCursor()
self.loadTables(self.rilevatoriTable)
# pulisci i campi
self.nomeEdit.clear()
self.cognomeEdit.clear()
def exec_(self):
settings = QSettings()
self.setValue(self.comuneCombo, self._getIDComune())
self.setValue(self.rilevatoriTable, self._getIDRilevatore())
offline = self.offlineMode()
self.offlineBtn.setChecked( offline )
self.onlineBtn.setChecked( not offline )
return QDialog.exec_(self)
def accept(self):
if self.offlineBtn.isChecked() and not self.offlineMode():
if not self.selectCacheFolder():
return
settings = QSettings()
settings.setValue( "/omero_RT/lastIDComune", self.getValue(self.comuneCombo) )
settings.setValue( "/omero_RT/lastIDRilevatore", self.getValue(self.rilevatoriTable) )
self.setOfflineMode( self.offlineBtn.isChecked() or not self.onlineBtn.isChecked() )
return QDialog.accept(self)
def selectCacheFolder(self):
subdir = ".omero-cache"
cache_path = self.getPathToCache()
if cache_path == "":
cache_path = self._getPathToDb()
else:
cache_dir = QDir(cache_path)
if cache_dir.dirName() == subdir:
cache_dir.cd( ".." )
cache_path = cache_dir.absolutePath()
if ManagerWindow.instance.startedYet:
caption = u"Seleziona la directory dove salvare la cache"
else:
caption = u"Seleziona la directory da dove recuperare la cache"
cache_path = QFileDialog.getExistingDirectory(self, caption, cache_path )
if cache_path == "":
return False
cache_dir = QDir( cache_path )
if ManagerWindow.instance.startedYet:
if cache_dir.dirName() != subdir:
cache_dir.mkdir( subdir )
if not cache_dir.cd( subdir ):
QMessageBox.critical(self, "RT Omero", "Impossibile scrivere nella directory selezionata.")
return False
else:
if cache_dir.dirName() != subdir and not cache_dir.cd( subdir ):
QMessageBox.information(self, "RT Omero", "Sottocartella \".omero_cache\" non trovata, parto offline senza strati wms")
self.setPathToCache( cache_dir.absolutePath() )
return True