commit 97986aa6ce9147f88ac190e772176b799c6fe660
Author: David Sorber <david.sorber@gmail.com>
Date:   Fri Nov 23 09:49:34 2018 -0500

    Remove instances of Gtk.idle_add() in favor of a trick I discovered for
    updating the UI inline.

diff --git a/software/pwmgr/pwmgr.py b/software/pwmgr/pwmgr.py
index bb9fa38..ff85d9d 100755
--- a/software/pwmgr/pwmgr.py
+++ b/software/pwmgr/pwmgr.py
@@ -19,7 +19,7 @@ SCRATCH_FILE_PATH = '/mnt/pw_ramdisk/chicken_soup.txt'
 ENC_TMP_FILE_PATH = '/home/dsorber/Documents/chicken_soup.enc.tmp'
 KEY_FILE_PATH = '/mnt/pw_ramdisk/.f05d11ef-000c-45c2-ae14-56b56c23e1c5'
 
-VERSION = '0.0.6'
+VERSION = '0.0.7'
 
 class SearchDialog(Gtk.Dialog):
 
@@ -104,7 +104,11 @@ def get_user_pw(parent, message, title=''):
     if (response == Gtk.ResponseType.OK) and (text != ''):
         return text
     else:
-        return None    
+        return None
+        
+def yield_gtk():
+    while Gtk.events_pending():
+            Gtk.main_iteration()
     
 class ProgressBarWindow(Gtk.Window):
 
@@ -154,19 +158,10 @@ class TextViewWindow(Gtk.Window):
         self.pwd_file_fd = None
         self.original_hash = None
         self.pbar_win = None
-        self.should_quit = False
 
         # Open password prompt window at start
-        GLib.idle_add(self.open_pwd_file, self.grid)
-        
-    
-    def async_quit(self):        
-        if self.should_quit:
-            if self.pbar_win is not None:
-                self.pbar_win.destroy()
-            Gtk.main_quit()
-            print('REAL QUIT')
-        return True
+        self.open_pwd_file(self.grid)
+        yield_gtk()
 
     def _key_press_event(self, widget, event):
         keyval = event.keyval
@@ -352,9 +347,11 @@ class TextViewWindow(Gtk.Window):
         """
         Clean up ramdisk by overwriting, then unmount
         """
-        GLib.idle_add(self.pbar_win.update_text, 'Starting ramdisk cleanup')
-        
+        self.pbar_win.update_text('Starting ramdisk cleanup')
+        yield_gtk()
         
+        # Build shell commands to write random and zero data (respectively) to
+        # the file
         rand_write_cmd = 'dd if=/dev/urandom of={:s} bs=16M count=1 status=none'
         rand_write_cmd = rand_write_cmd.format(os.path.join(MOUNT_PATH, 'data'))
         
@@ -367,22 +364,28 @@ class TextViewWindow(Gtk.Window):
         for ctr in range(10):
             print(ctr)
             message = 'Overwrite {:d} of 10'.format(ctr +  1)
-            GLib.idle_add(self.pbar_win.update_text, message)
+            self.pbar_win.update_text(message)
+            yield_gtk()
             
+            # Do one pass, write random data then write zeros
             subprocess.call(rand_write_cmd, shell=True, timeout=5)
             self._remove_mount_files()
             subprocess.call(zero_write_cmd, shell=True, timeout=5)
             self._remove_mount_files()
             
-            GLib.idle_add(self.pbar_win.update_complete, (ctr + 1) / 10)
+            # Update progress bar
+            self.pbar_win.update_complete((ctr + 1) / 10)
+            yield_gtk()
+        
+        self.pbar_win.update_text('Unmounting ramdisk')
+        yield_gtk()
         
-        GLib.idle_add(self.pbar_win.update_text, 'Unmounting ramdisk')
+        # Unmount the ramdisk
         umount_cmd = 'umount {:s}'.format(MOUNT_PATH)
         subprocess.call(umount_cmd, shell=True, timeout=5)
-        GLib.idle_add(self.pbar_win.update_text, 'Complete')
-        
-        self.should_quit = True
-        print('SET should quit')
+
+        self.pbar_win.update_text('Complete')
+        yield_gtk()
     
     def close_pwd_file(self, widget, other):
         """
@@ -408,19 +411,15 @@ class TextViewWindow(Gtk.Window):
         self.textview.set_cursor_visible(False)
         
         if self.mounted:
-            # Start async polling of the quit flag
-            GLib.timeout_add(500, self.async_quit)
-        
             # Create the progress window
             self.pbar_win = ProgressBarWindow(self, 'Closing...')
             self.pbar_win.show_all()
+            yield_gtk()
             
-            # Start the work thread that does the cleanup
-            thread = threading.Thread(target=self.do_mount_cleanup)
-            thread.start()
-        else:
-            Gtk.main_quit()
-        
+            self.do_mount_cleanup()
+            
+        # Quit GTK app
+        Gtk.main_quit()
         print('CLOSE')
 
     def on_clear_clicked(self, widget):
