Class: RubyCurses::TabbedWindow
- Inherits:
-
Object
- Object
- RubyCurses::TabbedWindow
show all
- Includes:
- DSL, EventHandler
- Defined in:
- lib/rbcurse/rtabbedwindow.rb
Defined Under Namespace
Classes: Tab
Instance Attribute Summary collapse
Instance Method Summary
collapse
#bind, #fire_handler, #fire_property_change
Methods included from DSL
#OLD_method_missing
Constructor Details
#initialize(win, aconfig = {}, &block) ⇒ TabbedWindow
Returns a new instance of TabbedWindow.
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 85
def initialize win, aconfig={}, &block
@parent = win
@tabs ||= []
@forms ||= []
@bgcolor ||= "black" @color ||= "white" @attr = nil
@current_form = nil
@current_tab = nil
@config = aconfig
@config.each_pair { |k,v| variable_set(k,v) }
instance_eval &block if block_given?
end
|
Instance Attribute Details
#selected_index ⇒ Object
Returns the value of attribute selected_index.
84
85
86
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 84
def selected_index
@selected_index
end
|
Instance Method Details
#add_tab(text, aconfig = {}, &block) ⇒ Object
when adding tabs, you may use ampersand in text to create hotkey
100
101
102
103
104
105
106
107
108
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 100
def add_tab text, aconfig={}, &block
@tabs << Tab.new(text, aconfig, &block)
tab = @tabs.last
@forms << create_tab_form(tab)
tab.form = @forms.last
return tab
end
|
#center_column(textlen) ⇒ Object
295
296
297
298
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 295
def center_column textlen
width = @layout[:width]
return (width-textlen)/2
end
|
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 115
def configure(*val , &block)
case val.size
when 1
return @config[val[0]]
when 2
@config[val[0]] = val[1]
variable_set(val[0], val[1])
end
instance_eval &block if block_given?
end
|
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 251
def create_buttons
case @button_type.to_s.downcase
when "ok"
make_buttons ["&OK"]
when "ok_cancel" make_buttons %w[&OK &Cancel]
when "yes_no"
make_buttons %w[&Yes &No]
when "yes_no_cancel"
make_buttons ["&Yes", "&No", "&Cancel"]
when "custom"
raise "Blank list of buttons passed to custom" if @buttons.nil? or @buttons.size == 0
make_buttons @buttons
else
$log.debug "No buttontype passed for creating tabbedpane. Using default (OK)"
make_buttons ["&OK"]
end
end
|
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 182
def create_tab_form tab
layout = { :height => @height-2, :width => @width, :top => @row+2, :left => @col }
window = VER::Window.new(layout)
form = RubyCurses::Form.new window
form.navigation_policy = :NON_CYCLICAL
window.bkgd(Ncurses.COLOR_PAIR($datacolor));
window.box( 0, 0);
window.mvprintw(1,1, tab.text.tr('&', ''))
return form
end
|
#create_window ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 132
def create_window
@layout = { :height => @height, :width => @width, :top => @row, :left => @col }
@window = VER::Window.new(@layout)
@form = RubyCurses::Form.new @window
@form.navigation_policy = :NON_CYCLICAL
@current_form = @form
@window.bkgd(Ncurses.COLOR_PAIR($datacolor));
@window.box( 0, 0);
@window.wrefresh
Ncurses::Panel.update_panels
col = 1
@buttons = []
$tabradio = Variable.new
@tabs.each do |tab|
text = tab.text
@buttons << RubyCurses::TabbedButton.new(@form) do
variable $tabradio
text text
name text
value text
row 1
col col
end
col += text.length+4
form = tab.form
form.window = @window if form.window.nil? panel = form.window.panel
@buttons.last.command { Ncurses::Panel.top_panel(panel)
Ncurses::Panel.update_panels();
Ncurses.doupdate();
form.repaint
@current_form = form
@current_tab = form
}
end
create_buttons
@form.repaint
end
|
#destroy ⇒ Object
247
248
249
250
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 247
def destroy
@window.destroy
@forms.each { |f| w = f.window; w.destroy unless w.nil? }
end
|
175
176
177
178
179
180
181
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 175
def display_form form
panel = form.window.panel
Ncurses::Panel.top_panel(panel)
Ncurses::Panel.update_panels();
Ncurses.doupdate();
form.repaint
end
|
#handle_keys ⇒ Object
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 194
def handle_keys
begin
while (( ch=@window.getchar()) != 999)
if ch == ?\C-q.getbyte(0)
@selected_index = -1 @stop = true
return
end
return if @stop
@current_form ||= @form
ret = @current_form.handle_key(ch)
case ret
when :NO_NEXT_FIELD
if @current_form != @form
@current_form = @form
@current_form.req_first_field
else
if !@current_tab.nil?
@current_form = @current_tab
display_form @current_form
@current_form.req_first_field
end
end
when :NO_PREV_FIELD
if @current_form != @form
$log.debug " 1 no prev field - going to button "
@current_form = @form
@current_form.req_last_field
else
if !@current_tab.nil?
@current_form = @current_tab
display_form @current_form
@current_form.req_last_field
end
end
when :UNHANDLED
$log.debug " unhandled in tabbed pane #{ch}"
ret = @form.process_key ch, self @form.repaint
end
return if @stop
@current_form.window.wrefresh
@window.refresh
end
ensure
destroy
end
end
|
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 269
def make_buttons names
total = names.inject(0) {|total, item| total + item.length + 4}
bcol = center_column total
brow = @layout[:height]-2
button_ct=0
names.each_with_index do |bname, ix|
text = bname
button = Button.new @form do
text text
name bname
row brow
col bcol
highlight_background $reversecolor
color $datacolor
bgcolor $datacolor
end
index = button_ct
button.command { |form| @selected_index = index; @stop = true; $log.debug "Pressed Button #{bname}";}
button_ct += 1
bcol += text.length+6
end
end
|
#repaint ⇒ Object
125
126
127
128
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 125
def repaint
@window || create_window
@window.show
end
|
#show ⇒ Object
129
130
131
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 129
def show
repaint
end
|
#variable_set(var, val) ⇒ Object
110
111
112
113
|
# File 'lib/rbcurse/rtabbedwindow.rb', line 110
def variable_set var, val
var = "@#{var}"
instance_variable_set(var, val)
end
|