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.



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
# File 'lib/watobo/gui/list_box.rb', line 53

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



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

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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/watobo/gui/list_box.rb', line 20

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



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

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

#set(list) ⇒ Object



13
14
15
16
17
18
# File 'lib/watobo/gui/list_box.rb', line 13

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

#to_aObject



5
6
7
8
9
10
11
# File 'lib/watobo/gui/list_box.rb', line 5

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