Class: Canis::MenuBar
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
-
#_object_created ⇒ Object
2011-10-7 if visible then Form will call this.
-
#active_index ⇒ Object
Returns the value of attribute active_index.
-
#bgcolor ⇒ Object
2011-09-25 V1.3.1.
-
#color ⇒ Object
2011-09-25 V1.3.1.
-
#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.
-
#text ⇒ Object
readonly
temp 2011-09-24 V1.3.1.
-
#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
(also: #<<)
add a precreated menu, returning self.
- #create_window_menubar ⇒ Object
-
#current_menu ⇒ Object
returns current_menu.
- #destroy ⇒ Object
-
#focusable ⇒ Object
(also: #focusable?)
is this widget focusable, always returns false.
-
#handle_keys ⇒ Object
menubar LEFT, RIGHT, DOWN.
- #hide ⇒ Object
- #init_vars ⇒ Object
-
#initialize(&block) ⇒ MenuBar
constructor
A new instance of MenuBar.
-
#keep_visible(flag = nil) ⇒ Object
keep the menu bar visible at all times.
-
#menu(text, &block) ⇒ Object
add a menu through the block, this would happen through instance eval 2010-09-10 12:07 added while simplifying the interface this calls add so you get the MB back, not a ref to the menu created NOTE.
-
#next_menu ⇒ Object
move focus to next menu.
-
#prev_menu ⇒ Object
move focus to previous menu.
-
#repaint ⇒ Object
menubar TODO: check for menu to be flush right (only for last one).
-
#set_menu(index) ⇒ Object
set the given menu index as the current or active menu after closing the active menu.
- #show ⇒ Object
-
#toggle ⇒ Object
called by set_menu_bar in widget.rb (class Form).
Constructor Details
#initialize(&block) ⇒ MenuBar
Returns a new instance of MenuBar.
681 682 683 684 685 686 687 688 689 |
# File 'lib/canis/core/widgets/rmenu.rb', line 681 def initialize &block @window = nil @text = "menubar" @items = [] init_vars @visible = false @cols = Ncurses.COLS-1 instance_eval &block if block_given? end |
Instance Attribute Details
#_object_created ⇒ Object
2011-10-7 if visible then Form will call this
680 681 682 |
# File 'lib/canis/core/widgets/rmenu.rb', line 680 def _object_created @_object_created end |
#active_index ⇒ Object
Returns the value of attribute active_index.
676 677 678 |
# File 'lib/canis/core/widgets/rmenu.rb', line 676 def active_index @active_index end |
#bgcolor ⇒ Object
2011-09-25 V1.3.1
679 680 681 |
# File 'lib/canis/core/widgets/rmenu.rb', line 679 def bgcolor @bgcolor end |
#color ⇒ Object
2011-09-25 V1.3.1
679 680 681 |
# File 'lib/canis/core/widgets/rmenu.rb', line 679 def color @color end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
670 671 672 |
# File 'lib/canis/core/widgets/rmenu.rb', line 670 def items @items end |
#panel ⇒ Object (readonly)
Returns the value of attribute panel.
672 673 674 |
# File 'lib/canis/core/widgets/rmenu.rb', line 672 def panel @panel end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
673 674 675 |
# File 'lib/canis/core/widgets/rmenu.rb', line 673 def selected @selected end |
#state ⇒ Object
normal, selected, highlighted
677 678 679 |
# File 'lib/canis/core/widgets/rmenu.rb', line 677 def state @state end |
#text ⇒ Object (readonly)
temp 2011-09-24 V1.3.1
674 675 676 |
# File 'lib/canis/core/widgets/rmenu.rb', line 674 def text @text end |
#toggle_key ⇒ Object
key used to popup, should be set prior to attaching to form
678 679 680 |
# File 'lib/canis/core/widgets/rmenu.rb', line 678 def toggle_key @toggle_key end |
#visible ⇒ Object
Returns the value of attribute visible.
675 676 677 |
# File 'lib/canis/core/widgets/rmenu.rb', line 675 def visible @visible end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
671 672 673 |
# File 'lib/canis/core/widgets/rmenu.rb', line 671 def window @window end |
Instance Method Details
#add(menu) ⇒ Object Also known as: <<
add a precreated menu, returning self
700 701 702 703 |
# File 'lib/canis/core/widgets/rmenu.rb', line 700 def add @items << return self end |
#create_window_menubar ⇒ Object
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 |
# File 'lib/canis/core/widgets/rmenu.rb', line 886 def @layout = { :height => 1, :width => 0, :top => 0, :left => 0 } $log.debug "create window menu bar " @win = Canis::Window.new(@layout) @win.name = "WINDOW:menubar" @window = @win # hack since we put all windows in there, and this should not be coming after Root. # This should not have been a window in the first place. $global_windows.delete @win att = get_attrib @attr @win.bkgd(Ncurses.COLOR_PAIR(5)); # <---- FIXME len = @window.width len = Ncurses.COLS-0 if len == 0 # 2016-01-14 - replacing 1 with space since junk is showing up in some cases. space_char = " ".codepoints.first # print a bar across the screen , which hopefully will not go blank in some terms @window.attron(Ncurses.COLOR_PAIR(@color_pair) | att) #@window.mvhline(0, 0, 1, len) @window.mvhline(0, 0, space_char, len) @window.attroff(Ncurses.COLOR_PAIR(@color_pair) | att) @panel = @win.panel return @window end |
#current_menu ⇒ Object
returns current_menu
824 825 826 |
# File 'lib/canis/core/widgets/rmenu.rb', line 824 def @items[@active_index] end |
#destroy ⇒ Object
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
# File 'lib/canis/core/widgets/rmenu.rb', line 911 def destroy $log.debug "DESTRY menubar #{@keep_visible} " # when we close, but keep visible, we don't want menu to still be hightlighted # added on 2011-12-12 = @items[@active_index] .on_leave # hide its window, if open @items.each do |item| item.destroy end $log.debug " DESTROY finished with items " # TODO the current menu should not be highlighted # FIXME even here i think underlying windows need to be repainted. #return if @keep_visible if @keep_visible Window.refresh_all return end @visible = false # replacing next 3 lines with destroy. 2014-05-12 - 17:07 CANIS #panel = @window.panel #Ncurses::Panel.del_panel(panel.pointer) if !panel.nil? #@window.delwin if [email protected]? $log.debug " CALLING WINDOW DESTROY from menubar" @window.destroy @window = nil end |
#focusable ⇒ Object Also known as: focusable?
is this widget focusable, always returns false
695 696 697 |
# File 'lib/canis/core/widgets/rmenu.rb', line 695 def focusable false end |
#handle_keys ⇒ Object
menubar LEFT, RIGHT, DOWN
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
# File 'lib/canis/core/widgets/rmenu.rb', line 764 def handle_keys @selected = false @repaint_required = true # added 2011-12-12 otherwise keeps repainting and you see a flicker @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 if !@selected .fire else .handle_key ch end @selected = true when KEY_ENTER, 10, 13, 32 @selected = true ret = .handle_key ch #break; ## 2008-12-29 18:00 This will close after firing anything break if ret == :CLOSE when KEY_UP .handle_key ch when KEY_LEFT ret = .handle_key ch if ret == :UNHANDLED when KEY_RIGHT ret = .handle_key ch if ret == :UNHANDLED when ?\C-g.getbyte(0) # abort throw :menubarclose else 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" . @repaint_required = false destroy # Note that we destroy the menu bar upon exit end end |
#hide ⇒ Object
846 847 848 849 |
# File 'lib/canis/core/widgets/rmenu.rb', line 846 def hide @visible = false @window.hide if !@window.nil? # seems to cause auto-firing when we resume toggle 2011-09-26 end |
#init_vars ⇒ Object
690 691 692 693 |
# File 'lib/canis/core/widgets/rmenu.rb', line 690 def init_vars @active_index = 0 @repaint_required = true end |
#keep_visible(flag = nil) ⇒ Object
keep the menu bar visible at all times. If not, then it appears only on using the toggle key. In any case, control only goes to the menubar when you use the toggle key, so it is best NOT to keep it visible.
757 758 759 760 761 762 |
# File 'lib/canis/core/widgets/rmenu.rb', line 757 def keep_visible flag=nil return @keep_visible unless flag @keep_visible = flag @visible = flag self end |
#menu(text, &block) ⇒ Object
add a menu through the block, this would happen through instance eval 2010-09-10 12:07 added while simplifying the interface this calls add so you get the MB back, not a ref to the menu created NOTE
709 710 711 712 713 714 715 |
# File 'lib/canis/core/widgets/rmenu.rb', line 709 def text, &block m = Menu.new text, &block m.color = @color m.bgcolor = @bgcolor add m return m end |
#next_menu ⇒ Object
move focus to next menu
717 718 719 720 721 722 723 724 |
# File 'lib/canis/core/widgets/rmenu.rb', line 717 def #$log.debug "next meu: #{@active_index} " if @active_index < @items.length-1 @active_index + 1 else 0 end end |
#prev_menu ⇒ Object
move focus to previous menu
726 727 728 729 730 731 732 733 |
# File 'lib/canis/core/widgets/rmenu.rb', line 726 def #$log.debug "prev meu: #{@active_index} " if @active_index > 0 @active_index-1 else @items.length-1 end end |
#repaint ⇒ Object
menubar TODO: check for menu to be flush right (only for last one). TODO: repaint only if needed
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
# File 'lib/canis/core/widgets/rmenu.rb', line 861 def repaint return if !@visible return unless @repaint_required @repaint_required = false @color_pair = get_color($reversecolor, @color, @bgcolor) @window ||= #@window.printstring( 0, 0, "%-*s" % [@cols," "], @color_pair) # this becomes blank in some terms c = 1; r = 0; @items.each do |item| item.row = r; item.col = c; item.coffset = c; item.parent = self item.color = @color item.bgcolor = @bgcolor @window.printstring( r, c, " %s " % item.text, @color_pair) # 2011-09-26 V1.3.1 quick dirty highlighting of first menu on menubar # on opening since calling highlight was giving bug in parent.width #if c == 1 #att = Ncurses::A_REVERSE #@window.mvchgat(y=r, x=c+1, item.text.length+1, att, @color_pair, nil) #end c += (item.text.length + 2) end #@items[0].on_enter # 2011-09-25 V1.3.1 caused issues when toggling, first item fired on DOWN @items[0].highlight unless @keep_visible # 2011-09-26 V1.3.1 fixed to take both cases into account @window.wrefresh end |
#set_menu(index) ⇒ Object
set the given menu index as the current or active menu
after closing the active menu.
738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
# File 'lib/canis/core/widgets/rmenu.rb', line 738 def index #$log.debug "set meu: #{@active_index} #{index}" # first leave the existing window = @items[@active_index] .on_leave # hide its window, if open # now move to given menu @active_index = index = @items[@active_index] .on_enter #display window, if previous was displayed # move cursor to selected menu option on top, not inside list @window.wmove .row, .col # menu.show # menu.window.wrefresh # XXX we need this end |
#show ⇒ Object
850 851 852 853 854 855 856 857 |
# File 'lib/canis/core/widgets/rmenu.rb', line 850 def show @visible = true if @window.nil? repaint # XXX FIXME else @window.show end end |
#toggle ⇒ Object
called by set_menu_bar in widget.rb (class Form).
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
# File 'lib/canis/core/widgets/rmenu.rb', line 828 def toggle # added keeping it visible, 2011-10-7 being tested in dbdemo if @keep_visible init_vars show @items[0].highlight @window.ungetch(KEY_DOWN) return end #@items.each { |i| $log.debug " ITEM DDD : #{i.text}" } @visible = !@visible if !@visible hide else init_vars show end end |