Read first and last name from entries

This commit is contained in:
Thaddäus Tintenfisch 2014-03-30 21:26:33 +02:00
parent 323435efaa
commit 965e8ad064
1 changed files with 15 additions and 7 deletions

View File

@ -231,17 +231,12 @@ class MugshotWindow(Window):
name, office, office_phone, home_phone = details.split(',', 3)
break
# Expand the user's fullname into first, last, and initials.
# Expand the user's fullname into first and last.
try:
first_name, last_name = name.split(' ', 1)
self.initials_suggestion = first_name[0] + last_name[0]
except:
first_name = name
last_name = ''
if first_name:
self.initials_suggestion = first_name[0]
else:
self.initials_suggestion = ''
# If the variables are defined as 'none', use blank for cleanliness.
if home_phone == 'none':
@ -283,6 +278,17 @@ class MugshotWindow(Window):
else:
self.user_image.set_from_icon_name('avatar-default', 128)
def suggest_initials(self, first_name, last_name):
"""Generate initials from first and last name."""
try:
initials = first_name[0] + last_name[0]
except:
if first_name:
initials = first_name[0]
else:
initials = ''
return initials
def filter_numbers(self, entry, *args):
"""Allow only numbers and + in phone entry fields."""
text = entry.get_text().strip()
@ -333,8 +339,10 @@ class MugshotWindow(Window):
def initials_entry_focused(self, widget):
"""Paste initials into empty field."""
logger.debug('Initials field focused.')
first_name = get_entry_value(self.first_name_entry)
last_name = get_entry_value(self.last_name_entry)
if get_entry_value(self.initials_entry) == '':
self.initials_entry.set_text(self.initials_suggestion)
self.initials_entry.set_text(self.suggest_initials(first_name, last_name))
def on_cancel_button_clicked(self, widget):
"""When the window cancel button is clicked, close the program."""