Date editor crashes on invalid date
Back-port from gramps40 the following commits as a single change: [ca4eab8
] [b4a5df2
] [531e662
] [83c6788
] [1d654a2
]
This commit is contained in:
@@ -47,7 +47,7 @@ unambiguously built using UI controls such as menus and spin buttons.
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import logging
|
import logging
|
||||||
__LOG = logging.getLogger(".DateEdit")
|
LOG = logging.getLogger(".DateEdit")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@@ -62,7 +62,7 @@ import gtk
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gen.ggettext import sgettext as _
|
from gen.ggettext import sgettext as _
|
||||||
from gen.lib.date import Date, NextYear
|
from gen.lib.date import Date, DateError, NextYear
|
||||||
import DateHandler
|
import DateHandler
|
||||||
import const
|
import const
|
||||||
import GrampsDisplay
|
import GrampsDisplay
|
||||||
@@ -201,6 +201,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
self.top.get_object('title'),
|
self.top.get_object('title'),
|
||||||
_('Date selection'))
|
_('Date selection'))
|
||||||
|
|
||||||
|
self.ok_button = self.top.get_object('ok_button')
|
||||||
self.calendar_box = self.top.get_object('calendar_box')
|
self.calendar_box = self.top.get_object('calendar_box')
|
||||||
for name in Date.ui_calendar_names:
|
for name in Date.ui_calendar_names:
|
||||||
self.calendar_box.get_model().append([name])
|
self.calendar_box.get_model().append([name])
|
||||||
@@ -275,6 +276,13 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
|
|
||||||
self.return_date = None
|
self.return_date = None
|
||||||
|
|
||||||
|
for o in self.top.get_objects():
|
||||||
|
try:
|
||||||
|
if o != self.ok_button:
|
||||||
|
o.connect_after('changed', self.revalidate)
|
||||||
|
except TypeError:
|
||||||
|
pass # some of them don't support the signal, ignore them...
|
||||||
|
self.revalidate()
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -286,19 +294,43 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
(the_quality, the_modifier, the_calendar,
|
# if the user pressed OK/enter while inside an edit field,
|
||||||
the_value, the_text, the_newyear) = self.build_date_from_ui()
|
# e.g., the year,
|
||||||
self.return_date = Date(self.date)
|
# build_date_from_ui won't pick up the new text in the
|
||||||
self.return_date.set(
|
# run of revalidate that allowed the OK!
|
||||||
quality=the_quality,
|
if not self.revalidate():
|
||||||
modifier=the_modifier,
|
continue
|
||||||
calendar=the_calendar,
|
self.return_date = Date()
|
||||||
value=the_value,
|
self.return_date.copy(self.date)
|
||||||
text=the_text,
|
|
||||||
newyear=the_newyear)
|
|
||||||
self.close()
|
self.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def revalidate(self, obj = None):
|
||||||
|
"""
|
||||||
|
If anything changed, revalidate the date and
|
||||||
|
enable/disable the "OK" button based on the result.
|
||||||
|
"""
|
||||||
|
(the_quality, the_modifier, the_calendar, the_value,
|
||||||
|
the_text, the_newyear) = self.build_date_from_ui()
|
||||||
|
LOG.debug("revalidate: {0} changed, value: {1}".format(
|
||||||
|
obj, the_value))
|
||||||
|
d = Date(self.date)
|
||||||
|
try:
|
||||||
|
d.set(
|
||||||
|
quality=the_quality,
|
||||||
|
modifier=the_modifier,
|
||||||
|
calendar=the_calendar,
|
||||||
|
value=the_value,
|
||||||
|
text=the_text,
|
||||||
|
newyear=the_newyear)
|
||||||
|
self.date.copy(d)
|
||||||
|
LOG.debug("return_date set to: {0}".format(d.dateval))
|
||||||
|
self.ok_button.set_sensitive(1)
|
||||||
|
return True
|
||||||
|
except DateError as e:
|
||||||
|
self.ok_button.set_sensitive(0)
|
||||||
|
return False
|
||||||
|
|
||||||
def build_menu_names(self, obj):
|
def build_menu_names(self, obj):
|
||||||
"""
|
"""
|
||||||
Define the menu entry for the ManagedWindows
|
Define the menu entry for the ManagedWindows
|
||||||
|
@@ -559,7 +559,7 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="button176">
|
<object class="GtkButton" id="ok_button">
|
||||||
<property name="label">gtk-ok</property>
|
<property name="label">gtk-ok</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
@@ -585,7 +585,7 @@
|
|||||||
<action-widgets>
|
<action-widgets>
|
||||||
<action-widget response="-11">button174</action-widget>
|
<action-widget response="-11">button174</action-widget>
|
||||||
<action-widget response="-6">button175</action-widget>
|
<action-widget response="-6">button175</action-widget>
|
||||||
<action-widget response="-5">button176</action-widget>
|
<action-widget response="-5">ok_button</action-widget>
|
||||||
</action-widgets>
|
</action-widgets>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkListStore" id="calendar_model">
|
<object class="GtkListStore" id="calendar_model">
|
||||||
|
Reference in New Issue
Block a user