Class: Canis::Field

Inherits:
Widget show all
Defined in:
lib/canis/core/widgets/rwidget.rb

Overview

Text edit field NOTE: width is the length of the display whereas maxlen is the maximum size that the value can take. Thus, maxlen can exceed width. Currently, maxlen defaults to width which defaults to 20. NOTE: Use text(val) to set value, and text() to retrieve value

Example

f = Field.new @form, text: "Some value", row: 10, col: 2

Field introduces an event :CHANGE which is fired for each character deleted or inserted TODO: some methods should return self, so chaining can be done. Not sure if the return value of the

fire_handler is being checked.
NOTE: i have just added repain_required check in Field before repaint
this may mean in some places field does not paint. repaint_require will have to be set
to true in those cases. this was since field was overriding a popup window that was not modal.

Since:

  • 1.2.0

Direct Known Subclasses

LabeledField

Instance Attribute Summary collapse

Attributes inherited from Widget

#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #state

Instance Method Summary collapse

Methods inherited from Widget

#action_manager, #bgcolor, #color, #color_pair, #command, #destroy, #focus, #focusable, #focusable?, #getvalue_for_paint, #hide, #move, #override_graphic, #process_key, #property_set, #remove, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key

Methods included from Io

#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rb_getstr, #warn

Methods included from Utils

#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping

Methods included from ConfigSetup

#config_setup, #variable_set

Methods included from EventHandler

#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events

Constructor Details

#initialize(form = nil, config = {}, &block) ⇒ Field

# so can be nil if accessed early 2011-12-8

Since:

  • 1.2.0



2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
# File 'lib/canis/core/widgets/rwidget.rb', line 2307

def initialize form=nil, config={}, &block
  @form = form
  @buffer = String.new
  #@type=config.fetch("type", :varchar)
  @row = 0
  @col = 0
  @editable = true
  @focusable = true
  #@event_args = {}             # arguments passed at time of binding, to use when firing event
  map_keys 
  init_vars
  register_events(:CHANGE)
  super
  @width ||= 20
  @maxlen ||= @width
end

Instance Attribute Details

#aboveObject

for numeric fields, specify lower or upper limit of entered value

Since:

  • 1.2.0



2278
2279
2280
# File 'lib/canis/core/widgets/rwidget.rb', line 2278

def above
  @above
end

#belowObject

for numeric fields, specify lower or upper limit of entered value

Since:

  • 1.2.0



2278
2279
2280
# File 'lib/canis/core/widgets/rwidget.rb', line 2278

def below
  @below
end

#bufferObject (readonly)

actual buffer being used for storage

Since:

  • 1.2.0



2271
2272
2273
# File 'lib/canis/core/widgets/rwidget.rb', line 2271

def buffer
  @buffer
end

#datatypeObject

this accesses the field created or passed with set_label attr_reader :label this is the class of the field set in text(), so value is returned in same class

Examples:

: Integer, Integer, Float

Since:

  • 1.2.0



2297
2298
2299
# File 'lib/canis/core/widgets/rwidget.rb', line 2297

def datatype
  @datatype
end

#field_colObject (readonly)

column on which field printed, usually the same as col unless label used. Required by History to popup field history.

Since:

  • 1.2.0



2303
2304
2305
# File 'lib/canis/core/widgets/rwidget.rb', line 2303

def field_col
  @field_col
end

#original_valueObject (readonly)

value on entering field

Since:

  • 1.2.0



2298
2299
2300
# File 'lib/canis/core/widgets/rwidget.rb', line 2298

def original_value
  @original_value
end

#overwrite_modeObject

true or false INSERT OVERWRITE MODE

Since:

  • 1.2.0



2299
2300
2301
# File 'lib/canis/core/widgets/rwidget.rb', line 2299

def overwrite_mode
  @overwrite_mode
end

Instance Method Details

#_set_buffer(value) ⇒ Object

set value of Field fires CHANGE handler Please don’t use this directly, use text This name is from ncurses field, added underscore to emphasize not to use

Since:

  • 1.2.0



2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
# File 'lib/canis/core/widgets/rwidget.rb', line 2441

def _set_buffer value   #:nodoc:
  @repaint_required = true
  @datatype = value.class
  @delete_buffer = @buffer.dup
  @buffer = value.to_s.dup
  # don't allow setting of value greater than maxlen
  @buffer = @buffer[0,@maxlen] if @maxlen && @buffer.length > @maxlen
  @curpos = 0
  # hope @delete_buffer is not overwritten
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, @delete_buffer)     # 2010-09-11 13:01 
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :INSERT, 0, @buffer)     # 2010-09-11 13:01 
  self # 2011-10-2 
end

#addcol(num) ⇒ Object

add a column to cursor position. Field

Since:

  • 1.2.0



2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
# File 'lib/canis/core/widgets/rwidget.rb', line 2704

def addcol num
  if num < 0
    if @form.col <= @col + @col_offset
     # $log.debug " error trying to cursor back #{@form.col}"
      return -1
    end
  elsif num > 0
    if @form.col >= @col + @col_offset + @width
  #    $log.debug " error trying to cursor forward #{@form.col}"
      return -1
    end
  end
  @form.addcol num
end

#cursor_backwardObject

$log.debug “ crusor FORWARD cp:#@curpos pcol:#@pcol b.l:#Canis::Field.@[email protected] d_l:#@display_length fc:#Canis::Field.@[email protected]

Since:

  • 1.2.0



2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
# File 'lib/canis/core/widgets/rwidget.rb', line 2664

def cursor_backward
  if @curpos > 0
    @curpos -= 1
    if @pcol > 0 and @form.col == @col + @col_offset
      @pcol -= 1
    end
    addcol -1
  elsif @pcol > 0 #  added 2008-11-26 23:05 
    @pcol -= 1   
  end
 #   $log.debug " crusor back cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}"
=begin
# this is perfect if not scrolling, but now needs changes
  if @curpos > 0
    @curpos -= 1
    addcol -1
  end
=end
end

#cursor_endObject

goto end of field, “end” is a keyword so could not use it.

Since:

  • 1.2.0



2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
# File 'lib/canis/core/widgets/rwidget.rb', line 2618

def cursor_end
  blen = @buffer.rstrip.length
  if blen < @width
    set_form_col blen
  else
    # there is a problem here FIXME. 
    @pcol = blen-@width
    #set_form_col @width-1
    set_form_col blen
  end
  @curpos = blen # this is position in array where editing or motion is to happen regardless of what you see
                 # regardless of pcol (panning)
  #  $log.debug " crusor END cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@width} fc:#{@form.col}"
  #set_form_col @buffer.length
end

#cursor_forwardObject

Since:

  • 1.2.0



2655
2656
2657
2658
2659
2660
2661
2662
2663
# File 'lib/canis/core/widgets/rwidget.rb', line 2655

def cursor_forward
  if @curpos < @buffer.length 
    if addcol(1)==-1  # go forward if you can, else scroll
      @pcol += 1 if @pcol < @width 
    end
    @curpos += 1
  end
 # $log.debug " crusor FORWARD cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}"
end

#cursor_homeObject

position cursor at start of field

Since:

  • 1.2.0



2611
2612
2613
2614
2615
# File 'lib/canis/core/widgets/rwidget.rb', line 2611

def cursor_home
  @curpos = 0
  @pcol = 0
  set_form_col 0
end

#delete_at(index = @curpos) ⇒ Object

Since:

  • 1.2.0



2417
2418
2419
2420
2421
2422
2423
2424
# File 'lib/canis/core/widgets/rwidget.rb', line 2417

def delete_at index=@curpos
  return -1 if !@editable 
  char = @buffer.slice!(index,1)
  #$log.debug " delete at #{index}: #{@buffer.length}: #{@buffer}"
  @modified = true
  #fire_handler :CHANGE, self    # 2008-12-09 14:51 
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, char)     # 2010-09-11 13:01 
end

#delete_curr_charObject

# this is perfect if not scrolling, but now needs changes

if @curpos > 0
  @curpos -= 1
  addcol -1
end

Since:

  • 1.2.0



2683
2684
2685
2686
2687
# File 'lib/canis/core/widgets/rwidget.rb', line 2683

def delete_curr_char
  return -1 unless @editable
  delete_at
  set_modified 
end

#delete_eolObject

Since:

  • 1.2.0



2646
2647
2648
2649
2650
2651
2652
2653
2654
# File 'lib/canis/core/widgets/rwidget.rb', line 2646

def delete_eol
  return -1 unless @editable
  pos = @curpos-1
  @delete_buffer = @buffer[@curpos..-1]
  # if pos is 0, pos-1 becomes -1, end of line!
  @buffer = pos == -1 ? "" : @buffer[0..pos]
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE, 0, @delete_buffer)
  return @delete_buffer
end

#delete_prev_charObject

Since:

  • 1.2.0



2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
# File 'lib/canis/core/widgets/rwidget.rb', line 2688

def delete_prev_char
  return -1 if !@editable 
  return if @curpos <= 0
  # if we've panned, then unpan, and don't move cursor back
  # Otherwise, adjust cursor (move cursor back as we delete)
  adjust = true
  if @pcol > 0
    @pcol -= 1
    adjust = false
  end
  @curpos -= 1 if @curpos > 0
  delete_at
  addcol -1 if adjust # move visual cursor back
  set_modified 
end

#getvalueObject

converts back into original type

changed to convert on 2009-01-06 23:39

Since:

  • 1.2.0



2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
# File 'lib/canis/core/widgets/rwidget.rb', line 2456

def getvalue
  dt = @datatype || String
  case dt.to_s
  when "String"
    return @buffer
  when "Integer"
    return @buffer.to_i
  when "Float"
    return @buffer.to_f
  else
    return @buffer.to_s
  end
end

#handle_key(ch) ⇒ Object

field

Since:

  • 1.2.0



2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
# File 'lib/canis/core/widgets/rwidget.rb', line 2586

def handle_key ch
  @repaint_required = true 
  case ch
  when 32..126
    #$log.debug("FIELD: ch #{ch} ,at #{@curpos}, buffer:[#{@buffer}] bl: #{@buffer.to_s.length}")
    putc ch
  when 27 # cannot bind it
    #text @original_value 
    # commented above and changed 2014-05-12 - 20:05 I think above creates positioning issues. TEST XXX
    restore_original_value
  else
    ret = super
    return ret
  end
  0 # 2008-12-16 23:05 without this -1 was going back so no repaint
end

#in_range?(val) ⇒ Boolean

checks field against valid_range, above and below , returning true if it passes set attributes, false if it fails any one.

Returns:

  • (Boolean)

Since:

  • 1.2.0



2752
2753
2754
2755
2756
2757
# File 'lib/canis/core/widgets/rwidget.rb', line 2752

def in_range?( val )
  val = val.to_i
  (@above.nil? or val > @above) and
    (@below.nil? or val < @below) and
    (@valid_range.nil? or @valid_range.include?(val))
end

#init_varsObject

Since:

  • 1.2.0



2323
2324
2325
2326
2327
2328
2329
2330
# File 'lib/canis/core/widgets/rwidget.rb', line 2323

def init_vars
  @pcol = 0                    # needed for horiz scrolling
  @curpos = 0                  # current cursor position in buffer
                               # this is the index where characters are put or deleted
  #                            # when user edits
  @modified = false
  @repaint_required = true
end

#label(*val) ⇒ Object

Since:

  • 1.2.0



2500
2501
2502
2503
# File 'lib/canis/core/widgets/rwidget.rb', line 2500

def label *val
  return @label if val.empty?
  raise "Field does not allow setting of label. Please use LabeledField instead with lcol for label column"
end

#map_keysObject

Since:

  • 1.2.0



2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
# File 'lib/canis/core/widgets/rwidget.rb', line 2568

def map_keys
  return if @keys_mapped
  bind_key(FFI::NCurses::KEY_LEFT, :cursor_backward )
  bind_key(FFI::NCurses::KEY_RIGHT, :cursor_forward )
  bind_key(FFI::NCurses::KEY_BACKSPACE, :delete_prev_char )
  bind_key(127, :delete_prev_char )
  bind_key(330, :delete_curr_char )
  bind_key(?\C-a, :cursor_home )
  bind_key(?\C-e, :cursor_end )
  bind_key(?\C-k, :delete_eol )
  bind_key(?\C-_, :undo_delete_eol )
  #bind_key(27){ text @original_value }
  bind_key(?\C-g, 'revert'){ text @original_value } # 2011-09-29 V1.3.1 ESC did not work
  @keys_mapped = true
end

#modified?Boolean

overriding widget, check for value change

2009-01-18 12:25

Returns:

  • (Boolean)

Since:

  • 1.2.0



2770
2771
2772
# File 'lib/canis/core/widgets/rwidget.rb', line 2770

def modified?
  getvalue() != @original_value
end

#on_enterObject

save original value on enter, so we can check for modified.

2009-01-18 12:25 
 2011-10-9 I have changed to take @buffer since getvalue returns a datatype
 and this causes a crash in set_original on cursor forward.

Since:

  • 1.2.0



2762
2763
2764
2765
2766
# File 'lib/canis/core/widgets/rwidget.rb', line 2762

def on_enter
  #@original_value = getvalue.dup rescue getvalue
  @original_value = @buffer.dup # getvalue.dup rescue getvalue
  super
end

#on_leaveObject

upon leaving a field returns false if value not valid as per values or valid_regex 2008-12-22 12:40 if null_allowed, don’t validate, but do fire_handlers

Since:

  • 1.2.0



2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
# File 'lib/canis/core/widgets/rwidget.rb', line 2721

def on_leave
  val = getvalue
  #$log.debug " FIELD ON LEAVE:#{val}. #{@values.inspect}"
  valid = true
  if val.to_s.empty? && @null_allowed
    #$log.debug " empty and null allowed"
  else
    if !@values.nil?
      valid = @values.include? val
      raise FieldValidationException, "Field value (#{val}) not in values: #{@values.join(',')}" unless valid
    end
    if !@valid_regex.nil?
      valid = @valid_regex.match(val.to_s)
      raise FieldValidationException, "Field not matching regex #{@valid_regex}" unless valid
    end
    # added valid_range for numerics 2011-09-29 
    if !in_range?(val)
      raise FieldValidationException, "Field not matching range #{@valid_range}, above #{@above} or below #{@below}  "
    end
  end
  # here is where we should set the forms modified to true - 2009-01
  if modified?
    set_modified true
  end
  # if super fails we would have still set modified to true
  super
  #return valid
end

#position_labelObject

FIXME this may not work since i have disabled -1, now i do not set row and col

Since:

  • 1.2.0



2505
2506
2507
2508
2509
2510
2511
# File 'lib/canis/core/widgets/rwidget.rb', line 2505

def position_label
  $log.debug "XXX: LABEL row #{@label.row}, #{@label.col} "
  @label.row  @row unless @label.row #if @label.row == -1
  @label.col  @col-(@label.name.length+1) unless @label.col #if @label.col == -1
  @label.label_for(self) # this line got deleted when we redid stuff !
  $log.debug "   XXX: LABEL row #{@label.row}, #{@label.col} "
end

#putc(c) ⇒ Object

TODO : sending c>=0 allows control chars to go. Should be >= ?A i think.

Since:

  • 1.2.0



2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
# File 'lib/canis/core/widgets/rwidget.rb', line 2401

def putc c
  if c >= 0 and c <= 127
    ret = putch c.chr
    if ret == 0
      if addcol(1) == -1  # if can't go forward, try scrolling
        # scroll if exceeding display len but less than max len
        if @curpos > @width && @curpos <= @maxlen
          @pcol += 1 if @pcol < @width 
        end
      end
      set_modified 
      return 0 # 2010-09-11 12:59 else would always return -1
    end
  end
  return -1
end

#putch(char) ⇒ Integer

add a char to field, and validate NOTE: this should return self for chaining operations and throw an exception if disabled or exceeding size

Parameters:

  • a (char)

    character to add

Returns:

  • (Integer)

    0 if okay, -1 if not editable or exceeding length

Since:

  • 1.2.0



2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
# File 'lib/canis/core/widgets/rwidget.rb', line 2370

def putch char
  return -1 if !@editable 
  return -1 if !@overwrite_mode && (@buffer.length >= @maxlen)
  blen = @buffer.length
  if @chars_allowed != nil
    return if char.match(@chars_allowed).nil?
  end
  # added insert or overwrite mode 2010-03-17 20:11 
  oldchar = nil
  if @overwrite_mode
    oldchar = @buffer[@curpos] 
    @buffer[@curpos] = char
  else
    @buffer.insert(@curpos, char)
  end
  oldcurpos = @curpos
  #$log.warn "XXX:  FIELD CURPOS #{@curpos} blen #{@buffer.length} " #if @curpos > blen
  @curpos += 1 if @curpos < @maxlen
  @modified = true
  #$log.debug " FIELD FIRING CHANGE: #{char} at new #{@curpos}: bl:#{@buffer.length} buff:[#{@buffer}]"
  # i have no way of knowing what change happened and what char was added deleted or changed
  #fire_handler :CHANGE, self    # 2008-12-09 14:51 
  if @overwrite_mode
    fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :DELETE, 0, oldchar) # 2010-09-11 12:43 
  end
  fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :INSERT, 0, char) # 2010-09-11 12:43 
  0
end

#repaintObject

Note that some older widgets like Field repaint every time the form.repaint + is called, whether updated or not. I can’t remember why this is, but + currently I’ve not implemented events with these widgets. 2010-01-03 15:00

Since:

  • 1.2.0



2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
# File 'lib/canis/core/widgets/rwidget.rb', line 2517

def repaint
  return unless @repaint_required  # 2010-11-20 13:13 its writing over a window i think TESTING
  if @label_unattached
    alert "came here unattachd"
    @label.set_form(@form)
    @label_unattached = nil
  end
  if @label_unplaced
    alert "came here unplaced"
    position_label
    @label_unplaced = nil
  end
  #@bgcolor ||= $def_bg_color
  #@color   ||= $def_fg_color
  _color = color()
  _bgcolor = bgcolor()
  $log.debug("repaint FIELD: #{id}, #{name}, #{row} #{col},pcol:#{@pcol},  #{focusable} st: #{@state} ")
  @width = 1 if width == 0
  printval = getvalue_for_paint().to_s # added 2009-01-06 23:27 
  printval = mask()*printval.length unless @mask.nil?
  if !printval.nil? 
    if printval.length > width # only show maxlen
      printval = printval[@pcol..@pcol+width-1] 
    else
      printval = printval[@pcol..-1]
    end
  end

  acolor = @color_pair || get_color($datacolor, _color, _bgcolor)
  if @state == :HIGHLIGHTED
    _bgcolor = @highlight_bgcolor || _bgcolor
    _color = @highlight_color || _color
    acolor = get_color(acolor, _color, _bgcolor)
  end
  @graphic = @form.window if @graphic.nil? ## cell editor listbox hack 
  #$log.debug " Field g:#{@graphic}. r,c,displen:#{@row}, #{@col}, #{@width} c:#{@color} bg:#{@bgcolor} a:#{@attr} :#{@name} "
  r = row
  c = col
  @graphic.printstring r, c, sprintf("%-*s", width, printval), acolor, attr()
  @field_col = c
  @repaint_required = false
end

#restore_original_valueObject

silently restores value without firing handlers, use if exception and you want old value

Since:

  • 1.4.0 2011-10-2



2428
2429
2430
2431
2432
2433
2434
2435
# File 'lib/canis/core/widgets/rwidget.rb', line 2428

def restore_original_value
  @buffer = @original_value.dup
  # earlier commented but trying again, since i am getting IndexError in insert 2188
  # Added next 3 lines to fix issue, now it comes back to beginning.
  cursor_home

  @repaint_required = true
end

#set_focusable(tf) ⇒ Object

deprecated set or unset focusable

Since:

  • 1.2.0



2562
2563
2564
2565
# File 'lib/canis/core/widgets/rwidget.rb', line 2562

def set_focusable(tf)
  $log.warn "pls don't use, deprecated. use focusable(boolean)"
  focusable tf
end

#set_form_col(col1 = @curpos) ⇒ Object

sets the visual cursor on the window at correct place added here since we need to account for pcol. 2011-12-7 NOTE be careful of curpos - pcol being less than 0

Since:

  • 1.2.0



2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
# File 'lib/canis/core/widgets/rwidget.rb', line 2636

def set_form_col col1=@curpos
  @curpos = col1 || 0 # NOTE we set the index of cursor here
  c = @col + @col_offset + @curpos - @pcol
  min = @col + @col_offset
  max = min + @width
  c = min if c < min
  c = max if c > max
  #$log.debug " #{@name} FIELD set_form_col #{c}, curpos #{@curpos}  , #{@col} + #{@col_offset} pcol:#{@pcol} "
  setrowcol nil, c
end

#set_label(label) ⇒ Object

create a label linked to this field Typically one passes a Label, but now we can pass just a String, a label is created. This differs from label in positioning. The Field is printed on row and col and the label before it. Thus, all fields are aligned on column, however you must leave adequate columns for the label to be printed to the left of the field.

NOTE: 2011-10-20 when field attached to some container, label won’t be attached In such cases, use just label() not set_label(). FIXME this may not work since i have disabled -1, now i do not set row and col 2011-11-5

Parameters:

  • label (Label, String)

    object to be associated with this field

Returns:

  • label created which can be further customized.

Since:

  • 1.2.0



2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
# File 'lib/canis/core/widgets/rwidget.rb', line 2481

def set_label label
  # added case for user just using a string
  case label
  when String
    # what if no form at this point
    @label_unattached = true unless @form
    label = Label.new @form, {:text => label}
  end
  @label = label
  # in the case of app it won't be set yet FIXME
  # So app sets label to 0 and t his won't trigger
  # can this be delayed to when paint happens XXX
  if @row
    position_label
  else
    @label_unplaced = true
  end
  label
end

#text(*val) ⇒ Object Also known as: default

Set the value in the field.

Parameters:

  • if

    none given, returns value existing

  • value (can be int, float, String)

Returns:

  • self

Since:

  • 1.2.0



2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
# File 'lib/canis/core/widgets/rwidget.rb', line 2779

def text(*val)
  if val.empty?
    return getvalue()
  else
    return unless val # added 2010-11-17 20:11, dup will fail on nil
    return unless val[0]
    # 2013-04-20 - 19:02 dup failing on fixnum, set_buffer does a dup
    # so maybe i can do without it here
    #s = val[0].dup
    s = val[0]
    _set_buffer(s)
  end
end

#text=(val) ⇒ Object

Since:

  • 1.2.0



2793
2794
2795
2796
2797
2798
# File 'lib/canis/core/widgets/rwidget.rb', line 2793

def text=(val)
  return unless val # added 2010-11-17 20:11, dup will fail on nil
  # will bomb on integer or float etc !!
  #_set_buffer(val.dup)
  _set_buffer(val)
end

#type(*val) ⇒ Object Also known as: chars_allowed

NOTE: earlier there was some confusion over type, chars_allowed and datatype Now type and chars_allowed are merged into one. If you pass a symbol such as :integer, :float or Float Integer then some

standard chars_allowed will be used. Otherwise you may pass a regexp.

Parameters:

  • symbol

    :integer, :float, :alpha, :alnum, Float, Integer, Numeric, Regexp

Since:

  • 1.2.0



2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
# File 'lib/canis/core/widgets/rwidget.rb', line 2338

def type *val
  return @chars_allowed if val.empty?

  dtype = val[0]
  #return self if @chars_allowed # disallow changing
  if dtype.is_a? Regexp 
    @chars_allowed = dtype
    return self
  end
  dtype = dtype.to_s.downcase.to_sym if dtype.is_a? String
  case dtype # missing to_sym would have always failed due to to_s 2011-09-30 1.3.1
  when :integer, Integer
    @chars_allowed = /\d/
  when :numeric, :float, Numeric, Float
    @chars_allowed = /[\d\.]/ 
  when :alpha
    @chars_allowed = /[a-zA-Z]/ 
  when :alnum
    @chars_allowed = /[a-zA-Z0-9]/ 
  else
    raise ArgumentError, "Field type: invalid datatype specified. Use :integer, :numeric, :float, :alpha, :alnum "
  end
  self
end

#undo_delete_eolObject

does an undo on delete_eol, not a real undo

Since:

  • 1.2.0



2603
2604
2605
2606
2607
2608
# File 'lib/canis/core/widgets/rwidget.rb', line 2603

def undo_delete_eol
  return if @delete_buffer.nil?
  #oldvalue = @buffer
  @buffer.insert @curpos, @delete_buffer 
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT, 0, @delete_buffer)     # 2010-09-11 13:01 
end