-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from BallAerospace/improve_intchooser_and_flo…
…atchooser closes #235. Improve IntChooser and FloatChooser validation
- Loading branch information
Showing
4 changed files
with
147 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# encoding: ascii-8bit | ||
|
||
# Copyright 2014 Ball Aerospace & Technologies Corp. | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can modify and/or redistribute it | ||
# under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; version 3 with | ||
# attribution addendums as found in the LICENSE.txt | ||
|
||
require 'cosmos' | ||
|
||
module Cosmos | ||
|
||
class ValueChooser < Qt::Widget | ||
|
||
# Callback for a new value entered into the text field | ||
attr_accessor :sel_command_callback | ||
|
||
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 | ||
|
||
# Returns the value as a string | ||
def string | ||
@value.text | ||
end | ||
|
||
# Returns the value as a string | ||
def value | ||
string() | ||
end | ||
|
||
# Sets the value of the text field | ||
def value=(new_value) | ||
@value.setText(new_value.to_s) | ||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters