2007-01-11 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/DisplayState.py (DisplayState.__init__): fix level of 'root' looger and WarnHandler * src/GrampsWidgets.py: ValidatableMaskedEntry.set_default_error_msg() method added svn: r7892
This commit is contained in:
parent
cd89a41bb4
commit
477fb9157d
@ -1,3 +1,9 @@
|
|||||||
|
2007-01-11 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||||
|
* src/DisplayState.py (DisplayState.__init__): fix level of 'root'
|
||||||
|
looger and WarnHandler
|
||||||
|
* src/GrampsWidgets.py: ValidatableMaskedEntry.set_default_error_msg()
|
||||||
|
method added
|
||||||
|
|
||||||
2007-01-10 Don Allingham <don@gramps-project.org>
|
2007-01-10 Don Allingham <don@gramps-project.org>
|
||||||
* src/GrampsWidgets.py: add support for an "empty" signal on
|
* src/GrampsWidgets.py: add support for an "empty" signal on
|
||||||
ValidatableMaskedEntry so that we can update the value when the
|
ValidatableMaskedEntry so that we can update the value when the
|
||||||
|
@ -273,8 +273,8 @@ class DisplayState(GrampsDb.GrampsDBCallback):
|
|||||||
formatter = logging.Formatter('%(levelname)s %(name)s: %(message)s')
|
formatter = logging.Formatter('%(levelname)s %(name)s: %(message)s')
|
||||||
self.rh = WarnHandler(capacity=400,button=warnbtn)
|
self.rh = WarnHandler(capacity=400,button=warnbtn)
|
||||||
self.rh.setFormatter(formatter)
|
self.rh.setFormatter(formatter)
|
||||||
|
self.rh.setLevel(logging.WARNING)
|
||||||
self.log = logging.getLogger()
|
self.log = logging.getLogger()
|
||||||
self.log.setLevel(logging.WARN)
|
|
||||||
self.log.addHandler(self.rh)
|
self.log.addHandler(self.rh)
|
||||||
# This call has been moved one level up,
|
# This call has been moved one level up,
|
||||||
# but this connection is still made!
|
# but this connection is still made!
|
||||||
|
@ -2064,6 +2064,7 @@ class ValidatableMaskedEntry(MaskedEntry):
|
|||||||
|
|
||||||
self._block_changed = False
|
self._block_changed = False
|
||||||
self._valid = True
|
self._valid = True
|
||||||
|
self._def_error_msg = None
|
||||||
self._fade = FadeOut(self, err_color)
|
self._fade = FadeOut(self, err_color)
|
||||||
self._fade.connect('color-changed', self._on_fadeout__color_changed)
|
self._fade.connect('color-changed', self._on_fadeout__color_changed)
|
||||||
|
|
||||||
@ -2111,6 +2112,22 @@ class ValidatableMaskedEntry(MaskedEntry):
|
|||||||
|
|
||||||
# Public API
|
# Public API
|
||||||
|
|
||||||
|
def set_default_error_msg(self, text):
|
||||||
|
"""
|
||||||
|
Set default message for validation error.
|
||||||
|
|
||||||
|
Default error message for an instance is useful when completion is
|
||||||
|
used, because this case custom validation is not called.
|
||||||
|
|
||||||
|
@param text: can contain one and only one '%s', where the actual value
|
||||||
|
of the Entry will be inserted.
|
||||||
|
@type text: str
|
||||||
|
"""
|
||||||
|
if not isinstance(text, str):
|
||||||
|
raise TypeError("text must be a string")
|
||||||
|
|
||||||
|
self._def_error_msg = text
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
"""
|
"""
|
||||||
@returns: True if the widget is in validated state
|
@returns: True if the widget is in validated state
|
||||||
@ -2151,8 +2168,8 @@ class ValidatableMaskedEntry(MaskedEntry):
|
|||||||
raise ValidationError()
|
raise ValidationError()
|
||||||
else:
|
else:
|
||||||
if not self.is_empty():
|
if not self.is_empty():
|
||||||
# this signal calls the on_widgetname__validate method
|
# this signal calls the custom validation method
|
||||||
# of the view class and gets the exception (if any).
|
# of the instance and gets the exception (if any).
|
||||||
error = self.emit("validate", text)
|
error = self.emit("validate", text)
|
||||||
if error:
|
if error:
|
||||||
raise error
|
raise error
|
||||||
@ -2188,11 +2205,28 @@ class ValidatableMaskedEntry(MaskedEntry):
|
|||||||
|
|
||||||
self._set_valid_state(False)
|
self._set_valid_state(False)
|
||||||
|
|
||||||
# If there is no error text, set a generic one so the error icon
|
generic_text = _("'%s' is not a valid value "
|
||||||
# still have a tooltip
|
"for this field") % self.get_text()
|
||||||
|
|
||||||
|
# If there is no error text, let's try with the default or
|
||||||
|
# fall back to a generic one
|
||||||
if not text:
|
if not text:
|
||||||
text = _("'%s' is not a valid value "
|
text = self._def_error_msg
|
||||||
"for this field") % self.get_text()
|
if not text:
|
||||||
|
text = generic_text
|
||||||
|
|
||||||
|
try:
|
||||||
|
text.index('%s')
|
||||||
|
text = text % self.get_text()
|
||||||
|
except TypeError:
|
||||||
|
# if text contains '%s' more than once
|
||||||
|
log.error('There must be only one instance of "%s"'
|
||||||
|
' in validation error message')
|
||||||
|
# fall back to a generic one so the error icon still have a tooltip
|
||||||
|
text = generic_text
|
||||||
|
except ValueError:
|
||||||
|
# if text does not contain '%s'
|
||||||
|
pass
|
||||||
|
|
||||||
self.set_tooltip(text)
|
self.set_tooltip(text)
|
||||||
|
|
||||||
@ -2281,7 +2315,7 @@ def main(args):
|
|||||||
def on_validate(widget, text):
|
def on_validate(widget, text):
|
||||||
myDate = parser.parse(text)
|
myDate = parser.parse(text)
|
||||||
if not myDate.is_regular():
|
if not myDate.is_regular():
|
||||||
return ValidationError("This is not a proper date value")
|
return ValidationError("'%s' is not a valid date value")
|
||||||
|
|
||||||
win = gtk.Window()
|
win = gtk.Window()
|
||||||
win.set_title('ValidatableMaskedEntry test window')
|
win.set_title('ValidatableMaskedEntry test window')
|
||||||
@ -2298,6 +2332,8 @@ def main(args):
|
|||||||
|
|
||||||
widget1 = ValidatableMaskedEntry(str)
|
widget1 = ValidatableMaskedEntry(str)
|
||||||
widget1.set_completion_mode(inline=True, popup=False)
|
widget1.set_completion_mode(inline=True, popup=False)
|
||||||
|
#widget1.set_default_error_msg("'%s' is not a default Event")
|
||||||
|
widget1.set_default_error_msg(widget1)
|
||||||
widget1.prefill(('Birth', 'Death', 'Conseption'))
|
widget1.prefill(('Birth', 'Death', 'Conseption'))
|
||||||
#widget1.set_exact_completion(True)
|
#widget1.set_exact_completion(True)
|
||||||
vbox.pack_start(widget1, fill=False)
|
vbox.pack_start(widget1, fill=False)
|
||||||
@ -2305,7 +2341,8 @@ def main(args):
|
|||||||
label = gtk.Label('Mandatory masked entry validated against user function:')
|
label = gtk.Label('Mandatory masked entry validated against user function:')
|
||||||
vbox.pack_start(label)
|
vbox.pack_start(label)
|
||||||
|
|
||||||
widget2 = ValidatableMaskedEntry(str, "#e0e0e0", error_icon=None)
|
#widget2 = ValidatableMaskedEntry(str, "#e0e0e0", error_icon=None)
|
||||||
|
widget2 = ValidatableMaskedEntry()
|
||||||
widget2.set_mask('00/00/0000')
|
widget2.set_mask('00/00/0000')
|
||||||
widget2.connect('validate', on_validate)
|
widget2.connect('validate', on_validate)
|
||||||
widget2.mandatory = True
|
widget2.mandatory = True
|
||||||
@ -2316,4 +2353,6 @@ def main(args):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
|
# fall back to root logger for testing
|
||||||
|
log = logging
|
||||||
sys.exit(main(sys.argv))
|
sys.exit(main(sys.argv))
|
||||||
|
Loading…
Reference in New Issue
Block a user