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 00028 ## @brief The Notifications module handles warning and error notifications that 00029 # some components might need to throw. 00030 # 00031 # The mechanism allows KTiny components to be loosely coupled with whatever 00032 # the application programmer wants to do in these cases. 00033 # The error and warning handlers should be registered: 00034 # 00035 #\code 00036 # def error(title, message, detail): 00037 # print "ERROR: Title: %s, Message: %s, Detail: %s" % (title, message, detail) 00038 # def warning(title, message): 00039 # print "WARNING: Title: %s, Message: %s, Detail: %s" % (title, message, detail) 00040 # 00041 # Notifications.errorHandler = error 00042 # Notifications.warningHandler = warning 00043 #\endcode 00044 # 00045 # This will make that any component that needs to notify an error using 00046 # Notifications.notifyError(), the error() function will be called. The same 00047 # for warnings. 00048 # 00049 # If no handler is specified the notification will be ignored. The KTiny 00050 # application uses a special form for errors and a message box for warnings. 00051 00052 errorHandler = None 00053 warningHandler = None 00054 concurrencyErrorHandler = None 00055 lostConnectionErrorHandler = None 00056 00057 ## @brief Calls the function that has been registered to handle errors. 00058 def notifyError(title, message, detail): 00059 if errorHandler: 00060 errorHandler(title, message, detail) 00061 00062 ## @brief Calls the function that has been registered to handle warnings. 00063 def notifyWarning(title, message): 00064 if warningHandler: 00065 warningHandler(title, message) 00066 00067 ## @brief Calls the function that has been registered to handle concurrency errors. 00068 def notifyConcurrencyError(model, id, context): 00069 if concurrencyErrorHandler: 00070 return concurrencyErrorHandler(model, id, context) 00071 00072 ## @brief Calls the function that has been registered to handle lost connection errors. 00073 def notifyLostConnection(count): 00074 if lostConnectionErrorHandler: 00075 return lostConnectionErrorHandler(count)