root/tags/release-0.6.2/lib/errortype.py

Revision 1, 3.5 kB (checked in by mjoc, 2 years ago)

Initial import.

Line 
1 #
2 # OpenDict
3 # Copyright (c) 2005 Martynas Jocius <mjoc@akl.lt>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your opinion) any later version.
9 #
10 # This program is distributed in the hope that will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more detals.
14 #
15 # You shoud have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 # 02111-1307 USA
19 #
20
21 """
22 Error types
23 """
24
25 import wx
26 _ = wx.GetTranslation
27
28 class ErrorType:
29     """Error type interface"""
30
31     shortMessage = None
32     longMessage = None
33
34     def getShortMessage(self):
35         """Return short message"""
36
37         return self.shortMessage
38
39
40     def getLongMessage(self):
41         """Return long message"""
42
43         return self.longMessage
44
45
46     def getMessage(self):
47         """Alternative for getShortMessage()"""
48
49         return self.getShortMessage()
50    
51
52
53 class ErrorOk(ErrorType):
54     """No error class"""
55
56     shortMessage = _("Success")
57     longMessage = _("Search successfully finished.")
58
59
60
61 class ErrorNotFound(ErrorType):
62     """Not found error class"""
63
64     shortMessage = _("Not found")
65     longMessage = _("Word or phrase not found. Try less letters or " \
66                   "fewer words.")
67
68
69
70 class ErrorInternal(ErrorType):
71     """Internal error class"""
72
73     shortMessage = _("Internal error")
74     longMessage = _("Internal error occured. Please send bug report to " \
75                   "the dictionary's of current use authors. Thank you.")
76
77
78
79 class ErrorNotConnected(ErrorType):
80     """Not connected error class"""
81
82     shortMessage = _("Not connected")
83     longMessage = _("This dictionary uses Internet connection " \
84                   "to translate words. Please connect to the Internet and " \
85                   "try again.")
86
87
88
89 class ErrorConnectionTimeout(ErrorType):
90     """Not connected error class"""
91
92     shortMessage = _("Connection Error")
93     longMessage = _("Could not connect to host. " \
94                   "Check your Internet connection or try later.")
95
96
97
98 class ErrorInvalidEncoding(ErrorType):
99     """Invalid encoding error class"""
100
101     shortMessage = _("Invalid encoding")
102     longMessage = _("Selected encoding is not correct for " \
103                   "this dictionary. Please select another from Edit > " \
104                   "Character Encoding menu")
105
106
107
108 class ErrorOpenDict(ErrorType):
109     """OpenDict bug class"""
110
111     shortMessage = _("OpenDict Bug")
112     longMessage = _("Internal error occured. Please send bug report to " \
113                   "OpenDict authors to prevent this error in the future. " \
114                   "Thank you!")
115
116
117 class ErrorCustom(ErrorType):
118     """Custom error"""
119
120     shortMessage = _("Unknown Error")
121     longMessage = _("Unknown error occured.")
122
123     def setMessage(self, msg):
124         """Set custom message"""
125
126         self.shortMessage = msg
127
128
129     def setLongMessage(self, msg):
130         """Set custom descriptive message"""
131
132         self.longMessage = msg
133
134
135 # Error constant instances
136 OK = ErrorOk()
137 NOT_FOUND = ErrorNotFound()
138 INTERNAL_ERROR = ErrorInternal()
139 NOT_CONNECTED = ErrorNotConnected()
140 CONNECTION_ERROR = ErrorConnectionTimeout()
141 CONNECTION_TIMEOUT = CONNECTION_ERROR
142 INVALID_ENCODING = ErrorInvalidEncoding()
143 OPENDICT_BUG = ErrorOpenDict()
144 CUSTOM_ERROR = ErrorCustom()
Note: See TracBrowser for help on using the browser.