def show(self): try: if self.debriefController: self.debriefController.close() except: pass # open window from NIB file, show front and center self.debriefController = DebriefController.alloc().initWithWindowNibName_("Debriefer") self.debriefController.showWindow_(None) self.debriefController.window().makeKeyAndOrderFront_(None) self.debriefController.window().center() self.debriefController.retain() # needed to show window on top of other applications NSNotificationCenter.defaultCenter().postNotificationName_object_('makeAppActive',self) # get cmd-w to close window self.debriefController.window().standardWindowButton_(NSWindowCloseButton).setKeyEquivalentModifierMask_(NSCommandKeyMask) self.debriefController.window().standardWindowButton_(NSWindowCloseButton).setKeyEquivalent_("w") # get random set of experiences NSNotificationCenter.defaultCenter().postNotificationName_object_('getDebriefExperiences',self) self.currentExperience = 0 self.advanceExperienceWindow_(self, self)
def applicationDidFinishLaunching_(self, notification): NSLog("Application did finish launching...") # Register preferance defaults for user-facing preferences prefDictionary = {} prefDictionary[u"screenshots"] = True prefDictionary[u'imageSize'] = 720 # in px prefDictionary[u"imageTimeMax"] = 60 # in s prefDictionary[u"imageTimeMin"] = 100 # in ms prefDictionary[u"experienceTime"] = 1800 # in s prefDictionary[u"experienceLoop"] = True prefDictionary[u"recording"] = True NSUserDefaultsController.sharedUserDefaultsController().setInitialValues_(prefDictionary) mask = (NSKeyDownMask | NSKeyUpMask | NSLeftMouseDownMask | NSLeftMouseUpMask | NSRightMouseDownMask | NSRightMouseUpMask | NSMouseMovedMask | NSScrollWheelMask | NSFlagsChangedMask) NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(mask, sc.handler) self.createStatusMenu() # self.createStatusButton() NSNotificationCenter.defaultCenter().postNotificationName_object_('checkLoops',self) NSNotificationCenter.defaultCenter().postNotificationName_object_('noteRecordingState',self)
def show(self): try: if self.prefController: self.prefController.close() except: pass # open window from NIB file, show front and center self.prefController = PreferencesController.alloc( ).initWithWindowNibName_("Preferences") self.prefController.showWindow_(None) self.prefController.window().makeKeyAndOrderFront_(None) self.prefController.window().center() self.prefController.retain() # needed to show window on top of other applications NSNotificationCenter.defaultCenter().postNotificationName_object_( 'makeAppActive', self) # make window close on Cmd-w self.prefController.window().standardWindowButton_( NSWindowCloseButton).setKeyEquivalentModifierMask_( NSCommandKeyMask) self.prefController.window().standardWindowButton_( NSWindowCloseButton).setKeyEquivalent_("w")
def applicationWillTerminate_(self, application): # need to release the lock here as when the application terminates it does not run the rest the # original main, only the code that has crossed the pyobc bridge. NSNotificationCenter.defaultCenter().postNotificationName_object_('closeNotification',self) if cfg.LOCK.is_locked(): cfg.LOCK.release() NSLog("Exiting Selfspy...")
def advanceExperienceWindow_(self, sender): controller = self.debriefController i = self.currentExperience # close if user clicked Finish on window with no experiences to comment if i == -1: controller.close() return # disable all controls if no experiences to debrief if self.experiences: l = len(self.experiences) if (not self.experiences) or (l == 0): controller.errorMessage.setHidden_(False) controller.doingText.setEnabled_(False) controller.recordButton.setEnabled_(False) controller.progressLabel.setStringValue_("0/0") controller.progressButton.setTitle_("Finish") self.currentExperience = -1 return if i > 0: NSNotificationCenter.defaultCenter().postNotificationName_object_('recordDebrief',self) if i == l-1: controller.progressButton.setTitle_("Finish") if i < l: NSNotificationCenter.defaultCenter().postNotificationName_object_('populateDebriefWindow',self) path = os.path.expanduser(self.experiences[i]['screenshot'][:]) experienceImage = NSImage.alloc().initByReferencingFile_(path) width = experienceImage.size().width height = experienceImage.size().height ratio = width / height if( width > 960 or height > 600 ): if (ratio > 1.6): width = 960 height = 960 / ratio else: width = 600 * ratio height = 600 experienceImage.setScalesWhenResized_(True) experienceImage.setSize_((width, height)) experienceImage.setName_(path.split("/")[-1]) controller.mainPanel.setImage_(experienceImage) controller.progressLabel.setStringValue_( str(i + 1) + '/' + str(l) ) self.currentExperience += 1 else: self.debriefController.close()
def run(self): self.app = NSApplication.sharedApplication() self.delegate = self.createAppDelegate().alloc().init() self.app.setDelegate_(self.delegate) self.app.setActivationPolicy_(NSApplicationActivationPolicyAccessory) self.workspace = NSWorkspace.sharedWorkspace() # listen for events thrown by the Experience sampling window s = objc.selector(self.makeAppActive_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'makeAppActive', None) s = objc.selector(self.takeExperienceScreenshot_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'takeExperienceScreenshot', None) AppHelper.runEventLoop()
def show(self): try: if self.expController.window().isVisible(): if os.path.exists(self.path): os.remove(self.path) self.expController.close() except: pass # take initial full-screen screenshot self.takeFullScreenshot = True self.takeExperienceScreenshot_(self,self) self.takeFullScreenshot = False # open window from NIB file, show front and center self.expController = ExperienceController.alloc().initWithWindowNibName_("Experience") self.expController.showWindow_(None) self.expController.window().makeKeyAndOrderFront_(None) self.expController.window().center() self.expController.retain() self.path = os.path.expanduser(self.currentScreenshot) experienceImage = NSImage.alloc().initByReferencingFile_(self.path) width = experienceImage.size().width height = experienceImage.size().height ratio = width / height if( width > 360 or height > 225 ): if (ratio > 1.6): width = 360 height = 360 / ratio else: width = 225 * ratio height = 225 experienceImage.setScalesWhenResized_(True) experienceImage.setSize_((width, height)) self.expController.screenshotDisplay.setImage_(experienceImage) # needed to show window on top of other applications NSNotificationCenter.defaultCenter().postNotificationName_object_('makeAppActive',self) NSNotificationCenter.defaultCenter().postNotificationName_object_('getPriorExperiences',self.expController) self.overrideClose(self) return self.expController
def toggleLogging_(self, notification): NSLog("Toggle Recording") recording = NSUserDefaultsController.sharedUserDefaultsController().values().valueForKey_('recording') recording = not recording NSUserDefaultsController.sharedUserDefaultsController().defaults().setBool_forKey_(recording,'recording') NSNotificationCenter.defaultCenter().postNotificationName_object_('checkLoops',self) NSNotificationCenter.defaultCenter().postNotificationName_object_('noteRecordingState',self) #change text and enabled status of screenshot menu item if recording: self.loggingMenuItem.setTitle_("Pause Recording") # self.screenshotMenuItem.setEnabled_(True) else: self.loggingMenuItem.setTitle_("Start Recording") # self.screenshotMenuItem.setEnabled_(False) self.changeIcon()
def show(self): try: if self.prefController: self.prefController.close() except: pass # open window from NIB file, show front and center self.prefController = PreferencesController.alloc().initWithWindowNibName_("Preferences") self.prefController.showWindow_(None) self.prefController.window().makeKeyAndOrderFront_(None) self.prefController.window().center() self.prefController.retain() # needed to show window on top of other applications NSNotificationCenter.defaultCenter().postNotificationName_object_('makeAppActive',self) # make window close on Cmd-w self.prefController.window().standardWindowButton_(NSWindowCloseButton).setKeyEquivalentModifierMask_(NSCommandKeyMask) self.prefController.window().standardWindowButton_(NSWindowCloseButton).setKeyEquivalent_("w")
def __init__(self): app = NSApplication.sharedApplication() self.screen_window = app.windows()[0] self.screen_window.setStyleMask_(0) self.screen_window.setHasShadow_(False) frame = self.screen_window.frame() frame.origin = self.image_window.frame().origin frame.origin.x += 61 frame.origin.y += 72 self.screen_window.setFrame_display_(frame, False) self.image_window.makeKeyAndOrderFront_(None) self.image_window.addChildWindow_ordered_(self.screen_window, 1) image_window_frame = self.image_window.frame().copy() if 'TIDE_WINDOW_FRAME' in os.environ: left, top, width, height = ( float(x) for x in os.environ['TIDE_WINDOW_FRAME'].split(',')) # image_window_frame. print left, top, width, height image_window_left = left + width + 20 image_window_top = top + height / 2 + 180 self.image_window.cascadeTopLeftFromPoint_( CGPointMake(image_window_left, image_window_top)) else: self.image_window.center() def window_did_close(notification): app.terminate_(None) NSNotificationCenter.defaultCenter( ).addObserverForName_object_queue_usingBlock_( "NSWindowDidCloseNotification", self.image_window, None, window_did_close)
def __init__(self): app = NSApplication.sharedApplication() self.screen_window = app.windows()[0] self.screen_window.setStyleMask_(0) self.screen_window.setHasShadow_(False) frame = self.screen_window.frame() frame.origin = self.image_window.frame().origin frame.origin.x += 61 frame.origin.y += 72 self.screen_window.setFrame_display_(frame, False) self.image_window.makeKeyAndOrderFront_(None) self.image_window.addChildWindow_ordered_(self.screen_window, 1) image_window_frame = self.image_window.frame().copy() if 'TIDE_WINDOW_FRAME' in os.environ: left, top, width, height = (float(x) for x in os.environ['TIDE_WINDOW_FRAME'].split(',')) # image_window_frame. print left, top, width, height image_window_left = left + width + 20 image_window_top = top + height/2 + 180 self.image_window.cascadeTopLeftFromPoint_(CGPointMake(image_window_left, image_window_top)) else: self.image_window.center() def window_did_close(notification): app.terminate_(None) NSNotificationCenter.defaultCenter().addObserverForName_object_queue_usingBlock_( "NSWindowDidCloseNotification", self.image_window, None, window_did_close)
def bookmark_(self, notification): self.statusitem.setImage_(self.iconBook) NSNotificationCenter.defaultCenter().postNotificationName_object_('recordBookmark',self) s = objc.selector(self.changeIcon,signature='v@:') self.screenshotTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(3, self, s, None, False)
def changedMaxScreenshot_(self, sender): NSNotificationCenter.defaultCenter().postNotificationName_object_( 'changedMaxScreenshotPref', self)
def clearData_(self, sender): NSNotificationCenter.defaultCenter().postNotificationName_object_( 'clearData', self)
def changedExperienceRate_(self, sender): NSNotificationCenter.defaultCenter().postNotificationName_object_( 'changedExperiencePref', self)
def addObservers(self): # Listen for events from the Preferences window s = objc.selector(self.checkMaxScreenshotOnPrefChange_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'changedMaxScreenshotPref', None) s = objc.selector(self.checkExperienceOnPrefChange_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'changedExperiencePref', None) s = objc.selector(self.toggleScreenshotMenuTitle_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'changedScreenshot', None) s = objc.selector(self.clearData_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'clearData', None) # Listen for events from the Experience sampling window s = objc.selector(self.gotExperience_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'experienceReceived', None) s = objc.selector(self.getPriorExperiences_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'getPriorExperiences', None) # Listen for events from the Debriefer window s = objc.selector(self.getDebriefExperiences_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'getDebriefExperiences', None) s = objc.selector(self.recordDebrief_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'recordDebrief', None) s = objc.selector(self.populateDebriefWindow_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'populateDebriefWindow', None) s = objc.selector(self.queryMetadata_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'queryMetadata', None) # Listen for events thrown by the Status bar menu s = objc.selector(self.checkLoops_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'checkLoops', None) s = objc.selector(self.recordBookmark_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'recordBookmark', None) s = objc.selector(self.noteRecordingState_,signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'noteRecordingState', None) # Listen for events from Sniff Cocoa s = objc.selector(self.checkDrive_,signature='v@:') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'checkDrive_', None) # Listen for close of Selfspy s = objc.selector(self.gotCloseNotification_,signature='v@:') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, s, 'closeNotification', None)
def changedMaxScreenshot_(self,sender): NSNotificationCenter.defaultCenter().postNotificationName_object_('changedMaxScreenshotPref',self)
DataModelVersionDict = NSDictionary.dictionaryWithContentsOfFile_(pathname+"/Aperture.aplib/DataModelVersion.plist") # d1.update(Conversion.pythonCollectionFromPropertyList(ns_dict)) print DataModelVersionDict['databaseUuid'] print DataModelVersionDict # # begin # nc = NSNotificationCenter.defaultCenter() q = 'kMDItemKind = "Aperture Library"' query = do_metadata_query(q) n = query.resultCount() for i in range(n): item = query.resultAtIndex_(i) d1 = item.valuesForAttributes_( [ 'kMDItemFSName', 'kMDItemDisplayName', 'kMDItemPath', 'kMDItemKind', 'kMDItemContentType', 'kMDItemDateAdded',
def recordText_(self, sender): message_value = self.experienceText.stringValue() NSLog('Received experience message of: ' + message_value) NSNotificationCenter.defaultCenter().postNotificationName_object_('experienceReceived',self) self.expController.close()
def setIgnoredAndClose_(self, notification): self.ignored = True NSNotificationCenter.defaultCenter().postNotificationName_object_('experienceReceived',self) self.expController.close()
def initWithFrame_(self, frameRect): self = super(FontSampleDisplayView, self).initWithFrame_(frameRect) dnc = NSNotificationCenter.defaultCenter() dnc.addObserver_selector_name_object_(self, "redisplay:", NSUserDefaultsDidChangeNotification, None) return self
def takeExperienceScreenshot_(self,sender): NSNotificationCenter.defaultCenter().postNotificationName_object_('takeExperienceScreenshot',self)
def initWithFrame_(self, frameRect): self = super(FontSampleDisplayView, self).initWithFrame_(frameRect) dnc = NSNotificationCenter.defaultCenter() dnc.addObserver_selector_name_object_( self, "redisplay:", NSUserDefaultsDidChangeNotification, None) return self
def clearData_(self,sender): NSNotificationCenter.defaultCenter().postNotificationName_object_('clearData',self)
def awakeFromNib(self): # Register a transformer object for easy generation of # human-readable priority strings # # See CalPriorityToStringTransformer implementation below prioTransformer = CalPriorityToStringTransformer.alloc().init() NSValueTransformer.setValueTransformer_forName_( prioTransformer, "CalPriorityToStringTransformer") # Register for notifications on calendars, events and tasks so we can # update the GUI to reflect any changes beneath us NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, 'calendarsChanged:', CalCalendarsChangedExternallyNotification, None) NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, 'calendarsChanged:', CalCalendarsChangedNotification, None) NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, 'eventsChanged:', CalEventsChangedExternallyNotification, None) NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, 'eventsChanged:', CalEventsChangedNotification, None) NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, 'tasksChanged:', CalTasksChangedExternallyNotification, None) NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, 'tasksChanged:', CalTasksChangedNotification, None)
def changedExperienceRate_(self,sender): NSNotificationCenter.defaultCenter().postNotificationName_object_('changedExperiencePref',self)
def addObservers(self): # Listen for events from the Preferences window s = objc.selector(self.checkMaxScreenshotOnPrefChange_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'changedMaxScreenshotPref', None) s = objc.selector(self.checkExperienceOnPrefChange_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'changedExperiencePref', None) s = objc.selector(self.toggleScreenshotMenuTitle_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'changedScreenshot', None) s = objc.selector(self.clearData_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'clearData', None) # Listen for events from the Experience sampling window s = objc.selector(self.gotExperience_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'experienceReceived', None) s = objc.selector(self.getPriorExperiences_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'getPriorExperiences', None) # Listen for events from the Debriefer window s = objc.selector(self.getDebriefExperiences_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'getDebriefExperiences', None) s = objc.selector(self.recordDebrief_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'recordDebrief', None) s = objc.selector(self.populateDebriefWindow_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'populateDebriefWindow', None) s = objc.selector(self.queryMetadata_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'queryMetadata', None) s = objc.selector(self.getAppsAndWindows_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'getAppsAndWindows', None) s = objc.selector(self.getProcessTimes_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'getProcessTimes', None) s = objc.selector(self.getProcessNameFromID_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'getProcessNameFromID', None) # Listen for events thrown by the Status bar menu s = objc.selector(self.checkLoops_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'checkLoops', None) s = objc.selector(self.recordBookmark_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'recordBookmark', None) s = objc.selector(self.noteRecordingState_, signature='v@:@') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'noteRecordingState', None) # Listen for events from Sniff Cocoa s = objc.selector(self.checkDrive_, signature='v@:') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'checkDrive_', None) # Listen for close of Selfspy s = objc.selector(self.gotCloseNotification_, signature='v@:') NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( self, s, 'closeNotification', None)