Package Camelot :: Package camelot :: Package view :: Package wizard :: Package pages :: Module select |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.wizard.pages.select

     1  #  ============================================================================

     2  #

     3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved.

     4  #  www.conceptive.be / project-camelot@conceptive.be

     5  #

     6  #  This file is part of the Camelot Library.

     7  #

     8  #  This file may be used under the terms of the GNU General Public

     9  #  License version 2.0 as published by the Free Software Foundation

    10  #  and appearing in the file LICENSE.GPL included in the packaging of

    11  #  this file.  Please review the following information to ensure GNU

    12  #  General Public Licensing requirements will be met:

    13  #  http://www.trolltech.com/products/qt/opensource.html

    14  #

    15  #  If you are unsure which license is appropriate for your use, please

    16  #  review the following information:

    17  #  http://www.trolltech.com/products/qt/licensing.html or contact

    18  #  project-camelot@conceptive.be.

    19  #

    20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE

    21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

    22  #

    23  #  For use of this library in commercial applications, please contact

    24  #  project-camelot@conceptive.be

    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          # file path is a mandatory field

    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

    77 -    def setpath(self):
    78          settings = QtCore.QSettings()
    79          dir = settings.value('datasource').toString()
    80          #if not os.path.exists(dir)

    81          #    dir = QDesktopServices.displayName(QDesktopServices.DocumentsLocation)

    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