Exemplo n.º 1
0
 def make_custom_row(self, row, rowname, values, widgets):
   rowLabel = QtGui.QLabel(rowname)
   self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                             QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
   self.logger.debug("make_custom_row: processing dictionary: %s",
                     str(values))
   flatdict = flattenDict(values)
   keys = flatdict.keys()
   keys.sort()
   self.logger.debug("make_custom_row: new keys for custom row: %s",
                     str(keys))
   custom = {}
   col = 1
   keylen = len(keys[0])
   for key in keys:
     col, colspan = self._position_widget(key,keylen,col)
     if rowname == "Firmware":
       self.logger.debug("make_custom_row: column %s has firmware key %s",
                         key, flatdict[key])
       widget = widgets[flatdict[key]]
       self.logger.debug("make_custom_row: widget class is %s", widget)
       if widget:
         custom[key] = widget(self,key[0])
         self.logger.debug("make_custom_widget: at row %d, column %d",row,col)
         self.gridLayout.addWidget(custom[key], row, col, 1, colspan,
                                   QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
       else:
         custom[key] = None
     else:
       self.logger.error("make_custom_row: unknown category %s", rowname)
     col += colspan
   return custom
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
  def columnize(self,rows):
    """
    Extract information about multiply-indexed widgets to be gridded.

    One column will be created for each key in highest_depth_keys.
    Creates attribute::
     highest_depth_keys:      list of highest dimension keys

    @param rows : rows to be created in gridded frame
    @type  rows : list

    @return: tuple
    """
    dicts = []
    rekeyed = []
    flatdicts = []
    for row in rows:
      dicts.append(row['values'])
      keys = row['values'].keys()
      keys.sort()
      newdict = {}
      for index in range(len(keys)):
        key = keys[index]
        if type(key) == int:
          newdict[key] = row['values'][key]
        else:
          newdict[index] = row['values'][key]
      rekeyed.append(newdict)
    self.logger.debug("columnize: collected: %s", str(dicts))
    self.logger.debug("columnize: re-keyed: %s", str(rekeyed))
    for d in rekeyed:
      flatdicts.append(flattenDict(d))
    self.highest_depth_keys = self.get_highest_depth_keys(flatdicts)
    self.highest_depth_keys.sort()
Exemplo n.º 6
0
  def make_label_row(self, row, row_name, dictionary, **kwargs):
    """
    Make a row of labels in the grid

    Three parameters are required to describe the row.

    @param row : row number for positioning the widgets in the grid
    @type  row : int

    @param row_name : name of monitor data or control widget
    @type  row_name : str

    @param dictionary : values for the widgets in the row
    @type  dictionary : dict of whatever, defaulting to str
    """
    rowLabel = QtGui.QLabel(row_name)
    rowLabel.setSizePolicy(8,0)
    # the numeric arguments below are: row, column,rowspan, colspan
    self.gridLayout.addWidget(rowLabel, row, 0, 1, 1,
                              QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
    self.logger.debug("make_label_row: processing dictionary: %s",
                      str(dictionary))
    flatdict = flattenDict(dictionary)
    keys = flatdict.keys()
    keys.sort()
    self.logger.debug("make_label_row: new keys for label row: %s", str(keys))
    labels = {}
    # the following code figures out where to put the widgets
    col = 1
    if len(keys):
      keylen = len(keys[0])
      if kwargs.has_key('format'):
        format = kwargs['format']
      else:
        format = "%s"
      for key in keys:
        col, colspan = self._position_widget(key,keylen,col)
        labels[key] = QtGui.QLabel()
        labels[key].setSizePolicy(8,0)
        self.gridLayout.addWidget(labels[key],
                                  row, col, 1, colspan,
                                  QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
        if flatdict[key]:
          labels[key].setText(format % flatdict[key])
          labels[key].setFrameShape(QtGui.QFrame.Panel)
        else:
          labels[key].setText("None")
        col += colspan
    #if kwargs.has_key('slots'):
    #  for pair in kwargs['slots']:
    #    signal = pair[0]
    #    self.logger.debug("make_label_row: signal = %s", signal)
    #    slot = pair[1]
    #    self.logger.debug("make_label_row: slot = %s", slot)
    #    signal.connect(slot)
    return labels
Exemplo n.º 7
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
Exemplo n.º 8
0
 def update_RF_labels(self):
     """
 """
     levels = flattenDict(self.ADC_levels)
     for key in levels.keys():
         #roach = key[0]
         #adc = key[1]
         #rf = key[2]
         #self.ADC_levels[key[0]][key[1]][key[2]] = levels[key]
         #self.ADC_levels[roach][adc][rf] = levels[key]
         self.frames['Overview'].labels["RF level (dBm)"][key].setText(
             ("%5.2f" % levels[key]))
         self.frames['Signals'].labels["RF level (dBm)"][key].setText(
             ("%5.2f" % levels[key]))
         self.logger.debug(
             "refresh_RF_labels: Changed row 'RF level' column %s value to %s",
             key, levels[key])
Exemplo n.º 9
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
Exemplo n.º 10
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