当前位置: 首页>>代码示例>>Python>>正文


Python repository.WebKit类代码示例

本文整理汇总了Python中gi.repository.WebKit的典型用法代码示例。如果您正苦于以下问题:Python WebKit类的具体用法?Python WebKit怎么用?Python WebKit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WebKit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self):
        WebKit.WebView.__init__(self)
        
        # Check version
        if WEBKIT2:
            webkit_ver = WebKit.get_major_version(), WebKit.get_minor_version(), WebKit.get_micro_version()
            if webkit_ver[0] < 2 or \
               webkit_ver[1] < 22:
                   raise Exception('WebKit2 wrong version ({0}). Upgrade to version 2.22.x or higher: {}'.format('.'.join(map(str, webkit_ver))))
                   sys.exit()
        
        # Store JS output
        self.js_values = []
        # Store html response
        self.html_response = ''

        # WebKit2 Signals
        if WEBKIT2:
            self.connect('decide-policy', self.on_decide_policy)
            self.connect("load_changed", self.on_load_changed)
            self.connect('button-press-event', lambda w, e: e.button == 3)
        else:
            self.connect('new-window-policy-decision-requested', self.on_nav_request)
            self.connect('resource-load-finished', self.on_resource_load_finished)
            self.connect('button-press-event', lambda w, e: e.button == 3)
        
        # Settings
        s = self.get_settings()
        if WEBKIT2:
            s.set_property('allow_file_access_from_file_urls', True)
            s.set_property('enable-spatial-navigation', False)
            s.set_property('enable_javascript', True)
        else:
            s.set_property('enable-file-access-from-file-uris', True)
            s.set_property('enable-default-context-menu', False)
开发者ID:SolydXK,项目名称:solydxk-welcome,代码行数:35,代码来源:simplebrowser.py

示例2: global_webkit_init

def global_webkit_init():
    """ this sets the defaults for webkit, its important that this gets
        run if you want a secure webkit session
    """
    session = WebKit.get_default_session()
    # add security by default (see bugzilla #666280 and #666276)
    # enable certificates validation in webkit views unless specified otherwise
    if not "SOFTWARE_CENTER_FORCE_DISABLE_CERTS_CHECK" in os.environ:
        session = webkit.get_default_session()
        session.set_property(
            "ssl-ca-file", "/etc/ssl/certs/ca-certificates.crt")
    else:
        # WARN the user!! Do not remove this
        LOG.warning("SOFTWARE_CENTER_FORCE_DISABLE_CERTS_CHECK " +
                    "has been specified, all purchase transactions " +
                    "are now INSECURE and UNENCRYPTED!!")
    # cookies by default
    fname = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "cookies.txt")
    # clear cookies again in a new session, see #1018347 comment #4
    # there is no "logout" support right now on any of the USC pages
    try:
        os.remove(fname)
    except OSError:
        pass
    cookie_jar = Soup.CookieJarText.new(fname, False)
    session.add_feature(cookie_jar)
    # optional session debugging
    if "SOFTWARE_CENTER_DEBUG_WEBKIT" in os.environ:
        # alternatively you can use HEADERS, BODY here
        logger = Soup.Logger.new(Soup.LoggerLogLevel.BODY, -1)
        logger.attach(session)
开发者ID:pombredanne,项目名称:shop,代码行数:31,代码来源:webkit.py

示例3: __init__

    def __init__(self, parentWidget):
        WebKit.WebView.__init__(self)
        self.load_finish_flag = False
        self.set_property('can-focus', True)
        self.set_property('can-default', True)
        self.set_full_content_zoom(1)
        self.parentWidget = parentWidget;

        settings = self.get_settings()
        try:
            settings.set_property('enable-universal-access-from-file-uris', True)
            settings.set_property('javascript-can-access-clipboard', True)
            settings.set_property('enable-default-context-menu', True)
            settings.set_property('enable-page-cache', True)
            settings.set_property('tab-key-cycles-through-elements', True)
            settings.set_property('enable-file-access-from-file-uris', True)
            settings.set_property('enable-spell-checking', False)
            settings.set_property('enable-caret-browsing', False)
            settings.set_property('enable-developer-extras', config.ENABLE_INSPECTOR)
            try:
                # Since 1.7.5
                settings.set_property('enable-accelerated-compositing', True)
            except TypeError:
                pass
        except:
            print 'Error: settings property was not set.'

        WebKit.set_web_database_directory_path(config.get_path("db"))
        WebKit.set_default_web_database_quota(1024**3L)
        
        ## bind events
        self.connect('navigation-requested', self.on_navigation_requested);
        self.connect('new-window-policy-decision-requested', self.on_new_window_requested);
        self.connect('script-alert', self.on_script_alert);
        self.connect('load-finished', self.on_load_finish);
        self.connect("hovering-over-link", self.on_over_link);
#       self.connect('drag_data_received', self.on_drag_data_received)
#       self.connect('drag_motion', self.on_drag_motion)
#       self.connect('drag_drop', self.on_drag_drop)
#       # @TODO DND for gir
#       TARGET_TYPE_URI_LIST = 80
#       dnd_list = [ ( 'text/uri-list', 0, TARGET_TYPE_URI_LIST ) ]
#       te = Gtk.TargetEntry.new(
#           'text/uri-list', 0, TARGET_TYPE_URI_LIST)
#       self.drag_dest_set( Gtk.DestDefaults.ALL,
#                 [te], Gdk.DragAction.COPY)

        if config.ENABLE_INSPECTOR:
            from inspector import HermelinInspector
            HermelinInspector(self.get_inspector())

        templatefile = utils.get_ui_object(config.TEMPLATE)
        template = open(templatefile, 'rb').read()
        self.load_string(template, 'text/html', 'UTF-8', 'file://' + templatefile)
开发者ID:hermelin,项目名称:hermelin-universal,代码行数:54,代码来源:view.py

示例4: on_request_geo_permission

    def on_request_geo_permission(self, view, frame, decision, data=None):
        d = ConfirmDialog(self.app.name, _('Geolocation permission requested'),
            _('%s wants to know your current location. Do you want to share?'\
            % (frame.get_uri() or self.app.name)), None, self,
            _('Share'))
        response = d.run()
        d.destroy()

        if response == Gtk.ResponseType.YES:
            WebKit.geolocation_policy_allow(decision)
        else:
            WebKit.geolocation_policy_deny(decision)
        return True
开发者ID:MadcapJake,项目名称:Fogger,代码行数:13,代码来源:AppWindow.py

示例5: __init__

    def __init__(self):
        Gtk.Dialog.__init__(self, _("vk.com authorization"), None, Gtk.DialogFlags.MODAL, ())
        ChildTopWindow.__init__(self)
        self.set_size_request(550, -1)
        self.auth_url = "http://oauth.vk.com/oauth/authorize?" + \
                        "redirect_uri=http://oauth.vk.com/blank.html&response_type=token&" + \
                        "client_id=%s&scope=%s" % (self.CLIENT_ID, ",".join(self.SCOPE))
        self.web_view = WebKit.WebView()

        self.vbox.pack_start(self.web_view, False, False, 0)

        self.web_view.connect('resource-load-finished', self.on_load)
        session = WebKit.get_default_session()
        if FC().proxy_enable and FC().proxy_url:
            if FC().proxy_user and FC().proxy_password:
                proxy_url = "http://%s:%[email protected]%s" % (FC().proxy_user, FC().proxy_password, FC().proxy_url)
            else:
                proxy_url = "http://%s" % FC().proxy_url
            soup_url = Soup.URI.new(proxy_url)
            session.set_property("proxy-uri", soup_url)
        else:
            session.set_property("proxy-uri", None)

        cookiejar = Soup.CookieJarText.new(cookiefile, False)
        session.add_feature(cookiejar)

        self.access_token = None
        self.user_id = None
        self.on_load_method_finished = False
开发者ID:Cgruppo,项目名称:foobnix,代码行数:29,代码来源:vk_service.py

示例6: config_soup

    def config_soup(self):
        """Load config values to a soup session"""
        soup_session = WebKit.get_default_session()
        cid = soup_session.connect("request_queued",
                self.on_soup_request_queued)
        soup_session.request_queued_cid = cid

        sec = SOUP_SECTION
        for k in SOUP_PROPERTY_TYPE [int]:
            if k in ["cache-size"]:
                continue
            val = self.config.getint(sec, k)
            soup_session.set_property(k, val)
        for k in SOUP_PROPERTY_TYPE [bool]:
            val = self.config.getboolean(sec, k)
            if k == "enable-disk-cache":
                if val:
                    self.load_soup_cache(soup_session)
                else:
                    self.unload_soup_cache(soup_session)
            elif k == "enable-persistent-cookie":
                if val:
                    self.load_soup_cookiejar(soup_session)
                else:
                    self.unload_soup_cookiejar(soup_session)
            elif k in ["enable-do-not-track"]:
                pass
            else:
                soup_session.set_property(k, val)
开发者ID:GreenLunar,项目名称:liferea-plugin-studio,代码行数:29,代码来源:webkitsetting.py

示例7: __init__

    def __init__(self, activity, window_xid):
        self.parent_window_xid = window_xid

        url, title = get_help_url_and_title(activity)
        has_local_help = url is not None
        self._mode = _MODE_HELP if has_local_help else _MODE_SOCIAL_HELP

        Gtk.Window.__init__(self)
        box = Gtk.Box()
        box.set_orientation(Gtk.Orientation.VERTICAL)
        self.add(box)
        box.show()

        self.set_decorated(False)
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_border_width(style.LINE_WIDTH)
        self.set_has_resize_grip(False)

        width = Gdk.Screen.width() - style.GRID_CELL_SIZE * 2
        height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 2
        self.set_size_request(width, height)

        self.connect('realize', self.__realize_cb)
        self.connect('hide', self.__hide_cb)
        self.connect('key-press-event', self.__key_press_event_cb)

        toolbar = Toolbar(title, has_local_help)
        box.pack_start(toolbar, False, False, 0)
        toolbar.show()
        toolbar.connect('stop-clicked', self.__stop_clicked_cb)
        toolbar.connect('mode-changed', self.__mode_changed_cb)

        session = WebKit.get_default_session()
        cookie_jar = SoupGNOME.CookieJarSqlite(
            filename=os.path.join(env.get_profile_path(),
                                  'social-help.cookies'),
            read_only=False)
        session.add_feature(cookie_jar)

        self._webview = WebKit.WebView()
        self._webview.set_full_content_zoom(True)
        self._webview.connect('resource-request-starting',
                              self._resource_request_starting_cb)

        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.add(self._webview)
        scrolled_window.show()

        box.pack_start(scrolled_window, True, True, 0)
        self._webview.show()

        language = self._get_current_language()
        if has_local_help:
            self._help_url = 'file://' + self._get_help_file(language, url)
        self._social_help_url = '{}/goto/{}'.format(
            get_social_help_server(), activity.get_bundle_id())

        self._webview.connect(
            'notify::load-status', self.__load_status_changed_cb)
        self._load_mode(self._mode)
开发者ID:icarito,项目名称:sugar,代码行数:60,代码来源:viewhelp.py

示例8: setup_webkit_session

 def setup_webkit_session(self):
     session = WebKit.get_default_session()
     cache = get_or_create_directory(op.join(
         GLib.get_user_cache_dir(), 'fogger', self.app.uuid))
     cookie_jar = Soup.CookieJarText.new(op.join(cache, 'WebkitSession'), False)
     session.add_feature(cookie_jar)
     session.props.max_conns_per_host = 8
开发者ID:MadcapJake,项目名称:Fogger,代码行数:7,代码来源:AppWindow.py

示例9: __init__

    def __init__(self):
        GObject.GObject.__init__(self)
        self.window = window = Gtk.Window()
        self.inspectorWindow = Gtk.Window()
        self.session = WebKit.get_default_session()
        self.zcbrowser = MBCZeroconfBrowser()

        self.services = {}
        self.zcbrowser.connect('service-up', self.on_new_service)
        self.zcbrowser.connect('service-down', self.on_service_removed)

        self.webView = webView = WebKit.WebView()
        window.add(webView)
        window.set_decorated(False)
        window.set_title('MBC - Vineyard')

        self.init_settings()
        self.add_inspector()
        self.add_cookie_jar()

        webView.connect ("navigation-policy-decision-requested", self.decide_policy_cb)
        webView.connect ("close-web-view", lambda app: Gtk.main_quit())
        webView.connect ("load-error", self.load_error_cb)
        webView.connect ("document-load-finished", self.load_finished_cb)
        webView.connect ("window-object-cleared", self.window_object_cleared_cb)
        webView.set_property ("view-mode", WebKit.WebViewViewMode.FULLSCREEN)

        window.connect ("destroy", lambda app: Gtk.main_quit())
        window.show_all ()
        window.fullscreen ()

        webView.grab_focus()
        # replace this with magic.
        webView.load_uri('http://localhost:3000/')
开发者ID:Lacrymology,项目名称:mbc-vineyard,代码行数:34,代码来源:vineyard.py

示例10: __init__

    def __init__(self, cookie_path="~/.netflix.cookie",
                 *args, **kwargs):
        Gtk.Window.__init__(self, title=sys.argv[1])
        icontheme = Gtk.IconTheme.get_default()
        
        self.set_icon_from_file(sys.argv[3])

        
        super(NetflixWindow, self).__init__(*args, **kwargs)
 
        cookiejar = Soup.CookieJarText.new(
            os.path.expanduser(cookie_path), False)
        cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)
        session = WebKit.get_default_session()
        session.add_feature(cookiejar)



        self.width = int(sys.argv[4])
        self.height = int(sys.argv[5])
        
	self.set_default_size(self.width, self.height)
        self.connect('destroy', Gtk.main_quit)
        self.connect('delete-event', Gtk.main_quit)
 

        self.scroll = Gtk.ScrolledWindow()
        self.web = WebKit.WebView()
        self.add(self.scroll)
        self.scroll.add(self.web)
 
        self.show_all()
 
        self.web.open(sys.argv[2])
开发者ID:LordDan78,项目名称:core-apps,代码行数:34,代码来源:kaiana-netflix.py

示例11: __init__

	def __init__(self, *args, **kwargs):
		super(Messenger, self).__init__(*args, **kwargs)

		self.connect("destroy", Gtk.main_quit)
		self.connect("key-press-event", self.key_pressed)
		self.set_size_request(800, 600)
		self.set_icon_from_file("/opt/messenger/messenger.svg")

		if not os.path.exists(os.path.expanduser("~/.messenger")) or not os.path.isdir(os.path.expanduser("~/.messenger")):
			os.makedirs(os.path.expanduser("~/.messenger"))
			open(os.path.expanduser("~/.messenger/cookies.txt"), "a").close()

		cookiejar = Soup.CookieJarText.new(os.path.expanduser("~/.messenger/cookies.txt"), False)
		cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)
		session = WebKit.get_default_session()
		session.add_feature(cookiejar)

		self.webview = WebKit.WebView()
		self.webview.get_settings().set_property("enable-smooth-scrolling", True)
		self.webview.get_settings().set_property("enable-default-context-menu", False)

		self.webview.connect("title-changed", self.title_changed)
		self.webview.connect("load-finished", self.load_finished)
		self.webview.connect("new-window-policy-decision-requested", self.link_clicked)

		self.scrolled_window = Gtk.ScrolledWindow()

		self.webview.load_uri("https://messenger.com/login")

		self.scrolled_window.add(self.webview)
		self.add(self.scrolled_window)

		self.show_all()
开发者ID:Semmu,项目名称:messenger,代码行数:33,代码来源:messenger.py

示例12: test_have_cookie_jar

 def test_have_cookie_jar(self):
     # ensure we have a cookie jar available
     session = WebKit.get_default_session()
     cookie_jars = [feature 
             for feature in  session.get_features(Soup.SessionFeature)
             if isinstance(feature, Soup.CookieJar)]
     self.assertEqual(len(cookie_jars), 1)
开发者ID:gusDuarte,项目名称:software-center-5.2,代码行数:7,代码来源:test_webkit.py

示例13: webkit_set_proxy_uri

def webkit_set_proxy_uri(scheme = None, host = None, port = None, user = None, passwd = None):
    try:
        session = WebKit.get_default_session()
        if looseVersion(Soup._version) < looseVersion('2.4'):
            session.set_property("max-conns", 3)
            session.set_property("max-conns-per-host", 1)
        else:
            session.set_property("max-conns", 10)
            session.set_property("max-conns-per-host", 5)
        session.set_property("timeout", 10)
        
        if scheme == None:
            return True
        elif ":" in scheme:
            proxy_uri = Soup.URI.new(str(scheme))
        elif host:
            proxy_uri = Soup.URI.new("http://127.0.0.1")
            proxy_uri.set_scheme(str(scheme))
            proxy_uri.set_host(str(host))
            if port:
                proxy_uri.set_port(int(port))
            if user:
                proxy_uri.set_user(str(user))
            if passwd:
                proxy_uri.set_password(str(passwd))

        session.set_property("proxy-uri", proxy_uri)
        return True
    except:
        exctype, value = sys.exc_info()[:2]
        print 'error: webkit_set_proxy_uri: (%s, %s)' % (exctype,value)
        return False
开发者ID:hermelin,项目名称:hermelin-universal,代码行数:32,代码来源:utils.py

示例14: __init__

  def __init__(self):
    Gtk.Window.__init__(self)
    self.set_type_hint(Gdk.WindowTypeHint.DOCK)
    #self.fullscreen()
    self.set_size_request(480, 320)

    WebKit.set_cache_model(WebKit.CacheModel.DOCUMENT_VIEWER)
    self.view = WebKit.WebView()
    self.view.connect("close-web-view", self.closehandler)

    box = Gtk.Box()
    self.add(box)
    box.pack_start(self.view, True, True, 0)
    self.connect("destroy", lambda q: Gtk.main_quit())

    self.show_all()
    self.move(0, 0)
开发者ID:cluening,项目名称:weatherpi,代码行数:17,代码来源:weatherpi-widget.py

示例15: __init__

    def __init__(self, com_dict: object):
        """ Initialize the process.


        """

        from gi.repository import Soup as libsoup
        from gi.repository import WebKit as libwebkit
        from gi.repository import Gtk as gtk
        from gi.repository import Gdk as gdk
        from gi.repository import GLib as glib

        self._icon_db = libwebkit.get_favicon_database()
        cookiejar = libsoup.CookieJar()
        cookiejar.set_accept_policy(libsoup.CookieJarAcceptPolicy.NO_THIRD_PARTY)
        session = libwebkit.get_default_session()
        print("SESSION: ", session)
        session.add_feature(cookiejar)
        session.set_property('ssl-use-system-ca-file', True)
        session.set_property('ssl-strict', True)
        print("SESSION PROP", session.get_property('tls-database'))
        # session.connect('connection-created', self._soup_connection)
        # proxy_uri = libsoup.URI.new(os.getenv('http_proxy'))
        # session.set_property('proxy-uri', proxy_uri)

        self._libsoup = libsoup
        self._gtk = gtk
        self._gdk = gdk
        self._glib = glib
        self._libwebkit = libwebkit

        self._dict = com_dict
        self._coms = []

        self._pid = multiprocessing.current_process().pid

        self._windows = []

        for socket_id, com_pipe in self._dict.items():
            print("CREATING: ", socket_id, com_pipe)
            try:
                com_pipe.send(('pid', self._pid))
            except BrokenPipeError as err:
                print("BROKEN PIPE: ", err, ' on PIPE ', com_pipe)
                continue
            self._windows.append(self._create_window(socket_id, com_pipe))
开发者ID:zepto,项目名称:webbrowser2,代码行数:46,代码来源:webkit_test.py


注:本文中的gi.repository.WebKit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。