From 323435efaa61b9399e77ac115ca88c5f13a43693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thadd=C3=A4us=20Tintenfisch?= Date: Fri, 28 Mar 2014 03:35:00 +0100 Subject: [PATCH 1/2] Improve initials field behavior --- data/ui/MugshotWindow.ui | 1 + mugshot/MugshotWindow.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/data/ui/MugshotWindow.ui b/data/ui/MugshotWindow.ui index 7036558..c81102d 100644 --- a/data/ui/MugshotWindow.ui +++ b/data/ui/MugshotWindow.ui @@ -358,6 +358,7 @@ 4 alpha + diff --git a/mugshot/MugshotWindow.py b/mugshot/MugshotWindow.py index 7579986..be8d9be 100644 --- a/mugshot/MugshotWindow.py +++ b/mugshot/MugshotWindow.py @@ -234,14 +234,14 @@ class MugshotWindow(Window): # Expand the user's fullname into first, last, and initials. try: first_name, last_name = name.split(' ', 1) - initials = first_name[0] + last_name[0] + self.initials_suggestion = first_name[0] + last_name[0] except: first_name = name last_name = '' if first_name: - initials = first_name[0] + self.initials_suggestion = first_name[0] else: - initials = '' + self.initials_suggestion = '' # If the variables are defined as 'none', use blank for cleanliness. if home_phone == 'none': @@ -251,8 +251,7 @@ class MugshotWindow(Window): # Get dconf settings logger.debug('Getting initials, email, and fax from dconf') - if self.settings['initials'] != '': - initials = self.settings['initials'] + initials = self.settings['initials'] email = self.settings['email'] fax = self.settings['fax'] @@ -330,6 +329,12 @@ class MugshotWindow(Window): logger.debug('Entry activated, focusing next widget.') vbox = widget.get_parent().get_parent().get_parent().get_parent() vbox.child_focus(Gtk.DirectionType.TAB_FORWARD) + + def initials_entry_focused(self, widget): + """Paste initials into empty field.""" + logger.debug('Initials field focused.') + if get_entry_value(self.initials_entry) == '': + self.initials_entry.set_text(self.initials_suggestion) def on_cancel_button_clicked(self, widget): """When the window cancel button is clicked, close the program.""" From 965e8ad0643e5264555376177044205c9b7b5c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thadd=C3=A4us=20Tintenfisch?= Date: Sun, 30 Mar 2014 21:26:33 +0200 Subject: [PATCH 2/2] Read first and last name from entries --- mugshot/MugshotWindow.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mugshot/MugshotWindow.py b/mugshot/MugshotWindow.py index be8d9be..d8d4d38 100644 --- a/mugshot/MugshotWindow.py +++ b/mugshot/MugshotWindow.py @@ -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."""