示例#1
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.debug = False
        self.setObjectName("ExcelBrowserWidget")

        self.mainLayout = QtGui.QVBoxLayout()
        self.mainLayout.setSpacing(0)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.mainLayout)

        self.toolbar = QtGui.QToolBar()
        self.mainLayout.addWidget(self.toolbar, 0)

        tbg = xwidgets.ToolBarGroup(title="Selected Dir")
        self.toolbar.addWidget(tbg)

        buttSel = xwidgets.XToolButton(text="Select")
        self.toolbar.addWidget(buttSel)

        self.txtPath = QtGui.QLineEdit()
        tbg.addWidget(self.txtPath)
        if G.args.dev:
            self.txtPath.setText("/home/ogt/gstl_examples/35579")

        self.tree = QtGui.QTreeView()
        self.mainLayout.addWidget(self.tree, 30)

        self.dirModel = QtGui.QFileSystemModel()
        self.dirModel.setRootPath(self.txtPath.text())
        self.dirModel.setNameFilters(["*.xlsx"])

        self.tree.setModel(self.dirModel)
        self.tree.setRootIndex(self.dirModel.index(self.txtPath.text()))
        #print self.txtPath.text()

        if G.args.dev:
            ed = os.path.join(str(self.txtPath.text()), "ATTS")
            self.tree.expand(self.dirModel.index(ed))

        self.tree.setColumnWidth(0, 400)

        self.tree.doubleClicked.connect(self.on_tree_double_clicked)
示例#2
0
        if not self.index_at.isValid():
            # 空白处点击
            path = self.new_path
        else:
            # 非空白点击
            index = self.currentIndex()
            model = index.model()
            path = model.filePath(index)
        return path

    def _open_file(self, i):
        if self.model.isDir(i):
            indice = self.model.index(i.row(), 0, i.parent())
            archivo = self.model.filePath(indice)

    def join_path(self, start_path, end_path):
        return os.path.join(start_path, end_path)


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    treeView = Explorer()
    fileSystemModel = QtGui.QFileSystemModel(treeView)
    fileSystemModel.setReadOnly(False)
    root = fileSystemModel.setRootPath('C:/')
    fileSystemModel.setNameFilters(["*.exe", "*.log", "*.s"])
    fileSystemModel.setNameFilterDisables(False)
    treeView.setModel(fileSystemModel)
    treeView.setRootIndex(root)
    treeView.show()
    app.exec_()