rbcurse 0.1.3 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +126 -0
- data/Manifest.txt +53 -20
- data/README.markdown +423 -0
- data/Rakefile +3 -1
- data/examples/keytest.rb +177 -0
- data/examples/mpad2.rb +156 -0
- data/examples/newtesttabp.rb +121 -0
- data/examples/rfe.rb +48 -10
- data/examples/rfe_renderer.rb +4 -4
- data/examples/rvimsplit.rb +376 -0
- data/examples/sqlc.rb +97 -106
- data/examples/sqlm.rb +446 -0
- data/examples/test1.rb +4 -4
- data/examples/test2.rb +12 -12
- data/examples/testchars.rb +140 -0
- data/examples/testkeypress.rb +9 -4
- data/examples/testmulticomp.rb +72 -0
- data/examples/testscroller.rb +136 -0
- data/examples/testscrolllb.rb +86 -0
- data/examples/testscrollp.rb +87 -0
- data/examples/testscrollta.rb +80 -0
- data/examples/testscrolltable.rb +166 -0
- data/examples/testsplit.rb +87 -0
- data/examples/testsplit2.rb +123 -0
- data/examples/testsplit3.rb +215 -0
- data/examples/testsplit3_1.rb +244 -0
- data/examples/testsplit3a.rb +215 -0
- data/examples/testsplit3b.rb +237 -0
- data/examples/testsplitta.rb +148 -0
- data/examples/testsplittv.rb +142 -0
- data/examples/testsplittvv.rb +144 -0
- data/examples/testtable.rb +1 -1
- data/examples/testtabp.rb +3 -2
- data/examples/testtestw.rb +69 -0
- data/examples/testtodo.rb +5 -3
- data/examples/testtpane.rb +203 -0
- data/examples/testtpane2.rb +145 -0
- data/examples/testtpanetable.rb +199 -0
- data/examples/viewtodo.rb +5 -3
- data/lib/rbcurse.rb +1 -1
- data/lib/rbcurse/celleditor.rb +2 -2
- data/lib/rbcurse/colormap.rb +5 -5
- data/lib/rbcurse/defaultlistselectionmodel.rb +3 -3
- data/lib/rbcurse/io.rb +663 -0
- data/lib/rbcurse/listeditable.rb +306 -0
- data/lib/rbcurse/listkeys.rb +15 -15
- data/lib/rbcurse/listscrollable.rb +168 -27
- data/lib/rbcurse/mapper.rb +35 -13
- data/lib/rbcurse/rchangeevent.rb +28 -0
- data/lib/rbcurse/rform.rb +845 -0
- data/lib/rbcurse/rlistbox.rb +144 -34
- data/lib/rbcurse/rmessagebox.rb +10 -5
- data/lib/rbcurse/rmulticontainer.rb +325 -0
- data/lib/rbcurse/rmultitextview.rb +306 -0
- data/lib/rbcurse/rscrollform.rb +369 -0
- data/lib/rbcurse/rscrollpane.rb +511 -0
- data/lib/rbcurse/rsplitpane.rb +820 -0
- data/lib/rbcurse/rtabbedpane.rb +737 -109
- data/lib/rbcurse/rtabbedwindow.rb +326 -0
- data/lib/rbcurse/rtable.rb +220 -64
- data/lib/rbcurse/rtextarea.rb +340 -181
- data/lib/rbcurse/rtextview.rb +237 -101
- data/lib/rbcurse/rviewport.rb +203 -0
- data/lib/rbcurse/rwidget.rb +919 -95
- data/lib/rbcurse/scrollable.rb +7 -7
- data/lib/rbcurse/selectable.rb +4 -4
- data/lib/rbcurse/table/tablecellrenderer.rb +3 -0
- data/lib/rbcurse/undomanager.rb +181 -0
- data/lib/rbcurse/vieditable.rb +100 -0
- data/lib/ver/window.rb +471 -21
- metadata +66 -22
- data/README.txt +0 -312
- data/examples/testd.db +0 -0
- data/examples/todocsv.csv +0 -28
@@ -0,0 +1,69 @@
|
|
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/rtestwidget'
|
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
|
+
@form = Form.new @window
|
23
|
+
r = 1; c = 30; w = 40
|
24
|
+
ht = 10
|
25
|
+
# print filler stars
|
26
|
+
filler = "*" * (w+2)
|
27
|
+
(ht+3).times(){|i| @form.window.printstring(i,c-1, filler, $datacolor) }
|
28
|
+
|
29
|
+
# strangely, first displays textview, then puts the fillers over it.
|
30
|
+
# then after a keypress, again refreshes textview.
|
31
|
+
|
32
|
+
|
33
|
+
@textview = TestWidget.new @form do
|
34
|
+
name "myView"
|
35
|
+
row r
|
36
|
+
col c
|
37
|
+
width w
|
38
|
+
height ht
|
39
|
+
title "README.txt"
|
40
|
+
title_attrib 'bold'
|
41
|
+
print_footer true
|
42
|
+
footer_attrib 'bold'
|
43
|
+
end
|
44
|
+
content = File.open("../README.txt","r").readlines
|
45
|
+
@textview.set_content content #, :WRAP_WORD
|
46
|
+
|
47
|
+
@help = "q to quit. This is a test of testWidget which uses a pad/buffer."
|
48
|
+
RubyCurses::Label.new @form, {'text' => @help, "row" => 21, "col" => 2, "color" => "yellow"}
|
49
|
+
|
50
|
+
@form.repaint
|
51
|
+
@window.wrefresh
|
52
|
+
Ncurses::Panel.update_panels
|
53
|
+
while((ch = @window.getchar()) != ?q.getbyte(0) )
|
54
|
+
str = keycode_tos ch
|
55
|
+
@form.handle_key(ch)
|
56
|
+
@form.repaint
|
57
|
+
@window.wrefresh
|
58
|
+
end
|
59
|
+
end
|
60
|
+
rescue => ex
|
61
|
+
ensure
|
62
|
+
@window.destroy if !@window.nil?
|
63
|
+
VER::stop_ncurses
|
64
|
+
p ex if ex
|
65
|
+
p(ex.backtrace.join("\n")) if ex
|
66
|
+
$log.debug( ex) if ex
|
67
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
68
|
+
end
|
69
|
+
end
|
data/examples/testtodo.rb
CHANGED
@@ -26,7 +26,8 @@ class TodoList
|
|
26
26
|
@categories=[]
|
27
27
|
@modules=[]
|
28
28
|
require 'csv'
|
29
|
-
CSV::Reader.parse(File.open(@file, 'r')) do |row|
|
29
|
+
#CSV::Reader.parse(File.open(@file, 'r')) do |row|
|
30
|
+
CSV.foreach(@file) do |row| # 1.9 2009-10-05 11:12
|
30
31
|
@data << row
|
31
32
|
$log.debug " #{row.inspect} "
|
32
33
|
@categories << row[0] unless @categories.include? row[0]
|
@@ -109,7 +110,8 @@ class TodoList
|
|
109
110
|
=end
|
110
111
|
d = @data
|
111
112
|
require 'csv'
|
112
|
-
CSV.open('todocsv.csv', 'w') do |writer|
|
113
|
+
#CSV.open('todocsv.csv', 'w') do |writer|
|
114
|
+
CSV.open("todocsv.csv", "w") do |writer|
|
113
115
|
#writer << [nil, nil]
|
114
116
|
d.each do |row|
|
115
117
|
#parced_cells = CSV.generate_rows(row, row.size, buf)
|
@@ -500,7 +502,7 @@ class TodoApp
|
|
500
502
|
@window.wrefresh
|
501
503
|
Ncurses::Panel.update_panels
|
502
504
|
begin
|
503
|
-
while((ch = @window.getchar()) != ?\C-q )
|
505
|
+
while((ch = @window.getchar()) != ?\C-q.getbyte(0) )
|
504
506
|
colcount = tcm.column_count-1
|
505
507
|
s = keycode_tos ch
|
506
508
|
#status_row.text = "Pressed #{ch} , #{s}"
|
@@ -0,0 +1,203 @@
|
|
1
|
+
#*******************************************************#
|
2
|
+
# testtpane.rb #
|
3
|
+
# written by Rahul Kumar #
|
4
|
+
# January 20, 2010 #
|
5
|
+
# #
|
6
|
+
# testing tabbedpane with textarea, view, listbox #
|
7
|
+
# #
|
8
|
+
# Released under ruby license. See #
|
9
|
+
# http://www.ruby-lang.org/en/LICENSE.txt #
|
10
|
+
# Copyright 2010, Rahul Kumar #
|
11
|
+
#*******************************************************#
|
12
|
+
|
13
|
+
# this is a test program, tests out tabbed panes. type F1 to exit
|
14
|
+
# position cursor in button form and press M-x to add a few tabs
|
15
|
+
# M-l in button form will scroll. M-h to scroll left.
|
16
|
+
# dd to kill a tab, u to undo kill, or p/P to paste deleted tab
|
17
|
+
#
|
18
|
+
#$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
|
19
|
+
require 'rubygems'
|
20
|
+
require 'ncurses'
|
21
|
+
require 'logger'
|
22
|
+
require 'rbcurse'
|
23
|
+
require 'rbcurse/rtabbedpane'
|
24
|
+
require 'rbcurse/rtextview'
|
25
|
+
require 'rbcurse/rtextarea'
|
26
|
+
require 'rbcurse/rtable'
|
27
|
+
|
28
|
+
class TestTabbedPane
|
29
|
+
def initialize
|
30
|
+
acolor = $reversecolor
|
31
|
+
@tctr = 0
|
32
|
+
end
|
33
|
+
def run
|
34
|
+
$config_hash ||= Variable.new Hash.new
|
35
|
+
@window = VER::Window.root_window
|
36
|
+
@form = Form.new @window
|
37
|
+
@form.name = "MainForm"
|
38
|
+
r = 4; c = 7;
|
39
|
+
h = 20; w = 70
|
40
|
+
@tp = RubyCurses::TabbedPane.new @form do
|
41
|
+
name "MainPane"
|
42
|
+
height h
|
43
|
+
width w
|
44
|
+
row 2
|
45
|
+
col 8
|
46
|
+
#button_type :ok
|
47
|
+
end
|
48
|
+
|
49
|
+
textview = TextView.new do
|
50
|
+
name "myView"
|
51
|
+
row 4
|
52
|
+
col 0
|
53
|
+
#width w-0
|
54
|
+
#height h-4
|
55
|
+
title "README.mrku"
|
56
|
+
title_attrib 'bold'
|
57
|
+
print_footer true
|
58
|
+
footer_attrib 'bold'
|
59
|
+
end
|
60
|
+
content = File.open("../README.markdown","r").readlines
|
61
|
+
textview.set_content content #, :WRAP_WORD
|
62
|
+
#textview.show_caret = true
|
63
|
+
|
64
|
+
@tab1 = @tp.add_tab "&TextView", textview
|
65
|
+
#@tabl.add_component textview
|
66
|
+
#f1 = @tab1.form
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
#f2 = @tab2.form
|
71
|
+
r = 4
|
72
|
+
texta = TextArea.new do
|
73
|
+
name "myText"
|
74
|
+
#row r
|
75
|
+
#col 2
|
76
|
+
#width w-5
|
77
|
+
#height h-5
|
78
|
+
title "EditMe.txt"
|
79
|
+
title_attrib 'bold'
|
80
|
+
print_footer true
|
81
|
+
footer_attrib 'bold'
|
82
|
+
end
|
83
|
+
@tab2 = @tp.add_tab "&Settings", texta
|
84
|
+
|
85
|
+
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."
|
86
|
+
texta << "Let me not defer it or neglect it, for I shall not pass this way again."
|
87
|
+
texta << " "
|
88
|
+
texta << "q to exit."
|
89
|
+
texta << "Some more text going below scrollpane.. "
|
90
|
+
texta << "Love all creatures for they are none but yourself."
|
91
|
+
#texta.show_caret = true # since the cursor is not showing correctly, show internal one.
|
92
|
+
|
93
|
+
@tab3 = @tp.add_tab "&Editors"
|
94
|
+
#f3 = @tab3.form
|
95
|
+
f3 = @tp.form @tab3
|
96
|
+
butts = %w[ &Vim E&macs &Jed E&lvis ]
|
97
|
+
bcodes = %w[ VIM EMACS JED ELVIS]
|
98
|
+
row = 2
|
99
|
+
butts.each_with_index do |name, i|
|
100
|
+
RubyCurses::CheckBox.new f3 do
|
101
|
+
text name
|
102
|
+
variable $config_hash
|
103
|
+
name bcodes[i]
|
104
|
+
row row+i
|
105
|
+
col 5
|
106
|
+
end
|
107
|
+
end
|
108
|
+
tab3 = @tp.add_tab "S&ongs"
|
109
|
+
#f3 = tab3.form
|
110
|
+
#f3 = @tp.form tab3
|
111
|
+
data = [["Pathetique",3,"Tchaikovsky",3.21, true, "WIP"],
|
112
|
+
["Ali Maula Ali Maula",3,"NFAK",3.47, true, "WIP"],
|
113
|
+
["Tera Hijr Mera Nasib",92,"Razia Sultan",412, true, "Fin"],
|
114
|
+
["Piano Concerto 4&5",4,"Beethoven",110.0, false, "Cancel"],
|
115
|
+
["Toccata and Fugue",4,"J S Bach",102.72, false, "Postp"],
|
116
|
+
["Symphony No. 3",4,"Henryk Gorecki",102.72, true, "Postp"],
|
117
|
+
["The Great Gig in the Sky",8,"Pink Floyd",12.72, false, "Todo"],
|
118
|
+
["Steppes of Central Asia",9,"Borodin",12.2, false, "WIP"],
|
119
|
+
["Wish You Were Here",8,"Pink Floyd",2.7, false, "Todo"],
|
120
|
+
["Habanera",nil,"Maria Callas",112.7, true, "Cancel"],
|
121
|
+
["Mack the Knife",9,"Loius Armstrong",12.2, false, "Todo"],
|
122
|
+
["Prince Igor",9,"Borodin",16.3, false, "WIP"],
|
123
|
+
["Shahbaaz Qalandar",9,"Nusrat Fateh Ali Khan",12.2, false, "Todo"],
|
124
|
+
["Raag Darbari",9,"Ustad Fateh Ali Khan",12.2, false, "Todo"],
|
125
|
+
["Yaad-e-Mustafa Aisi",9,"Santoo Khan",12.2, true, "Todo"],
|
126
|
+
["Chaconne",4,"Johann S Bach",12.42, true, "Postp"],
|
127
|
+
["Raag Jaunpuri",9,"Ustad Fateh Ali Khan",12.2, false, "Todo"],
|
128
|
+
["Dalaleragita",9,"Vaishnava",12.2, false, "Todo"],
|
129
|
+
["Prasada sevaya",9,"Vaishnava",12.2, false, "Todo"],
|
130
|
+
["Sri Rupamanjiri",9,"Vaishnava",12.2, false, "Todo"],
|
131
|
+
["M Vlast ",9,"Smetana",12.2, false, "Todo"],
|
132
|
+
["Jai Radha Madhava",163,"Jagjit Singh",5.4, false, "WIP"]]
|
133
|
+
colnames = %w[ Song Cat Artist Ratio Flag Status]
|
134
|
+
statuses = ["Todo", "WIP", "Fin", "Cancel", "Postp"]
|
135
|
+
|
136
|
+
row = 1
|
137
|
+
# when adding as a component it is best not to specify row and col
|
138
|
+
# We can skip sizing too for large components, so comp will fill the TP.
|
139
|
+
atable = Table.new do
|
140
|
+
name "mytable"
|
141
|
+
#row row
|
142
|
+
#col 0
|
143
|
+
#width 76
|
144
|
+
#height h - 4
|
145
|
+
#title "A Table"
|
146
|
+
#title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
|
147
|
+
cell_editing_allowed true
|
148
|
+
editing_policy :EDITING_AUTO
|
149
|
+
set_data data, colnames
|
150
|
+
end
|
151
|
+
tab3.component = atable
|
152
|
+
sel_col = Variable.new 0
|
153
|
+
sel_col.value = 0
|
154
|
+
tcm = atable.get_table_column_model
|
155
|
+
selcolname = atable.get_column_name sel_col.value
|
156
|
+
tcm.column(0).width 24
|
157
|
+
tcm.column(1).width 3
|
158
|
+
tcm.column(2).width 18
|
159
|
+
#tcm.column(2).editable false
|
160
|
+
tcm.column(3).width 7
|
161
|
+
tcm.column(4).width 5
|
162
|
+
tcm.column(5).width 6
|
163
|
+
@help = "F1 to quit. M-s M-t M-e M-o, TAB, M-x to add tab #{$0} Check logger too"
|
164
|
+
RubyCurses::Label.new @form, {'text' => @help, "row" => r+h+2, "col" => 2, "color" => "yellow"}
|
165
|
+
|
166
|
+
# M-x when inside the buttons form will create a new tab
|
167
|
+
@form.bind_key(?\M-x) {
|
168
|
+
textv = TextView.new
|
169
|
+
t = @tp.add_tab "Text#{@tctr}", textv
|
170
|
+
textv.set_content content
|
171
|
+
@tctr += 1
|
172
|
+
}
|
173
|
+
@form.repaint
|
174
|
+
$catch_alt_digits = false # we want to use Alt-1, 2 for tabs.
|
175
|
+
@window.wrefresh
|
176
|
+
Ncurses::Panel.update_panels
|
177
|
+
while((ch = @window.getchar()) != KEY_F1 )
|
178
|
+
# @tp.repaint
|
179
|
+
@form.handle_key(ch)
|
180
|
+
@window.wrefresh
|
181
|
+
end
|
182
|
+
#@tp.show
|
183
|
+
#@tp.handle_keys
|
184
|
+
end
|
185
|
+
end
|
186
|
+
if $0 == __FILE__
|
187
|
+
# Initialize curses
|
188
|
+
begin
|
189
|
+
# XXX update with new color and kb
|
190
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
191
|
+
$log = Logger.new("view.log")
|
192
|
+
$log.level = Logger::DEBUG
|
193
|
+
n = TestTabbedPane.new
|
194
|
+
n.run
|
195
|
+
rescue => ex
|
196
|
+
ensure
|
197
|
+
VER::stop_ncurses
|
198
|
+
p ex if ex
|
199
|
+
p(ex.backtrace.join("\n")) if ex
|
200
|
+
$log.debug( ex) if ex
|
201
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#*******************************************************#
|
2
|
+
# testtpane2.rb #
|
3
|
+
# written by Rahul Kumar #
|
4
|
+
# February 1, 2010 #
|
5
|
+
# #
|
6
|
+
# testing tabbedpane with textarea, view, listbox #
|
7
|
+
# Differs from testtpane added scrollpanes outside view #
|
8
|
+
# #
|
9
|
+
# Released under ruby license. See #
|
10
|
+
# http://www.ruby-lang.org/en/LICENSE.txt #
|
11
|
+
# Copyright 2010, Rahul Kumar #
|
12
|
+
#*******************************************************#
|
13
|
+
|
14
|
+
# this is a test program, tests out tabbed panes. type F1 to exit
|
15
|
+
#
|
16
|
+
#$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
|
17
|
+
require 'rubygems'
|
18
|
+
require 'ncurses'
|
19
|
+
require 'logger'
|
20
|
+
require 'rbcurse'
|
21
|
+
require 'rbcurse/rtabbedpane'
|
22
|
+
require 'rbcurse/rtextview'
|
23
|
+
require 'rbcurse/rtextarea'
|
24
|
+
require 'rbcurse/rscrollpane'
|
25
|
+
|
26
|
+
class TestTabbedPane
|
27
|
+
def initialize
|
28
|
+
acolor = $reversecolor
|
29
|
+
end
|
30
|
+
def run
|
31
|
+
$config_hash ||= Variable.new Hash.new
|
32
|
+
@window = VER::Window.root_window
|
33
|
+
@form = Form.new @window
|
34
|
+
@form.name = "MAINFORM"
|
35
|
+
$log.debug " MAIN FORM #{@form} , #{@window} "
|
36
|
+
r = 3; c = 5;
|
37
|
+
h = 20; w = 70
|
38
|
+
@tp = RubyCurses::TabbedPane.new @form do
|
39
|
+
height h
|
40
|
+
width w
|
41
|
+
row r #5
|
42
|
+
col c #8
|
43
|
+
#button_type :ok
|
44
|
+
end
|
45
|
+
sr = 4
|
46
|
+
sc = 2
|
47
|
+
@scroll = ScrollPane.new nil do
|
48
|
+
name "myScroller"
|
49
|
+
# row 4 #+ht+1
|
50
|
+
# col 0
|
51
|
+
# width w-1
|
52
|
+
# height h-4
|
53
|
+
end
|
54
|
+
textview = TextView.new do
|
55
|
+
name "myView"
|
56
|
+
row 0 #sr+1 # 4
|
57
|
+
col 0 #sc+1 # 2
|
58
|
+
width w-0
|
59
|
+
# height h+10
|
60
|
+
title "README.mrku"
|
61
|
+
title_attrib 'bold'
|
62
|
+
print_footer true
|
63
|
+
footer_attrib 'bold'
|
64
|
+
end
|
65
|
+
content = File.open("../README.markdown","r").readlines
|
66
|
+
textview.set_content content #, :WRAP_WORD
|
67
|
+
#textview.show_caret = true
|
68
|
+
$log.debug " before adding tab to TP "
|
69
|
+
@tab1 = @tp.add_tab "&TextView", @scroll
|
70
|
+
@scroll.child(textview)
|
71
|
+
|
72
|
+
|
73
|
+
@tab2 = @tp.add_tab "&Settings"
|
74
|
+
|
75
|
+
#f2 = @tab2.form
|
76
|
+
#$log.debug " textarea tp form #{f2} "
|
77
|
+
r = 4
|
78
|
+
texta = TextArea.new do
|
79
|
+
name "myText"
|
80
|
+
#row r
|
81
|
+
#col 1
|
82
|
+
#width w-5
|
83
|
+
#height h-5
|
84
|
+
title "EditMe.txt"
|
85
|
+
title_attrib 'bold'
|
86
|
+
print_footer true
|
87
|
+
footer_attrib 'bold'
|
88
|
+
end
|
89
|
+
@tab2.component = texta
|
90
|
+
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."
|
91
|
+
texta << "Let me not defer it or neglect it, for I shall not pass this way again."
|
92
|
+
texta << " "
|
93
|
+
texta << "q to exit."
|
94
|
+
texta << "Some more text going below scrollpane.. "
|
95
|
+
texta << "Love all creatures for they are none but yourself."
|
96
|
+
#texta.show_caret = true # since the cursor is not showing correctly, show internal one.
|
97
|
+
|
98
|
+
# This uses the old style, we get a padded form and then add objects to it.
|
99
|
+
@tab3 = @tp.add_tab "&Editors"
|
100
|
+
#f3 = @tab3.form
|
101
|
+
f3 = @tp.form @tab3 # this replaces previous line, since we don't create form by default
|
102
|
+
butts = %w[ &Vim E&macs &Jed E&lvis ]
|
103
|
+
bcodes = %w[ VIM EMACS JED ELVIS]
|
104
|
+
row = 4
|
105
|
+
butts.each_with_index do |name, i|
|
106
|
+
RubyCurses::CheckBox.new f3 do
|
107
|
+
text name
|
108
|
+
variable $config_hash
|
109
|
+
name bcodes[i]
|
110
|
+
row row+i
|
111
|
+
col 5
|
112
|
+
end
|
113
|
+
end
|
114
|
+
@help = "F1 to quit. M- T/S/E for tabs. M-n p h l scrollpane #{$0} Check logger too"
|
115
|
+
RubyCurses::Label.new @form, {'text' => @help, "row" => r+h+2, "col" => 2, "color" => "yellow"}
|
116
|
+
@form.repaint
|
117
|
+
@window.wrefresh
|
118
|
+
Ncurses::Panel.update_panels
|
119
|
+
while((ch = @window.getchar()) != KEY_F1 )
|
120
|
+
# @tp.repaint
|
121
|
+
@form.handle_key(ch)
|
122
|
+
@window.wrefresh
|
123
|
+
end
|
124
|
+
#@tp.show
|
125
|
+
#@tp.handle_keys
|
126
|
+
end
|
127
|
+
end
|
128
|
+
if $0 == __FILE__
|
129
|
+
# Initialize curses
|
130
|
+
begin
|
131
|
+
# XXX update with new color and kb
|
132
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
133
|
+
$log = Logger.new("view.log")
|
134
|
+
$log.level = Logger::DEBUG
|
135
|
+
n = TestTabbedPane.new
|
136
|
+
n.run
|
137
|
+
rescue => ex
|
138
|
+
ensure
|
139
|
+
VER::stop_ncurses
|
140
|
+
p ex if ex
|
141
|
+
p(ex.backtrace.join("\n")) if ex
|
142
|
+
$log.debug( ex) if ex
|
143
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#*******************************************************#
|
2
|
+
# testtpanetable.rb #
|
3
|
+
# written by Rahul Kumar #
|
4
|
+
# January 29, 2010 #
|
5
|
+
# #
|
6
|
+
# testing tabbedpane with table #
|
7
|
+
# #
|
8
|
+
# Released under ruby license. See #
|
9
|
+
# http://www.ruby-lang.org/en/LICENSE.txt #
|
10
|
+
# Copyright 2010, Rahul Kumar #
|
11
|
+
#*******************************************************#
|
12
|
+
|
13
|
+
# this is a test program, tests out tabbed panes. type F1 to exit
|
14
|
+
#
|
15
|
+
#$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
|
16
|
+
require 'rubygems'
|
17
|
+
require 'ncurses'
|
18
|
+
require 'logger'
|
19
|
+
require 'rbcurse'
|
20
|
+
require 'rbcurse/rtabbedpane'
|
21
|
+
require 'rbcurse/rtable'
|
22
|
+
require 'rbcurse/rscrollpane'
|
23
|
+
|
24
|
+
class TestTabbedPane
|
25
|
+
def initialize
|
26
|
+
acolor = $reversecolor
|
27
|
+
end
|
28
|
+
def run
|
29
|
+
$config_hash ||= Variable.new Hash.new
|
30
|
+
@window = VER::Window.root_window
|
31
|
+
@form = Form.new @window
|
32
|
+
$log.debug " MAIN FORM #{@form} "
|
33
|
+
r = 1; c = 1;
|
34
|
+
h = 20; w = 70
|
35
|
+
@tp = RubyCurses::TabbedPane.new @form do
|
36
|
+
height h
|
37
|
+
width w
|
38
|
+
row 2
|
39
|
+
col 8
|
40
|
+
#button_type :ok
|
41
|
+
end
|
42
|
+
@tab1 = @tp.add_tab "&Table"
|
43
|
+
f1 = @tab1.form
|
44
|
+
$log.debug " TABLE FORM #{f1} "
|
45
|
+
|
46
|
+
data = [["Pathetique",3,"Tchaikovsky",3.21, true, "WIP"],
|
47
|
+
["Ali Maula Ali Maula",3,"NFAK",3.47, true, "WIP"],
|
48
|
+
["Tera Hijr Mera Nasib",92,"Razia Sultan",412, true, "Fin"],
|
49
|
+
["Piano Concerto 4&5",4,"Beethoven",110.0, false, "Cancel"],
|
50
|
+
["Toccata and Fugue",4,"J S Bach",102.72, false, "Postp"],
|
51
|
+
["Symphony No. 3",4,"Henryk Gorecki",102.72, true, "Postp"],
|
52
|
+
["The Great Gig in the Sky",8,"Pink Floyd",12.72, false, "Todo"],
|
53
|
+
["Steppes of Central Asia",9,"Borodin",12.2, false, "WIP"],
|
54
|
+
["Wish You Were Here",8,"Pink Floyd",2.7, false, "Todo"],
|
55
|
+
["Habanera",nil,"Maria Callas",112.7, true, "Cancel"],
|
56
|
+
["Mack the Knife",9,"Loius Armstrong",12.2, false, "Todo"],
|
57
|
+
["Prince Igor",9,"Borodin",16.3, false, "WIP"],
|
58
|
+
["Shahbaaz Qalandar",9,"Nusrat Fateh Ali Khan",12.2, false, "Todo"],
|
59
|
+
["Raag Darbari",9,"Ustad Fateh Ali Khan",12.2, false, "Todo"],
|
60
|
+
["Yaad-e-Mustafa Aisi",9,"Santoo Khan",12.2, true, "Todo"],
|
61
|
+
["Chaconne",4,"Johann S Bach",12.42, true, "Postp"],
|
62
|
+
["Raag Jaunpuri",9,"Ustad Fateh Ali Khan",12.2, false, "Todo"],
|
63
|
+
["Dalaleragita",9,"Vaishnava",12.2, false, "Todo"],
|
64
|
+
["Prasada sevaya",9,"Vaishnava",12.2, false, "Todo"],
|
65
|
+
["Sri Rupamanjiri",9,"Vaishnava",12.2, false, "Todo"],
|
66
|
+
["M Vlast ",9,"Smetana",12.2, false, "Todo"],
|
67
|
+
["Jai Radha Madhava",163,"Jagjit Singh",5.4, false, "WIP"]]
|
68
|
+
|
69
|
+
colnames = %w[ Song Cat Artist Ratio Flag Status]
|
70
|
+
statuses = ["Todo", "WIP", "Fin", "Cancel", "Postp"]
|
71
|
+
|
72
|
+
atable = Table.new f1 do
|
73
|
+
name "mytable"
|
74
|
+
row 4
|
75
|
+
col 0
|
76
|
+
width 78
|
77
|
+
height 15
|
78
|
+
#title "A Table"
|
79
|
+
#title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
|
80
|
+
cell_editing_allowed true
|
81
|
+
editing_policy :EDITING_AUTO
|
82
|
+
set_data data, colnames
|
83
|
+
end
|
84
|
+
sel_col = Variable.new 0
|
85
|
+
sel_col.value = 0
|
86
|
+
tcm = atable.get_table_column_model
|
87
|
+
selcolname = atable.get_column_name sel_col.value
|
88
|
+
#
|
89
|
+
## key bindings fo atable
|
90
|
+
# column widths
|
91
|
+
tcm.column(0).width 24
|
92
|
+
tcm.column(1).width 5
|
93
|
+
tcm.column(2).width 18
|
94
|
+
#tcm.column(2).editable false
|
95
|
+
tcm.column(3).width 7
|
96
|
+
tcm.column(4).width 5
|
97
|
+
tcm.column(5).width 8
|
98
|
+
atable.configure() do
|
99
|
+
bind_key(330) { atable.remove_column(tcm.column(atable.focussed_col)) rescue "" }
|
100
|
+
bind_key(?+) {
|
101
|
+
acolumn = atable.get_column selcolname
|
102
|
+
w = acolumn.width + 1
|
103
|
+
acolumn.width w
|
104
|
+
#atable.table_structure_changed
|
105
|
+
}
|
106
|
+
bind_key(?-) {
|
107
|
+
acolumn = atable.get_column selcolname
|
108
|
+
w = acolumn.width - 1
|
109
|
+
if w > 3
|
110
|
+
acolumn.width w
|
111
|
+
#atable.table_structure_changed
|
112
|
+
end
|
113
|
+
}
|
114
|
+
bind_key(?>) {
|
115
|
+
colcount = tcm.column_count-1
|
116
|
+
#atable.move_column sel_col.value, sel_col.value+1 unless sel_col.value == colcount
|
117
|
+
col = atable.focussed_col
|
118
|
+
atable.move_column col, col+1 unless col == colcount
|
119
|
+
}
|
120
|
+
bind_key(?<) {
|
121
|
+
col = atable.focussed_col
|
122
|
+
atable.move_column col, col-1 unless col == 0
|
123
|
+
#atable.move_column sel_col.value, sel_col.value-1 unless sel_col.value == 0
|
124
|
+
}
|
125
|
+
#bind_key(KEY_RIGHT) { sel_col.value = sel_col.value+1; current_column sel_col.value}
|
126
|
+
#bind_key(KEY_LEFT) { sel_col.value = sel_col.value-1;current_column sel_col.value}
|
127
|
+
end
|
128
|
+
|
129
|
+
@tab2 = @tp.add_tab "&ScrollTable"
|
130
|
+
f2 = @tab2.form
|
131
|
+
scroll = ScrollPane.new f2 do
|
132
|
+
name "myScroller"
|
133
|
+
row 4
|
134
|
+
col 0
|
135
|
+
width w-2
|
136
|
+
height h-2
|
137
|
+
end
|
138
|
+
|
139
|
+
$log.debug " TABLE FORM 2 #{f2} "
|
140
|
+
btable = Table.new nil do
|
141
|
+
name "mytab2"
|
142
|
+
row 0
|
143
|
+
col 0
|
144
|
+
width 78
|
145
|
+
height 15
|
146
|
+
#title "A Table"
|
147
|
+
#title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
|
148
|
+
cell_editing_allowed true
|
149
|
+
editing_policy :EDITING_AUTO
|
150
|
+
set_data data, colnames
|
151
|
+
end
|
152
|
+
sel_col = Variable.new 0
|
153
|
+
sel_col.value = 0
|
154
|
+
tcm = btable.get_table_column_model
|
155
|
+
selcolname = btable.get_column_name sel_col.value
|
156
|
+
#
|
157
|
+
## key bindings fo atable
|
158
|
+
# column widths
|
159
|
+
tcm.column(0).width 24
|
160
|
+
tcm.column(1).width 5
|
161
|
+
tcm.column(2).width 18
|
162
|
+
#tcm.column(2).editable false
|
163
|
+
tcm.column(3).width 7
|
164
|
+
tcm.column(4).width 5
|
165
|
+
tcm.column(5).width 8
|
166
|
+
scroll.child(btable)
|
167
|
+
|
168
|
+
@help = "F1 to quit. Use any key of key combination to see what's caught. #{$0} Check logger too"
|
169
|
+
RubyCurses::Label.new @form, {'text' => @help, "row" => r+h+2, "col" => 2, "color" => "yellow"}
|
170
|
+
@form.repaint
|
171
|
+
@window.wrefresh
|
172
|
+
Ncurses::Panel.update_panels
|
173
|
+
while((ch = @window.getchar()) != KEY_F1 )
|
174
|
+
# @tp.repaint
|
175
|
+
@form.handle_key(ch)
|
176
|
+
@window.wrefresh
|
177
|
+
end
|
178
|
+
#@tp.show
|
179
|
+
#@tp.handle_keys
|
180
|
+
end
|
181
|
+
end
|
182
|
+
if $0 == __FILE__
|
183
|
+
# Initialize curses
|
184
|
+
begin
|
185
|
+
# XXX update with new color and kb
|
186
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
187
|
+
$log = Logger.new("view.log")
|
188
|
+
$log.level = Logger::DEBUG
|
189
|
+
n = TestTabbedPane.new
|
190
|
+
n.run
|
191
|
+
rescue => ex
|
192
|
+
ensure
|
193
|
+
VER::stop_ncurses
|
194
|
+
p ex if ex
|
195
|
+
p(ex.backtrace.join("\n")) if ex
|
196
|
+
$log.debug( ex) if ex
|
197
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
198
|
+
end
|
199
|
+
end
|