00001 ############################################################################## 00002 # 00003 # Copyright (c) 2007-2008 Albert Cervera i Areny <albert@nan-tic.com> 00004 # 00005 # WARNING: This program as such is intended to be used by professional 00006 # programmers who take the whole responsability of assessing all potential 00007 # consequences resulting from its eventual inadequacies and bugs 00008 # End users who are looking for a ready-to-use solution with commercial 00009 # garantees and support are strongly adviced to contract a Free Software 00010 # Service Company 00011 # 00012 # This program is Free Software; you can redistribute it and/or 00013 # modify it under the terms of the GNU General Public License 00014 # as published by the Free Software Foundation; either version 2 00015 # of the License, or (at your option) any later version. 00016 # 00017 # This program is distributed in the hope that it will be useful, 00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 # GNU General Public License for more details. 00021 # 00022 # You should have received a copy of the GNU General Public License 00023 # along with this program; if not, write to the Free Software 00024 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00025 # 00026 ############################################################################## 00027 from PyQt4.QtGui import * 00028 00029 ## @brief The AbstractView class describes the interface Views must implement 00030 class AbstractView(QWidget): 00031 def __init__(self, parent): 00032 QWidget.__init__( self, parent ) 00033 # TODO: By now, needs the self.widget 00034 self.widget = None 00035 # The 'id' corresponds to the view id in the database. Not directly 00036 # used by the view itself might be filled and used by other classes 00037 # such as Screen, which will use this id for storing/loading settings 00038 self.id = False 00039 self._onWrite = '' 00040 00041 ## @brief This function should return the type of view the class handles. Such as 'tree' or 'from'. 00042 def viewType(self): 00043 return None 00044 00045 ## @brief This function should store the information in the model 00046 # The model used should be the one given by display() 00047 # which will always have been called before store(). 00048 def store(self): 00049 pass 00050 00051 ## @brief This function should display the information of the model or models 00052 # currentRecord points to the record (object Record) that is currently selected 00053 # models points to the model list (object RecordGroup) 00054 # Example: forms only use the currentModel, while tree & charts use models 00055 def display(self, currentRecord, models): 00056 pass 00057 00058 ## @brief Not used in the TreeView, used in the FormView to 00059 # set all widgets to the state of 'valid' 00060 def reset(self): 00061 pass 00062 00063 ## @brief Should return a list with the currently selected 00064 # records in the view. If the view is a form, for example, 00065 # the current id is returned. If it's a tree with 00066 # several items selected, returns all of them. 00067 def selectedRecords(self): 00068 return [] 00069 00070 ## @brief Selects the current record 00071 def setSelected(self, record): 00072 pass 00073 00074 ## @brief This function should return False if the view modifies data 00075 # or True if it doesn't 00076 def isReadOnly(self): 00077 return True 00078 00079 ## @brief This function should be implemented if the view can be 00080 # configured to be read-only or read-write. 00081 def setReadOnly(self, value): 00082 return 00083 00084 ## @brief Override this function in your view if you wish to store 00085 # some settings per user and view. The function should return 00086 # a python string with all the information which should be 00087 # parseable afterwords by setViewSettings(). 00088 def viewSettings(self): 00089 return '' 00090 00091 ## @brief Override this function in your view if you wish to restore 00092 # a previous configuration. The function will be called when 00093 # necessary. The string given in 'settings' will be one 00094 # previously returned by viewSettings(). 00095 def setViewSettings(self, settings): 00096 pass 00097 00098 ## @brief Should return True if the view is capable of showing multiple records 00099 # or False if it can only show one. 00100 # 00101 # For example, tree will return True whereas 'form' will return False. 00102 # The default implementation returns True. 00103 def showsMultipleRecords(self): 00104 return True 00105 00106 ## @brief Start editing current record. 00107 # 00108 # Some views (such as TreeView) need a way of being told to start edit mode. 00109 # Such is the case when a new record is created as we want TreeView to start 00110 # editing the newly created record. Other views such as form can simply ignore 00111 # this call. 00112 def startEditing(self): 00113 return 00114 00115 ## @brief Returns True if new records should be added at the top of the list 00116 # or False if they should be added at the bottom (the default). 00117 def addOnTop(self): 00118 return False 00119 00120 ## @brief Returns the on_write function. 00121 # 00122 # This server side function can be configured in the view so it's called each 00123 # time a record is created or written. 00124 def onWriteFunction(self): 00125 return self._onWrite 00126 00127 ## @brief Establishes the name of the on_write function. 00128 # 00129 # By default it's the empty string, so no function will be called on the server. 00130 def setOnWriteFunction(self, value): 00131 self._onWrite = value 00132