本文整理汇总了Python中gi.repository.WebKit2.WebView方法的典型用法代码示例。如果您正苦于以下问题:Python WebKit2.WebView方法的具体用法?Python WebKit2.WebView怎么用?Python WebKit2.WebView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.WebKit2
的用法示例。
在下文中一共展示了WebKit2.WebView方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_window
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def create_window(self):
app_icon = GdkPixbuf.Pixbuf.new_from_file(sys.path[0] + '/images/icon.png')
self.login_window = Gtk.Window(
title = "Games Nebula",
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
icon = app_icon,
width_request = 390,
height_request = 496,
resizable = True
)
self.login_window.connect('delete-event', self.quit_app)
self.setup_cookies()
content_manager = self.new_content_manager()
self.webpage = WebKit2.WebView(user_content_manager=content_manager)
self.webpage.connect('load_changed', self.webpage_loaded)
self.webpage_color = Gdk.RGBA(
red = 0.149019,
green = 0.149019,
blue = 0.149019,
alpha = 1.0,
)
self.webpage.set_background_color(self.webpage_color)
auth_url = get_auth_url()
self.webpage.load_uri(auth_url)
self.scrolled_window = Gtk.ScrolledWindow()
self.scrolled_window.add(self.webpage)
self.login_window.add(self.scrolled_window)
self.login_window.show_all()
示例2: __init__
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def __init__(self, target_url, dest_dir):
"""
:param str target_url: The URL of the target web page to clone.
:param str dest_dir: The path of a directory to write the resources to.
"""
if not has_webkit2:
raise RuntimeError('cloning requires WebKit2GTK+')
self.target_url = urllib.parse.urlparse(target_url)
dest_dir = os.path.abspath(dest_dir)
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
self.dest_dir = os.path.abspath(os.path.normpath(dest_dir))
self.logger = logging.getLogger('KingPhisher.Client.WebPageScraper')
self.cloned_resources = collections.OrderedDict()
"""A :py:class:`collections.OrderedDict` instance of :py:class:`.ClonedResourceDetails` keyed by the web resource they describe."""
self.load_started = False
self.load_failed_event = None
self.__web_resources = []
self.webview = WebKit2.WebView()
web_context = self.webview.get_context()
web_context.set_cache_model(WebKit2.CacheModel.DOCUMENT_VIEWER)
web_context.set_tls_errors_policy(WebKit2.TLSErrorsPolicy.IGNORE)
self.webview.connect('decide-policy', self.signal_decide_policy)
self.webview.connect('load-changed', self.signal_load_changed)
self.webview.connect('load-failed', self.signal_load_failed)
self.webview.connect('resource-load-started', self.signal_resource_load_started)
self.webview.load_uri(self.target_url_str)
示例3: __init__
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def __init__(self, url, proxy=False, *args, **kwargs):
super(WebView, self).__init__(*args, **kwargs)
""" WebKit2 Webview widget """
web_context = WebKit2.WebContext.get_default()
web_context.set_tls_errors_policy(WebKit2.TLSErrorsPolicy.IGNORE)
if proxy:
# proxy False or "http://127.0.0.1:8080"
web_context.set_network_proxy_settings(WebKit2.NetworkProxyMode.CUSTOM, WebKit2.NetworkProxySettings.new(proxy))
self.set_hexpand(True)
self.set_vexpand(True)
self.toolbar = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.address_bar = Gtk.Entry()
self.go_button = Gtk.Button("go")
self.address_bar.set_text(url)
self.toolbar.add(self.address_bar)
self.toolbar.add(self.go_button)
if proxy:
GLib.timeout_add_seconds(2, self._reload)
self.toolbar.set_hexpand(True)
self.address_bar.set_hexpand(True)
self.load_uri(url)
self.toolbar.show_all()
self.show_all()
self.load_uri(url)
self.connect("load-changed", self._load_changed)
self.go_button.connect("clicked", self._load_uri)
示例4: __init__
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def __init__(self, dbg, app):
"""__init__
:param dbg: Dbg instance
:param app: SoftwareBoutique instance
"""
self.webkit = WebKit2
self.webkit.WebView.__init__(self)
self.app = app
self.inspector = False
# Python <--> WebView communication
self.connect("notify::title", self._recv_data)
self.connect("context-menu", self._on_context_menu)
self.connect("load-changed", self.on_finish_load)
# Enable keyboard navigation
self.get_settings().set_enable_spatial_navigation(True)
self.get_settings().set_enable_caret_browsing(True)
# Show console messages in stdout if we're debugging.
if dbg.verbose_level >= 1:
self.get_settings().set_enable_write_console_messages_to_stdout(True)
# Enable web inspector for debugging
if dbg.verbose_level == 2:
self.get_settings().set_property("enable-developer-extras", True)
self.inspector = True
示例5: __init__
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def __init__(self, uri, html=None, verbose=False, cookies=None, verify=True):
window = Gtk.Window()
# API reference: https://lazka.github.io/pgi-docs/#WebKit2-4.0
self.closed = False
self.success = False
self.saml_result = {}
self.verbose = verbose
self.ctx = WebKit2.WebContext.get_default()
if not args.verify:
self.ctx.set_tls_errors_policy(WebKit2.TLSErrorsPolicy.IGNORE)
self.cookies = self.ctx.get_cookie_manager()
if args.cookies:
self.cookies.set_accept_policy(WebKit2.CookieAcceptPolicy.ALWAYS)
self.cookies.set_persistent_storage(args.cookies, WebKit2.CookiePersistentStorage.TEXT)
self.wview = WebKit2.WebView()
window.resize(500, 500)
window.add(self.wview)
window.show_all()
window.set_title("SAML Login")
window.connect('delete-event', self.close)
self.wview.connect('load-changed', self.get_saml_headers)
self.wview.connect('resource-load-started', self.log_resources)
if html:
self.wview.load_html(html, uri)
else:
self.wview.load_uri(uri)
示例6: _init_webview
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def _init_webview(self):
self.webview = WebKit2.WebView()
web_context = self.webview.get_context()
web_context.set_cache_model(WebKit2.CacheModel.DOCUMENT_VIEWER)
web_context.set_tls_errors_policy(WebKit2.TLSErrorsPolicy.IGNORE)
self.webview.connect('decide-policy',
self.signal_decide_policy)
self.webview.connect('load-changed',
self.signal_load_changed)
self.webview.connect('load-failed',
self.signal_load_failed)
self.webview.connect('resource-load-started',
self.signal_resource_load_started)
self.webview.load_uri(self.target_url_str)
示例7: __init__
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def __init__(self, lat=39.36873, lon=-2.417274645879):
self.images = {}
self.echo = True
Gtk.Dialog.__init__(self)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_title(comun.APP)
self.set_default_size(900, 600)
self.set_icon_from_file(comun.ICON)
self.connect('destroy', self.close_application)
#
vbox = Gtk.VBox(spacing=5)
self.get_content_area().add(vbox)
hbox1 = Gtk.HBox()
vbox.pack_start(hbox1, True, True, 0)
self.scrolledwindow1 = Gtk.ScrolledWindow()
self.scrolledwindow1.set_policy(
Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.scrolledwindow1.set_shadow_type(Gtk.ShadowType.IN)
hbox1.pack_start(self.scrolledwindow1, True, True, 0)
self.viewer = WebKit2.WebView()
self.scrolledwindow1.add(self.viewer)
self.scrolledwindow1.set_size_request(900, 600)
self.viewer.connect('load-changed', self.load_changed)
self.viewer.load_uri('file://' + comun.HTML)
self.lat = lat
self.lon = lon
self.set_focus(self.viewer)
self.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
self.show_all()
self.run()
self.destroy()
示例8: on_decide_policy
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def on_decide_policy(self, _web_view, decision, decision_type):
if decision_type == WebKit2.PolicyDecisionType.NAVIGATION_ACTION and \
decision.get_navigation_action().is_user_gesture():
webbrowser.open(decision.get_request().get_uri())
decision.ignore() # Do not follow the link in the WebView
return True
return False
示例9: get_view_for_link
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def get_view_for_link(self, match):
url = match.group("url")
web_view = WebKit2.WebView(zoom_level=0.3125) # ~1280x960
web_view.set_size_request(self.WIDTH, self.HEIGHT)
if GLib.uri_parse_scheme(url) is None:
url = "http://{}".format(url)
web_view.load_uri(url)
return web_view
示例10: __init__
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def __init__(self):
WebKit2.WebView.__init__(self)
webkit_settings = self.get_settings()
webkit_settings.set_property("enable-plugins", False)
示例11: load_html
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def load_html(self, html):
WebKit2.WebView.load_html(self, content=html, base_uri="file:///")
示例12: __init__
# 需要导入模块: from gi.repository import WebKit2 [as 别名]
# 或者: from gi.repository.WebKit2 import WebView [as 别名]
def __init__(self, title='', subtitle='', temperature='', humidity='',
cloudiness=''):
self.images = {}
self.echo = True
Gtk.Window.__init__(self)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_title(comun.APP)
self.set_default_size(900, 600)
self.set_icon_from_file(comun.ICON)
self.connect('destroy', self.close_application)
#
vbox = Gtk.VBox(spacing=5)
self.get_content_area().add(vbox)
hbox1 = Gtk.HBox()
vbox.pack_start(hbox1, True, True, 0)
#
self.scrolledwindow1 = Gtk.ScrolledWindow()
self.scrolledwindow1.set_policy(Gtk.PolicyType.AUTOMATIC,
Gtk.PolicyType.AUTOMATIC)
self.scrolledwindow1.set_shadow_type(Gtk.ShadowType.IN)
hbox1.pack_start(self.scrolledwindow1, True, True, 0)
#
self.viewer = WebKit2.WebView()
self.scrolledwindow1.add(self.viewer)
self.scrolledwindow1.set_size_request(900, 600)
self.viewer.connect('load-changed', self.load_changed)
self.viewer.load_uri('file://' + comun.HTML_GRAPH)
#
self.title = title
self.subtitle = subtitle
self.humidity = humidity
self.cloudiness = cloudiness
self.temperature = temperature
self.set_focus(self.viewer)
self.show_all()
self.message_queue = queue.Queue()
while Gtk.events_pending():
Gtk.main_iteration()
self.show_all()
self.inicialize()
self.run()
self.destroy()
# ###################################################################
# #########################ENGINE####################################
# ###################################################################