editdate: better pylint score
This commit is contained in:
@@ -44,7 +44,6 @@ unambiguously built using UI controls such as menus and spin buttons.
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import logging
|
import logging
|
||||||
LOG = logging.getLogger(".EditDate")
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@@ -59,7 +58,6 @@ from gi.repository import Gtk
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.sgettext
|
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
from gramps.gen.lib.date import Date, DateError, calendar_has_fixed_newyear
|
from gramps.gen.lib.date import Date, DateError, calendar_has_fixed_newyear
|
||||||
from gramps.gen.datehandler import displayer
|
from gramps.gen.datehandler import displayer
|
||||||
@@ -68,24 +66,26 @@ from ..display import display_help
|
|||||||
from ..managedwindow import ManagedWindow
|
from ..managedwindow import ManagedWindow
|
||||||
from ..glade import Glade
|
from ..glade import Glade
|
||||||
|
|
||||||
|
LOG = logging.getLogger(".EditDate")
|
||||||
|
_ = glocale.translation.sgettext
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Constants
|
# Constants
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
MOD_TEXT = (
|
MOD_TEXT = (
|
||||||
(Date.MOD_NONE , _('Regular')),
|
(Date.MOD_NONE, _('Regular')),
|
||||||
(Date.MOD_BEFORE , _('Before')),
|
(Date.MOD_BEFORE, _('Before')),
|
||||||
(Date.MOD_AFTER , _('After')),
|
(Date.MOD_AFTER, _('After')),
|
||||||
(Date.MOD_ABOUT , _('About')),
|
(Date.MOD_ABOUT, _('About')),
|
||||||
(Date.MOD_RANGE , _('Range')),
|
(Date.MOD_RANGE, _('Range')),
|
||||||
(Date.MOD_SPAN , _('Span')),
|
(Date.MOD_SPAN, _('Span')),
|
||||||
(Date.MOD_TEXTONLY , _('Text only')) )
|
(Date.MOD_TEXTONLY, _('Text only')))
|
||||||
|
|
||||||
QUAL_TEXT = (
|
QUAL_TEXT = (
|
||||||
(Date.QUAL_NONE, _('Regular')),
|
(Date.QUAL_NONE, _('Regular')),
|
||||||
(Date.QUAL_ESTIMATED, _('Estimated')),
|
(Date.QUAL_ESTIMATED, _('Estimated')),
|
||||||
(Date.QUAL_CALCULATED, _('Calculated')) )
|
(Date.QUAL_CALCULATED, _('Calculated')))
|
||||||
|
|
||||||
CAL_TO_MONTHS_NAMES = {
|
CAL_TO_MONTHS_NAMES = {
|
||||||
Date.CAL_GREGORIAN : displayer.short_months,
|
Date.CAL_GREGORIAN : displayer.short_months,
|
||||||
@@ -94,7 +94,7 @@ CAL_TO_MONTHS_NAMES = {
|
|||||||
Date.CAL_FRENCH : displayer.french,
|
Date.CAL_FRENCH : displayer.french,
|
||||||
Date.CAL_PERSIAN : displayer.persian,
|
Date.CAL_PERSIAN : displayer.persian,
|
||||||
Date.CAL_ISLAMIC : displayer.islamic,
|
Date.CAL_ISLAMIC : displayer.islamic,
|
||||||
Date.CAL_SWEDISH : displayer.swedish }
|
Date.CAL_SWEDISH : displayer.swedish}
|
||||||
|
|
||||||
WIKI_HELP_PAGE = URL_MANUAL_SECT1
|
WIKI_HELP_PAGE = URL_MANUAL_SECT1
|
||||||
WIKI_HELP_SEC = _('Editing_dates', 'manual')
|
WIKI_HELP_SEC = _('Editing_dates', 'manual')
|
||||||
@@ -209,13 +209,14 @@ class EditDate(ManagedWindow):
|
|||||||
|
|
||||||
self.validated_date = self.return_date = None
|
self.validated_date = self.return_date = None
|
||||||
|
|
||||||
for o in self.top.get_objects():
|
for obj in self.top.get_objects():
|
||||||
if o != self.ok_button:
|
if obj != self.ok_button:
|
||||||
for signal in ['changed', 'value-changed']:
|
for signal in ['changed', 'value-changed']:
|
||||||
try:
|
try:
|
||||||
o.connect_after(signal, self.revalidate)
|
obj.connect_after(signal, self.revalidate)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass # some of them don't support the signal, ignore them...
|
# some of them don't support the signal, ignore them...
|
||||||
|
pass
|
||||||
self.revalidate()
|
self.revalidate()
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
@@ -223,8 +224,7 @@ class EditDate(ManagedWindow):
|
|||||||
response = self.window.run()
|
response = self.window.run()
|
||||||
LOG.debug("response: {0}".format(response))
|
LOG.debug("response: {0}".format(response))
|
||||||
if response == Gtk.ResponseType.HELP:
|
if response == Gtk.ResponseType.HELP:
|
||||||
display_help(webpage=WIKI_HELP_PAGE,
|
display_help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC)
|
||||||
section=WIKI_HELP_SEC)
|
|
||||||
elif response == Gtk.ResponseType.DELETE_EVENT:
|
elif response == Gtk.ResponseType.DELETE_EVENT:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -240,7 +240,7 @@ class EditDate(ManagedWindow):
|
|||||||
self.close()
|
self.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
def revalidate(self, obj = None):
|
def revalidate(self, obj=None):
|
||||||
"""
|
"""
|
||||||
If anything changed, revalidate the date and
|
If anything changed, revalidate the date and
|
||||||
enable/disable the "OK" button based on the result.
|
enable/disable the "OK" button based on the result.
|
||||||
@@ -249,31 +249,31 @@ class EditDate(ManagedWindow):
|
|||||||
the_text, the_newyear) = self.build_date_from_ui()
|
the_text, the_newyear) = self.build_date_from_ui()
|
||||||
LOG.debug("revalidate: {0} changed, value: {1}".format(
|
LOG.debug("revalidate: {0} changed, value: {1}".format(
|
||||||
obj, the_value))
|
obj, the_value))
|
||||||
d = Date(self.date)
|
dat = Date(self.date)
|
||||||
if not self.ok_button.get_sensitive():
|
if not self.ok_button.get_sensitive():
|
||||||
self.statusbar.pop(1)
|
self.statusbar.pop(1)
|
||||||
try:
|
try:
|
||||||
d.set(
|
dat.set(quality=the_quality,
|
||||||
quality=the_quality,
|
|
||||||
modifier=the_modifier,
|
modifier=the_modifier,
|
||||||
calendar=the_calendar,
|
calendar=the_calendar,
|
||||||
value=the_value,
|
value=the_value,
|
||||||
text=the_text,
|
text=the_text,
|
||||||
newyear=the_newyear)
|
newyear=the_newyear)
|
||||||
# didn't throw yet?
|
# didn't throw yet?
|
||||||
self.validated_date = d
|
self.validated_date = dat
|
||||||
LOG.debug("validated_date set to: {0}".format(d.__dict__))
|
LOG.debug("validated_date set to: {0}".format(dat.__dict__))
|
||||||
self.ok_button.set_sensitive(1)
|
self.ok_button.set_sensitive(1)
|
||||||
self.calendar_box.set_sensitive(1)
|
self.calendar_box.set_sensitive(1)
|
||||||
return True
|
return True
|
||||||
except DateError as e:
|
except DateError as dummy_err:
|
||||||
self.ok_button.set_sensitive(0)
|
self.ok_button.set_sensitive(0)
|
||||||
self.calendar_box.set_sensitive(0)
|
self.calendar_box.set_sensitive(0)
|
||||||
|
curmode = MOD_TEXT[self.type_box.get_active()][1]
|
||||||
|
txtmode = MOD_TEXT[-1][1]
|
||||||
self.statusbar.push(1,
|
self.statusbar.push(1,
|
||||||
_("Correct the date or switch from `{cur_mode}' to `{text_mode}'"
|
_("Correct the date or switch from `{cur_mode}'"
|
||||||
).format(
|
" to `{text_mode}'").format(
|
||||||
cur_mode = MOD_TEXT[self.type_box.get_active()][1],
|
cur_mode=curmode, text_mode=txtmode))
|
||||||
text_mode = MOD_TEXT[-1][1]))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def build_menu_names(self, obj):
|
def build_menu_names(self, obj):
|
||||||
@@ -384,11 +384,10 @@ class EditDate(ManagedWindow):
|
|||||||
|
|
||||||
self.align_newyear_ui_with_calendar(new_cal)
|
self.align_newyear_ui_with_calendar(new_cal)
|
||||||
|
|
||||||
(the_quality, the_modifier, the_calendar,
|
(the_quality, the_modifier, dummy_the_calendar,
|
||||||
the_value, the_text, the_newyear) = self.build_date_from_ui()
|
the_value, the_text, the_newyear) = self.build_date_from_ui()
|
||||||
try:
|
try:
|
||||||
self.date.set(
|
self.date.set(quality=the_quality,
|
||||||
quality=the_quality,
|
|
||||||
modifier=the_modifier,
|
modifier=the_modifier,
|
||||||
calendar=old_cal,
|
calendar=old_cal,
|
||||||
value=the_value,
|
value=the_value,
|
||||||
|
Reference in New Issue
Block a user