-
Notifications
You must be signed in to change notification settings - Fork 2
/
DlgSelezionaDB.py
90 lines (71 loc) · 3.26 KB
/
DlgSelezionaDB.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : Omero RT
Description : Omero plugin
Date : August 15, 2010
copyright : (C) 2010 by Giuseppe Sucameli (Faunalia)
email : sucameli@faunalia.it
***************************************************************************/
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.dlgSelezionaDB_ui import Ui_DlgSelezionaDB as Ui_Dlg
from AutomagicallyUpdater import *
from Utils import Porting
class DlgSelezionaDB(QDialog, Ui_Dlg):
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setupUi(self)
self.connect(self.buttonBox, SIGNAL("helpRequested()"), self.help)
self.connect(self.btnDbDemo, SIGNAL("clicked()"), self.copiaDemoDB)
self.connect(self.btnDbWork, SIGNAL("clicked()"), self.copiaWorkDB)
def help(self):
import os.path
path = os.path.join( os.path.dirname(__file__), 'docs', 'manuale_uso.pdf' )
QDesktopServices.openUrl( QUrl.fromLocalFile(path) )
@classmethod
def selezionaDB(self, parent=None):
path = AutomagicallyUpdater._getPathToDb()
dbpath = QFileDialog.getOpenFileName(parent, u"Seleziona il DB di lavoro da utilizzare", path if path != None else "", "Sqlite DB (*.sqlite *.db3);;Tutti i file (*)" )
if dbpath == "":
return
AutomagicallyUpdater._setPathToDb( dbpath )
return dbpath
def copiaWorkDB(self):
if self.selezionaDB( self ) == None:
return
return self.accept()
def copiaDemoDB(self):
path = AutomagicallyUpdater._getPathToDb()
# copia il database di test nella directory indicata dall'utente
dbpath = QFileDialog.getSaveFileName(self, u"Salva il DB dimostrativo", path if path != None else "", "Sqlite DB (*.sqlite *.db3);;Tutti i file (*)" )
if dbpath == "":
return
import os.path, zipfile
demoZip = os.path.join(os.path.dirname(__file__), "docs", "demo.zip")
try:
zf = zipfile.ZipFile( unicode(demoZip) )
if len( zf.namelist() ) <= 0:
raise zipfile.BadZipfile( "no files in the archive" )
outfile = open( unicode(dbpath), 'wb' )
try:
outfile.write( zf.read( zf.namelist()[0] ) )
finally:
outfile.close()
except (IOError, zipfile.BadZipfile), e:
QMessageBox.critical( self, u"Errore", u"Impossibile estrarre dall'archivio contenente il DB dimostrativo.\n\nError message: %s" % unicode(Porting.str(e), 'utf8') )
return self.reject()
AutomagicallyUpdater._setPathToDb( dbpath )
return self.accept()