Use AppHelper and add try-catch block
This commit is contained in:
17
main.py
17
main.py
@@ -24,8 +24,11 @@ from Foundation import NSObject, NSTimer, NSDate
|
||||
|
||||
load_dotenv()
|
||||
|
||||
from PyObjCTools import AppHelper
|
||||
|
||||
class ItemSenseApp(NSObject):
|
||||
def applicationDidFinishLaunching_(self, notification):
|
||||
try:
|
||||
print("Application did finish launching...")
|
||||
self.window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
|
||||
NSMakeRect(0, 0, 800, 700),
|
||||
@@ -46,14 +49,12 @@ class ItemSenseApp(NSObject):
|
||||
# Image View for Camera Feed
|
||||
self.image_view = NSImageView.alloc().init()
|
||||
self.image_view.setImageScaling_(0) # NSImageScaleProportionallyDown
|
||||
# Add constraint for height logic later if needed, but stackview handles it well enough for basic
|
||||
self.stack_view.addView_inGravity_(self.image_view, 1) # Top gravity
|
||||
|
||||
# Result View (Scrollable Text)
|
||||
self.scroll_view = NSScrollView.alloc().init()
|
||||
self.scroll_view.setHasVerticalScroller_(True)
|
||||
self.scroll_view.setBorderType_(2) # NSBezelBorder
|
||||
self.scroll_view.setHeightAdjustLimit_(1.0)
|
||||
|
||||
# Text View
|
||||
content_size = self.scroll_view.contentSize()
|
||||
@@ -78,11 +79,19 @@ class ItemSenseApp(NSObject):
|
||||
self.stack_view.addView_inGravity_(self.capture_button, 3) # Bottom gravity
|
||||
|
||||
self.window.makeKeyAndOrderFront_(None)
|
||||
self.window.orderFrontRegardless() # Force it front
|
||||
self.window.orderFrontRegardless()
|
||||
print("Window ordered front.")
|
||||
|
||||
# State
|
||||
self.is_capturing = True
|
||||
self.current_frame = None
|
||||
|
||||
# Initialize Camera with a delay to allow UI to render first
|
||||
self.performSelector_withObject_afterDelay_("initCamera:", None, 0.5)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
print(f"Error in applicationDidFinishLaunching: {e}")
|
||||
|
||||
def initCamera_(self, sender):
|
||||
print("Initializing camera...")
|
||||
@@ -205,4 +214,4 @@ if __name__ == "__main__":
|
||||
|
||||
# Allow time for policy to take effect? Usually acceptable immediately.
|
||||
app.activateIgnoringOtherApps_(True)
|
||||
app.run()
|
||||
AppHelper.runEventLoop()
|
||||
|
||||
Reference in New Issue
Block a user