Make case differences between author and author sort show red, while preserving the behavior of automatically correcting the case if the author changes.

This commit is contained in:
Charles Haley 2015-01-05 17:25:26 +01:00
parent 01511731e3
commit 4cfa6fdf1f

View File

@ -461,6 +461,7 @@ class AuthorSortEdit(EnLineEdit, ToMetadataMixin):
a_to_as.triggered.connect(self.author_to_sort) a_to_as.triggered.connect(self.author_to_sort)
as_to_a.triggered.connect(self.sort_to_author) as_to_a.triggered.connect(self.sort_to_author)
self.original_val = '' self.original_val = ''
self.first_time = True
self.update_state() self.update_state()
@dynamic_property @dynamic_property
@ -480,8 +481,9 @@ class AuthorSortEdit(EnLineEdit, ToMetadataMixin):
def update_state_and_val(self): def update_state_and_val(self):
# Handle case change if the authors box changed # Handle case change if the authors box changed
aus = authors_to_sort_string(self.authors_edit.current_val) aus = authors_to_sort_string(self.authors_edit.current_val)
if strcmp(aus, self.current_val) == 0: if not self.first_time and strcmp(aus, self.current_val) == 0:
self.current_val = aus self.current_val = aus
self.first_time = False
self.update_state() self.update_state()
def update_state(self, *args): def update_state(self, *args):
@ -489,7 +491,7 @@ class AuthorSortEdit(EnLineEdit, ToMetadataMixin):
au = re.sub(r'\s+et al\.$', '', au) au = re.sub(r'\s+et al\.$', '', au)
au = self.db.author_sort_from_authors(string_to_authors(au)) au = self.db.author_sort_from_authors(string_to_authors(au))
normal = strcmp(au, self.current_val) == 0 normal = au == self.current_val
col = OK_COLOR if normal else ERR_COLOR col = OK_COLOR if normal else ERR_COLOR
self.setStyleSheet(INDICATOR_SHEET % col) self.setStyleSheet(INDICATOR_SHEET % col)
tt = self.tooltips[0 if normal else 1] tt = self.tooltips[0 if normal else 1]
@ -536,6 +538,7 @@ class AuthorSortEdit(EnLineEdit, ToMetadataMixin):
aus = self.current_val aus = self.current_val
if aus != self.original_val or self.authors_edit.original_val != self.authors_edit.current_val: if aus != self.original_val or self.authors_edit.original_val != self.authors_edit.current_val:
db.set_author_sort(id_, aus, notify=False, commit=False) db.set_author_sort(id_, aus, notify=False, commit=False)
self.first_time = True
return True return True
def break_cycles(self): def break_cycles(self):