示例#1
0
    def createPeers(self):
        for p in self._dynamicPeers: p.destroy(remove=True)

        self._dynamicPeers = []

        observer = House.observer()

        for dct in self._peers:
            name = dct['name']
            if name is None or name == "None": continue

            args = {}
            if 'config' in dct: args = dct['config']

            if not args:
                try:
                    obj = observer.peer(name, self._name)
                except Exception as e:
                    FX.crit("Exception while creating instance of", name)
                    import traceback 
                    traceback.print_exc(file=sys.stdout)

            elif isinstance(args, dict):
                lst = ()

                obj = observer.peer(name, self._name, *lst, **args)

            if not obj:
                FX.crit("Error creating peer", name, "for room", self._name, "with options", args)
            else:
                FX.info("Successfully created peer", name, "for room", self._name)
                self._dynamicPeers.append(obj)
示例#2
0
    def __dequeue(self):
        calls = []
        statefullCnt = 0

        for pillow in self._statefullQueue:
            if pillow not in self._statefullPillows: continue

            for ident, (args, ka) in self._statefullPillows[pillow].items():
                statefullCnt += len(self._statefullQueue[pillow])

                for catcher, passThrower in self._statefullQueue[pillow]:
                    if passThrower and 'me' in ka:
                        call = (catcher, args, {"thrower":ka['me']})
                    else:
                        call = (catcher, args, {})

                    calls.append(call)

        self._statefullQueue = {}

        for call in self._normalQueue:
            calls.append(call)

        # print "[", self._name, "] Queue sizes:", statefullCnt, len(self._normalQueue) 

        self._normalQueue = []

        for catcher, args, ka in calls: 
            try:
                catcher(*args, **ka)
            except Exception as e:
                FX.crit("Exception while throwing pillow")
                import traceback 
                traceback.print_exc(file=sys.stdout)

        self._dequeueCall = None
        if len(self._statefullQueue) + len(self._normalQueue) > 0: self.__dequeueRequest()
    def __init__(self, appName = 'example', checkRoom = None, suggest = False, options=None):
        splash = None

        FXUI.app = QtGui.QApplication(sys.argv)
        FXUI.app.setApplicationName("wallaby - " + appName)

        for s in ['16', '32', '64', '128', '256']:
            FXUI.app.setWindowIcon(QtGui.QIcon(QtGui.QPixmap(':/icons/images/wallaby_logo_' + s + '.png')))

        pixmap = QtGui.QPixmap(":/images/images/wallaby_splash.png")
        splash = QtGui.QSplashScreen(pixmap)
        splash.show()
        splash.raise_()
        FXUI.app.processEvents()

        if USES_PYSIDE or FXUI.qt4reactor:
            print "Install qt4reactor. USES_PYSIDE =", USES_PYSIDE
            import wallaby.frontends.qt.reactor.qt4reactor as qtreactor
            qtreactor.install()
        else:
            threadedselect.install()
             
            from twisted.internet import reactor
            ii = Interleaver()
            reactor.interleave(ii.toInterleave)
            reactor.suggestThreadPoolSize(50)

        FXUI.mineIcon = QtGui.QIcon(':/icons/images/mine.png')
        FXUI.theirsIcon = QtGui.QIcon(':/icons/images/theirs.png')

        tapp = twisted.application.service.Application("gui")
        service  = FXLogger('wallaby.log')
        service.setServiceParent(tapp)
        service.startService()

        FX.appModule = 'wallaby.apps.' + appName

        try:
            from twisted.plugin import getCache
            pkg = __import__(FX.appModule, globals(), locals(), ["*"], 0)
            if pkg is not None and len(pkg.__path__) > 0 and os.path.exists(pkg.__path__[0]):
                FX.appPath = pkg.__path__[0]
            else:
                FX.appPath = os.path.join(".", "wallaby", "apps", appName)
        except:
            FX.appPath = os.path.join(".", "wallaby", "apps", appName)

        FXUI.css = None

        try:
            print "importing", options.module, "from", FX.appModule
            if options.module == "WallabyApp2" and os.path.exists(os.path.join(FX.appPath, "mainWindow.py")):
                mod = FX.imp(FX.appModule + '.mainWindow', False)
                if os.path.exists(os.path.join(FX.appPath, "mainWindow.css")):
                    FXUI.css = open(os.path.join(FX.appPath, "mainWindow.css")).read()
            else:
                module = options.module
                module = module[0].lower() + module[1:]
                mod = FX.imp(FX.appModule + '.' + module, False)

                if os.path.exists(os.path.join(FX.appPath, module + ".css")):
                    FXUI.css = open(os.path.join(FX.appPath, module + ".css")).read()
        except:
            mod = None

        if mod == None:
            FX.crit('Module', FX.appModule, 'not found')
            reactor.callWhenRunning(self.myQuit)
            if USES_PYSIDE or FXUI.qt4reactor: reactor.runReturn()
            FXUI.app.exec_()
            return

        try:
            FXUI.mainWindow = mod.MainWindow(self.myQuit, options)
            if FXUI.css is not None:
                FXUI.app.setStyle("plastique")
                FXUI.mainWindow.setStyleSheet(FXUI.css)
        except Exception as e:
            import traceback
            traceback.print_exc(file=sys.stdout)

            from twisted.internet import reactor
            reactor.callWhenRunning(self.myQuit)
            if USES_PYSIDE or FXUI.qt4reactor: reactor.runReturn()
            FXUI.app.exec_()
            return

        FXUI.mainWindow.setSplash(splash)

        from twisted.internet import reactor
        reactor.callWhenRunning(self.run, mod, options, checkRoom)

        FXUI.mainWindow.enabled = False
        FXUI.mainWindow.configure()
        FXUI.mainWindow.show()
        FXUI.mainWindow.raise_()

        signal.signal(signal.SIGINT, self.sigint_handler)
        signal.signal(signal.SIGTERM, self.sigint_handler)

        # self.gc = GarbageCollector(FXUI.mainWindow, True)

        if USES_PYSIDE or FXUI.qt4reactor: reactor.runReturn()
        FXUI.app.exec_()
示例#4
0
    def _throw(self, pillow, feathers="", **ka):
        try:
            wcPeers     = None
            normalPeers = None
            singlePeers = None

            if pillow == None: 
                # print "WARNING - skipping none pillow"
                return

            # decode json feathers
            if feathers != None and isinstance(feathers, (str, unicode)) and feathers.startswith('json:'):
                jsonString = '{"object":' + feathers.replace('json:', '', 1) + '}'
                try: 
                    import json
                    feathers = json.loads(jsonString)
                    feathers = feathers["object"]
                except Exception as e:
                    print "Error while parsing json", jsonString, e
                    feathers = None

            # save statefull pillow for resending
            if pillow.endswith("!"):
                identifier = "__any__"
                try: identifier = feathers.identifier()
                except: pass

                if pillow not in self._statefullPillows: self._statefullPillows[pillow] = {}

                self._statefullPillows[pillow][identifier] = ((pillow, feathers), ka)
                self._statefullQueue[pillow] = []

            # create copies of peers to avoid race conditions
            # FIXME: this can result in calls of unallocated QObject methods!!! 
            if "*" in self._pillows:
                wcPeers = copy.copy(self._pillows["*"])

            if pillow in self._pillows:
                normalPeers = copy.copy(self._pillows[pillow])

            if pillow in self._singlePillows:
                singlePeers = copy.copy(self._singlePillows[pillow])
                del self._singlePillows[pillow]

            for peers in (wcPeers, normalPeers, singlePeers):
                if peers != None and pillow != Room.Out.NoHandlerFound:
                    for (catcher, passThrower) in peers:
                        if passThrower and 'me' in ka:
                            self.__enqueue(catcher, pillow, feathers, passThrower=passThrower, thrower=ka['me'])
                        else:
                            self.__enqueue(catcher, pillow, feathers, passThrower=passThrower)

            # Send a "NoHandlerFound" pillow if not already handled
            if normalPeers == None and singlePeers == None and pillow != Room.Out.NoHandlerFound:
                self._throw(Room.Out.NoHandlerFound, pillow, thrower=self)

        except Exception as e:
            FX.crit("Exception while throwing pillow", pillow)
            import traceback 
            traceback.print_exc(file=sys.stdout)

        self.__dequeueRequest()