Exemplo n.º 1
0
    def __init__(self):
        try:
            ns = doc().namespaces.item("v")
        except:
            doc().namespaces.add("v", "urn:schemas-microsoft-com:vml")
            doc().createStyleSheet(
            ).cssText = "v\\:*{behavior:url(#default#VML);}"
        """*
        * This will be used for an array join. Currently a bit faster than
        * StringBuilder.append() & toString() because of the extra collections
        * overhead.
        """
        self.pathStr = JSOStack()
        """*
        * Stack uses preallocated arrays which makes push() slightly faster than
        * [].push() since each push is simply an indexed setter.
        """
        self.contextStack = []

        self.currentX = 0

        self.currentY = 0

        self.parentElement = None

        self.parentHeight = 0

        self.parentWidth = 0
Exemplo n.º 2
0
    def __init__(self):
        try:
            ns = doc().namespaces.item("v")
        except:
            doc().namespaces.add("v", "urn:schemas-microsoft-com:vml")
            doc().createStyleSheet().cssText = "v\\:*{behavior:url(#default#VML);}"



        """*
        * This will be used for an array join. Currently a bit faster than
        * StringBuilder.append() & toString() because of the extra collections
        * overhead.
        """
        self.pathStr = JSOStack()

        """*
        * Stack uses preallocated arrays which makes push() slightly faster than
        * [].push() since each push is simply an indexed setter.
        """
        self.contextStack = []

        self.currentX = 0

        self.currentY = 0

        self.parentElement = None

        self.parentHeight = 0

        self.parentWidth = 0
    def __init__(self, cssFile=''):
        self._e = DOM.createElement('link')
        self._e.setAttribute('rel', 'stylesheet')
        self._e.setAttribute('type', 'text/css')
        self._e.setAttribute('href', cssFile);

        print "css file", cssFile
        doc().getElementsByTagName("head").item(0).appendChild(self._e) 
Exemplo n.º 4
0
    def __init__(self, cssFile=''):
        self._e = DOM.createElement('link')
        self._e.setAttribute('rel', 'stylesheet')
        self._e.setAttribute('type', 'text/css')
        self._e.setAttribute('href', cssFile)

        print "css file", cssFile
        doc().getElementsByTagName("head").item(0).appendChild(self._e)
Exemplo n.º 5
0
    def onTimer(self, timer):

        iframe = doc().getElementById("__edit_%s" % self.editor_id)
        print dir(iframe)
        txt = iframe.innerText
        if not txt:
            return

        timer.cancel()

        doc().body.removeChild(iframe)
        self.app.save_page(self.token, self.fname, txt)
Exemplo n.º 6
0
    def onTimer(self, timer):

        iframe = doc().getElementById("__edit_%s" % self.editor_id)
        print dir(iframe)
        txt = iframe.innerText
        if not txt:
            return

        timer.cancel()

        doc().body.removeChild(iframe)
        self.app.save_page(self.token, self.fname, txt)
Exemplo n.º 7
0
    def doRESTQuery(self, url, timer):
        """this is a totally different from an RPC call in that we have to
           dynamically add script tags to the DOM when we want to query the 
           REST API. These rely on callbacks in the DOM so we can either add 
           them dynamically or pre-define them in public/Main.html. 
           Once we've done that have to wait for the response.
           Which means we need to provide a listener for the timer"""

        new_script = DOM.createElement("script")
        DOM.setElemAttribute(new_script, "src", url)
        DOM.setElemAttribute(new_script, "type","text/javascript")
        doc().body.appendChild(new_script)
        self.timer.schedule(100)
Exemplo n.º 8
0
    def doRESTQuery(self, url, timer):
        """this is a totally different from an RPC call in that we have to
           dynamically add script tags to the DOM when we want to query the
           REST API. These rely on callbacks in the DOM so we can either add
           them dynamically or pre-define them in public/Main.html.
           Once we've done that have to wait for the response.
           Which means we need to provide a listener for the timer"""

        new_script = DOM.createElement("script")
        DOM.setElemAttribute(new_script, "src", url)
        DOM.setElemAttribute(new_script, "type", "text/javascript")
        doc().body.appendChild(new_script)
        self.timer.schedule(100)
Exemplo n.º 9
0
    def add_tinymce(self):

        # for storing the results when available
        iframe = DOM.createElement("iframe")
        DOM.setElemAttribute(iframe, "id", "__edit_%s" % self.editor_id)
        DOM.setElemAttribute(iframe, "style", "display:none")
        doc().body.appendChild(iframe)

        # activate tinymce
        new_script = DOM.createElement("script")
        new_script.innerHTML = """
tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "simple",

        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,|,table,removeformat",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,
});
"""

        ih = """
var ed = new tinymce.Editor('%s',{
        mode : "none",
        theme : "advanced",
        plugins : "inlinepopups",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,table,image,removeformat",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true
});
ed.render();
ed.load();
tinymce.add(ed);
""" % self.editor_id

        print new_script.innerHTML

        DOM.setElemAttribute(new_script, "type", "text/javascript")
        doc().body.appendChild(new_script)
Exemplo n.º 10
0
    def add_tinymce(self):

        # for storing the results when available
        iframe = DOM.createElement("iframe")
        DOM.setElemAttribute(iframe, "id", "__edit_%s" % self.editor_id)
        DOM.setElemAttribute(iframe, "style", "display:none")
        doc().body.appendChild(iframe)

        # activate tinymce
        new_script = DOM.createElement("script")
        new_script.innerHTML = """
tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "simple",

        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,|,table,removeformat",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,
});
"""

        ih = """
var ed = new tinymce.Editor('%s',{
        mode : "none",
        theme : "advanced",
        plugins : "inlinepopups",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,table,image,removeformat",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true
});
ed.render();
ed.load();
tinymce.add(ed);
""" % self.editor_id

        print new_script.innerHTML

        DOM.setElemAttribute(new_script, "type", "text/javascript")
        doc().body.appendChild(new_script)
Exemplo n.º 11
0
    def load_tinymce(self):

        # activate tinymce
        new_script = DOM.createElement("script")
        new_script.innerHTML = """
var ed = tinyMCE.get('%s');
ed.init();
ed.render();
""" % self.editor_id

        print new_script.innerHTML

        DOM.setElemAttribute(new_script, "type","text/javascript")
        doc().body.appendChild(new_script)
Exemplo n.º 12
0
    def load_tinymce(self):

        # activate tinymce
        new_script = DOM.createElement("script")
        new_script.innerHTML = """
var ed = tinyMCE.get('%s');
ed.init();
ed.render();
""" % self.editor_id

        print new_script.innerHTML

        DOM.setElemAttribute(new_script, "type", "text/javascript")
        doc().body.appendChild(new_script)
Exemplo n.º 13
0
 def onDragStart(self, event):
     dt = event.dataTransfer
     target = DOM.eventGetTarget(event)
     target = Widget(Element=target)
     id = target.getID()
     dt.setData("Text", "Dropped %s" % target.getID())
     dt.effectAllowed = 'copy'
     if id == 'imgdrag1':
         parent = self.getParent()
         while not hasattr(parent, 'h2'):
             parent = parent.getParent()
         dt.setDragImage(parent.h2.getElement(), 10, 10)
     elif id == 'imgdrag2':
         dt.setDragImage(doc().getElementById('logo'), 10, 10)
     elif id == 'imgdrag3':
         # OK, it's a bit of a cheat, but the following works on current
         # Opera, IE, Firefox, Safari, Chrome.
         ctx = GWTCanvas(50, 50)
         self.makeCanvasImg(ctx)
         try:
             img = DOM.createImg()
             DOM.setAttribute(img, 'src', ctx.canvas.toDataURL())
             dt.setDragImage(img, 25, 25)
         except:
             dt.setDragImage(ctx.canvas, 25, 25)
Exemplo n.º 14
0
 def checkForChange(self):
     text = self.m_textW.getHTML()
     if text != self.m_lastText:
         nEvt = doc().createEvent("HTMLEvents")
         nEvt.initEvent("change", False, True)
         self.getElement().dispatchEvent(nEvt)
         self.m_lastText = text
Exemplo n.º 15
0
 def onDragStart(self, event):
     dt = event.dataTransfer
     target = DOM.eventGetTarget(event)
     target = Widget(Element=target)
     id = target.getID()
     dt.setData("Text", "Dropped %s" % target.getID())
     dt.effectAllowed = 'copy'
     if id == 'imgdrag1':
         parent = self.getParent()
         while not hasattr(parent, 'h2'):
             parent = parent.getParent()
         dt.setDragImage(parent.h2.getElement(), 10, 10)
     elif id == 'imgdrag2':
         dt.setDragImage(doc().getElementById('logo'), 10, 10)
     elif id == 'imgdrag3':
         # OK, it's a bit of a cheat, but the following works on current
         # Opera, IE, Firefox, Safari, Chrome.
         ctx = GWTCanvas(50, 50)
         self.makeCanvasImg(ctx)
         try:
             img = DOM.createImg()
             DOM.setAttribute(img, 'src', ctx.canvas.toDataURL())
             dt.setDragImage(img, 25, 25)
         except:
             dt.setDragImage(ctx.canvas, 25, 25)
Exemplo n.º 16
0
    def onElementInitialized(self):
        # Issue 1897: This method is called after a timeout, during which time the
        # element might by detached.
        if not self.initializing:
            return

        print "onElementInit", DOM.getInnerHTML(self.beforeInitPlaceholder)
        self.initializing = False

        RichTextAreaImpl.onElementInitialized(self)

        # clone styles from main document
        if self.css_styling:
            elem = self.elem;
            _doc = elem.contentWindow.document
            fragment = _doc.createDocumentFragment()
            nl = doc().getElementsByTagName("style")
            for i in range(nl.length):
                n = nl.item(i)
                fragment.appendChild(n.cloneNode(True))
            _doc.getElementsByTagName("head").item(0).appendChild(fragment)

        # When the iframe is ready, ensure cached content is set.
        if self.beforeInitPlaceholder is not None:
            self.setHTMLImpl(DOM.getInnerHTML(self.beforeInitPlaceholder))
            self.beforeInitPlaceholder = None

        if self.isPendingFocus:
            self.isPendingFocus = False
            self.setFocus(True)
Exemplo n.º 17
0
 def checkForChange(self):
     text = self.m_textW.getHTML()
     if text != self.m_lastText:
         nEvt = doc().createEvent("HTMLEvents")
         nEvt.initEvent("change", False, True)
         self.getElement().dispatchEvent(nEvt)
         self.m_lastText = text
Exemplo n.º 18
0
Arquivo: Cookies.py Projeto: Afey/pyjs
def getCookie2(cookie_name):
    cookiestr = doc().cookie
    c = SimpleCookie(str(cookiestr))
    cs = c.get(cookie_name, None)
    print "getCookie2", cookiestr, "name", cookie_name, "val", cs
    if cs:
        return cs.value
    return None
Exemplo n.º 19
0
def activate_css(targetnode):
    scriptnodes = list(targetnode.getElementsByTagName('link'))
    for LC in range(len(scriptnodes)):
        sn = scriptnodes[LC]
        sn.parentNode.removeChild(sn)

        fileref = DOM.createElement('link')

        if hassattr(sn, "href"):
            fileref.href = sn.href
        else:
            fileref.text = sn.text

        fileref.rel = "stylesheet"
        fileref.type = "text/css"

        doc().getElementsByTagName("head").item(0).appendChild(fileref)
Exemplo n.º 20
0
Arquivo: dynamic.py Projeto: Afey/pyjs
def activate_javascript(txt):
    fileref = DOM.createElement('script')

    fileref.text = txt
    fileref.type = "text/javascript"
    fileref.language = "javascript"
    #fileref.defer = True

    #debug = DOM.createElement('pre')
    #debug.innerHTML = 'test'
    #debug.innerHTML += "href:" + sn.src + " text:" + fileref.text
    #var bodyels = doc().getElementsByTagName("body")
    #bodyels[bodyels.length-1].appendChild(debug)

    fileref = fileref.cloneNode(True)

    doc().getElementsByTagName("head").item(0).appendChild(fileref)
Exemplo n.º 21
0
def activate_javascript(txt):
    fileref = DOM.createElement('script')

    fileref.text = txt
    fileref.type = "text/javascript"
    fileref.language = "javascript"
    #fileref.defer = True

    #debug = DOM.createElement('pre')
    #debug.innerHTML = 'test'
    #debug.innerHTML += "href:" + sn.src + " text:" + fileref.text
    #var bodyels = doc().getElementsByTagName("body")
    #bodyels[bodyels.length-1].appendChild(debug)

    fileref = fileref.cloneNode(True)

    doc().getElementsByTagName("head").item(0).appendChild(fileref)
Exemplo n.º 22
0
 def checkForChange(self):
     text = self.richText.getHTML()
     if text == self.lastText:
         return
     nEvt = doc().createEvent("HTMLEvents")
     nEvt.initEvent("change", False, True)
     self.getElement().dispatchEvent(nEvt)
     self.lastText = text
Exemplo n.º 23
0
 def checkForChange(self):
     text = self.richText.getHTML()
     if text == self.lastText:
         return
     nEvt = doc().createEvent("HTMLEvents")
     nEvt.initEvent("change", False, True)
     self.getElement().dispatchEvent(nEvt)
     self.lastText = text
 def __addLogElement(self):
     """Add a container in the DOM where logging output will be written to.
     This cannot be done in the constructor as it must happen late enough
     to ensure a document body (to add an element to) does already exist."""
     if self.div == None:
         self.div = DOM.createDiv()
         self.div.setAttribute('id', self.div_id)
         DOM.appendChild(doc().body, self.div)
Exemplo n.º 25
0
Arquivo: Feed.py Projeto: Afey/pyjs
 def __init__(self, url, callback):
     global frameId
     frame = DOM.createElement("iframe")
     frameid = "__pygwt_feedFrame%d" % frameId
     frameId += 1
     DOM.setAttribute(frame, "id", frameid)
     DOM.setAttribute(frame, "src", url)
     #DOM.setStyleAttribute(frame, 'width', '0')
     #DOM.setStyleAttribute(frame, 'height', '0')
     #DOM.setStyleAttribute(frame, 'border', '0')
     #DOM.setStyleAttribute(frame, 'position', 'absolute')
     self.frameId = frameId
     self.frame = frame
     self.timer = Timer(notify=self)
     doc().parent.body.appendChild(frame)
     self.callback = callback
     self.timer.scheduleRepeating(100)
 def __init__(self, url, callback):
     global frameId
     frame = DOM.createElement("iframe")
     frameid = "__pygwt_feedFrame%d" % frameId
     frameId += 1
     DOM.setAttribute(frame, "id", frameid)
     DOM.setAttribute(frame, "src", url)
     #DOM.setStyleAttribute(frame, 'width', '0')
     #DOM.setStyleAttribute(frame, 'height', '0')
     #DOM.setStyleAttribute(frame, 'border', '0')
     #DOM.setStyleAttribute(frame, 'position', 'absolute')
     self.frameId = frameId
     self.frame = frame
     self.timer = Timer(notify=self)
     doc().parent.body.appendChild(frame)
     self.callback = callback
     self.timer.scheduleRepeating(100)
 def __addLogElement(self):
     """Add a container in the DOM where logging output will be written to.
     This cannot be done in the constructor as it must happen late enough
     to ensure a document body (to add an element to) does already exist."""
     if self.div == None:
         self.div = DOM.createDiv()
         self.div.setAttribute('id', self.div_id)
         DOM.appendChild(doc().body, self.div)
Exemplo n.º 28
0
Arquivo: dynamic.py Projeto: Afey/pyjs
def activate_css(targetnode):
    scriptnodes = list(targetnode.getElementsByTagName('link'))
    for LC in range(len(scriptnodes)):
        sn = scriptnodes[LC]
        sn.parentNode.removeChild(sn)

        fileref = DOM.createElement('link')

        if hassattr(sn, "href"):
            fileref.href = sn.href
        else:
            fileref.text = sn.text

        fileref.rel = "stylesheet"
        fileref.type = "text/css"

        doc().getElementsByTagName("head").item(0).appendChild(fileref)
Exemplo n.º 29
0
def getCookie2(cookie_name):
    cookiestr = doc().cookie
    c = SimpleCookie(str(cookiestr))
    cs = c.get(cookie_name, None)
    print "getCookie2", cookiestr, "name", cookie_name, "val", cs
    if cs:
        return cs.value
    return None
Exemplo n.º 30
0
    def __init__(self, text='', _doc=None):
        self._e = DOM.createElement('style')
        self._e.setAttribute('type', 'text/css')
        setStyleElementText(self._e, text)

        if _doc is None:
            _doc = doc()
        _doc.getElementsByTagName("head").item(0).appendChild(self._e) 
Exemplo n.º 31
0
Arquivo: CSS.py Projeto: sofianhw/pyjs
    def __init__(self, text='', _doc=None):
        self._e = DOM.createElement('style')
        self._e.setAttribute('type', 'text/css')
        setStyleElementText(self._e, text)

        if _doc is None:
            _doc = doc()
        _doc.getElementsByTagName("head").item(0).appendChild(self._e)
Exemplo n.º 32
0
    def __init__(self, cssFile='', _doc=None):
        self._e = DOM.createElement('link')
        self._e.setAttribute('rel', 'stylesheet')
        self._e.setAttribute('type', 'text/css')
        self._e.setAttribute('href', cssFile)

        if _doc is None:
            _doc = doc()
        _doc.getElementsByTagName("head").item(0).appendChild(self._e)
Exemplo n.º 33
0
Arquivo: CSS.py Projeto: Afey/pyjs
    def __init__(self, cssFile='', _doc=None):
        self._e = DOM.createElement('link')
        self._e.setAttribute('rel', 'stylesheet')
        self._e.setAttribute('type', 'text/css')
        self._e.setAttribute('href', cssFile);

        if _doc is None:
            _doc = doc()
        _doc.getElementsByTagName("head").item(0).appendChild(self._e)
Exemplo n.º 34
0
def getComputedStyle(element, style=None):
    """
    Get computed style of an element, like in
    http://efreedom.com/Question/1-1848445/Duplicating-Element-Style-JavaScript
    """
    element_style = doc().defaultView.getComputedStyle(element, None)
    #element_style = doc().defaultView.getComputedStyle(element, None)
    if style:
        return element_style[style]
    return element_style
Exemplo n.º 35
0
    def transfer_tinymce(self):

        new_script = DOM.createElement("script")
        new_script.innerHTML = """
var ed = tinyMCE.get('%s');
var data = ed.getContent({'format': 'raw'});
frame = document.getElementById('__edit_%s');
frame.innerText = data;
ed.save();
ed.remove();
""" % (self.editor_id, self.editor_id)

        self.editor_created = False

        DOM.setElemAttribute(new_script, "type", "text/javascript")
        doc().body.appendChild(new_script)
        self.hide()
        t = Timer(notify=self)
        t.scheduleRepeating(1000)
Exemplo n.º 36
0
def setCookie(name, value, expires, domain=None, path=None, secure=False):
    cookiestr = doc().cookie
    c = SimpleCookie(cookiestr)
    c[name] = value
    m = c[name]
    d = datetime.datetime.now() + datetime.timedelta(0, expires / 1000)
    d = d.strftime("%a, %d %b %Y %H:%M:%S GMT")
    m['expires'] = '"%s"' % d
    if domain:
        m['domain'] = domain
    if path:
        m['path'] = path
    if secure:
        m['secure'] = ''

    c = c.output(header='').strip()
    print "set cookies", c
    _doc = doc()
    _doc.cookie = c

    return
    JS("""
    if (expires instanceof Date) expires = expires.getTime();
    if (pyjslib_isUndefined(domain)) domain = null;
    if (pyjslib_isUndefined(path)) path = null;
    if (pyjslib_isUndefined(secure)) secure = false;
    
    var today = new Date();
    var expiration = new Date();
    expiration.setTime(today.getTime() + expires)

    var c = encodeURIComponent(name) + '=' + encodeURIComponent(value);
    c += ';expires=' + expiration.toGMTString();

    if (domain)
        c += ';domain=' + domain;
    if (path)
        c += ';path=' + path;
    if (secure)
        c += ';secure';

    $doc.cookie = c;
    """)
Exemplo n.º 37
0
def setCookie(name, value, expires, domain=None, path=None, secure=False):
    cookiestr = doc().cookie
    c = SimpleCookie(cookiestr)
    c[name] = value
    m = c[name]
    d = datetime.datetime.now() + datetime.timedelta(0, expires/1000)
    d = d.strftime("%a, %d %b %Y %H:%M:%S GMT")
    m['expires'] = '"%s"' % d
    if domain:
        m['domain'] = domain
    if path:
        m['path'] = path
    if secure:
        m['secure'] = ''

    c = c.output(header='').strip()
    print "set cookies", c
    _doc = doc()
    _doc.cookie = c

    return
    JS("""
    if (expires instanceof Date) expires = expires.getTime();
    if (pyjslib_isUndefined(domain)) domain = null;
    if (pyjslib_isUndefined(path)) path = null;
    if (pyjslib_isUndefined(secure)) secure = false;
    
    var today = new Date();
    var expiration = new Date();
    expiration.setTime(today.getTime() + expires)

    var c = encodeURIComponent(name) + '=' + encodeURIComponent(value);
    c += ';expires=' + expiration.toGMTString();

    if (domain)
        c += ';domain=' + domain;
    if (path)
        c += ';path=' + path;
    if (secure)
        c += ';secure';

    $doc.cookie = c;
    """)
Exemplo n.º 38
0
def getComputedStyle(element, style=None):
    """
    Get computed style of an element, like in
    http://efreedom.com/Question/1-1848445/Duplicating-Element-Style-JavaScript
    """
    element_style = doc().defaultView.getComputedStyle(element, None)
    #element_style = doc().defaultView.getComputedStyle(element, None)
    if style:
        return element_style[style]
    return element_style
Exemplo n.º 39
0
    def transfer_tinymce(self):

        new_script = DOM.createElement("script")
        new_script.innerHTML = """
var ed = tinyMCE.get('%s');
var data = ed.getContent({'format': 'raw'});
frame = document.getElementById('__edit_%s');
frame.innerText = data;
ed.save();
ed.remove();
""" % (self.editor_id, self.editor_id)

        self.editor_created = False

        DOM.setElemAttribute(new_script, "type","text/javascript")
        doc().body.appendChild(new_script)
        self.hide()
        t = Timer(notify=self)
        t.scheduleRepeating(1000)
Exemplo n.º 40
0
def _init_testing():
    body = doc().getElementsByTagName("body")[0]
    mf._addEventListener(body, "click", cb)
    mf._addEventListener(body, "change", cb)
    mf._addEventListener(body, "mouseout", cb)
    mf._addEventListener(body, "mousedown", cb)
    mf._addEventListener(body, "mouseup", cb)
    mf._addEventListener(body, "mousemove", cb)
    mf._addEventListener(body, "resize", cb)
    mf._addEventListener(body, "keyup", cb)
    mf._addEventListener(body, "keydown", cb)
    mf._addEventListener(body, "keypress", cb)
Exemplo n.º 41
0
Arquivo: Cookies.py Projeto: Afey/pyjs
def setCookie(name, value, expires, domain=None, path=None, secure=False):
    cookiestr = doc().cookie
    c = SimpleCookie(str(cookiestr))
    c[name] = value
    m = c[name]
    d = datetime.datetime.now() + datetime.timedelta(0, expires/1000)
    d = d.strftime("%a, %d %b %Y %H:%M:%S GMT")
    m['expires'] = '"%s"' % d
    if domain:
        m['domain'] = domain
    if path:
        m['path'] = path
    if secure:
        m['secure'] = ''

    c = c.output(header='').strip()
    print "set cookies", c
    _doc = doc()
    _doc.cookie = c

    return
Exemplo n.º 42
0
def setCookie(name, value, expires, domain=None, path=None, secure=False):
    cookiestr = doc().cookie
    c = SimpleCookie(str(cookiestr))
    c[name] = value
    m = c[name]
    d = datetime.datetime.now() + datetime.timedelta(0, expires / 1000)
    d = d.strftime("%a, %d %b %Y %H:%M:%S GMT")
    m['expires'] = '"%s"' % d
    if domain:
        m['domain'] = domain
    if path:
        m['path'] = path
    if secure:
        m['secure'] = ''

    c = c.output(header='').strip()
    print "set cookies", c
    _doc = doc()
    _doc.cookie = c

    return
Exemplo n.º 43
0
def _init_testing():
    body = doc().getElementsByTagName("body")[0]
    mf._addEventListener(body, "click", cb)
    mf._addEventListener(body, "change", cb)
    mf._addEventListener(body, "mouseout", cb)
    mf._addEventListener(body, "mousedown", cb)
    mf._addEventListener(body, "mouseup", cb)
    mf._addEventListener(body, "mousemove", cb)
    mf._addEventListener(body, "resize", cb)
    mf._addEventListener(body, "keyup", cb)
    mf._addEventListener(body, "keydown", cb)
    mf._addEventListener(body, "keypress", cb)
Exemplo n.º 44
0
def _dispatchCapturedMouseoutEvent(evt):
    cap = getCaptureElement()
    if cap:
        #print "cap", dir(evt), cap
        if not eventGetToElement(evt):
            #print "synthesise", cap
            #When the mouse leaves the window during capture, release capture
            #and synthesize an 'onlosecapture' event.
            setCapture(None)
            listener = get_listener(cap)
            if listener:
                # this should be interesting...
                lcEvent = doc().createEvent('UIEvent')
                lcEvent.initUIEvent('losecapture', False, False, wnd(), 0)
                dispatchEvent(lcEvent, cap, listener)
Exemplo n.º 45
0
    def onTimer(self, timer):
        fd = doc().getElementById("__pygwt_hiddenData")
        receiver = fd.innerHTML

        if receiver == 'wait':
            self.timer.schedule(1000)
            return

        fd.innerHTML = 'wait'

        if self.drill == 0:
            self.parseAlbums(receiver)
            self.fillGrid(self.albums, "albums")
        elif self.drill == 1:
            self.parsePhotos(receiver)
            self.fillGrid(self.photos, "photos")
Exemplo n.º 46
0
    def onTimer(self, timer):
        fd = doc().getElementById("__pygwt_hiddenData")
        receiver = fd.innerHTML

        if receiver == 'wait':
            self.timer.schedule(1000)
            return

        fd.innerHTML = 'wait'

        if self.drill == 0:
            self.parseAlbums(receiver)
            self.fillGrid(self.albums, "albums")
        elif self.drill == 1:
            self.parsePhotos(receiver)
            self.fillGrid(self.photos, "photos")
Exemplo n.º 47
0
def ajax_dlink(idname, url, on_load_fn):
    global running_timeout, timeout_idname, timeout_url, timeout_on_load_fn, redo_timeout, timeout_id
    from __pyjamas__ import doc
    body = doc().body

    from __javascript__ import clearTimeout
    if timeout_id:
        clearTimeout(
            timeout_id)  # really important - get into a mess otherwise

    def onreadystatechange():
        if xhtoj.readyState == 4:
            jsnode = 0
            if xhtoj.status == 200:
                txt = xhtoj.responseText

                jsnode = None

                if idname:
                    jsnode = DOM.getElementById(idname)

                if jsnode is None:
                    jsnode = DOM.createElement('script')

                #tst = DOM.createElement('html')
                #tst.innerHTML = str

                activate_javascript(txt)
                if not on_load_fn is None:
                    wnd().alert(on_load_fn)
                    # eval(on_load_fn)
                    test_fn()

                return 1
            else:
                jsnode = DOM.getElementById(idname)

                if not jsnode is None:
                    jsnode.innerHTML = xhtoj.status

    xhtoj = createHttpRequest()
    xhtoj.onreadystatechange = onreadystatechange
    xhtoj.open("GET", url, True)
    xhtoj.send("")

    return 0
Exemplo n.º 48
0
Arquivo: dynamic.py Projeto: Afey/pyjs
def ajax_dlink(idname, url, on_load_fn):
    global running_timeout, timeout_idname, timeout_url, timeout_on_load_fn, redo_timeout, timeout_id
    from __pyjamas__ import doc
    body = doc().body

    from __javascript__ import clearTimeout
    if timeout_id:
        clearTimeout(timeout_id) # really important - get into a mess otherwise

    def onreadystatechange():
        if xhtoj.readyState == 4:
            jsnode = 0
            if xhtoj.status == 200:
                txt = xhtoj.responseText

                jsnode = None

                if idname:
                    jsnode = DOM.getElementById(idname)

                if jsnode is None:
                    jsnode = DOM.createElement('script')

                #tst = DOM.createElement('html')
                #tst.innerHTML = str

                activate_javascript(txt)
                if not on_load_fn is None:
                    wnd().alert(on_load_fn)
                    # eval(on_load_fn)
                    test_fn()

                return 1
            else:
                jsnode = DOM.getElementById(idname)

                if not jsnode is None:
                    jsnode.innerHTML = xhtoj.status

    xhtoj = createHttpRequest()
    xhtoj.onreadystatechange = onreadystatechange
    xhtoj.open("GET", url , True )
    xhtoj.send("")

    return 0
Exemplo n.º 49
0
    def execute(self):
        if self.command in ("Beginner", "Intermediate", "Expert", "Custom"):
            body = doc().getElementsByTagName("body").item(0)
            body.setAttribute("id", self.command)

        modes = {"New": [(0, 0), 0], "Beginner": [(8, 8), 1], "Intermediate": [(16, 16), 2], "Expert": [(16, 32), 3]}
        level = modes.get(self.command)
        if level:
            if level[1]:
                self.menu.game.level = level[1]
            self.menu.game.next_game(level[0])
        elif self.command == "Custom":
            self.menu.game.level = 4
            self.show_custom()
        elif self.command == "Instructions":
            pass
        elif self.command == "About":
            self.show_about()
Exemplo n.º 50
0
def _dispatchCapturedMouseoutEvent(evt):
    cap = getCaptureElement()
    #print "cap", evt, cap
    if cap is None:
        return
    #print "cap", evt, cap
    if eventGetToElement(evt):
        return
    #print "synthesise", cap
    #When the mouse leaves the window during capture, release capture
    #and synthesize an 'onlosecapture' event.
    setCapture(None)
    listener = get_listener(cap)
    if listener is None:
        return
    # this should be interesting...
    #print "lose capture synthesised"
    lcEvent = doc().createEvent('UIEvent')
    lcEvent.initUIEvent('losecapture', False, False, wnd(), 0)
    dispatchEvent(lcEvent, cap, listener)
Exemplo n.º 51
0
    def __init__(self, game):
        self.game = game
        super(MineMenuBar, self).__init__()

        body = doc().getElementsByTagName("body").item(0)
        body.setAttribute("id", "Beginner")

        menu_game = MenuBar(True)
        menu_game.addItem("New", MenuCmd(self, "New"))
        menu_game.addItem(self.span_text("Beginner"), True, MenuCmd(self, "Beginner"))
        menu_game.addItem(self.span_text("Intermediate"), True, MenuCmd(self, "Intermediate"))
        menu_game.addItem(self.span_text("Expert"), True, MenuCmd(self, "Expert"))
        menu_game.addItem(self.span_text("Custom"), True, MenuCmd(self, "Custom"))

        menu_help = MenuBar(True)
        # menu_help.addItem('Instructions', MenuCmd(self, 'Instructions'))
        menu_help.addItem("About", MenuCmd(self, "About"))

        self.addItem(MenuItem("Game", menu_game))
        self.addItem(MenuItem("Help", menu_help))
Exemplo n.º 52
0
 def onDragStart(self, event):
     dt = event.dataTransfer
     target = DOM.eventGetTarget(event)
     target = Widget(Element=target)
     try:
         id = target.getID()
     except:
         id = ''
     if id == 'datadrag0':
         dt.setData('text/plain', 'Hello World!')
     elif id == 'datadrag1':
         logo = doc().getElementById('logo')
         logo_parent_element = DOM.getParent(logo)
         text = DOM.getInnerText(logo_parent_element)
         html = DOM.getInnerHTML(logo_parent_element)
         uri = DOM.getAttribute(logo, 'src')
         dt.setData('text/plain', text)
         dt.setData('text/html', html)
         dt.setData('text/uri-list', uri)
     elif id == 'datadrag2':
         dt.setData('x-star-trek/tribble', 'I am a tribble')
Exemplo n.º 53
0
 def onDragStart(self, event):
     dt = event.dataTransfer
     target = DOM.eventGetTarget(event)
     target = Widget(Element=target)
     try:
         id = target.getID()
     except:
         id = ''
     if id == 'datadrag0':
         dt.setData('text/plain', 'Hello World!')
     elif id == 'datadrag1':
         logo = doc().getElementById('logo')
         logo_parent_element = DOM.getParent(logo)
         text = DOM.getInnerText(logo_parent_element)
         html = DOM.getInnerHTML(logo_parent_element)
         uri = DOM.getAttribute(logo, 'src')
         dt.setData('text/plain', text)
         dt.setData('text/html', html)
         dt.setData('text/uri-list', uri)
     elif id == 'datadrag2':
         dt.setData('x-star-trek/tribble', 'I am a tribble')
Exemplo n.º 54
0
    def execute(self):
        if self.command in ('Beginner', 'Intermediate', 'Expert', 'Custom'):
            body = doc().getElementsByTagName('body').item(0)
            body.setAttribute('id', self.command)

        modes = {'New': [(0, 0), 0],
                 'Beginner': [(8, 8), 1],
                 'Intermediate': [(16, 16), 2],
                 'Expert': [(16, 32), 3]}
        level = modes.get(self.command)
        if level:
            if level[1]:
                self.menu.game.level = level[1]
            self.menu.game.next_game(level[0])
        elif self.command == 'Custom':
            self.menu.game.level = 4
            self.show_custom()
        elif self.command == 'Instructions':
            pass
        elif self.command == 'About':
            self.show_about()
Exemplo n.º 55
0
 def execute(self):
     if self.command in ('Beginner', 'Intermediate', 'Expert', 'Custom'):
         body = doc().getElementsByTagName('body').item(0)
         body.setAttribute('id', self.command)
     
     modes = {'New': [(0, 0), 0],
              'Beginner': [(8, 8), 1],
              'Intermediate': [(16, 16), 2],
              'Expert': [(16, 32), 3]}
     level = modes.get(self.command)
     if level:
         if level[1]:
             self.menu.game.level = level[1]
         self.menu.game.next_game(level[0])
     elif self.command == 'Custom':
         self.menu.game.level = 4
         self.show_custom()
     elif self.command == 'Instructions':
         pass
     elif self.command == 'About':
         self.show_about()
Exemplo n.º 56
0
    def execute(self):
        if self.command == 'New':
            self.menu.game.restart()
        if self.command in ('Beginner', 'Intermediate', 'Expert', 'Custom'):
            body = doc().getElementsByTagName('body').item(0)
            body.setAttribute('id', self.command)

            levels = {'Beginner':     [1, ( 8,  8)],
                      'Intermediate': [2, (16, 16)],
                      'Expert':       [3, (16, 32)],
                      'Custom':       [4]}
            level_rc = levels[self.command]
            self.menu.game.level = level_rc[0]
            if level_rc[0] == 4:
                self.show_custom()
            else:
                self.menu.game.next_game(*level_rc[1])
        elif self.command == 'Instructions':
            pass
        elif self.command == 'About':
            self.show_about()
Exemplo n.º 57
0
    def __init__(self, game):
        self.game = game
        super(MineMenuBar, self).__init__()

        body = doc().getElementsByTagName('body').item(0)
        body.setAttribute('id', 'Beginner')

        menu_game = MenuBar(True)
        menu_game.addItem('New', MenuCmd(self, 'New'))
        menu_game.addItem(self.span_text('Beginner'), True, \
                                                MenuCmd(self, 'Beginner'))
        menu_game.addItem(self.span_text('Intermediate'), True, \
                                                MenuCmd(self, 'Intermediate'))
        menu_game.addItem(self.span_text('Expert'), True, \
                                                MenuCmd(self, 'Expert'))
        menu_game.addItem(self.span_text('Custom'), True, \
                                                MenuCmd(self, 'Custom'))

        menu_help = MenuBar(True)
        #menu_help.addItem('Instructions', MenuCmd(self, 'Instructions'))
        menu_help.addItem('About', MenuCmd(self, 'About'))

        self.addItem(MenuItem('Game', menu_game))
        self.addItem(MenuItem('Help', menu_help))
Exemplo n.º 58
0
def get_crumbs():
    docCookie = doc().cookie
    c = SimpleCookie(docCookie)
    c = c.output(header='')
    return map(strip, c.split('\n'))
Exemplo n.º 59
0
def display_log_output():
    global element
    global data
    element = doc().createElement("div")
    doc().body.appendChild(element)
    element.innerHTML = data