本文整理汇总了Python中PyQt5.QtCore.QUrl.fromLocalFile方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.fromLocalFile方法的具体用法?Python QUrl.fromLocalFile怎么用?Python QUrl.fromLocalFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QUrl
的用法示例。
在下文中一共展示了QUrl.fromLocalFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def play(self):
try:
media = self.musics[self.currentIndex]
except:
logger.error("unknow error. musics info: {0}".format(self.musics))
return
if type(media) == str:
if 'http' in media or 'file' in media:
content = QMediaContent(QUrl(media))
else:
content = QMediaContent(QUrl.fromLocalFile(media))
self.musics = self.musics[:self.currentIndex] + [content] + self.musics[self.currentIndex+1:]
media = content
self.parent.setMedia(media)
self.parent.playMusic()
self.tabMusicEvent()
示例2: setCurrentIndex
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def setCurrentIndex(self, index):
try:
media = self.musics[index]
except:
logger.error("unknow error. musics info: {0}".format(self.musics))
return
if type(media) == str:
if 'http' in media or 'file' in media:
content = QMediaContent(QUrl(media))
else:
content = QMediaContent(QUrl.fromLocalFile(media))
self.musics = self.musics[:index] + [content] + self.musics[index+1:]
self.parent.setMedia(content)
else:
self.parent.setMedia(media)
self.parent.playMusic()
self.tabMusicEvent()
self.currentIndex = index
示例3: __init__
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def __init__(self, address: str) -> None:
image_path = os.path.join(
CuraApplication.getInstance().getPluginRegistry().getPluginPath("UM3NetworkPrinting") or "",
"resources", "svg", "cloud-flow-start.svg"
)
super().__init__(
text=I18N_CATALOG.i18nc("@info:status",
"Send and monitor print jobs from anywhere using your Ultimaker account."),
lifetime=0,
dismissable=True,
option_state=False,
image_source=QUrl.fromLocalFile(image_path),
image_caption=I18N_CATALOG.i18nc("@info:status Ultimaker Cloud should not be translated.",
"Connect to Ultimaker Cloud"),
)
self._address = address
self.addAction("", I18N_CATALOG.i18nc("@action", "Get started"), "", "")
self.actionTriggered.connect(self._onCloudFlowStarted)
示例4: connectSlots
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def connectSlots(self):
"""connect slots with buttons/
short cuts/signals
"""
# home tab
self.download.clicked.connect(self.downloadSound)
self.download.setShortcut("CTRL+L")
self.search.clicked.connect(self.searchInfo)
self.search.setShortcut("CTRL+Return")
self.toolButton.clicked.connect(
lambda: QDesktopServices.openUrl(QUrl.fromLocalFile("./sound"))
)
# self.clearBtn.clicked.connect(self.clearAllDownloaded)
示例5: addFileToRecentFiles
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def addFileToRecentFiles(self, file_name: str) -> None:
file_path = QUrl.fromLocalFile(file_name)
if file_path in self._recent_files:
self._recent_files.remove(file_path)
self._recent_files.insert(0, file_path)
if len(self._recent_files) > 10:
del self._recent_files[10]
pref = ""
for path in self._recent_files:
pref += path.toLocalFile() + ";"
self.getPreferences().setValue("%s/recent_files" % self.getApplicationName(), pref)
self.recentFilesChanged.emit()
示例6: __init__
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def __init__(self, fig):
# Create a QApplication instance or use the existing one if it exists
self.app = QApplication.instance() if QApplication.instance() else QApplication(sys.argv)
super().__init__()
# This ensures there is always a reference to this widget and it doesn't get garbage collected
global instance_list
instance_list.append(self)
# self.file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "temp.html"))
self.file_path = os.path.join(os.getcwd(), 'temp.html')
self.setWindowTitle("Plotly Viewer")
plotly.offline.plot(fig, filename=self.file_path, auto_open=False)
self.load(QUrl.fromLocalFile(self.file_path))
self.resize(640, 480)
self.show()
示例7: QmlWidget
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def QmlWidget(qmlpath: str, context: dict, parent: QWidget) -> QWidget:
"""
Generate a QtWidgets widget from a QML file.
:qmlpath
The pat of the QML file.
:context
The context objects to expose to QML.
"""
qmlpath = os.fspath(qmlpath)
view = QQuickView()
engine = view.engine()
for name, obj in context.items():
engine.rootContext().setContextProperty(name, obj)
container = QWidget.createWindowContainer(view, parent)
container.setStyleSheet("Widget { padding: 7px; }")
view.setSource(QUrl.fromLocalFile(qmlpath))
return container
示例8: imprimirReciboRec
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def imprimirReciboRec(self):
self.documento = QWebEngineView()
self.renderTemplate(
"recibo.html",
estilo=self.resourcepath('Template/estilo.css'),
cod=self.tx_Cod.text(),
nome=self.tx_NomeFantasia.text(),
descricao=self.tx_descricao.text(),
valor=self.tx_valor.text().replace('.', ','),
valor_ext=retorno(self.tx_valor.text()),
data=date.today().strftime("%d-%m-%Y")
)
self.documento.load(QUrl.fromLocalFile(
self.resourcepath("report.html")))
self.documento.loadFinished['bool'].connect(self.previaImpressao)
示例9: imprimirReciboPag
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def imprimirReciboPag(self):
self.documento = QWebEngineView()
self.renderTemplate(
"recibopagamento.html",
estilo=self.resourcepath('Template/estilo.css'),
cod=self.tx_Cod.text(),
descricao=self.tx_descricao.text(),
valor=self.tx_valor.text().replace('.', ','),
valor_ext=retorno(self.tx_valor.text()),
data=date.today().strftime("%d-%m-%Y")
)
self.documento.load(QUrl.fromLocalFile(
self.resourcepath("report.html")))
self.documento.loadFinished['bool'].connect(self.previaImpressao)
示例10: test_parent_in_root_dir
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def test_parent_in_root_dir(dir_layout, quteproc):
# This actually works on windows
root_path = os.path.realpath('/')
urlstr = QUrl.fromLocalFile(root_path).toString(QUrl.FullyEncoded)
quteproc.open_url(urlstr)
page = parse(quteproc)
assert page.parent is None
示例11: test_dir
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def test_dir(self, tmpdir):
url = QUrl.fromLocalFile(str(tmpdir))
req = QNetworkRequest(url)
reply = filescheme.handler(req, None, None)
# The URL will always use /, even on Windows - so we force this here
# too.
tmpdir_path = str(tmpdir).replace(os.sep, '/')
assert reply.readAll() == filescheme.dirbrowser_html(tmpdir_path)
示例12: test_file
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def test_file(self, tmpdir):
filename = tmpdir / 'foo'
filename.ensure()
url = QUrl.fromLocalFile(str(filename))
req = QNetworkRequest(url)
reply = filescheme.handler(req, None, None)
assert reply is None
示例13: load_file
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def load_file(self, path: str, force: bool = False):
"""Load a file from disk.
Args:
path: The string path from disk to load (relative to this file)
force: Whether to force loading even if the file is invalid.
"""
self.load_url(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__), path)), force)
示例14: fuzzy_url
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def fuzzy_url(urlstr: str,
cwd: str = None,
relative: bool = False,
do_search: bool = True,
force_search: bool = False) -> QUrl:
"""Get a QUrl based on a user input which is URL or search term.
Args:
urlstr: URL to load as a string.
cwd: The current working directory, or None.
relative: Whether to resolve relative files.
do_search: Whether to perform a search on non-URLs.
force_search: Whether to force a search even if the content can be
interpreted as a URL or a path.
Return:
A target QUrl to a search page or the original URL.
"""
urlstr = urlstr.strip()
path = get_path_if_valid(urlstr, cwd=cwd, relative=relative,
check_exists=True)
if not force_search and path is not None:
url = QUrl.fromLocalFile(path)
elif force_search or (do_search and not is_url(urlstr)):
# probably a search term
log.url.debug("URL is a fuzzy search term")
try:
url = _get_search_url(urlstr)
except ValueError: # invalid search engine
url = qurl_from_user_input(urlstr)
else: # probably an address
log.url.debug("URL is a fuzzy address")
url = qurl_from_user_input(urlstr)
log.url.debug("Converting fuzzy term {!r} to URL -> {}".format(
urlstr, url.toDisplayString()))
ensure_valid(url)
return url
示例15: file_url
# 需要导入模块: from PyQt5.QtCore import QUrl [as 别名]
# 或者: from PyQt5.QtCore.QUrl import fromLocalFile [as 别名]
def file_url(path: str) -> str:
"""Return a file:// url (as string) to the given local path.
Arguments:
path: The absolute path to the local file
"""
url = QUrl.fromLocalFile(path)
return url.toString(QUrl.FullyEncoded) # type: ignore[arg-type]