[accerciser: 1/2] treeview: Populate path for bookmark right away




commit a092dc933985fafd5b1e2cc3374c7bbc0fb2d12e
Author: Michael Weghorn <m weghorn posteo de>
Date:   Thu Jul 14 09:38:57 2022 +0200

    treeview: Populate path for bookmark right away
    
    Accessing the given path in the model can
    fail if the items have not been populated yet.
    
    Therefore, try to access the given path again
    right after populating the model to the
    given path.
    
    To make sure the model has actually been
    populated, process all pending events
    after the call to `self.model.popToPath(path)`
    since populating is done via idles
    (s. `AccessibleModel#popLevel`) that may
    otherwise not have been processed yet.
    
    This makes expanding and selecting the
    corresponding item in the treeview work
    when clicking on a bookmark for the first
    time, while it required clicking the bookmark
    a second time previously if the path had not
    already been populated.
    
    (The documentation for `selectNodeAtPath`
    already claimed this:
    "The path does not need to exist in the model,
    only in the accessibles tree. The model will get
    populated accordingly.")

 src/lib/accerciser/accessible_treeview.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/src/lib/accerciser/accessible_treeview.py b/src/lib/accerciser/accessible_treeview.py
index ed4b650..e6282e3 100644
--- a/src/lib/accerciser/accessible_treeview.py
+++ b/src/lib/accerciser/accessible_treeview.py
@@ -856,7 +856,16 @@ class AccessibleTreeView(gtk.TreeView, ToolsAccessor):
     if dummy:
       self._path_to_expand = path
       self.model.popToPath(path)
-    else:
+      # process all pending events, so the path actually
+      # gets populated via the corresponding idles
+      main_loop_context = GLib.MainContext.default()
+      while main_loop_context.iteration(False):
+        pass
+      try:
+        dummy = self.model[path][COL_DUMMY]
+      except:
+        pass
+    if not dummy:
       self._selectExistingPath(path)
 
   def _onRowFilled(self, model, iter):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]