Python PyQt5.QtCore.QFileInfo() Examples

The following are 30 code examples for showing how to use PyQt5.QtCore.QFileInfo(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .

Example 1
Project: Lector   Author: BasioMeusPuga   File: __main__.py    License: GNU General Public License v3.0 6 votes vote down vote up
def open_books_at_startup(self):
        # Last open books and command line books aren't being opened together
        # so that command line books are processed last and therefore retain focus

        # Open last... open books.
        # Then set the value to None for the next run
        if self.settings['last_open_books']:
            files_to_open = {i: None for i in self.settings['last_open_books']}
            self.open_files(files_to_open)
        else:
            self.settings['last_open_tab'] = None

        # Open input files if specified
        cl_parser = QtCore.QCommandLineParser()
        cl_parser.process(QtWidgets.qApp)
        my_args = cl_parser.positionalArguments()
        if my_args:
            file_list = [QtCore.QFileInfo(i).absoluteFilePath() for i in my_args]
            self.process_post_hoc_files(file_list, True) 
Example 2
Project: PyQt5   Author: andresnino   File: visualizarImprimirExportar.py    License: MIT License 6 votes vote down vote up
def exportarPDF(self):
        if not self.documento.isEmpty():
            nombreArchivo, _ = QFileDialog.getSaveFileName(self, "Exportar a PDF", "Listado de usuarios",
                                                           "Archivos PDF (*.pdf);;All Files (*)",
                                                           options=QFileDialog.Options())

            if nombreArchivo:
                # if QFileInfo(nombreArchivo).suffix():
                #     nombreArchivo += ".pdf"

                impresion = QPrinter(QPrinter.HighResolution)
                impresion.setOutputFormat(QPrinter.PdfFormat)
                impresion.setOutputFileName(nombreArchivo)
                self.documento.print_(impresion)

                QMessageBox.information(self, "Exportar a PDF", "Datos exportados con éxito.   ",
                                        QMessageBox.Ok)
        else:
            QMessageBox.critical(self, "Exportar a PDF", "No hay datos para exportar.   ",
                                 QMessageBox.Ok)


# ================================================================ 
Example 3
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 6 votes vote down vote up
def runto(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        g = globals()
        os.chdir(str(self.path))
        script = str(self.codebox.text())
        try:
            os.chdir(str(self.path))
            os.path.join(os.path.expanduser('~'), os.path.expandvars(str(self.path)))
            sys.path.insert(0, str(self.path))
            exec (script, g)
        except Exception as e:
            print e.__doc__
            print e.message
        else:
            pass
            #exec (script, g) 
Example 4
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 6 votes vote down vote up
def runto(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        g = globals()
        os.chdir(str(self.path))
        script = str(self.codebox.text())
        try:
            os.chdir(str(self.path))
            os.path.join(os.path.expanduser('~'), os.path.expandvars(str(self.path)))
            sys.path.insert(0, str(self.path))
            exec (script, g)
        except Exception as e:
            print e.__doc__
            print e.message
        else:
            pass
            #exec (script, g) 
Example 5
Project: PyQt   Author: PyQt5   File: CustomIcon.py    License: GNU General Public License v3.0 6 votes vote down vote up
def icon(self, type_info):
        '''
        :param fileInfo: 参考http://doc.qt.io/qt-5/qfileinfo.html
        '''
        if isinstance(type_info, QFileInfo):
            # 如果type_info是QFileInfo类型则用getInfoIcon来返回图标
            return self.getInfoIcon(type_info)
        # 如果type_info是QFileIconProvider自身的IconType枚举类型则执行下面的方法
        # 这里只能自定义通用的几种类型,参考http://doc.qt.io/qt-5/qfileiconprovider.html#IconType-enum
        '''
        QFileIconProvider::Computer     0
        QFileIconProvider::Desktop      1
        QFileIconProvider::Trashcan     2
        QFileIconProvider::Network      3
        QFileIconProvider::Drive        4
        QFileIconProvider::Folder       5
        QFileIconProvider::File         6
        '''
        if type_info == QFileIconProvider.Folder:
            # 如果是文件夹
            return self.DirIcon
        return super(FileIconProvider, self).icon(type_info) 
Example 6
Project: equant   Author: epolestar   File: utils.py    License: GNU General Public License v2.0 6 votes vote down vote up
def icon(self, type_info):
        '''
        :param fileInfo: 参考http://doc.qt.io/qt-5/qfileinfo.html
        '''
        if isinstance(type_info, QFileInfo):
            # 如果type_info是QFileInfo类型则用getInfoIcon来返回图标
            return self.getInfoIcon(type_info)
        # 如果type_info是QFileIconProvider自身的IconType枚举类型则执行下面的方法
        # 这里只能自定义通用的几种类型,参考http://doc.qt.io/qt-5/qfileiconprovider.html#IconType-enum
        '''
        QFileIconProvider::Computer     0
        QFileIconProvider::Desktop      1
        QFileIconProvider::Trashcan     2
        QFileIconProvider::Network      3
        QFileIconProvider::Drive        4
        QFileIconProvider::Folder       5
        QFileIconProvider::File         6
        '''
        if type_info == QFileIconProvider.Folder:
            # 如果是文件夹
            return self.DirIcon
        return super(FileIconProvider, self).icon(type_info) 
Example 7
Project: X64dbg_script_editor   Author: techbliss   File: Editor_x64dbg.py    License: The Unlicense 6 votes vote down vote up
def runto(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        g = globals()
        os.chdir(str(self.path))
        script = str(self.codebox.text())
        try:
            os.chdir(str(self.path))
            os.path.join(os.path.expanduser('~'), os.path.expandvars(str(self.path)))
            sys.path.insert(0, str(self.path))
            exec (script, g)
        except Exception as e:
            print e.__doc__
            print e.message
        else:
            pass
            #exec (script, g) 
Example 8
Project: vidcutter   Author: ozmartian   File: videostyle.py    License: GNU General Public License v3.0 5 votes vote down vote up
def loadQSS(theme) -> None:
        filename = ':/styles/{}.qss'.format(theme)
        if QFileInfo(filename).exists():
            qssfile = QFile(filename)
            qssfile.open(QFile.ReadOnly | QFile.Text)
            content = QTextStream(qssfile).readAll()
            qApp.setStyleSheet(content) 
Example 9
Project: vidcutter   Author: ozmartian   File: singleapplication.py    License: GNU General Public License v3.0 5 votes vote down vote up
def getSettingsPath() -> str:
        if sys.platform == 'win32':
            settings_path = os.path.join(QDir.homePath(), 'AppData', 'Local', 'vidcutter')
        elif sys.platform == 'darwin':
            settings_path = os.path.join(QDir.homePath(), 'Library', 'Preferences', 'vidcutter')
        else:
            if QFileInfo(__file__).absolutePath().startswith('/app/'):
                settings_path = QProcessEnvironment.systemEnvironment().value('XDG_CONFIG_HOME', '')
                if not len(settings_path):
                    settings_path = os.path.join(QDir.homePath(), '.var', 'app', vidcutter.__desktopid__, 'config')
            else:
                settings_path = os.path.join(QDir.homePath(), '.config', 'vidcutter')
        return os.path.join(settings_path, 'vidcutter.ini') 
Example 10
Project: nanovna-saver   Author: NanoVNA-Saver   File: Chart.py    License: GNU General Public License v3.0 5 votes vote down vote up
def saveScreenshot(self):
        logger.info("Saving %s to file...", self.name)
        filename, _ = QtWidgets.QFileDialog.getSaveFileName(parent=self, caption="Save image",
                                                            filter="PNG (*.png);;All files (*.*)")

        logger.debug("Filename: %s", filename)
        if filename != "":
            if not QtCore.QFileInfo(filename).suffix():
                filename += ".png"
            self.grab().save(filename) 
Example 11
Project: parsec-cloud   Author: Scille   File: desktop.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def open_file(path):
    QDesktopServices.openUrl(QUrl.fromLocalFile(QFileInfo(path).absoluteFilePath())) 
Example 12
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def open(self):
        self.path = QtCore.QFileInfo(self.filename).path()

        # Get filename and show only .writer files
        (self.filename, _) = \
            QtWidgets.QFileDialog.getOpenFileName(self.vindu,
                'Open File', self.path,
                'Python Files (*.py *.pyc *.pyw)', '')

        if self.filename:
            with open(self.filename, 'r') as self.file:
                self.codebox.setText(self.file.read())
        os.chdir(str(self.path)) 
Example 13
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savefile(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        (self.filename, _) = \
            QtWidgets.QFileDialog.getSaveFileName(self.vindu, 'Save as'
                , self.path, 'Python Files (*.py *.pyc *.pyw)')
        if self.filename:
            self.savetext(self.filename)
        os.chdir(str(self.path)) 
Example 14
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def runto(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        g = globals()
        os.chdir(str(self.path))
        script = str(self.codebox.text())
        try:
            os.chdir(str(self.path))
            os.path.join(os.path.expanduser('~'), os.path.expandvars(str(self.path)))
            sys.path.insert(0, str(self.path))
            exec (script, g)
        except Exception as e:
            print e.__doc__
            print e.message
        else:
            exec (script, g) 
Example 15
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def runtoprob(self):
        try:
            self.path = QtCore.QFileInfo(self.filename).path()
            self.path = QtCore.QFileInfo(self.filename).path()
            g = globals()
            os.chdir(str(self.path))
            script = str(self.codebox.text())
            import cProfile
            cProfile.run(script)
        except Exception as e:
            print e.__doc__
            print e.message
        else:
            import cProfile
            cProfile.run(script) 
Example 16
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def opentemp(self):
        print "hello"
        self.path = QtCore.QFileInfo(self.filename).path()

        # Get filename and show only .writer files
        (self.filename, _) = \
            QtWidgets.QFileDialog.getOpenFileName(self.wizardPage_3,
                'Open File', self.path,
                'Python Files (*.py *.pyc *.pyw)', '')

        if self.filename:
            with open(self.filename, 'r') as self.file:
                self.TemptextEdit.setText(self.file.read())
        os.chdir(str(self.path)) 
Example 17
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def openscript(self):
        print "hello"
        self.path = QtCore.QFileInfo(self.filename).path()

        # Get filename and show only .writer files
        (self.filename, _) = \
            QtWidgets.QFileDialog.getOpenFileName(self.wizardPage_3,
                'Open File', self.path,
                'Python Files (*.py *.pyc *.pyw)', '')

        if self.filename:
            with open(self.filename, 'r') as self.file:
                self.script_textEdit.setText(self.file.read())
        os.chdir(str(self.path)) 
Example 18
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savescript(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        (self.filename, _) = \
            QtWidgets.QFileDialog.getSaveFileName(self.wizardPage_3, 'Save as'
                , self.path, 'Python Files (*.py *.pyc *.pyw)')
        if self.filename:
            self.savetextscript(self.filename)
        os.chdir(str(self.path)) 
Example 19
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def open(self):
        self.path = QtCore.QFileInfo(self.filename).path()

        # Get filename and show only .writer files
        (self.filename, _) = \
            QtWidgets.QFileDialog.getOpenFileName(self.vindu,
                'Open File', self.path,
                'Python Files (*.py *.pyc *.pyw)', '')

        if self.filename:
            with open(self.filename, 'r') as self.file:
                self.codebox.setText(self.file.read())
        os.chdir(str(self.path)) 
Example 20
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savefile(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        (self.filename, _) = \
            QtWidgets.QFileDialog.getSaveFileName(self.vindu, 'Save as'
                , self.path, 'Python Files (*.py *.pyc *.pyw)')
        if self.filename:
            self.savetext(self.filename)
        os.chdir(str(self.path)) 
Example 21
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def opentemp(self):
        #print "hello"
        self.path = QtCore.QFileInfo(self.filename).path()

        # Get filename and show only .writer files
        (self.filename, _) = \
            QtWidgets.QFileDialog.getOpenFileName(self.wizardPage_3,
                'Open File', self.path,
                'Python Files (*.py *.pyc *.pyw)', '')

        if self.filename:
            with open(self.filename, 'r') as self.file:
                self.TemptextEdit.setText(self.file.read())
        os.chdir(str(self.path)) 
Example 22
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savetemp(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        (self.filename, _) = \
            QtWidgets.QFileDialog.getSaveFileName(self, 'Save as'
                , self.path, 'Python Files (*.py *.pyc *.pyw)')
        if self.filename:
            self.savetexttemp(self.filename)
        os.chdir(str(self.path)) 
Example 23
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def openscript(self):
        print "hello"
        self.path = QtCore.QFileInfo(self.filename).path()

        # Get filename and show only .writer files
        (self.filename, _) = \
            QtWidgets.QFileDialog.getOpenFileName(self.wizardPage_3,
                'Open File', self.path,
                'Python Files (*.py *.pyc *.pyw)', '')

        if self.filename:
            with open(self.filename, 'r') as self.file:
                self.script_textEdit.setText(self.file.read())
        os.chdir(str(self.path)) 
Example 24
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savescript(self):
        self.path = QtCore.QFileInfo(self.filename).path()
        (self.filename, _) = \
            QtWidgets.QFileDialog.getSaveFileName(self.wizardPage_3, 'Save as'
                , self.path, 'Python Files (*.py *.pyc *.pyw)')
        if self.filename:
            self.savetextscript(self.filename)
        os.chdir(str(self.path)) 
Example 25
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def open(self):
        self.path = QtCore.QFileInfo(self.filename).path()

        # Get filename and show only .writer files
        (self.filename, _) = \
            QtWidgets.QFileDialog.getOpenFileName(self.vindu,
                'Open File', self.path,
                'Python Files (*.py *.pyc *.pyw)', '')

        if self.filename:
            with open(self.filename, 'r') as self.file:
                self.codebox.setText(self.file.read())
        os.chdir(str(self.path)) 
Example 26
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def runtoprob(self):
        try:
            self.path = QtCore.QFileInfo(self.filename).path()
            self.path = QtCore.QFileInfo(self.filename).path()
            g = globals()
            os.chdir(str(self.path))
            script = str(self.codebox.text())
            import cProfile
            cProfile.run(script)
        except Exception as e:
            print e.__doc__
            print e.message
        else:
            import cProfile
            cProfile.run(script) 
Example 27
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: question_4_example_code.py    License: MIT License 5 votes vote down vote up
def on_click(self):
        filename, _ = qtw.QFileDialog.getOpenFileName(
            None, "Select an image to use",
            qtc.QDir.homePath(), "Images (*.png *.xpm *.jpg)")
        if filename:
            self._filename = filename
            # set button text to filename without path
            self.setText(qtc.QFileInfo(filename).fileName())
            self.changed.emit() 
Example 28
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: meme_gen.py    License: MIT License 5 votes vote down vote up
def on_click(self):
        filename, _ = qtw.QFileDialog.getOpenFileName(
            None, "Select an image to use",
            qtc.QDir.homePath(), "Images (*.png *.xpm *.jpg)")
        if filename:
            self._filename = filename
            # set button text to filename without path
            self.setText(qtc.QFileInfo(filename).fileName())
            self.changed.emit() 
Example 29
Project: pySPM   Author: scholi   File: spectra.py    License: Apache License 2.0 5 votes vote down vote up
def open(self, t_filename=None):
        settings = QSettings(QSettings.IniFormat, QSettings.UserScope, "pySPM", "pySPM")
        if t_filename is None:
            home = QDir.cleanPath(os.getenv("HOMEPATH"))
            path = settings.value("lastPath", home)
            self.filename = QFileDialog.getOpenFileName(None, "Choose measurement file", path, "*.ita")[0]
        else:
            self.filename = t_filename
        check_file = QFileInfo(self.filename)
        self.setWindowTitle(check_file.fileName())
        if not check_file.exists() or  not check_file.isFile():
            return
        
        settings.setValue("lastPath", check_file.path())
        self.ita = pySPM.ITA(self.filename, readonly=False)
        self.t, self.S = self.ita.getSpectrum(time=True)
        self.sf, self.k0 = self.ita.get_mass_cal()
        self.mass = pySPM.utils.time2mass(self.t, self.sf, self.k0)
        self.spec = self.ax.plot(self.mass, self.S)[0]
        SatLevel = self.ita.size['pixels']['x']*self.ita.size['pixels']['y']*self.ita.Nscan
        self.sat_level = self.ax.axhline(SatLevel, color='r')
        if 'pySPM' in self.ita.root.goto("MassScale"):
            self.MassCal = []
            N = self.ita.root.goto("MassScale/pySPM/N").get_ulong()
            for i in range(N):
                elt = self.ita.root.goto("MassScale/pySPM/"+str(i)+"/elt").value.decode('utf8')
                mass = self.ita.root.goto("MassScale/pySPM/"+str(i)+"/mass").get_double()
                time = self.ita.root.goto("MassScale/pySPM/"+str(i)+"/time").get_double()
                self.MassCal.append(dict(elt=elt, mass=mass, time=time))
        else:
            self.MassCal = []
            for x in self.ita.root.goto("MassScale/calib"):
                if x.name == 'assign':
                    self.MassCal.append({'elt':x.get_string()})
                if x.name == 'mcp':
                    mcp = struct.unpack("<10d", x.value)
                    self.MassCal[-1]['time'] = mcp[0]
                    self.MassCal[-1]['mass']  =  mcp[1]
        self.DoMassCal() 
Example 30
Project: urh   Author: jopohl   File: FileIconProvider.py    License: GNU General Public License v3.0 5 votes vote down vote up
def icon(self, arg):
        if isinstance(arg, QFileInfo):
            try:
                if (arg.isDir() and os.path.isfile(os.path.join(arg.filePath(), settings.PROJECT_FILE))) \
                        or (arg.isFile() and arg.fileName() == settings.PROJECT_FILE):
                    return QIcon(":/icons/icons/appicon.png")
            except:
                # In some environments (e.g. docker) there tend to be encoding errors
                pass

        return super().icon(arg)