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.

Since:

  • 1.2.0

Constant Summary

Constants included from Io

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

Instance Attribute Summary collapse

Attributes inherited from Widget

#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #parent_component, #row_offset, #rows_panned, #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

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

Methods inherited from Widget

#changed, #click, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue, #height, #height=, #hide, #init_vars, #initialize, #leave, #modified?, #move, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #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, #warn

Methods included from Utils

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

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

This class inherits a constructor from RubyCurses::RadioButton

Instance Attribute Details

#display_tab_on_traversalObject

Returns the value of attribute display_tab_on_traversal.



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

def display_tab_on_traversal
  @display_tab_on_traversal
end

Instance Method Details

#getvalue_for_paintObject

Since:

  • 1.2.0



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

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.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/rbcurse/rtabbedpane.rb', line 129

def handle_key ch # tabbed button
  case ch
  when  KEY_DOWN
    # form will not do a next_field, it will ignore this
    @state = :NORMAL # 2011-10-5 
    @form.repaint
    return :NO_NEXT_FIELD
  when KEY_RIGHT
    ret =  @form.select_next_field
    ret = @form.select_first_field if ret == :NO_NEXT_FIELD
    return ret
  when KEY_LEFT
    ret =  @form.select_prev_field
    ret = @form.select_last_field if ret == :NO_PREV_FIELD
    return ret
  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)



119
120
121
122
123
124
125
126
# File 'lib/rbcurse/rtabbedpane.rb', line 119

def on_enter
  $log.debug " overridden on_enter of tabbedbutton #{@name}, foc #{@focussed}  "
  super
  #@state = :HIGHLIGHTED if @focussed
  $log.debug " overridden on_enter of tabbedbutton #{@name} state #{@state}, foc #{@focussed}  "
  $log.debug " calling fire overridden on_enter of tabbedbutton" if @display_tab_on_traversal
  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

Since:

  • 1.2.0



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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rbcurse/rtabbedpane.rb', line 51

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 ||= $reversecolor # 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 =  "red" #@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

    # add bar character on sides of selected  2011-10-5 
    # mvwaddch was not doing anything ??
    if _state == :HIGHLIGHTED
      @graphic.printstring r, c-1, ">",  color, @attrs unless c-1 < @graphic.left
      #@graphic.printstring r, c+len+1, "<",  color, @attrs
    else
      @graphic.printstring r, c-1, " ",  color, @attrs unless c-1 < @graphic.left
      #@graphic.printstring r, c+len+1, " ",  color, @attrs
    end
    @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)


45
46
47
# File 'lib/rbcurse/rtabbedpane.rb', line 45

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