How keen are you on using wxWidgets? This would be very easy with Qt + QtWebkit - you can inject (native) QObjects into the QWebView, where they can be manipulated via Javascript. Here's an old QtRuby example I had lying around:
Code:
#! /usr/bin/ruby
# Use a native Ruby QObject to decide what string to show
# in the HTML text box based on the string entered into the HTML input box.
require 'Qt4'
require 'qtwebkit'
app = Qt::Application.new(ARGV)
class JSObjectTest < Qt::Object
def initialize()
super(nil)
end
def doSomethingWithString(string)
# I'm not very imaginative, so just reverse the string for now.
# You could, of course, use absolutely any aspect of ruby in order
# to do more interesting stuff with the string instead :)
return "Backwards is #{string.reverse}"
end
slots 'QString doSomethingWithString(QString)'
end
webView = Qt::WebView.new
webView.page.currentFrame.addToJavaScriptWindowObject("jsObjTest", JSObjectTest.new)
webView.setHtml(
<<-HTMLPAGEEND
<html>
<head>
<script type="text/javascript">
function textChanged()
{
// Update the rubytext text with the text returned by the native ruby method.
inputtextstring = document.getElementById("textinput").value;
rubytext = document.getElementById("rubytext");
rubytext.value = jsObjTest.doSomethingWithString(inputtextstring);
}
function pageLoaded()
{
document.getElementById("textinput").addEventListener("keyup", textChanged);
}
</script>
</head>
<body onload="pageLoaded()">
Enter some text:
<input type="text" id="textinput">
Ruby sez:
<input type="text" id="rubytext">
</body>
</html>
HTMLPAGEEND
)
webView.show
app.exec
I'm guessing PyQt would be similar.
Anyway, perhaps wxWidgets has the same feature, but this is another option should the worst come to the worst
Edit:
Here we go - an even better example:
Code:
#! /usr/bin/ruby
# Inspired by: http://ubuntuforums.org/showthread.php?t=1939168
require 'Qt4'
require 'qtwebkit'
app = Qt::Application.new(ARGV)
class JSObjectTest < Qt::Object
def initialize()
super(nil)
end
def doSomethingWithCoords(latitude, longtitude)
# Just print to stdout for now, but the sky's the limit!
print "Lat: #{latitude} Long: #{longtitude}\n"
end
slots 'QString doSomethingWithCoords(QString, QString)'
end
webView = Qt::WebView.new
webView.page.currentFrame.addToJavaScriptWindowObject("jsObjTest", JSObjectTest.new)
webView.setHtml(
<<-HTMLPAGEEND
<html>
<head>
<title>OpenLayers Example</title>
<script type='text/javascript'
src='http://www.openlayers.org/api/OpenLayers.js'></script>
<script type='text/javascript'
src='http://www.openstreetmap.org/openlayers/OpenStreetMap.js'></script>
<script type='text/javascript'
src='http://www.free-map.org.uk/javascript/ezol.js'></script>
<script type='text/javascript'>
function init()
{
var map = makeMap("map1");
var layerOSM = new OpenLayers.Layer.OSM();
map.addLayer(layerOSM);
map.setCenter(project(new OpenLayers.LonLat(-0.71,51.06)), 14);
map.events.register("click",map,clickHandler);
}
function clickHandler(e)
{
var pos1 = unproject(this.getLonLatFromViewPortPx(e.xy));
//alert("Longitude: " + pos1.lon + " Latitude: " + pos1.lat);
jsObjTest.doSomethingWithCoords(pos1.lat, pos1.lon);
}
</script>
</head>
<body onload="init()">
<h1>OpenLayers Test</h1>
<div id="map1" style="width:800px; height:600px"> </div>
</body>
</html>
HTMLPAGEEND
)
webView.show
app.exec
Bookmarks