本文整理汇总了Python中PyQt4.QtCore.QUrl.path方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.path方法的具体用法?Python QUrl.path怎么用?Python QUrl.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QUrl
的用法示例。
在下文中一共展示了QUrl.path方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def downloadFile(self, url_to_download, download_location):
url = QUrl(url_to_download)
fileInfo = QFileInfo(url.path())
#fileName = fileInfo.fileName()
fileName = download_location + fileInfo.fileName()
self.file_name = fileName
print("Filename = " + fileName)
if QFile.exists(fileName):
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(self, 'Error',
'Unable to save the file %s: %s.' % (fileName, self.outFile.errorString()))
self.outFile = None
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.httpRequestAborted = False
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if path:
path = str(path)
else:
path = '/'
# Download the file.
self.httpGetId = self.http.get(path, self.outFile)
return fileName
示例2: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def downloadFile(self, url_to_download, fout):
" get the file from remote url to local folder "
url = QUrl(url_to_download)
fileInfo = QFileInfo(url.path())
fileName = path.join(fout, str(fileInfo.fileName()))
if QFile.exists(fileName):
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(
self, "ERROR", "Cant save the file %s: %s." % (fileName, self.outFile.errorString())
)
self.outFile = None
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.httpRequestAborted = False
tpath = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if tpath:
tpath = str(tpath)
else:
tpath = sep
# Download the file.
print(" INFO: Blender Download Started ! ")
self.httpGetId = self.http.get(tpath, self.outFile)
示例3: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def downloadFile(self):
url = QUrl(self.downloadUrl)
fileInfo = QFileInfo(url.path())
#fileName = fileInfo.fileName()
fileName = self.targetDirectory + fileInfo.fileName()
if QFile.exists(fileName):
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(self, 'Error', 'Unable to save the file %s: %s.' % (fileName, self.outFile.errorString()))
self.outFile = None
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.httpRequestAborted = False
print url
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if path:
path = str(path)
else:
path = '/'
# Right at the end we append the query string that is lost, the original author did not include this unfortunately.
parsedUrl = urlparse(self.downloadUrl)
if not parsedUrl.query == '':
# fix this mess, otherwise leave it alone
path = path + "?" + parsedUrl.query
print path
# Download the file.
self.httpGetId = self.http.get(path, self.outFile)
示例4: DownloadFtp
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
class DownloadFtp(Download):
def __init__(self, file_share, local_path, date):
Download.__init__(self, file_share, local_path, date)
self.ftp = QFtp(self)
self.ftp.dataTransferProgress.connect(self.update_progress)
self.ftp.done.connect(self.download_finished)
self.ftp.stateChanged.connect(self.state_changed)
self.url = QUrl(self._file_share.url)
self.out_file = QFile(self.local_path)
self.read_bytes = self.out_file.size()
def start_download(self):
self.ftp.connectToHost(self.url.host(), self.url.port(21))
self.ftp.login()
if self.out_file.open(QIODevice.WriteOnly):
self.ftp.get(self.url.path(), self.out_file)
def stop(self):
self.ftp
def state_changed(self, state):
if state == 1 or state == 2:
self._state = 1
def download_finished(self, _):
print "finished !"
def update_progress(self, read_bytes, total_bytes):
self.read_bytes = read_bytes
示例5: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def downloadFile(self, url, archivo_destino):
url = QUrl(url)
fileName = archivo_destino
directorio_usuario_para_pilas = os.path.dirname(archivo_destino)
if not os.path.exists(directorio_usuario_para_pilas):
os.mkdir(directorio_usuario_para_pilas)
if QFile.exists(fileName):
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(self, 'Error', 'Lo siento, no se puede descargar el archivo desde %s: %s.' % (self.url, self.outFile.errorString()))
self.outFile = None
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.httpRequestAborted = False
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if path:
path = str(path)
else:
path = '/'
self.httpGetId = self.http.get(path, self.outFile)
示例6: search
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def search(self, description):
if description.help_ref:
ref = description.help_ref
else:
raise KeyError()
url = QUrl(self.baseurl).resolved(QUrl(ref))
if url.isLocalFile():
path = url.toLocalFile()
fragment = url.fragment()
if os.path.isfile(path):
return url
elif os.path.isfile("{}.html".format(path)):
url = QUrl.fromLocalFile("{}.html".format(path))
url.setFragment(fragment)
return url
elif os.path.isdir(path) and \
os.path.isfile(os.path.join(path, "index.html")):
url = QUrl.fromLocalFile(os.path.join(path, "index.html"))
url.setFragment(fragment)
return url
else:
raise KeyError()
else:
if url.scheme() in ["http", "https"]:
path = url.path()
if not (path.endswith(".html") or path.endswith("/")):
url.setPath(path + ".html")
return url
示例7: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def downloadFile(self):
url = QUrl(self.url_to_download)
fileName = QFileDialog.getSaveFileName(self, "Enregistrer la liste des dossiers", self.nameFile, "conf")
if QFile.exists(fileName):
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(self, 'Erreur','Impossible d\'enregistrer le fichier %s: %s.' % (fileName, self.outFile.errorString()))
self.outFile = None
return
#Création que la connexion HTTPS
mode = QHttp.ConnectionModeHttps
port = 0
self.http.setHost(url.host(), mode, port)
self.requeteHTTPannule = False
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if path:
path = str(path)
else:
path = '/'
#Concaténation des paramètres à l'URL
path = path+("?")
for item in url.queryItems():
path = path + item[0] + "=" + item[1] + "&"
self.http.setUser(self.login, self.password)
self.httpGetId = self.http.get(path, self.outFile)
示例8: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def downloadFile(self):
url = QUrl(self.url_text.text())
if self.txt_location.text()=="":
QDir.setCurrent("$HOME/Downloads")
else:
QDir.setCurrent(self.loc)
self.statusbar.showMessage("Downloading")
fileInfo = QFileInfo(url.path())
fileName = fileInfo.fileName()
if QFile.exists(fileName):
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(self, 'Error',
'Unable to save the file %s: %s.' % (fileName, self.outFile.errorString()))
self.outFile = None
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.httpRequestAborted = False
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if path:
path = str(path)
else:
path = '$HOME/Downloads'
# Download the file.
self.httpGetId = self.http.get(path, self.outFile)
示例9: urlFromValue
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
def urlFromValue(self, value):
variable = value.variable
origin = variable.attributes.get("origin", "")
if origin and QDir(origin).exists():
origin = QUrl.fromLocalFile(origin)
elif origin:
origin = QUrl(origin)
if not origin.scheme():
origin.setScheme("file")
else:
origin = QUrl("")
base = origin.path()
if base.strip() and not base.endswith("/"):
origin.setPath(base + "/")
name = QUrl(str(value))
url = origin.resolved(name)
if not url.scheme():
url.setScheme("file")
return url
示例10: FTP_Handler
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
class FTP_Handler( QFtp ):
# =======================================================================
def __init__( self, parent=None ):
# -------------------------------------------------------------------
QFtp.__init__( self, parent );
# -------------------------------------------------------------------
self.PARENT = parent;
self.DEBUG = False;
self.LOG_TAG = str(self.__class__.__name__).upper();
# -------------------------------------------------------------------
self.stateChanged.connect( self.ON_STATE_CHANGED );
self.listInfo.connect( self.ON_LIST_INFO_AVAILABLE );
self.commandFinished.connect( self.ON_COMMAND_FINISHED );
self.commandStarted.connect( self.ON_COMMAND_STARTED );
self.readyRead.connect( self.ON_READY_READ );
self.done.connect( self.ON_DONE );
self.dataTransferProgress.connect( self.ON_DATA_TRANSFER_PROGRESS );
self.rawCommandReply.connect( self.ON_RAW_COMMAND_REPLY );
# -------------------------------------------------------------------
self.HOST = "";
self.PATH = "";
self.USER = "";
self.PWD = "";
self.PORT = 21;
# -------------------------------------------------------------------
self.FILE_INFO_LIST = [];
self.LOGIN_SUCCESS = False;
self.ALLOW_TO_RUN = True;
self.LAST_ERROR = QFtp.NoError;
self.NEW_URL = "";
self.SHOW_HIDDEN_FILES = False;
self.SHOW_FILES_FIRST = False;
self.PRINT_CONN_INFO = False;
# -------------------------------------------------------------------
self.REQ_UIDS = {
"connect" : 0,
"login" : 0,
"cd" : 0,
"list" : 0,
}
# -------------------------------------------------------------------
self.PARENT.SPLASH.STATUS( self.LOG_TAG+": [INIT]" );
# -------------------------------------------------------------------
# =======================================================================
def MK_CONNECT( self, _url, _user="anonymous", _pwd="", _port=21 ):
# -------------------------------------------------------------------
try:
req = urllib2.Request( _url, headers=self.PARENT.WEB_PAGE.HEADERS );
resp = urllib2.urlopen( req );
t = resp.headers["content-type"];
self.PARENT.DOWNLOAD_MANAGER.REQUEST( _url, False );
return;
except Exception as _err:
pass;
# -------------------------------------------------------------------
try:
# -----------------------------------------------------------
# Name, isFile, date, size, owner
for _f_info in self.FILE_INFO_LIST:
if _url.split("/")[-1] == _f_info[0] and _f_info[1]:
self.PARENT.DOWNLOAD_MANAGER.REQUEST( "ftp://"+self.HOST+self.PATH+_f_info[0], False );
return;
# -----------------------------------------------------------
self.FILE_INFO_LIST = [];
self.Q_URL = QUrl( _url );
self.USER = str(_user);
self.PWD = str(_pwd);
self.PORT = int(_port);
self.HOST = self.HOST if str(self.Q_URL.host()) == "" else str(self.Q_URL.host());
self.PATH = "/" if str(self.Q_URL.path()) == "" else str(self.Q_URL.path());
# -----------------------------------------------------------
if self.PRINT_CONN_INFO:
print(" --------------------------------------------------------- " );
print("USER: ["+self.USER+"]" );
#.........这里部分代码省略.........
示例11: FileDownloader
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
class FileDownloader(object):
"""The blueprint for downloading file from url."""
def __init__(self, url, output_path, progress_dialog=None):
"""Constructor of the class.
.. versionchanged:: 3.3 removed manager parameter.
:param url: URL of file.
:type url: str
:param output_path: Output path.
:type output_path: str
:param progress_dialog: Progress dialog widget.
:type progress_dialog: QWidget
"""
# noinspection PyArgumentList
self.manager = qgis.core.QgsNetworkAccessManager.instance()
self.url = QUrl(url)
self.output_path = output_path
self.progress_dialog = progress_dialog
if self.progress_dialog:
self.prefix_text = self.progress_dialog.labelText()
self.output_file = None
self.reply = None
self.downloaded_file_buffer = None
self.finished_flag = False
def download(self):
"""Downloading the file.
:returns: True if success, otherwise returns a tuple with format like
this (QNetworkReply.NetworkError, error_message)
:raises: IOError - when cannot create output_path
"""
# Prepare output path
self.output_file = QFile(self.output_path)
if not self.output_file.open(QFile.WriteOnly):
raise IOError(self.output_file.errorString())
# Prepare downloaded buffer
self.downloaded_file_buffer = QByteArray()
# Request the url
request = QNetworkRequest(self.url)
self.reply = self.manager.get(request)
self.reply.readyRead.connect(self.get_buffer)
self.reply.finished.connect(self.write_data)
self.manager.requestTimedOut.connect(self.request_timeout)
if self.progress_dialog:
# progress bar
def progress_event(received, total):
"""Update progress.
:param received: Data received so far.
:type received: int
:param total: Total expected data.
:type total: int
"""
# noinspection PyArgumentList
QCoreApplication.processEvents()
self.progress_dialog.adjustSize()
human_received = humanize_file_size(received)
human_total = humanize_file_size(total)
label_text = tr("%s : %s of %s" % (
self.prefix_text, human_received, human_total))
self.progress_dialog.setLabelText(label_text)
self.progress_dialog.setMaximum(total)
self.progress_dialog.setValue(received)
# cancel
def cancel_action():
"""Cancel download."""
self.reply.abort()
self.reply.deleteLater()
self.reply.downloadProgress.connect(progress_event)
self.progress_dialog.canceled.connect(cancel_action)
# Wait until finished
# On Windows 32bit AND QGIS 2.2, self.reply.isFinished() always
# returns False even after finished slot is called. So, that's why we
# are adding self.finished_flag (see #864)
while not self.reply.isFinished() and not self.finished_flag:
# noinspection PyArgumentList
QCoreApplication.processEvents()
result = self.reply.error()
try:
http_code = int(self.reply.attribute(
QNetworkRequest.HttpStatusCodeAttribute))
except TypeError:
#.........这里部分代码省略.........
示例12: Downloader
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
class Downloader(QDialog):
" MultiThreaded GUI Downloader Dialog "
def __init__(self, parent=None, url_to_download=None, fout=None):
" init class "
super(Downloader, self).__init__(parent)
self.timer = time()
self.httpGetId = 0
self.httpRequestAborted = False
self.url = QUrl(url_to_download)
self.fileInfo = QFileInfo(self.url.path())
self.fout = fout
self.fileName = path.join(fout, str(self.fileInfo.fileName()))
self.statusLabel = QLabel(
"<center><h3>Downloading from:</h3>%s<h3>Saving to:</h3>%s</center>" % (url_to_download, fout)
)
self.bytes = QLabel(" ??? ")
self.closeButton = QPushButton(" Cancel ")
self.closeButton.setAutoDefault(False)
self.progressBar = QProgressBar()
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.closeButton, QDialogButtonBox.RejectRole)
self.http = QHttp(self)
self.http.requestFinished.connect(self.httpRequestFinished)
self.http.dataReadProgress.connect(self.updateDataReadProgress)
self.http.responseHeaderReceived.connect(self.readResponseHeader)
self.closeButton.clicked.connect(self.cancelDownload)
mainLayout = QVBoxLayout()
mainLayout.addWidget(self.statusLabel)
mainLayout.addWidget(self.progressBar)
mainLayout.addWidget(self.bytes)
mainLayout.addWidget(buttonBox)
self.setLayout(mainLayout)
self.setWindowTitle(__doc__ + " - MultiThreaded Downloader ")
self.resize(parent.size().width(), self.size().height())
self.downloadFile(url_to_download, fout)
def downloadFile(self, url_to_download, fout):
" get the file from remote url to local folder "
url = QUrl(url_to_download)
fileInfo = QFileInfo(url.path())
fileName = path.join(fout, str(fileInfo.fileName()))
if QFile.exists(fileName):
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(
self, "ERROR", "Cant save the file %s: %s." % (fileName, self.outFile.errorString())
)
self.outFile = None
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.httpRequestAborted = False
tpath = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if tpath:
tpath = str(tpath)
else:
tpath = sep
# Download the file.
print(" INFO: Blender Download Started ! ")
self.httpGetId = self.http.get(tpath, self.outFile)
def cancelDownload(self):
" abort the download "
self.statusLabel.setText(" INFO: Download Canceled ! ")
self.httpRequestAborted = True
self.http.abort()
self.close()
def httpRequestFinished(self, requestId, error):
" what to do when download is finised "
if requestId != self.httpGetId:
return
if self.httpRequestAborted:
if self.outFile is not None:
self.outFile.close()
self.outFile.remove()
self.outFile = None
return
self.outFile.close()
if error:
self.outFile.remove()
QMessageBox.information(self, "ERROR", "Download Failed: %s." % self.http.errorString())
self.statusLabel.setText(" <center> <h1> ✔ OK! ʘ‿ʘ </h1> <center> ")
print(" INFO: Blender Download Finished ! ")
if self.fileName.lower().endswith((".tar.gz", ".tgz", ".tar.bz2", ".tbz")):
self.extract_file(self.fileName)
#.........这里部分代码省略.........
示例13: DownloadFtp
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import path [as 别名]
class DownloadFtp(Download):
progressModified = pyqtSignal(object)
stateChanged = pyqtSignal(object)
downloadFinished = pyqtSignal(object)
speedModified = pyqtSignal(object)
def __init__(self, file_share, local_path, date, state):
Download.__init__(self, file_share, local_path, date, state)
self.ftp = QFtp(self)
# Signaux
self.ftp.dataTransferProgress.connect(self.update_progress)
self.ftp.done.connect(self.download_finished)
self.ftp.stateChanged.connect(self.state_changed)
# Ouverture de fichiers
self.url = QUrl(self._file_share.url)
self.out_file = QFile(self.local_path)
# Vars
self.read_bytes = self.out_file.size()
# Timer
self.timer = QTimer()
self.timer.start(500)
self.timer.timeout.connect(self.update_speed)
def start_download(self):
self.ftp.connectToHost(self.url.host(), self.url.port(21))
self.ftp.login()
if self.out_file.open(QIODevice.WriteOnly):
self.ftp.get(self.url.path(), self.out_file)
def stop(self):
self._state = 5
self.ftp.abort()
self.timer.stop()
self.ftp.close()
def state_changed(self, state):
if state == 1 or state == 2:
self._state = 1
elif state == 3 or state == 4:
self._state = 3
self.stateChanged.emit(self)
def download_finished(self, _):
print "finished !"
if self.read_bytes != self.file_share.size:
self._state = 7
self._speed = 0
self.timer.stop()
self.ftp.abort()
self.ftp.close()
self._state = 4
self.stateChanged.emit(self)
self.ftp.done.disconnect(self.download_finished)
self.ftp.stateChanged.disconnect(self.state_changed)
self.ftp.dataTransferProgress.disconnect(self.update_progress)
self.downloadFinished.emit(self)
def update_speed(self):
delta = time.time() - self._last_time
self._speed = float(self.read_bytes - self._last_size) / delta
self.last_time = time.time()
self.last_size = self.read_bytes
self.speedModified.emit(self)
def update_progress(self, read_bytes, total_bytes):
self.read_bytes = read_bytes
self.progressModified.emit(self)