本文整理汇总了Python中PyQt5.QtCore.QFileInfo.fileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileInfo.fileName方法的具体用法?Python QFileInfo.fileName怎么用?Python QFileInfo.fileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QFileInfo
的用法示例。
在下文中一共展示了QFileInfo.fileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __insertFlashCookie
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
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)
示例2: downloadFile
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
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)
示例3: FileBasedTextStream
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [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()
示例4: __init__
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
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()
示例5: _qfile_to_stream
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
def _qfile_to_stream(a_file, I_or_O, encoding=None):
if not a_file.open(I_or_O | QIODevice.Text) :
f_info = QFileInfo(a_file) # for the name
utilities_logger.error('Error {0} ({1}) opening file {2}'.format(
a_file.error(), a_file.errorString(), f_info.fileName() ) )
return None
fbts = FileBasedTextStream(a_file)
fbts.setCodec(_check_encoding(fbts.filename()) if encoding is None else encoding)
return fbts
示例6: directory
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [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
示例7: addFilesClicked
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
def addFilesClicked(self):
newFiles = QFileDialog.getOpenFileNames(self, "Please select the files to add to stack", "",
"Images (*.png *.jpg *.bmp)")
for file in newFiles[0]:
entries = self.fileTreeWidget.findItems(file, Qt.MatchCaseSensitive)
for entry in entries:
self.fileTreeWidget.takeItem(self.fileTreeWidget.row(entry))
item = QTreeWidgetItem()
fileInfo = QFileInfo(file)
fileInfo.fileName()
exif = getExifInfo(file)
item.setText(0, fileInfo.fileName())
item.setText(1, exif.exposureTime)
item.setText(2, exif.aperture)
item.setText(3, exif.ISO)
item.setText(4, fileInfo.absolutePath())
self.fileTreeWidget.insertTopLevelItem(self.fileTreeWidget.topLevelItemCount(), item)
示例8: getDocumentTitle
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
def getDocumentTitle(self, baseName=False):
if self.markup and not baseName:
text = self.editBox.toPlainText()
try:
return self.markup.get_document_title(text)
except Exception:
self.p.printError()
if self.fileName:
fileinfo = QFileInfo(self.fileName)
basename = fileinfo.completeBaseName()
return (basename if basename else fileinfo.fileName())
return self.tr("New document")
示例9: read_file
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
def read_file(self, path):
"""Read in a file
"""
file = QFile(path)
fileinfo = QFileInfo(file)
file.open(QIODevice.ReadOnly)
data = file.readAll()
codec = QTextCodec.codecForName("UTF-8")
self.contents = codec.toUnicode(data).rstrip("\n")
self.filename = fileinfo.fileName()
示例10: open_file
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
def open_file(self, filename):
if not QFile.exists(filename):
return
# is file open?
idx = self.find_tab_by_filename(filename)
if idx is not None:
self.main_tabs.setCurrentIndex(idx)
return
file = QFile(filename)
fileinfo = QFileInfo(file)
self.create_new_editor(fileinfo.fileName(), filename)
示例11: getDocumentTitle
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
def getDocumentTitle(self, baseName=False):
markup = self.markups[self.ind]
realTitle = ''
if markup and not baseName:
text = self.editBoxes[self.ind].toPlainText()
try:
realTitle = markup.get_document_title(text)
except Exception:
self.printError()
if realTitle:
return realTitle
elif self.fileNames[self.ind]:
fileinfo = QFileInfo(self.fileNames[self.ind])
basename = fileinfo.completeBaseName()
return (basename if basename else fileinfo.fileName())
return self.tr("New document")
示例12: save_as
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
def save_as(self, tab_index, filename):
if not self.is_editor_modified(tab_index):
return
sci = self.get_editor(tab_index)
sci.set_mode_by_filename(filename)
out_file = QFile(filename)
out_file.open(QFile.WriteOnly)
out_file.write(sci.text.encode())
out_file.close()
sci.modified = False
sci.filename = filename
file_info = QFileInfo(out_file)
self.main_tabs.setTabText(tab_index, file_info.fileName())
示例13: FileBasedTextStream
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [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 )
示例14: directory
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [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: open
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import fileName [as 别名]
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")
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)
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()