class SummaryTab(QWidget):
  """
  Represents the ping output in a numeric format
  """
  def __init__(self, parent=None):
    super(SummaryTab, self).__init__(parent)
    #create the widgets
    self.label_info = QLabel("No summary data to display")
    label_sent_packets = QLabel("Sent Packet Count")
    self.label_sent_packets = StyledLabel()
    self.label_sent_packets.setMaximumHeight(30)
    label_received_packets = QLabel("Received Packet Count")
    self.label_received_packets = StyledLabel()
    self.label_received_packets.setMaximumHeight(30)
    label_packets_lost = QLabel("Packets Lost")
    self.label_packets_lost = StyledLabel()
    self.label_packets_lost.setMaximumHeight(30)
    label_loss_percentage = QLabel("Packet Loss Percentage")
    self.label_loss_percentage = StyledLabel()
    self.label_loss_percentage.setMaximumHeight(30)
    label_output_delay = QLabel("Average Output Delay")
    self.label_output_delay = StyledLabel()
    self.label_output_delay.setMaximumHeight(30)
    #setup summary_layout
    #first, setup a stacked summary_layout to indicate first there's no summary data
    self.layout_stack = QStackedLayout()
    summary_centerer_layout = QHBoxLayout()
    summary_layout = QGridLayout() #if I use formlayout, i'm afraid things will stretch out too much horizontally
    row = 1; col = 0;
    summary_layout.addWidget(label_sent_packets, row, col)
    col += 2
    summary_layout.addWidget(self.label_sent_packets, row, col) #leave a middle column empty
    row += 1; col -= 2;
    summary_layout.addWidget(label_received_packets, row, col)
    col += 2
    summary_layout.addWidget(self.label_received_packets, row, col)
    row += 1; col -= 2
    summary_layout.addWidget(label_packets_lost, row, col)
    col += 2
    summary_layout.addWidget(self.label_packets_lost, row, col)
    row += 1; col -= 2;
    summary_layout.addWidget(label_loss_percentage, row, col)
    col += 2
    summary_layout.addWidget(self.label_loss_percentage, row, col)
    row += 1; col -= 2;
    summary_layout.addWidget(label_output_delay, row, col)
    col += 2
    summary_layout.addWidget(self.label_output_delay, row, col)
    #center things out
    summary_layout.setColumnMinimumWidth(1, 100) # 100 pixels in the middle
    summary_layout.setRowMinimumHeight(0, 10) #100 pixels from top
    summary_centerer_layout.addStretch()
    summary_centerer_layout.addLayout(summary_layout)
    summary_centerer_layout.addStretch()
    #make a dump widget for the stacked summary_layout
    widget = QWidget()
    widget.setLayout(summary_centerer_layout)
    self.layout_stack.insertWidget(0, widget)
    #setup summary_layout for info label!
    layout_info_label = QVBoxLayout()
    layout_info_label.addStretch()
    layout_info_label.addWidget(self.label_info)
    layout_info_label.addStretch()
    #make dump widget for info label summary_layout!!
    widget_info_label = QWidget()
    widget_info_label.setLayout(layout_info_label)
    self.layout_stack.insertWidget(1, widget_info_label)
    self.setLayout(self.layout_stack)
    self.zeroOut()
    
  def setSummaryData(self, summaryData):
    self.label_sent_packets.setText(str(summaryData.sent_packets))
    self.label_received_packets.setText(str(summaryData.received_packets))
    self.label_packets_lost.setText(str(summaryData.packets_lost))
    self.label_loss_percentage.setText("%.2f %%" % summaryData.loss_percentage)
    self.label_output_delay.setText("%.2f ms" % summaryData.output_delay)
    self.layout_stack.setCurrentIndex(0)
    
  def zeroOut(self):
    #set all summary fields to their defaults
    self.setSummaryData(SummaryData(0, 0, 0))
    self.layout_stack.setCurrentIndex(1)