Example #1
0
class FileSelector(QWidget):
    ScopeLayout = 0
    ScopeDevice = 1
    ScopeFirmware = 2
    ScopeAll = 3

    def __init__(self):
        super(FileSelector, self).__init__()

        self.initUI()
        self.lastDir = None

    def initUI(self):

        self.scopeSelector = QComboBox()
        self.scopeSelector.addItem("Layout", FileSelector.ScopeLayout)
        self.scopeSelector.addItem("Device and RF", FileSelector.ScopeDevice)
        self.scopeSelector.addItem("Firmware Update",
                                   FileSelector.ScopeFirmware)
        # self.scopeSelector.addItem("All", FileSelector.ScopeAll)

        self.scopeSelector.currentIndexChanged.connect(self.scopeUpdate)

        self.layoutSettings = LayoutSettingsScope()
        self.deviceSettings = DeviceSettingsScope()
        self.firmwareSettings = FirmwareSettingsScope()

        self.scope = None

        self.layout = QVBoxLayout()
        self.layout.addWidget(self.scopeSelector)

        self.stackedLayout = QStackedLayout()
        self.stackedLayout.addWidget(self.layoutSettings)
        self.stackedLayout.addWidget(self.deviceSettings)
        self.stackedLayout.addWidget(self.firmwareSettings)

        self.layout.addLayout(self.stackedLayout)

        self.setMinimumSize(0, 300)

        self.setLayout(self.layout)
        # self.updateUI(FileSelector.ScopeLayout)

    def scopeUpdate(self, index):
        self.stackedLayout.setCurrentIndex(index)

    def updateUI(self, scope):
        if self.scope == scope:
            return

        self.layout.removeWidget(self.layoutSettings)
        self.layout.removeWidget(self.deviceSettings)
        self.layout.removeWidget(self.firmwareSettings)

        if scope == FileSelector.ScopeLayout:
            self.layout.addWidget(self.layoutSettings)
        elif scope == FileSelector.ScopeDevice:
            self.layout.addWidget(self.deviceSettings)
        elif scope == FileSelector.ScopeFirmware:
            self.layout.addWidget(self.firmwareSettings)
        elif scope == FileSelector.ScopeAll:
            self.layout.addWidget(self.layoutSettings)
            self.layout.addWidget(self.deviceSettings)
            self.layout.addWidget(self.firmwareSettings)

    def getProgramingInfo(self):
        return self.scopeSelector.currentIndex()

    def getFirmwareFile(self):
        return self.firmwareSettings.getFirmwareFile()

    def getLayoutFile(self):
        return self.layoutSettings.getLayoutFile()

    def getRFLayoutFile(self):
        return self.deviceSettings.getCurrentSettings()[2]

    def getRFFile(self):
        return self.deviceSettings.getCurrentSettings()[1]

    def getTargetID(self):
        return self.deviceSettings.getCurrentSettings()[0]
Example #2
0
class VerticalSideBarLayout(QFrame):
    def _hide_content_pane(self):
        self.layout().setStretch(0, 1)
        self.layout().setStretch(1, 0)

        self.stack_widget.setVisible(False)
        self.separator.setVisible(False)

    @Slot(int)
    def _tab_changed(self, ndx):
        w = self.side_widgets[ndx]

        if self.stack.currentWidget() == w and self.stack_widget.isVisible():
            self._hide_content_pane()
        else:
            self.layout().setStretch(0, 4)
            self.layout().setStretch(1, 1)
            self.stack_widget.setVisible(True)
            self.separator.setVisible(True)

        self.stack.setCurrentWidget(w)

    def _make_tabs_button(self, side_widgets, side_icons):

        if len(side_widgets) != len(side_icons):
            raise Exception(
                "Bad parameters : len(side_widgets) ({}) != len(side_icons) ({})"
                .format(len(side_widgets), len(side_icons)))

        layout = QVBoxLayout()

        self._side_icons = []

        ndx = 0
        for w in side_widgets:

            resource_name = side_icons[ndx]
            pixmap = QPixmap(os.path.join(resource_dir, resource_name))
            icon = QIcon(pixmap)
            self._side_icons.append(icon)

            b = QToolButton()
            b.setIcon(icon)
            b.setIconSize(pixmap.rect().size())
            b.setMaximumWidth(pixmap.rect().width() + 6)

            b.clicked.connect(self.signal_mapper_tab_changed.map)
            self.signal_mapper_tab_changed.setMapping(b, ndx)

            layout.addWidget(b)
            layout.setStretch(ndx, 1)
            ndx += 1

        layout.addStretch()

        return layout

    def show_star_on_widget(self, w, show=True):
        mainlog.debug("show_star_on_widget {} {}".format(w, show))

        n = self.stack.indexOf(w)

        if n < 0:
            mainlog.error("The widget was not found")
            return

        b = self.buttons_layout.itemAt(n).widget()

        widget_star = None
        for s in self.stars:
            if s.enlightened == b and s.enabled:
                mainlog.debug("Found a star for the widget")
                widget_star = s

        if show == False and widget_star:
            mainlog.debug("Removing a star")
            self.stars.remove(widget_star)
            widget_star.hide()
            widget_star.setParent(None)
            del widget_star
            return

        elif show == True and widget_star:
            mainlog.debug("Reshow")
            widget_star.show()
            widget_star.enabled = True

        elif show == True and not widget_star:

            mainlog.debug("Show new star")
            star = Star(b)
            star.show()
            star.raise_()
            self.stars.append(star)

    def show_widget(self, widget):

        if widget not in self.side_widgets:
            raise Exception(
                "Tring to show a widget that is not in the side widgets")

        self.stack_widget.setVisible(True)
        self.separator.setVisible(True)
        self.stack.setCurrentWidget(widget)

    def __init__(self, main_widget_or_layout, side_widgets, parent=None):
        super(VerticalSideBarLayout, self).__init__(parent)

        self.stars = []

        self.signal_mapper_tab_changed = QSignalMapper()
        self.signal_mapper_tab_changed.mapped.connect(self._tab_changed)

        self.side_widgets = side_widgets

        self.stack = QStackedLayout(self)
        for w in side_widgets:
            self.stack.addWidget(w)

        self.stack.setCurrentIndex(-1)

        # I need a widget so that I can show/hide it.
        # (we can't do that with a layout)
        self.stack_widget = QWidget(self)
        self.stack_widget.setLayout(self.stack)

        layout = QHBoxLayout()
        if isinstance(main_widget_or_layout, QWidget):
            layout.addWidget(main_widget_or_layout)
        else:
            layout.addLayout(main_widget_or_layout)

        # The panel layout is made of
        # stack of widgets, vertical separator, buttons for widget selection
        panel_layout = QHBoxLayout()
        panel_layout.addWidget(self.stack_widget)

        self.separator = VerticalSeparator(self)
        panel_layout.addWidget(self.separator)

        self.buttons_layout = self._make_tabs_button(
            side_widgets,
            ["appbar.cabinet.files.png", "thumb-up-3x.png"])  # ,"comments.png"
        panel_layout.addLayout(self.buttons_layout)

        # The panel layout is wrapped into an inline sub frame

        isf = InlineSubFrame(panel_layout, parent=self)
        isf.setObjectName("HorseSubFrame")  # ""HorseTightFrame")
        isf.layout().setContentsMargins(2, 2, 2, 2)

        # isf.setObjectName("HorseTightFrame")
        layout.addWidget(isf)

        # layout.setStretch(0,3)
        # layout.setStretch(1,2)

        self.setLayout(layout)
        self._hide_content_pane()
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)