rbcurse 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/CHANGELOG +1570 -0
  2. data/History.txt +6 -0
  3. data/Manifest.txt +54 -0
  4. data/README.txt +304 -0
  5. data/Rakefile +28 -0
  6. data/examples/qdfilechooser.rb +68 -0
  7. data/examples/rfe.rb +853 -0
  8. data/examples/rfe_renderer.rb +69 -0
  9. data/examples/test1.rb +242 -0
  10. data/examples/test2.rb +498 -0
  11. data/examples/testcombo.rb +95 -0
  12. data/examples/testkeypress.rb +61 -0
  13. data/examples/testmenu.rb +105 -0
  14. data/examples/testtable.rb +266 -0
  15. data/examples/testtabp.rb +106 -0
  16. data/examples/testtodo.rb +532 -0
  17. data/examples/viewtodo.rb +512 -0
  18. data/lib/rbcurse/action.rb +31 -0
  19. data/lib/rbcurse/applicationheader.rb +57 -0
  20. data/lib/rbcurse/celleditor.rb +120 -0
  21. data/lib/rbcurse/checkboxcellrenderer.rb +69 -0
  22. data/lib/rbcurse/colormap.rb +133 -0
  23. data/lib/rbcurse/comboboxcellrenderer.rb +45 -0
  24. data/lib/rbcurse/defaultlistselectionmodel.rb +49 -0
  25. data/lib/rbcurse/keylabelprinter.rb +143 -0
  26. data/lib/rbcurse/listcellrenderer.rb +99 -0
  27. data/lib/rbcurse/listkeys.rb +33 -0
  28. data/lib/rbcurse/listscrollable.rb +216 -0
  29. data/lib/rbcurse/listselectable.rb +67 -0
  30. data/lib/rbcurse/mapper.rb +108 -0
  31. data/lib/rbcurse/orderedhash.rb +77 -0
  32. data/lib/rbcurse/rcombo.rb +243 -0
  33. data/lib/rbcurse/rdialogs.rb +183 -0
  34. data/lib/rbcurse/rform.rb +845 -0
  35. data/lib/rbcurse/rinputdataevent.rb +36 -0
  36. data/lib/rbcurse/rlistbox.rb +804 -0
  37. data/lib/rbcurse/rmenu.rb +666 -0
  38. data/lib/rbcurse/rmessagebox.rb +325 -0
  39. data/lib/rbcurse/rpopupmenu.rb +754 -0
  40. data/lib/rbcurse/rtabbedpane.rb +259 -0
  41. data/lib/rbcurse/rtable.rb +1296 -0
  42. data/lib/rbcurse/rtextarea.rb +673 -0
  43. data/lib/rbcurse/rtextview.rb +335 -0
  44. data/lib/rbcurse/rwidget.rb +1731 -0
  45. data/lib/rbcurse/scrollable.rb +301 -0
  46. data/lib/rbcurse/selectable.rb +94 -0
  47. data/lib/rbcurse/table/tablecellrenderer.rb +85 -0
  48. data/lib/rbcurse/table/tabledatecellrenderer.rb +102 -0
  49. data/lib/rbcurse.rb +7 -0
  50. data/lib/ver/keyboard.rb +150 -0
  51. data/lib/ver/keyboard2.rb +170 -0
  52. data/lib/ver/ncurses.rb +102 -0
  53. data/lib/ver/window.rb +369 -0
  54. data/test/test_rbcurse.rb +0 -0
  55. metadata +118 -0
@@ -0,0 +1,325 @@
1
+ =begin
2
+ * Name: rmessagebox: creates messageboxes
3
+ * Description
4
+ * Author: rkumar (arunachalesha)
5
+ * Date: 2008-11-19 12:49
6
+ * License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
7
+ * file separated on 2009-01-13 22:39
8
+
9
+ =end
10
+ require 'rbcurse/rwidget'
11
+ require 'rbcurse/rlistbox'
12
+
13
+ module RubyCurses
14
+ ##
15
+ # dimensions of window should be derived on content
16
+ #
17
+ class MessageBox
18
+ include DSL
19
+ include RubyCurses::Utils
20
+ dsl_accessor :title
21
+ dsl_accessor :message
22
+ dsl_accessor :type # :ok, :ok_cancel :yes_no :yes_no_cancel :custom
23
+ dsl_accessor :default_button # TODO - currently first
24
+ dsl_accessor :layout
25
+ dsl_accessor :buttons # used if type :custom
26
+ dsl_accessor :underlines # offsets of each button to underline
27
+ attr_reader :config
28
+ attr_reader :selected_index # button index selected by user
29
+ attr_reader :window # required for keyboard
30
+ dsl_accessor :list_selection_mode # true or false allow multiple selection
31
+ dsl_accessor :list # 2009-01-05 23:59
32
+ dsl_accessor :button_type # ok, ok_cancel, yes_no
33
+ dsl_accessor :default_value #
34
+ dsl_accessor :default_values # # 2009-01-06 00:05 after removing meth missing
35
+ dsl_accessor :height, :width, :top, :left # 2009-01-06 00:05 after removing meth missing
36
+
37
+ dsl_accessor :message_height
38
+
39
+
40
+ def initialize form=nil, aconfig={}, &block
41
+ @form = form
42
+ @config = aconfig
43
+ @buttons = []
44
+ #@keys = {}
45
+ @bcol = 5
46
+ @selected_index = -1
47
+ @config.each_pair { |k,v| instance_variable_set("@#{k}",v) }
48
+ instance_eval &block if block_given?
49
+ if @layout.nil?
50
+ case @type.to_s
51
+ when "input"
52
+ layout(10,60, 10, 20)
53
+ when "list"
54
+ height = [5, @list.length].min
55
+ layout(10+height, 60, 5, 20)
56
+ when "field_list"
57
+ height = @field_list.length
58
+ layout(10+height, 60, 5, 20)
59
+ when "override"
60
+ $log.debug " override: #{@height},#{@width}, #{@top}, #{@left} "
61
+ layout(@height,@width, @top, @left)
62
+ $log.debug " override: #{@layout.inspect}"
63
+ else
64
+ height = @form && @form.widgets.length ## quick fix. FIXME
65
+ height ||= 0
66
+ layout(10+height,60, 10, 20)
67
+ end
68
+ end
69
+ @window = VER::Window.new(@layout)
70
+ if @form.nil?
71
+ @form = RubyCurses::Form.new @window
72
+ else
73
+ @form.window = @window
74
+ end
75
+ acolor = get_color $reversecolor
76
+ $log.debug " MESSAGE BOX #{@bgcolor} , #{@color} , #{acolor}"
77
+ @window.bkgd(Ncurses.COLOR_PAIR(acolor));
78
+ @window.wrefresh
79
+ @panel = @window.panel
80
+ Ncurses::Panel.update_panels
81
+ process_field_list
82
+ print_borders
83
+ print_title
84
+ print_message unless @message.nil?
85
+ print_input
86
+ create_buttons
87
+ @form.repaint
88
+ @window.wrefresh
89
+ handle_keys
90
+ end
91
+ ##
92
+ # takes care of a field list sent in
93
+ def process_field_list
94
+ return if @field_list.nil? or @field_list.length == 0
95
+ @field_list.each do |f|
96
+ f.set_form @form
97
+ end
98
+ end
99
+ def default_button offset0
100
+ @selected_index = offset0
101
+ end
102
+ ##
103
+ # value entered by user if type = input
104
+ def input_value
105
+ return @input.buffer if !@input.nil?
106
+ return @listbox.getvalue if !@listbox.nil?
107
+ end
108
+ def create_buttons
109
+ case @button_type.to_s.downcase
110
+ when "ok"
111
+ make_buttons ["&OK"]
112
+ when "ok_cancel" #, "input", "list", "field_list"
113
+ make_buttons %w[&OK &Cancel]
114
+ when "yes_no"
115
+ make_buttons %w[&Yes &No]
116
+ when "yes_no_cancel"
117
+ make_buttons ["&Yes", "&No", "&Cancel"]
118
+ when "custom"
119
+ raise "Blank list of buttons passed to custom" if @buttons.nil? or @buttons.size == 0
120
+ make_buttons @buttons
121
+ else
122
+ $log.debug "No type passed for creating messagebox. Using default (OK)"
123
+ make_buttons ["&OK"]
124
+ end
125
+ end
126
+ def make_buttons names
127
+ total = names.inject(0) {|total, item| total + item.length + 4}
128
+ bcol = center_column total
129
+
130
+ brow = @layout[:height]-3
131
+ button_ct=0
132
+ names.each_with_index do |bname, ix|
133
+ text = bname
134
+ #underline = @underlines[ix] if !@underlines.nil?
135
+
136
+ button = Button.new @form do
137
+ text text
138
+ name bname
139
+ row brow
140
+ col bcol
141
+ #underline underline
142
+ highlight_background $datacolor
143
+ color $reversecolor
144
+ bgcolor $reversecolor
145
+ end
146
+ index = button_ct
147
+ button.command { |form| @selected_index = index; @stop = true; $log.debug "Pressed Button #{bname}";}
148
+ button_ct += 1
149
+ bcol += text.length+6
150
+ end
151
+ end
152
+ ## message box
153
+ def stopping?
154
+ @stop
155
+ end
156
+ def handle_keys
157
+ begin
158
+ while((ch = @window.getchar()) != 999 )
159
+ case ch
160
+ when -1
161
+ next
162
+ else
163
+ press ch
164
+ break if @stop
165
+ end
166
+ end
167
+ ensure
168
+ destroy
169
+ end
170
+ return @selected_index
171
+ end
172
+ def press ch
173
+ #$log.debug "message box handle_keys : #{ch}" if ch != -1
174
+ case ch
175
+ when -1
176
+ return
177
+ when KEY_F1, 27, ?\C-q
178
+ @selected_index = -1
179
+ @stop = true
180
+ return
181
+ when KEY_ENTER, 10, 13
182
+ field = @form.get_current_field
183
+ if field.respond_to? :fire
184
+ field.fire
185
+ end
186
+ $log.debug "popup ENTER : #{@selected_index} "
187
+ $log.debug "popup ENTER : #{field.name}" if !field.nil?
188
+ @stop = true
189
+ return
190
+ when 9
191
+ @form.select_next_field
192
+ else
193
+ # fields must return unhandled else we will miss hotkeys.
194
+ # On messageboxes, often if no edit field, then O and C are hot.
195
+ field = @form.get_current_field
196
+ handled = field.handle_key ch
197
+
198
+ if handled == :UNHANDLED
199
+ ret = @form.process_key ch, self ## trying out trigger button
200
+ end
201
+ end
202
+ @form.repaint
203
+ Ncurses::Panel.update_panels();
204
+ Ncurses.doupdate();
205
+ @window.wrefresh
206
+ end
207
+ def print_borders
208
+ width = @layout[:width]
209
+ height = @layout[:height]
210
+ @window.print_border_mb 1,2, height, width, $normalcolor, A_REVERSE
211
+ =begin
212
+ start = 2
213
+ hline = "+%s+" % [ "-"*(width-((start+1)*2)) ]
214
+ hline2 = "|%s|" % [ " "*(width-((start+1)*2)) ]
215
+ @window.printstring(row=1, col=start, hline, color=$reversecolor)
216
+ (start).upto(height-2) do |row|
217
+ @window.printstring row, col=start, hline2, color=$normalcolor, A_REVERSE
218
+ end
219
+ @window.printstring(height-2, col=start, hline, color=$reversecolor)
220
+ =end
221
+ end
222
+ def print_title title=@title
223
+ width = @layout[:width]
224
+ title = " "+title+" "
225
+ @window.printstring(row=1,col=(width-title.length)/2,title, color=$normalcolor)
226
+ end
227
+ def center_column textlen
228
+ width = @layout[:width]
229
+ return (width-textlen)/2
230
+ end
231
+ def print_message message=@message, row=nil
232
+ @message_row = @message_col = 2
233
+ display_length = @layout[:width]-8
234
+ # XXX this needs to go up and decide height of window
235
+ if @message_height.nil?
236
+ @message_height = (message.length/display_length)+1
237
+ $log.debug " print_message: mh:#{@message_height}"
238
+ end
239
+ @message_height ||= 1
240
+ width = @layout[:width]
241
+ return if message.nil?
242
+ case @type.to_s
243
+ when "input"
244
+ row=(@layout[:height]/3) if row.nil?
245
+ @message_col = 4
246
+ when "list"
247
+ row=3
248
+ @message_col = 4
249
+ else
250
+ row=(@layout[:height]/3) if row.nil?
251
+ @message_col = (width-message.length)/2
252
+ end
253
+ @message_row = row
254
+ #@window.printstring( row, @message_col , message, color=$reversecolor)
255
+ # 2008-12-30 19:45 experimenting with label so we can get justify and wrapping.
256
+ #@window.printstring( row, @message_col , message, color=$reversecolor)
257
+ message_label = RubyCurses::Label.new @form, {'text' => message, "name"=>"message_label","row" => row, "col" => @message_col, "display_length" => display_length, "height" => @message_height, "attr"=>"reverse"}
258
+
259
+ end
260
+ def print_input
261
+ #return if @type.to_s != "input"
262
+ @message_height ||= 0
263
+ @message_row ||= 2
264
+ @message_col ||= 2
265
+ r = @message_row + @message_height + 1
266
+ c = @message_col
267
+ defaultvalue = @default_value || ""
268
+ input_config = @config["input_config"] || {}
269
+ case @type.to_s
270
+ when "input"
271
+ @input = RubyCurses::Field.new @form, input_config do
272
+ name "input"
273
+ row r
274
+ col c
275
+ display_length 30
276
+ set_buffer defaultvalue
277
+ end
278
+ when "list"
279
+ list = @list
280
+ selection_mode = @list_selection_mode
281
+ default_values = @default_values
282
+ $log.debug " value of select_mode #{selection_mode}"
283
+ @listbox = RubyCurses::Listbox.new @form do
284
+ name "input"
285
+ row r
286
+ col c
287
+ # attr 'reverse'
288
+ color 'black'
289
+ bgcolor 'white'
290
+ width 30
291
+ height 6
292
+ list list
293
+ # ?? display_length 30
294
+ #set_buffer defaultvalue
295
+ selection_mode selection_mode
296
+ default_values default_values
297
+ is_popup false
298
+ end
299
+ end
300
+ end
301
+ def configure(*val , &block)
302
+ case val.size
303
+ when 1
304
+ return @config[val[0]]
305
+ when 2
306
+ @config[val[0]] = val[1]
307
+ instance_variable_set("@#{val[0]}", val[1])
308
+ end
309
+ instance_eval &block if block_given?
310
+ end
311
+ def cget param
312
+ @config[param]
313
+ end
314
+
315
+ def layout(height=0, width=0, top=0, left=0)
316
+ @layout = { :height => height, :width => width, :top => top, :left => left }
317
+ end
318
+ def destroy
319
+ $log.debug "DESTROY : widget"
320
+ panel = @window.panel
321
+ Ncurses::Panel.del_panel(panel) if !panel.nil?
322
+ @window.delwin if !@window.nil?
323
+ end
324
+ end
325
+ end