-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextInput.py
68 lines (51 loc) · 2.28 KB
/
TextInput.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from rubicon.objc import objc_method, ObjCClass, send_super, ObjCInstance
ObjCClass.auto_rename = True
NSOperation = ObjCClass("NSOperation")
NSOperationQueue = ObjCClass("NSOperationQueue")
UIApplication = ObjCClass('UIApplication')
UIColor = ObjCClass('UIColor')
UIViewController = ObjCClass('UIViewController')
UIAlertController = ObjCClass('UIAlertController')
UIAlertAction = ObjCClass('UIAlertAction')
class MyViewController(UIViewController):
@objc_method
def viewDidLoad(self):
send_super(__class__, self, "viewDidLoad")
self.view.backgroundColor = UIColor.blackColor
print("View")
# Create and present a UIAlertController after a delay
# the 500 argument is whats preventing the app from crashing
self.performSelector_withObject_afterDelay_(
'presentAlert', None, 500.0)
@objc_method
def presentAlert(self):
alert_controller = UIAlertController.alertControllerWithTitle_message_preferredStyle_(
'Ask Bot', 'Enter your prompt to the AI: 🤖💬', 1)
print("Alert")
# Add a text field for user input
alert_controller.addTextFieldWithConfigurationHandler_(None)
def _result_handler(action: ObjCInstance) -> None:
print("User entered prompt")
action = UIAlertAction.actionWithTitle_style_handler_(
'OK', 0, _result_handler)
alert_controller.addAction(action)
self.presentViewController_animated_completion_(
alert_controller, True, None)
class MainOperation(NSOperation):
@objc_method
def main(self):
send_super(__class__, self, "main")
app = UIApplication.sharedApplication
rootVC = app.keyWindow.rootViewController
mainVC = MyViewController.new().autorelease()
rootVC.presentViewController_animated_completion_(
mainVC, True, None) # Present the mainVC first
while childVC := rootVC.presentedViewController:
rootVC = childVC
# After presenting mainVC, check if there is a presented view controller and dismiss it
rootVC.presentAlert()
if __name__ == "__main__":
operation = MainOperation.new()
queue = NSOperationQueue.mainQueue
queue.addOperation(operation)
queue.waitUntilAllOperationsAreFinished()