本文整理汇总了Python中PyQt5.QtCore.QFileInfo.absoluteFilePath方法的典型用法代码示例。如果您正苦于以下问题:Python QFileInfo.absoluteFilePath方法的具体用法?Python QFileInfo.absoluteFilePath怎么用?Python QFileInfo.absoluteFilePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QFileInfo
的用法示例。
在下文中一共展示了QFileInfo.absoluteFilePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __installEric6Doc
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def __installEric6Doc(self, engine):
"""
Private method to install/update the eric6 help documentation.
@param engine reference to the help engine (QHelpEngineCore)
@return flag indicating success (boolean)
"""
versionKey = "eric6_ide"
info = engine.customValue(versionKey, "")
lst = info.split('|')
dt = QDateTime()
if len(lst) and lst[0]:
dt = QDateTime.fromString(lst[0], Qt.ISODate)
qchFile = ""
if len(lst) == 2:
qchFile = lst[1]
docsPath = QDir(getConfig("ericDocDir") + QDir.separator() + "Help")
files = docsPath.entryList(["*.qch"])
if not files:
engine.setCustomValue(
versionKey, QDateTime().toString(Qt.ISODate) + '|')
return False
for f in files:
if f == "source.qch":
fi = QFileInfo(docsPath.absolutePath() + QDir.separator() + f)
if dt.isValid() and \
fi.lastModified().toString(Qt.ISODate) == \
dt.toString(Qt.ISODate) and \
qchFile == fi.absoluteFilePath():
return False
namespace = QHelpEngineCore.namespaceName(
fi.absoluteFilePath())
if not namespace:
continue
if namespace in engine.registeredDocumentations():
engine.unregisterDocumentation(namespace)
if not engine.registerDocumentation(fi.absoluteFilePath()):
self.errorMessage.emit(
self.tr(
"""<p>The file <b>{0}</b> could not be"""
""" registered. <br/>Reason: {1}</p>""")
.format(fi.absoluteFilePath, engine.error())
)
return False
engine.setCustomValue(
versionKey,
fi.lastModified().toString(Qt.ISODate) + '|' +
fi.absoluteFilePath())
return True
return False
示例2: directory
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
class QuarkNotebookModel:
"""Subdirectories located in the Quark notes directory (defined by its path in
'config.json' under "notes_dir") are represented by this class in the Quark
note manager."""
def __init__(self, dirPath):
"""Initialize data for the model."""
self._notebookDir = QFileInfo(dirPath) #store path to the notebook as a 'QFileInfo' for added flexibility
q = QFileIconProvider() #objec used to create model display icon
self._icon = q.icon(self._notebookDir) #create model display icon
self._notes = [] #initialize empty list of notes
notebookPath = self._notebookDir.absoluteFilePath() #get the absolute path to the notebook
#load all the notes inside this notebook
for item in sorted(os.listdir(notebookPath)): #for every item in the notebook
itemPath = os.path.join(notebookPath, item) #get absolute path to the item
if os.path.isfile(itemPath): #if the item is a file/note
self._notes.append( QuarkNoteModel(itemPath, self) ) #append a new note to the notes list
def noteAt(self, i):
"""Returns the note at a given index."""
if i >= 0 and i < len(self._notes):
return self._notes[i]
else:
return None
def noteCount(self):
"""Returns the number notes inside this notebook."""
return len(self._notes)
def getName(self):
"""Returns the name of this notebook/directory."""
return self._notebookDir.fileName()
def getFilePath(self):
"""Returns path to the note."""
return self._notebookDir.absoluteFilePath()
def getIcon(self):
"""Returns the icon to be displayed in the Quark note manager."""
return self._icon
示例3: open
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def open(self, file_name):
"""Open the file at the given path for reading.
Args:
file_name (str): File path of the file to open. Only .wav files
permitted.
Raises:
FileNotFoundError: If the filename given cannot be opened.
"""
if file_name is not None:
file_info = QFileInfo(file_name)
if file_info.exists():
self.file_name = file_name
# Update the waveform data
wave_read = wave.open(file_name, 'r')
self.waveform_info = wave_read.getparams()
step = int(self.waveform_info.framerate / self.stored_fps)
self.waveform_data = list(bytesToInts(
data=wave_read.readframes(-1),
channelWidth=self.waveform_info.sampwidth,
numChannels=self.waveform_info.nchannels,
signed=True,
step=step))
# Update the media player
url = QUrl.fromLocalFile(file_info.absoluteFilePath())
self.media_player.setMedia(QMediaContent(url))
# Send out appropriate event
self.signalFileChanged.emit()
wave_read.close()
else:
raise FileNotFoundError('No file exists at given file path')
示例4: openFile
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def openFile(self):
"""
Public slot to open the downloaded file.
"""
info = QFileInfo(self.__fileName)
url = QUrl.fromLocalFile(info.absoluteFilePath())
QDesktopServices.openUrl(url)
示例5: __open
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def __open(self):
"""
Private slot to open the downloaded file.
"""
info = QFileInfo(self.__output)
url = QUrl.fromLocalFile(info.absoluteFilePath())
QDesktopServices.openUrl(url)
示例6: browsePath
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def browsePath(self):
"""用户点击了浏览路径的按钮。如果成功设置了路径,就返回True,如果用户取消了操作或者出错,就返回False
返回的用途参见showEvent()"""
filename, selectedFilter = QFileDialog.getOpenFileName(self, self.windowTitle())
if not filename:
return False
fi = QFileInfo(filename)
if fi.isSymLink():
filename = fi.symLinkTarget()
if not os.path.exists(filename):
QMessageBox.information(self, self.windowTitle(), self.tr("快捷方式所指向的程序不正确。"))
return False
fi = QFileInfo(filename)
self.txtName.setText(fi.baseName())
self.txtPath.setText(fi.absoluteFilePath())
self.setFileIcon(fi.absoluteFilePath())
self.txtDir.setText(fi.dir().absolutePath())
return True
示例7: path_with_tilde_homepath
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def path_with_tilde_homepath(path):
if IS_WINDOWS:
return path
home_path = QDir.homePath()
fi = QFileInfo(QDir.cleanPath(path))
outpath = fi.absoluteFilePath()
if outpath.startswith(home_path):
outpath = "~" + outpath[len(home_path):]
else:
outpath = path
return outpath
示例8: add_song
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def add_song(self, song_path):
if song_path.split(".")[-1] not in ["mp3", "flac", "ogg"]:
raise AssertionError
song = self.path_to_song(song_path)
filepath = song.path
fileInfo = QFileInfo(filepath)
if fileInfo.exists():
url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
if fileInfo.suffix().lower() == "mp3" or "flac" or "ogg":
self.playlist.addMedia(QMediaContent(url))
self.songs.append(song)
示例9: addToPlaylist
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def addToPlaylist(self, fileNames):
for name in fileNames:
fileInfo = QFileInfo(name)
if fileInfo.exists():
url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
if fileInfo.suffix().lower() == 'm3u':
self.playlist.load(url)
else:
self.playlist.addMedia(QMediaContent(url))
else:
url = QUrl(name)
if url.isValid():
self.playlist.addMedia(QMediaContent(url))
示例10: _load_audio
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def _load_audio(self):
filename = os.path.join(self.audio_path, "{:03}.mp3".format(self._song_number))
self.playlist.clear()
fileInfo = QFileInfo(filename)
if fileInfo.exists():
url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
if fileInfo.suffix().lower() == 'm3u':
self.playlist.load(url)
else:
self.playlist.addMedia(QMediaContent(url))
self._loading_audio = True
self.player.play()
示例11: __init__
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def __init__(self, el, parent=None):
super(MenuContentItem, self).__init__(parent)
self.name = el.getAttribute("name")
self.heading = None
self.description1 = None
self.description2 = None
readme_dir = QFileInfo(__file__).dir()
readme_dir.cdUp()
readme_dir.cd(el.getAttribute("dirname"))
self.readmePath = readme_dir.absoluteFilePath("README")
self._prepared = False
示例12: browseOpenwith
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def browseOpenwith(self):
filename, selectedFilter = QFileDialog.getOpenFileName(self, self.windowTitle())
if not filename:
return
fi = QFileInfo(filename)
if fi.isSymLink():
filename = fi.symLinkTarget()
if not os.path.exists(filename):
QMessageBox.information(self, self.windowTitle(),
self.tr("快捷方式所指向的程序不正确。"))
return
fi = QFileInfo(filename)
if not fi.isExecutable():
QMessageBox.information(self, self.windowTitle(),
self.tr("编辑程序必须是一个可执行文件。请重新选择。该选项是选填项,并不一定要填写。"))
self.txtOpenwith.setText(fi.absoluteFilePath())
示例13: on_main_window_start
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def on_main_window_start(main_window):
main_window.theme_menu = main_window.menuBar().addMenu(
main_window.tr('Themes'))
themes_directory = QFileInfo('themes')
if themes_directory.exists():
active_theme = ThemeManager.get_active_theme()
path = themes_directory.absoluteFilePath()
group_action = QActionGroup(main_window)
group_action.setExclusive(True)
for theme in os.listdir(path):
action = QAction(theme, main_window)
action.setData(theme)
action.setCheckable(True)
if theme == active_theme:
action.setChecked(True)
action.changed.connect(ThemeManager.wrapper(main_window))
group_action.addAction(action)
group_action.addAction(action)
main_window.theme_menu.addAction(action)
示例14: directory
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
class QuarkNoteModel:
"""Files located in the Quark notes directory (defined by its path in
'config.json' under "notes_dir") are represented by this class in the Quark
note manager."""
def __init__(self, fileInfo, _parent = None):
"""Initializes data for the model."""
self._noteFile = QFileInfo(fileInfo)
q = QFileIconProvider()
self._icon = q.icon(self._noteFile)
self._parent = _parent
def getIcon(self):
"""Returns the icon to be displayed in the Quark note manager."""
return self._icon
def getName(self):
"""Returns the file name of the note."""
return self._noteFile.fileName()
def getFilePath(self):
"""Returns path to the note."""
return self._noteFile.absoluteFilePath()
def getParent(self):
"""Returns the parent notebook."""
return self._parent
def setNewParent(self, newParent):
"""Set a new parent for the note."""
self._parent = newParent
示例15: __installQtDoc
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import absoluteFilePath [as 别名]
def __installQtDoc(self, name, version, engine):
"""
Private method to install/update a Qt help document.
@param name name of the Qt help document (string)
@param version Qt version of the help documens (integer)
@param engine reference to the help engine (QHelpEngineCore)
@return flag indicating success (boolean)
"""
versionKey = "qt_version_{0}@@{1}".format(version, name)
info = engine.customValue(versionKey, "")
lst = info.split("|")
dt = QDateTime()
if len(lst) and lst[0]:
dt = QDateTime.fromString(lst[0], Qt.ISODate)
qchFile = ""
if len(lst) == 2:
qchFile = lst[1]
if version == 4:
docsPath = QDir(QLibraryInfo.location(QLibraryInfo.DocumentationPath) + QDir.separator() + "qch")
elif version == 5:
docsPath = QDir(QLibraryInfo.location(QLibraryInfo.DocumentationPath))
else:
# unsupported Qt version
return False
files = docsPath.entryList(["*.qch"])
if not files:
engine.setCustomValue(versionKey, QDateTime().toString(Qt.ISODate) + "|")
return False
for f in files:
if f.startswith(name):
fi = QFileInfo(docsPath.absolutePath() + QDir.separator() + f)
namespace = QHelpEngineCore.namespaceName(fi.absoluteFilePath())
if not namespace:
continue
if (
dt.isValid()
and namespace in engine.registeredDocumentations()
and fi.lastModified().toString(Qt.ISODate) == dt.toString(Qt.ISODate)
and qchFile == fi.absoluteFilePath()
):
return False
if namespace in engine.registeredDocumentations():
engine.unregisterDocumentation(namespace)
if not engine.registerDocumentation(fi.absoluteFilePath()):
self.errorMessage.emit(
self.tr(
"""<p>The file <b>{0}</b> could not be""" """ registered. <br/>Reason: {1}</p>"""
).format(fi.absoluteFilePath, engine.error())
)
return False
engine.setCustomValue(versionKey, fi.lastModified().toString(Qt.ISODate) + "|" + fi.absoluteFilePath())
return True
return False