Exemple #1
0
class ExampleLoader(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_Form()
        self.cw = QtGui.QWidget()
        self.setCentralWidget(self.cw)
        self.ui.setupUi(self.cw)
        
        global examples
        self.populateTree(self.ui.exampleTree.invisibleRootItem(), examples)
        self.ui.exampleTree.expandAll()
        
        self.resize(900,500)
        self.show()
        self.ui.splitter.setSizes([150,750])
        self.ui.loadBtn.clicked.connect(self.loadFile)
        self.ui.exampleTree.currentItemChanged.connect(self.showFile)
        self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile)


    def populateTree(self, root, examples):
        for key, val in examples.iteritems():
            item = QtGui.QTreeWidgetItem([key])
            if isinstance(val, basestring):
                item.file = val
            else:
                self.populateTree(item, val)
            root.addChild(item)
            
    
    def currentFile(self):
        item = self.ui.exampleTree.currentItem()
        if hasattr(item, 'file'):
            global path
            return os.path.join(path, item.file)
        return None
    
    def loadFile(self):
        fn = self.currentFile()
        if fn is None:
            return
        if sys.platform.startswith('win'):
            os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, '"' + fn + '"')
        else:
            os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, fn)
        
            
    def showFile(self):
        fn = self.currentFile()
        if fn is None:
            self.ui.codeView.clear()
            return
        if os.path.isdir(fn):
            fn = os.path.join(fn, '__main__.py')
        text = open(fn).read()
        self.ui.codeView.setPlainText(text)
Exemple #2
0
 def __init__(self):
     QtGui.QMainWindow.__init__(self)
     self.ui = Ui_Form()
     self.cw = QtGui.QWidget()
     self.setCentralWidget(self.cw)
     self.ui.setupUi(self.cw)
     
     global examples
     self.populateTree(self.ui.exampleTree.invisibleRootItem(), examples)
     self.ui.exampleTree.expandAll()
     
     self.resize(900,500)
     self.show()
     self.ui.splitter.setSizes([150,750])
     self.ui.loadBtn.clicked.connect(self.loadFile)
     self.ui.exampleTree.currentItemChanged.connect(self.showFile)
     self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile)