Read first and last name from entries
This commit is contained in:
parent
323435efaa
commit
965e8ad064
|
@ -231,17 +231,12 @@ class MugshotWindow(Window):
|
||||||
name, office, office_phone, home_phone = details.split(',', 3)
|
name, office, office_phone, home_phone = details.split(',', 3)
|
||||||
break
|
break
|
||||||
|
|
||||||
# Expand the user's fullname into first, last, and initials.
|
# Expand the user's fullname into first and last.
|
||||||
try:
|
try:
|
||||||
first_name, last_name = name.split(' ', 1)
|
first_name, last_name = name.split(' ', 1)
|
||||||
self.initials_suggestion = first_name[0] + last_name[0]
|
|
||||||
except:
|
except:
|
||||||
first_name = name
|
first_name = name
|
||||||
last_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 the variables are defined as 'none', use blank for cleanliness.
|
||||||
if home_phone == 'none':
|
if home_phone == 'none':
|
||||||
|
@ -283,6 +278,17 @@ class MugshotWindow(Window):
|
||||||
else:
|
else:
|
||||||
self.user_image.set_from_icon_name('avatar-default', 128)
|
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):
|
def filter_numbers(self, entry, *args):
|
||||||
"""Allow only numbers and + in phone entry fields."""
|
"""Allow only numbers and + in phone entry fields."""
|
||||||
text = entry.get_text().strip()
|
text = entry.get_text().strip()
|
||||||
|
@ -333,8 +339,10 @@ class MugshotWindow(Window):
|
||||||
def initials_entry_focused(self, widget):
|
def initials_entry_focused(self, widget):
|
||||||
"""Paste initials into empty field."""
|
"""Paste initials into empty field."""
|
||||||
logger.debug('Initials field focused.')
|
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) == '':
|
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):
|
def on_cancel_button_clicked(self, widget):
|
||||||
"""When the window cancel button is clicked, close the program."""
|
"""When the window cancel button is clicked, close the program."""
|
||||||
|
|
Loading…
Reference in New Issue