rbcurse 1.4.1 → 1.5.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/CHANGELOG +31 -0
  2. data/README.markdown +69 -11
  3. data/VERSION +1 -1
  4. data/lib/rbcurse.rb +5 -5
  5. metadata +10 -198
  6. data/Makefile +0 -21
  7. data/Manifest.txt +0 -91
  8. data/TODO +0 -372
  9. data/TODO2.txt +0 -118
  10. data/examples/README.txt +0 -67
  11. data/examples/abasiclist.rb +0 -33
  12. data/examples/alpmenu.rb +0 -42
  13. data/examples/app.rb +0 -859
  14. data/examples/app.sample +0 -10
  15. data/examples/appdirtree.rb +0 -75
  16. data/examples/appemail.rb +0 -191
  17. data/examples/appemaillb.rb +0 -308
  18. data/examples/appgcompose.rb +0 -315
  19. data/examples/atree.rb +0 -64
  20. data/examples/common/file.rb +0 -40
  21. data/examples/common/rmail.rb +0 -257
  22. data/examples/data.txt +0 -683
  23. data/examples/data/README.markdown +0 -9
  24. data/examples/data/brew.txt +0 -38
  25. data/examples/data/color.2 +0 -37
  26. data/examples/data/gemlist.txt +0 -60
  27. data/examples/data/lotr.txt +0 -12
  28. data/examples/data/ports.txt +0 -136
  29. data/examples/data/tasks.txt +0 -27
  30. data/examples/data/todocsv.csv +0 -28
  31. data/examples/data/unix1.txt +0 -21
  32. data/examples/data/unix2.txt +0 -11
  33. data/examples/dbdemo.rb +0 -495
  34. data/examples/deprecated/appgmail.rb +0 -952
  35. data/examples/deprecated/splitp.rb +0 -56
  36. data/examples/deprecated/testscrolllb.rb +0 -86
  37. data/examples/deprecated/testscrollp.rb +0 -88
  38. data/examples/deprecated/testscrollta.rb +0 -80
  39. data/examples/deprecated/testscrolltable.rb +0 -165
  40. data/examples/deprecated/testsplit.rb +0 -87
  41. data/examples/deprecated/testsplit2.rb +0 -123
  42. data/examples/deprecated/testsplit3.rb +0 -215
  43. data/examples/deprecated/testsplit3_1.rb +0 -244
  44. data/examples/deprecated/testsplit3a.rb +0 -215
  45. data/examples/deprecated/testsplit3b.rb +0 -237
  46. data/examples/deprecated/testsplitta.rb +0 -148
  47. data/examples/deprecated/testsplittv.rb +0 -142
  48. data/examples/deprecated/testsplittvv.rb +0 -144
  49. data/examples/deprecated/testtpane.rb +0 -215
  50. data/examples/deprecated/testtpane2.rb +0 -145
  51. data/examples/deprecated/testtpanetable.rb +0 -203
  52. data/examples/dirtree.rb +0 -88
  53. data/examples/experimental/resultsetdemo.rb +0 -280
  54. data/examples/experimental/testmform.rb +0 -35
  55. data/examples/experimental/testscroller.rb +0 -117
  56. data/examples/experimental/teststackflow.rb +0 -111
  57. data/examples/menu1.rb +0 -112
  58. data/examples/multispl.rb +0 -86
  59. data/examples/newmessagebox.rb +0 -130
  60. data/examples/newtabbedwindow.rb +0 -100
  61. data/examples/newtesttabp.rb +0 -121
  62. data/examples/qdfilechooser.rb +0 -68
  63. data/examples/rfe.rb +0 -1195
  64. data/examples/rfe_renderer.rb +0 -121
  65. data/examples/sqlc.rb +0 -454
  66. data/examples/sqlm.rb +0 -437
  67. data/examples/sqlt.rb +0 -408
  68. data/examples/status.txt +0 -68
  69. data/examples/table1.rb +0 -24
  70. data/examples/term2.rb +0 -84
  71. data/examples/test1.rb +0 -239
  72. data/examples/test2.rb +0 -674
  73. data/examples/testapp.rb +0 -44
  74. data/examples/testapp2.rb +0 -58
  75. data/examples/testchars.rb +0 -137
  76. data/examples/testcombo.rb +0 -91
  77. data/examples/testkeypress.rb +0 -66
  78. data/examples/testlistbox.rb +0 -113
  79. data/examples/testmenu.rb +0 -101
  80. data/examples/testmulticomp.rb +0 -70
  81. data/examples/testmulticontainer.rb +0 -94
  82. data/examples/testmultispl.rb +0 -199
  83. data/examples/testree.rb +0 -106
  84. data/examples/testtable.rb +0 -263
  85. data/examples/testtabp.rb +0 -107
  86. data/examples/testtodo.rb +0 -584
  87. data/examples/testvimsplit.rb +0 -112
  88. data/examples/testwsshortcuts.rb +0 -64
  89. data/examples/testwsshortcuts2.rb +0 -126
  90. data/examples/todo.db +0 -0
  91. data/examples/todo.yml +0 -191
  92. data/examples/viewtodo.rb +0 -574
  93. data/lib/rbcurse/action.rb +0 -40
  94. data/lib/rbcurse/app.rb +0 -1374
  95. data/lib/rbcurse/applicationheader.rb +0 -102
  96. data/lib/rbcurse/celleditor.rb +0 -112
  97. data/lib/rbcurse/checkboxcellrenderer.rb +0 -57
  98. data/lib/rbcurse/colormap.rb +0 -159
  99. data/lib/rbcurse/comboboxcellrenderer.rb +0 -30
  100. data/lib/rbcurse/common/ansiparser.rb +0 -117
  101. data/lib/rbcurse/common/appmethods.rb +0 -112
  102. data/lib/rbcurse/common/basestack.rb +0 -407
  103. data/lib/rbcurse/common/bordertitle.rb +0 -41
  104. data/lib/rbcurse/common/chunk.rb +0 -177
  105. data/lib/rbcurse/common/colorparser.rb +0 -71
  106. data/lib/rbcurse/common/keydefs.rb +0 -30
  107. data/lib/rbcurse/common/widgetshortcuts.rb +0 -302
  108. data/lib/rbcurse/defaultlistselectionmodel.rb +0 -79
  109. data/lib/rbcurse/deprecated/README.markdown +0 -12
  110. data/lib/rbcurse/deprecated/rscrollpane.rb +0 -512
  111. data/lib/rbcurse/deprecated/rsplitpane.rb +0 -894
  112. data/lib/rbcurse/deprecated/rsplitpane2.rb +0 -1009
  113. data/lib/rbcurse/deprecated/rviewport.rb +0 -204
  114. data/lib/rbcurse/experimental/README.markdown +0 -14
  115. data/lib/rbcurse/experimental/resultsettextview.rb +0 -585
  116. data/lib/rbcurse/experimental/stackflow.rb +0 -478
  117. data/lib/rbcurse/extras/bottomline.rb +0 -1850
  118. data/lib/rbcurse/extras/box.rb +0 -58
  119. data/lib/rbcurse/extras/directorylist.rb +0 -467
  120. data/lib/rbcurse/extras/directorytree.rb +0 -69
  121. data/lib/rbcurse/extras/divider.rb +0 -310
  122. data/lib/rbcurse/extras/focusmanager.rb +0 -31
  123. data/lib/rbcurse/extras/horizlist.rb +0 -203
  124. data/lib/rbcurse/extras/listselectable.rb +0 -264
  125. data/lib/rbcurse/extras/masterdetail.rb +0 -166
  126. data/lib/rbcurse/extras/menutree.rb +0 -63
  127. data/lib/rbcurse/extras/multiform.rb +0 -330
  128. data/lib/rbcurse/extras/multilinelabel.rb +0 -142
  129. data/lib/rbcurse/extras/newmessagebox.rb +0 -328
  130. data/lib/rbcurse/extras/newtabbedpane.rb +0 -612
  131. data/lib/rbcurse/extras/newtabbedwindow.rb +0 -68
  132. data/lib/rbcurse/extras/padreader.rb +0 -189
  133. data/lib/rbcurse/extras/rcomboedit.rb +0 -256
  134. data/lib/rbcurse/extras/resultsetbrowser.rb +0 -281
  135. data/lib/rbcurse/extras/rlink.rb +0 -27
  136. data/lib/rbcurse/extras/rmenulink.rb +0 -21
  137. data/lib/rbcurse/extras/scrollbar.rb +0 -143
  138. data/lib/rbcurse/extras/statusline.rb +0 -94
  139. data/lib/rbcurse/extras/stdscrwindow.rb +0 -309
  140. data/lib/rbcurse/extras/tableextended.rb +0 -40
  141. data/lib/rbcurse/extras/tabular.rb +0 -264
  142. data/lib/rbcurse/extras/tabularwidget.rb +0 -1150
  143. data/lib/rbcurse/extras/textpad.rb +0 -516
  144. data/lib/rbcurse/extras/viewer.rb +0 -136
  145. data/lib/rbcurse/io.rb +0 -850
  146. data/lib/rbcurse/keylabelprinter.rb +0 -178
  147. data/lib/rbcurse/listcellrenderer.rb +0 -140
  148. data/lib/rbcurse/listeditable.rb +0 -310
  149. data/lib/rbcurse/listkeys.rb +0 -37
  150. data/lib/rbcurse/listscrollable.rb +0 -564
  151. data/lib/rbcurse/listselectable.rb +0 -142
  152. data/lib/rbcurse/mapper.rb +0 -130
  153. data/lib/rbcurse/orderedhash.rb +0 -77
  154. data/lib/rbcurse/ractionevent.rb +0 -67
  155. data/lib/rbcurse/rbasiclistbox.rb +0 -768
  156. data/lib/rbcurse/rchangeevent.rb +0 -27
  157. data/lib/rbcurse/rcombo.rb +0 -238
  158. data/lib/rbcurse/rcommandwindow.rb +0 -587
  159. data/lib/rbcurse/rcontainer.rb +0 -415
  160. data/lib/rbcurse/rdialogs.rb +0 -451
  161. data/lib/rbcurse/rinputdataevent.rb +0 -47
  162. data/lib/rbcurse/rlistbox.rb +0 -1196
  163. data/lib/rbcurse/rmenu.rb +0 -939
  164. data/lib/rbcurse/rmessagebox.rb +0 -348
  165. data/lib/rbcurse/rmulticontainer.rb +0 -304
  166. data/lib/rbcurse/rmultisplit.rb +0 -722
  167. data/lib/rbcurse/rmultitextview.rb +0 -306
  168. data/lib/rbcurse/rpopupmenu.rb +0 -755
  169. data/lib/rbcurse/rprogress.rb +0 -118
  170. data/lib/rbcurse/rscrollform.rb +0 -418
  171. data/lib/rbcurse/rtabbedpane.rb +0 -1158
  172. data/lib/rbcurse/rtabbedwindow.rb +0 -167
  173. data/lib/rbcurse/rtable.rb +0 -1718
  174. data/lib/rbcurse/rtextarea.rb +0 -920
  175. data/lib/rbcurse/rtextview.rb +0 -761
  176. data/lib/rbcurse/rtree.rb +0 -780
  177. data/lib/rbcurse/rvimsplit.rb +0 -763
  178. data/lib/rbcurse/rwidget.rb +0 -2915
  179. data/lib/rbcurse/scrollable.rb +0 -301
  180. data/lib/rbcurse/table/tablecellrenderer.rb +0 -86
  181. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -98
  182. data/lib/rbcurse/tree/treecellrenderer.rb +0 -150
  183. data/lib/rbcurse/tree/treemodel.rb +0 -428
  184. data/lib/rbcurse/undomanager.rb +0 -188
  185. data/lib/rbcurse/vieditable.rb +0 -144
  186. data/lib/ver/keyboard.rb +0 -150
  187. data/lib/ver/keyboard2.rb +0 -170
  188. data/lib/ver/ncurses.rb +0 -218
  189. data/lib/ver/panel.rb +0 -162
  190. data/lib/ver/rpad.rb +0 -375
  191. data/lib/ver/window.rb +0 -882
  192. data/test/test_rbcurse.rb +0 -0
@@ -1,117 +0,0 @@
1
- # ----------------------------------------------------------------------------- #
2
- # File: colorparser.rb
3
- # Description: Default parse for our tmux format
4
- # The aim is to be able to specify parsers so different kinds
5
- # of formatting or documents can be used, such as ANSI formatted
6
- # manpages.
7
- # Author: rkumar http://github.com/rkumar/rbcurse/
8
- # Date: 07.11.11 - 13:17
9
- # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
10
- # Last update: use ,,L
11
- # ----------------------------------------------------------------------------- #
12
- # == TODO
13
- # - perhaps we can compile the regexp once and reuse
14
- #
15
-
16
- class AnsiParser
17
-
18
- # NOTE: Experimental and minimal
19
- # parses the formatted string and yields either an array of color, bgcolor and attrib
20
- # or the text. This will be called by convert_to_chunk.
21
- #
22
- # Currently, assumes colors and attributes are correct. No error checking or fancy stuff.
23
- # s="#[fg=green]hello there#[fg=yellow, bg=black, dim]"
24
- # @since 1.4.1 2011-11-3 experimental, can change
25
- # @return [nil] knows nothign about output format.
26
-
27
- def parse_format s # yields attribs or text
28
- ## set default colors
29
- color = :white
30
- bgcolor = :black
31
- attrib = FFI::NCurses::A_NORMAL
32
- text = ""
33
-
34
- ## split #[...]
35
- #a = s.split /(#\[[^\]]*\])/
36
- a = s.split /(\x1b\[\d*(?:;\d+)*?[a-zA-Z])/
37
- a.each { |e|
38
- ## process color or attrib portion
39
- #[ "", "\e[1m", "", "\e[34m", "", "\e[47m", "Showing all items...", "\e[0m", "", "\e[0m", "\n"]
40
- if e[0] == "\x1b" && e[-1] == "m"
41
-
42
- #e.each { |f| x=/^.\[(.*).$/.match(f)
43
- $log.debug "XXX: ANSI e #{e} "
44
- x=/^.\[(.*).$/.match(e)
45
- color, bgcolor, attrib = nil, nil, nil
46
- $log.debug "XXX: ANSI #{x} ..... #{x[1]} "
47
- args = x[1].split ';'
48
- ## first split on commas to separate fg, bg and attr
49
- # http://ascii-table.com/ansi-escape-sequences.php
50
- args.each { |att|
51
- $log.debug "XXX: ANSI att: #{att} "
52
- case att.to_i
53
- when 0
54
- color, bgcolor, attrib = nil, nil, nil
55
- yield :reset # actually this resets all so we need an endall or clearall reset
56
-
57
- when 1
58
- attrib = 'bold'
59
- when 2
60
- attrib = 'dim'
61
- when 4
62
- attrib = 'underline'
63
- when 5
64
- attrib = 'blink'
65
- when 7
66
- attrib = 'reverse'
67
- when 8
68
- attrib = 'hidden' # XXX
69
- when 30
70
- color = 'black'
71
- when 31
72
- color = 'red'
73
- when 32
74
- color = 'green'
75
- when 33
76
- color = 'yellow'
77
- when 34
78
- color = 'blue'
79
- when 35
80
- color = 'magenta'
81
- when 36
82
- color = 'cyan'
83
- when 37
84
- color = 'white'
85
-
86
- #Background colors
87
- when 40
88
- bgcolor = 'black'
89
- when 41
90
- bgcolor = 'red'
91
- when 42
92
- bgcolor = 'green'
93
- when 43
94
- bgcolor = 'yellow'
95
- when 44
96
- bgcolor = 'blue'
97
- when 45
98
- bgcolor = 'magenta'
99
- when 46
100
- bgcolor = 'cyan'
101
- when 47
102
- bgcolor = 'white'
103
- else
104
- $log.warn "XXX: WARN ANSI not used #{att} "
105
- end
106
- } # args.ea
107
- #} # e.each
108
- $log.debug "XXX: ANSI YIELDING #{color} , #{bgcolor} , #{attrib} "
109
- yield [color,bgcolor,attrib] if block_given?
110
- else
111
- text = e
112
- yield text if block_given?
113
- end
114
- } # a.each
115
- end
116
-
117
- end
@@ -1,112 +0,0 @@
1
- module RubyCurses
2
- module Utils
3
- private
4
- def _suspend clear=true
5
- return unless block_given?
6
- Ncurses.def_prog_mode
7
- if clear
8
- Ncurses.endwin
9
- # NOTE: avoid false since screen remains half off
10
- # too many issues
11
- else
12
- system "/bin/stty sane"
13
- end
14
- yield if block_given?
15
- Ncurses.reset_prog_mode
16
- if !clear
17
- # Hope we don't screw your terminal up with this constantly.
18
- VER::stop_ncurses
19
- VER::start_ncurses
20
- #@form.reset_all # not required
21
- end
22
- @form.repaint if @form
23
- @window.wrefresh if @window
24
- Ncurses::Panel.update_panels
25
- end
26
- #
27
- # Suspends to shell so user can execute commands.
28
- # Maybe not be able to get your prompt correctly.
29
- #
30
- public
31
- def suspend
32
- _suspend(false) do
33
- system("tput cup 26 0")
34
- system("tput ed")
35
- system("echo Enter C-d to return to application")
36
- system (ENV['PS1']='\s-\v\$ ') if ENV['SHELL']== '/bin/bash'
37
- system(ENV['SHELL']);
38
- end
39
- end
40
-
41
- #
42
- # Displays application help using either array provided
43
- # or checking for :help_text method
44
- # @param [Array] help text
45
- def display_app_help help_array= nil
46
- if help_array
47
- arr = help_array
48
- elsif respond_to? :help_text
49
- arr = help_text
50
- else
51
- arr = []
52
- arr << " NO HELP SPECIFIED FOR APP #{self} "
53
- arr << " "
54
- arr << " --- General help --- "
55
- arr << " F10 - exit application "
56
- arr << " Alt-x - select commands "
57
- arr << " : - select commands "
58
- arr << " "
59
- end
60
- case arr
61
- when String
62
- arr = arr.split("\n")
63
- when Array
64
- end
65
- w = arr.max_by(&:length).length
66
-
67
- require 'rbcurse/extras/viewer'
68
- RubyCurses::Viewer.view(arr, :layout => [2, 10, [4+arr.size, 24].min, w+2],:close_key => KEY_RETURN, :title => "<Enter> to close", :print_footer => true) do |t|
69
- # you may configure textview further here.
70
- #t.suppress_borders true
71
- #t.color = :black
72
- #t.bgcolor = :white
73
- # or
74
- t.attr = :reverse
75
- end
76
- end
77
- #
78
- # prompts user for unix command and displays output in viewer
79
- #
80
- def shell_output
81
- cmd = get_string("Enter shell command:", 50)
82
- if cmd && !cmd.empty?
83
- run_command cmd
84
- end
85
- end
86
-
87
- #
88
- # executes given command and displays in viewer
89
- # @param [String] unix command, e.g., git -st
90
- def run_command cmd
91
- # http://whynotwiki.com/Ruby_/_Process_management#What_happens_to_standard_error_.28stderr.29.3F
92
- require 'rbcurse/extras/viewer'
93
- begin
94
- res = `#{cmd} 2>&1`
95
- rescue => ex
96
- res = ex.to_s
97
- res << ex.backtrace.join("\n")
98
- end
99
- res.gsub!("\t"," ")
100
- RubyCurses::Viewer.view(res.split("\n"), :close_key => KEY_RETURN, :title => "<Enter> to close, M-l M-h to scroll")
101
- end
102
- def shell_out command
103
- @window.hide
104
- Ncurses.endwin
105
- system command
106
- Ncurses.refresh
107
- #Ncurses.curs_set 0 # why ?
108
- @window.show
109
- end
110
- end # utils
111
- end # module RubyC
112
- include RubyCurses::Utils
@@ -1,407 +0,0 @@
1
- #
2
- # Common stack flow functionality
3
- # * Name: basestack.rb
4
- # * Description: Classes that allow user to stack and flow components
5
- #
6
- # * Date: 30.10.11 - 12:57
7
- # * Last update: 30.10.11 - 12:57
8
- #
9
- module RubyCurses
10
- module ModStack
11
- #
12
- # Base class for stacks and flows.
13
- # Will manage determining row col and width height of objects
14
- # Stacks place objects one below another. Flows place objects to the
15
- # right of the previous. Orientation can be reversed.
16
- #
17
- class BaseStack
18
- attr_accessor :components
19
- attr_reader :config
20
- attr_accessor :form
21
- def initialize config={}, components=[]
22
- @config = config
23
- config.each do |k, v|
24
- instance_variable_set "@#{k}", v
25
- end
26
- @components = components
27
- @calc_needed = true
28
- end
29
- # XXX if user sets later, we won't be checking the config
30
- # We check the actual variables which config sets in init
31
- %w[ parent_component width height weight row col orientation].each { |e|
32
- eval(
33
- "def #{e}
34
- @config[:#{e}]
35
- end
36
- def #{e}=(val)
37
- @config[:#{e}]=val
38
- instance_variable_set \"@#{e}\", val
39
- @calc_needed = true
40
- end"
41
- )
42
- }
43
- alias :parent :parent_component
44
- #alias :parent= :parent_component
45
- def repaint # stack
46
- $log.debug "XXX: stack repaint recalc #{@calc_needed} "
47
- @components.each { |e| e.form = @form unless e.form } #unless @calc_needed
48
- recalc if @calc_needed
49
- @components.each { |e| e.repaint }
50
- end
51
- def repaint_all x
52
- @calc_needed = true
53
- end
54
- def override_graphic gr
55
- @graphic = gr
56
- end
57
- def focusable; false; end
58
- # Calculates row col and width height
59
- # for each subc-omponent based on coords of Container
60
- # This is to be called only when the container has got its coordinates (i.e
61
- # Containers repaint). This should be in this objects repaint.
62
- def recalc
63
- @calc_needed = false
64
- comp = self
65
- if comp.is_a? BaseStack
66
- check_coords comp
67
- @margin_left ||= 0
68
- @margin_right ||= 0
69
- @margin_top ||= 0
70
- @margin_bottom ||= 0
71
- if comp.is_a? Stack
72
- r = row + @margin_top
73
- rem = 0
74
- ht = height - (@margin_top + @margin_bottom)
75
- if @orientation == :bottom
76
- mult = -1
77
- comps = @components.reverse
78
- r = row + height - @margin_bottom
79
-
80
- else
81
- mult = 1
82
- comps = @components
83
-
84
- end
85
- comps.each { |e|
86
- # should only happen if expandable FIXME
87
- e.height = 0.01 * e.weight * (ht - (e.margin_top + e.margin_bottom))
88
- hround = e.height.floor
89
- rem += e.height - hround
90
- e.height = hround #- (@margin_top + @margin_bottom)
91
- # rounding creates a problem, since 0.5 gets rounded up and we can exceed bound
92
- # So i floor, and maintain the lost space, and add it back when it exceeds 1
93
- # This way the last components gets stretched to meet the end, which is required
94
- # when the height of the stack is odd and there's a left-over row
95
- if rem >= 1
96
- e.height += 1
97
- rem = 0
98
- end
99
- # Item level margins have not been accounted for when calculating weightages, and
100
- # should not be used on the weightage axis
101
- r += e.margin_top
102
- if @orientation == :bottom
103
- r += e.height * mult
104
- e.row = r
105
- else
106
- e.row = r
107
- r += e.height + 0
108
- end
109
- e.width = width - (@margin_left + @margin_right + e.margin_left + e.margin_right)
110
- e.col = col + @margin_left + e.margin_left # ??? XXX
111
- $log.debug "XXX: recalc stack #{e.widget.class} r:#{e.row} c:#{e.col} h:#{e.height} = we:#{e.weight} * h:#{height} "
112
- #e.col_offset = col_offset # ??? XXX
113
- check_coords e
114
- e.repaint_all(true)
115
- e.recalc if e.is_a? BaseStack
116
- }
117
- elsif comp.is_a? Flow
118
- c = col + @margin_left #+ col_offset
119
- rem = 0
120
- wd = width - (@margin_left + @margin_right)
121
- # right_to_left orientation
122
- if @orientation == :right
123
- mult = -1
124
- comps = @components.reverse
125
- c = col + width - @margin_right
126
- $log.debug "XXX: ORIENT1f recalc #{@orientation} "
127
- else
128
- mult = 1
129
- comps = @components
130
- $log.debug "XXX: ORIENT2f recalc #{@orientation} "
131
- end
132
- comps.each { |e|
133
- e.width = e.weight * wd * 0.01
134
- wround = e.width.floor
135
- rem += e.width - wround
136
- e.width = wround
137
- # see comment in prev block regarding remaininder
138
- if rem >= 1
139
- e.width += 1
140
- rem = 0
141
- end
142
- e.height = height - (@margin_top + @margin_bottom) #* weight * 0.01
143
- #e.height = e.height.round
144
- if @orientation == :right
145
- c += e.width * mult # mult 1 or -1
146
- e.col = c
147
- else
148
- e.col = c
149
- c += e.width * mult # mult 1 or -1
150
- end
151
- e.row = row + @margin_top
152
- check_coords e
153
- $log.debug "XXX: recalc flow #{e.widget.class} r:#{e.row} c:#{e.col} h:#{e.height} = we:#{e.weight} * w:#{width} "
154
- e.repaint_all(true) # why not happening when we change row, hieght etc
155
- e.recalc if e.is_a? BaseStack
156
- }
157
- end
158
- else
159
- alert "in else recalc DOES NOT COME HERE "
160
- comp.col = comp.parent.col
161
- comp.row = comp.parent.row
162
- comp.height = comp.parent.height
163
- comp.width = comp.parent.width
164
- $log.debug "XXX: recalc else #{comp.class} r #{comp.row} c #{comp.col} . h #{comp} height w #{comp.width} "
165
- end
166
- end
167
- # Traverses the comopnent tree and calculates weightages for all components
168
- # based on what has been specified by user
169
- def check_coords e # stack
170
- r = e.row
171
- c = e.col
172
- if r >= row + height
173
- $log.warn "XXX: WARN e.class is out of bounds row #{r} "
174
- e.visible = false
175
- end
176
- if c >= col + width
177
- $log.warn "XXX: WARN e.class is out of bounds col #{c} "
178
- e.visible = false
179
- end
180
- end
181
- def increase c=@current_component
182
- p = self #c.parent_component
183
- ci = p.components.index(c)
184
- ni = ci + 1
185
- if p.components[ni].nil?
186
- ni = nil
187
- end
188
- case p
189
- when Flow
190
- # increase width of current and reduce from neighbor
191
- if ni
192
- n = p.components[ni]
193
- $log.debug "XXX: INC fl current #{ci}, total#{p.components.count}, next #{n} "
194
-
195
- c.width += 1
196
- n.width -= 1
197
- n.col += 1
198
- end
199
-
200
- when Stack
201
- if ni
202
- n = p.components[ni]
203
- $log.debug "XXX: INC fl current #{ci}, total#{p.components.count}, next #{n} "
204
-
205
- c.height += 1
206
- n.height -= 1
207
- n.row += 1
208
- end
209
- $log.debug "XXX: INC st current #{ci}, total#{p.components.count} "
210
- end
211
-
212
- end
213
- def decrease c=@current_component
214
- p = self #c.parent_component
215
- ci = p.components.index(c)
216
- ni = ci + 1
217
- if p.components[ni].nil?
218
- ni = nil
219
- end
220
- case p
221
- when Flow
222
- # increase width of current and reduce from neighbor
223
- if ni
224
- n = p.components[ni]
225
- $log.debug "XXX: INC fl current #{ci}, total#{p.components.count}, next #{n} "
226
-
227
- c.width -= 1
228
- n.width += 1
229
- n.col -= 1
230
- end
231
-
232
- when Stack
233
- if ni
234
- n = p.components[ni]
235
- $log.debug "XXX: INC fl current #{ci}, total#{p.components.count}, next #{n} "
236
-
237
- c.height -= 1
238
- n.height += 1
239
- n.row -= 1
240
- end
241
- $log.debug "XXX: INC st current #{ci}, total#{p.components.count} "
242
- end
243
-
244
- end
245
- def to_s
246
- @components
247
- end
248
- end # class Base
249
- # A stack positions objects one below the other
250
- class Stack < BaseStack; end
251
- # A flow positions objects in a left to right
252
- class Flow < BaseStack; end
253
- #
254
- # A wrapper over widget mostly because it adds weight and margins
255
- #
256
- class Item
257
- attr_reader :config, :widget
258
- attr_reader :margin_top, :margin_left, :margin_bottom, :margin_right
259
- def initialize config={}, widget
260
- @config = config
261
- config.each do |k, v|
262
- instance_variable_set "@#{k}", v
263
- end
264
- @margin_left ||= 0
265
- @margin_right ||= 0
266
- @margin_top ||= 0
267
- @margin_bottom ||= 0
268
- @widget = widget
269
- end
270
- def weight; @config[:weight]||100; end
271
- def weight=(val); @config[:weight]=val; end
272
- def repaint; @widget.repaint; end
273
- %w[ form parent parent_component width height row col row_offset col_offset focusable].each { |e|
274
- eval(
275
- "def #{e}
276
- @widget.#{e}
277
- end
278
- def #{e}=(val)
279
- @widget.#{e}=val
280
- end"
281
- )
282
- }
283
- def method_missing(sym, *args, &block)
284
- @widget.send sym, *args, &block
285
- end
286
- end # class Item
287
-
288
- # --------------------- module level ------------------------------#
289
- # General routin to traverse components and their components
290
- def traverse c, &block
291
- if c.is_a? BaseStack
292
- yield c
293
- c.components.each { |e|
294
- yield e
295
- }
296
- c.components.each { |e| traverse(e, &block) }
297
- @ctr -= 1
298
- else
299
- end
300
- end
301
-
302
- # traverse the components and their children
303
- #
304
- def each &block
305
- @components.each { |e| traverse e, &block }
306
- end
307
- # module level
308
- private
309
- def _stack type, config={}, &block
310
- case type
311
- when :stack
312
- s = Stack.new(config)
313
- when :flow
314
- s = Flow.new(config)
315
- end
316
- _add s
317
- @active << s
318
- yield_or_eval &block if block_given?
319
- @active.pop
320
- # if active is empty then this is where we could calculate
321
- # percentatges and do recalc, thus making it independent
322
- end
323
- # module level
324
- private
325
- private
326
- def _add s
327
- if @active.empty?
328
- $log.debug "XXX: ADDING TO components #{s} "
329
- unless s.is_a? BaseStack
330
- raise "No stack or flow to add to. Results may not be what you want"
331
- end
332
- @components << s
333
- else
334
- @active.last.components << s
335
- end
336
- __add s
337
- end
338
-
339
- # module level
340
- private
341
- public
342
- def stack config={}, &block
343
- _stack :stack, config, &block
344
- end
345
- def flow config={}, &block
346
- _stack :flow, config, &block
347
- end
348
- # module level
349
- private
350
- def add w, config={}
351
- i = Item.new config, w
352
- _add i
353
- end
354
- alias :add_widget :add
355
- # module level
356
- private
357
- def calc_weightages2 components, parent
358
- #puts " #{@ctr} --> #{c.type}, wt: #{c.config[:weight]} "
359
- @ctr += 1
360
- wt = 0
361
- cnt = 0
362
- sz = components.count
363
- $log.debug "XXX: calc COMP COUNT #{sz} "
364
- # calculate how much weightage has been given by user
365
- # so we can allocate average to other components
366
- components.each { |e|
367
- if e.config[:weight]
368
- wt += e.config[:weight]
369
- cnt += 1
370
- end
371
- $log.debug "XXX: INC setting parent #{parent} to #{e} "
372
- e.config[:parent] = parent
373
- e.config[:level] = @ctr
374
- }
375
- used = sz - cnt
376
- $log.debug "XXX: ADDING calc COMP COUNT #{sz} - #{cnt} "
377
- if used > 0
378
- avg = (100-wt)/used
379
- # Allocate average to other components
380
- components.each { |e| e.config[:weight] = avg unless e.config[:weight] }
381
- end
382
- components.each { |e| calc_weightages2(e.components, e) if e.respond_to? :components }
383
- @ctr -= 1
384
- end
385
- # module level
386
- private
387
- # given an widget, return the item, so we can change weight or some other config
388
- def item_for widget
389
- each do |e|
390
- if e.is_a? Item
391
- if e.widget == widget
392
- return e
393
- end
394
- end
395
- end
396
- return nil
397
- end
398
- # module level
399
- # returns the parent (flow or stack) for a given widget
400
- # allowing user to change configuration such as weight
401
- def parent_of widget
402
- f = item_for widget
403
- return f.config[:parent] if f
404
- return nil
405
- end
406
- end # mod modstack
407
- end # mod