examples/meta_example.rb in glimmer-dsl-libui-0.2.9 vs examples/meta_example.rb in glimmer-dsl-libui-0.2.10
- old
+ new
@@ -1,7 +1,5 @@
-# frozen_string_literal: true
-
require 'glimmer-dsl-libui'
require 'facets'
class MetaExample
include Glimmer
@@ -40,47 +38,59 @@
def selected_example
examples[@selected_example_index]
end
+ def run_example(example)
+ command = "ruby -r #{glimmer_dsl_libui_file} #{example} 2>&1"
+ result = ''
+ IO.popen(command) do |f|
+ f.each_line do |line|
+ result << line
+ puts line
+ end
+ end
+ msg_box('Error Running Example', result) if result.downcase.include?('error')
+ end
+
def launch
window('Meta-Example', 700, 500) {
margined true
horizontal_box {
vertical_box {
stretchy false
- @rbs = radio_buttons {
+ @example_radio_buttons = radio_buttons {
stretchy false
items examples_with_versions
selected @selected_example_index
on_selected do
- @selected_example_index = @rbs.selected
+ @selected_example_index = @example_radio_buttons.selected
example = selected_example
- @nwme.text = File.read(file_path_for(example))
- @sb.value = 1
+ @code_entry.text = File.read(file_path_for(example))
+ @version_spinbox.value = 1
end
}
horizontal_box {
label('Version') {
stretchy false
}
- @sb = spinbox(1, 100) {
+ @version_spinbox = spinbox(1, 100) {
value 1
on_changed do
example = selected_example
- if @sb.value > version_count_for(example)
- @sb.value -= 1
+ if @version_spinbox.value > version_count_for(example)
+ @version_spinbox.value -= 1
else
- version_number = @sb.value == 1 ? '' : @sb.value
+ version_number = @version_spinbox.value == 1 ? '' : @version_spinbox.value
example = "#{selected_example}#{version_number}"
- @nwme.text = File.read(file_path_for(example))
+ @code_entry.text = File.read(file_path_for(example))
end
end
}
}
@@ -89,27 +99,27 @@
button('Launch') {
on_clicked do
begin
meta_example_file = File.join(Dir.home, '.meta_example.rb')
- File.write(meta_example_file, @nwme.text)
- result = `ruby -r #{glimmer_dsl_libui_file} #{meta_example_file} 2>&1`
- msg_box('Error Running Example', result) if result.include?('error')
+ File.write(meta_example_file, @code_entry.text)
+ run_example(meta_example_file)
rescue => e
+ puts e.full_message
puts 'Unable to write code changes! Running original example...'
- system "ruby -r #{glimmer_dsl_libui_file} #{file_path_for(selected_example)}"
+ run_example(file_path_for(selected_example))
end
end
}
button('Reset') {
on_clicked do
- @nwme.text = File.read(file_path_for(selected_example))
+ @code_entry.text = File.read(file_path_for(selected_example))
end
}
}
}
- @nwme = non_wrapping_multiline_entry {
+ @code_entry = non_wrapping_multiline_entry {
text File.read(file_path_for(selected_example))
}
}
}.show
end