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 from PyQt4 import QtGui
29 from PyQt4 import QtCore
30 from PyQt4.QtGui import QDesktopServices
31
32 from camelot.view.art import Icon
33 from camelot.core.utils import ugettext_lazy as _
34 from camelot.core.utils import ugettext
35
36
37 -class SelectFilePage(QtGui.QWizardPage):
38 """SelectFilePage is the file selection page of an import wizard"""
39
40 title = _('Import data from a file')
41 sub_title = _(
42 "To import data, click 'Browse' to "
43 "select a file then click 'Import'."
44 )
45 icon = Icon('tango/32x32/mimetypes/x-office-spreadsheet.png')
46 caption = _('Select file')
47 save = False
48
49 - def __init__(self, parent=None):
50 super(SelectFilePage, self).__init__(parent)
51 self.setTitle( unicode(self.title) )
52 self.setSubTitle( unicode(self.sub_title) )
53 self.setPixmap(QtGui.QWizard.LogoPixmap, self.icon.getQPixmap())
54
55 label = QtGui.QLabel(ugettext('Select file:'))
56 self.filelineedit = QtGui.QLineEdit()
57 label.setBuddy(self.filelineedit)
58 browsebutton = QtGui.QPushButton(ugettext('Browse...'))
59
60
61 self.registerField('datasource*', self.filelineedit)
62
63 layout = QtGui.QVBoxLayout()
64 layout.addWidget(label)
65 hlayout = QtGui.QHBoxLayout()
66 hlayout.addWidget(self.filelineedit)
67 hlayout.addWidget(browsebutton)
68 layout.addLayout(hlayout)
69 self.setLayout(layout)
70
71 self.connect(
72 browsebutton,
73 QtCore.SIGNAL('clicked()'),
74 self.setpath
75 )
76
78 settings = QtCore.QSettings()
79 dir = settings.value('datasource').toString()
80
81
82 if self.save:
83 path = QtGui.QFileDialog.getSaveFileName(self, unicode(self.caption), dir)
84 else:
85 path = QtGui.QFileDialog.getOpenFileName(self, unicode(self.caption), dir)
86 if path:
87 self.filelineedit.setText(QtCore.QDir.toNativeSeparators(path))
88 settings.setValue('datasource', QtCore.QVariant(path))
89