Skip to content

Commit

Permalink
#213 - add support for relative jsonrpc urls with pyjd
Browse files Browse the repository at this point in the history
git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@1136 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information
lkcl committed Aug 10, 2009
1 parent 0e83ec7 commit 1cec270
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 28 deletions.
7 changes: 6 additions & 1 deletion examples/helloworld/Hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
from pyjamas.ui.Label import Label
from pyjamas import Window

import pygwt

def greet(fred):
print "greet button"
Window.alert("Hello, AJAX!")

if __name__ == '__main__':
pyjd.setup("public/Hello.html")
pyjd.setup("public/Hello.html?fred=foo#me")
b = Button("Click me", greet, StyleName='teststyle')
h = HTML("<b>Hello World</b> (html)", StyleName='teststyle')
l = Label("Hello World (label)", StyleName='teststyle')
base = HTML("Hello from %s" % pygwt.getModuleBaseURL(),
StyleName='teststyle')
RootPanel().add(b)
RootPanel().add(h)
RootPanel().add(l)
RootPanel().add(base)
pyjd.run()
File renamed without changes.
44 changes: 21 additions & 23 deletions library/pygwt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys
from __pyjamas__ import get_main_frame, doc

sNextHashId = 0

Expand All @@ -10,40 +10,38 @@ def getNextHashId():
def getHashCode(o):
JS("""
return (o == null) ? 0 :
(o.$H ? o.$H : (o.$H = pygwt_getNextHashId()));
(o.$H ? o.$H : (o.$H = pygwt_getNextHashId()))
""")

def getModuleName():
import os
import sys
mod_name = sys.argv[0]
mod_name = os.path.split(mod_name)[1]
mod_name = os.path.spliext(mod_name)[0]
return mod_name

def getModuleBaseURL():

print "getModuleBaseURL: TODO"
return ""

return ""
JS("""
// this is intentionally not using $doc, because we want the module's own url
var s = document.location.href;
# get original app base
s = get_main_frame().getUri()
#s = doc().location.href

// Pull off any hash.
var i = s.indexOf('#');
if (i != -1)
s = s.substring(0, i);
# Pull off any hash.
i = s.find('#')
if i != -1:
s = s[:i]

// Pull off any query string.
i = s.indexOf('?');
if (i != -1)
s = s.substring(0, i);
# Pull off any query string.
i = s.find('?')
if i != -1:
s = s[:i]

// Rip off everything after the last slash.
i = s.lastIndexOf('/');
if (i != -1)
s = s.substring(0, i);
# Rip off everything after the last slash.
i = s.rfind('/')
if i != -1:
s = s[:i]

return (s.length > 0) ? s + "/" : "";
""")
if len(s) > 0:
return s + "/"
return ""
5 changes: 2 additions & 3 deletions library/pyjamas/HTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
if sys.platform not in ['mozilla', 'ie6', 'opera', 'oldmoz', 'safari']:
from __pyjamas__ import get_main_frame
from pyjamas import Cookies
else:
from __pyjamas__ import JS
import pygwt

handlers = {}

Expand Down Expand Up @@ -79,7 +78,7 @@ def asyncPostImpl(self, user, pwd, url, postData, handler,
mf = get_main_frame()
xmlHttp = self.doCreateXmlHTTPRequest()
if url[0] != '/':
uri = mf.getUri()
uri = pygwt.getModuleBaseURL()
if url[:7] != 'file://' and url[:7] != 'http://' and \
url[:8] != 'https://':
slash = uri.rfind('/')
Expand Down
2 changes: 1 addition & 1 deletion library/pyjamas/JSONService.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self, url, methods=None):
# only in the override (JSONServicePyJS.py) is JSONService.__init__
# needed. in here, for pyjd, things are done slightly differently.
# (using __getattr__).
self._serviceURL = "http://127.0.0.1/%s" % url # TODO: allow alternate locations
self._serviceURL = url

def __createMethod(self, method):
pass
Expand Down
4 changes: 4 additions & 0 deletions pyjd/pywebkitgtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ def load_app(self):

self._browser.open(uri)

def getUri(self):
return self.application

def init_app(self):
# TODO: ideally, this should be done by hooking body with an "onLoad".

Expand All @@ -432,6 +435,7 @@ def init_app(self):
main_frame.gobject_wrap = webkit.gobject_wrap
main_frame.platform = 'webkit'
main_frame.addEventListener = addEventListener
main_frame.getUri = self.getUri
main_frame.getDomWindow = new.instancemethod(getDomWindow, main_frame)
main_frame.getDomDocument = new.instancemethod(getDomDocument, main_frame)
main_frame._addXMLHttpRequestEventListener = addXMLHttpRequestEventListener
Expand Down

0 comments on commit 1cec270

Please sign in to comment.