本文整理汇总了Python中PyQt5.QtCore.QFileInfo类的典型用法代码示例。如果您正苦于以下问题:Python QFileInfo类的具体用法?Python QFileInfo怎么用?Python QFileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFileInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, ui_file, bus, devices=[], parent=None):
QtWidgets.QMainWindow.__init__(self, parent=parent)
self.bus = bus
# TODO: CAMPid 980567566238416124867857834291346779
ico_file = os.path.join(QFileInfo.absolutePath(QFileInfo(__file__)), "icon.ico")
ico = QtGui.QIcon(ico_file)
self.setWindowIcon(ico)
ui = ui_file
# TODO: CAMPid 9549757292917394095482739548437597676742
if not QFileInfo(ui).isAbsolute():
ui_file = os.path.join(QFileInfo.absolutePath(QFileInfo(__file__)), ui)
else:
ui_file = ui
ui_file = QFile(ui_file)
ui_file.open(QFile.ReadOnly | QFile.Text)
ts = QTextStream(ui_file)
sio = io.StringIO(ts.readAll())
self.ui = uic.loadUi(sio, self)
self.ui.action_About.triggered.connect(self.about)
device_tree = epyqlib.devicetree.Tree()
device_tree_model = epyqlib.devicetree.Model(root=device_tree)
device_tree_model.device_removed.connect(self._remove_device)
self.ui.device_tree.setModel(device_tree_model)
self.ui.device_tree.device_selected.connect(self.set_current_device)
示例2: FileBasedTextStream
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()
示例3: restoreDir
def restoreDir(self):
"用户点击了“默认运行目录”按钮。"
path = self.txtPath.text().strip()
fi = QFileInfo(path)
if path == "" or not fi.exists():
return
self.txtDir.setText(fi.dir().absolutePath())
示例4: _addIcon
def _addIcon(self):
filter_ = self.tr("Images (*.jpg *.jpeg *.bmp *.png *.tiff *.gif);;"
"All files (*.*)")
fileName, _selectedFilter = QFileDialog.getOpenFileName(self,
self.tr("Open File"), self.latestDir,
filter_)
if fileName:
file_info = QFileInfo(fileName)
self.latestDir = file_info.absolutePath()
image = QImage()
if image.load(fileName):
maxWidth = 22
maxHeight = 15
if image.width() > maxWidth or image.height() > maxHeight:
scaledImage = image.scaled(maxWidth, maxHeight,
Qt.KeepAspectRatio, Qt.SmoothTransformation)
else:
scaledImage = image
ba = QByteArray()
buffer = QBuffer(ba)
buffer.open(QIODevice.WriteOnly)
scaledImage.save(buffer, 'png')
model = self.model()
index = model.index(self.selectedIndex().row(), model.fieldIndex('icon'))
model.setData(index, ba)
示例5: __saveFileName
def __saveFileName(self, directory):
"""
Private method to calculate a name for the file to download.
@param directory name of the directory to store the file into (string)
@return proposed filename and original filename (string, string)
"""
path = parseContentDisposition(self.__reply)
info = QFileInfo(path)
baseName = info.completeBaseName()
endName = info.suffix()
origName = baseName
if endName:
origName += '.' + endName
name = directory + baseName
if endName:
name += '.' + endName
if not self.__requestFilename:
# do not overwrite, if the user is not being asked
i = 1
while QFile.exists(name):
# file exists already, don't overwrite
name = directory + baseName + ('-{0:d}'.format(i))
if endName:
name += '.' + endName
i += 1
return name, origName
示例6: outputFiles
def outputFiles(self, map, fileName):
result = []
# Extract file name without extension and path
fileInfo = QFileInfo(fileName)
base = fileInfo.completeBaseName() + "_"
path = fileInfo.path()
# Loop layers to calculate the path for the exported file
for layer in map.layers():
if layer.layerType() != Layer.TileLayerType:
continue
# Get the output file name for this layer
layerName = layer.name()
layerFileName = base + layerName + ".csv"
layerFilePath = QDir(path).filePath(layerFileName)
result.append(layerFilePath)
# If there was only one tile layer, there's no need to change the name
# (also keeps behavior backwards compatible)
if len(result) == 1:
result[0] = fileName
return result
示例7: open
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')
示例8: checkPluginUpdatesAvailable
def checkPluginUpdatesAvailable(self):
"""
Public method to check the availability of updates of plug-ins.
"""
period = Preferences.getPluginManager("UpdatesCheckInterval")
if period == 0:
return
elif period in [1, 2, 3]:
lastModified = QFileInfo(self.pluginRepositoryFile).lastModified()
if lastModified.isValid() and lastModified.date().isValid():
lastModifiedDate = lastModified.date()
now = QDate.currentDate()
if period == 1 and lastModifiedDate.day() == now.day():
# daily
return
elif period == 2 and lastModifiedDate.daysTo(now) < 7:
# weekly
return
elif period == 3 and \
(lastModifiedDate.daysTo(now) <
lastModifiedDate.daysInMonth()):
# monthly
return
self.__updateAvailable = False
request = QNetworkRequest(
QUrl(Preferences.getUI("PluginRepositoryUrl6")))
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
QNetworkRequest.AlwaysNetwork)
reply = self.__networkManager.get(request)
reply.finished.connect(self.__downloadRepositoryFileDone)
self.__replies.append(reply)
示例9: downloadFile
def downloadFile(self):
self.url = QUrl(self.urlLineEdit.text())
fileInfo = QFileInfo(self.url.path())
fileName = fileInfo.fileName()
if not fileName:
fileName = 'index.html'
if QFile.exists(fileName):
ret = QMessageBox.question(self, "HTTP",
"There already exists a file called %s in the current "
"directory. Overwrite?" % fileName,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if ret == QMessageBox.No:
return
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(self, "HTTP",
"Unable to save the file %s: %s." % (fileName, self.outFile.errorString()))
self.outFile = None
return
self.progressDialog.setWindowTitle("HTTP")
self.progressDialog.setLabelText("Downloading %s." % fileName)
self.downloadButton.setEnabled(False)
self.httpRequestAborted = False
self.startRequest(self.url)
示例10: __open
def __open(self):
"""
Private slot to open the downloaded file.
"""
info = QFileInfo(self.__output)
url = QUrl.fromLocalFile(info.absoluteFilePath())
QDesktopServices.openUrl(url)
示例11: openFolder
def openFolder(self):
"""
Public slot to open the folder containing the downloaded file.
"""
info = QFileInfo(self.__fileName)
url = QUrl.fromLocalFile(info.absolutePath())
QDesktopServices.openUrl(url)
示例12: __insertFlashCookie
def __insertFlashCookie(self, path):
"""
Private method to insert a Flash cookie into the cache.
@param path Flash cookies path
@type str
"""
solFile = QFile(path)
if not solFile.open(QFile.ReadOnly):
return
dataStr = ""
data = bytes(solFile.readAll())
if data:
try:
reader = FlashCookieReader()
reader.setBytes(data)
reader.parse()
dataStr = reader.toString()
except FlashCookieReaderError as err:
dataStr = err.msg
solFileInfo = QFileInfo(solFile)
cookie = FlashCookie()
cookie.contents = dataStr
cookie.name = solFileInfo.fileName()
cookie.path = solFileInfo.canonicalPath()
cookie.size = int(solFile.size())
cookie.lastModified = solFileInfo.lastModified()
cookie.origin = self.__extractOriginFrom(path)
self.__flashCookies.append(cookie)
示例13: __init__
def __init__(self, pluginManager, pluginFileNames, parent=None):
"""
Constructor
@param pluginManager reference to the plugin manager object
@param pluginFileNames list of plugin files suggested for
installation (list of strings)
@param parent parent of this dialog (QWidget)
"""
super(PluginInstallWidget, self).__init__(parent)
self.setupUi(self)
if pluginManager is None:
# started as external plugin installer
from .PluginManager import PluginManager
self.__pluginManager = PluginManager(doLoadPlugins=False)
self.__external = True
else:
self.__pluginManager = pluginManager
self.__external = False
self.__backButton = self.buttonBox.addButton(
self.tr("< Back"), QDialogButtonBox.ActionRole)
self.__nextButton = self.buttonBox.addButton(
self.tr("Next >"), QDialogButtonBox.ActionRole)
self.__finishButton = self.buttonBox.addButton(
self.tr("Install"), QDialogButtonBox.ActionRole)
self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close)
self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel)
userDir = self.__pluginManager.getPluginDir("user")
if userDir is not None:
self.destinationCombo.addItem(
self.tr("User plugins directory"),
userDir)
globalDir = self.__pluginManager.getPluginDir("global")
if globalDir is not None and os.access(globalDir, os.W_OK):
self.destinationCombo.addItem(
self.tr("Global plugins directory"),
globalDir)
self.__installedDirs = []
self.__installedFiles = []
self.__restartNeeded = False
downloadDir = QDir(Preferences.getPluginManager("DownloadPath"))
for pluginFileName in pluginFileNames:
fi = QFileInfo(pluginFileName)
if fi.isRelative():
pluginFileName = QFileInfo(
downloadDir, fi.fileName()).absoluteFilePath()
self.archivesList.addItem(pluginFileName)
self.archivesList.sortItems()
self.__currentIndex = 0
self.__selectPage()
示例14: set_mode_by_filename
def set_mode_by_filename(self, filename):
file = QFile(filename)
fileinfo = QFileInfo(file)
suffix = fileinfo.suffix()
self.page().mainFrame().evaluateJavaScript("editor.getSession().setMode('%s');" % (
self.SUFIX_2_MODE[suffix] if suffix in self.SUFIX_2_MODE else self.SUFIX_2_MODE[None]
))
示例15: onActivated
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)