Class: Cosmos::PacketLogFrame

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

Overview

Widget which displays a button to browse for log files. Files are listed and can be removed. Buttons exist to display start and stop time choosers which apply to all files in the list. The widget can also show a button which allows the user to change the Cosmos log file reader class.

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, multiple_file_select = true) ⇒ PacketLogFrame

Returns a new instance of PacketLogFrame.

Parameters:

  • parent (Qt::Widget)

    Parent to this dialog

  • log_directory (String)

    Initial directory to display when browsing for log files

  • packet_log_reader (PacketLogReader)

    The COSMOS log reader class used to parse the log

  • initial_filenames (Array<String>) (defaults to: [])

    Array of filenames to pre-populate the dialog with

  • initial_output_filename (String) (defaults to: nil)

    Initial output filename if show_output_filename is true

  • show_output_filename (Boolean) (defaults to: false)

    Whether to show the output filename and button to open a file chooser

  • show_time (Boolean) (defaults to: true)

    Whether to show the start and end time fields and buttons which popup a calendar browser

  • show_log_reader (Boolean) (defaults to: true)

    Whether to show the log reader class and button which popup a dialog to select a new log reader

  • input_filename_filter (String) (defaults to: Cosmos::BIN_FILE_PATTERN)

    File filter to apply when selecting input log files with the FileDialog

  • output_filename_filter (String) (defaults to: Cosmos::BIN_FILE_PATTERN)

    File filter to apply when selecting an output filename with the FileDialog

  • multiple_file_select (Boolean) (defaults to: true)

    Whether to allow multiple file selections when browsing for files



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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 70

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,
               multiple_file_select = true)
  super(parent)

  @output_select = :FILE
  @input_filename_filter = input_filename_filter
  @output_filename_filter = output_filename_filter
  @multiple_file_select = multiple_file_select
  @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
  @log_files_label = Qt::Label.new('Log Files:')
  @layout.addWidget(@log_files_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 = PacketLogFrameListWidget.new(self)
  @filenames.setSelectionMode(Qt::AbstractItemView::ExtendedSelection)
  @filenames.setSortingEnabled(true)
  @filenames.delete_callback = method(:handle_remove_button)
  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

  # Declare these regardless of if show_time is set so getters and setters work
  @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
    @packet_log_reader_label = Qt::Label.new('Packet Log Reader:')
    @layout.addWidget(@packet_log_reader_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)
    @plr_select_button = Qt::PushButton.new('Select')
    @plr_select_button.connect(SIGNAL('clicked()')) { handle_log_reader_button() }
    @layout.addWidget(@plr_select_button, row, 3)
    row += 1
  end

  setLayout(@layout)
end

Instance Attribute Details

#change_callback#call

Returns Callback called when something changes. Called with the item that was changed as a symbol. The possible values are :INPUT_FILES, :OUTPUT_FILE, :OUTPUT_DIR, :TIME_START, :TIME_END, :LOG_READER.

Returns:

  • (#call)

    Callback called when something changes. Called with the item that was changed as a symbol. The possible values are :INPUT_FILES, :OUTPUT_FILE, :OUTPUT_DIR, :TIME_START, :TIME_END, :LOG_READER



47
48
49
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 47

def change_callback
  @change_callback
end

#output_filename_filterString

Returns Output filename filter. Must conform to the syntax as described in the Qt::FileDialog class.

Returns:

  • (String)

    Output filename filter. Must conform to the syntax as described in the Qt::FileDialog class.



42
43
44
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 42

def output_filename_filter
  @output_filename_filter
end

#packet_log_readerPacketLogReader (readonly)

Returns Log reader class to use.

Returns:



39
40
41
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 39

def packet_log_reader
  @packet_log_reader
end

#time_endTime

Returns End time of packets to process.

Returns:

  • (Time)

    End time of packets to process



37
38
39
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 37

def time_end
  @time_end
end

#time_startTime

Returns Start time of packets to process.

Returns:

  • (Time)

    Start time of packets to process



35
36
37
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 35

def time_start
  @time_start
end

Instance Method Details

#filenamesArray<String>

Returns The chosen filenames.

Returns:



181
182
183
184
185
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 181

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

#output_filenameString

Returns The output filename.

Returns:

  • (String)

    The output filename



188
189
190
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 188

def output_filename
  @output_filename.text
end

#output_filename=(output_filename) ⇒ Object

Parameters:

  • output_filename (String)

    Output filename to set



193
194
195
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 193

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

#select_output_dirObject

Change the output selection to select a directory (not a file)



204
205
206
207
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 204

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

#select_output_fileObject

Change the output selection to select a file (not a directory)



198
199
200
201
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 198

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

#show_log_fields(show_fields) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/cosmos/gui/widgets/packet_log_frame.rb', line 229

def show_log_fields(show_fields)
  if show_fields
    @filenames.show if @filenames
    @log_files_label.show if @log_files_label
    @browse_button.show if @browse_button
    @remove_button.show if @remove_button
    @packet_log_reader_field.show if @packet_log_reader_field
    @packet_log_reader_label.show if @packet_log_reader_label
    @plr_select_button.show if @plr_select_button
  else
    @filenames.hide if @filenames
    @log_files_label.hide if @log_files_label
    @browse_button.hide if @browse_button
    @remove_button.hide if @remove_button
    @packet_log_reader_field.hide if @packet_log_reader_field
    @packet_log_reader_label.hide if @packet_log_reader_label
    @plr_select_button.hide if @plr_select_button
  end
end