Exemple #1
0
def create_main_surface():
    pygame.init()
    surface = pygame.display.set_mode((320, 240))

    try:
        SDL_QuartzWindow = objc.lookUpClass('SDL_QuartzWindow')
    except objc.nosuchclass_error:
        # SDL2 doesn't have this class or need the runtime patch
        pass
    else:

        class SDL_QuartzWindow(objc.Category(SDL_QuartzWindow)):
            def canBecomeKeyWindow(self):
                return True

            def canBecomeMainWindow(self):
                return True

            def acceptsFirstResponder(self):
                return True

            def becomeFirstResponder(self):
                return True

            def resignFirstResponder(self):
                return True

    global window_controller
    window_controller = WindowController()

    # run the run loop just once to finish setting up the window
    NSRunLoop.mainRunLoop().runMode_beforeDate_(NSDefaultRunLoopMode,
                                                NSDate.date())

    return surface
Exemple #2
0
def create_main_surface():
    pygame.init()
    surface = pygame.display.set_mode((320, 240))

    SDL_QuartzWindow = objc.lookUpClass('SDL_QuartzWindow')

    class SDL_QuartzWindow(objc.Category(SDL_QuartzWindow)):
        def canBecomeKeyWindow(self):
            return True

        def canBecomeMainWindow(self):
            return True

        def acceptsFirstResponder(self):
            return True

        def becomeFirstResponder(self):
            return True

        def resignFirstResponder(self):
            return True

    global window_controller
    window_controller = WindowController()

    # run the run loop just once to finish setting up the window
    NSRunLoop.mainRunLoop().runMode_beforeDate_(NSDefaultRunLoopMode, NSDate.date())

    return surface
Exemple #3
0
    def initWithDocument_andConfig_(self, document, config):
        self = super(LLDBPlugin,
                     self).initWithDocument_andConfig_(document, config)

        # setup debugger
        self.debugger = lldb.SBDebugger.Create()
        self.debugger.SetAsync(True)
        self.debugger.SetTerminalWidth(
            80)  # XXX: should really be set in resize handler

        self.interpreter = self.debugger.GetCommandInterpreter()
        self.listener = self.debugger.GetListener()
        self.listener.StartListeningForEvents(
            self.interpreter.GetBroadcaster(),
            lldb.SBCommandInterpreter.eBroadcastBitThreadShouldExit
            | lldb.SBCommandInterpreter.eBroadcastBitResetPrompt
            | lldb.SBCommandInterpreter.eBroadcastBitQuitCommandReceived
            | lldb.SBCommandInterpreter.eBroadcastBitAsynchronousOutputData
            | lldb.SBCommandInterpreter.eBroadcastBitAsynchronousErrorData)

        self.event_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(
            0.05, self, '_event_handler', None, YES)
        loop = NSRunLoop.currentRunLoop()
        loop.addTimer_forMode_(self.event_timer, NSDefaultRunLoopMode)

        self.first_stop = True
        self.launch_info = None
        return self
Exemple #4
0
def main():
    configure_logging()

    global CRANKD_OPTIONS, CRANKD_CONFIG

    CRANKD_OPTIONS = process_commandline()
    CRANKD_CONFIG = load_config(CRANKD_OPTIONS)

    if "NSDistributed" in CRANKD_CONFIG:
        add_distributed_notifications(CRANKD_CONFIG["NSDistributed"])

    if "NSWorkspace" in CRANKD_CONFIG:
        add_workspace_notifications(CRANKD_CONFIG['NSWorkspace'])

    if "SystemConfiguration" in CRANKD_CONFIG:
        add_sc_notifications(CRANKD_CONFIG['SystemConfiguration'])

    if "FSEvents" in CRANKD_CONFIG:
        add_fs_notifications(CRANKD_CONFIG['FSEvents'])

    if "NSNetService" in CRANKD_CONFIG:
        add_mdns_notifications(CRANKD_CONFIG['NSNetService'])

    if "CLLocation" in CRANKD_CONFIG:
        add_cl_notifications(CRANKD_CONFIG['CLLocation'])

    # We reuse our FSEvents code to watch for changes to our files and
    # restart if any of our libraries have been updated:
    add_conditional_restart(
        CRANKD_OPTIONS.config_file,
        "Configuration file %s changed" % CRANKD_OPTIONS.config_file)
    for m in filter(lambda i: i and hasattr(i, '__file__'),
                    sys.modules.values()):
        if m.__name__ == "__main__":
            msg = "%s was updated" % m.__file__
        else:
            msg = "Module %s was updated" % m.__name__

        add_conditional_restart(m.__file__, msg)

    signal.signal(signal.SIGHUP, partial(restart, "SIGHUP received"))

    start_fs_events()

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 2.0, 0, 0,
                             timer_callback, None), kCFRunLoopCommonModes)

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        logging.info("KeyboardInterrupt received, exiting")

    sys.exit(0)
Exemple #5
0
def main():
    configure_logging()
    
    global CRANKD_OPTIONS, CRANKD_CONFIG
    
    CRANKD_OPTIONS = process_commandline()
    CRANKD_CONFIG  = load_config(CRANKD_OPTIONS)
    
    if "NSDistributed" in CRANKD_CONFIG:
        add_distributed_notifications(CRANKD_CONFIG["NSDistributed"])
    
    if "NSWorkspace" in CRANKD_CONFIG:
        add_workspace_notifications(CRANKD_CONFIG['NSWorkspace'])
    
    if "SystemConfiguration" in CRANKD_CONFIG:
        add_sc_notifications(CRANKD_CONFIG['SystemConfiguration'])
    
    if "FSEvents" in CRANKD_CONFIG:
        add_fs_notifications(CRANKD_CONFIG['FSEvents'])
    
    if "NSNetService" in CRANKD_CONFIG:
        add_mdns_notifications(CRANKD_CONFIG['NSNetService'])
    
    if "CLLocation" in CRANKD_CONFIG:
        add_cl_notifications(CRANKD_CONFIG['CLLocation'])
    
    # We reuse our FSEvents code to watch for changes to our files and
    # restart if any of our libraries have been updated:
    add_conditional_restart(CRANKD_OPTIONS.config_file, "Configuration file %s changed" % CRANKD_OPTIONS.config_file)
    for m in filter(lambda i: i and hasattr(i, '__file__'), sys.modules.values()):
        if m.__name__ == "__main__":
            msg = "%s was updated" % m.__file__
        else:
            msg = "Module %s was updated" % m.__name__
        
        add_conditional_restart(m.__file__, msg)
    
    signal.signal(signal.SIGHUP, partial(restart, "SIGHUP received"))
    
    start_fs_events()
    
    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 2.0, 0, 0, timer_callback, None),
        kCFRunLoopCommonModes
    )
    
    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        logging.info("KeyboardInterrupt received, exiting")
    
    sys.exit(0)
def main():
    add_workspace_notifications(load_workspace_notifications())

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 2.0, 0, 0,
                             timer_callback, None), kCFRunLoopCommonModes)

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        logging.info("KeyboardInterrupt received, exiting")

    sys.exit(0)
def main():
    global CRANKD_OPTIONS, CRANKD_CONFIG
    CRANKD_OPTIONS = process_commandline()
    CRANKD_CONFIG  = load_config(CRANKD_OPTIONS)

    # We replace the initial program name with one which won't break if relative paths are used:
    sys.argv[0]    = os.path.realpath(sys.argv[0])

    configure_logging()

    logging.info("Loaded configuration from %s" % CRANKD_OPTIONS.config_file)

    if "NSWorkspace" in CRANKD_CONFIG:
        add_workspace_notifications(CRANKD_CONFIG['NSWorkspace'])

    if "SystemConfiguration" in CRANKD_CONFIG:
        add_sc_notifications(CRANKD_CONFIG['SystemConfiguration'])

    if "FSEvents" in CRANKD_CONFIG:
        add_fs_notifications(CRANKD_CONFIG['FSEvents'])

    # We reuse our FSEvents code to watch for changes to our files and
    # restart if any of our libraries have been updated:
    add_conditional_restart(CRANKD_OPTIONS.config_file, "Configuration file %s changed" % CRANKD_OPTIONS.config_file)
    for (m_name, m_file) in [(k, v) for k, v in sys.modules.iteritems() if hasattr(v, '__file__')]:
        add_conditional_restart(m_file.__file__, "Module %s was updated" % m_name)

    signal.signal(signal.SIGHUP, partial(restart, "SIGHUP received"))

    start_fs_events()

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 5.0, 0, 0, timer_callback, None),
        kCFRunLoopCommonModes
    )

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        logging.info("KeyboardInterrupt received, exiting")

    sys.exit(0)
def main():
    add_workspace_notifications(load_workspace_notifications())

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 2.0, 0, 0, timer_callback, None),
        kCFRunLoopCommonModes
    )

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        logging.info("KeyboardInterrupt received, exiting")

    sys.exit(0)
Exemple #9
0
def start_fs_events():
    stream_ref = FSEventStreamCreate(
        None,                               # Use the default CFAllocator
        fsevent_callback,
        None,                               # We don't need a FSEventStreamContext
        FS_WATCHED_FILES.keys(),
        kFSEventStreamEventIdSinceNow,      # We only want events which happen in the future
        1.0,                                # Process events within 1 second
        0                                   # We don't need any special flags for our stream
    )

    if not stream_ref:
        raise RuntimeError("FSEventStreamCreate() failed!")

    FSEventStreamScheduleWithRunLoop(stream_ref, NSRunLoop.currentRunLoop().getCFRunLoop(), kCFRunLoopDefaultMode)

    if not FSEventStreamStart(stream_ref):
        raise RuntimeError("Unable to start FSEvent stream!")

    logging.debug("FSEventStream started for %d paths: %s" % (len(FS_WATCHED_FILES), ", ".join(FS_WATCHED_FILES)))
Exemple #10
0
def start_fs_events():
    stream_ref = FSEventStreamCreate(
        None,                               # Use the default CFAllocator
        fsevent_callback,
        None,                               # We don't need a FSEventStreamContext
        FS_WATCHED_FILES.keys(),
        kFSEventStreamEventIdSinceNow,      # We only want events which happen in the future
        1.0,                                # Process events within 1 second
        0                                   # We don't need any special flags for our stream
    )

    if not stream_ref:
        raise RuntimeError("FSEventStreamCreate() failed!")

    FSEventStreamScheduleWithRunLoop(stream_ref, NSRunLoop.currentRunLoop().getCFRunLoop(), kCFRunLoopDefaultMode)

    if not FSEventStreamStart(stream_ref):
        raise RuntimeError("Unable to start FSEvent stream!")

    logging.debug("FSEventStream started for %d paths: %s" % (len(FS_WATCHED_FILES), ", ".join(FS_WATCHED_FILES)))
Exemple #11
0
    keys = sc_config.keys()

    try:
        for key in keys:
            SC_HANDLERS[key] = get_callable_for_event(key, sc_config[key], context="SystemConfiguration: %s" % key)
    except AttributeError, exc:
        print  >> sys.stderr, "Error configuring SystemConfiguration events: %s" % exc
        sys.exit(1)

    store = get_sc_store()

    SCDynamicStoreSetNotificationKeys(store, None, keys)

    # Get a CFRunLoopSource for our store session and add it to the application's runloop:
    CFRunLoopAddSource(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        SCDynamicStoreCreateRunLoopSource(None, store, 0),
        kCFRunLoopCommonModes
    )

    log_list("Listening for these SystemConfiguration events: %s", keys)


def add_fs_notifications(fs_config):
    for path in fs_config:
        add_fs_notification(path, get_callable_for_event(path, fs_config[path], context="FSEvent: %s" % path))


def add_fs_notification(f_path, callback):
    """Adds an FSEvent notification for the specified path"""
    path = os.path.realpath(os.path.expanduser(f_path))
Exemple #12
0
    sc_keys = ['State:/Network/Global/IPv4', 'State:/Network/Global/IPv6']

    store = SCDynamicStoreCreate(None, "global-network-change",
                                 network_state_changed, None)
    SCDynamicStoreSetNotificationKeys(store, None, sc_keys)

    CFRunLoopAddSource(
        # NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopGetCurrent(),
        SCDynamicStoreCreateRunLoopSource(None, store, 0),
        kCFRunLoopCommonModes)

    # signal.signal(signal.SIGHUP, partial(quit, "SIGHUP received"))

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), timer_interval,
                             0, 0, timer_callback, None),
        kCFRunLoopCommonModes)

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        print "KeyboardInterrupt received, exiting"

    sys.exit(0)
    keys = sc_config.keys()

    try:
        for key in keys:
            SC_HANDLERS[key] = get_callable_for_event(
                key, sc_config[key], context="SystemConfiguration: %s" % key)
    except AttributeError, exc:
        print >> sys.stderr, "Error configuring SystemConfiguration events: %s" % exc
        sys.exit(1)

    store = get_sc_store()

    SCDynamicStoreSetNotificationKeys(store, None, keys)

    # Get a CFRunLoopSource for our store session and add it to the application's runloop:
    CFRunLoopAddSource(NSRunLoop.currentRunLoop().getCFRunLoop(),
                       SCDynamicStoreCreateRunLoopSource(None, store, 0),
                       kCFRunLoopCommonModes)

    log_list("Listening for these SystemConfiguration events: %s", keys)


def add_fs_notifications(fs_config):
    for path in fs_config:
        add_fs_notification(
            path,
            get_callable_for_event(path,
                                   fs_config[path],
                                   context="FSEvent: %s" % path))

query = decode(sys.argv[1])

f = open('vendor')
try:
	url = vendors[f.readline().rstrip()]
except Exception, e:
	url = vendors['google']
	f.close()	

dests = filter(lambda x:x!=u"", query.split(';',1))

if len(dests)<2:
	clm = LocationManager.alloc().init_with_thread(NSThread.currentThread())

	loop = NSRunLoop.currentRunLoop()

	loop.runMode_beforeDate_(NSDefaultRunLoopMode, NSDate.distantFuture())

	loc = clm.goodLocation

	if loc != None:
		latitude = unicode(loc.coordinate().latitude)
		longitude = unicode(loc.coordinate().longitude)
	clm.dealloc()
	if query.index(';') < 2:
		url = url.replace(u"{source}",latitude + u"," + longitude)
		url = url.replace(u"{destination}", dests[0])
	else: 
		url = url.replace(u"{destination}",latitude + u"," + longitude)
		url = url.replace(u"{source}", dests[0])