|
6 | 6 | # LICENSE file in the root directory of this source tree.
|
7 | 7 |
|
8 | 8 |
|
9 |
| -import lldb |
10 | 9 | import fblldbbase as fb
|
11 | 10 | import fblldbviewhelpers as viewHelpers
|
| 11 | +import lldb |
12 | 12 |
|
13 |
| -def lldbcommands(): |
14 |
| - return [ |
15 |
| - FBPrintAutolayoutTrace(), |
16 |
| - FBAutolayoutBorderAmbiguous(), |
17 |
| - FBAutolayoutUnborderAmbiguous(), |
18 |
| - ] |
19 |
| - |
20 |
| -class FBPrintAutolayoutTrace(fb.FBCommand): |
21 |
| - def name(self): |
22 |
| - return 'paltrace' |
23 | 13 |
|
24 |
| - def description(self): |
25 |
| - return "Print the Auto Layout trace for the given view. Defaults to the key window." |
| 14 | +def lldbcommands(): |
| 15 | + return [ |
| 16 | + FBPrintAutolayoutTrace(), |
| 17 | + FBAutolayoutBorderAmbiguous(), |
| 18 | + FBAutolayoutUnborderAmbiguous(), |
| 19 | + ] |
26 | 20 |
|
27 |
| - def args(self): |
28 |
| - return [ fb.FBCommandArgument(arg='view', type='UIView *', help='The view to print the Auto Layout trace for.', default='(id)[[UIApplication sharedApplication] keyWindow]') ] |
29 | 21 |
|
30 |
| - def run(self, arguments, options): |
31 |
| - view = fb.evaluateInputExpression(arguments[0]) |
32 |
| - opt = fb.evaluateBooleanExpression('[UIView instancesRespondToSelector:@selector(_autolayoutTraceRecursively:)]') |
33 |
| - traceCall = '_autolayoutTraceRecursively:1' if opt else '_autolayoutTrace' |
34 |
| - print(fb.describeObject('[{} {}]'.format(view, traceCall))) |
| 22 | +class FBPrintAutolayoutTrace(fb.FBCommand): |
| 23 | + def name(self): |
| 24 | + return "paltrace" |
| 25 | + |
| 26 | + def description(self): |
| 27 | + return ( |
| 28 | + "Print the Auto Layout trace for the given view. " |
| 29 | + "Defaults to the key window." |
| 30 | + ) |
| 31 | + |
| 32 | + def args(self): |
| 33 | + return [ |
| 34 | + fb.FBCommandArgument( |
| 35 | + arg="view", |
| 36 | + type="UIView *", |
| 37 | + help="The view to print the Auto Layout trace for.", |
| 38 | + default="(id)[[UIApplication sharedApplication] keyWindow]", |
| 39 | + ) |
| 40 | + ] |
| 41 | + |
| 42 | + def run(self, arguments, options): |
| 43 | + view = fb.evaluateInputExpression(arguments[0]) |
| 44 | + opt = fb.evaluateBooleanExpression( |
| 45 | + "[UIView instancesRespondToSelector:@selector(_autolayoutTraceRecursively:)]" # noqa B950 |
| 46 | + ) |
| 47 | + traceCall = "_autolayoutTraceRecursively:1" if opt else "_autolayoutTrace" |
| 48 | + print(fb.describeObject("[{} {}]".format(view, traceCall))) |
35 | 49 |
|
36 | 50 |
|
37 | 51 | def setBorderOnAmbiguousViewRecursive(view, width, color):
|
38 |
| - if not fb.evaluateBooleanExpression('[(id)%s isKindOfClass:(Class)[UIView class]]' % view): |
39 |
| - return |
40 |
| - |
41 |
| - isAmbiguous = fb.evaluateBooleanExpression('(BOOL)[%s hasAmbiguousLayout]' % view) |
42 |
| - if isAmbiguous: |
43 |
| - layer = viewHelpers.convertToLayer(view) |
44 |
| - fb.evaluateEffect('[%s setBorderWidth:(CGFloat)%s]' % (layer, width)) |
45 |
| - fb.evaluateEffect('[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color)) |
46 |
| - |
47 |
| - subviews = fb.evaluateExpression('(id)[%s subviews]' % view) |
48 |
| - subviewsCount = int(fb.evaluateExpression('(int)[(id)%s count]' % subviews)) |
49 |
| - if subviewsCount > 0: |
50 |
| - for i in range(0, subviewsCount): |
51 |
| - subview = fb.evaluateExpression('(id)[%s objectAtIndex:%i]' % (subviews, i)) |
52 |
| - setBorderOnAmbiguousViewRecursive(subview, width, color) |
| 52 | + if not fb.evaluateBooleanExpression( |
| 53 | + "[(id)%s isKindOfClass:(Class)[UIView class]]" % view |
| 54 | + ): |
| 55 | + return |
| 56 | + |
| 57 | + isAmbiguous = fb.evaluateBooleanExpression("(BOOL)[%s hasAmbiguousLayout]" % view) |
| 58 | + if isAmbiguous: |
| 59 | + layer = viewHelpers.convertToLayer(view) |
| 60 | + fb.evaluateEffect("[%s setBorderWidth:(CGFloat)%s]" % (layer, width)) |
| 61 | + fb.evaluateEffect( |
| 62 | + "[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]" |
| 63 | + % (layer, color) |
| 64 | + ) |
| 65 | + |
| 66 | + subviews = fb.evaluateExpression("(id)[%s subviews]" % view) |
| 67 | + subviewsCount = int(fb.evaluateExpression("(int)[(id)%s count]" % subviews)) |
| 68 | + if subviewsCount > 0: |
| 69 | + for i in range(0, subviewsCount): |
| 70 | + subview = fb.evaluateExpression("(id)[%s objectAtIndex:%i]" % (subviews, i)) |
| 71 | + setBorderOnAmbiguousViewRecursive(subview, width, color) |
53 | 72 |
|
54 | 73 |
|
55 | 74 | class FBAutolayoutBorderAmbiguous(fb.FBCommand):
|
56 |
| - def name(self): |
57 |
| - return 'alamborder' |
58 |
| - |
59 |
| - def description(self): |
60 |
| - return "Put a border around views with an ambiguous layout" |
61 |
| - |
62 |
| - def options(self): |
63 |
| - return [ |
64 |
| - fb.FBCommandArgument(short='-c', long='--color', arg='color', type='string', default='red', help='A color name such as \'red\', \'green\', \'magenta\', etc.'), |
65 |
| - fb.FBCommandArgument(short='-w', long='--width', arg='width', type='CGFloat', default=2.0, help='Desired width of border.') |
66 |
| - ] |
67 |
| - |
68 |
| - def run(self, arguments, options): |
69 |
| - keyWindow = fb.evaluateExpression('(id)[[UIApplication sharedApplication] keyWindow]') |
70 |
| - setBorderOnAmbiguousViewRecursive(keyWindow, options.width, options.color) |
71 |
| - lldb.debugger.HandleCommand('caflush') |
| 75 | + def name(self): |
| 76 | + return "alamborder" |
| 77 | + |
| 78 | + def description(self): |
| 79 | + return "Put a border around views with an ambiguous layout" |
| 80 | + |
| 81 | + def options(self): |
| 82 | + return [ |
| 83 | + fb.FBCommandArgument( |
| 84 | + short="-c", |
| 85 | + long="--color", |
| 86 | + arg="color", |
| 87 | + type="string", |
| 88 | + default="red", |
| 89 | + help="A color name such as 'red', 'green', 'magenta', etc.", |
| 90 | + ), |
| 91 | + fb.FBCommandArgument( |
| 92 | + short="-w", |
| 93 | + long="--width", |
| 94 | + arg="width", |
| 95 | + type="CGFloat", |
| 96 | + default=2.0, |
| 97 | + help="Desired width of border.", |
| 98 | + ), |
| 99 | + ] |
| 100 | + |
| 101 | + def run(self, arguments, options): |
| 102 | + keyWindow = fb.evaluateExpression( |
| 103 | + "(id)[[UIApplication sharedApplication] keyWindow]" |
| 104 | + ) |
| 105 | + setBorderOnAmbiguousViewRecursive(keyWindow, options.width, options.color) |
| 106 | + lldb.debugger.HandleCommand("caflush") |
72 | 107 |
|
73 | 108 |
|
74 | 109 | class FBAutolayoutUnborderAmbiguous(fb.FBCommand):
|
75 |
| - def name(self): |
76 |
| - return 'alamunborder' |
77 |
| - |
78 |
| - def description(self): |
79 |
| - return "Removes the border around views with an ambiguous layout" |
80 |
| - |
81 |
| - def run(self, arguments, options): |
82 |
| - keyWindow = fb.evaluateExpression('(id)[[UIApplication sharedApplication] keyWindow]') |
83 |
| - setBorderOnAmbiguousViewRecursive(keyWindow, 0, "red") |
84 |
| - lldb.debugger.HandleCommand('caflush') |
| 110 | + def name(self): |
| 111 | + return "alamunborder" |
| 112 | + |
| 113 | + def description(self): |
| 114 | + return "Removes the border around views with an ambiguous layout" |
| 115 | + |
| 116 | + def run(self, arguments, options): |
| 117 | + keyWindow = fb.evaluateExpression( |
| 118 | + "(id)[[UIApplication sharedApplication] keyWindow]" |
| 119 | + ) |
| 120 | + setBorderOnAmbiguousViewRecursive(keyWindow, 0, "red") |
| 121 | + lldb.debugger.HandleCommand("caflush") |
0 commit comments