Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: pyjs/pyjs
base: 21f589b65309
...
head fork: pyjs/pyjs
compare: 6138af7d9c3e
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
8 pyjs/runners/__init__.py
@@ -5,10 +5,14 @@
logging.getLogger(__name__).setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
+from pprint import pformat
from os import path
import ConfigParser
+default_conf = path.join(path.expanduser('~'), '.pyjd', 'pyjdrc')
+
+
class RunnerManager(object):
_platforms = {
@@ -30,7 +34,7 @@ def __init__(self):
self._conf = self._conf.copy()
self._listeners = []
- def set_conf(self, rc=path.join(path.expanduser('~'), '.pyjd', 'pyjdrc')):
+ def set_conf(self, rc=default_conf):
conf = self._conf
cf = ConfigParser.ConfigParser()
cf.read(rc)
@@ -38,7 +42,7 @@ def set_conf(self, rc=path.join(path.expanduser('~'), '.pyjd', 'pyjdrc')):
conf.update(dict(cf.items('gui')))
conf.setdefault('engine', conf['runner'])
conf['runner'] = conf['engine']
- logger.info('conf: %s', conf)
+ logger.info('conf:\n%s', pformat(conf))
def set_runner(self, runner=None):
if runner is None:
View
98 pyjs/runners/giwebkit.py
@@ -22,8 +22,12 @@
from gi.repository import WebKit
import types
+import signal
from traceback import print_exc
+sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)
+
class GIXMLHttpRequestEventTarget(object):
@@ -428,20 +432,27 @@ class ApplicationFrame(object):
class ApplicationView(object):
- def __init__(self, uri, appdir=None, width=800, height=600):
- self.uri = uri
- self.appdir = appdir
- self.width = width = 900
- self.height = height = 1440
+ _resolver = GIResolver(WebKit.DOMObject)
+
+ uri = 'about:blank'
+ #TODO: rename, accidentally removed?
+ appdir = None
+ width = 800
+ height = 600
+ listeners = None
+
+ def __init__(self):
self.listeners = dict()
- self.initialized = False
- def load_app(self):
- uri = self.uri
- if uri.find('://') == -1:
+ def setup(self, uri=uri, **kwds):
+ self.uri = uri
+ for k, v in kwds.iteritems():
+ if hasattr(self, k):
+ setattr(self, k, v)
+ if self.uri.find('://') == -1:
# assume file
- uri = 'file://'+os.path.abspath(uri)
- logger.debug(uri)
+ self.uri = 'file://'+os.path.abspath(self.uri)
+ logger.debug(self.uri)
view = self._view = WebKit.WebView()
view.set_data('__app__', self)
@@ -450,12 +461,18 @@ def load_app(self):
toplevel.set_default_size(self.width, self.height)
toplevel.add(scroller)
scroller.add(view)
- toplevel.show_all()
- # file:/// with # or ? causes error
- view.load_uri(uri)
+ char_q, mod_ctrl = Gtk.accelerator_parse('<Ctrl>q')
+ accel_destroy = Gtk.AccelGroup.new()
+ accel_destroy.connect(char_q, mod_ctrl, 0, self._destroy_cb)
+
+ #TODO: file:/// with # or ? causes error
+ view.load_uri(self.uri)
+
+ signal.signal(signal.SIGINT, self._destroy_cb)
+ toplevel.connect('destroy', self._destroy_cb)
+ toplevel.add_accel_group(accel_destroy)
- toplevel.connect('delete-event', self._delete_event_cb)
view.connect('onload-event', self._frame_loaded_cb)
view.connect('title-changed', self._title_changed_cb)
view.connect('icon-loaded', self._icon_loaded_cb)
@@ -471,6 +488,10 @@ def load_app(self):
settings.set_property('enable-accelerated-compositing', True)
settings.set_property('enable-webgl', True)
+ # display and run mainloop (returns after frame load)
+ toplevel.show_all()
+ Gtk.main()
+
def getUri(self):
return self.uri
@@ -515,6 +536,9 @@ def _frame_loaded_cb(self, view, frame):
self.initialized = True
self.init_app()
+ # return control to setup()
+ Gtk.main_quit()
+
def _icon_loaded_cb(self, view, icon_uri):
current = view.get_property('uri')
dom = wv.getDomDocument()
@@ -612,12 +636,12 @@ def addEventListener(self, element, event_name, cb):
element.add_event_listener(event_name, listener, False)
self.listeners[listener] = element
- def _delete_event_cb(self, window, event):
- #TODO: Gtk.main_quit() *should* work, but we are driving
- # the loop manually ... see below
+ def _destroy_cb(self, *args):
+ logger.info('destroy:draining events...')
while Gtk.events_pending():
Gtk.main_iteration_do(False)
- window.unrealize()
+ Gtk.main_quit()
+ logger.info('destroy:exiting...')
def _title_changed_cb(self, view, frame, title):
self._toplevel.set_title(title)
@@ -628,36 +652,6 @@ def _title_changed_cb(self, view, frame, title):
_addXMLHttpRequestEventListener = addXMLHttpRequestEventListener
-def setup(application, appdir=None, width=800, height=600):
-
- global wv
- global giresolver
-
- giresolver = GIResolver(WebKit.DOMObject)
- wv = ApplicationView(application, appdir, width, height)
- wv.load_app()
-
- while 1:
- if is_loaded():
- return
- run(one_event=True)
-
-
-def is_loaded():
- return wv.initialized
-
-
-def run(one_event=False, block=True):
- if one_event:
- if block or Gtk.events_pending():
- Gtk.main_iteration()
- sys.stdout.flush()
- return Gtk.events_pending()
- else:
- #TODO: Gtk.main() is probably fine too
- try:
- while wv._toplevel.get_realized():
- Gtk.main_iteration()
- sys.stdout.flush()
- except KeyboardInterrupt:
- logger.info('SIGINT:exiting...')
+application = ApplicationView()
+setup = application.setup
+run = Gtk.main
View
8 pyjs/src/pyjs/lib/pyjd.py
@@ -1,5 +1,7 @@
-from __pyjamas__ import JS
-
is_desktop = False
-setup = run = JS('''function(){return null;}''')
+def setup(application, appdir=None, width=800, height=600):
+ pass
+
+def run(one_event=False, block=True):
+ pass

No commit comments for this range

Something went wrong with that request. Please try again.