rbcurse 1.4.0 → 1.4.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/NOTES +68 -0
  2. data/README.markdown +73 -330
  3. data/TODO2.txt +2 -2
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +8 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +1 -24
  8. data/examples/appdirtree.rb +1 -1
  9. data/examples/appemail.rb +8 -14
  10. data/examples/appemaillb.rb +2 -2
  11. data/examples/appgcompose.rb +7 -5
  12. data/examples/common/file.rb +40 -0
  13. data/examples/{rmail.rb → common/rmail.rb} +0 -0
  14. data/examples/data/README.markdown +9 -0
  15. data/examples/data/brew.txt +38 -0
  16. data/examples/data/color.2 +37 -0
  17. data/examples/data/gemlist.txt +60 -0
  18. data/examples/data/lotr.txt +12 -0
  19. data/examples/data/ports.txt +136 -0
  20. data/examples/data/tasks.txt +27 -0
  21. data/examples/{todocsv.csv → data/todocsv.csv} +0 -0
  22. data/examples/data/unix1.txt +21 -0
  23. data/examples/data/unix2.txt +11 -0
  24. data/examples/dbdemo.rb +49 -14
  25. data/examples/{appgmail.rb → deprecated/appgmail.rb} +1 -1
  26. data/examples/{splitp.rb → deprecated/splitp.rb} +0 -0
  27. data/examples/{testscrolllb.rb → deprecated/testscrolllb.rb} +0 -0
  28. data/examples/{testscrollp.rb → deprecated/testscrollp.rb} +0 -0
  29. data/examples/{testscrollta.rb → deprecated/testscrollta.rb} +0 -0
  30. data/examples/{testscrolltable.rb → deprecated/testscrolltable.rb} +0 -0
  31. data/examples/{testsplit.rb → deprecated/testsplit.rb} +0 -0
  32. data/examples/{testsplit2.rb → deprecated/testsplit2.rb} +0 -0
  33. data/examples/{testsplit3.rb → deprecated/testsplit3.rb} +0 -0
  34. data/examples/{testsplit3_1.rb → deprecated/testsplit3_1.rb} +0 -0
  35. data/examples/{testsplit3a.rb → deprecated/testsplit3a.rb} +0 -0
  36. data/examples/{testsplit3b.rb → deprecated/testsplit3b.rb} +0 -0
  37. data/examples/{testsplitta.rb → deprecated/testsplitta.rb} +0 -0
  38. data/examples/{testsplittv.rb → deprecated/testsplittv.rb} +0 -0
  39. data/examples/{testsplittvv.rb → deprecated/testsplittvv.rb} +0 -0
  40. data/examples/{testtpane.rb → deprecated/testtpane.rb} +0 -0
  41. data/examples/{testtpane2.rb → deprecated/testtpane2.rb} +0 -0
  42. data/examples/{testtpanetable.rb → deprecated/testtpanetable.rb} +0 -0
  43. data/examples/dirtree.rb +17 -7
  44. data/examples/experimental/resultsetdemo.rb +280 -0
  45. data/examples/experimental/testmform.rb +35 -0
  46. data/examples/{testscroller.rb → experimental/testscroller.rb} +1 -19
  47. data/examples/experimental/teststackflow.rb +111 -0
  48. data/examples/menu1.rb +1 -0
  49. data/examples/multispl.rb +4 -4
  50. data/examples/newmessagebox.rb +130 -0
  51. data/examples/newtabbedwindow.rb +100 -0
  52. data/examples/newtesttabp.rb +0 -3
  53. data/examples/qdfilechooser.rb +0 -3
  54. data/examples/rfe.rb +134 -18
  55. data/examples/rfe_renderer.rb +48 -2
  56. data/examples/sqlc.rb +2 -1
  57. data/examples/sqlm.rb +0 -2
  58. data/examples/table1.rb +1 -7
  59. data/examples/term2.rb +4 -1
  60. data/examples/test1.rb +0 -5
  61. data/examples/test2.rb +42 -31
  62. data/examples/testapp2.rb +8 -1
  63. data/examples/testchars.rb +0 -4
  64. data/examples/testcombo.rb +5 -9
  65. data/examples/testkeypress.rb +0 -3
  66. data/examples/testmenu.rb +0 -4
  67. data/examples/testmulticomp.rb +3 -5
  68. data/examples/testmulticontainer.rb +94 -0
  69. data/examples/testtable.rb +0 -5
  70. data/examples/testtabp.rb +16 -18
  71. data/examples/testtodo.rb +1 -5
  72. data/examples/testwsshortcuts.rb +64 -0
  73. data/examples/testwsshortcuts2.rb +126 -0
  74. data/examples/viewtodo.rb +1 -4
  75. data/lib/rbcurse.rb +1 -1
  76. data/lib/rbcurse/app.rb +92 -69
  77. data/lib/rbcurse/applicationheader.rb +46 -6
  78. data/lib/rbcurse/celleditor.rb +1 -9
  79. data/lib/rbcurse/comboboxcellrenderer.rb +0 -4
  80. data/lib/rbcurse/common/ansiparser.rb +117 -0
  81. data/{examples → lib/rbcurse/common}/appmethods.rb +25 -0
  82. data/lib/rbcurse/common/basestack.rb +407 -0
  83. data/lib/rbcurse/common/bordertitle.rb +41 -0
  84. data/lib/rbcurse/common/chunk.rb +177 -0
  85. data/lib/rbcurse/common/colorparser.rb +71 -0
  86. data/lib/rbcurse/common/keydefs.rb +30 -0
  87. data/lib/rbcurse/common/widgetshortcuts.rb +302 -0
  88. data/lib/rbcurse/deprecated/README.markdown +12 -0
  89. data/lib/rbcurse/{rscrollpane.rb → deprecated/rscrollpane.rb} +0 -0
  90. data/lib/rbcurse/{rsplitpane.rb → deprecated/rsplitpane.rb} +0 -0
  91. data/lib/rbcurse/{rsplitpane2.rb → deprecated/rsplitpane2.rb} +0 -0
  92. data/lib/rbcurse/{rviewport.rb → deprecated/rviewport.rb} +0 -0
  93. data/lib/rbcurse/experimental/README.markdown +14 -0
  94. data/lib/rbcurse/experimental/resultsettextview.rb +585 -0
  95. data/lib/rbcurse/experimental/stackflow.rb +478 -0
  96. data/lib/rbcurse/extras/bottomline.rb +85 -16
  97. data/lib/rbcurse/extras/box.rb +58 -0
  98. data/lib/rbcurse/extras/directorylist.rb +1 -1
  99. data/lib/rbcurse/extras/horizlist.rb +203 -0
  100. data/lib/rbcurse/extras/listselectable.rb +8 -0
  101. data/lib/rbcurse/extras/multiform.rb +330 -0
  102. data/lib/rbcurse/extras/multilinelabel.rb +142 -0
  103. data/lib/rbcurse/extras/newmessagebox.rb +328 -0
  104. data/lib/rbcurse/extras/newtabbedpane.rb +612 -0
  105. data/lib/rbcurse/extras/newtabbedwindow.rb +68 -0
  106. data/lib/rbcurse/extras/padreader.rb +189 -0
  107. data/lib/rbcurse/extras/rcomboedit.rb +256 -0
  108. data/lib/rbcurse/extras/resultsetbrowser.rb +281 -0
  109. data/lib/rbcurse/extras/statusline.rb +44 -6
  110. data/lib/rbcurse/extras/tabularwidget.rb +141 -104
  111. data/lib/rbcurse/extras/textpad.rb +516 -0
  112. data/lib/rbcurse/extras/viewer.rb +2 -0
  113. data/lib/rbcurse/io.rb +120 -3
  114. data/lib/rbcurse/listcellrenderer.rb +2 -1
  115. data/lib/rbcurse/listkeys.rb +1 -1
  116. data/lib/rbcurse/listscrollable.rb +72 -7
  117. data/lib/rbcurse/rbasiclistbox.rb +64 -12
  118. data/lib/rbcurse/rchangeevent.rb +0 -1
  119. data/lib/rbcurse/rcombo.rb +54 -59
  120. data/lib/rbcurse/rcommandwindow.rb +46 -10
  121. data/lib/rbcurse/rcontainer.rb +415 -0
  122. data/lib/rbcurse/rdialogs.rb +242 -165
  123. data/lib/rbcurse/rinputdataevent.rb +0 -1
  124. data/lib/rbcurse/rlistbox.rb +19 -9
  125. data/lib/rbcurse/rmessagebox.rb +1 -5
  126. data/lib/rbcurse/rmulticontainer.rb +64 -61
  127. data/lib/rbcurse/rmultitextview.rb +0 -2
  128. data/lib/rbcurse/rpopupmenu.rb +0 -2
  129. data/lib/rbcurse/rscrollform.rb +61 -12
  130. data/lib/rbcurse/rtabbedpane.rb +89 -73
  131. data/lib/rbcurse/rtabbedwindow.rb +53 -211
  132. data/lib/rbcurse/rtable.rb +0 -2
  133. data/lib/rbcurse/rtextarea.rb +14 -14
  134. data/lib/rbcurse/rtextview.rb +165 -50
  135. data/lib/rbcurse/rvimsplit.rb +15 -12
  136. data/lib/rbcurse/rwidget.rb +404 -150
  137. data/lib/rbcurse/table/tablecellrenderer.rb +1 -4
  138. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -3
  139. data/lib/ver/ncurses.rb +1 -9
  140. data/lib/ver/rpad.rb +375 -0
  141. data/lib/ver/window.rb +262 -440
  142. metadata +73 -31
@@ -3,9 +3,10 @@
3
3
  * Description:
4
4
  * A tabbed pane, mostly based (iirc) on the Terminal Preferences in OSX PPC 10.5.x
5
5
  * Starting a new version using pads 2009-10-25 12:05
6
- TODO - need to rewrite this pronto. 1.3.1 or 1.3.2 should have a rewritten TabbedPane
7
- NOTE: PLEASE AVOID THIS. USE MULTI_CONTAINERS if you need inside a form.
8
- TABBEDWINDOW IS OKAY IF YOU ARE POPPING A TABBEDPANE UP.
6
+
7
+ 2011-10-18 : removed ScrollForm since it would not print if window was not at 0,0 top left.
8
+
9
+
9
10
  * Author: rkumar
10
11
 
11
12
  --------
@@ -24,11 +25,12 @@ NOTE:
24
25
  #
25
26
  # TODO : disable/hide tab ???
26
27
  =end
27
- require 'logger'
28
28
  require 'rbcurse'
29
+ require 'ver/rpad'
30
+ #require 'rbcurse/rscrollform' # tried, shows in all cases teh buttons but never gets control
29
31
 
30
- KEY_TAB = 9
31
- KEY_BTAB = 353
32
+ KEY_TAB ||= 9
33
+ KEY_BTAB ||= 353
32
34
  #include Ncurses # FFI 2011-09-8
33
35
  include RubyCurses
34
36
  module RubyCurses
@@ -49,20 +51,21 @@ module RubyCurses
49
51
  # highlight abd selected colors and attribs should perhaps be in a
50
52
  # structure, so user can override easily
51
53
  def repaint # tabbedbutton
52
- $log.debug("TabbedBUTTon repaint : #{self.class()} r:#{@row} c:#{@col} #{getvalue_for_paint}" )
54
+ $log.debug("TabbedBUTTon repaint : #{self.class()} fn:#{@form.name} r:#{@row} c:#{@col} #{getvalue_for_paint} gt #{@form.window.top} gl #{@form.window.left}" )
53
55
  r,c = rowcol
54
56
  attribs = @attrs
55
57
  @highlight_foreground ||= $reversecolor
56
58
  @highlight_background ||= $reversecolor # 0
57
59
  _state = @state
58
60
  _state = :SELECTED if @variable.value == @value
61
+ color = $datacolor
59
62
  case _state
60
63
  when :HIGHLIGHTED
61
64
  $log.debug("TabbedBUTTon repaint : HIGHLIGHTED #{bgcolor}, #{color}, v: #{@value}" )
62
65
  bgcolor = @highlight_background
63
66
  color = @highlight_foreground
64
67
  bgcolor = @bgcolor
65
- color = "red" #@color
68
+ color = :red #@color
66
69
  attribs = Ncurses::A_BOLD
67
70
  setrowcol r,c # show cursor on highlighted as we tab through
68
71
  ## but when tabbing thru selected one, then selected one doesn't show cursor
@@ -92,20 +95,26 @@ module RubyCurses
92
95
  #@graphic.printstring r+@graphic.top, c+@graphic.left, "%-*s" % [len, value], color, attribs
93
96
  #@graphic.printstring r-@graphic.top, c-@graphic.left, "%-*s" % [len, value], color, attribs
94
97
 
95
- # add bar character on sides of selected 2011-10-5
96
- # mvwaddch was not doing anything ??
98
+ ro = @graphic.top
99
+ co = @graphic.left
100
+ ro = 0
101
+ co = 0
102
+ # NOTE after removing scrollform I've replaced check of graphic with 0, Note if we revert
97
103
  if _state == :HIGHLIGHTED
98
- @graphic.printstring r, c-1, ">", color, @attrs unless c-1 < @graphic.left
104
+ color = $datacolor
105
+ @graphic.printstring r+ro, c-1+co, ">", color, @attrs unless c-1 < 0 #@graphic.left
99
106
  #@graphic.printstring r, c+len+1, "<", color, @attrs
100
107
  else
101
- @graphic.printstring r, c-1, " ", color, @attrs unless c-1 < @graphic.left
108
+ color = $datacolor
109
+ @graphic.printstring r+ro, c-1+co, " ", color, @attrs unless c-1 < 0 #@graphic.left
102
110
  #@graphic.printstring r, c+len+1, " ", color, @attrs
103
111
  end
104
- @graphic.printstring r, c, "%-*s" % [len, value], color, attribs
112
+ @graphic.printstring r+ro, c+co, "%-*s" % [len, value], color, attribs
105
113
  @graphic.modified = true
106
114
  # @form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, bgcolor, nil)
107
115
  # underline for the top tab buttons.
108
116
  if @underline != nil
117
+ # 2011-10-17 cmmented
109
118
  r -= @graphic.top # because of pad, remove if we go back to windows
110
119
  c -= @graphic.left # because of pad, remove if we go back to windows
111
120
  @graphic.mvchgat(y=r, x=c+@underline+0, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, color, nil)
@@ -166,10 +175,15 @@ module RubyCurses
166
175
  # set to true if you want tabs to show as you traverse the tab buttons
167
176
  dsl_accessor :display_tab_on_traversal
168
177
 
178
+ # creates a scrollable form so many buttons can be placed
179
+ # NOTE: this only works in a root window, I can't figure out why.
180
+ dsl_accessor :scrolling_allowed
181
+
169
182
  attr_reader :selected_index
170
183
  attr_reader :current_tab
171
184
  attr_reader :window
172
185
  def initialize form, aconfig={}, &block
186
+ @scrolling_allowed = false
173
187
  super
174
188
  @parent = form
175
189
  @parentwin = form.window
@@ -409,19 +423,22 @@ module RubyCurses
409
423
  # button_gap = 1 if @tabs.size > 6 # quick dirty fix, we need something that checks fit
410
424
  # we may also need to truncate text to fit
411
425
 
412
- @buttonpad.wclear
426
+ @buttonpad.wclear if @buttonpad # 2011-10-18
413
427
  ## create a button for each tab
414
428
  $tabradio = Variable.new # so we know which is highlighted
429
+ # 2011-10-17 seems objects on this form do not get windows offset
430
+ wco = @window.left
431
+ wro = @window.top
415
432
  @tabs.each do |tab|
416
433
  text = tab.text
417
- $log.debug " TABS EACH #{text} "
434
+ $log.debug " TABS EACH #{text}, #{wro} #{wco} "
418
435
  @buttons << RubyCurses::TabbedButton.new(@form) do
419
436
  variable $tabradio
420
437
  text text
421
438
  name text
422
439
  value text
423
- row r + 1
424
- col col
440
+ row r + 1 #+ wro
441
+ col col #+ wco
425
442
  end
426
443
  col += text.length + button_gap
427
444
  # if col exceeds pad_w then we need to expand pad
@@ -472,11 +489,31 @@ module RubyCurses
472
489
 
473
490
  r = @row
474
491
  c = @col
475
- @form = ScrollForm.new(@parentwin)
476
- @form.set_layout(1, @width, @row+1, @col+1)
477
- @form.display_h = 1
478
- @form.display_w = @width-3
479
- @buttonpad = @form.create_pad
492
+ # NOTE: I had to remove ScrollForm since it would not work if
493
+ # window was not root window. This means I cannot have more buttons
494
+ # than fit on screen.
495
+
496
+
497
+ # tried out proper ScrollForm, it shows the buttons but does not take
498
+ # cursor there or show cursor there at all.
499
+
500
+ scrolling = @scrolling_allowed
501
+ if scrolling
502
+ @form = ScrollForm.new(@parentwin)
503
+ # 2011-10-18 trying to see why buttons won't print if window is not 0,0
504
+ #@form.parent_form = @parent # 2011-10-18 trying out why buttons not coming at correct place
505
+ #@form.add_cols = @parent.window.left
506
+ #@form.add_rows = @parent.window.top
507
+ offset = 1
508
+ @form.set_layout(1, @width, @row+offset, @col+offset)
509
+ @form.display_h = 1
510
+ @form.display_w = @width-3
511
+ @buttonpad = @form.create_pad
512
+ @buttonpad.name = "Window::TPTOPPAD" # 2010-02-02 20:01
513
+
514
+ else
515
+ @form = Form.new(@parentwin)
516
+ end
480
517
 
481
518
 
482
519
  ## We will use the parent window, and not a pad. We will write absolute coordinates.
@@ -484,7 +521,6 @@ module RubyCurses
484
521
  color = $datacolor
485
522
  # border around button bar. should this not be in scrollform as a border ? XXX
486
523
  @window.print_border @row, @col, 2, @width, color #, Ncurses::A_REVERSE
487
- @buttonpad.name = "Window::TPTOPPAD" # 2010-02-02 20:01
488
524
  @form.name = "Form::TPTOPFORM"
489
525
  $log.debug("TP WINDOW TOP ? PAD MAIN FORM W:#{@window.name}, F:#{@form.name} ")
490
526
  @form.parent_form = @parent ## 2010-01-21 15:55 TRYING OUT BUFFERED
@@ -512,36 +548,8 @@ module RubyCurses
512
548
  @form.select_field 0
513
549
  end
514
550
  end
515
- def _on_enter
516
- # if BTAB the last comp
517
- if $current_key == KEY_BTAB
518
- # FIXME last is not focusable, then ??
519
- current_component = @buttons.last
520
- @current_tab = @form
521
- @old_tab = @tabs.last
522
- #@form.select_last_field
523
- else
524
- current_component = @buttons.first
525
- @current_tab = @form
526
- @old_tab = @tabs.first
527
- #@form.select_first_field
528
- end
529
- #set_form_row
530
- current_component.on_enter
531
- $log.debug " TP came to on_enter #{current_component}, #{current_component.state} "
532
- current_component.set_form_col # XXX
533
- current_component.repaint
534
- end
535
551
  def button_form_repaint flag = true
536
552
  $log.debug " INSIDE button_form_repaint #{flag} "
537
- #if flag
538
- #@form.repaint if flag # This paints the outer form not inner
539
- #@buttonpad.mvwaddch(2, 0, Ncurses::ACS_LTEE) # beautify the corner 2010-02-06 19:35
540
- #@buttonpad.mvwaddch(2, @width-1, Ncurses::ACS_RTEE)
541
- #end
542
- #ret = @buttonpad.prefresh(0,0, @row+0, @col+0, @row+@height, @col+@width)
543
- #$log.debug " prefresh error buttonpad 2 " if ret < 0
544
- #@buttonpad.modified = false
545
553
  if flag
546
554
  # repaint form and refresh pad
547
555
  @form.repaint
@@ -551,37 +559,39 @@ module RubyCurses
551
559
  @form.prefresh
552
560
  end
553
561
  end
562
+
554
563
  ##
555
564
  # This creates a form for the tab, in case we wish to put many components in it.
556
565
  # Else just pass single components in add_tab.
557
566
  # @params tab tab just created for which a form is required
558
567
  # @return form - a pad based form
559
568
  def create_tab_form tab
560
- mtop = 0
561
- mleft = 0
562
- bottom_offset = 2 # 0 will overwrite bottom line, 1 will make another line for inner form
569
+
570
+ mtop = 0
571
+ mleft = 0
572
+ bottom_offset = 2 # 0 will overwrite bottom line, 1 will make another line for inner form
563
573
  layout = { :height => @height-(mtop+bottom_offset), :width => @width, :top => mtop, :left => mleft }
564
- # create a pad but it must behave like a window at all times 2009-10-25 12:25
565
574
  window = VER::Pad.create_with_layout(layout)
566
575
 
567
576
  form = RubyCurses::Form.new window
568
- $log.debug " pad created in TP create_tab_form: #{window.name} , form #{form.name} "
569
- $log.debug " hwtl: #{layout[:height]} #{layout[:width]} #{layout[:top]} #{layout[:left]} "
570
- ## added 2010-01-21 15:46 to pass cursor up
577
+
571
578
  form.parent_form = @parent
579
+ form.add_cols = @col + 0
580
+ form.add_rows = @row + 2
581
+
582
+
572
583
  form.navigation_policy = :NON_CYCLICAL
573
584
  window.bkgd(Ncurses.COLOR_PAIR($datacolor));
574
- window.box( 0, 0);
585
+ window.box(0, 0);
575
586
  window.mvwaddch(0, 0, Ncurses::ACS_LTEE) # beautify the corner 2010-02-06 19:35
576
587
  window.mvwaddch(0, @width-1, Ncurses::ACS_RTEE)
588
+ window.mvwaddch(layout[:height]-1, 0, Ncurses::ACS_LTEE) # beautify the corner 2010-02-06 19:35
589
+ window.mvwaddch(layout[:height]-1, @width-1, Ncurses::ACS_RTEE)
577
590
 
578
- # XXX TODO this wastes space we should ditch it.
579
591
  ## this prints the tab name on top left
580
592
  window.mvprintw(1,1, tab.text.tr('&', '')) if @print_subheader
581
- window.name = "Tab::TAB-#{tab.text}" # 2010-02-02 19:59
582
- form.name = "Form::TAB-#{tab.text}" # 2010-02-02 19:59
583
- form.add_cols=@col + 0
584
- form.add_rows=@row + 2 # 2011-10-3 position cursor correctly
593
+ window.name = "Tab::TAB-#{tab.text}"
594
+ form.name = "Form::TAB-#{tab.text}"
585
595
  return form
586
596
  end
587
597
  ##
@@ -699,7 +709,7 @@ module RubyCurses
699
709
 
700
710
  return ret if ret == :UNHANDLED
701
711
  end
702
- if @buttonpad.modified
712
+ if @buttonpad && @buttonpad.modified
703
713
  button_form_repaint
704
714
  end
705
715
  end
@@ -728,10 +738,11 @@ module RubyCurses
728
738
  end
729
739
  end
730
740
  def make_buttons names
741
+ $log.debug "XXX: came to TP make lower buttons FORM #{@form.name} "
731
742
  total = names.inject(0) {|total, item| total + item.length + 4}
732
743
  bcol = center_column total
733
744
 
734
- brow = @layout[:height]-2
745
+ brow = @layout[:height]-2 # check for < 0
735
746
  button_ct=0
736
747
  names.each_with_index do |bname, ix|
737
748
  text = bname
@@ -754,7 +765,7 @@ module RubyCurses
754
765
  end
755
766
  end
756
767
  def center_column textlen
757
- width = @layout[:width]
768
+ width = @layout[:width] # check for 0 XXX
758
769
  return (width-textlen)/2
759
770
  end
760
771
  def fire_event tab, index, event
@@ -943,23 +954,28 @@ module RubyCurses
943
954
  @scroll_ctr = 2
944
955
  @cols_panned = @rows_panned = 0
945
956
  end
957
+
946
958
  def set_layout(h, w, t, l)
947
959
  @pad_h = h
948
960
  @pad_w = w
949
- @top = @orig_top = t
950
- @left = @orig_left = l
961
+ @top = t
962
+ @left = l
963
+ @top += @target_window.top
964
+ @left += @target_window.left
965
+ @orig_top = @top
966
+ @orig_left = @left
951
967
  end
952
968
  def create_pad
953
969
  r = @top
954
970
  c = @left
955
971
  layout = { :height => @pad_h, :width => @pad_w, :top => r, :left => c }
956
972
  @window = VER::Pad.create_with_layout(layout)
957
- #@window = @parentwin
958
- #@form = RubyCurses::Form.new @buttonpad
959
- @window.name = "Pad::ScrollPad" # 2010-02-02 20:01
960
- @name = "Form::ScrollForm"
973
+
974
+ @window.name = "Pad::ScrollPad"
975
+ @name = "Form::ScrollForm"
961
976
  return @window
962
977
  end
978
+
963
979
  ## ScrollForm handle key, scrolling
964
980
  def handle_key ch
965
981
  #alert("SCROLLFORM #{ch} , ai: #{@active_index} , #{get_current_field.name} ")
@@ -1,25 +1,23 @@
1
1
  =begin
2
2
  * Name: tabbed pane: can have multiple forms overlapping.
3
- * Description: This is the old program that uses multiple windows.
4
- * This cannot be embedded inside a form, but can be used as a popup.
5
- * Avoid using this, move to the widget TabbedPane which can be embedded inside a form.
3
+ * Description: This embeds a tabbedpane inside a window - a retake on tabbedwindow
6
4
  * Author: rkumar
7
5
 
6
+ * Consists of a main window and form that contains the TabbedPane and several buttons
7
+ below.
8
+ The tabbedpane itself contains a Form for the buttons, and then one form and Pad
9
+ each for the tab. Check TabbedPane for details since it can change.
8
10
 
9
- *** rtabbedpane renamed to rtabbedwindow 2009-11-02 13:04
10
-
11
11
  --------
12
- * Date: 2008-12-13 13:06
12
+ * Date: 2011-10-17 3:38 PM
13
13
  * License:
14
14
  Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
15
15
 
16
16
  =end
17
- require 'rubygems'
18
- #require 'ncurses'
19
17
  require 'logger'
20
18
  require 'rbcurse'
19
+ require 'rbcurse/rtabbedpane'
21
20
 
22
- #include Ncurses # FFI 2011-09-8
23
21
  include RubyCurses
24
22
  module RubyCurses
25
23
  extend self
@@ -27,53 +25,6 @@ module RubyCurses
27
25
  # TODO : insert_tab, remove_tab, disable/hide tab
28
26
  # Hotkeys should be defined with ampersand, too.
29
27
  #
30
- # Multiple independent overlapping forms using the tabbed metaphor.
31
- class TabbedButton < RubyCurses::RadioButton
32
- def getvalue_for_paint
33
- @text
34
- end
35
- ##
36
- # highlight abd selected colors and attribs should perhaps be in a
37
- # structure, so user can override easily
38
- def repaint # tabbedbutton
39
- # $log.debug("BUTTon repaint : #{self.class()} r:#{@row} c:#{@col} #{getvalue_for_paint}" )
40
- r,c = rowcol
41
- attribs = @attrs
42
- @highlight_foreground ||= $reversecolor
43
- @highlight_background ||= 0
44
- _state = @state
45
- _state = :SELECTED if @variable.value == @value
46
- case _state
47
- when :HIGHLIGHTED
48
- bgcolor = @highlight_background
49
- color = @highlight_foreground
50
- bgcolor = @bgcolor
51
- color = @color
52
- attribs = Ncurses::A_BOLD
53
- when :SELECTED
54
- bgcolor = @bgcolor
55
- color = @color
56
- attribs = Ncurses::A_REVERSE
57
- else
58
- bgcolor = @bgcolor
59
- color = @color
60
- end
61
- #bgcolor = @state==:HIGHLIGHTED ? @highlight_background : @bgcolor
62
- #color = @state==:HIGHLIGHTED ? @highlight_foreground : @color
63
- if bgcolor.is_a? String and color.is_a? String
64
- color = ColorMap.get_color(color, bgcolor)
65
- end
66
- value = getvalue_for_paint
67
- # $log.debug("button repaint : r:#{r} c:#{c} col:#{color} bg #{bgcolor} v: #{value} ")
68
- len = @display_length || value.length
69
- @form.window.printstring r, c, "%-*s" % [len, value], color, attribs
70
- # @form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, bgcolor, nil)
71
- if @underline != nil
72
- # changed +1 to +0 on 2008-12-15 21:23 pls check.
73
- @form.window.mvchgat(y=r, x=c+@underline+0, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, color, nil)
74
- end
75
- end
76
- end
77
28
  class TabbedWindow
78
29
  include EventHandler
79
30
  dsl_accessor :row, :col
@@ -83,169 +34,79 @@ module RubyCurses
83
34
  attr_reader :selected_index
84
35
  def initialize win, aconfig={}, &block
85
36
  @parent = win
86
- @tabs ||= []
87
- @forms ||= []
88
37
  @bgcolor ||= "black" # 0
89
38
  @color ||= "white" # $datacolor
90
39
  @attr = nil
91
- @current_form = nil
92
- @current_tab = nil
40
+
93
41
  @config = aconfig
94
42
  @config.each_pair { |k,v| variable_set(k,v) }
95
43
  instance_eval &block if block_given?
44
+ @tp = nil
96
45
  end
97
- ##
98
- # when adding tabs, you may use ampersand in text to create hotkey
99
- def add_tab text, aconfig={}, &block
100
- #create a button here and block is taken care of in button's instance
101
- #or push this for later creation.
102
- @tabs << Tab.new(text, aconfig, &block)
103
- tab = @tabs.last
104
- @forms << create_tab_form(tab)
105
- tab.form = @forms.last
106
- return tab
107
- end
108
- # private
109
- def variable_set var, val
110
- var = "@#{var}"
111
- instance_variable_set(var, val)
112
- end
113
- # private
114
- def configure(*val , &block)
115
- case val.size
116
- when 1
117
- return @config[val[0]]
118
- when 2
119
- @config[val[0]] = val[1]
120
- variable_set(val[0], val[1])
46
+ def tabbed_pane
47
+ return @tp if @tp
48
+ @layout = { :height => @height, :width => @width, :top => @row, :left => @col }
49
+ #@layout = { :height => 0, :width => 0, :top => 0, :left => 0 }
50
+ @window = VER::Window.new(@layout)
51
+ @form = RubyCurses::Form.new @window
52
+ @form.name = "TWindow"
53
+ @form.navigation_policy = :CYCLICAL
54
+ h = @layout[:height] == 0 ? FFI::NCurses.LINES-2 : @layout[:height]-2
55
+ w = @layout[:width] == 0 ? FFI::NCurses.COLS : @layout[:width]-0
56
+ h -= 0
57
+ w -= 0
58
+ r = 0 # @row-0
59
+ c =0 # @col
60
+ @tp = RubyCurses::TabbedPane.new @form, :height => h, :width =>w, :row => r, :col => c
61
+ return @tp
62
+ end
63
+ #
64
+ # I am honestly not sure what block anyone is gonna pass to Tab
65
+ # I confess i may have been even more ignorant than I am today. We
66
+ # could use the block here, pass form here, if component not given especially
67
+ def add_tab text, component = nil, aconfig={}, &block
68
+ @tp ||= tabbed_pane
69
+ t = @tp.add_tab text, component, aconfig #, &block # NOTE, not passing block there
70
+ if block_given?
71
+ yield @tp.form(t)
121
72
  end
122
- instance_eval &block if block_given?
73
+ return t
123
74
  end
75
+ alias :tab :add_tab
76
+ alias :new_tab :add_tab
77
+ ##
124
78
  def repaint
125
- @window || create_window
126
- @window.show
127
79
  end
128
80
  def show
129
- repaint
130
- end
131
- def create_window
132
81
  # first create the main top window with the tab buttons on it.
133
- @layout = { :height => @height, :width => @width, :top => @row, :left => @col }
134
- @window = VER::Window.new(@layout)
135
- @form = RubyCurses::Form.new @window
136
- @form.navigation_policy = :NON_CYCLICAL
137
- @current_form = @form
138
82
  @window.bkgd(Ncurses.COLOR_PAIR($datacolor));
139
83
  @window.box( 0, 0);
140
84
  @window.wrefresh
141
85
  Ncurses::Panel.update_panels
142
- col = 1
143
- @buttons = []
144
- ## create a button for each tab
145
- $tabradio = Variable.new
146
- @tabs.each do |tab|
147
- text = tab.text
148
- @buttons << RubyCurses::TabbedButton.new(@form) do
149
- variable $tabradio
150
- text text
151
- name text
152
- value text
153
- row 1
154
- col col
155
- end
156
- col += text.length+4
157
- # @forms << create_tab_form(tab)
158
- # form = @forms.last
159
- form = tab.form
160
- form.window = @window if form.window.nil? ## XXX
161
- panel = form.window.panel
162
- @buttons.last.command { Ncurses::Panel.top_panel(panel.pointer)
163
- Ncurses::Panel.update_panels();
164
- Ncurses.doupdate();
165
- form.repaint
166
- @current_form = form
167
- @current_tab = form
168
- }
169
-
170
- end
171
86
  create_buttons
172
87
  @form.repaint
173
- end
174
- def display_form form
175
- panel = form.window.panel
176
- Ncurses::Panel.top_panel(panel.pointer)
177
- Ncurses::Panel.update_panels();
178
- Ncurses.doupdate();
179
- form.repaint
180
- end
181
- def create_tab_form tab
182
- layout = { :height => @height-2, :width => @width, :top => @row+2, :left => @col }
183
- window = VER::Window.new(layout)
184
- form = RubyCurses::Form.new window
185
- form.navigation_policy = :NON_CYCLICAL
186
- window.bkgd(Ncurses.COLOR_PAIR($datacolor));
187
- window.box( 0, 0);
188
- window.mvprintw(1,1, tab.text.tr('&', ''))
189
- ##window.wrefresh
190
- ##Ncurses::Panel.update_panels
191
- return form
88
+ #handle_keys
89
+ # need to convey button pressed
192
90
  end
193
91
  def handle_keys
194
92
  begin
195
- while (( ch=@window.getchar()) != 999)
196
- if ch == ?\C-q.getbyte(0)
197
- @selected_index = -1 # this signifies cancel by ?C-q
198
- @stop = true
199
- return
200
- end
201
- return if @stop
202
- @current_form ||= @form
203
- ret = @current_form.handle_key(ch)
204
- case ret
205
- when :NO_NEXT_FIELD
206
- if @current_form != @form
207
- @current_form = @form
208
- #@current_form.select_field -1
209
- @current_form.req_first_field
210
- #ret = @current_form.handle_key(ch)
211
- else
212
- if !@current_tab.nil?
213
- @current_form = @current_tab
214
- display_form @current_form
215
- @current_form.req_first_field
216
- #@current_form.select_field -1
217
- #ret = @current_form.handle_key(ch)
218
- end
93
+ while (( ch=@window.getchar()) != 999)
94
+ break if ch == ?\C-q.getbyte(0) || @stop
95
+ ret = @form.handle_key(ch)
96
+ if ret == :UNHANDLED
97
+ ret = @form.process_key ch, self # field
98
+ @form.repaint
219
99
  end
220
- when :NO_PREV_FIELD
221
- if @current_form != @form
222
- $log.debug " 1 no prev field - going to button "
223
- @current_form = @form
224
- @current_form.req_last_field
225
- else
226
- if !@current_tab.nil?
227
- @current_form = @current_tab
228
- display_form @current_form
229
- @current_form.req_last_field
230
- end
231
- end
232
- when :UNHANDLED
233
- $log.debug " unhandled in tabbed pane #{ch}"
234
- ret = @form.process_key ch, self # field
235
- @form.repaint
236
- #return :UNHANDLED if ret == :UNHANDLED
100
+ @window.wrefresh
101
+ break if @stop # 2011-10-21 somehow not coming out
237
102
  end
238
103
  return if @stop
239
- @current_form.window.wrefresh
240
- @window.refresh
241
- end
242
104
  ensure
243
105
  destroy
244
106
  end
245
107
  end
246
108
  def destroy
247
109
  @window.destroy
248
- @forms.each { |f| w = f.window; w.destroy unless w.nil? }
249
110
  end
250
111
  def create_buttons
251
112
  case @button_type.to_s.downcase
@@ -266,10 +127,13 @@ module RubyCurses
266
127
  end
267
128
  end
268
129
  def make_buttons names
130
+ $log.debug "XXX: came to TW make buttons FORM= #{@form.name} "
269
131
  total = names.inject(0) {|total, item| total + item.length + 4}
270
132
  bcol = center_column total
271
133
 
134
+ # this craps out when height is zero
272
135
  brow = @layout[:height]-2
136
+ brow = FFI::NCurses.LINES-2 if brow < 0
273
137
  button_ct=0
274
138
  names.each_with_index do |bname, ix|
275
139
  text = bname
@@ -292,32 +156,10 @@ module RubyCurses
292
156
  end
293
157
  end
294
158
  def center_column textlen
295
- width = @layout[:width]
159
+ width = @layout[:width].ifzero( FFI::NCurses.COLS )
296
160
  return (width-textlen)/2
297
161
  end
298
162
 
299
- ##
300
- # nested class tab
301
- class Tab
302
- attr_reader :text
303
- attr_reader :config
304
- attr_accessor :form
305
- def initialize text, aconfig={}, &block
306
- @text = text
307
- @config = aconfig
308
- @config.each_pair { |k,v| variable_set(k,v) }
309
- instance_eval &block if block_given?
310
- end
311
- # private
312
- def variable_set var, val
313
- var = "@#{var}"
314
- instance_variable_set(var, val)
315
- end
316
- def repaint
317
-
318
-
319
- end
320
- end
321
163
 
322
164
  end # class TabbedWindow
323
165