Created
September 23, 2012 13:23
-
-
Save shitsyndrome/3770911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| require 'Qt4' | |
| require 'qtwebkit' | |
| class Foo < Qt::Object | |
| signals 'mySignal()' | |
| slots "int compute(int)" | |
| def compute value | |
| value * 2 | |
| end | |
| slots "quit()" | |
| def quit | |
| Qt::Application.quit | |
| end | |
| end | |
| class Window < Qt::Widget | |
| attr_accessor :foo | |
| def initialize | |
| super | |
| view = Qt::WebView.new self | |
| layout = Qt::VBoxLayout.new do | |
| addWidget view | |
| end | |
| @foo = Foo.new | |
| view.page.mainFrame.addToJavaScriptWindowObject("foo", @foo) | |
| Qt::Object.connect(@foo, SIGNAL('mySignal()'), | |
| self, SLOT('int compute(int)')) | |
| emit @foo.mySignal() | |
| html = '<html><head><script> | |
| function updateEntry(){ | |
| var element = document.getElementById("entry"); | |
| var result = foo.compute(element.value); | |
| element.value = result;}</script> | |
| <body><div><input type="text" id="entry" value="1"/> | |
| <input type="button" value="Compute" onclick="updateEntry()"/></div> | |
| <div><input type="button" value="Quit" onclick="foo.quit()"/> | |
| </div></body></html>' | |
| view.setHtml html | |
| end | |
| end | |
| def main | |
| app = Qt::Application.new ARGV do | |
| window = Window.new | |
| window.resize(400, 200) | |
| window.show | |
| exec | |
| end | |
| end | |
| if __FILE__ == $0 | |
| main | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment