Class: Watobo::Gui::ListBox

Inherits:
FXGroupBox
  • Object
show all
Defined in:
lib/watobo/gui/list_box.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner, title = "", info_text = "", opts = LAYOUT_SIDE_RIGHT|FRAME_GROOVE|LAYOUT_FILL_X) ⇒ ListBox

Returns a new instance of ListBox.



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
114
115
116
117
118
119
120
121
# File 'lib/watobo/gui/list_box.rb', line 74

def initialize(owner, title="", info_text="", opts= LAYOUT_SIDE_RIGHT|FRAME_GROOVE|LAYOUT_FILL_X)
  gbframe = super(owner, title, opts , 0, 0, 0, 0)
  frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X, :padding => 0)

  unless info_text.empty?
    fxtext = FXText.new(frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|TEXT_WORDWRAP)
  fxtext.backColor = fxtext.parent.backColor
  fxtext.disable
  text = "#{info_text}"
  fxtext.setText(text)
  end

  input_frame = FXHorizontalFrame.new(frame, :opts => LAYOUT_FILL_X)
  #@text = FXTextField.new(input_frame, 20, :target => @expath_dt, :selector => FXDataTarget::ID_VALUE, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_LEFT|LAYOUT_FILL_X)
  @text = FXTextField.new(input_frame, 20, nil, 0, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_LEFT|LAYOUT_FILL_X)
  @rem_btn = FXButton.new(input_frame, "Remove" , :opts => BUTTON_NORMAL|BUTTON_DEFAULT|LAYOUT_RIGHT)
  @add_btn = FXButton.new(input_frame, "Add" , :opts => BUTTON_NORMAL|BUTTON_DEFAULT|LAYOUT_RIGHT)

  list_frame = FXVerticalFrame.new(frame, :opts => LAYOUT_FILL_X|FRAME_SUNKEN, :padding => 0)
  @list = FXList.new(list_frame, :opts => LIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @list.numVisible = 5

  @list.connect(SEL_COMMAND){ |sender, sel, item|
    @text.text = sender.getItemText(item)
    @text.handle(self, FXSEL(SEL_UPDATE, 0), nil)
  }

  @rem_btn.connect(SEL_COMMAND){ |sender, sel, item|
    removePattern(@text.text) if @text.text != ''
    @text.text = ''
    @text.handle(self, FXSEL(SEL_UPDATE, 0), nil)
  }
  
  @text.connect(SEL_COMMAND){
    @add_btn.setFocus()
   # @add_btn.setDefault()
    
  }
  
  @add_btn.connect(SEL_COMMAND){ |sender, sel, item|

    addPattern(@text.text) if @text.text != ''
    @text.text = ''
    @text.handle(self, FXSEL(SEL_UPDATE, 0), nil)
    @text.setFocus()
    #@text.setDefault()
  }
end

Instance Method Details

#addPattern(pattern) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/watobo/gui/list_box.rb', line 60

def addPattern(pattern)
  if pattern != "" then
    pattern_ok, *error = Watobo::Utils.checkRegex(pattern)
    if pattern_ok == true
      item = @list.appendItem("#{pattern}")
    @list.setItemData(item, pattern)
    @list.sortItems()

    else
      FXMessageBox.information(self, MBOX_OK, "Wrong Path Format", "Path must be a Regex!!!\nError: #{error.join('\n')}")
    end
  end
end

#append(list) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/watobo/gui/list_box.rb', line 41

def append(list)
  if list.is_a? Array
    list.each do |e|
      addPattern(e) if e.is_a? String
    end
  elsif list.is_a? String
    addPattern(list)
  else
    raise ArgumentError, "Need String or Array"
  end
end

#removePattern(pattern) ⇒ Object



53
54
55
56
57
58
# File 'lib/watobo/gui/list_box.rb', line 53

def removePattern(pattern)
  index = @list.currentItem
  if  index >= 0
  @list.removeItem(index)
  end
end

#set(list) ⇒ Object



34
35
36
37
38
39
# File 'lib/watobo/gui/list_box.rb', line 34

def set(list)
  @list.clearItems
  list.each do |le|
    addPattern(le)
  end
end

#to_aObject



26
27
28
29
30
31
32
# File 'lib/watobo/gui/list_box.rb', line 26

def to_a
  a=[]
  @list.each do |i|
    a << i.to_s
  end
  a
end