0
# Interface Builder Integration
1
2
Decorators and descriptors for creating Interface Builder-compatible outlets, actions, and properties, enabling seamless integration with macOS app development workflows and Xcode's Interface Builder.
3
4
## Capabilities
5
6
### Interface Builder Outlets
7
8
Descriptors for creating outlets that can be connected to Interface Builder elements.
9
10
```python { .api }
11
def IBOutlet(name=None):
12
"""
13
Create an Interface Builder outlet descriptor.
14
15
Args:
16
name (str, optional): Name for the outlet (defaults to attribute name)
17
18
Returns:
19
Property descriptor that can be connected in Interface Builder
20
"""
21
```
22
23
### Interface Builder Actions
24
25
Decorator for marking methods as Interface Builder actions that can be connected to UI controls.
26
27
```python { .api }
28
def IBAction(func):
29
"""
30
Mark method as an Interface Builder action.
31
32
Args:
33
func: Method to mark as IBAction
34
35
Returns:
36
Method that can be connected to UI controls in Interface Builder
37
"""
38
```
39
40
### Interface Builder Properties
41
42
Decorator for marking properties as inspectable in Interface Builder's attribute inspector.
43
44
```python { .api }
45
def IBInspectable(prop):
46
"""
47
Mark property as Interface Builder inspectable.
48
49
Args:
50
prop: Property to mark as inspectable
51
52
Returns:
53
Property that appears in Interface Builder's attribute inspector
54
"""
55
```
56
57
### Interface Builder Design-Time Support
58
59
Class decorator for enabling design-time rendering in Interface Builder.
60
61
```python { .api }
62
def IB_DESIGNABLE(cls):
63
"""
64
Mark class as Interface Builder designable for design-time rendering.
65
66
Args:
67
cls: Class to mark as designable
68
69
Returns:
70
Class that can render at design-time in Interface Builder
71
"""
72
```
73
74
**Usage Examples:**
75
76
```python
77
import objc
78
from objc import IBOutlet, IBAction, IBInspectable, IB_DESIGNABLE
79
80
@IB_DESIGNABLE
81
class MyViewController:
82
# Interface Builder outlets
83
titleLabel = IBOutlet()
84
submitButton = IBOutlet("submitBtn") # Custom name
85
86
# Inspectable properties (appear in Interface Builder)
87
@IBInspectable
88
@property
89
def cornerRadius(self):
90
return self._cornerRadius
91
92
@cornerRadius.setter
93
def cornerRadius(self, value):
94
self._cornerRadius = value
95
# Update UI based on property change
96
97
# Interface Builder actions
98
@IBAction
99
def submitButtonPressed_(self, sender):
100
"""Connected to button's Touch Up Inside event."""
101
print(f"Button pressed: {sender}")
102
self.handleSubmit()
103
104
@IBAction
105
def textFieldChanged_(self, sender):
106
"""Connected to text field's Editing Changed event."""
107
self.validateInput(sender.stringValue())
108
109
def handleSubmit(self):
110
"""Regular Python method (not an IBAction)."""
111
pass
112
```
113
114
### Integration with macOS Development
115
116
These decorators enable full integration with Xcode's Interface Builder:
117
118
- **IBOutlet**: Creates connections between Python properties and UI elements
119
- **IBAction**: Enables method connections to user interface events
120
- **IBInspectable**: Exposes properties in Interface Builder's attribute inspector
121
- **IB_DESIGNABLE**: Enables custom view rendering at design-time
122
123
This allows developers to use the visual interface design tools while implementing logic in Python, maintaining the standard macOS development workflow.