module Vizkit::PortItemUserInteraction

Public Instance Methods

context_menu(pos,parent_widget,items = []) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 572
def context_menu(pos,parent_widget,items = [])
    if port.output?
        port_temp = port_from_items items
        return unless port_temp
        widget_name = Vizkit::ContextMenu.widget_for(port_temp.type_name,parent_widget,pos)
        if widget_name
            widget = Vizkit.display(port_temp, :widget => widget_name)
            set_widget_title(widget, port_temp.full_name)
            widget.setAttribute(Qt::WA_QuitOnClose, false) if widget.is_a? Qt::Widget
        end
    else
        widget_name = Vizkit::ContextMenu.control_widget_for(port.type_name,parent_widget,pos)
        if widget_name
            widget = Vizkit.control port, :widget => widget_name
        end
    end
end
mime_data(items=[]) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 590
def mime_data(items=[])
    port_temp = port_from_items items
    return 0 unless port_temp
    val = Qt::MimeData.new
    val.setText URI::Orocos.from_port(port_temp).to_s if defined? URI::DEFAULT_PARSER
    val
end
port_from_items(items = []) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 539
def port_from_items(items = [])
    # do not show context menu if clicked on second column
    return if items.find{|i|i.column == 1}
    sub_path = items.reverse.map(&:text)
    #convert string to number if possible
    sub_path = sub_path.map do |s|
        if s.to_i.to_s == s
            s.to_i
        else
            s
        end
    end
    if !sub_path.empty?
        item = items.last
        port.sub_port(sub_path)
    else
        port
    end
end
set_widget_title(widget, name) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 559
def set_widget_title(widget, name)
    # It seems that #respond_to? is broken on QtRuby. try the different
    # methods one by one ...
    begin
        widget.window_title = "#{name} #{widget.window_title}"
    rescue NoMethodError
        begin
            widget.setPluginName("#{name} #{widget.getPluginName}")
        rescue NoMethodError
        end
    end
end