本文整理汇总了Python中AnyQt.QtCore.QUrl.fromLocalFile方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.fromLocalFile方法的具体用法?Python QUrl.fromLocalFile怎么用?Python QUrl.fromLocalFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QUrl
的用法示例。
在下文中一共展示了QUrl.fromLocalFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [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
示例2: create_html_provider
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def create_html_provider(entry_point):
locations = entry_point.resolve()
replacements = _replacements_for_dist(entry_point.dist)
formatter = string.Formatter()
for target in locations:
# Extract all format fields
format_iter = formatter.parse(target)
fields = {name for _, name, _, _ in format_iter if name}
if not set(fields) <= set(replacements.keys()):
log.warning("Invalid replacement fields %s",
set(fields) - set(replacements.keys()))
continue
target = formatter.format(target, **replacements)
targeturl = qurl_from_path(target)
if not targeturl.isValid():
continue
if targeturl.isLocalFile():
if not os.path.exists(target):
log.info("Local doc root '%s' does not exist.", target)
continue
if target:
return provider.SimpleHelpProvider(
baseurl=QUrl.fromLocalFile(target))
return None
示例3: test_dragEnterEvent_rejects_binary
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_dragEnterEvent_rejects_binary(self):
with named_file("", suffix=".42") as fn:
with open(fn, "wb") as f:
f.write(b"\xc3\x28")
event = self._drag_enter_event(QUrl.fromLocalFile(fn))
self.widget.dragEnterEvent(event)
self.assertFalse(event.isAccepted())
示例4: test_dropEvent_replaces_file
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_dropEvent_replaces_file(self):
with named_file("test", suffix=".42") as fn:
previous = self.widget.text.toPlainText()
event = self._drop_event(QUrl.fromLocalFile(fn))
self.widget.dropEvent(event)
self.assertEqual("test", self.widget.text.toPlainText())
self.widget.text.undo()
self.assertEqual(previous, self.widget.text.toPlainText())
示例5: test_script_insert_mime_file
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_script_insert_mime_file(self):
with named_file("test", suffix=".42") as fn:
previous = self.widget.text.toPlainText()
mime = QMimeData()
url = QUrl.fromLocalFile(fn)
mime.setUrls([url])
self.widget.text.insertFromMimeData(mime)
self.assertEqual("test", self.widget.text.toPlainText())
self.widget.text.undo()
self.assertEqual(previous, self.widget.text.toPlainText())
示例6: test_dropEvent_selects_file
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_dropEvent_selects_file(self):
self.widget.load_data = Mock()
self.widget.source = OWFile.URL
event = self._drop_event(QUrl.fromLocalFile(TITANIC_PATH))
self.widget.dropEvent(event)
self.assertEqual(self.widget.source, OWFile.LOCAL_FILE)
self.assertTrue(path.samefile(self.widget.last_path(), TITANIC_PATH))
self.widget.load_data.assert_called_with()
示例7: url_from_value
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def url_from_value(self, value):
base = value.variable.attributes.get("origin", "")
if QDir(base).exists():
base = QUrl.fromLocalFile(base)
else:
base = QUrl(base)
path = base.path()
if path.strip() and not path.endswith("/"):
base.setPath(path + "/")
url = base.resolved(QUrl(str(value)))
return url
示例8: urlFromValue
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [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 + "/")
if os.path.exists(str(value)):
url = QUrl.fromLocalFile(str(value))
else:
name = QUrl(str(value))
url = origin.resolved(name)
if not url.scheme():
url.setScheme("file")
return url
示例9: create_intersphinx_provider
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def create_intersphinx_provider(entry_point):
locations = entry_point.resolve()
replacements = _replacements_for_dist(entry_point.dist)
formatter = string.Formatter()
for target, inventory in locations:
# Extract all format fields
format_iter = formatter.parse(target)
if inventory:
format_iter = itertools.chain(format_iter,
formatter.parse(inventory))
# Names used in both target and inventory
fields = {name for _, name, _, _ in format_iter if name}
if not set(fields) <= set(replacements.keys()):
log.warning("Invalid replacement fields %s",
set(fields) - set(replacements.keys()))
continue
target = formatter.format(target, **replacements)
if inventory:
inventory = formatter.format(inventory, **replacements)
targeturl = qurl_from_path(target)
if not targeturl.isValid():
continue
if targeturl.isLocalFile():
if os.path.exists(os.path.join(target, "objects.inv")):
inventory = QUrl.fromLocalFile(
os.path.join(target, "objects.inv"))
else:
log.info("Local doc root '%s' does not exist.", target)
continue
else:
if not inventory:
# Default inventory location
inventory = targeturl.resolved(QUrl("objects.inv"))
if inventory is not None:
return provider.IntersphinxHelpProvider(
inventory=inventory, target=target)
return None
示例10: __init__
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def __init__(self, parent=None, bridge=None, *, style='', javascript=''):
class _Bridge(QObject):
@pyqtSlot('QVariantList')
def on_selected_points(_, indices):
self.on_selected_points([np.sort(np.array(selected)).astype(int)
for selected in indices])
@pyqtSlot('QVariantList')
def on_selected_range(_, ranges):
self.on_selected_range(ranges)
if bridge is not None:
# Patch existing user-passed bridge with our selection callbacks
assert isinstance(bridge, QObject), 'bridge needs to be a QObject'
_Bridge = type(bridge.__class__.__name__,
bridge.__class__.__mro__,
dict(bridge.__dict__,
on_selected_points=_Bridge.on_selected_points,
on_selected_range=_Bridge.on_selected_range))
super().__init__(parent=parent,
bridge=_Bridge(),
url=QUrl.fromLocalFile(path.join(path.dirname(__file__),
'_plotly', 'html.html')))
if style:
if path.isfile(style):
with open(style, encoding='utf-8') as f:
style = f.read()
# Add each of the rules of the stylesheet into the document
# If you feel this is overly complicated, be my guest to improve it
for i, style in enumerate(filter(None, style.replace(' ', '').replace('\n', '').split('}'))):
self.evalJS("document.styleSheets[0].insertRule('%s }', 0);" % style)
if javascript:
if isinstance(javascript, str):
javascript = [javascript]
for js in javascript:
if path.isfile(js):
with open(js, encoding='utf-8') as f:
js = f.read()
self.evalJS(js)
示例11: test_drop
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_drop(self):
widget = self.widget
with tempfile.TemporaryDirectory() as tmpdir:
urlpath = QUrl.fromLocalFile(tmpdir)
data = QMimeData()
data.setUrls([urlpath])
pos = widget.recent_cb.rect().center()
actions = Qt.LinkAction | Qt.CopyAction
ev = QDragEnterEvent(pos, actions, data,
Qt.LeftButton, Qt.NoModifier)
assert QApplication.sendEvent(widget.recent_cb, ev)
self.assertTrue(ev.isAccepted())
del ev
ev = QDropEvent(pos, actions, data,
Qt.LeftButton, Qt.NoModifier, QDropEvent.Drop)
assert QApplication.sendEvent(widget.recent_cb, ev)
self.assertTrue(ev.isAccepted())
del ev
self.assertEqual(widget.recent_paths[0].abspath,
urlpath.toLocalFile())
self._startandwait(widget)
self.widget.commit()
示例12: create_html_inventory_provider
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def create_html_inventory_provider(entry_point):
locations = entry_point.resolve()
replacements = _replacements_for_dist(entry_point.dist)
formatter = string.Formatter()
for target, xpathquery in locations:
if isinstance(target, (tuple, list)):
pass
# Extract all format fields
format_iter = formatter.parse(target)
fields = {name for _, name, _, _ in format_iter if name}
if not set(fields) <= set(replacements.keys()):
log.warning("Invalid replacement fields %s",
set(fields) - set(replacements.keys()))
continue
target = formatter.format(target, **replacements)
targeturl = qurl_from_path(target)
if not targeturl.isValid():
continue
if targeturl.isLocalFile():
if not os.path.exists(target):
log.info("Local doc root '%s' does not exist", target)
continue
inventory = QUrl.fromLocalFile(target)
else:
inventory = QUrl(target)
return provider.HtmlIndexProvider(
inventory=inventory, xpathquery=xpathquery)
return None
示例13: test_dragEnterEvent_skips_usupported_files
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_dragEnterEvent_skips_usupported_files(self):
event = self._drag_enter_event(QUrl.fromLocalFile('file.unsupported'))
self.widget.dragEnterEvent(event)
self.assertFalse(event.isAccepted())
示例14: test_dragEnterEvent_skips_osx_file_references
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_dragEnterEvent_skips_osx_file_references(self):
event = self._drag_enter_event(QUrl.fromLocalFile('/.file/id=12345'))
self.widget.dragEnterEvent(event)
self.assertFalse(event.isAccepted())
示例15: test_dragEnterEvent_accepts_urls
# 需要导入模块: from AnyQt.QtCore import QUrl [as 别名]
# 或者: from AnyQt.QtCore.QUrl import fromLocalFile [as 别名]
def test_dragEnterEvent_accepts_urls(self):
event = self._drag_enter_event(QUrl.fromLocalFile(TITANIC_PATH))
self.widget.dragEnterEvent(event)
self.assertTrue(event.isAccepted())