Class: RubyCurses::PopupList
- Inherits:
-
Object
- Object
- RubyCurses::PopupList
- Includes:
- DSL, EventHandler
- Defined in:
- lib/rbcurse/rlistbox.rb
Overview
pops up a list of values for selection 2008-12-10
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#listbox ⇒ Object
readonly
Returns the value of attribute listbox.
-
#selected_index ⇒ Object
readonly
button index selected by user.
-
#window ⇒ Object
readonly
required for keyboard.
Instance Method Summary collapse
- #cget(param) ⇒ Object
-
#configure(*val, &block) ⇒ Object
may need to be upgraded to new one XXX FIXME.
- #destroy ⇒ Object
-
#handle_keys ⇒ Object
popuplist.
-
#initialize(aconfig = {}, &block) ⇒ PopupList
constructor
A new instance of PopupList.
- #input_value ⇒ Object
- #layout(height = 0, width = 0, top = 0, left = 0) ⇒ Object
- #list(alist = nil) ⇒ Object
-
#list_data_model(ldm) ⇒ Object
will we need this ? listbox made each time so data should be fresh @list.bind(:LIST_DATA_EVENT) { |e| list_data_changed() }.
-
#press(ch) ⇒ Object
TODO get next match for key.
- #print_input ⇒ Object
-
#stopping? ⇒ Boolean
popuplist.
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Methods included from DSL
Constructor Details
#initialize(aconfig = {}, &block) ⇒ PopupList
Returns a new instance of PopupList.
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 |
# File 'lib/rbcurse/rlistbox.rb', line 200 def initialize aconfig={}, &block @config = aconfig @selected_index = -1 @list_config ||= {} @config.each_pair { |k,v| instance_variable_set("@#{k}",v) } instance_eval &block if block_given? @list_config.each_pair { |k,v| instance_variable_set("@#{k}",v) } @height ||= [@max_visible_items || 10, @list.length].min $log.debug " POPUP XXX #{@max_visible_items} ll:#{@list.length} h:#{@height}" # get widgets absolute coords if !@relative_to.nil? layout = @relative_to.form.window.layout @row = @row + layout[:top] @col = @col + layout[:left] end if !@valign.nil? case @valign.to_sym when :BELOW @row += 1 when :ABOVE @row -= @height+1 @row = 0 if @row < 0 when :CENTER @row -= @height/2 @row = 0 if @row < 0 else end end layout(1+height, @width+4, @row, @col) # changed 2 to 1, 2008-12-17 13:48 @window = VER::Window.new(@layout) @form = RubyCurses::Form.new @window @window.bkgd(Ncurses.COLOR_PAIR($reversecolor)); @window.wrefresh @panel = @window.panel # useless line ? Ncurses::Panel.update_panels print_input # creates the listbox @form.repaint @window.wrefresh handle_keys end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
189 190 191 |
# File 'lib/rbcurse/rlistbox.rb', line 189 def config @config end |
#listbox ⇒ Object (readonly)
Returns the value of attribute listbox.
198 199 200 |
# File 'lib/rbcurse/rlistbox.rb', line 198 def listbox @listbox end |
#selected_index ⇒ Object (readonly)
button index selected by user
190 191 192 |
# File 'lib/rbcurse/rlistbox.rb', line 190 def selected_index @selected_index end |
#window ⇒ Object (readonly)
required for keyboard
191 192 193 |
# File 'lib/rbcurse/rlistbox.rb', line 191 def window @window end |
Instance Method Details
#cget(param) ⇒ Object
355 356 357 |
# File 'lib/rbcurse/rlistbox.rb', line 355 def cget param @config[param] end |
#configure(*val, &block) ⇒ Object
may need to be upgraded to new one XXX FIXME
345 346 347 348 349 350 351 352 353 354 |
# File 'lib/rbcurse/rlistbox.rb', line 345 def configure(*val , &block) case val.size when 1 return @config[val[0]] when 2 @config[val[0]] = val[1] instance_variable_set("@#{val[0]}", val[1]) end instance_eval &block if block_given? end |
#destroy ⇒ Object
362 363 364 |
# File 'lib/rbcurse/rlistbox.rb', line 362 def destroy @window.destroy if !@window.nil? end |
#handle_keys ⇒ Object
popuplist
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/rbcurse/rlistbox.rb', line 263 def handle_keys begin while((ch = @window.getchar()) != 999 ) case ch when -1 next else press ch break if @stop end end ensure destroy end return 0 #@selected_index end |
#input_value ⇒ Object
254 255 256 257 |
# File 'lib/rbcurse/rlistbox.rb', line 254 def input_value #return @listbox.getvalue if [email protected]? return @listbox.focussed_index if !@listbox.nil? end |
#layout(height = 0, width = 0, top = 0, left = 0) ⇒ Object
359 360 361 |
# File 'lib/rbcurse/rlistbox.rb', line 359 def layout(height=0, width=0, top=0, left=0) @layout = { :height => height, :width => width, :top => top, :left => left } end |
#list(alist = nil) ⇒ Object
241 242 243 244 245 246 |
# File 'lib/rbcurse/rlistbox.rb', line 241 def list alist=nil return @list if alist.nil? @list = ListDataModel.new(alist) # will we need this ? listbox made each time so data should be fresh #@list.bind(:LIST_DATA_EVENT) { |e| list_data_changed() } end |
#list_data_model(ldm) ⇒ Object
will we need this ? listbox made each time so data should be fresh @list.bind(:LIST_DATA_EVENT) { |e| list_data_changed() }
247 248 249 250 251 252 |
# File 'lib/rbcurse/rlistbox.rb', line 247 def list_data_model ldm raise "Expecting list_data_model" unless ldm.is_a? RubyCurses::ListDataModel @list = ldm # will we need this ? listbox made each time so data should be fresh #@list.bind(:LIST_DATA_EVENT) { |e| list_data_changed() } end |
#press(ch) ⇒ Object
TODO get next match for key
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/rbcurse/rlistbox.rb', line 281 def press ch $log.debug "popup handle_keys : #{ch}" if ch != -1 case ch when -1 return when KEY_F1, 27, ?\C-q # 27/ESC does not come here since gobbled by keyboard.rb @stop = true return when KEY_ENTER, 10, 13 fire_handler :PRESS, @listbox.focussed_index # since Listbox is handling enter, COMBO_SELECT will not be fired # $log.debug "popup ENTER : #{@selected_index} " # $log.debug "popup ENTER : #{field.name}" if !field.nil? @stop = true return when 9 @form.select_next_field else # fields must return unhandled else we will miss hotkeys. # On messageboxes, often if no edit field, then O and C are hot. field = @form.get_current_field handled = field.handle_key ch if handled == :UNHANDLED @stop = true return end end @form.repaint Ncurses::Panel.update_panels(); Ncurses.doupdate(); @window.wrefresh end |
#print_input ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/rbcurse/rlistbox.rb', line 314 def print_input r = c = 0 width = @layout[:width] #$log.debug " print_input POPUP ht:#{@height} lh:#{@layout[:height]} " height = @layout[:height] #height = @height # 2010-01-06 12:52 why was this overriding previous line. its one less than layout # i am now using layout height since it gives a closer size to whats asked for. parent = @relative_to defaultvalue = @default_value || "" list = @list selection_mode = @list_selection_mode default_values = @default_values @list_config['color'] ||= 'black' @list_config['bgcolor'] ||= 'yellow' @listbox = RubyCurses::Listbox.new @form, @list_config do name "input" row r col c # attr 'reverse' width width height height list_data_model list # ?? XXX display_length 30 # set_buffer defaultvalue selection_mode selection_mode default_values default_values is_popup true #add_observer parent end end |
#stopping? ⇒ Boolean
popuplist
259 260 261 |
# File 'lib/rbcurse/rlistbox.rb', line 259 def stopping? @stop end |