Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 133 lines (114 sloc) 5.01 kb
568f05e @rdp jruby only for now
authored
1 #!/usr/bin/env ruby
2 # assumes has rubygems loaded...since we need the sane gem
1acd601 @rdp cleanup intro, ease dev
authored
3
4 begin
5 require 'os'
382e32c @rdp yo
authored
6 rescue LoadError # ease of development :P
1acd601 @rdp cleanup intro, ease dev
authored
7 require 'rubygems'
382e32c @rdp yo
authored
8 require 'os'
1acd601 @rdp cleanup intro, ease dev
authored
9 end
10
568f05e @rdp jruby only for now
authored
11 if !OS.jruby?
12 $stderr.puts 'jruby only for now, you can request a change to this, exiting...'
13 exit 1
14 end
382e32c @rdp yo
authored
15
39be67f @rdp better binary
authored
16 require File.dirname(__FILE__) + "/../lib/simple_gui_creator.rb"
713f18c @rdp DRY up documentation
authored
17
f77dda8 @rdp fix some specs, fix backtrace, make display optional
authored
18 class TestWindow < SimpleGuiCreator::ParseTemplate
2a75710 @rdp working bin
authored
19
20 def initialize
21 super
22 string = <<-EOL
ba2f1ca @rdp more code tweakage, nice
authored
23 ---------- Simple Ruby Gui Creator Test Window ----------------------------------------
24 | "Edit this, then..." |
39be67f @rdp better binary
authored
25 | [Test it out! :test_it_out_button] |
ba2f1ca @rdp more code tweakage, nice
authored
26 | [ :text_area_to_use, width=70chars, height=500, font=fixed_width] |
27 | [ ] |
28 | [ ] |
29 | [ ] |
30 | [ ] |
31 | [ ] |
32 | [ ] |
33 | [ ] |
34 | |
39be67f @rdp better binary
authored
35 | [Create code snippet :create_snippet] [Insert code for this window:replace_button] |
ba2f1ca @rdp more code tweakage, nice
authored
36 ---------------------------------------------------------------------------------------
2a75710 @rdp working bin
authored
37 EOL
38 parse_setup_string string
1acd601 @rdp cleanup intro, ease dev
authored
39 elements[:text_area_to_use].text = <<-EOL
40 -------------A Title-------------
41 "Some text"
42 [Button text :button1]
43 [a text area :text_area1,height=300]
c08b58f @rdp remove non 1.8.x friendly require [yikes require, yikes]
authored
44 [ ]
1acd601 @rdp cleanup intro, ease dev
authored
45 EOL
46
ba2f1ca @rdp more code tweakage, nice
authored
47 elements[:replace_button].on_clicked {
1acd601 @rdp cleanup intro, ease dev
authored
48 elements[:text_area_to_use].text = string
49 }
ba2f1ca @rdp more code tweakage, nice
authored
50 elements[:test_it_out_button].on_clicked {
1acd601 @rdp cleanup intro, ease dev
authored
51 frame = SimpleGuiCreator::ParseTemplate.new
52 frame.parse_setup_string elements[:text_area_to_use].text
ba2f1ca @rdp more code tweakage, nice
authored
53 frame.instance_eval(enumerate_elements_and_get_code) # give the buttons something to do when clicked :P
2a75710 @rdp working bin
authored
54 }
9cc23bc @rdp huge rename <sniff>
authored
55 elements[:create_snippet].on_clicked {
e592165 @rdp refactor it out to new files
authored
56 code = create_snippet_from_current
57
f77dda8 @rdp fix some specs, fix backtrace, make display optional
authored
58 display_frame = SimpleGuiCreator::ParseTemplate.new
59 display_frame.parse_setup_string <<-EOL
60 --------Here's your snippet!--------------------
e592165 @rdp refactor it out to new files
authored
61 "Here's your snippet!"
62 [:code,width=500,height=400]
63 [ ]
64 [ ]
65 "Here's your template:"
66 [:template_text,width=500,height=400,font=fixed_width]
67 [ ]
68 [Save Both files:save_all]
69 EOL
70 display_frame.elements[:code].text = code
71 template_text = elements[:text_area_to_use].text
72 display_frame.elements[:template_text].text = template_text
73
74 display_frame.elements[:save_all].on_clicked {
75 dir = SimpleGuiCreator.new_existing_dir_chooser_and_go "Pick directory to save both files to:"
f689807 @rdp wrote all in one button
authored
76 template_file = dir + '/my_window.template'
f77dda8 @rdp fix some specs, fix backtrace, make display optional
authored
77 if File.exist? template_file
a0a37f3 @rdp prettier
authored
78 if(SimpleGuiCreator.show_select_buttons_prompt("#{template_file} already exists, overwrite?", :yes => 'Overwrite!') != :yes)
f77dda8 @rdp fix some specs, fix backtrace, make display optional
authored
79 raise 'abort this button!'
80 end
81 end
82
f689807 @rdp wrote all in one button
authored
83 File.write(template_file, elements[:text_area_to_use].text)
84 rb_file = dir + '/my_window.rb'
85 File.write(rb_file, create_snippet_from_current)
830f65a @rdp allow reveal to work in windows
authored
86 puts 'wrote to ' + rb_file + ' and ' + template_file
f689807 @rdp wrote all in one button
authored
87 SimpleGuiCreator.show_in_explorer rb_file
e592165 @rdp refactor it out to new files
authored
88 }
89 }
90 end
91
92 def create_snippet_from_current
93 # create a demo frame, so I can then pull elements from it
ba2f1ca @rdp more code tweakage, nice
authored
94 element_code = enumerate_elements_and_get_code
e592165 @rdp refactor it out to new files
authored
95 code=<<-END_CODE
24c9bfb @rdp attempt to make it work <sniff>
authored
96 # demo code to parse template file
97 require 'rubygems'
98 require 'simple_gui_creator'
9cc23bc @rdp huge rename <sniff>
authored
99
f77dda8 @rdp fix some specs, fix backtrace, make display optional
authored
100 class MyWindow < SimpleGuiCreator::ParseTemplate
9cc23bc @rdp huge rename <sniff>
authored
101 def initialize
102 super
766f6cb @rdp better
authored
103 parse_setup_filename 'my_window.template' # layout/design template
9cc23bc @rdp huge rename <sniff>
authored
104 #{element_code}
105 end
106
107 end
f77dda8 @rdp fix some specs, fix backtrace, make display optional
authored
108
ba2f1ca @rdp more code tweakage, nice
authored
109 MyWindow.new # runs forever until closed
e592165 @rdp refactor it out to new files
authored
110
111 END_CODE
112 code
9cc23bc @rdp huge rename <sniff>
authored
113 end
ba2f1ca @rdp more code tweakage, nice
authored
114
115 def enumerate_elements_and_get_code
116 fake_frame = SimpleGuiCreator::ParseTemplate.new.parse_setup_string elements[:text_area_to_use].text
117 fake_frame.close
118
119 element_code = ""
120 fake_frame.elements.each{|e|
121 if e[1].is_a? Java::JavaxSwing::JButton
122 element_code += " elements[:#{e[0]}].on_clicked { puts 'clicked #{e[0]}' }\n"
123 else
124 element_code += " #{e[0]}_current_text = elements[:#{e[0]}].text\n"
125 end
126 }
127 element_code
128 end
9cc23bc @rdp huge rename <sniff>
authored
129
2a75710 @rdp working bin
authored
130 end
131
132 TestWindow.new
Something went wrong with that request. Please try again.