Class: Gtk3webtable
- Inherits:
-
Object
- Object
- Gtk3webtable
- Defined in:
- lib/gtk3webtable.rb
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Gtk3webtable
constructor
A new instance of Gtk3webtable.
- #on_webview_console_message(*args) ⇒ Object
- #on_webview_title_changed(*args) ⇒ Object
- #on_window_destroy ⇒ Object
- #reload_table ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Gtk3webtable
Returns a new instance of Gtk3webtable.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gtk3webtable.rb', line 4 def initialize(args = {}) @ui = Gtk3assist::Builder.new.add_from_file("#{File.dirname(__FILE__)}/win_main.glade") @ui.connect_signals{|h| method(h)} @wview = WebKit::WebView.new @wview.signal_connect("title-changed", &self.method(:on_webview_title_changed)) @wview.signal_connect("console-message", &self.method(:on_webview_console_message)) #Enable loading of local files (used for jQuery). @wview.settings.set_property("enable-file-access-from-file-uris", true) @ui["scrolledwindow"].add(@wview) self.reload_table @ui["window"].show_all end |
Instance Method Details
#on_webview_console_message(*args) ⇒ Object
21 22 23 24 |
# File 'lib/gtk3webtable.rb', line 21 def (*args) Gtk3assist::Msgbox.new(:type => :warning, :msg => args[1]) puts "Console msg: #{args}" end |
#on_webview_title_changed(*args) ⇒ Object
26 27 28 29 |
# File 'lib/gtk3webtable.rb', line 26 def on_webview_title_changed(*args) str = args[2].to_s Gtk3assist::Msgbox.new(:msg => "Callback from JavaScript. Clicked on TD with content: '#{str}'.") end |
#on_window_destroy ⇒ Object
114 115 116 |
# File 'lib/gtk3webtable.rb', line 114 def on_window_destroy Gtk.main_quit end |
#reload_table ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/gtk3webtable.rb', line 31 def reload_table html = Html_gen::Element.new(:html) head = html.add(:head) head.add(:link, { :attr => { "rel" => "stylesheet", "type" => "text/css", "href" => "file://#{File.realpath("#{File.dirname(__FILE__)}/../css")}/default.css" } }) head.add(:script, { :attr => { "type" => "text/javascript", "src" => "file://#{File.realpath("#{File.dirname(__FILE__)}/../js")}/jquery-1.8.1.min.js" } }) script = head.add(:script, { :attr => {"type" => "text/javascript"}, :str => " function remove_row(row_ele){ $('div, span', row_ele).slideUp('fast', function(){ row_ele.remove() }) } " }) body = html.add(:body) table = body.add(:table, :css => {"width" => "100%"}) thead = table.add(:thead) thead.add(:th, :str => "First name") thead.add(:th, :str => "Last name") thead.add(:th, :str => "Age") thead.add(:th, :str => "Actions") tbody = table.add(:tbody) persons = [ ["Kasper", "Johansen", "27"], ["Jacob", "Emcken", "29"], ["Christina", "Stöckel", "25"] ] persons.each do |person| tr = tbody.add(:tr) person.each do |data| td = tr.add(:td).add(:span, { :str => data, :css => { "cursor" => "pointer" }, :attr => { "onclick" => "document.title = $(this).text()" } }) end add = tr.add(:td).add(:span).add(:a, { :str => "[remove]", :css => { "cursor" => "pointer" }, :attr => { "onclick" => "remove_row($(this).parent().parent().parent())" } }) end html_str = html.html print "Reload table HTML:\n" print html_str print "\n\n" @wview.load_string(html_str, "text/html", "utf-8", "file://") end |