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/')
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])
def __init__(self, application, **kwargs): #print(self.game_list) self.lutris = application window = Gtk.Window() window.set_size_request(800, 600) # webkit (see use of webkit, cause this use jdk with alot dependencies) webView = WebKit.WebView() webView.connect("load-finished", self.on_load_finished) webView.connect("navigation-requested", self.on_navigation_requested) webView.open('' + os.path.join(datapath.get(), 'xmb', 'index.html')) settings = WebKit.WebSettings() settings.set_property('enable-default-context-menu', False) settings.set_property('enable-file-access-from-file-uris', True) webView.set_settings(settings) # to close window correct window.connect("destroy", self.on_quit) # scroll scrolls = Gtk.ScrolledWindow() scrolls.add(webView) # add webkit and start window #window.fullscreen() window.add(scrolls) window.show_all() Gtk.main()
def init_gui(self): self.vbox = Gtk.VBox() #---- set up webkit pane -----# self.webview = WebKit.WebView() self.webview.connect("navigation-requested", self.navigation_request_cb) scroll = Gtk.ScrolledWindow() scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scroll.set_shadow_type(Gtk.ShadowType.NONE) scroll.add(self.webview) # set up webkit settings to match gtk font settings self.websettings = WebKit.WebSettings() self.webview.set_settings(self.websettings) self.apply_font_settings() self.webview.connect("style-set", self.style_set_cb) #---- pack everything into side pane ----# self.buttons = Gtk.HBox(spacing=3) self.buttons.set_margin_start(6) self.buttons.set_margin_end(6) self.vbox.pack_start(self.buttons, False, True, 6) self.vbox.pack_start(scroll, True, True, 0) self.vbox.show_all() self.vbox.set_size_request(200, -1) self.shell.add_widget(self.vbox, RB.ShellUILocation.RIGHT_SIDEBAR, True, True)
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)
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)
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)
def __init__(self): super(VKWebkitAuth, self).__init__(_("vk.com authorization"), None, Gtk.DialogFlags.MODAL, ()) 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.web_view.show() self.vbox.pack_start(self.web_view, False, False, 0) self.web_view.connect('onload-event', 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:%s@%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.first_page_loaded = False
def init_view(self): settings = WebKit.WebSettings() for setting in self.webkit_settings: settings.set_property(*setting) dimensions = self.load_config() self.view = WebKit.WebView() self.view.set_settings(settings) self.sw = Gtk.ScrolledWindow() self.sw.add(self.view) self.win = Gtk.Window() self.win.set_size_request(self.min_width, self.min_height) self.win.resize(dimensions['w'], dimensions['h']) self.win.move(dimensions['x'], dimensions['y']) self.win.add(self.sw) self.win.set_title("Wasabi Twitter") self.win.connect("destroy", Gtk.main_quit) self.win.connect("configure-event", self.window_resized) self.win.show_all() #self.view.connect("navigation-requested", self.on_nav_req) self.view.connect("new-window-policy-decision-requested", self.open_external_link) self.view.connect("navigation-policy-decision-requested", self.open_link) GLib.timeout_add_seconds(self.refresh_time, self.fetch_tweets, self.view, self.sw) self.view.load_string(self.full_content, "text/html", "UTF-8", "wasabi://home") Gtk.main()
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)
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)
def __init__(self): # Create window self.window = gtk.Window() self.window.set_icon_from_file(settings['icon']) self.window.connect('destroy', lambda w: gtk.main_quit()) self.window.set_default_size(settings['window_width'], settings['window_height']) # Create navigation bar self.nav = gtk.HBox() self.back = gtk.ToolButton(gtk.STOCK_GO_BACK) self.forward = gtk.ToolButton(gtk.STOCK_GO_FORWARD) self.refresh = gtk.ToolButton(gtk.STOCK_REFRESH) self.address_bar = gtk.Entry() self.back.connect('clicked', self.go_back) self.forward.connect('clicked', self.go_forward) self.refresh.connect('clicked', self.refresh_page) self.address_bar.connect('activate', self.load_page) # Buttons and url-field self.nav.pack_start(self.back, expand=False, fill=False, padding=0) self.nav.pack_start(self.forward, expand=False, fill=False, padding=0) self.nav.pack_start(self.refresh, expand=False, fill=False, padding=0) self.nav.pack_start(self.address_bar, expand=True, fill=True, padding=5) # Create view for webpage self.view = gtk.ScrolledWindow() self.wv = webkit.WebView() # Webview settings wvs = webkit.WebSettings() wvs.set_property('user-agent', settings['ua']) self.wv.set_settings(wvs) self.wv.open(settings['start_url']) self.wv.connect('title-changed', self.change_title) self.wv.connect('load-committed', self.change_url) self.view.add(self.wv) # Add everything and initialize self.container = gtk.VBox() if settings['enable_nav'] == "true": self.container.pack_start(self.nav, expand=False, fill=False, padding=0) self.container.pack_start(self.view, expand=True, fill=True, padding=0) self.window.add(self.container) self.window.show_all() gtk.main()
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)
def __init__(self, coding='utf-8'): Gtk.VBox.__init__(self, False) self.coding = coding self.uri = 'file://' + os.path.dirname(__file__) self.settings = WebKit.WebSettings() self.settings.set_property('enable-default-context-menu', False) self.settings.set_property('enable-developer-extras', True) self.settings.set_property('enable-plugins', True) self.settings.set_property('enable-java_applet', False) self.settings.set_property('enable-page-cache', True) self.settings.set_property('enable-file-access-from-file-uris', True) self.settings.set_property('enable-offline-web-application_cache', False) self.settings.set_property('enable-html5-local-storage', False) self.settings.set_property('enable-html5-database', False) self.settings.set_property('enable-xss-auditor', False) try: self.settings.set_property('enable-dns-prefetching', False) except TypeError: pass self.settings.set_property('enable-caret-browsing', False) self.settings.set_property('resizable-text-areas', False) self.settings.web_security_enabled = False try: self.settings.set_property('enable-accelerated-compositing', True) except TypeError: print "No support for accelerated compositing" self.view = WebKit.WebView() self.view.set_settings(self.settings) #Added new properties in this way cause 'from' is recognized as a key word self.view.get_settings().set_property( 'enable-universal-access-from-file-uris', True) self.view.connect('load-started', self.__started) self.view.connect('load-finished', self.__finished) self.view.connect('console-message', self.__console_message) self.view.connect('navigation-policy-decision-requested', self.__process) self.view.connect('new-window-policy-decision-requested', self.__on_new_window_requested) scroll = Gtk.ScrolledWindow() scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER) scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.view) self.pack_start(scroll, True, True, 0)
def __init__(self): Gtk.ScrolledWindow.__init__(self) self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.webview = WebKit.WebView() self.webview.set_settings(WebKit.WebSettings()) self.webview.set_zoom_level(0.8) self.add(self.webview) self.show_all() self.webview.connect("title-changed", self.__title_changed)
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
def start_inspector(self): view = self.webview self.webview = WebKit.WebView() settings = WebKit.WebSettings() settings.set_property('enable-developer-extras', True) view.set_settings(settings) self.inspector = view.get_inspector() self.inspector.connect("inspect-web-view", self.inspect) self.webview = WebKit.WebView() self.scrolledwindowinspector.add(self.webview) self.scrolledwindowinspector.show() self.source_code_text_view.hide() self.main_view_box_foot.show()
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()
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
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)
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)
def inspect_webview(self, inspector, widget, data=None): inspector_view = WebKit.WebView() self.inspector_window.add(inspector_view) self.inspector_window.resize(800, 400) self.inspector_window.show_all() self.inspector_window.present() return inspector_view
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)
def setup_websettings(self): self.webview.props.full_content_zoom = True self.websettings = WebKit.WebSettings() self.websettings.props.html5_local_storage_database_path = \ get_or_create_directory(op.join( GLib.get_user_cache_dir(), 'fogger/%s/db' % self.app.uuid)) self.websettings.props.enable_accelerated_compositing = True self.websettings.props.enable_dns_prefetching = True self.websettings.props.enable_fullscreen = True self.websettings.props.enable_offline_web_application_cache = True self.websettings.props.javascript_can_open_windows_automatically = True self.websettings.props.enable_html5_database = True self.websettings.props.enable_html5_local_storage = True self.websettings.props.enable_hyperlink_auditing = False self.websettings.props.enable_file_access_from_file_uris = True self.websettings.props.enable_universal_access_from_file_uris = True self.websettings.props.enable_site_specific_quirks = True self.websettings.props.enable_spell_checking = True self.websettings.props.enable_webaudio = True self.websettings.props.enable_webgl = True self.websettings.props.enable_page_cache = True self.websettings.props.enable_plugins = True if logger.level == logging.DEBUG: self.websettings.props.enable_developer_extras = True self.webview.set_settings(self.websettings)
def area_derecha_del_panel(self): scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.descriptor = WebKit.WebView() scrolled_window.add_with_viewport(self.descriptor) return scrolled_window
def __init__(self): self.builder = Gtk.Builder() self.builder.add_from_file("roksolana.glade") self.builder.connect_signals(self) self.toolbar1 = self.builder.get_object("toolbar1") self.back = self.builder.get_object("back") self.forward = self.builder.get_object("forward") self.refresh = self.builder.get_object("refresh") self.stop = self.builder.get_object("stop") self.url = self.builder.get_object("url") self.spinner = self.builder.get_object("spinner") self.progressbar = self.builder.get_object("progressbar") self.window = self.builder.get_object("window1") self.window.connect('destroy', lambda w: Gtk.main_quit()) self.scrolledwindow = self.builder.get_object("scrolledwindow") self.window.show_all() self.webview = WebKit.WebView() self.scrolledwindow.add(self.webview) self.webview.open('http://google.com') self.webview.connect('title-changed', self.change_title) self.webview.connect('load-committed', self.change_url) self.webview.connect('load-committed', self.spinner_on) self.webview.connect('load_finished', self.spinner_off) #self.webview.connect('load-committed', self.progress_on) #self.webview.connect('load-progress-changed', self.progress_change) #self.webview.connect('document_load_finished',self.progress_off) self.webview.show()
def __init__(self, parent): Gtk.Dialog.__init__(self, "My Dialog", parent, 0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) oauth_url = "{0}/authorize?response_type=token&client_id={1}&redirect_uri={2}&scope=read%20write".format( BASE_URL, CLIENT_ID, CALLBACK_URL) self.settings = Gio.Settings( "com.andrewsomething.digitalocean-indicator") box = self.get_content_area() self.web = WebKit.WebView() self.scrolled = Gtk.ScrolledWindow() self.scrolled.add(self.web) box.pack_start(self.scrolled, True, True, 0) self.set_size_request(850, 650) self.set_position(Gtk.WindowPosition.CENTER) self.set_title("Authorize") self.set_skip_taskbar_hint(True) self.set_resizable(False) self.set_default_size(850, 650) self.web.load_uri(oauth_url) self.show_all() self.web.connect('navigation-policy-decision-requested', self.navigation_callback)
def __init__(self, username, password, *args, **kwargs): super(BrowserTab, self).__init__(*args, **kwargs) self.webview = WebKit.WebView() self.show() scrolled_window = Gtk.ScrolledWindow() scrolled_window.add(self.webview) find_box = Gtk.HBox() close_button = Gtk.Button("Close") close_button.connect("clicked", lambda x: find_box.hide()) self.find_entry = Gtk.Entry() self.find_entry.connect("activate", lambda x: self.webview.search_text(self.find_entry.get_text(), False, True, True)) find_box.pack_start(close_button, False, False, 0) find_box.pack_start(self.find_entry, False, False, 0) self.find_box = find_box self.pack_start(scrolled_window, True, True, 0) self.pack_start(find_box, False, False, 0) self.username = username self.password = password scrolled_window.show_all()
def setup_webview(self): self.webview = getattr(self, 'webview', None) or WebKit.WebView() self.setup_websettings() self.setup_webkit_session() self.webview_inspector = self.webview.get_inspector() self.webview_inspector.connect('inspect-web-view', self.inspect_webview) self.inspector_window = Gtk.Window() if self.root: self.downloads = self.root.downloads else: self.downloads = DownloadManager(self) self.webview.connect('notify::progress', self.on_load_progress) self.webview.connect('notify::title', self.on_title_changed) self.webview.connect('download-requested', self.downloads.requested) self.webview.connect('resource-request-starting', self.on_resource_request_starting) self.webview.connect('geolocation-policy-decision-requested', self.on_request_geo_permission) self.webview.connect('create-web-view', self.on_create_webview) self.webview.connect('database-quota-exceeded', self.on_database_quota_exceeded) frame = self.webview.get_main_frame() frame.connect('notify::load-status', self.on_frame_load_status) self.webcontainer.add(self.webview) self.webview.show() try: self.js_lib = open(get_media_file('js/fogger.js', '')).read() except: logger.error('Error reading fogger.js') self.js_lib = ""
def __init__(self, main_instance): Gtk.ScrolledWindow.__init__(self) self._main_instance = main_instance self._view = WebKit.WebView() self._last_y_scroll = -1 self._latest_y_scroll = -2 settings = self._view.get_settings() settings.props.zoom_step = _ZOOM_AMOUNT additional_css_path = \ os.path.join(env.SUGAR_ACTIVITY_ROOT,'styling', 'webkit.css') settings.props.user_stylesheet_uri = 'file://' + additional_css_path self._view.set_highlight_text_matches(True) self._view.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) self._view.connect('button-press-event', self._disable_click) self.add(self._view) self.get_vscrollbar().set_child_visible(False) self.show_all()
def main(): global browser global window frontend = frontend_fill() window = gtk.Window() window.connect('destroy', gtk.main_quit) window.set_title("Linux Lite Control Center") window.set_icon(Pixbuf.new_from_file("{0}/litecc.png".format(app_dir))) window.set_size_request(870, 650) # Valtam do we need to resize window? window.set_resizable(False) window.set_position(gtk.WindowPosition.CENTER), browser = webkit.WebView() swindow = gtk.ScrolledWindow() window.add(swindow) swindow.add(browser) window.show_all() browser.connect("navigation-requested", functions) browser.load_html_string(frontend, "file://{0}/frontend/".format(app_dir)) # no right click menu settings = browser.get_settings() settings.set_property('enable-default-context-menu', False) browser.set_settings(settings) # Engage gtk.main()
def __init__(self): Gtk.Window.__init__(self, skip_pager_hint=True, skip_taskbar_hint=True) self.set_wmclass("sildesktopwidget", "sildesktopwidget") self.set_type_hint(Gdk.WindowTypeHint.DOCK) self.set_size_request(600, 400) self.set_keep_below(True) #Set transparency screen = self.get_screen() rgba = screen.get_rgba_visual() self.set_visual(rgba) self.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 0)) #Add all the parts self.view = WebKit.WebView() self.view.set_transparent(True) self.view.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 0)) self.view.props.settings.props.enable_default_context_menu = False # self.view.load_uri("file:///home/aquarius/Work/jobs.html") self.view.load_uri("https://www.bbc.co.uk/weather/2647793") box = Gtk.Box() self.add(box) box.pack_start(self.view, True, True, 0) self.set_decorated(False) self.connect("destroy", lambda q: Gtk.main_quit()) #Show all the parts self.show_all() self.move(100, 100)
def __init__(self, *args, **kwargs): super(BasicoBrowser, self).__init__(*args, **kwargs) self.webview = WebKit.WebView() settings = self.webview.get_settings() settings.set_property('enable-developer-extras', True) settings.set_property('enable-default-context-menu', True) settings.set_property('default-encoding', 'utf-8') settings.set_property('enable-private-browsing', True) settings.set_property('enable-html5-local-storage', True) # disable plugins, like Adobe Flash and Java settings.set_property('enable-plugins', True) # scale other content besides from text as well self.webview.set_full_content_zoom(True) self.show() scrolled_window = Gtk.ScrolledWindow() scrolled_window.add(self.webview) scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrolled_window.set_hexpand(True) scrolled_window.set_vexpand(True) self.pack_start(scrolled_window, True, True, 0) scrolled_window.show_all()
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:%s@%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
def do_startup(self): """Gtk.Application.run() will call this function()""" Gtk.Application.do_startup(self) gtk_window = Gtk.ApplicationWindow(application=self) gtk_window.set_title('AppKit') webkit_web_view = WebKit.WebView() webkit_web_view.load_uri('http://localhost:' + str(self.port)) screen = Gdk.Screen.get_default() monitor_geometry = screen.get_primary_monitor() monitor_geometry = screen.get_monitor_geometry(monitor_geometry) settings = webkit_web_view.get_settings() settings.set_property('enable-universal-access-from-file-uris', True) settings.set_property('enable-file-access-from-file-uris', True) settings.set_property('default-encoding', 'utf-8') gtk_window.set_default_size( monitor_geometry.width * 1.0 / 2.0, monitor_geometry.height * 3.0 / 5.0, ) scrollWindow = Gtk.ScrolledWindow() scrollWindow.add(webkit_web_view) gtk_window.add(scrollWindow) gtk_window.connect('delete-event', self._on_gtk_window_destroy) webkit_web_view.connect('notify::title', self._on_notify_title) self.gtk_window = gtk_window self.webkit_web_view = webkit_web_view gtk_window.show_all()
def __init__(self, title, url, width, height, resizable, fullscreen, min_size, webview_ready): BrowserView.instance = self self.webview_ready = webview_ready Gdk.threads_init() window = gtk.Window(title=title) if resizable: window.set_size_request(min_size[0], min_size[1]) window.resize(width, height) else: window.set_size_request(width, height) window.set_resizable(resizable) window.set_position(gtk.WindowPosition.CENTER) if fullscreen: window.fullscreen() window.connect("delete-event", gtk.main_quit) scrolled_window = gtk.ScrolledWindow() window.add(scrolled_window) self.window = window self.webview = webkit.WebView() self.webview.connect("notify::visible", self._handle_webview_ready) self.webview.props.settings.props.enable_default_context_menu = False scrolled_window.add(self.webview) window.show_all() if url != None: self.webview.load_uri(url)
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
def test(url: str = 'https://inbox.google.com'): 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 GLib as glib # proxy_uri = libsoup.URI.new(os.getenv('http_proxy')) # session = libwebkit.get_default_session() # session.set_property('proxy-uri', proxy_uri) webview = libwebkit.WebView() settings = webview.get_settings() settings.set_property( 'user-agent', '''Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36''') webview.load_uri(url) scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC) scroll.set_shadow_type(gtk.ShadowType.IN) window = gtk.Window() window.connect_after('destroy', gtk.main_quit) window.add(scroll) scroll.add(webview) window.show_all() gtk.main()
def __init__(self): Renderer.__init__(self) self.window = webkit.WebView() try: self.window.set_custom_encoding('utf-8') # needs webkit 1.1.10 except: # pylint: disable-msg=W0702 pass settings = self.window.get_settings() try: proxy = os.environ['http_proxy'] # webkit use libsoup instead of libcurl. #if proxy: # settings.set_property("use-proxy", True) except: # pylint: disable-msg=W0702 pass try: # needs webkit 1.1.22 settings.set_property("auto-resize-window", True) except: # pylint: disable-msg=W0702 pass try: # needs webkit 1.1.2 settings.set_property("enable-private-browsing", True) except: # pylint: disable-msg=W0702 pass #settings.set_property("ident-string", get_identity()) # do we need it ? Yes if webkit avoid to use local files for security ## The following available starting from WebKitGTK+ 1.1.13 #settings.set_property("enable-universal-access-from-file-uris", True) self.browser = WEBKIT self.title = None self.frame = self.window.get_main_frame() self.window.connect("document-load-finished", self.page_loaded) self.fct = None
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)
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))
def loadSession(self): if not os.path.exists(self.pidir): os.mkdir(self.pidir) if not os.path.exists(self.sessiondir): os.mkdir(self.sessiondir) session = WebKit.get_default_session() cookiepath = self.sessiondir + "/" + "cookies" cookiejar = Soup.CookieJarText(filename=cookiepath, read_only=False) session.add_feature(cookiejar)
def global_webkit_init(): session = WebKit.get_default_session() 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)
def __init__(self): # Create GTK window self.window = Gtk.Window() self.window.set_title('Slacker') self.window.connect('destroy', Gtk.main_quit) # Quit cleanly self.window.set_default_size(1200,720) # Create persistent cookie storage cookiejar = Soup.CookieJarText.new(self.cookie_path, False) cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS) session = WebKit.get_default_session() session.add_feature(cookiejar)
def setup_features(self): try: session = WebKit.get_default_session() cookie = Soup.CookieJarText(filename=os.path.join(CONFIG_ROOT, 'cookies')) session.add_feature(cookie) self._cache = Soup.Cache(cache_dir=os.path.join(CONFIG_ROOT, 'cache'), cache_type=Soup.CacheType.SHARED) session.add_feature(self._cache) self._cache.set_max_size(10 * 1024 * 1024) self._cache.load() except Exception, e: log.error("setup_features failed with %s" % e)
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) except: print 'Error: settings property was not set.' WebKit.set_web_database_directory_path(config.DB_DIR) 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); if config.ENABLE_INSPECTOR: from inspector import HototInspector HototInspector(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)
def __init__ ( self, conf ): cid = conf['client_id'] curl = conf['client_url'] self._conf = conf self._client = stravalib.Client() self._web = WebKit.WebView() self._win = Gtk.Window() self._authurl = self._client.authorization_url(client_id=cid, redirect_uri=curl, scope='write') # Auth condition self._authcv = threading.Condition() # Cookie processing cpath = os.path.expanduser(self._conf['cookiepath']) cookiejar = Soup.CookieJarText.new(cpath, False) cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS) session = WebKit.get_default_session() session.add_feature(cookiejar) # Setup Webkit callbacks self._web.connect('load-committed', self.load_start) self._web.connect('load-error', self.load_error) # Setup Web Window self._win.set_title('Strava Authentication') self._win.set_default_size(800, 600) # Add browser sw = Gtk.ScrolledWindow() sw.add(self._web) self._win.add(sw) # Event handlers self._win.connect('delete-event', Gtk.main_quit) # Hack (for some reason, not opening something here causes # things to crash) self._win.show_all() self._web.open('http://strava.com') self._win.hide()
def __init__(self, toolbar): self._toolbar = toolbar 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) self._webview.connect('notify::uri', self.__load_changed_cb) toolbar.update_back_forward(False, False) toolbar.connect('back-clicked', self.__back_cb) toolbar.connect('forward-clicked', self.__forward_cb) self._webview.show()
def set_property(self, pname, pvalue): """Set a property for WebView or SoupSession """ pname = pname.replace("_", "-") sec = None for ptype, pnames in WEBVIEW_PROPERTY_TYPE.items(): if pname not in pnames: continue sec = WEBKIT_SECTION wk_views = self.current_webviews for wk_view in wk_views: wk_settings = wk_view.get_settings() wk_settings.set_property(pname, pvalue) break if sec is None: for ptype, pnames in SOUP_PROPERTY_TYPE.items(): if pname not in pnames: continue sec = SOUP_SECTION soup_session = WebKit.get_default_session() if pname == "enable-disk-cache": if pvalue: self.load_soup_cache(soup_session) else: self.unload_soup_cache(soup_session) sb = self.builder.get_object("spinbutton_cache_size") sb.props.sensitive = pvalue elif pname == "enable-persistent-cookie": if pvalue: self.load_soup_cookiejar(soup_session) else: self.unload_soup_cookiejar(soup_session) elif pname == "cache-size": cache = self.get_soup_cache(soup_session) if cache: cache.set_max_size(pvalue * 1024 * 1024) elif pname in ["enable-do-not-track"]: pass else: soup_session.set_property(pname, pvalue) break if sec is not None: self.config.set(sec, pname, pvalue)
def __init__(self): Gtk.Window.__init__(self) screen = Gdk.Screen.get_default() self.set_default_size(screen.get_width(), screen.get_height()) # Hide scrollbars style_provider = Gtk.CssProvider() css = "GtkScrollbar{background-color:#000;-GtkRange-slider-width:0;" \ "-GtkRange-trough-border:0;" \ "-GtkScrollbar-has-backward-stepper:false;" \ "-GtkScrollbar-has-forward-stepper:false}" style_provider.load_from_data(css) Gtk.StyleContext.add_provider_for_screen( screen, style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) self.fullscreen() self.connect("delete-event", Gtk.main_quit) self.timeout_id = GObject.timeout_add(POLL_DELAY, self.update, None) self.session = WebKit.get_default_session() self.session.add_feature(Soup.CookieJar()) self.webview = WebKit.WebView() self.webview.set_full_content_zoom(True) self.webview.connect_after('notify::load-status', self._on_load_finished) scrolled_window = Gtk.ScrolledWindow() scrolled_window.add(self.webview) self.add(scrolled_window) self.last_update = 0 self.website = Website(**default_website) self.load_website() self.show_all() cursor = Gdk.Cursor.new(Gdk.CursorType.BLANK_CURSOR) self.get_window().set_cursor(cursor)
def webkit_set_proxy_uri(scheme, host, port, user=None, passwd=None): try: session = WebKit.get_default_session() session.set_property("max-conns", 3) session.set_property("max-conns-per-host", 1) if host: proxy_uri = Soup.URI() 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
def finish_initializing(self, builder): # pylint: disable=E1002 """Set up the main window""" super(LightreadWindow, self).finish_initializing(builder) # We'll need to keep track of the indicator and handler later, so declare them here self.indicator = None self.window_close_handler = None self.AboutDialog = AboutLightreadDialog self.scroller = self.builder.get_object("scroller") #Enables Cookies session = WebKit.get_default_session() cache = os.path.join(xdg_data_home, 'com.caffeinatedcode.lightread') cookie_jar = Soup.CookieJarText.new(os.path.join(cache, 'WebkitSession'), False) session.add_feature(cookie_jar) session.props.max_conns_per_host = 8 self.webview = WebKit.WebView() self.scroller.add(self.webview) self.webview.props.settings.enable_default_context_menu = False self.webviewsettings = self.webview.get_settings() self.webviewsettings.set_property("javascript-can-open-windows-automatically", True) self.webviewsettings.set_property("enable-universal-access-from-file-uris", True) self.webviewsettings.set_property("enable-developer-extras", True) self.webview.load_uri(get_media_file('app/index.html')) self.webview_inspector = self.webview.get_inspector() self.webview_inspector.connect('inspect-web-view', self.inspect_webview) self.inspector_window = Gtk.Window() self.webview.show() #Menubar self.add = self.builder.get_object("add") self.refresh = self.builder.get_object("refresh") self.star = self.builder.get_object("star") self.read = self.builder.get_object("read") self.logout = self.builder.get_object("logout") self.next_article = self.builder.get_object("next-article") self.prev_article = self.builder.get_object("prev-article") self.filter_all = self.builder.get_object("filter-all") self.filter_unread = self.builder.get_object("filter-unread") self.filter_starred = self.builder.get_object("filter-starred") # Unity Support Notify.init('Lightread') self.notification = Notify.Notification.new('Lightread', '', '/usr/share/icons/hicolor/128x128/apps/lightread.png') try: launcher = Unity.LauncherEntry.get_for_desktop_id("extras-lightread.desktop") ql = Dbusmenu.Menuitem.new() updatenews = Dbusmenu.Menuitem.new() updatenews.property_set(Dbusmenu.MENUITEM_PROP_LABEL, "Update News") updatenews.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True) ql.child_append(updatenews) launcher.set_property("quicklist", ql) except NameError: pass # Message Passing Stuff def reload_feeds(this, widget, data=None): self.webview.execute_script('cmd("refresh")') def menuexternal(this, widget, data=None): print(this) print(this.get_name()) self.webview.execute_script('cmd("' + this.get_name() + '")') def _navigation_requested_cb(view, frame, networkRequest): uri = networkRequest.get_uri() if uri[:26] != 'http://www.instapaper.com/': subprocess.Popen(['xdg-open', uri]) return 1 return def console_message_cb(widget, message, line, source): logger.debug('%s:%s "%s"' % (source, line, message)) return True def title_changed(widget, frame, title): if title != 'null': print title title = title.split("|") #Gets Data from Disk if title[0] == 'count': try: if int(title[1]) == 0: launcher.set_property("count_visible", False) self.set_title("Lightread") else: launcher.set_property("count_visible", True) self.set_title(title[1] + " - Lightread") launcher.set_property("count", int(title[1])) except UnboundLocalError: pass elif title[0] == 'notify': # Update notification and show only if not changed and window not focused if self.notification.get_property('body') != title[2]: if self.is_active() is not True: self.notification.set_property('body', title[2]) self.notification.show() elif title[0] == 'copy': clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text(title[1], -1) clipboard.store() elif title[0] == 'gwibber': if sharingsupport: subprocess.call(["/usr/bin/gwibber-poster", "--message", title[1]]) elif title[0] == 'settings': settings_json = json.loads(title[1]) if settings_json.get('indicators') is True: if self.indicator is None: self.indicator = LightreadIndicator(self) self.indicator.show() elif settings_json.get('indicators') is False and self.indicator is not None: # indicator set to false but was already created: hide it self.indicator.hide() # if settings background true and not self.is connected delete-event if settings_json.get('background') is True and self.window_close_handler is None: self.window_close_handler = self.connect('delete-event', self._on_delete_event) elif settings_json.get('background') is False and self.window_close_handler is not None: self.disconnect(self.window_close_handler) self.window_close_handler = None elif title[0] == 'feed_count': if self.indicator is not None: feed_json = json.loads(title[1]) count = int(feed_json['count']) if count > 0: self.indicator.add_indicator(urllib.unquote(feed_json['id']), urllib.unquote(feed_json['title']), count) else: self.indicator.remove_indicator(urllib.unquote(feed_json['id'])) # Connects to WebView self.webview.connect('title-changed', title_changed) self.webview.connect('navigation-requested', _navigation_requested_cb) self.webview.connect('console-message', console_message_cb) self.add.connect("activate", menuexternal, None) self.refresh.connect("activate", menuexternal, None) self.star.connect("activate", menuexternal, None) self.read.connect("activate", menuexternal, None) self.logout.connect("activate", menuexternal, None) self.next_article.connect("activate", menuexternal, None) self.prev_article.connect("activate", menuexternal, None) self.filter_all.connect("activate", menuexternal, None) self.filter_unread.connect("activate", menuexternal, None) self.filter_starred.connect("activate", menuexternal, None) try: updatenews.connect("item-activated", reload_feeds, None) except UnboundLocalError: pass
def __init__(self, com_pipe: object, 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 from gi.repository import Pango as pango from gi.repository import Gio as gio from gi.repository import GdkPixbuf as gdkpixbuf self._gtk = gtk self._gdk = gdk self._glib = glib self._pango = pango self._webkit = libwebkit self._gio = gio self._gdkpixbuf = gdkpixbuf self._revived = [] self._icon_db = libwebkit.get_favicon_database() self._accels = self._gtk.AccelGroup() accel_dict = { ('<Ctrl>t', '<Ctrl><Shift>t'): self._new_tab, ('<Ctrl>w',): self._close_tab, ('<Ctrl><Alt>r',): lambda *a: com_pipe.send(('refresh', True)), ('<Ctrl>l',): self._focus_address_entry, } for accel_tup, func in accel_dict.items(): for accel in accel_tup: keyval, modifier = self._gtk.accelerator_parse(accel) self._accels.connect(keyval, modifier, self._gtk.AccelFlags.VISIBLE, func) for i in range(9): self._accels.connect(self._gdk.keyval_from_name(str(i)), self._gdk.ModifierType.MOD1_MASK, self._gtk.AccelFlags.VISIBLE, self._switch_tab) self._window = self._gtk.Window() self._window.add_accel_group(self._accels) self._window.set_default_size(1024, 768) self._window.set_resizable(True) self._window.set_icon_name('web-browser') # self._window.connect('delete-event', self._quit) self._window.connect('destroy', self._quit) self._tabs = self._gtk.Notebook() self._tabs.connect('page-reordered', self._tab_reordered) self._tabs.connect('page-removed', self._tab_removed) self._tabs.connect('switch-page', self._tab_switched) self._tabs.set_scrollable(True) self._tabs.set_show_tabs(True) self._statusbar = self._gtk.Statusbar() self._status_context = self._statusbar.get_context_id('hover-link') vbox = self._gtk.VBox() vbox.pack_start(self._tabs, True, True, 0) vbox.pack_end(self._statusbar, False, False, 0) self._window.add(vbox) self._window.show_all() self._pipe = com_pipe self._dict = com_dict self._windows = {} self._closed = {} self._glib.io_add_watch(self._pipe.fileno(), self._glib.IO_IN, self._recieve) self._pipe.send(('new-proc', self._make_tab()))
if namespace.webapp:# start web application mode view = WebKit.WebView() # view.connect("navigation-requested", navrequest) browser_settings = view.get_settings() #browser_settings.set_property('user-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1') browser_settings.set_property("enable-media-stream",True) browser_settings.set_property("enable-mediasource",True) view.set_settings(browser_settings) cookiejar = Soup.CookieJarText.new(namespace.apppath + "/.cookies.txt", False) cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS) session = WebKit.get_default_session() session.add_feature(cookiejar) sw = Gtk.ScrolledWindow() sw.connect("key_press_event", browser_key_press) sw.add(view) # hbox=Gtk.HBox(); vbox = Gtk.VBox() vbox.add(sw) win = Gtk.Window()
def __init__(self, width, height): # create the window Gtk.Window.__init__(self) splitter = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL) splitter.show() # create the widget container vbox = Gtk.VBox(homogeneous=False) self.add(splitter) vbox.show() splitter.add1(vbox) # create the menu file_menu = Gtk.Menu() accel_group = Gtk.AccelGroup() self.add_accel_group(accel_group) quit_item = Gtk.MenuItem() quit_item.set_label('_Quit') quit_item.set_use_underline(True) accel = Gtk.accelerator_parse('<Control>q') quit_item.add_accelerator('activate', accel_group, accel[0], accel[1], Gtk.AccelFlags.VISIBLE) quit_item.show() quit_item.connect('activate', self.quit) file_menu.append(quit_item) quit_item.show() menu_bar = Gtk.MenuBar() vbox.pack_start(menu_bar, False, False, 0) menu_bar.show() file_item = Gtk.MenuItem() file_item.set_label('_File') file_item.set_use_underline(True) file_item.show() file_item.set_submenu(file_menu) menu_bar.append(file_item) #Settings #self.settings = Settings("com.dz0ny.ubuntu-si-welcome") # create the WebView self.scroller = Gtk.ScrolledWindow() # Enables Cookies session = WebKit.get_default_session() cache = os.path.join(xdg_data_home(), 'com.dz0ny.ubuntu-si-welcome') cookie_jar = Soup.CookieJarText.new(os.path.join(cache, 'WebkitSession'), False) session.add_feature(cookie_jar) session.props.max_conns_per_host = 8 self.webview = WebKit.WebView() self.scroller.add(self.webview) self.webview.props.settings.enable_default_context_menu = False settings = self.webview.get_settings() settings.set_property("enable-plugins", False) settings.set_property('javascript-can-open-windows-automatically', True) settings.set_property('enable-universal-access-from-file-uris', True) settings.set_property('enable-developer-extras', False) self.webview_inspector = self.webview.get_inspector() self.webview_inspector.connect('inspect-web-view', self.inspect_webview) self.inspector_window = Gtk.Window() self.webview.show() self.scroller.show() # and use that for sizing self.set_size_request(width, height) # add the webkit window vbox.pack_start(self.scroller, True, True, 0) self.webview.connect("navigation-policy-decision-requested", self._on_new_window) #self.webview.connect("console-message", self._on_console_message) # a possible way to do IPC (script or title change) self.webview.connect("script-alert", self._on_script_alert) self.webview.connect("title-changed", self._on_title_changed) html_file = """%s/web_app/public/index.html""" % get_data_path() self.webview.open(html_file)
def __init__(self, handle): activity.Activity.__init__(self, handle) _logger.debug('Starting the web activity') session = WebKit.get_default_session() session.set_property('accept-language-auto', True) session.set_property('ssl-use-system-ca-file', True) session.set_property('ssl-strict', False) # By default, cookies are not stored persistently, we have to # add a cookie jar so that they get saved to disk. We use one # with a SQlite database: cookie_jar = SoupGNOME.CookieJarSqlite(filename=_cookies_db_path, read_only=False) session.add_feature(cookie_jar) _seed_xs_cookie(cookie_jar) # FIXME # downloadmanager.remove_old_parts() self._force_close = False self._tabbed_view = TabbedView() self._tabbed_view.connect('focus-url-entry', self._on_focus_url_entry) self._tabbed_view.connect('switch-page', self.__switch_page_cb) self._tray = HTray() self.set_tray(self._tray, Gtk.PositionType.BOTTOM) self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self) self._edit_toolbar = EditToolbar(self) self._view_toolbar = ViewToolbar(self) self._primary_toolbar.connect('add-link', self._link_add_button_cb) self._primary_toolbar.connect('go-home', self._go_home_button_cb) self._primary_toolbar.connect('go-library', self._go_library_button_cb) self._primary_toolbar.connect('set-home', self._set_home_button_cb) self._primary_toolbar.connect('reset-home', self._reset_home_button_cb) self._edit_toolbar_button = ToolbarButton( page=self._edit_toolbar, icon_name='toolbar-edit') self._primary_toolbar.toolbar.insert( self._edit_toolbar_button, 1) view_toolbar_button = ToolbarButton( page=self._view_toolbar, icon_name='toolbar-view') self._primary_toolbar.toolbar.insert( view_toolbar_button, 2) self._primary_toolbar.show_all() self.set_toolbar_box(self._primary_toolbar) self.set_canvas(self._tabbed_view) self._tabbed_view.show() self.model = Model() self.model.connect('add_link', self._add_link_model_cb) self.connect('key-press-event', self._key_press_cb) if handle.uri: self._tabbed_view.current_browser.load_uri(handle.uri) elif not self._jobject.file_path: # TODO: we need this hack until we extend the activity API for # opening URIs and default docs. self._tabbed_view.load_homepage() self.messenger = None self.connect('shared', self._shared_cb) # Get the Presence Service self.pservice = presenceservice.get_instance() try: name, path = self.pservice.get_preferred_connection() self.tp_conn_name = name self.tp_conn_path = path self.conn = telepathy.client.Connection(name, path) except TypeError: _logger.debug('Offline') self.initiating = None if self.get_shared_activity() is not None: _logger.debug('shared: %s', self.get_shared()) # We are joining the activity _logger.debug('Joined activity') self.connect('joined', self._joined_cb) if self.get_shared(): # We've already joined self._joined_cb() else: _logger.debug('Created activity') # README: this is a workaround to remove old temp file # http://bugs.sugarlabs.org/ticket/3973 self._cleanup_temp_files()