Exemplo n.º 1
0
 def subviewsOfView(self, view):
     """
     Generates a BFS of the views tree starting at the given view as root.
     Yields a tuple of the current view in the tree and its level (view, level)
     """
     views = [(view, 0)]
     yield views[0]
     while views:
         (view, level) = views.pop(0)
         subviews = base.evaluateExpression('(id)[%s subviews]' % view)
         subviewsCount = int(base.evaluateExpression(
             '(int)[(id)%s count]' % subviews))
         for i in xrange(subviewsCount):
             subview = base.evaluateExpression(
                 '(id)[%s objectAtIndex:%i]' % (subviews, i))
             views.append((subview, level + 1))
             yield (subview, level + 1)
Exemplo n.º 2
0
 def convertToLayer(self, viewOrLayer):
     """
     Convert the View or layer to a CALayer
     """
     expression_cla = '[(id)%s isKindOfClass:(Class)[CALayer class]]' % viewOrLayer
     expression_sel = '[(id)%s respondsToSelector:(SEL)@selector(layer)]' % viewOrLayer
     if base.evaluateBooleanExpression(expression_cla):
         return viewOrLayer
     elif base.evaluateBooleanExpression(expression_sel):
         return base.evaluateExpression('(CALayer *)[%s layer]' % viewOrLayer)
     else:
         raise Exception('Argument must be a CALayer, UIView, or NSView.')