summaryrefslogtreecommitdiffstats
path: root/usr/share/mageiawelcome/webgui.py
diff options
context:
space:
mode:
Diffstat (limited to 'usr/share/mageiawelcome/webgui.py')
-rw-r--r--usr/share/mageiawelcome/webgui.py139
1 files changed, 0 insertions, 139 deletions
diff --git a/usr/share/mageiawelcome/webgui.py b/usr/share/mageiawelcome/webgui.py
deleted file mode 100644
index 14f7be0..0000000
--- a/usr/share/mageiawelcome/webgui.py
+++ /dev/null
@@ -1,139 +0,0 @@
-# from http://www.aclevername.com/articles/python-webgui/
-
-import time
-import queue
-import _thread
-import urllib.request, urllib.parse, urllib.error
-
-import gi
-from gi.repository import Gdk
-from gi.repository import Gtk
-from gi.repository import GLib
-
-try:
- gi.require_version('WebKit2', '4.0')
- from gi.repository import WebKit2
- have_webkit = True
-except:
- have_webkit = False
-
-class UseWebKit: pass
-
-
-
-use = UseWebKit
-
-class WebKitMethods(object):
-
- @staticmethod
- def create_browser():
- return WebKit2.WebView()
-
- @staticmethod
- def inject_javascript(browser, script):
- browser.execute_script(script)
-
- @staticmethod
- def connect_title_changed(browser, callback):
- def callback_wrapper(widget, param): callback(widget.get_property(param.name))
- browser.connect('notify::title', callback_wrapper)
-
- @staticmethod
- def open_uri(browser, html):
- browser.load_html(html, 'file:///usr/share/mageiawelcome/')
-
-
-if use is UseWebKit:
- implementation = WebKitMethods
-
-
-def asynchronous_gtk_message(fun):
-
- def worker(wargs):
- (function, args, kwargs) = wargs
- function(*args, **kwargs)
-
- def fun2(*args, **kwargs):
- GLib.idle_add(worker, (fun, args, kwargs))
-
- return fun2
-
-
-def synchronous_gtk_message(fun):
-
- class NoResult: pass
-
- def worker(wargs):
- (R, function, args, kwargs) = wargs
- R.result = function(*args, **kwargs)
-
- def fun2(*args, **kwargs):
- class R: result = NoResult
- GLib.idle_add(worker, (R, fun, args, kwargs))
- while R.result is NoResult: time.sleep(0.01)
- return R.result
-
- return fun2
-
-def launch_browser(html, quit_function=None, echo=True):
-
- def no_menu(*args): return True
-
- window = Gtk.Window()
- browser = implementation.create_browser()
- settings = browser.get_settings()
- settings.set_enable_write_console_messages_to_stdout(1)
- settings.set_allow_universal_access_from_file_urls(1);
- browser.connect('context-menu', no_menu)
-
- inspector = browser.get_inspector()
- inspector.show()
-
- box = Gtk.VBox(homogeneous=False, spacing=0)
- window.add(box)
-
-
- if quit_function is not None:
- window.connect('destroy', quit_function)
-
- box.pack_start(browser, expand=True, fill=True, padding=0)
- window.set_icon_name('preferences-desktop-personal')
- window.set_title(_('Welcome to Mageia!'))
- window.set_position(Gtk.WindowPosition.CENTER)
- window.set_default_size(800, 500)
- window.set_size_request(800, 500)
- window.set_resizable(False)
- window.show_all()
-
- message_queue = queue.Queue()
-
- def title_changed(title):
- if title != 'null': message_queue.put(title)
-
- implementation.connect_title_changed(browser, title_changed)
-
- implementation.open_uri(browser, html)
-
- def web_recv():
- if message_queue.empty():
- return None
- else:
- msg = message_queue.get()
- if echo: print('>>>', msg)
- return msg
-
- def web_send(msg):
- if echo: print('<<<', msg)
- asynchronous_gtk_message(implementation.inject_javascript)(browser, msg)
-
- return browser, web_recv, web_send
-
-
-def start_gtk_thread():
- # Start GTK in its own thread:
- Gdk.threads_init()
- Gdk.threads_enter()
- _thread.start_new_thread(Gtk.main, ())
-
-def kill_gtk_thread():
- asynchronous_gtk_message(Gtk.main_quit)()