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
data/examples/test2.rb ADDED
@@ -0,0 +1,498 @@
1
+ #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
2
+ # this program tests out various widgets.
3
+ require 'rubygems'
4
+ require 'ncurses'
5
+ require 'logger'
6
+ require 'rbcurse'
7
+ require 'rbcurse/rwidget'
8
+ #require 'rbcurse/rform'
9
+ require 'rbcurse/rtextarea'
10
+ require 'rbcurse/rtextview'
11
+ require 'rbcurse/rmenu'
12
+ require 'rbcurse/rcombo'
13
+ require 'rbcurse/listcellrenderer'
14
+ require 'rbcurse/checkboxcellrenderer'
15
+ require 'rbcurse/comboboxcellrenderer'
16
+ require 'rbcurse/celleditor'
17
+ require 'qdfilechooser'
18
+ require 'rbcurse/rlistbox'
19
+ require 'rbcurse/rmessagebox'
20
+ if $0 == __FILE__
21
+ include RubyCurses
22
+
23
+ begin
24
+ # Initialize curses
25
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
26
+ $log = Logger.new("view.log")
27
+ $log.level = Logger::DEBUG
28
+
29
+ @window = VER::Window.root_window
30
+ # Initialize few color pairs
31
+ # Create the window to be associated with the form
32
+ # Un post form and free the memory
33
+
34
+ catch(:close) do
35
+ colors = Ncurses.COLORS
36
+ $log.debug "START #{colors} colors ---------"
37
+ @form = Form.new @window
38
+ @form.window.printstring 0, 25, "Demo of Ruby Curses Widgets", $normalcolor, 'reverse'
39
+ r = 1; fc = 12;
40
+ mnemonics = %w[ n l r p]
41
+ %w[ name line regex password].each_with_index do |w,i|
42
+ field = Field.new @form do
43
+ name w
44
+ row r
45
+ col fc
46
+ display_length 30
47
+ #set_buffer "abcd "
48
+ set_label Label.new @form, {'text' => w, 'color'=>'cyan','mnemonic'=> mnemonics[i]}
49
+ end
50
+ r += 1
51
+ end
52
+
53
+ $message = Variable.new
54
+ $message.value = "Message Comes Here"
55
+ message_label = RubyCurses::Label.new @form, {'text_variable' => $message, "name"=>"message_label","row" => 27, "col" => 1, "display_length" => 60, "height" => 2, 'color' => 'cyan'}
56
+
57
+ $results = Variable.new
58
+ $results.value = "A variable"
59
+ var = RubyCurses::Label.new @form, {'text_variable' => $results, "row" => r, "col" => fc}
60
+ r += 1
61
+ mylist = []
62
+ 0.upto(100) { |v| mylist << "#{v} scrollable data" }
63
+ $listdata = Variable.new mylist
64
+ listb = Listbox.new @form do
65
+ name "mylist"
66
+ row r
67
+ col 1
68
+ width 40
69
+ height 10
70
+ # list mylist
71
+ list_variable $listdata
72
+ #selection_mode :SINGLE
73
+ show_selector true
74
+ row_selected_symbol "[X] "
75
+ row_unselected_symbol "[ ] "
76
+ title "A long list"
77
+ title_attrib 'reverse'
78
+ cell_editing_allowed true
79
+ end
80
+ #listb.insert 55, "hello ruby", "so long python", "farewell java", "RIP .Net"
81
+ #$listdata.value.insert 55, "hello ruby", "so long python", "farewell java", "RIP .Net"
82
+ listb.list_data_model.insert 55, "hello ruby", "so long python", "farewell java", "RIP .Net", "hi lisp", "hi perl6"
83
+ texta = TextArea.new @form do
84
+ name "mytext"
85
+ row 1
86
+ col 52
87
+ width 40
88
+ height 14
89
+ title "Editable box"
90
+ title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
91
+ print_footer true
92
+ bind(:CHANGE){|e| $message.value = e.to_s+" CP:"+e.source.curpos.to_s }
93
+ end
94
+ texta << "I expect to pass through this world but once." << "Any good therefore that I can do, or any kindness or abilities that I can show to any fellow creature, let me do it now."
95
+ texta << "Let me not defer it or neglect it, for I shall not pass this way again."
96
+ texta << " "
97
+ texta << " F1 to exit. or click cancel button"
98
+ texta << " Or alt-c"
99
+
100
+ alist = [true, false, true, false, true, false, true, false, true]
101
+ cblist = Variable.new alist
102
+ listcb = Listbox.new @form do
103
+ name "cblist"
104
+ row 1
105
+ col 96
106
+ width 8
107
+ height 10
108
+ # list mylist
109
+ list_variable cblist
110
+ #selection_mode :SINGLE
111
+ title "Checklist"
112
+ title_attrib 'reverse'
113
+ cell_renderer RubyCurses::CheckBoxCellRenderer.new nil, {"parent" => self, "display_length"=> @width-2}
114
+ cell_editing_allowed true
115
+ cell_editor RubyCurses::CellEditor.new(RubyCurses::CheckBox.new nil, {"focusable"=>false, "visible"=>false})
116
+ end
117
+ colist = ["Todo", "WIP", "Fin", "Cancel", "Postp"]
118
+ colistdata = ["Todo", "Todo", "WIP","WIP", "Postp", "Cancel","Cancel", "Postp"]
119
+ colistv = Variable.new colistdata
120
+ listcb = Listbox.new @form do
121
+ name "colist"
122
+ row 16
123
+ col 96
124
+ width 12
125
+ height 10
126
+ # list mylist
127
+ list_variable colistv
128
+ #selection_mode :SINGLE
129
+ title "Status"
130
+ title_attrib 'bold'
131
+ cell_editing_allowed true
132
+ cell_renderer RubyCurses::ComboBoxCellRenderer.new nil, {"parent" => self, "display_length"=> width()-2}
133
+ cell_editor RubyCurses::CellEditor.new(RubyCurses::ComboBox.new nil, {"focusable"=>false, "visible"=>false, "list"=>colist, "display_length"=>width()-2})
134
+ end
135
+ #listcb.cell_editor.component.form = @form
136
+
137
+ @textview = TextView.new @form do
138
+ name "myView"
139
+ row 16
140
+ col 52
141
+ width 40
142
+ height 10
143
+ title "README.txt"
144
+ title_attrib 'bold'
145
+ print_footer true
146
+ footer_attrib 'bold'
147
+ end
148
+ content = File.open("../README.txt","r").readlines
149
+ @textview.set_content content #, :WRAP_WORD
150
+ @textview.top_row 21
151
+
152
+ # just for demo, lets scroll the text view as we scroll this.
153
+ listb.bind(:ENTER_ROW, @textview) { |alist, tview| tview.top_row alist.current_index }
154
+
155
+ # just for demo, lets scroll the text view to the line you enter
156
+ @form.by_name["line"].bind(:LEAVE, @textview) { |fld, tv| raise(FieldValidationException, "#{fld.getvalue.to_i} Outside range 1,200") if fld.getvalue.to_i >200; tv.top_row(fld.getvalue.to_i) }
157
+ @form.by_name["regex"].bind(:LEAVE, @textview) { |fld, tv| tv.top_row(tv.find_first_match(fld.getvalue)) }
158
+ @form.by_name["regex"].bind(:CHANGED) { |fld|
159
+ $message.value = "REGEX CHANGED!!! #{fld.getvalue} " }
160
+ row = 17
161
+ col = 2
162
+ align = ComboBox.new @form do
163
+ name "combo"
164
+ row row
165
+ col fc
166
+ display_length 10
167
+ editable false
168
+ list %w[left right center]
169
+ set_label Label.new @form, {'text' => "Align", 'color'=>'cyan','col'=>1, "mnemonic"=>"I"}
170
+ list_config 'color' => 'yellow', 'bgcolor'=>'red', 'height' => 4
171
+ end
172
+
173
+ list = ListDataModel.new( %w[spotty tiger panther jaguar leopard ocelot lion])
174
+ list.bind(:LIST_DATA_EVENT) { |lde| $message.value = lde.to_s; $log.debug " STA: #{$message.value} #{lde}" }
175
+ list.bind(:ENTER_ROW) { |obj| $message.value = "ENTER_ROW :#{obj.current_index} : #{obj.selected_item} "; $log.debug " ENTER_ROW: #{$message.value} , #{obj}" }
176
+
177
+ row += 1
178
+ combo1 = ComboBox.new @form do
179
+ name "combo1"
180
+ row row
181
+ col fc
182
+ display_length 10
183
+ editable true
184
+ list_data_model list
185
+ set_label Label.new @form, {'text' => "Edit Combo",'color'=>'cyan','col'=>1}
186
+ list_config 'color' => 'white', 'bgcolor'=>'blue', 'max_visible_items' => 6, 'height' => 7
187
+ end
188
+ row += 1
189
+ checkbutton = CheckBox.new @form do
190
+ variable $results
191
+ #value = true
192
+ onvalue "Selected bold "
193
+ offvalue "UNselected bold"
194
+ text "Bold attribute "
195
+ display_length 18 # helps when right aligning
196
+ row row
197
+ col col
198
+ mnemonic 'B'
199
+ end
200
+ row += 1
201
+ @cb_rev = Variable.new false # related to checkbox reverse
202
+ cbb = @cb_rev
203
+ checkbutton1 = CheckBox.new @form do
204
+ variable cbb # $cb_rev
205
+ #value = true
206
+ onvalue "Selected reverse "
207
+ offvalue "UNselected reverse"
208
+ text "Reverse attribute "
209
+ display_length 18
210
+ row row
211
+ col col
212
+ mnemonic 'R'
213
+ end
214
+ row += 1
215
+ togglebutton = ToggleButton.new @form do
216
+ value true
217
+ onvalue " Toggle Down "
218
+ offvalue " Untoggle "
219
+ row row
220
+ col col
221
+ mnemonic 'T'
222
+ #underline 0
223
+ end
224
+ # a special case required since another form (combo popup also modifies)
225
+ $message.update_command() { message_label.repaint }
226
+
227
+ @form.by_name["line"].display_length = 3
228
+ @form.by_name["line"].maxlen = 3
229
+ @form.by_name["line"].set_buffer "24"
230
+ @form.by_name["name"].set_buffer "Not focusable"
231
+ @form.by_name["name"].set_focusable(false)
232
+ @form.by_name["line"].chars_allowed = /\d/
233
+ #@form.by_name["regex"].type(:ALPHA)
234
+ @form.by_name["regex"].valid_regex(/^[A-Z][a-z]*/)
235
+ @form.by_name["regex"].set_buffer "SYNOP"
236
+ @form.by_name["regex"].display_length = 10
237
+ @form.by_name["regex"].maxlen = 20
238
+ #@form.by_name["regex"].bgcolor 'cyan'
239
+ @form.by_name["password"].set_buffer ""
240
+ @form.by_name["password"].show '*'
241
+ @form.by_name["password"].color 'red'
242
+ #@form.by_name["password"].bgcolor 'blue'
243
+ @form.by_name["password"].values(%w[scotty tiger secret pass qwerty])
244
+ @form.by_name["password"].null_allowed true
245
+
246
+ # a form level event, whenever any widget is focussed
247
+ @form.bind(:ENTER) { |f| f.label && f.label.bgcolor = 'red' if f.respond_to? :label}
248
+ @form.bind(:LEAVE) { |f| f.label && f.label.bgcolor = 'black' if f.respond_to? :label}
249
+
250
+ row += 1
251
+ colorlabel = Label.new @form, {'text' => "Select a color:", "row" => row, "col" => col, "color"=>"cyan", "mnemonic" => 'S'}
252
+ $radio = Variable.new
253
+ $radio.update_command(colorlabel) {|tv, label| label.color tv.value; }
254
+ $radio.update_command() {|tv| message_label.color tv.value; align.bgcolor tv.value; combo1.bgcolor tv.value}
255
+
256
+ # whenever updated set colorlabel and messagelabel to bold
257
+ $results.update_command(colorlabel,checkbutton) {|tv, label, cb| attrs = cb.value ? 'bold' : nil; label.attr(attrs); message_label.attr(attrs)}
258
+
259
+ align.bind(:ENTER_ROW) {|fld| message_label.justify fld.getvalue}
260
+ align.bind(:ENTER_ROW) {|fld|
261
+ if fld.getvalue == 'right'
262
+ checkbutton1.align_right true
263
+ checkbutton.align_right true
264
+ else
265
+ checkbutton1.align_right false
266
+ checkbutton.align_right false
267
+ end
268
+ }
269
+
270
+ # whenever updated set colorlabel and messagelabel to reverse
271
+ @cb_rev.update_command(colorlabel,checkbutton1) {|tv, label, cb| attrs = cb.value ? 'reverse' : nil; label.attr(attrs); message_label.attr(attrs)}
272
+ row += 1
273
+ radio1 = RadioButton.new @form do
274
+ variable $radio
275
+ text "red"
276
+ value "red"
277
+ color "red"
278
+ display_length 18 # helps when right aligning
279
+ row row
280
+ col col
281
+ end
282
+ radio11 = RadioButton.new @form do
283
+ variable $radio
284
+ text "c&yan"
285
+ value "cyan"
286
+ color "cyan"
287
+ display_length 18 # helps when right aligning
288
+ row row
289
+ col col+24
290
+ end
291
+ row += 1
292
+ radio2 = RadioButton.new @form do
293
+ variable $radio
294
+ text "&green"
295
+ value "green"
296
+ color "green"
297
+ display_length 18 # helps when right aligning
298
+ row row
299
+ col col
300
+ end
301
+ radio22 = RadioButton.new @form do
302
+ variable $radio
303
+ text "magenta"
304
+ value "magenta"
305
+ color "magenta"
306
+ display_length 18 # helps when right aligning
307
+ row row
308
+ col col+24
309
+ end
310
+ colorlabel.label_for radio1
311
+ align.bind(:ENTER_ROW) {|fld|
312
+ if fld.getvalue == 'right'
313
+ radio1.align_right true
314
+ radio2.align_right true
315
+ radio11.align_right true
316
+ radio22.align_right true
317
+ else
318
+ radio1.align_right false
319
+ radio2.align_right false
320
+ radio11.align_right false
321
+ radio22.align_right false
322
+ end
323
+ }
324
+
325
+ @mb = RubyCurses::MenuBar.new
326
+ filemenu = RubyCurses::Menu.new "File"
327
+ filemenu.add(item = RubyCurses::MenuItem.new("Open",'O'))
328
+ item.command(@form) {|it, form| $message.value = "Open called on menu bar";
329
+ fchooser = QDFileChooser.new
330
+ option = fchooser.show_open_dialog
331
+ $message.value = "File Selection #{option}, #{fchooser.get_selected_file}"
332
+ if option == :OK
333
+ filesel = fchooser.get_selected_file
334
+ if !filesel.nil?
335
+ texta.remove_all
336
+ content = File.open(filesel,"r").readlines
337
+ content.each do |line|
338
+ texta << line
339
+ end
340
+ end
341
+ end
342
+ }
343
+
344
+ filemenu.insert_separator 1
345
+ filemenu.add(RubyCurses::MenuItem.new "New",'N')
346
+ filemenu.add(item = RubyCurses::MenuItem.new("Save",'S'))
347
+ item.command() do |it|
348
+ filename = get_string("Please enter file to save in", 20, "t.t")
349
+ $message.value = "file: #{filename}"
350
+ filename ||= "tmpzzzz.tmp"
351
+ str = texta.to_s
352
+ File.open(filename, 'w') {|f| f.write(str) }
353
+ $message.value = " written #{str.length} bytes to file: #{filename}"
354
+ end
355
+ filemenu.add(item = RubyCurses::MenuItem.new("Test",'T'))
356
+ item.command(@form, texta) do |it, form, testa|
357
+ $message.value = "Testing textarea"
358
+ str = "Hello there good friends and fellow rubyists. Here is a textarea that I am testing out with"
359
+ str << " some long data, to see how it acts, how the wrapping takes place. Sit back and enjoy the "
360
+ str << " bugs as they crop up."
361
+ testa.goto_start
362
+ #testa.cursor_bol
363
+ testa.handle_key ?\C-a # bol
364
+ str.each_char {|c| testa.putch(c)}
365
+ testa.repaint
366
+ testa.handle_key KEY_DOWN # down
367
+ testa.handle_key KEY_DOWN # down
368
+ testa.handle_key KEY_DOWN # down
369
+ testa.handle_key ?\C-a # bol
370
+ #testa.cursor_bol
371
+ str.each_char {|c| testa.putch(c)}
372
+ $message.value = "Wrapping textarea"
373
+ testa.repaint
374
+ throw(:menubarclose)
375
+ end
376
+ filemenu.add(item = RubyCurses::MenuItem.new("Wrap",'W'))
377
+ item.command(@form, texta) do |it, form, testa|
378
+ #testa.goto_start
379
+ testa.handle_key ?\C-a # bol
380
+ testa.wrap_para
381
+ testa.repaint
382
+ throw(:menubarclose)
383
+ end
384
+ filemenu.add(item = RubyCurses::MenuItem.new("Exit",'X'))
385
+ item.command() {
386
+ #throw(:menubarclose);
387
+ throw(:close)
388
+ }
389
+ item = RubyCurses::CheckBoxMenuItem.new "Reverse"
390
+ # item.onvalue="On"
391
+ # item.offvalue="Off"
392
+ #item.checkbox.text "Labelcb"
393
+ #item.text="Labelcb"
394
+ # in next line, an explicit repaint is required since label is on another form.
395
+ item.command(colorlabel){|it, label| att = it.getvalue ? 'reverse' : nil; label.attr(att); label.repaint}
396
+
397
+ row += 2
398
+ ok_button = Button.new @form do
399
+ text "OK"
400
+ name "OK"
401
+ row row
402
+ col col
403
+ mnemonic 'O'
404
+ end
405
+ ok_button.command { |form|
406
+ alert("About to dump data into log file!")
407
+ form.dump_data; $message.value = "Dumped data to log file"
408
+ listb.list.insert 0, "hello ruby", "so long python", "farewell java", "RIP .Net"
409
+ }
410
+
411
+ # using ampersand to set mnemonic
412
+ cancel_button = Button.new @form do
413
+ #variable $results
414
+ text "&Cancel"
415
+ row row
416
+ col col + 10
417
+ #surround_chars ['{ ',' }'] ## change the surround chars
418
+ end
419
+ cancel_button.command { |form|
420
+ if confirm("Do your really want to quit?")== :YES
421
+ throw(:close);
422
+ else
423
+ $message.value = "Quit aborted"
424
+ end
425
+ }
426
+
427
+
428
+ filemenu.add(item)
429
+ @mb.add(filemenu)
430
+ editmenu = RubyCurses::Menu.new "Edit"
431
+ item = RubyCurses::MenuItem.new "Cut"
432
+ editmenu.add(item)
433
+ item.accelerator = "Ctrl-X"
434
+ item=RubyCurses::MenuItem.new "Copy"
435
+ editmenu.add(item)
436
+ item.accelerator = "Ctrl-C"
437
+ item=RubyCurses::MenuItem.new "Paste"
438
+ editmenu.add(item)
439
+ item.accelerator = "Ctrl-V"
440
+ @mb.add(editmenu)
441
+ @mb.add(menu=RubyCurses::Menu.new("Others"))
442
+ #item=RubyCurses::MenuItem.new "Save","S"
443
+ item = RubyCurses::MenuItem.new "Options"
444
+ item.command() do |it|
445
+ require 'testtabp'
446
+ tp = TestTabbedPane.new
447
+ tp.run
448
+ $message.value=$config_hash.inspect
449
+ $log.debug " returning with #{$config_hash}: #{$config_hash.inspect}"
450
+ end
451
+ menu.add(item)
452
+ item = RubyCurses::MenuItem.new "Config"
453
+ menu.add(item)
454
+ item = RubyCurses::MenuItem.new "Tables"
455
+ menu.add(item)
456
+ savemenu = RubyCurses::Menu.new "EditM"
457
+ item = RubyCurses::MenuItem.new "CutM"
458
+ savemenu.add(item)
459
+ item = RubyCurses::MenuItem.new "DeleteM"
460
+ savemenu.add(item)
461
+ item = RubyCurses::MenuItem.new "PasteM"
462
+ savemenu.add(item)
463
+ menu.add(savemenu)
464
+
465
+ savemenu2 = RubyCurses::Menu.new "EditM2"
466
+ item = RubyCurses::MenuItem.new "CutM2"
467
+ savemenu2.add(item)
468
+ item = RubyCurses::MenuItem.new "DeleteM2"
469
+ savemenu2.add(item)
470
+ item = RubyCurses::MenuItem.new "PasteM2"
471
+ savemenu2.add(item)
472
+ savemenu.add(savemenu2)
473
+ # 2008-12-20 13:06 no longer hardcoding toggle key of menu_bar.
474
+ @mb.toggle_key = KEY_F2
475
+ @form.set_menu_bar @mb
476
+ #@cell = CellRenderer.new "Hello", {"col" => 1, "row"=>29, "justify"=>:right, "display_length" => 30}
477
+ # END
478
+ @form.repaint
479
+ @window.wrefresh
480
+ Ncurses::Panel.update_panels
481
+ while((ch = @window.getchar()) != KEY_F1 )
482
+ #@cell.repaint @form.window, 29,1, "ok #{ch} pressed!"
483
+ #@cell.repaint @form.window, 29,45, "#{ch} pressed!"
484
+ @form.handle_key(ch)
485
+ #@form.repaint
486
+ @window.wrefresh
487
+ end
488
+ end
489
+ rescue => ex
490
+ ensure
491
+ @window.destroy if !@window.nil?
492
+ VER::stop_ncurses
493
+ p ex if ex
494
+ p(ex.backtrace.join("\n")) if ex
495
+ $log.debug( ex) if ex
496
+ $log.debug(ex.backtrace.join("\n")) if ex
497
+ end
498
+ end
@@ -0,0 +1,95 @@
1
+ #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
2
+ require 'rubygems'
3
+ require 'ncurses'
4
+ require 'logger'
5
+ #require 'lib/rbcurse/mapper'
6
+ #require 'lib/rbcurse/keylabelprinter'
7
+ #require 'lib/rbcurse/commonio'
8
+ #require 'lib/rbcurse/rwidget'
9
+ #require 'lib/rbcurse/rform'
10
+ require 'rbcurse/rcombo'
11
+ if $0 == __FILE__
12
+ include RubyCurses
13
+
14
+ begin
15
+ # Initialize curses
16
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
17
+ $log = Logger.new("view.log")
18
+ $log.level = Logger::DEBUG
19
+
20
+ @window = VER::Window.root_window
21
+ # Initialize few color pairs
22
+ # Create the window to be associated with the form
23
+ # Un post form and free the memory
24
+
25
+ catch(:close) do
26
+ colors = Ncurses.COLORS
27
+ $log.debug "START #{colors} colors ---------"
28
+ @form = Form.new @window
29
+ r = 1; c = 30;
30
+ mylist = []
31
+ 0.upto(100) { |i| mylist << i.to_s }
32
+ combo = ComboBox.new @form do
33
+ name "combo"
34
+ row r
35
+ col c
36
+ bgcolor 'magenta'
37
+ display_length 10
38
+ editable false
39
+ list mylist
40
+ set_label Label.new @form, {'text' => "Non-edit Combo"}
41
+ list_config 'color' => 'yellow', 'bgcolor'=>'magenta', 'max_visible_items' => 6
42
+ end
43
+ r+=1
44
+ $results = Variable.new
45
+ $results.value = "Event:"
46
+ status = RubyCurses::Label.new @form, {'text_variable' => $results, "row" => 22, "col" => 2}
47
+ # since updated from another window, so explicit repaint required
48
+ $results.update_command { status.repaint }
49
+
50
+ v_positions = [:BELOW, :SAME, :CENTER, :CENTER, :ABOVE, :ABOVE]
51
+ #h_positions = [:SAME, :LEFT, :RIGHT, :SAME, :SAME, :ABOVE]
52
+ policies = [:NO_INSERT, :INSERT_AT_TOP, :INSERT_AT_BOTTOM,
53
+ :INSERT_AT_CURRENT, :INSERT_BEFORE_CURRENT, :INSERT_AFTER_CURRENT]
54
+ policies.each_with_index do |policy, ix|
55
+ name="combo#{r}"
56
+ list = ListDataModel.new( %w[spotty tiger secret pass torvalds qwerty quail toiletry])
57
+ list.bind(:LIST_DATA_EVENT, name) { |lde,n| $results.value = lde.to_s[0,70]; $log.debug " STA: #{$results} #{lde}" }
58
+ list.bind(:ENTER_ROW, name) { |obj,n| $results.value = "ENTER_ROW :#{obj.current_index} : #{obj.selected_item} "; $log.debug " ENTER_ROW: #{$results.value} , #{obj}" }
59
+ ComboBox.new @form do
60
+ name name
61
+ row r
62
+ col 30
63
+ display_length 10
64
+ bgcolor 'cyan'
65
+ editable true
66
+ #list %w[spotty tiger secret pass torvalds qwerty quail toiletry]
67
+ list_data_model list
68
+ insert_policy policy
69
+ set_label Label.new @form, {'text' => "Combo: "+policy.to_s}
70
+ list_config 'color' => 'white', 'bgcolor'=>'blue', 'valign' => v_positions[ix]
71
+ end
72
+ r+=2
73
+ end
74
+
75
+ @help = "Use UP and DOWN to navigate values, alt-DOWN for popup, TAB / BACKTAB between fields. F1-quit"
76
+ RubyCurses::Label.new @form, {'text' => @help, "row" => 21, "col" => 2, "color" => "yellow"}
77
+
78
+ @form.repaint
79
+ @window.wrefresh
80
+ Ncurses::Panel.update_panels
81
+ while((ch = @window.getchar()) != KEY_F1 )
82
+ @form.handle_key(ch)
83
+ @window.wrefresh
84
+ end
85
+ end
86
+ rescue => ex
87
+ ensure
88
+ @window.destroy if !@window.nil?
89
+ VER::stop_ncurses
90
+ p ex if ex
91
+ p(ex.backtrace.join("\n")) if ex
92
+ $log.debug( ex) if ex
93
+ $log.debug(ex.backtrace.join("\n")) if ex
94
+ end
95
+ end
@@ -0,0 +1,61 @@
1
+ #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
2
+ require 'rubygems'
3
+ require 'ncurses'
4
+ require 'logger'
5
+ #require 'lib/ver/keyboard'
6
+ require 'rbcurse'
7
+ require 'rbcurse/rtextarea'
8
+ if $0 == __FILE__
9
+ include RubyCurses
10
+ include RubyCurses::Utils
11
+
12
+ begin
13
+ # Initialize curses
14
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
15
+ $log = Logger.new("view.log")
16
+ $log.level = Logger::DEBUG
17
+
18
+ @window = VER::Window.root_window
19
+
20
+ catch(:close) do
21
+ colors = Ncurses.COLORS
22
+ $log.debug "START #{colors} colors ---------"
23
+ @form = Form.new @window
24
+ r = 1; c = 30;
25
+
26
+ texta = TextArea.new @form do
27
+ name "mytext"
28
+ row r
29
+ col c
30
+ width 60
31
+ height 15
32
+ editable false
33
+ focusable false
34
+ title "Keypresses"
35
+ auto_scroll true
36
+ title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
37
+ end
38
+ @help = "q to quit. Use any key of key combination to see what's caught. Check logger too"
39
+ RubyCurses::Label.new @form, {'text' => @help, "row" => 21, "col" => 2, "color" => "yellow"}
40
+
41
+ @form.repaint
42
+ @window.wrefresh
43
+ Ncurses::Panel.update_panels
44
+ while((ch = @window.getchar()) != ?q )
45
+ str = keycode_tos ch
46
+ texta << "#{ch} got (#{str})"
47
+ texta.repaint
48
+ @form.handle_key(ch)
49
+ @window.wrefresh
50
+ end
51
+ end
52
+ rescue => ex
53
+ ensure
54
+ @window.destroy if !@window.nil?
55
+ VER::stop_ncurses
56
+ p ex if ex
57
+ p(ex.backtrace.join("\n")) if ex
58
+ $log.debug( ex) if ex
59
+ $log.debug(ex.backtrace.join("\n")) if ex
60
+ end
61
+ end