Skip to content

Instantly share code, notes, and snippets.

@fela
Created August 23, 2010 19:53
Show Gist options
  • Save fela/546187 to your computer and use it in GitHub Desktop.
Save fela/546187 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$VERBOSE = true
$:.unshift File.dirname($0)
require 'Qt4'
module Shoes
def self.app &blk
# block is passed as proc to not trigger the qtruby initialization
Shoes::App.new blk
end
end
require 'forwardable'
class Shoes::StackLayout < Qt::VBoxLayout
extend Forwardable
# TODO most are still missing
def_delegators :@layout, :add_widget#, :add_layout, :add_item, :remove_item,
#:remove_widget, :remove_layout, :count
def initialize
super
@layout = Qt::VBoxLayout.new
add_layout(@layout, 0)
add_stretch(1)
end
end
class Shoes::App < Qt::Application
def initialize blk
super ARGV
@_main_window = Qt::Widget.new do
self.layout = Shoes::StackLayout.new
resize 200, 400
end
@_current_widget = @_main_window
instance_eval &blk
@_main_window.show
exec
exit
end
def button txt, &blk
b = Qt::PushButton.new txt do
puts blk
puts self
#connect(SIGNAL :clicked) &blk if blk # TODO: not working ?????
connect(SIGNAL :clicked) { blk.call } if blk
end
add_widget b
end
def add_widget widget
@_current_widget.layout.add_widget widget, 0
end
end
Shoes.app do
button("Hello") { puts self }
button "Another button"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment