Class: RubyCurses::PMenuBar
- Inherits:
-
Object
- Object
- RubyCurses::PMenuBar
- Defined in:
- lib/rbcurse/extras/widgets/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
-
#initialize(&block) ⇒ PMenuBar
constructor
A new instance of PMenuBar.
- #next_menu ⇒ Object
- #prev_menu ⇒ Object
-
#repaint ⇒ Object
menubar.
- #set_menu(index) ⇒ Object
- #show ⇒ Object
- #toggle ⇒ Object
Constructor Details
#initialize(&block) ⇒ PMenuBar
Returns a new instance of PMenuBar.
549 550 551 552 553 554 555 556 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 549 def initialize &block @window = nil @active_index = 0 @items = [] @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.
546 547 548 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 546 def active_index @active_index end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
541 542 543 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 541 def items @items end |
#panel ⇒ Object (readonly)
Returns the value of attribute panel.
543 544 545 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 543 def panel @panel end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
544 545 546 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 544 def selected @selected end |
#state ⇒ Object
normal, selected, highlighted
547 548 549 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 547 def state @state end |
#toggle_key ⇒ Object
key used to popup, should be set prior to attaching to form
548 549 550 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 548 def toggle_key @toggle_key end |
#visible ⇒ Object
Returns the value of attribute visible.
545 546 547 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 545 def visible @visible end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
542 543 544 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 542 def window @window end |
Instance Method Details
#add(menu) ⇒ Object
560 561 562 563 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 560 def add @items << return self end |
#create_window ⇒ Object
688 689 690 691 692 693 694 695 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 688 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
652 653 654 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 652 def @items[@active_index] end |
#destroy ⇒ Object
696 697 698 699 700 701 702 703 704 705 706 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 696 def destroy $log.debug "DESTRY menubar " @visible = false panel = @window.panel Ncurses::Panel.del_panel(panel.pointer) if !panel.nil? @window.delwin if !@window.nil? @items.each do |item| item.destroy end @window = nil end |
#focusable ⇒ Object
557 558 559 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 557 def focusable false end |
#handle_keys ⇒ Object
menubar LEFT, RIGHT, DOWN
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 592 def handle_keys @selected = false @toggle_key ||= 27 # default switch off with ESC, if nothing else defined 0 begin catch(:popupclose) 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 destroy # Note that we destroy the menu bar upon exit end end |
#hide ⇒ Object
663 664 665 666 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 663 def hide @visible = false @window.hide if !@window.nil? end |
#next_menu ⇒ Object
564 565 566 567 568 569 570 571 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 564 def $log.debug "next meu: #{@active_index} " if @active_index < @items.length-1 @active_index + 1 else 0 end end |
#prev_menu ⇒ Object
572 573 574 575 576 577 578 579 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 572 def $log.debug "prev meu: #{@active_index} " if @active_index > 0 @active_index-1 else @items.length-1 end end |
#repaint ⇒ Object
menubar
676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 676 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
580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 580 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
667 668 669 670 671 672 673 674 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 667 def show @visible = true if @window.nil? repaint # XXX FIXME else @window.show end end |
#toggle ⇒ Object
655 656 657 658 659 660 661 662 |
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 655 def toggle @visible = !@visible if !@visible hide else show end end |