コード例 #1
0
    def loadUIFiles(self):
        self._sheetPrototypes = {}

        prefs = []

        import wallaby.frontends as frontends
        from twisted.plugin import getCache

        for p in FX.packagePath(FX.appModule + ".prefs"): prefs.append(p)
        for frontend in getCache(frontends):
            for p in FX.packagePath("wallaby.frontends." + frontend + ".prefs"): prefs.append(p)

        import os
        for path in prefs:
            root = re.sub(r'[/\\]','.', path).replace('..', '')
            root = re.sub(r'^.*wallaby\.', 'wallaby.', root)
            files = os.listdir(path)
 
            for file in files:
                if '.py' in file and '.pyc' not in file and 'UI_' in file:
                    basename, ext = os.path.splitext(file)
                    if ext == '.py':
                        mod = FX.imp(root + '.' + basename)
                        print "Loading prefs sheet", root + '.' + basename, mod
                        if mod == None: continue
   
                        import string 
                        cls = basename[0] + string.lower(basename[1]) + basename[2] + string.upper(basename[3]) + basename[4:]
    
                        sheetName = unicode(basename.replace('UI_', ''))
    
                        if not cls in mod.__dict__: continue
                        self._sheetPrototypes[sheetName] = mod.__dict__[cls]
コード例 #2
0
ファイル: room.py プロジェクト: FreshXOpenSource/wallaby-base
    def get(room):
        if room in (None, ""): room = "None"

        if not room in House.rooms:
            if FX.appModule:
                app = FX.appModule
                if room in ("__CONFIG__", "__WIDGETQUERY__"): app = "wallaby.apps.inspector"

                try:
                    from twisted.plugin import getCache
                    pkg = __import__(app + '.rooms', globals(), locals(), ["*"], 0)
                    modules = getCache(pkg)

                    if room.lower() in modules:
                        mod = FX.imp(app + '.rooms.' + room.lower())
                        if mod:
                            cls = room.capitalize()

                            if cls in mod.__dict__:
                                ctx = House.rooms[room] = mod.__dict__[cls](room)
                                return ctx
                except:
                    pass
                        
            # No room template found. Create generic room
            House.rooms[room] = Room(room)

        return House.rooms[room]
コード例 #3
0
    def scan(self, peers=None):
        fqPeers = []

        if peers is None:
            import wallaby.pf.peer as peers
            from twisted.plugin import getCache
            peers = getCache(peers)
            root = "wallaby.pf.peer"

            for peer in peers:
                fqPeers.append(root + "." + peer)
        else:
            fqPeers = peers

        for fqPeer in fqPeers:
            
            mod = FX.imp(fqPeer)
            root, basename = fqPeer.rsplit('.', 1)

            if mod == None: continue

            cls = string.upper(basename[0]) + basename[1:]                       

            if not cls in mod.__dict__: continue

            fqn = root + '.' + basename + '.' + cls

            self._fqn[cls] = fqn

            if re.search(r"\.room", root) != None:
                self._rooms[cls] = mod.__dict__[cls]
            else:
                self._peers[cls] = mod.__dict__[cls]

            self._objectTypes[fqn] = mod.__dict__[cls].ObjectType

            for base in mod.__dict__[cls].__bases__:
                fqBase = base.__module__ + '.' + base.__name__
                if not fqBase in self._extendedBy:
                    self._extendedBy[fqBase] = set()

                self._extendedBy[fqBase].add(fqn)

                if not fqn in self._bases:
                    self._bases[fqn] = set()

                self._bases[fqn].add(fqBase)

            if 'Receiving' in mod.__dict__[cls].__dict__:
                for fqa in mod.__dict__[cls].Receiving:
                    pillow = None
                    try:
                        pillow = fqa.split('.')[2]
                    except:
                        print "Split error:", fqa

                    pillow = pillow.replace('!', '')
                    fqa = fqa.replace('!', '')

                    if not pillow in self._inBoundPillows: self._inBoundPillows[pillow] = []
                    if not fqa in self._inBoundPillowsFQ: self._inBoundPillowsFQ[fqa] = []
                    if not fqn in self._inBoundPillowsPerPeer: self._inBoundPillowsPerPeer[fqn] = []
                    self._inBoundPillows[pillow].append(fqn)
                    self._inBoundPillowsFQ[fqa].append(fqn)
                    self._inBoundPillowsPerPeer[fqn].append(fqa)


            for pillow in mod.__dict__[cls].InPillows:
                pillow = pillow.replace('!', '')

                fqa = cls + '.In.' + pillow
                fqa = fqa.replace('!', '')

                if not pillow in self._inBoundPillows: self._inBoundPillows[pillow] = []
                if not fqa in self._inBoundPillowsFQ: self._inBoundPillowsFQ[fqa] = []
                if not fqn in self._inBoundPillowsPerPeer: self._inBoundPillowsPerPeer[fqn] = []
                self._inBoundPillows[pillow].append(fqn)
                self._inBoundPillowsFQ[fqa].append(fqn)
                self._inBoundPillowsPerPeer[fqn].append(fqa)

            if 'Sending' in mod.__dict__[cls].__dict__:
                for fqa in mod.__dict__[cls].Sending:
                    pillow = None
                    try:
                        pillow = fqa.split('.')[2]
                    except:
                        print "Split error:", fqa

                    fqa = fqa.replace('!', '')
                    pillow = pillow.replace('!', '')

                    if not pillow in self._outBoundPillows: self._outBoundPillows[pillow] = []
                    if not fqa in self._outBoundPillowsFQ: self._outBoundPillowsFQ[fqa] = []
                    if not fqn in self._outBoundPillowsPerPeer: self._outBoundPillowsPerPeer[fqn] = []
                    self._outBoundPillows[pillow].append(fqn)
                    self._outBoundPillowsFQ[fqa].append(fqn)
                    self._outBoundPillowsPerPeer[fqn].append(fqa)

            for pillow in mod.__dict__[cls].OutPillows:
                pillow = pillow.replace('!', '')

                fqa = cls + '.Out.' + pillow
                fqa = fqa.replace('!', '')
                if not pillow in self._outBoundPillows: self._outBoundPillows[pillow] = []
                if not fqa in self._outBoundPillowsFQ: self._outBoundPillowsFQ[fqa] = []
                if not fqn in self._outBoundPillowsPerPeer: self._outBoundPillowsPerPeer[fqn] = []
                self._outBoundPillows[pillow].append(fqn)
                self._outBoundPillowsFQ[fqa].append(fqn)
                self._outBoundPillowsPerPeer[fqn].append(fqa)
コード例 #4
0
    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_()
コード例 #5
0
    def loadUIFiles(self):
        # Do not reload widgets if not changed
        if self.sheets is None or self.sheets == self._lastSheets: return
        self._lastSheets = self.sheets

        self.clear()

        isheets = []

        self._sheetPrototypes = {}

        import wallaby.frontends as frontends
        from twisted.plugin import getCache

        for p in FX.packagePath(FX.appModule + ".isheet"): isheets.append(p)
        for frontend in getCache(frontends):
            for p in FX.packagePath("wallaby.frontends." + frontend + ".isheet"): isheets.append(p)

        import os
        for path in isheets:
            root = re.sub(r'[/\\]','.', path).replace('..', '')
            root = re.sub(r'^.*wallaby\.', 'wallaby.', root)
            files = os.listdir(path)
            for file in files:
                if '.py' in file and '.pyc' not in file and 'UI_' in file:
                    basename, ext = os.path.splitext(file)

                    if ext != '.py': continue

                    mod = FX.imp(root + '.' + basename)
                    if mod == None: continue

                    cls = basename[0] + string.lower(basename[1]) + basename[2] + string.upper(basename[3]) + basename[4:]
    
                    sheetName = unicode(basename.replace('UI_', ''))

                    sheetCache = None

                    if sheetName in self._sheetPrototypes: 
                        continue

                    if re.match(self.sheets, sheetName) is None: 
                        continue

                    if not self.isMultiPage():
                        p = self.parent()
                        while p != None and (not isinstance(p, Container) or not p.isMultiPage()):
                            p = p.parent()

                        if p is not None:
                            sheetCache = p.sheetCache

                            if sheetName in sheetCache:
                                self._sheet = sheetCache[sheetName]
                                return

                    if not cls in mod.__dict__:
                        for key, val in mod.__dict__.items():
                            if key.startswith("Ui_"):
                                cls = key
                                break

                    if not cls in mod.__dict__: continue

                    self._sheetPrototypes[sheetName] = mod.__dict__[cls]

                    sheet = QtGui.QWidget(self)
                    sheet.ui = self._sheetPrototypes[sheetName]()
                    sheet.ui.setupUi(sheet)
                    sheet.setObjectName(sheetName + "Sheet") 

                    if sheetCache is not None:
                        self._sheet = sheet
                        sheetCache[sheetName] = sheet
                        # also add the cached sheet to the current widget
                        # to allow nested widgets to also be loaded

                    self.addChildWidget(sheet)