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

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

      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, QtCore
     29
     30  from camelot.core.utils import ugettext as _
     31  from camelot.view.art import Icon
     32  from camelot.view.model_thread import post
     33
     34
     35 -class FormPage(QtGui.QWizardPage):
     36      """FormPage is a generic wizard page that displays a form for an object
     37      in a wizard page, subclass this class to use it.  The class attribute 'Data'
     38      should be the class of the object to be used to store the form information.
     39
     40      To access the data stored by the wizard form into a data object, use its
     41      get_data method.
     42
     43      The 'Next' button will only be activated when the form is complete.
     44      """
     45
     46      icon = Icon('tango/32x32/mimetypes/x-office-spreadsheet.png')
     47      title = None
     48      sub_title = None
     49      Data = None
     50      Admin = None
     51
     52 -    def __init__(self, parent=None):
     53
     54          from camelot.view.controls.formview import FormWidget
     55          from camelot.view.proxy.collection_proxy import CollectionProxy
     56
     57          super(FormPage, self).__init__(parent)
     58          assert self.Data
     59          self.setTitle(unicode(self.get_title()))
     60          self.setSubTitle(unicode(self.get_sub_title()))
     61          self.setPixmap(QtGui.QWizard.LogoPixmap, self.get_icon().getQPixmap())
     62          self._data = self.Data()
     63          self._complete = False
     64
     65          admin = self.get_admin()
     66          self._model = CollectionProxy(admin, lambda:[self._data], admin.get_fields)
     67          validator = self._model.get_validator()
     68
     69          layout = QtGui.QVBoxLayout()
     70          form = FormWidget(admin)
     71          self.connect(validator, validator.validity_changed_signal, self._validity_changed)
     72          form.set_model(self._model)
     73          layout.addWidget(form)
     74          self.setLayout(layout)
     75
     76 -    def initializePage(self):
     77          # do inital validation, so the validity changed signal is valid
     78          self._complete = False
     79          self.emit(QtCore.SIGNAL('completeChanged()'))
     80          self._validity_changed()
     81
     82 -    def _validity_changed(self):
     83
     84          def is_valid():
     85              return self._model.get_validator().isValid(0)
     86
     87          post(is_valid, self._change_complete)
     88
     89 -    def _change_complete(self, complete):
     90          self._complete = complete
     91          self.emit(QtCore.SIGNAL('completeChanged ()'))
     92
     93 -    def isComplete(self):
     94          return self._complete
     95
     96 -    def get_admin(self):
     97          from camelot.view.application_admin import get_application_admin
     98          app_admin = get_application_admin()
     99          if self.Admin:
    100              return self.Admin(app_admin, self.Data)
    101          return app_admin.get_entity_admin(self.Data)
    102
    103 -    def get_title(self):
    104          return self.title or self.get_admin().get_verbose_name()
    105
    106 -    def get_sub_title(self):
    107          return self.sub_title or _('Please complete')
    108
    109 -    def get_icon(self):
    110          return self.icon
    111
    112 -    def get_data(self):
    113          return self._data
    114