Class: Cosmos::PacketLogFrame

Inherits:
Qt::Widget show all
Defined in:
lib/cosmos/gui/widgets/packet_log_frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, log_directory, packet_log_reader, initial_filenames = [], initial_output_filename = nil, show_output_filename = false, show_time = true, show_log_reader = true, input_filename_filter = Cosmos::BIN_FILE_PATTERN, output_filename_filter = Cosmos::BIN_FILE_PATTERN) ⇒ PacketLogFrame

Returns a new instance of PacketLogFrame.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 34

def initialize(parent,
               log_directory,
               packet_log_reader,
               initial_filenames = [],
               initial_output_filename = nil,
               show_output_filename = false,
               show_time = true,
               show_log_reader = true,
               input_filename_filter = Cosmos::BIN_FILE_PATTERN,
               output_filename_filter = Cosmos::BIN_FILE_PATTERN)
  super(parent)

  @output_select = :FILE
  @input_filename_filter = input_filename_filter
  @output_filename_filter = output_filename_filter
  @log_directory = log_directory
  if initial_output_filename
    @output_directory = File.dirname(initial_output_filename)
  else
    @output_directory = log_directory.clone
  end
  @packet_log_reader = packet_log_reader
  @time_start = nil
  @time_end = nil
  @change_callback = nil

  @layout = Qt::GridLayout.new
  @layout.setContentsMargins(0,0,0,0)

  row = 0

  # Chooser for Log Files
  label = Qt::Label.new('Log Files:')
  @layout.addWidget(label, row, 0, 1, 2)
  @browse_button = Qt::PushButton.new('Browse...')
  @browse_button.connect(SIGNAL('clicked()')) { handle_browse_button() }
  @layout.addWidget(@browse_button, row, 2)
  @remove_button = Qt::PushButton.new('Remove')
  @remove_button.connect(SIGNAL('clicked()')) { handle_remove_button() }
  @layout.addWidget(@remove_button, row, 3)
  row += 1

  @filenames = Qt::ListWidget.new(self)
  @filenames.setSelectionMode(Qt::AbstractItemView::ExtendedSelection)
  @filenames.setSortingEnabled(true)
  initial_filenames.each {|filename| @filenames.addItem(filename)}
  @filenames.setMinimumHeight(90)
  @layout.addWidget(@filenames, row, 0, 3, 4)
  row += 3

  if show_output_filename
    @output_filename_label = Qt::Label.new('Output File:')
    @layout.addWidget(@output_filename_label, row, 0)
    @output_filename = Qt::LineEdit.new(initial_output_filename.to_s)
    @output_filename.setMinimumWidth(340)
    @output_filename.setReadOnly(true)
    @layout.addWidget(@output_filename, row, 1, 1, 2)
    @output_filename_select_button = Qt::PushButton.new('Select')
    @output_filename_select_button.connect(SIGNAL('clicked()')) { handle_output_file_button() }
    @layout.addWidget(@output_filename_select_button, row, 3)
    row += 1
  end

  @time_start_field = Qt::LineEdit.new('N/A')
  @time_end_field = Qt::LineEdit.new('N/A')
  if show_time
    %w(Start End).each do |time|
      time_label = Qt::Label.new("Time Period #{time}:")
      @layout.addWidget(time_label, row, 0)
      if time == 'Start'
        time_field = @time_start_field
      else
        time_field = @time_end_field
      end
      time_field.setMinimumWidth(340)
      time_field.setReadOnly(true)
      @layout.addWidget(time_field, row, 1)
      time_clear_button = Qt::PushButton.new('Clear')
      time_clear_button.connect(SIGNAL('clicked()')) { handle_time_clear_button(time, time_field) }
      @layout.addWidget(time_clear_button, row, 2)
      time_button = Qt::PushButton.new('Select')
      time_button.connect(SIGNAL('clicked()')) { handle_time_select_button(time, time_field) }
      @layout.addWidget(time_button, row, 3)
      row += 1
    end
  end

  if show_log_reader
    @packet_log_reader = PacketLogReader.new unless @packet_log_reader

    # Chooser or label for log reader
    label = Qt::Label.new('Packet Log Reader:')
    @layout.addWidget(label, row, 0)
    @packet_log_reader_field = Qt::LineEdit.new(@packet_log_reader.class.to_s)
    @packet_log_reader_field.setMinimumWidth(340)
    @packet_log_reader_field.setReadOnly(true)
    @layout.addWidget(@packet_log_reader_field, row, 1, 1, 2)
    select_button = Qt::PushButton.new('Select')
    select_button.connect(SIGNAL('clicked()')) { handle_log_reader_button() }
    @layout.addWidget(select_button, row, 3)
    row += 1
  end

  setLayout(@layout)
end

Instance Attribute Details

#change_callbackObject

Callback called when something changes



32
33
34
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 32

def change_callback
  @change_callback
end

#output_filename_filterObject

Output filename filter



29
30
31
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 29

def output_filename_filter
  @output_filename_filter
end

#packet_log_readerObject (readonly)

Log reader to use



26
27
28
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 26

def packet_log_reader
  @packet_log_reader
end

#time_endObject

End time of packets to process



23
24
25
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 23

def time_end
  @time_end
end

#time_startObject

Start time of packets to process



20
21
22
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 20

def time_start
  @time_start
end

Instance Method Details

#filenamesObject

Returns the chosen filenames



141
142
143
144
145
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 141

def filenames
  filename_array = []
  @filenames.each {|list_item| filename_array << list_item.text}
  filename_array
end

#output_filenameObject

Return the output filename



148
149
150
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 148

def output_filename
  @output_filename.text
end

#output_filename=(new_output_filename) ⇒ Object

Set the output filename



153
154
155
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 153

def output_filename= (new_output_filename)
  @output_filename.setText(new_output_filename.to_s)
end

#select_output_dirObject



162
163
164
165
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 162

def select_output_dir
  @output_filename_label.text = 'Output Dir:'
  @output_select = :DIR
end

#select_output_fileObject



157
158
159
160
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 157

def select_output_file
  @output_filename_label.text = 'Output File:'
  @output_select = :FILE
end