def _nestedRunLoopReaderUntilEOLchars_(self, eolchars): """ This makes the baby jesus cry. I want co-routines. """ app = NSApplication.sharedApplication() window = self.textView.window() self.setCharacterIndexForInput_(self.lengthOfTextView()) # change the color.. eh self.textView.setTypingAttributes_( {NSFontAttributeName: self.font(), NSForegroundColorAttributeName: self.codeColor()} ) while True: event = app.nextEventMatchingMask_untilDate_inMode_dequeue_( NSUIntegerMax, NSDate.distantFuture(), NSDefaultRunLoopMode, True ) if (event.type() == NSKeyDown) and (event.window() == window): eol = event.characters() if eol in eolchars: break app.sendEvent_(event) cl = self.currentLine() if eol == "\r": self.writeCode_("\n") return cl + eol
def softwareupdated_installhistory(start_date=None, end_date=None): '''Returns softwareupdated items from InstallHistory.plist that are within the given date range. (dates must be NSDates)''' start_date = start_date or NSDate.distantPast() end_date = end_date or NSDate.distantFuture() try: installhistory = FoundationPlist.readPlist(INSTALLHISTORY_PLIST) except FoundationPlist.FoundationPlistException: return [] return [item for item in installhistory if item.get('processName') == 'softwareupdated' and item['date'] >= start_date and item['date'] <= end_date]
def waituntil(conditionfunc, timeout=None): """ Waits until conditionfunc() returns true, or <timeout> seconds have passed. (If timeout=None, this waits indefinitely until conditionfunc() returns true.) Returns false if the process timed out, otherwise returns true. Note!! You must call interruptwait() when you know that conditionfunc() should be checked (e.g. if you are waiting for data and you know some data has arrived) so that this can check conditionfunc(); otherwise it will just continue to wait. (This allows the function to wait for an event that is sent by interruptwait() instead of polling conditionfunc().) This allows the caller to wait while the main event loop processes its events. This must be done for certain situations, e.g. to receive socket data or to accept client connections on a server socket, since IOBluetooth requires the presence of an event loop to run these operations. This function doesn't need to be called if there is something else that is already processing the main event loop, e.g. if called from within a Cocoa application. """ app = NSApplication.sharedApplication() starttime = time.time() if timeout is None: timeout = NSDate.distantFuture().timeIntervalSinceNow() if not isinstance(timeout, (int, float)): raise TypeError("timeout must be int or float, was %s" % \ type(timeout)) endtime = starttime + timeout while True: currtime = time.time() if currtime >= endtime: return False # use WAIT_MAX_TIMEOUT, don't wait forever in case of KeyboardInterrupt e = app.nextEventMatchingMask_untilDate_inMode_dequeue_(NSAnyEventMask, NSDate.dateWithTimeIntervalSinceNow_(min(endtime - currtime, WAIT_MAX_TIMEOUT)), NSDefaultRunLoopMode, True) if e is not None: if (e.type() == NSApplicationDefined and e.subtype() == LIGHTBLUE_NOTIFY_ID): if conditionfunc(): return True else: app.postEvent_atStart_(e, True)
def check_if_running(username): """ checks if self-control is already running. """ defaults = get_selfcontrol_settings(username) return defaults.has_key("BlockStartedDate") and not NSDate.distantFuture( ).isEqualToDate_(defaults["BlockStartedDate"])
NSKeyDown, NSKeyUp, NSMouseMoved, NSLeftMouseDown, NSSystemDefined, \ NSCommandKeyMask, NSPasteboard, NSStringPboardType, NSModalPanelRunLoopMode NSAnyEventMask = 0xffffffff from GUI import Globals, GApplications from GUI import application, export from GUI.GApplications import Application as GApplication from GUI import Event #------------------------------------------------------------------------------ Globals.ns_screen_height = None Globals.ns_last_mouse_moved_event = None Globals.pending_exception = None Globals.ns_application = None ns_distant_future = NSDate.distantFuture() #------------------------------------------------------------------------------ class Application(GApplication): # _ns_app _PyGui_NSApplication # _ns_pasteboard NSPasteboard # _ns_key_window Window _ns_menubar_update_pending = False _ns_files_opened = False _ns_using_clargs = False _ns_menus_updated = False def __init__(self, **kwds):
NSKeyDown, NSKeyUp, NSMouseMoved, NSLeftMouseDown, NSSystemDefined, \ NSCommandKeyMask, NSPasteboard, NSStringPboardType, NSModalPanelRunLoopMode NSAnyEventMask = 0xffffffff from GUI import Globals, GApplications from GUI import application, export from GUI.GApplications import Application as GApplication from GUI import Event #------------------------------------------------------------------------------ Globals.ns_screen_height = None Globals.ns_last_mouse_moved_event = None Globals.pending_exception = None Globals.ns_application = None ns_distant_future = NSDate.distantFuture() #------------------------------------------------------------------------------ class Application(GApplication): # _ns_app _PyGui_NSApplication # _ns_pasteboard NSPasteboard # _ns_key_window Window _ns_menubar_update_pending = False _ns_files_opened = False _ns_using_clargs = False _ns_menus_updated = False def __init__(self, **kwds): self._ns_app = Globals.ns_application
def check_if_running(username): """ checks if self-control is already running. """ defaults = get_selfcontrol_settings(username) return defaults.has_key("BlockStartedDate") and not NSDate.distantFuture().isEqualToDate_( defaults["BlockStartedDate"] )
def check_if_running(username): """ checks if self-control is already running and stops auto-selfcontrol if so. """ defaults = get_selfcontrol_settings(username) if not NSDate.distantFuture().isEqualToDate_(defaults["BlockStartedDate"]): syslog.syslog(syslog.LOG_ALERT, "SelfControl is already running, ignore current execution of Auto-SelfControl.") exit(2)