39
loading...
This website collects cookies to deliver better user experience
window {
title 'Hello, World!'
label('Hello, World!')
}.show
gem install glimmer-dsl-gtk
Gemfile
:gem 'glimmer-dsl-gtk', '~> 0.0.1'
bundle
Glimmer
module to utilize the Glimmer GUI DSL for GTK:require 'glimmer-dsl-gtk'
include Glimmer
window {
title 'Demo'
on(:destroy) do
puts 'Bye Bye'
::Gtk.main_quit
end
}.show
Glimmer
module into an application class instead:require 'glimmer-dsl-gtk'
class SomeGlimmerApplication
include Glimmer
def launch
application('org.glimmer.hello-application', :flags_none) {
on(:activate) do |app|
application_window(app) {
title 'Actual Application'
}.present
end
}.run
end
end
SomeGlimmerApplication.new.launch
application_window(app)
for Gtk::ApplicationWindow.new(app)
). Keywords can be nested under other keywords to represent the true hierarchy of nested widgets on the screen (e.g. window { label('Hello') }
is a label
nested under a window
). Note that widget objects returned are proxies of the GTK widget counterparts. This shields consumers of GTK from its lower-level details via composition (Proxy Design Pattern). To access lower-level GTK widget, simply call #gtk
method on widget proxy object (e.g. @w = window {...}; @w.gtk # Gtk::Window widget object
).window {|w| ... }
):
window {title 'Hello, World'}
sets title
property of window
)on(signal) { ... }
syntax (e.g. on(:activate) { do_something }
)girb
command (bin/girb
if you cloned the project locally):girb
irb
with the glimmer-dsl-gtk
gem loaded and the Glimmer
module mixed into the main object for easy experimentation with GUI.girb
, it remains open until you enter exit or open another GUI window.ruby -r glimmer-dsl-gtk -e "require 'samples/hello/hello_world'"
ruby -r ./lib/glimmer-dsl-gtk.rb samples/hello/hello_world.rb
window {
title 'Hello, World!'
label('Hello, World!')
}.show
ruby -r glimmer-dsl-gtk -e "require 'samples/hello/hello_application'"
ruby -r ./lib/glimmer-dsl-gtk.rb samples/hello/hello_application.rb
require 'glimmer-dsl-gtk'
include Glimmer
application('org.glimmer.hello-application', :flags_none) {
on(:activate) do |app|
application_window(app) {
title 'Hello, Application!'
}.present
end
}.run
ruby -r glimmer-dsl-gtk -e "require 'samples/hello/hello_button'"
ruby -r ./lib/glimmer-dsl-gtk.rb samples/hello/hello_button.rb
require 'glimmer-dsl-gtk'
include Glimmer
window { |w|
title 'Hello, Button!'
button('Button') {
on(:clicked) do
message_dialog(w) { |md|
title 'Information'
text 'You clicked the button'
on(:response) do
md.destroy
end
}.show
end
}
}.show
ruby -r glimmer-dsl-gtk -e "require 'samples/hello/hello_entry'"
ruby -r ./lib/glimmer-dsl-gtk.rb samples/hello/hello_entry.rb
require 'glimmer-dsl-gtk'
include Glimmer
window { |w|
title 'Hello, Entry!'
default_size 300, 50
box(:vertical) {
e = entry {
on(:changed) do
puts e.text
$stdout.flush # For Windows
end
}
button('Button') {
on(:clicked) do
message_dialog(w) { |md|
title 'You entered'
text e.text
on(:response) do
md.destroy
end
}.show
end
}
}
}.show