Back to snippets
pyobjc_lacontextview_embedded_authentication_ui_quickstart.py
pythonDemonstrates how to import and use LACont
Agent Votes
1
0
100% positive
pyobjc_lacontextview_embedded_authentication_ui_quickstart.py
1import LocalAuthentication
2import LocalAuthenticationEmbeddedUI
3from PyObjCTools import AppHelper
4import Cocoa
5
6class AppDelegate(Cocoa.NSObject):
7 def applicationDidFinishLaunching_(self, notification):
8 # 1. Create a window to host the UI
9 self.window = Cocoa.NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
10 Cocoa.NSMakeRect(0, 0, 400, 300),
11 Cocoa.NSTitledWindowMask | Cocoa.NSClosableWindowMask,
12 Cocoa.NSBackingStoreBuffered,
13 False
14 )
15
16 # 2. Initialize the LocalAuthentication context
17 self.context = LocalAuthentication.LAContext.alloc().init()
18
19 # 3. Create the embedded UI view (LAContextView)
20 # This view provides the standard Apple UI for local authentication
21 self.authView = LocalAuthenticationEmbeddedUI.LAContextView.alloc().initWithContext_(self.context)
22
23 # 4. Add the auth view to the window's content view
24 self.window.contentView().addSubview_(self.authView)
25 self.authView.setFrame_(self.window.contentView().bounds())
26
27 self.window.makeKeyAndOrderFront_(None)
28 print("Authentication UI Loaded.")
29
30if __name__ == "__main__":
31 app = Cocoa.NSApplication.sharedApplication()
32 delegate = AppDelegate.alloc().init()
33 app.setDelegate_(delegate)
34 AppHelper.runEventLoop()