[PyQt] how to use a JS method from within Python ?

Stef Mientki stef.mientki at gmail.com
Thu Jul 21 17:12:03 BST 2011


hello,

I use CodeMirror as an editable codeeditor in a QWebView.
After creating an inserting CodeMirror, I get a reference to that CodeMirror object.
Now I want to execute some of the methods of the CodeMirror object.
Is that possible from within Python ?


    # get the webframe
    frame = self.web.page().mainFrame()

    # insert a textarea at the current position
    self.execCommand ( 'insertHtml', """
<textarea name="%s" id="%s">

</textarea>
""" % ( "aap", "aap" ) )

    # Call the JS function, that transforms
    # the textarea "aap" into a editable CodeMirror thing
    JS = """Add_CodeMirror ( "%s" )""" % "aap"
    Editor = frame.evaluateJavaScript ( JS )

    # Editor now contains a reference (whatever that may be)
    # to the CodeMirror object
    print 'EEEE', Editor
    """
EEEE {u'undo': {}, u'getRange': {}, u'matchBrackets': {}, u'focus': {}, u'lineCount': {},
u'getTokenAt': {}, u'operation': {}, u'redo': {}, u'getLine': {}, u'toTextArea': {}, u'charCoords':
{}, u'setOption': {}, u'indentLine': {}, u'setLineClass': {}, u'replaceRange': {},
u'getScrollerElement': {}, u'setLine': {}, u'save': {}, u'removeLine': {}, u'getOption': {},
u'setValue': {}, u'getInputField': {}, u'getSelection': {}, u'lineInfo': {}, u'getCursor': {},
u'coordsChar': {}, u'somethingSelected': {}, u'addWidget': {}, u'markText': {}, u'setCursor': {},
u'setSelection': {}, u'cursorCoords': {}, u'getWrapperElement': {}, u'refresh': {}, u'getValue': {},
u'replaceSelection': {}, u'setMarker': {}, u'historySize': {}, u'getSearchCursor': {},
u'getStateAfter': {}, u'clearMarker': {}}
    """

    # Now I want to put text in the CodeMirror object
    # CodeMirror has a method "setValue(..)"
    # But how do I use that ?
    # the next line doesn't work
    Editor["setValue"] = 'jhdhashdjhj'

thanks,
Stef Mientki



More information about the PyQt mailing list