View Single Post
I will go off and think about this some more. My first concern is that this doesn't really help, because now I have a flat list of ancestors that is unique, but I don't know the hierarchy of the ancestors, so I'll have to process them all again to figure out the hierarchy. Might as well to have just built up my own tree...?

Code:
class TreeObj: 
  """Hold a pointer to a row object and its children. Create a tree mirroring OmniOutliner structs"""

  def __init__(self, o, is_row=0):
    self.obj = o
    self.children = []
    self.hidden = 0
    self.is_row = is_row

  def init_tree(self):
    """Recursively initialize a tree of python objects initialized from OmniOutliner doc"""
    for c_apple in self.obj.children():
      c = TreeObj(c_apple, 1) 
      c.init_tree()
      self.children.append(c)

  def find_row(self, pattern):
    retval = 0
    if (self.is_row and not self.hidden):
      for cell in self.obj.cells():
        if (re.search(pattern, str(cell.value()))):
          #print "found pattern " + pattern
          return 1

    for child in self.children:
      if (1 == child.find_row(pattern)):
        retval = 1

    if (retval == 0):
      self.hidden = 1

    return retval

# ... etc