本文整理汇总了Python中PyQt5.QtCore.QFileInfo.canonicalFilePath方法的典型用法代码示例。如果您正苦于以下问题:Python QFileInfo.canonicalFilePath方法的具体用法?Python QFileInfo.canonicalFilePath怎么用?Python QFileInfo.canonicalFilePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QFileInfo
的用法示例。
在下文中一共展示了QFileInfo.canonicalFilePath方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileBasedTextStream
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import canonicalFilePath [as 别名]
class FileBasedTextStream(QTextStream):
def __init__(self, qfile):
super().__init__(qfile)
self.saved_file = qfile
self.qfi = None # may never need this
def rewind(self):
self.flush()
self.seek(0)
def writeLine(self, str):
self << str
self << '\n'
def open_mode(self):
return self.saved_file.openMode()
def fullpath(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.canonicalFilePath()
def folderpath(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.canonicalPath()
def filename(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.fileName()
def basename(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.completeBaseName()
def suffix(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.suffix()
示例2: onActivated
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import canonicalFilePath [as 别名]
def onActivated(self, index):
path = self.model().filePath(index)
fileInfo = QFileInfo(path)
if (fileInfo.isDir()):
prefs = preferences.Preferences.instance()
prefs.setMapsDirectory(fileInfo.canonicalFilePath())
return
self.mMainWindow.openFile(path)
示例3: findDocument
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import canonicalFilePath [as 别名]
def findDocument(self, fileName):
canonicalFilePath = QFileInfo(fileName).canonicalFilePath()
if (canonicalFilePath==''): # file doesn't exist
return -1
for i in range(self.mDocuments.size()):
fileInfo = QFileInfo(self.mDocuments.at(i).fileName())
if (fileInfo.canonicalFilePath() == canonicalFilePath):
return i
return -1
示例4: FileBasedTextStream
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import canonicalFilePath [as 别名]
class FileBasedTextStream(QTextStream):
def __init__(self, qfile):
super().__init__(qfile)
self.saved_file = qfile
self.qfi = None # may never need this
def rewind(self):
self.flush()
self.seek(0)
def writeLine(self, str):
self << str
self << '\n'
def open_mode(self):
return self.saved_file.openMode()
def fullpath(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.canonicalFilePath()
def folderpath(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.canonicalPath()
def filename(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.fileName()
def basename(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.completeBaseName()
def suffix(self):
if self.qfi is None:
self.qfi = QFileInfo(self.saved_file)
return self.qfi.suffix()
def flush(self):
super().flush() # make sure text buffer goes to device
return self.device().flush() # do a real flush
def show_error( self, action, parent ):
error_number = self.device().error()
if error_number : # is not 0, no error
error_string = self.device().errorString()
msg_string = 'Error {} ({}) on {}'.format(
error_number, error_string, action )
warning_msg( msg_string, self.fullpath(), parent )
示例5: _generate_resource
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import canonicalFilePath [as 别名]
def _generate_resource(self, resources_dir, required_py, job_writer, nr_resources):
""" Generate the application resource. """
project = self._project
self._create_directory(resources_dir)
resource_contents = []
# Handle any application package.
if project.application_package.name is not None:
fi = QFileInfo(project.path_from_user(
project.application_package.name))
package_src_dir = fi.canonicalFilePath()
package_name = project.application_package.name
if package_name != '':
package_name = fi.completeBaseName()
self._write_package(resource_contents, resources_dir, package_name,
project.application_package, package_src_dir, job_writer)
# Handle the Python standard library.
self._write_stdlib_py(resource_contents, resources_dir, required_py,
job_writer)
# Handle any additional packages.
for package in project.other_packages:
self._write_package(resource_contents, resources_dir, '', package,
project.path_from_user(package.name), job_writer)
# Handle the PyQt package.
if len(project.pyqt_modules) != 0:
pyqt_subdir = 'PyQt5' if project.application_is_pyqt5 else 'PyQt4'
pyqt_dst_dir = resources_dir + '/' + pyqt_subdir
pyqt_src_dir = project.path_from_user(project.python_target_stdlib_dir) + '/site-packages/' + pyqt_subdir
self._create_directory(pyqt_dst_dir)
self._freeze(job_writer, pyqt_dst_dir + '/__init__.pyo',
pyqt_src_dir + '/__init__.py',
pyqt_subdir + '/__init__.pyo')
resource_contents.append(pyqt_subdir + '/__init__.pyo')
# Handle the PyQt.uic package.
if 'uic' in project.pyqt_modules:
skip_dirs = ['__pycache__']
if project.python_target_version[0] == 3:
skip_dirs.append('port_v2')
else:
skip_dirs.append('port_v3')
def copy_freeze(src, dst):
for skip in skip_dirs:
if skip in src:
break
else:
if dst.endswith('.py'):
dst += 'o'
src = QDir.fromNativeSeparators(src)
dst = QDir.fromNativeSeparators(dst)
rel_dst = dst[len(resources_dir) + 1:]
self._freeze(job_writer, dst, src, rel_dst)
resource_contents.append(rel_dst)
shutil.copytree(QDir.toNativeSeparators(pyqt_src_dir + '/uic'),
QDir.toNativeSeparators(pyqt_dst_dir + '/uic'),
copy_function=copy_freeze)
# Write the .qrc files.
if nr_resources == 1:
resource_names = [self._write_resource(resources_dir,
resource_contents)]
else:
resource_names = []
nr_files = len(resource_contents)
if nr_resources > nr_files:
nr_resources = nr_files
per_resource = (nr_files + nr_resources - 1) // nr_resources
start = 0
for r in range(nr_resources):
end = start + per_resource
if end > nr_files:
end = nr_files
resource_names.append(
self._write_resource(resources_dir,
resource_contents[start:end], r))
start += per_resource
return resource_names
示例6: load
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import canonicalFilePath [as 别名]
def load(cls, file_name):
""" Return a new project loaded from the given file. Raise a
UserException if there was an error.
"""
fi = QFileInfo(file_name)
tree = ElementTree()
try:
root = tree.parse(QDir.toNativeSeparators(fi.canonicalFilePath()))
except Exception as e:
raise UserException(
"There was an error reading the project file.", str(e))
cls._assert(root.tag == 'Project',
"Unexpected root tag '{0}', 'Project' expected.".format(
root.tag))
# Check the project version number.
version = root.get('version')
cls._assert(version is not None, "Missing 'version' attribute.")
try:
version = int(version)
except:
version = None
cls._assert(version is not None, "Invalid 'version'.")
if version < cls.min_version:
raise UserException("The project's format is no longer supported.")
if version > cls.version:
raise UserException(
"The project's format is version {0} but only version {1} is supported.".format(version, cls.version))
# Create the project and populate it.
project = cls()
project._name = fi
# The Python specific configuration.
python = root.find('Python')
cls._assert(python is not None, "Missing 'Python' tag.")
project.python_host_interpreter = python.get('hostinterpreter', '')
# This was added in version 5.
project.python_use_platform = python.get('platformpython', '').split()
project.python_source_dir = python.get('sourcedir', '')
project.python_ssl = cls._get_bool(python, 'ssl', 'Python')
project.python_target_include_dir = python.get('targetincludedir', '')
project.python_target_library = python.get('targetlibrary', '')
project.python_target_stdlib_dir = python.get('targetstdlibdir', '')
major = cls._get_int(python, 'major', 'Python')
minor = cls._get_int(python, 'minor', 'Python')
patch = cls._get_int(python, 'patch', 'Python', default=0)
project.python_target_version = (major, minor, patch)
# The application specific configuration.
application = root.find('Application')
cls._assert(application is not None, "Missing 'Application' tag.")
project.application_entry_point = application.get('entrypoint', '')
project.application_is_pyqt5 = cls._get_bool(application, 'ispyqt5',
'Application')
project.application_is_console = cls._get_bool(application,
'isconsole', 'Application')
project.application_is_bundle = cls._get_bool(application, 'isbundle',
'Application')
project.application_name = application.get('name', '')
project.application_script = application.get('script', '')
project.sys_path = application.get('syspath', '')
# Any qmake configuration. This was added in version 5.
qmake_configuration = application.find('QMakeConfiguration')
if qmake_configuration is not None:
project.qmake_configuration = qmake_configuration.text
# Any application package.
app_package = application.find('Package')
if app_package is not None:
project.application_package = cls._load_package(app_package)
else:
project.application_package = QrcPackage()
# Any PyQt modules.
for pyqt_m in root.iterfind('PyQtModule'):
name = pyqt_m.get('name', '')
cls._assert(name != '',
"Missing or empty 'PyQtModule.name' attribute.")
project.pyqt_modules.append(name)
# Any standard library modules.
for stdlib_module_element in root.iterfind('StdlibModule'):
#.........这里部分代码省略.........