class Syskit::GUI::IDE::Picker

Public Class Methods

new(parent, items) click to toggle source
Calls superclass method
# File lib/syskit/gui/ide.rb, line 116
def initialize(parent, items)
    super(parent)

    model = Qt::StringListModel.new(self)
    model.string_list = items.sort
    @filter = Qt::SortFilterProxyModel.new(self)
    @filter.dynamic_sort_filter = true
    @filter.source_model = model

    @filter_text = Qt::LineEdit.new(self)
    @filter_text.connect(SIGNAL('textChanged(QString)')) do |text|
        @filter.filterRegExp = Qt::RegExp.new(text)
    end
    @list = Qt::ListView.new(self)
    @list.edit_triggers = Qt::AbstractItemView::NoEditTriggers
    @list.model = @filter
    @list.connect(SIGNAL('doubleClicked(const QModelIndex&)')) do |index|
        accept
    end
    @list.current_index = @filter.index(0, 0)

    resize(500, 500)

    layout = Qt::VBoxLayout.new(self)
    layout.add_widget(@filter_text)
    layout.add_widget(@list)

    buttons = Qt::DialogButtonBox.new(
        Qt::DialogButtonBox::Ok | Qt::DialogButtonBox::Cancel)
    connect(buttons, SIGNAL('accepted()'), self, SLOT('accept()'))
    connect(buttons, SIGNAL('rejected()'), self, SLOT('reject()'))
    layout.add_widget(buttons)
end
select(parent, items) click to toggle source
# File lib/syskit/gui/ide.rb, line 150
def self.select(parent, items)
    if items.empty?
        Qt::MessageBox.information(parent, "Nothing to pick",
            "There is nothing to pick from")
        return
    end
    new(parent, items).select
end

Public Instance Methods

select() click to toggle source
# File lib/syskit/gui/ide.rb, line 159
def select
    result = exec
    if result == Qt::Dialog::Accepted
        @filter.data(@list.current_index).
            to_string
    end
end