rbcurse 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1570 -0
- data/History.txt +6 -0
- data/Manifest.txt +54 -0
- data/README.txt +304 -0
- data/Rakefile +28 -0
- data/examples/qdfilechooser.rb +68 -0
- data/examples/rfe.rb +853 -0
- data/examples/rfe_renderer.rb +69 -0
- data/examples/test1.rb +242 -0
- data/examples/test2.rb +498 -0
- data/examples/testcombo.rb +95 -0
- data/examples/testkeypress.rb +61 -0
- data/examples/testmenu.rb +105 -0
- data/examples/testtable.rb +266 -0
- data/examples/testtabp.rb +106 -0
- data/examples/testtodo.rb +532 -0
- data/examples/viewtodo.rb +512 -0
- data/lib/rbcurse/action.rb +31 -0
- data/lib/rbcurse/applicationheader.rb +57 -0
- data/lib/rbcurse/celleditor.rb +120 -0
- data/lib/rbcurse/checkboxcellrenderer.rb +69 -0
- data/lib/rbcurse/colormap.rb +133 -0
- data/lib/rbcurse/comboboxcellrenderer.rb +45 -0
- data/lib/rbcurse/defaultlistselectionmodel.rb +49 -0
- data/lib/rbcurse/keylabelprinter.rb +143 -0
- data/lib/rbcurse/listcellrenderer.rb +99 -0
- data/lib/rbcurse/listkeys.rb +33 -0
- data/lib/rbcurse/listscrollable.rb +216 -0
- data/lib/rbcurse/listselectable.rb +67 -0
- data/lib/rbcurse/mapper.rb +108 -0
- data/lib/rbcurse/orderedhash.rb +77 -0
- data/lib/rbcurse/rcombo.rb +243 -0
- data/lib/rbcurse/rdialogs.rb +183 -0
- data/lib/rbcurse/rform.rb +845 -0
- data/lib/rbcurse/rinputdataevent.rb +36 -0
- data/lib/rbcurse/rlistbox.rb +804 -0
- data/lib/rbcurse/rmenu.rb +666 -0
- data/lib/rbcurse/rmessagebox.rb +325 -0
- data/lib/rbcurse/rpopupmenu.rb +754 -0
- data/lib/rbcurse/rtabbedpane.rb +259 -0
- data/lib/rbcurse/rtable.rb +1296 -0
- data/lib/rbcurse/rtextarea.rb +673 -0
- data/lib/rbcurse/rtextview.rb +335 -0
- data/lib/rbcurse/rwidget.rb +1731 -0
- data/lib/rbcurse/scrollable.rb +301 -0
- data/lib/rbcurse/selectable.rb +94 -0
- data/lib/rbcurse/table/tablecellrenderer.rb +85 -0
- data/lib/rbcurse/table/tabledatecellrenderer.rb +102 -0
- data/lib/rbcurse.rb +7 -0
- data/lib/ver/keyboard.rb +150 -0
- data/lib/ver/keyboard2.rb +170 -0
- data/lib/ver/ncurses.rb +102 -0
- data/lib/ver/window.rb +369 -0
- data/test/test_rbcurse.rb +0 -0
- metadata +118 -0
@@ -0,0 +1,259 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: tabbed pane: can have multiple forms overlapping.
|
3
|
+
* Description:
|
4
|
+
* Author: rkumar
|
5
|
+
|
6
|
+
--------
|
7
|
+
* Date: 2008-12-13 13:06
|
8
|
+
* License:
|
9
|
+
Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
10
|
+
|
11
|
+
=end
|
12
|
+
require 'rubygems'
|
13
|
+
require 'ncurses'
|
14
|
+
require 'logger'
|
15
|
+
require 'rbcurse'
|
16
|
+
|
17
|
+
include Ncurses
|
18
|
+
include RubyCurses
|
19
|
+
module RubyCurses
|
20
|
+
extend self
|
21
|
+
|
22
|
+
# TODO : insert_tab, remove_tab, disable/hide tab
|
23
|
+
# Hotkeys should be defined with ampersand, too.
|
24
|
+
#
|
25
|
+
# Multiple independent overlapping forms using the tabbed metaphor.
|
26
|
+
class TabbedButton < RubyCurses::RadioButton
|
27
|
+
def getvalue_for_paint
|
28
|
+
@text
|
29
|
+
end
|
30
|
+
##
|
31
|
+
# highlight abd selected colors and attribs should perhaps be in a
|
32
|
+
# structure, so user can override easily
|
33
|
+
def repaint # tabbedbutton
|
34
|
+
# $log.debug("BUTTon repaint : #{self.class()} r:#{@row} c:#{@col} #{getvalue_for_paint}" )
|
35
|
+
r,c = rowcol
|
36
|
+
attribs = @attrs
|
37
|
+
@highlight_foreground ||= $reversecolor
|
38
|
+
@highlight_background ||= 0
|
39
|
+
_state = @state
|
40
|
+
_state = :SELECTED if @variable.value == @value
|
41
|
+
case _state
|
42
|
+
when :HIGHLIGHTED
|
43
|
+
bgcolor = @highlight_background
|
44
|
+
color = @highlight_foreground
|
45
|
+
bgcolor = @bgcolor
|
46
|
+
color = @color
|
47
|
+
attribs = Ncurses::A_BOLD
|
48
|
+
when :SELECTED
|
49
|
+
bgcolor = @bgcolor
|
50
|
+
color = @color
|
51
|
+
attribs = Ncurses::A_REVERSE
|
52
|
+
else
|
53
|
+
bgcolor = @bgcolor
|
54
|
+
color = @color
|
55
|
+
end
|
56
|
+
#bgcolor = @state==:HIGHLIGHTED ? @highlight_background : @bgcolor
|
57
|
+
#color = @state==:HIGHLIGHTED ? @highlight_foreground : @color
|
58
|
+
if bgcolor.is_a? String and color.is_a? String
|
59
|
+
color = ColorMap.get_color(color, bgcolor)
|
60
|
+
end
|
61
|
+
value = getvalue_for_paint
|
62
|
+
# $log.debug("button repaint : r:#{r} c:#{c} col:#{color} bg #{bgcolor} v: #{value} ")
|
63
|
+
len = @display_length || value.length
|
64
|
+
@form.window.printstring r, c, "%-*s" % [len, value], color, attribs
|
65
|
+
# @form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, bgcolor, nil)
|
66
|
+
if @underline != nil
|
67
|
+
# changed +1 to +0 on 2008-12-15 21:23 pls check.
|
68
|
+
@form.window.mvchgat(y=r, x=c+@underline+0, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, color, nil)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
class TabbedPane
|
73
|
+
include DSL
|
74
|
+
include EventHandler
|
75
|
+
dsl_accessor :row, :col
|
76
|
+
dsl_accessor :height, :width
|
77
|
+
def initialize win, aconfig={}, &block
|
78
|
+
@parent = win
|
79
|
+
@tabs ||= []
|
80
|
+
@forms ||= []
|
81
|
+
@bgcolor ||= "black" # 0
|
82
|
+
@color ||= "white" # $datacolor
|
83
|
+
@attr = nil
|
84
|
+
@current_form = nil
|
85
|
+
@current_tab = nil
|
86
|
+
@config = aconfig
|
87
|
+
@config.each_pair { |k,v| variable_set(k,v) }
|
88
|
+
instance_eval &block if block_given?
|
89
|
+
end
|
90
|
+
##
|
91
|
+
# when adding tabs, you may use ampersand in text to create hotkey
|
92
|
+
def add_tab text, aconfig={}, &block
|
93
|
+
#create a button here and block is taken care of in button's instance
|
94
|
+
#or push this for later creation.
|
95
|
+
@tabs << Tab.new(text, aconfig, &block)
|
96
|
+
tab = @tabs.last
|
97
|
+
@forms << create_tab_form(tab)
|
98
|
+
tab.form = @forms.last
|
99
|
+
return tab
|
100
|
+
end
|
101
|
+
# private
|
102
|
+
def variable_set var, val
|
103
|
+
var = "@#{var}"
|
104
|
+
instance_variable_set(var, val)
|
105
|
+
end
|
106
|
+
# private
|
107
|
+
def configure(*val , &block)
|
108
|
+
case val.size
|
109
|
+
when 1
|
110
|
+
return @config[val[0]]
|
111
|
+
when 2
|
112
|
+
@config[val[0]] = val[1]
|
113
|
+
variable_set(val[0], val[1])
|
114
|
+
end
|
115
|
+
instance_eval &block if block_given?
|
116
|
+
end
|
117
|
+
def repaint
|
118
|
+
@window || create_window
|
119
|
+
@window.show
|
120
|
+
end
|
121
|
+
def show
|
122
|
+
repaint
|
123
|
+
end
|
124
|
+
def create_window
|
125
|
+
# first create the main top window with the tab buttons on it.
|
126
|
+
@layout = { :height => @height, :width => @width, :top => @row, :left => @col }
|
127
|
+
@window = VER::Window.new(@layout)
|
128
|
+
@form = RubyCurses::Form.new @window
|
129
|
+
@form.navigation_policy = :NON_CYCLICAL
|
130
|
+
@current_form = @form
|
131
|
+
@window.bkgd(Ncurses.COLOR_PAIR($datacolor));
|
132
|
+
@window.box( 0, 0);
|
133
|
+
@window.wrefresh
|
134
|
+
Ncurses::Panel.update_panels
|
135
|
+
col = 1
|
136
|
+
@buttons = []
|
137
|
+
## create a button for each tab
|
138
|
+
$tabradio = Variable.new
|
139
|
+
@tabs.each do |tab|
|
140
|
+
text = tab.text
|
141
|
+
@buttons << RubyCurses::TabbedButton.new(@form) do
|
142
|
+
variable $tabradio
|
143
|
+
text text
|
144
|
+
name text
|
145
|
+
value text
|
146
|
+
row 1
|
147
|
+
col col
|
148
|
+
end
|
149
|
+
col += text.length+4
|
150
|
+
# @forms << create_tab_form(tab)
|
151
|
+
# form = @forms.last
|
152
|
+
form = tab.form
|
153
|
+
form.window = @window if form.window.nil? ## XXX
|
154
|
+
panel = form.window.panel
|
155
|
+
@buttons.last.command { Ncurses::Panel.top_panel(panel)
|
156
|
+
Ncurses::Panel.update_panels();
|
157
|
+
Ncurses.doupdate();
|
158
|
+
form.repaint
|
159
|
+
@current_form = form
|
160
|
+
@current_tab = form
|
161
|
+
}
|
162
|
+
|
163
|
+
end
|
164
|
+
@form.repaint
|
165
|
+
end
|
166
|
+
def display_form form
|
167
|
+
panel = form.window.panel
|
168
|
+
Ncurses::Panel.top_panel(panel)
|
169
|
+
Ncurses::Panel.update_panels();
|
170
|
+
Ncurses.doupdate();
|
171
|
+
form.repaint
|
172
|
+
end
|
173
|
+
def create_tab_form tab
|
174
|
+
layout = { :height => @height-2, :width => @width, :top => @row+2, :left => @col }
|
175
|
+
window = VER::Window.new(layout)
|
176
|
+
form = RubyCurses::Form.new window
|
177
|
+
form.navigation_policy = :NON_CYCLICAL
|
178
|
+
window.bkgd(Ncurses.COLOR_PAIR($datacolor));
|
179
|
+
window.box( 0, 0);
|
180
|
+
window.mvprintw(1,1, tab.text.tr('&', ''))
|
181
|
+
##window.wrefresh
|
182
|
+
##Ncurses::Panel.update_panels
|
183
|
+
return form
|
184
|
+
end
|
185
|
+
def handle_keys
|
186
|
+
while (( ch=@window.getchar()) != KEY_F1)
|
187
|
+
@current_form ||= @form
|
188
|
+
ret = @current_form.handle_key(ch)
|
189
|
+
case ret
|
190
|
+
when :NO_NEXT_FIELD
|
191
|
+
if @current_form != @form
|
192
|
+
@current_form = @form
|
193
|
+
#@current_form.select_field -1
|
194
|
+
@current_form.req_first_field
|
195
|
+
#ret = @current_form.handle_key(ch)
|
196
|
+
else
|
197
|
+
if !@current_tab.nil?
|
198
|
+
@current_form = @current_tab
|
199
|
+
display_form @current_form
|
200
|
+
@current_form.req_first_field
|
201
|
+
#@current_form.select_field -1
|
202
|
+
#ret = @current_form.handle_key(ch)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
when :NO_PREV_FIELD
|
206
|
+
if @current_form != @form
|
207
|
+
$log.debug " 1 no prev field - going to button "
|
208
|
+
@current_form = @form
|
209
|
+
@current_form.req_last_field
|
210
|
+
else
|
211
|
+
if !@current_tab.nil?
|
212
|
+
@current_form = @current_tab
|
213
|
+
display_form @current_form
|
214
|
+
@current_form.req_last_field
|
215
|
+
end
|
216
|
+
end
|
217
|
+
when :UNHANDLED
|
218
|
+
$log.debug " unhandled in tabbed pane #{ch}"
|
219
|
+
ret = @form.process_key ch, self # field
|
220
|
+
@form.repaint
|
221
|
+
#return :UNHANDLED if ret == :UNHANDLED
|
222
|
+
end
|
223
|
+
@current_form.window.wrefresh
|
224
|
+
@window.refresh
|
225
|
+
end
|
226
|
+
destroy
|
227
|
+
end
|
228
|
+
def destroy
|
229
|
+
@window.destroy
|
230
|
+
@forms.each { |f| w = f.window; w.destroy unless w.nil? }
|
231
|
+
end
|
232
|
+
|
233
|
+
##
|
234
|
+
# nested class tab
|
235
|
+
class Tab
|
236
|
+
attr_reader :text
|
237
|
+
attr_reader :config
|
238
|
+
attr_accessor :form
|
239
|
+
def initialize text, aconfig={}, &block
|
240
|
+
@text = text
|
241
|
+
@config = aconfig
|
242
|
+
@config.each_pair { |k,v| variable_set(k,v) }
|
243
|
+
instance_eval &block if block_given?
|
244
|
+
end
|
245
|
+
# private
|
246
|
+
def variable_set var, val
|
247
|
+
var = "@#{var}"
|
248
|
+
instance_variable_set(var, val)
|
249
|
+
end
|
250
|
+
def repaint
|
251
|
+
|
252
|
+
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
end # class Tabbedpane
|
257
|
+
|
258
|
+
|
259
|
+
end # module
|