Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tag: v0.1.4
Fetching contributors…

Cannot retrieve contributors at this time

132 lines (114 sloc) 5.021 kb
#!/usr/bin/env ruby
# assumes has rubygems loaded...since we need the sane gem
begin
require 'os'
rescue LoadError # ease of development :P
require 'rubygems'
retry
end
if !OS.jruby?
$stderr.puts 'jruby only for now, you can request a change to this, exiting...'
exit 1
end
require 'simple_gui_creator'#File.dirname(__FILE__) + "/../lib/simple_gui_creator.rb"
class TestWindow < SimpleGuiCreator::ParseTemplate
def initialize
super
string = <<-EOL
---------- Simple Ruby Gui Creator Test Window ----------------------------------------
| "Edit this, then..." |
| [Test it out! :test_it_out_button] [Insert code for this window:replace_button] |
| [ :text_area_to_use, width=70chars, height=500, font=fixed_width] |
| [ ] |
| [ ] |
| [ ] |
| [ ] |
| [ ] |
| [ ] |
| [ ] |
| |
| [Create code snippet :create_snippet] |
---------------------------------------------------------------------------------------
EOL
parse_setup_string string
elements[:text_area_to_use].text = <<-EOL
-------------A Title-------------
"Some text"
[Button text :button1]
[a text area :text_area1,height=300]
[ ]
EOL
elements[:replace_button].on_clicked {
elements[:text_area_to_use].text = string
}
elements[:test_it_out_button].on_clicked {
frame = SimpleGuiCreator::ParseTemplate.new
frame.parse_setup_string elements[:text_area_to_use].text
frame.instance_eval(enumerate_elements_and_get_code) # give the buttons something to do when clicked :P
}
elements[:create_snippet].on_clicked {
code = create_snippet_from_current
display_frame = SimpleGuiCreator::ParseTemplate.new
display_frame.parse_setup_string <<-EOL
--------Here's your snippet!--------------------
"Here's your snippet!"
[:code,width=500,height=400]
[ ]
[ ]
"Here's your template:"
[:template_text,width=500,height=400,font=fixed_width]
[ ]
[Save Both files:save_all]
EOL
display_frame.elements[:code].text = code
template_text = elements[:text_area_to_use].text
display_frame.elements[:template_text].text = template_text
display_frame.elements[:save_all].on_clicked {
dir = SimpleGuiCreator.new_existing_dir_chooser_and_go "Pick directory to save both files to:"
template_file = dir + '/my_window.template'
if File.exist? template_file
if(SimpleGuiCreator.show_select_buttons_prompt("#{template_file} already exists, overwrite?", :yes => 'Overwrite!') != :yes)
raise 'abort this button!'
end
end
File.write(template_file, elements[:text_area_to_use].text)
rb_file = dir + '/my_window.rb'
File.write(rb_file, create_snippet_from_current)
puts 'wrote to ' + rb_file + ' and ' + template_file
SimpleGuiCreator.show_in_explorer rb_file
}
}
end
def create_snippet_from_current
# create a demo frame, so I can then pull elements from it
element_code = enumerate_elements_and_get_code
code=<<-END_CODE
# demo code to parse template file
require 'rubygems'
require 'simple_gui_creator'
class MyWindow < SimpleGuiCreator::ParseTemplate
def initialize
super
parse_setup_filename 'my_window.template' # layout/design template
#{element_code}
end
end
MyWindow.new # runs forever until closed
END_CODE
code
end
def enumerate_elements_and_get_code
fake_frame = SimpleGuiCreator::ParseTemplate.new.parse_setup_string elements[:text_area_to_use].text
fake_frame.close
element_code = ""
fake_frame.elements.each{|e|
if e[1].is_a? Java::JavaxSwing::JButton
element_code += " elements[:#{e[0]}].on_clicked { puts 'clicked #{e[0]}' }\n"
else
element_code += " #{e[0]}_current_text = elements[:#{e[0]}].text\n"
end
}
element_code
end
end
TestWindow.new
Jump to Line
Something went wrong with that request. Please try again.