本文整理汇总了Python中PyQt4.QtCore.QUrl.host方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.host方法的具体用法?Python QUrl.host怎么用?Python QUrl.host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QUrl
的用法示例。
在下文中一共展示了QUrl.host方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DownloadFtp
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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
示例2: queryProxy
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [as 别名]
def queryProxy(self, query):
"""
Public method to determine a proxy for a given query.
@param query reference to the query object (QNetworkProxyQuery)
@return list of proxies in order of preference (list of QNetworkProxy)
"""
if query.queryType() == QNetworkProxyQuery.UrlRequest and \
query.protocolTag() in ["http", "https", "ftp"] and \
Preferences.getUI("UseProxy"):
if Preferences.getUI("UseSystemProxy"):
proxyList = QNetworkProxyFactory.systemProxyForQuery(query)
if sys.platform not in ["darwin", "nt"] and \
len(proxyList) == 1 and \
proxyList[0].type() == QNetworkProxy.NoProxy:
# try it the Python way
# scan the environment for variables named <scheme>_proxy
# scan over whole environment to make this case insensitive
for name, value in os.environ.items():
name = name.lower()
if value and name[-6:] == '_proxy' and \
name[:-6] == query.protocolTag().toLower():
url = QUrl(value)
if url.scheme() in ["http", "https"]:
proxyType = QNetworkProxy.HttpProxy
else:
proxyType = QNetworkProxy.FtpCachingProxy
proxy = QNetworkProxy(proxyType, url.host(), url.port(),
url.userName(), url.password())
proxyList = [proxy]
break
if proxyList:
proxyList[0].setUser(Preferences.getUI("ProxyUser"))
proxyList[0].setPassword(Preferences.getUI("ProxyPassword"))
return proxyList
else:
return [QNetworkProxy(QNetworkProxy.NoProxy)]
else:
host = Preferences.getUI("ProxyHost")
if not host:
QMessageBox.critical(None,
self.trUtf8("Proxy Configuration Error"),
self.trUtf8("""Proxy usage was activated"""
""" but no proxy host configured."""))
return [QNetworkProxy(QNetworkProxy.DefaultProxy)]
else:
pProxyType = Preferences.getUI("ProxyType")
if pProxyType == 0:
proxyType = QNetworkProxy.HttpProxy
elif pProxyType == 1:
proxyType = QNetworkProxy.HttpCachingProxy
elif pProxyType == 2:
proxyType = QNetworkProxy.Socks5Proxy
proxy = QNetworkProxy(proxyType, host,
Preferences.getUI("ProxyPort"),
Preferences.getUI("ProxyUser"),
Preferences.getUI("ProxyPassword"))
return [proxy, QNetworkProxy(QNetworkProxy.DefaultProxy)]
else:
return [QNetworkProxy(QNetworkProxy.NoProxy)]
示例3: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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)
示例4: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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
示例5: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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)
示例7: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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)
示例8: getObservationsUrl
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [as 别名]
def getObservationsUrl (self):
try:
url = QUrl(self.operationsMetadata['GetObservation'].methods['Post'])
#Para servidores mal configurados
if url.host() == 'localhost':
url.setHost (self.url.host())
url.setPort (self.url.port())
return url
return url
except:
return QUrl()
示例9: set_proxy
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [as 别名]
def set_proxy(proxy):
proxy_url = QUrl(proxy)
if unicode(proxy_url.scheme()).startswith('http'):
protocol = QNetworkProxy.HttpProxy
else:
protocol = QNetworkProxy.Socks5Proxy
QNetworkProxy.setApplicationProxy(
QNetworkProxy(
protocol,
proxy_url.host(),
proxy_url.port(),
proxy_url.userName(),
proxy_url.password()))
示例10: __init__
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [as 别名]
class CoverArtImage:
support_types = False
# consider all images as front if types aren't supported by provider
is_front = True
def __init__(self, url=None, types=[u'front'], comment=''):
if url is not None:
self.parse_url(url)
else:
self.url = None
self.types = types
self.comment = comment
def parse_url(self, url):
self.url = QUrl(url)
self.host = str(self.url.host())
self.port = self.url.port(80)
self.path = str(self.url.encodedPath())
if self.url.hasQuery():
self.path += '?' + str(self.url.encodedQuery())
def is_front_image(self):
# CAA has a flag for "front" image, use it in priority
if self.is_front:
return True
# no caa front flag, use type instead
return u'front' in self.types
def __repr__(self):
p = []
if self.url is not None:
p.append("url=%r" % self.url.toString())
p.append("types=%r" % self.types)
if self.comment:
p.append("comment=%r" % self.comment)
return "%s(%s)" % (self.__class__.__name__, ", ".join(p))
def __unicode__(self):
p = [u'Image']
if self.url is not None:
p.append(u"from %s" % self.url.toString())
p.append(u"of type %s" % u','.join(self.types))
if self.comment:
p.append(u"and comment '%s'" % self.comment)
return u' '.join(p)
def __str__(self):
return unicode(self).encode('utf-8')
示例11: downloadFile
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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)
示例12: __init__
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [as 别名]
def __init__(self, parent=None):
" Initialize QWidget inside MyMainWindow "
super(MyMainWindow, self).__init__(parent)
QWidget.__init__(self)
self.statusBar().showMessage(" " + __doc__)
self.setStyleSheet("QStatusBar{color:grey;}")
self.setWindowTitle(__doc__)
self.setWindowIcon(QIcon.fromTheme("face-monkey"))
self.setFont(QFont("Ubuntu Light", 10))
self.setMaximumSize(QDesktopWidget().screenGeometry().width(), QDesktopWidget().screenGeometry().height())
# directory auto completer
self.completer = QCompleter(self)
self.dirs = QDirModel(self)
self.dirs.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot)
self.completer.setModel(self.dirs)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setCompletionMode(QCompleter.PopupCompletion)
# process
self.process = QProcess(self)
# self.process.finished.connect(self.on_process_finished)
# self.process.error.connect(self.on_process_error)
# Proxy support, by reading http_proxy os env variable
proxy_url = QUrl(environ.get("http_proxy", ""))
QNetworkProxy.setApplicationProxy(
QNetworkProxy(
QNetworkProxy.HttpProxy if str(proxy_url.scheme()).startswith("http") else QNetworkProxy.Socks5Proxy,
proxy_url.host(),
proxy_url.port(),
proxy_url.userName(),
proxy_url.password(),
)
) if "http_proxy" in environ else None
print((" INFO: Proxy Auto-Config as " + str(proxy_url)))
# basic widgets layouts and set up
self.mainwidget = QTabWidget()
self.mainwidget.setToolTip(__doc__)
self.mainwidget.setMovable(True)
self.mainwidget.setTabShape(QTabWidget.Triangular)
self.mainwidget.setTabsClosable(True)
self.mainwidget.setContextMenuPolicy(Qt.CustomContextMenu)
self.mainwidget.tabCloseRequested.connect(
lambda: self.mainwidget.setTabPosition(1)
if self.mainwidget.tabPosition() == 0
else self.mainwidget.setTabPosition(0)
)
self.setCentralWidget(self.mainwidget)
self.dock1 = QDockWidget()
self.dock2 = QDockWidget()
self.dock3 = QDockWidget()
for a in (self.dock1, self.dock2, self.dock3):
a.setWindowModality(Qt.NonModal)
a.setWindowOpacity(0.9)
a.setWindowTitle(__doc__ if a.windowTitle() == "" else a.windowTitle())
a.setStyleSheet(" QDockWidget::title{text-align:center;}")
a.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable)
self.mainwidget.addTab(a, QIcon.fromTheme("face-cool"), str(a.windowTitle()).strip().lower())
# Paleta de colores para pintar transparente
self.palette().setBrush(QPalette.Base, Qt.transparent)
self.setPalette(self.palette())
self.setAttribute(Qt.WA_OpaquePaintEvent, False)
# toolbar and basic actions
self.toolbar = QToolBar(self)
self.toolbar.setIconSize(QSize(24, 24))
# spacer widget for left
self.left_spacer = QWidget(self)
self.left_spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
# spacer widget for right
self.right_spacer = QWidget(self)
self.right_spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
qaqq = QAction(QIcon.fromTheme("application-exit"), "Quit", self)
qaqq.setShortcut("Ctrl+Q")
qaqq.triggered.connect(exit)
qamin = QAction(QIcon.fromTheme("go-down"), "Minimize", self)
qamin.triggered.connect(lambda: self.showMinimized())
qamax = QAction(QIcon.fromTheme("go-up"), "Maximize", self)
qanor = QAction(QIcon.fromTheme("go-up"), "AutoCenter AutoResize", self)
qanor.triggered.connect(self.center)
qatim = QAction(QIcon.fromTheme("go-up"), "View Date and Time", self)
qatim.triggered.connect(self.timedate)
qabug = QAction(QIcon.fromTheme("help-about"), "Report a Problem", self)
qabug.triggered.connect(
lambda: qabug.setDisabled(True)
if not call("xdg-open mailto:" + "[email protected]".decode("rot13"), shell=True)
else " ERROR "
)
qamax.triggered.connect(lambda: self.showMaximized())
qaqt = QAction(QIcon.fromTheme("help-about"), "About Qt", self)
qaqt.triggered.connect(lambda: QMessageBox.aboutQt(self))
qaslf = QAction(QIcon.fromTheme("help-about"), "About Self", self)
qaslf.triggered.connect(
lambda: QMessageBox.about(
self.mainwidget,
__doc__,
"".join(
#.........这里部分代码省略.........
示例13: DownloadFtp
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [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)
示例14: __init__
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [as 别名]
def __init__(self, AUTO):
' Initialize QWidget inside MyMainWindow '
super(MyMainWindow, self).__init__()
QWidget.__init__(self)
self.auto = AUTO
self.statusBar().showMessage(' {}'.format(__doc__))
self.setStyleSheet('QStatusBar{color:grey;}')
self.setWindowTitle(__doc__)
self.setWindowIcon(QIcon.fromTheme("face-monkey"))
self.setFont(QFont('Ubuntu Light', 10))
self.setMaximumSize(QDesktopWidget().screenGeometry().width(),
QDesktopWidget().screenGeometry().height())
self.base = path.abspath(path.join(getcwd(), str(datetime.now().year)))
# directory auto completer
self.completer = QCompleter(self)
self.dirs = QDirModel(self)
self.dirs.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot)
self.completer.setModel(self.dirs)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setCompletionMode(QCompleter.PopupCompletion)
# process
self.process1 = None
self.process2 = None
self.cmd1 = 'nice -n {n} arecord{v} -f {f} -c {c} -r {b} -t raw'
self.cmd2 = 'oggenc - -r -C {c} -R {b} -q {q} {d}{t}{a} -o {o}'
self.process3 = QProcess(self)
#self.process3.finished.connect(self.on_process3_finished)
#self.process3.error.connect(self.on_process3_error)
self.cmd3 = ('nice -n 20 ' +
'sox "{o}" -n spectrogram -x {x} -y {y} -z 99 -t "{o}" -o "{o}.png"')
self.actual_file = ''
# re starting timers, one stops, one starts
self.timerFirst = QTimer(self)
self.timerFirst.timeout.connect(self.end)
self.timerSecond = QTimer(self)
self.timerSecond.timeout.connect(self.run)
# Proxy support, by reading http_proxy os env variable
proxy_url = QUrl(environ.get('http_proxy', ''))
QNetworkProxy.setApplicationProxy(QNetworkProxy(QNetworkProxy.HttpProxy
if str(proxy_url.scheme()).startswith('http')
else QNetworkProxy.Socks5Proxy, proxy_url.host(), proxy_url.port(),
proxy_url.userName(), proxy_url.password())) \
if 'http_proxy' in environ else None
print((' INFO: Proxy Auto-Config as ' + str(proxy_url)))
# basic widgets layouts and set up
self.mainwidget = QTabWidget()
self.mainwidget.setToolTip(__doc__)
self.mainwidget.setMovable(True)
self.mainwidget.setTabShape(QTabWidget.Triangular)
self.mainwidget.setContextMenuPolicy(Qt.CustomContextMenu)
self.mainwidget.setStyleSheet('QTabBar{color:white;font-weight:bold;}')
self.mainwidget.setTabBar(TabBar(self))
self.mainwidget.setTabsClosable(False)
self.setCentralWidget(self.mainwidget)
self.dock1 = QDockWidget()
self.dock2 = QDockWidget()
self.dock3 = QDockWidget()
self.dock4 = QDockWidget()
self.dock5 = QDockWidget()
for a in (self.dock1, self.dock2, self.dock3, self.dock4, self.dock5):
a.setWindowModality(Qt.NonModal)
# a.setWindowOpacity(0.9)
a.setWindowTitle(__doc__
if a.windowTitle() == '' else a.windowTitle())
a.setStyleSheet('QDockWidget::title{text-align:center;}')
self.mainwidget.addTab(a, QIcon.fromTheme("face-smile"),
'Double Click Me')
# Paleta de colores para pintar transparente
self.palette().setBrush(QPalette.Base, Qt.transparent)
self.setPalette(self.palette())
self.setAttribute(Qt.WA_OpaquePaintEvent, False)
# toolbar and basic actions
self.toolbar = QToolBar(self)
self.toolbar.setIconSize(QSize(24, 24))
# spacer widget for left
self.left_spacer = QWidget(self)
self.left_spacer.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
# spacer widget for right
self.right_spacer = QWidget(self)
self.right_spacer.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
qaqq = QAction(QIcon.fromTheme("application-exit"), 'Quit', self)
qaqq.setShortcut('Ctrl+Q')
qaqq.triggered.connect(exit)
qamin = QAction(QIcon.fromTheme("go-down"), 'Minimize', self)
qamin.triggered.connect(lambda: self.showMinimized())
qamax = QAction(QIcon.fromTheme("go-up"), 'Maximize', self)
qanor = QAction(QIcon.fromTheme("view-fullscreen"),
'AutoCenter AutoResize', self)
qanor.triggered.connect(self.center)
#.........这里部分代码省略.........
示例15: initialize
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import host [as 别名]
def initialize(self, *args, **kwargs):
" Init Main Class "
super(Main, self).initialize(*args, **kwargs)
self.completer, self.dirs = QCompleter(self), QDirModel(self)
self.dirs.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot)
self.completer.setModel(self.dirs)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setCompletionMode(QCompleter.PopupCompletion)
self.desktop, self.project, menu = '', '', QMenu('Vagrant')
menu.addAction('UP', lambda: self.vagrant_c('up'))
menu.addAction('HALT', lambda: self.vagrant_c('halt'))
menu.addAction('RELOAD', lambda: self.vagrant_c('reload'))
menu.addAction('STATUS', lambda: self.vagrant_c('status'))
menu.addAction('SUSPEND', lambda: self.vagrant_c('suspend'))
menu.addAction('RESUME', lambda: self.vagrant_c('resume'))
menu.addAction('PROVISION', lambda: self.vagrant_c('provision'))
menu.addAction('PACKAGE', lambda: self.vagrant_c('package'))
menu.addAction('INIT', lambda: self.vagrant_c('init'))
menu.addSeparator()
menu.addAction('DESTROY (!!!)', lambda: self.vagrant_c('destroy'))
self.locator.get_service('explorer').add_project_menu(menu, lang='all')
self.process = QProcess()
self.process.readyReadStandardOutput.connect(self.readOutput)
self.process.readyReadStandardError.connect(self.readErrors)
self.process.finished.connect(self._process_finished)
self.process.error.connect(self._process_finished)
# Proxy support, by reading http_proxy os env variable
proxy_url = QUrl(environ.get('http_proxy', ''))
QNetworkProxy.setApplicationProxy(QNetworkProxy(QNetworkProxy.HttpProxy
if str(proxy_url.scheme()).startswith('http')
else QNetworkProxy.Socks5Proxy, proxy_url.host(), proxy_url.port(),
proxy_url.userName(), proxy_url.password())) \
if 'http_proxy' in environ else None
self.mainwidget = QTabWidget()
self.mainwidget.tabCloseRequested.connect(lambda:
self.mainwidget.setTabPosition(1)
if self.mainwidget.tabPosition() == 0
else self.mainwidget.setTabPosition(0))
self.mainwidget.setStyleSheet('QTabBar{font-weight:bold;}')
self.mainwidget.setMovable(True)
self.mainwidget.setTabsClosable(True)
self.dock, self.scrollable = QDockWidget(), QScrollArea()
self.scrollable.setWidgetResizable(True)
self.scrollable.setWidget(self.mainwidget)
self.dock.setWindowTitle(__doc__)
self.dock.setStyleSheet('QDockWidget::title{text-align: center;}')
self.dock.setWidget(self.scrollable)
self.locator.get_service('misc').add_widget(self.dock,
QIcon.fromTheme("virtualbox"), __doc__)
self.tab1, self.tab2, self.tab3 = QGroupBox(), QGroupBox(), QGroupBox()
self.tab4, self.tab5, self.tab6 = QGroupBox(), QGroupBox(), QGroupBox()
for a, b in ((self.tab1, 'Basics'), (self.tab2, 'General Options'),
(self.tab3, 'VM Package Manager'), (self.tab4, 'VM Provisioning'),
(self.tab5, 'VM Desktop GUI'), (self.tab6, 'Run')):
a.setTitle(b)
a.setToolTip(b)
self.mainwidget.addTab(a, QIcon.fromTheme("virtualbox"), b)
QPushButton(QIcon.fromTheme("help-about"), 'About', self.dock
).clicked.connect(lambda: QMessageBox.information(self.dock, __doc__,
HELPMSG))
self.vmname = QLineEdit(self.get_name())
self.vmname.setPlaceholderText('type_your_VM_name_here_without_spaces')
self.vmname.setToolTip('Type VM name, no spaces or special characters')
self.target = QLabel('<b>Vagrant Target Folder: ' +
path.join(BASE, self.vmname.text()))
self.vmname.textChanged.connect(lambda: self.target.setText(
'<b>Vagrant Target Folder: ' + path.join(BASE, self.vmname.text())))
self.btn1 = QPushButton(QIcon.fromTheme("face-smile-big"), 'Suggestion')
self.btn1.setToolTip('Suggest me a Random VM name !')
self.btn1.clicked.connect(lambda: self.vmname.setText(self.get_name()))
self.vmcode, self.vmarch = QComboBox(), QComboBox()
self.vmcode.addItems(['saucy', 'raring', 'quantal', 'precise'])
self.vmarch.addItems(['x86_64 (amd64) 64-Bits', 'x86 (i386) 32-Bits'])
vboxg1 = QVBoxLayout(self.tab1)
for each_widget in (QLabel('<b>Name for VM'), self.vmname, self.btn1,
QLabel('<b>Choose Ubuntu Codename for the VM:</b>'), self.vmcode,
QLabel('<b>Choose Architecture for VM:'), self.vmarch, self.target):
vboxg1.addWidget(each_widget)
self.chrt = QCheckBox('LOW CPU priority for Backend Process')
self.chttps = QComboBox()
self.chttps.addItems(['https', 'http'])
try:
self.vinfo1 = QLabel('''<b> Vagrant Backend Version: </b> {},
<b> VirtualBox Backend Version: </b> {}. '''.format(
getoutput('vagrant --version', shell=1).strip(),
getoutput('vboxmanage --version', shell=1).strip()))
except:
self.vinfo1 = QLabel('<b>Warning: Failed to query Vagrant Backend!')
self.qckb1 = QCheckBox(' Open target directory later')
self.qckb1.setToolTip('Open the target directory when finished')
#.........这里部分代码省略.........