Class: RubyCurses::TabbedButton

Inherits:
RadioButton show all
Defined in:
lib/rbcurse/rtabbedpane.rb,
lib/rbcurse/rtabbedwindow.rb

Overview

TODO : insert_tab, remove_tab, disable/hide tab Hotkeys should be defined with ampersand, too.

Multiple independent overlapping forms using the tabbed metaphor.

Constant Summary

Constants included from Io

Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR

Instance Attribute Summary

Attributes inherited from Widget

#col_offset, #cols_panned, #config, #curpos, #ext_col_offset, #ext_row_offset, #form, #id, #parent_component, #row_offset, #rows_panned, #should_create_buffer, #state

Instance Method Summary collapse

Methods inherited from RadioButton

#checked, #fire, #getvalue, #initialize, #toggle

Methods inherited from ToggleButton

#checked, #checked?, #fire, #getvalue, #initialize, #toggle

Methods inherited from Button

#OLDunderline, #action, #bind_hotkey, button_layout, #command, #fire, #getvalue, #initialize, #mnemonic, #text

Methods inherited from Widget

#OLDbind_key, #buffer_to_screen, #buffer_to_window, #create_buffer, #destroy, #destroy_buffer, #focus, #get_buffer, #get_color, #get_preferred_size, #getvalue, #height, #height=, #hide, #init_vars, #initialize, #is_double_buffered?, #modified?, #move, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #safe_create_buffer, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=

Methods included from Io

#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr

Methods included from Utils

#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Methods included from DSL

#OLD_method_missing

Constructor Details

This class inherits a constructor from RubyCurses::RadioButton

Instance Method Details

#getvalue_for_paintObject



40
41
42
# File 'lib/rbcurse/rtabbedpane.rb', line 40

def getvalue_for_paint
  @text
end

#handle_key(ch) ⇒ Object

In order to get tab display as we traverse buttons, we need to tamper with KEY_DOWN since that’s the only way of getting down to selected tab in this case.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rbcurse/rtabbedpane.rb', line 115

def handle_key ch
  case ch
  when  KEY_DOWN
    # form will not do a next_field, it will ignore this
    return :NO_NEXT_FIELD
  when KEY_RIGHT
    @form.select_next_field
  when KEY_LEFT
    @form.select_prev_field
  when KEY_ENTER, 10, 13, 32  # added space bar also
    if respond_to? :fire
      fire
    end
  else
    # all thrse will be re-evaluated by form
    return :UNHANDLED
  end
end

#on_enterObject

trying to give the option so as we tab through buttons, the relevant tab opens but this is getting stuck on a tab and not going on fire() is causing the problem fire takes the focus into tab area so the next TAB goes back to first button due to current_tab = tab (so next key stroke goes to tab)



107
108
109
110
111
112
# File 'lib/rbcurse/rtabbedpane.rb', line 107

def on_enter
  $log.debug " overridden on_enter of tabbedbutton #{@name} "
  super
  $log.debug " calling fire overridden on_enter of tabbedbutton"
  fire if @display_tab_on_traversal
end

#repaintObject

highlight abd selected colors and attribs should perhaps be in a structure, so user can override easily



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rbcurse/rtabbedpane.rb', line 49

def repaint  # tabbedbutton
   $log.debug("TabbedBUTTon repaint : #{self.class()}  r:#{@row} c:#{@col} #{getvalue_for_paint}" )
    r,c = rowcol
    attribs = @attrs
    @highlight_foreground ||= $reversecolor
    @highlight_background ||= 0
    _state = @state
    _state = :SELECTED if @variable.value == @value 
    case _state
    when :HIGHLIGHTED
   $log.debug("TabbedBUTTon repaint : HIGHLIGHTED #{bgcolor}, #{color}, v: #{@value}" )
      bgcolor = @highlight_background
      color = @highlight_foreground
      bgcolor =  @bgcolor
      color =  @color
      attribs = Ncurses::A_BOLD
      setrowcol r,c  # show cursor on highlighted as we tab through
      ## but when tabbing thru selected one, then selected one doesn't show cursor
    when :SELECTED
   $log.debug("TabbedBUTTon repaint : SELECTED #{bgcolor}, #{color}")
      bgcolor =  @bgcolor
      color =  @color
      attribs = Ncurses::A_REVERSE
      if @state == :HIGHLIGHTED
        setrowcol r,c  # show cursor on highlighted as we tab through
      end
    else
   $log.debug("TabbedBUTTon repaint : ELSE #{bgcolor}, #{color}")
      bgcolor =  @bgcolor
      color =  @color
    end
    #bgcolor = @state==:HIGHLIGHTED ? @highlight_background : @bgcolor
    #color = @state==:HIGHLIGHTED ? @highlight_foreground : @color
    if bgcolor.is_a? String and color.is_a? String
      color = ColorMap.get_color(color, bgcolor)
    end
    value = getvalue_for_paint
   $log.debug("button repaint : r:#{r} #{@graphic.top}  c:#{c} #{@graphic.left} color:#{color} bg #{bgcolor} v: #{value}, g: #{@graphic} ")
    len = @display_length || value.length
    # paint the tabs name in approp place with attribs
    #@form.window.printstring r, c, "%-*s" % [len, value], color, attribs
    #@graphic.printstring [email protected], [email protected], "%-*s" % [len, value], color, attribs
    #@graphic.printstring [email protected], [email protected], "%-*s" % [len, value], color, attribs
    @graphic.printstring r, c, "%-*s" % [len, value], color, attribs
    @graphic.modified = true
#       @form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, bgcolor, nil)
     # underline for the top tab buttons.
    if @underline != nil
      r -= @graphic.top # because of pad, remove if we go back to windows
      c -= @graphic.left # because of pad, remove if we go back to windows
      @graphic.mvchgat(y=r, x=c+@underline+0, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, color, nil)
    end
end

#selected?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/rbcurse/rtabbedpane.rb', line 43

def selected?
    @variable.value == @value 
end