Class: Cosmos::FileChooser
- Inherits:
-
Qt::Widget
- Object
- Qt::Base
- Qt::Widget
- Cosmos::FileChooser
- Defined in:
- lib/cosmos/gui/choosers/file_chooser.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Callback for a chosen filename.
Instance Method Summary collapse
- #filename ⇒ Object
- #filename=(filename) ⇒ Object
-
#initialize(parent, label_text, initial_value, button_text, file_path, field_width = 20, fill = false, extensions = nil) ⇒ FileChooser
constructor
A new instance of FileChooser.
Constructor Details
#initialize(parent, label_text, initial_value, button_text, file_path, field_width = 20, fill = false, extensions = nil) ⇒ FileChooser
Returns a new instance of FileChooser.
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 49 50 51 52 53 54 55 56 |
# File 'lib/cosmos/gui/choosers/file_chooser.rb', line 20 def initialize( parent, label_text, initial_value, , file_path, field_width = 20, fill = false, extensions = nil ) super(parent) layout = Qt::HBoxLayout.new(self) layout.setContentsMargins(0,0,0,0) @file_label = Qt::Label.new(label_text) @file_label.setSizePolicy(Qt::SizePolicy::Fixed, Qt::SizePolicy::Fixed) if fill layout.addWidget(@file_label) layout.addStretch unless fill @filename_value = Qt::LineEdit.new(initial_value.to_s) @filename_value.setMinimumWidth(field_width) @filename_value.setReadOnly(true) layout.addWidget(@filename_value) @select_button = Qt::PushButton.new() @select_button.connect(SIGNAL('clicked()')) do if extensions filename = Qt::FileDialog.getOpenFileName(self, , file_path, extensions) else filename = Qt::FileDialog.getOpenFileName(self, , file_path) end if !filename.to_s.empty? @filename_value.text = filename.to_s @callback.call(@filename_value.text) if @callback end end layout.addWidget(@select_button) setLayout(layout) @callback = nil end |
Instance Attribute Details
#callback ⇒ Object
Callback for a chosen filename
18 19 20 |
# File 'lib/cosmos/gui/choosers/file_chooser.rb', line 18 def callback @callback end |
Instance Method Details
#filename ⇒ Object
58 59 60 |
# File 'lib/cosmos/gui/choosers/file_chooser.rb', line 58 def filename @filename_value.text end |
#filename=(filename) ⇒ Object
62 63 64 |
# File 'lib/cosmos/gui/choosers/file_chooser.rb', line 62 def filename=(filename) @filename_value.text = filename.to_s end |