Class: Cosmos::ValueChooser

Inherits:
Qt::Widget show all
Defined in:
lib/cosmos/gui/choosers/value_chooser.rb

Direct Known Subclasses

FloatChooser, IntegerChooser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, label_text, initial_value, field_width = 20, fill = false) ⇒ ValueChooser

Returns a new instance of ValueChooser.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cosmos/gui/choosers/value_chooser.rb', line 20

def initialize(parent, label_text, initial_value, field_width = 20, fill = false)
  super(parent)
  @field_width = field_width

  layout = Qt::HBoxLayout.new(self)
  layout.setContentsMargins(0,0,0,0)

  @label = Qt::Label.new(label_text)
  @label.setSizePolicy(Qt::SizePolicy::Fixed, Qt::SizePolicy::Fixed) if fill
  layout.addWidget(@label)
  layout.addStretch unless fill
  @value = Qt::LineEdit.new(initial_value.to_s)
  @value.setMinimumWidth(field_width)
  @callback_in_progress = false
  @value.connect(SIGNAL('editingFinished()')) do
    unless @callback_in_progress # Prevent double fire on loss of focus
      begin
        @callback_in_progress = true
        @sel_command_callback.call(string(), value()) if @sel_command_callback
      ensure
        @callback_in_progress = false
      end
    end
  end
  layout.addWidget(@value)
  setLayout(layout)

  @sel_command_callback = nil
end

Instance Attribute Details

#sel_command_callbackObject

Callback for a new value entered into the text field



18
19
20
# File 'lib/cosmos/gui/choosers/value_chooser.rb', line 18

def sel_command_callback
  @sel_command_callback
end

Instance Method Details

#stringObject

Returns the value as a string



51
52
53
# File 'lib/cosmos/gui/choosers/value_chooser.rb', line 51

def string
  @value.text
end

#valueObject

Returns the value as a string



56
57
58
# File 'lib/cosmos/gui/choosers/value_chooser.rb', line 56

def value
  string()
end

#value=(new_value) ⇒ Object

Sets the value of the text field



61
62
63
# File 'lib/cosmos/gui/choosers/value_chooser.rb', line 61

def value=(new_value)
  @value.setText(new_value.to_s)
end