Class: RubyCurses::MenuBar
- Inherits:
-
Object
- Object
- RubyCurses::MenuBar
- Defined in:
- lib/rbcurse/rmenu.rb,
lib/rbcurse/rpopupmenu.rb
Overview
An application related menubar. Currently, I am adding this to a form. But should this not be application specific ? It should popup no matter which window you are on ?? XXX
Instance Attribute Summary collapse
-
#active_index ⇒ Object
Returns the value of attribute active_index.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#panel ⇒ Object
readonly
Returns the value of attribute panel.
-
#selected ⇒ Object
readonly
Returns the value of attribute selected.
-
#state ⇒ Object
normal, selected, highlighted.
-
#toggle_key ⇒ Object
key used to popup, should be set prior to attaching to form.
-
#visible ⇒ Object
Returns the value of attribute visible.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #add(menu) ⇒ Object
- #create_window ⇒ Object
- #current_menu ⇒ Object
- #destroy ⇒ Object
- #focusable ⇒ Object
-
#handle_keys ⇒ Object
menubar LEFT, RIGHT, DOWN.
- #hide ⇒ Object
- #init_vars ⇒ Object
-
#initialize(&block) ⇒ MenuBar
constructor
A new instance of MenuBar.
- #next_menu ⇒ Object
- #prev_menu ⇒ Object
-
#repaint ⇒ Object
menubar.
- #set_menu(index) ⇒ Object
- #show ⇒ Object
- #toggle ⇒ Object
Constructor Details
#initialize(&block) ⇒ MenuBar
Returns a new instance of MenuBar.
453 454 455 456 457 458 459 460 |
# File 'lib/rbcurse/rmenu.rb', line 453 def initialize &block @window = nil @items = [] init_vars @visible = false @cols = Ncurses.COLS-1 instance_eval &block if block_given? end |
Instance Attribute Details
#active_index ⇒ Object
Returns the value of attribute active_index.
450 451 452 |
# File 'lib/rbcurse/rmenu.rb', line 450 def active_index @active_index end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
445 446 447 |
# File 'lib/rbcurse/rmenu.rb', line 445 def items @items end |
#panel ⇒ Object (readonly)
Returns the value of attribute panel.
447 448 449 |
# File 'lib/rbcurse/rmenu.rb', line 447 def panel @panel end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
448 449 450 |
# File 'lib/rbcurse/rmenu.rb', line 448 def selected @selected end |
#state ⇒ Object
normal, selected, highlighted
451 452 453 |
# File 'lib/rbcurse/rmenu.rb', line 451 def state @state end |
#toggle_key ⇒ Object
key used to popup, should be set prior to attaching to form
452 453 454 |
# File 'lib/rbcurse/rmenu.rb', line 452 def toggle_key @toggle_key end |
#visible ⇒ Object
Returns the value of attribute visible.
449 450 451 |
# File 'lib/rbcurse/rmenu.rb', line 449 def visible @visible end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
446 447 448 |
# File 'lib/rbcurse/rmenu.rb', line 446 def window @window end |
Instance Method Details
#add(menu) ⇒ Object
467 468 469 470 |
# File 'lib/rbcurse/rmenu.rb', line 467 def add @items << return self end |
#create_window ⇒ Object
599 600 601 602 603 604 605 606 |
# File 'lib/rbcurse/rmenu.rb', line 599 def create_window @layout = { :height => 1, :width => 0, :top => 0, :left => 0 } @win = VER::Window.new(@layout) @window = @win @win.bkgd(Ncurses.COLOR_PAIR(5)); @panel = @win.panel return @window end |
#current_menu ⇒ Object
561 562 563 |
# File 'lib/rbcurse/rmenu.rb', line 561 def @items[@active_index] end |
#destroy ⇒ Object
607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/rbcurse/rmenu.rb', line 607 def destroy $log.debug "DESTRY menubar " @visible = false panel = @window.panel Ncurses::Panel.del_panel(panel) if !panel.nil? @window.delwin if !@window.nil? @items.each do |item| item.destroy end @window = nil end |
#focusable ⇒ Object
464 465 466 |
# File 'lib/rbcurse/rmenu.rb', line 464 def focusable false end |
#handle_keys ⇒ Object
menubar LEFT, RIGHT, DOWN
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/rbcurse/rmenu.rb', line 499 def handle_keys @selected = false @toggle_key ||= 27 # default switch off with ESC, if nothing else defined 0 begin catch(:menubarclose) do while((ch = @window.getchar()) != @toggle_key ) $log.debug "menuubar inside handle_keys : #{ch}" if ch != -1 case ch when -1 next when KEY_DOWN $log.debug "insdie keyDOWN : #{ch}" if !@selected .fire else .handle_key ch end @selected = true when KEY_ENTER, 10, 13, 32 @selected = true $log.debug " mb insdie ENTER : #{}" ret = .handle_key ch $log.debug "ret = #{ret} mb insdie ENTER : #{}" #break; ## 2008-12-29 18:00 This will close after firing #anything break if ret == :CLOSE when KEY_UP $log.debug " mb insdie keyUPP : #{ch}" .handle_key ch when KEY_LEFT $log.debug " mb insdie KEYLEFT : #{ch}" ret = .handle_key ch if ret == :UNHANDLED #display_items if @selected when KEY_RIGHT $log.debug " mb insdie KEYRIGHT : #{ch}" ret = .handle_key ch if ret == :UNHANDLED else $log.debug " mb insdie ELSE : #{ch}" ret = .handle_key ch if ret == :UNHANDLED Ncurses.beep else break # we handled a menu action, close menubar (THIS WORKS FOR MNEMONICS ONLY and always) end end Ncurses::Panel.update_panels(); Ncurses.doupdate(); @window.wrefresh end end # catch ensure #ensure is required becos one can throw a :close $log.debug " DESTROY IN ENSURE" . #@@menus = [] # added 2009-01-23 13:21 destroy # Note that we destroy the menu bar upon exit end end |
#hide ⇒ Object
574 575 576 577 |
# File 'lib/rbcurse/rmenu.rb', line 574 def hide @visible = false @window.hide if !@window.nil? end |
#init_vars ⇒ Object
461 462 463 |
# File 'lib/rbcurse/rmenu.rb', line 461 def init_vars @active_index = 0 end |
#next_menu ⇒ Object
471 472 473 474 475 476 477 478 |
# File 'lib/rbcurse/rmenu.rb', line 471 def $log.debug "next meu: #{@active_index} " if @active_index < @items.length-1 @active_index + 1 else 0 end end |
#prev_menu ⇒ Object
479 480 481 482 483 484 485 486 |
# File 'lib/rbcurse/rmenu.rb', line 479 def $log.debug "prev meu: #{@active_index} " if @active_index > 0 @active_index-1 else @items.length-1 end end |
#repaint ⇒ Object
menubar
587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/rbcurse/rmenu.rb', line 587 def repaint return if !@visible @window ||= create_window @window.printstring( 0, 0, "%-*s" % [@cols," "], $reversecolor) c = 1; r = 0; @items.each do |item| item.row = r; item.col = c; item.parent = self @window.printstring( r, c, " %s " % item.text, $reversecolor) c += (item.text.length + 2) end @window.wrefresh end |
#set_menu(index) ⇒ Object
487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/rbcurse/rmenu.rb', line 487 def index $log.debug "set meu: #{@active_index} #{index}" = @items[@active_index] .on_leave # hide its window, if open @active_index = index = @items[@active_index] .on_enter #display window, if previous was displayed @window.wmove .row, .col # menu.show # menu.window.wrefresh # XXX we need this end |
#show ⇒ Object
578 579 580 581 582 583 584 585 |
# File 'lib/rbcurse/rmenu.rb', line 578 def show @visible = true if @window.nil? repaint # XXX FIXME else @window.show end end |
#toggle ⇒ Object
564 565 566 567 568 569 570 571 572 573 |
# File 'lib/rbcurse/rmenu.rb', line 564 def toggle @items.each { |i| $log.debug " ITEM DDD : #{i.text}" } @visible = !@visible if !@visible hide else init_vars show end end |