Beispiel #1
0
 def make_spinbox_row(self, row, row_name, values, action, steps=[]):
   """
   """
   rowLabel = QtGui.QLabel(row_name)
   self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                             QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
   self.logger.debug("make_spinbox_row: processing dictionary: %s",
                     str(values))
   flatdict = flattenDict(values)
   keys = flatdict.keys()
   keys.sort()
   self.logger.debug("make_spinslider_row: new keys for dial row: %s",
                     str(keys))
   spinboxes = {}
   col = 1
   keylen = len(keys[0])
   for key in keys:
     col, colspan = self._position_widget(key,keylen,col)
     spinboxes[key] = QtGui.QSpinBox(self)
     if steps:
       spinboxes[key].setRange(steps[0],steps[1])
       spinboxes[key].setSingleStep(steps[2])
     self.gridLayout.addWidget(spinboxes[key], row, col, 1, colspan,
                               QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
     if flatdict[key] == None:
       spinboxes[key].setDisabled(True)
     else:
       spinboxes[key].setValue(flatdict[key])
       spinboxes[key].valueChanged.connect(
                        slotgen((self,row_name)+key+(spinboxes[key].value(),),
                        action))
     col += colspan
   return spinboxes
Beispiel #2
0
  def make_switch_row(self, row, row_name, states, inputs,
                      label_template="Input "):
    """
    Row of buttons to active radiobutton pop-ups.

    Typical use would be for a 1xN or Nx1 switch.

    Four parameters are required to describe this row.

    @param row : row number
    @type  row : int

    @param row_name : name of monitor data
    @type  row_name : str

    @param states : states of the switches
    @type  states : multi-level dict of ints

    @param inputs : names of N inputs or outputs
    @type  inputs : list of str

    @param label_template : generates label text if none is known
    @type  label_template : str
    """
    rowLabel = QtGui.QLabel(row_name)
    self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                              QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
    self.logger.debug("make_switch_row: processing dictionary: %s",
                      str(states))
    flatdict = flattenDict(states)
    keys = flatdict.keys()
    keys.sort()
    self.logger.debug("make_switch_row: new keys for switch row: %s",
                      str(keys))
    switches = {}
    col = 1
    if len(keys):
      keylen = len(keys[0])
      for key in keys:
        col, colspan = self._position_widget(key,keylen,col)
        value = flatdict[key]
        self.logger.debug("make_switch_row: key %s becomes %s", key, value)
        if value != 'None':
          switches[key] = QtGui.QPushButton(label_template+str(value))
          switches[key].inputs = inputs
          self._set_switch_button_text(switches[key], value, label_template)
        else:
          switches[key] = QtGui.QPushButton("None")
          switches[key].inputs = inputs
        self.logger.debug(
           "make_switch_row: connecting multi-selector pushbutton to popup %s",
           str(key))
        switches[key].clicked.connect(slotgen((self, row_name, key,
                                               switches[key]),
                                              self._switch_popup))
        self.gridLayout.addWidget(switches[key],
                                  row, col, 1, colspan,
                                  QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
        col += colspan
    return switches
Beispiel #3
0
  def make_dial_row(self, row, row_name,
                    values, value_range, format,
                    convertTo, convertFrom, action):
    """
    Make a row of dials

    Eight parameters are required to describe this row.

    @param row : row number
    @type  row : int

    @param row_name : name of monitor data
    @type  row_name : str

    @param values : dial state values
    @type  values : dict of float

    @param value_range : minimum and maximum value
    @type  value_range : tuple

    @param format : format for displayed values
    @type  format : str

    @param convertTo : converts dial integer to user value
    @type  convertTo : method

    @param convertFrom : converts user value to dial integer
    @ type convertFrom : method

    @param action : method to invoke on state change
    @type  action : dict of functions
    """
    rowLabel = QtGui.QLabel(row_name)
    self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                              QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
    self.logger.debug("make_dial_row: processing dictionary: %s", str(values))
    flatdict = flattenDict(values)
    keys = flatdict.keys()
    keys.sort()
    self.logger.debug("make_dial_row: new keys for dial row: %s", str(keys))
    dials = {}
    col = 1
    if keys:
      keylen = len(keys[0])
      for key in keys:
        col, colspan = self._position_widget(key,keylen,col)
        dials[key] = GeneralDial(value_range,
                                 format,
                                 convertFrom, convertTo)
        dials[key].setWrapping(False)
        dials[key].setNotchesVisible(True)
        self.gridLayout.addWidget(dials[key], row, col, 1, colspan,
                                QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
        if flatdict[key] == None:
          dials[key].setDisabled(True)
        else:
          dials[key].setRealValue(flatdict[key])
          dials[key].valueChanged.connect(slotgen((self,row_name)+key, action))
        col += colspan
    return dials
Beispiel #4
0
  def make_checkbutton_row(self, row, row_name, states, action):
    """
    Make a row of checkbuttons

    Four parameters are required to describe this row.

    @param row : row number
    @type  row : int

    @param row_name : name of monitor data
    @type  row_name : str

    @param states : checkbutton states
    @type  states : dict of bool

    @param action : method to invoke on state change
    @type  action : dict of functions
    """
    rowLabel = QtGui.QLabel(row_name)
    rowLabel.setSizePolicy(8,0)
    self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                              QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
    self.logger.debug("make_checkbutton_row: processing dictionary: %s",
                      str(states))
    flatdict = flattenDict(states)
    keys = flatdict.keys()
    keys.sort()
    self.logger.debug("make_checkbutton_row: new keys for checkbox row: %s",
                      str(keys))
    checkbuttons = {}
    col = 1
    if keys:
      keylen = len(keys[0])
      for key in keys:
        col, colspan = self._position_widget(key,keylen,col)
        checkbuttons[key] = QtGui.QCheckBox("On")
        checkbuttons[key].setSizePolicy(8,0)
        self.gridLayout.addWidget(checkbuttons[key],
                                  row, col, 1, colspan,
                                  QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
        if flatdict[key] == None:
          checkbuttons[key].setDisabled(True)
        else:
          checkbuttons[key].setChecked(flatdict[key])
          checkbuttons[key].clicked.connect(slotgen((self,row_name)+key,
                                                     action))
        col += colspan
    return checkbuttons
Beispiel #5
0
  def make_pushbutton_row(self, row, row_name, button_text, action):
    """
    Make a row of checkbuttons

    Four parameters are required to describe this row.

    @param row : row number
    @type  row : int

    @param row_name : name of monitor data
    @type  row_name : str

    @param button_text : dictionary of text to be put on the buttons
    @type  button_text : multiple depth dictionary

    @param action : methods to invoke on state change
    @type  action : dict of functions
    """
    rowLabel = QtGui.QLabel(row_name)
    self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                              QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
    self.logger.debug("make_pushbutton_row: processing dictionary: %s",
                      str(button_text))
    flatdict = flattenDict(button_text)
    keys = flatdict.keys()
    keys.sort()
    self.logger.debug("make_pushbutton_row: new keys for button row: %s",
                      str(keys))
    pushbuttons = {}
    col = 1
    keylen = len(keys[0])
    for key in keys:
      col, colspan = self._position_widget(key,keylen,col)
      pushbuttons[key] = QtGui.QPushButton(flatdict[key])
      self.gridLayout.addWidget(pushbuttons[key],
                                row, col, 1, colspan,
                                QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
      if flatdict[key] == None:
        pushbuttons[key].setDisabled(True)
      else:
        pushbuttons[key].clicked.connect(slotgen((self,row_name)+key, action))
      col += colspan
    return pushbuttons
Beispiel #6
0
 def make_spinslider_row(self, row, row_name, values, action, limits = []):
   """
   Note that 'step' does not follow the Python convention but the
   QSpinBox convention.
   """
   rowLabel = QtGui.QLabel(row_name)
   self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                             QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
   self.logger.debug("make_spinslider_row: processing dictionary: %s",
                     str(values))
   flatdict = flattenDict(values)
   keys = flatdict.keys()
   keys.sort()
   self.logger.debug("make_spinslider_row: new keys for dial row: %s",
                     str(keys))
   spinsliders = {}
   col = 1
   keylen = len(keys[0])
   for key in keys:
     col, colspan = self._position_widget(key,keylen,col)
     if limits:
       spinsliders[key] = SpinSlider(self,
                                     flatdict[key],
                                     minval=limits[0],
                                     maxval=limits[1])
     else:
       spinsliders[key] = SpinSlider(self,flatdict[key])
     self.gridLayout.addWidget(spinsliders[key], row, col, 1, colspan,
                               QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
     if flatdict[key] == None:
       spinsliders[key].setDisabled(True)
     else:
       spinsliders[key].setValue(flatdict[key])
       spinsliders[key].signal.valueChanged.connect(
               slotgen( (self,
                         row_name)+key+(spinsliders[key].value,),
                         action ))
     col += colspan
   return spinsliders
Beispiel #7
0
  def _switch_popup(self, *args):
    """
    Pop up a 1xN selector if a button is pressed

    Arguments consist of a row name, a column key and the associated switch.
    Condition is something set by the widget.

    @param args : (rowname, key, switch, condition)
    @type  args : tuple of ints
    """
    self.logger.debug(" _switch_popup: invoked with %s",str(args))
    frame, rowname, key, switch, condition = args
    self.logger.debug(" _switch_popup: switch is %s", switch)
    selector = Selector_Form(key, parent=self)
    selector.switch = switch
    self.logger.debug(" _switch_popup: selector is type %s", type(selector))
    selector.setupUi(switch.inputs, label_default="Port", cols=2)
    selector.setWindowTitle("IF selection")
    selector.show()
    selector.signal.stateChanged.connect(
          slotgen((selector,key,rowname), selector.update_selector))
    self.logger.debug(
                     " _switch_popup: multi-selector form popup(%s) completed",
                     key)