def __init__(self): self.key_hook = lambda x: True self.mouse_button_hook = lambda x: True self.mouse_move_hook = lambda x: True self.screen_hook = lambda x: True self.screenSize = [NSScreen.mainScreen().frame().size.width, NSScreen.mainScreen().frame().size.height] self.screenRatio = self.screenSize[0]/self.screenSize[1] self.location_hook = lambda x: True self.geo = locationTracking.LocationTracking() self.geo.startTracking() self.geo.locationchange_hook = self.got_location_change self.delegate = None
def _screenImageOptions(screen): ''' Process an instance of NSScreen, returning its options as a hash ''' workspace = NSWorkspace.sharedWorkspace() if screen == NSScreen.mainScreen(): is_main = True else: is_main = False screen_options = workspace.desktopImageOptionsForScreen_(screen) scaling_factor = screen_options.objectForKey_( NSWorkspaceDesktopImageScalingKey) # NSImageScaling : NSNumber allow_clipping = screen_options.objectForKey_( NSWorkspaceDesktopImageAllowClippingKey) # NSNumber fill_color = screen_options.objectForKey_( NSWorkspaceDesktopImageFillColorKey) # NSColor image_url = workspace.desktopImageURLForScreen_( screen).absoluteString() # NSURL options_dict = { 'main': is_main, 'scaling_factor': scaling_factor, 'image_url': image_url, 'allow_clipping': allow_clipping } if fill_color: options_dict['fill_color'] = { 'r': fill_color.redComponent(), 'g': fill_color.greenComponent(), 'b': fill_color.blueComponent() } return options_dict
def _Window2(title=_argv0, fraction=0.5): '''Create the main NS window and the drawable NS view. ''' frame = NSScreen.mainScreen().frame() if 0.1 < fraction < 1.0: # use the lower left quarter of the screen size as frame w = int(frame.size.width * fraction + 0.5) h = int(frame.size.height * w / frame.size.width) frame = NSMakeRect(frame.origin.x + 10, frame.origin.y + 10, w, h) window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_( frame, NSWindowStyleMaskUsual, NSBackingStoreBuffered, False) # or 0 window.setTitle_(NSStr(title)) # create the drawable_nsobject NSView for vlc.py, see vlc.MediaPlayer.set_nsobject() # for an alternate NSView object with protocol VLCOpenGLVideoViewEmbedding # <http://StackOverflow.com/questions/11562587/create-nsview-directly-from-code> # <http://GitHub.com/ariabuckles/pyobjc-framework-Cocoa/blob/master/Examples/AppKit/DotView/DotView.py> view = NSView.alloc().initWithFrame_(frame) window.setContentView_(view) # force the video/window aspect ratio, adjusted # above when the window is/has been resized window.setContentAspectRatio_(frame.size) window.makeKeyAndOrderFront_(None) return window, view
def get_window_screen(window): pos = get_window_pos(window) screens = NSScreen.screens() for screen in screens: frame = screen.frame() if pos.x >= frame.origin.x and \ pos.y >= frame.origin.y and \ pos.x <= frame.origin.x + frame.size.width and \ pos.y <= frame.origin.y + frame.size.height: return screen # screen not found return NSScreen.mainScreen()
def _screenImageOptions(screen): ''' Process an instance of NSScreen, returning its options as a hash ''' workspace = NSWorkspace.sharedWorkspace() if screen == NSScreen.mainScreen(): is_main = True else: is_main = False screen_options = workspace.desktopImageOptionsForScreen_(screen) scaling_factor = screen_options.objectForKey_(NSWorkspaceDesktopImageScalingKey) # NSImageScaling : NSNumber allow_clipping = screen_options.objectForKey_(NSWorkspaceDesktopImageAllowClippingKey) # NSNumber fill_color = screen_options.objectForKey_(NSWorkspaceDesktopImageFillColorKey) # NSColor image_url = workspace.desktopImageURLForScreen_(screen).absoluteString() # NSURL options_dict = {'main': is_main, 'scaling_factor': scaling_factor, 'image_url': image_url, 'allow_clipping': allow_clipping} if fill_color: options_dict['fill_color'] = {'r': fill_color.redComponent(), 'g': fill_color.greenComponent(), 'b': fill_color.blueComponent()} return options_dict