Beispiel #1
0
Datei: ui.py Projekt: mgax/PyKit
 def __init__(self, x, y, sheet, jQ):
     self.x, self.y = x, y
     self.td = jQ('<td><span class="value"></span></td>')
     self.td.click(js_function(self.on_click))
     self.jQ = jQ
     self.value = ""
     self.sheet = sheet
Beispiel #2
0
Datei: ui.py Projekt: oloed/PyKit
 def __init__(self, x, y, sheet, jQ):
     self.x, self.y = x, y
     self.td = jQ('<td><span class="value"></span></td>')
     self.td.click(js_function(self.on_click))
     self.jQ = jQ
     self.value = ""
     self.sheet = sheet
Beispiel #3
0
def test_javascript_methods(ctx):
    ctx.window.eval('window.pykittest_callback = function(n){return n+6;};')
    assert ctx.window.pykittest_callback(10) == 16

    calls = []
    @js_function
    def call_to_python(this, *args):
        calls.append( (this, args) )
    ctx.window.eval('window.call_me_back = function(f) {\n'
                    '    f(); f(1, 3);\n'
                    '    var ob = {f: f, n: 13}; ob.f(); ob.f("asdf");\n'
                    '};')
    ctx.window.call_me_back(call_to_python)
    assert len(calls) == 4
    assert (calls[0][0].__pykit_private__.js_obj
            is ctx.window.__pykit_private__.js_obj)
    assert calls[1][1] == (1, 3)
    assert calls[2][0]['n'] == 13
    assert calls[3][1] == ("asdf",)

    values = [15, 'asdf', js_function(lambda this: 5), {'x': [1,2]}]
    @js_function
    def python_returns(this):
        return values.pop(0)
    calls[:] = []
    ctx.window.eval('(function(pr) { window.python_returns = pr; })')(
        python_returns)
    ctx.window.eval('window.pr_output = ""')
    ctx.window.eval('pr_output += "" + (python_returns()-2)')
    ctx.window.eval('pr_output += ", " + (python_returns().substr(1,2))')
    ctx.window.eval('pr_output += ", " + (python_returns()())')
    #ctx.window.eval('pr_output += ", " + (python_returns().x[0])')
    assert ctx.window['pr_output'] == '13, sd, 5'
Beispiel #4
0
Datei: ui.py Projekt: mgax/PyKit
    def on_click(self, this, event):
        # close any edit view
        if self.jQ(event.target).filter('input.edit-cell').length:
            return
        spreadsheet = self.td.closest('table.spreadsheet')
        self.jQ('input.edit-cell', spreadsheet).remove()

        # create our own edit box
        edit_input = self.jQ('<input class="edit-cell">')
        edit_input.val(unicode(self.value))
        edit_input.keydown(js_function(self.on_keydown))
        edit_input.prependTo(self.td).focus()
Beispiel #5
0
Datei: ui.py Projekt: oloed/PyKit
    def on_click(self, this, event):
        # close any edit view
        if self.jQ(event.target).filter('input.edit-cell').length:
            return
        spreadsheet = self.td.closest('table.spreadsheet')
        self.jQ('input.edit-cell', spreadsheet).remove()

        # create our own edit box
        edit_input = self.jQ('<input class="edit-cell">')
        edit_input.val(unicode(self.value))
        edit_input.keydown(js_function(self.on_keydown))
        edit_input.prependTo(self.td).focus()
Beispiel #6
0
def test_javascript_methods(ctx):
    ctx.window.eval('window.pykittest_callback = function(n){return n+6;};')
    assert ctx.window.pykittest_callback(10) == 16

    calls = []

    @js_function
    def call_to_python(this, *args):
        calls.append((this, args))

    ctx.window.eval('window.call_me_back = function(f) {\n'
                    '    f(); f(1, 3);\n'
                    '    var ob = {f: f, n: 13}; ob.f(); ob.f("asdf");\n'
                    '};')
    ctx.window.call_me_back(call_to_python)
    assert len(calls) == 4
    assert (calls[0][0].__pykit_private__.js_obj is
            ctx.window.__pykit_private__.js_obj)
    assert calls[1][1] == (1, 3)
    assert calls[2][0]['n'] == 13
    assert calls[3][1] == ("asdf", )

    values = [15, 'asdf', js_function(lambda this: 5), {'x': [1, 2]}]

    @js_function
    def python_returns(this):
        return values.pop(0)

    calls[:] = []
    ctx.window.eval('(function(pr) { window.python_returns = pr; })')(
        python_returns)
    ctx.window.eval('window.pr_output = ""')
    ctx.window.eval('pr_output += "" + (python_returns()-2)')
    ctx.window.eval('pr_output += ", " + (python_returns().substr(1,2))')
    ctx.window.eval('pr_output += ", " + (python_returns()())')
    #ctx.window.eval('pr_output += ", " + (python_returns().x[0])')
    assert ctx.window['pr_output'] == '13, sd, 5'