コード例 #1
0
    def update_view(self):
        """
        Updates file/folder view
        :return:
        """

        self.view.clear()
        qdir = QDir(self.directory)
        qdir.setNameFilters(self.get_filter_patterns())
        filters = QDir.Dirs | QDir.AllDirs | QDir.Files | QDir.NoDot | QDir.NoDotDot
        if self.show_hidden.isChecked():
            filters = filters | QDir.Hidden
        entries = qdir.entryInfoList(filters=filters,
                                     sort=QDir.DirsFirst | QDir.Name)
        file_path = self.get_file_path('..')
        if os.path.exists(file_path) and file_path != self.directory:
            icon = QFileIconProvider().icon(QFileInfo(self.directory))
            QListWidgetItem(icon, '..', self.view, 0)
        for info in entries:
            icon = QFileIconProvider().icon(info)
            suf = info.completeSuffix()
            name, tp = (info.fileName(), 0) if info.isDir() else (
                '%s%s' % (info.baseName(), '.%s' % suf if suf else ''), 1)
            QListWidgetItem(icon, name, self.view, tp)
        self.view.setFocus()
コード例 #2
0
ファイル: main.py プロジェクト: mrals2018/QtExamples
def main():
    import sys

    app = QApplication(sys.argv)

    QQuickWindow.setDefaultAlphaBuffer(True)

    QCoreApplication.setApplicationName("Photosurface")
    QCoreApplication.setOrganizationName("QtProject")
    QCoreApplication.setApplicationVersion(__qt_version__)
    parser = QCommandLineParser()
    parser.setApplicationDescription("Qt Quick Demo - Photo Surface")
    parser.addHelpOption()
    parser.addVersionOption()
    parser.addPositionalArgument("directory", "The image directory or URL to show.")
    parser.process(app)

    initialUrl = QUrl()
    if parser.positionalArguments():
        initialUrl = QUrl.fromUserInput(
            parser.positionalArguments()[0], QDir.currentPath(), QUrl.AssumeLocalFile
        )
        if not initialUrl.isValid():
            print(
                'Invalid argument: "',
                parser.positionalArguments()[0],
                '": ',
                initialUrl.errorString(),
            )
            sys.exit(1)

    nameFilters = imageNameFilters()

    engine = QQmlApplicationEngine()
    context: QQmlContext = engine.rootContext()

    picturesLocationUrl = QUrl.fromLocalFile(QDir.homePath())
    picturesLocations = QStandardPaths.standardLocations(
        QStandardPaths.PicturesLocation
    )
    if picturesLocations:
        picturesLocationUrl = QUrl.fromLocalFile(picturesLocations[0])
        if not initialUrl and QDir(picturesLocations[0]).entryInfoList(
            nameFilters, QDir.Files
        ):
            initialUrl = picturesLocationUrl

    context.setContextProperty("contextPicturesLocation", picturesLocationUrl)
    context.setContextProperty("contextInitialUrl", initialUrl)
    context.setContextProperty("contextImageNameFilters", nameFilters)

    engine.load(QUrl("qrc:///photosurface.qml"))
    if not engine.rootObjects():
        sys.exit(-1)

    sys.exit(app.exec_())
コード例 #3
0
    def get_drives_widget(self):
        """
        Returns a QGroupBox widget that contains all disk drivers of the PC in a vertical layout
        :return: QGroupBox
        """

        w = QGroupBox('')
        w.setParent(self)
        box = layouts.VerticalLayout()
        box.setAlignment(Qt.AlignTop)
        places = [(getpass.getuser(),
                   os.path.realpath(os.path.expanduser('~')))]
        places += [
            (q, q) for q in
            [os.path.realpath(x.absolutePath()) for x in QDir().drives()]
        ]
        for label, loc in places:
            icon = QFileIconProvider().icon(QFileInfo(loc))
            drive_btn = QRadioButton(label)
            drive_btn.setIcon(icon)
            drive_btn.setToolTip(loc)
            drive_btn.setProperty('path', loc)
            drive_btn.clicked.connect(self.go_to_drive)
            self.places[loc] = drive_btn
            box.addWidget(drive_btn)
        w.setLayout(box)
        return w
コード例 #4
0
ファイル: pyxpad.py プロジェクト: ZedThree/pyxpad
    def addXPADtree(self):
        try:
            from pyxpad.xpadsource import XPadSource
        except ImportError:
            self.main.write("Sorry, no XPAD tree support")
            self.main.write(str(sys.exc_info()))
            return

        try:
            # Select the directory
            tr = self.main.tr
            dname = QFileDialog.getExistingDirectory(self.main, tr('Open XPAD directory'),
                                                     QDir.currentPath())
            if (dname == "") or (dname is None):
                return
            # Create data source
            s = XPadSource(dname)

            # Add data source and update
            self.addSource(s)
            self.updateDisplay()
        except:
            self.main.write("Error creating XPadSource")
            self.main.write(str(sys.exc_info()))
            raise
コード例 #5
0
ファイル: pyxpad.py プロジェクト: ZedThree/pyxpad
    def addXPADtree(self):
        """Add an XPad tree as a data source, if UDA is available"""
        try:
            from pyxpad.xpadsource import XPadSource
        except ImportError:
            self.main.write("Sorry, no XPAD tree support")
            self.main.write(str(sys.exc_info()))
            return

        try:
            # Select the directory
            tr = self.main.tr
            dname = QFileDialog.getExistingDirectory(self.main,
                                                     tr("Open XPAD directory"),
                                                     QDir.currentPath())
            if (dname == "") or (dname is None):
                return
            # Create data source
            s = XPadSource.from_tree(dname)

            # Add data source and update
            self.addSource(s)
            self.updateDisplay()
        except:
            self.main.write("Error creating XPadSource")
            self.main.write(str(sys.exc_info()))
            raise
コード例 #6
0
ファイル: main.py プロジェクト: eyllanesc/QtExamples
    def openFile(self, path: str) -> None:
        f = QFile(path)

        if not f.open(QIODevice.ReadOnly):

            QMessageBox.warning(
                self,
                self.windowTitle(),
                self.tr("Could not open file %s: %s" %
                        (QDir.toNativeSeparators(path), f.errorString())),
            )
            return

        self.m_filePath = path
        self.editor.setPlainText(f.readAll().data().decode())
コード例 #7
0
ファイル: main.py プロジェクト: eyllanesc/QtExamples
    def onFileSave(self):
        if not self.m_filePath:
            self.onFileSaveAs()
            return

        f = QFile(self.m_filePath)
        if not f.open(QIODevice.WriteOnly | QIODevice.Text):
            QMessageBox.warning(
                self,
                self.windowTitle(),
                self.tr("Could not write to file %s: %s" %
                        (QDir.toNativeSeparators(
                            self.m_filePath), f.errorString())),
            )
            return

        text = QTextStream(f)
        text << self.editor.toPlainText()

        self.editor.document().setModified(False)
コード例 #8
0
ファイル: pyxpad.py プロジェクト: ZedThree/pyxpad
    def addBOUT(self):
        """
        Add a BOUT++ directory source
        """
        try:
            from pyxpad.boutsource import BoutDataSource

            # Select the directory
            tr = self.main.tr
            dname = QFileDialog.getExistingDirectory(self.main, tr('Open BOUT++ directory'),
                                                     QDir.currentPath())
            if (dname == "") or (dname is None):
                return
            # Create data source
            s = BoutDataSource(dname)

            # Add data source and update
            self.addSource(s)
            self.updateDisplay()
        except:
            self.main.write("Sorry, no BOUT++ support")
            raise
            return
コード例 #9
0
ファイル: pyxpad.py プロジェクト: ZedThree/pyxpad
    def addBOUT(self):
        """
        Add a BOUT++ directory source, if boutdata is available
        """
        try:
            from pyxpad.boutsource import BoutDataSource

            # Select the directory
            tr = self.main.tr
            dname = QFileDialog.getExistingDirectory(
                self.main, tr("Open BOUT++ directory"), QDir.currentPath())
            if (dname == "") or (dname is None):
                return
            # Create data source
            s = BoutDataSource(dname)

            # Add data source and update
            self.addSource(s)
            self.updateDisplay()
        except:
            self.main.write("Sorry, no BOUT++ support")
            raise
            return