class FlowTag::FlowTable
Public Class Methods
new(parent, flows)
click to toggle source
# File lib/flowtag/flowtable.rb, line 79 def initialize(parent, flows) @rows = 0 @tableframe = TkFrame.new(parent) header = '' (0..@@column_names.length-1).each do |i| header += @@column_names[i].center(@@column_lengths[i])+"|" end @table_header = TkLabel.new(@tableframe) { text header font TkFont.new('Monaco 12 bold') anchor 'sw' height 1 padx 0 pady 0 foreground 'lightblue' } @scrollbox = scrollbox = TkScrollbox.new(@tableframe) { setgrid 'yes' takefocus 'yes' width 59 font TkFont.new('Monaco 12') } @table_header.pack(:side=>'top',:fill=>'x') scrollbox.pack(:side=>'top',:fill=>'both',:expand=>1) scrollbox.bind('<ListboxSelect>', proc { |x| selected() }) addflows(flows) end
Public Instance Methods
addflow(flow)
click to toggle source
# File lib/flowtag/flowtable.rb, line 25 def addflow(flow) entry = Time.at(flow[FlowDB::ST]).strftime("%H:%M:%S")+" " (1..@@column_lengths.length-2).each do |i| entry += flow[i].to_s.rjust(@@column_lengths[i])+" " end entry += flow[FlowDB::TAGS].join(" ")[0,20] @scrollbox.insert 'end', entry end
addflows(flows)
click to toggle source
# File lib/flowtag/flowtable.rb, line 34 def addflows(flows) flows.each do |flow| addflow(flow) end end
clear()
click to toggle source
# File lib/flowtag/flowtable.rb, line 51 def clear @scrollbox.clear end
pack(*args)
click to toggle source
# File lib/flowtag/flowtable.rb, line 55 def pack(*args) @tableframe.pack(*args) end
selected()
click to toggle source
# File lib/flowtag/flowtable.rb, line 63 def selected items = [] indices = @scrollbox.curselection indices.each do |i| items.push(@scrollbox.get(i)) end if @select_cb @select_cb.call indices, items end @scrollbox.focus end
set_select_cb(callback)
click to toggle source
# File lib/flowtag/flowtable.rb, line 75 def set_select_cb(callback) @select_cb = callback end
unpack()
click to toggle source
# File lib/flowtag/flowtable.rb, line 59 def unpack @tableframe.unpack end
update_flow(idx, flow)
click to toggle source
# File lib/flowtag/flowtable.rb, line 40 def update_flow(idx, flow) entry = Time.at(flow[FlowDB::ST]).strftime("%H:%M:%S")+" " (1..@@column_lengths.length-2).each do |i| entry += flow[i].to_s.rjust(@@column_lengths[i])+" " end entry += flow[FlowDB::TAGS].join(" ")[0,20] @scrollbox.delete idx @scrollbox.insert idx, entry end