Example #1
0
 def testNegative(self):
     """Tests the function with negative values."""
     for n, trim, nontrim in self.TESTS[1:]:
         self.assertEqual(
             util.stringFromFloat(-n, 2, True),  u'\u2212' + trim)
         self.assertEqual(
             util.stringFromFloat(-n, 2, False), u'\u2212' + nontrim)
Example #2
0
 def testNonNuber(self):
     """Tests the function with non-numeric arguments."""
     try:
         util.stringFromFloat('foo', 2, False)
     except TypeError:
         pass
     else:
         self.fail()
Example #3
0
def makeList(currents):
    si = tuple(util.stringFromFloat(i, 2, True) for i in currents)
    if len(currents) == 1:
        return si[0]
    if len(currents) == 2:
        return si[0] + gettext(' and ') + si[1]
    else:
        return gettext(', ').join(si[:-1]) + gettext(', and ') + si[-1]
Example #4
0
    def _updateStatusBar(self):
        """
        Updates the information shown in the window's status bar. This method
        is called by GTK in the main event loop.
        """
        temperature = self._system.temperature
        voltage = self._system.temperatureSensorVoltage
        if temperature != None:
            text = u'%d °C' % temperature
        else:
            text = u'%s V' % util.stringFromFloat(voltage, 4, False)
        self._temperatureLabel.set_text(text)

        # TODO: The timeout is never properly removed.
        return True   # Yes, this method should be called again.
Example #5
0
 def label(value):
     return util.stringFromFloat(value, 8, True)
Example #6
0
    def _update(self):
        """
        Updates the progress widgets with the latest progress information.
        """
        if self._calibrationManager == None:
            return False   # We're done; the timeout can be removed.

        progress = self._calibrationManager.getExtendedProgress()
        stageProgress, stageTimeLeft, totalProgress, totalTimeLeft = progress

        state = self._calibrationManager.state

        if state == STATE_MOVING_HEATER:
            action = gettext('Moving the heater forwards')
        elif state in (STATE_HEATING, STATE_WAITING_FOR_TEMPERATURE):
            current = self._calibrationManager.system.heatingCurrent
            current = util.stringFromFloat(current, 8, True)
            action = gettext('Heating with %s mA') % current
        else:
            assert False

        assert 0.0 <= stageProgress <= 1.0
        assert 0.0 <= totalProgress <= 1.0

        stageProgressText = '%d%%' % (round(stageProgress * 100))
        totalProgressText = '%d%%' % (round(totalProgress * 100))

        for bar, showText in self.stageProgressBars:
            bar.set_fraction(stageProgress)
            if showText:
                bar.set_text(stageProgressText)

        for bar, showText in self.totalProgressBars:
            bar.set_fraction(totalProgress)
            if showText:
                bar.set_text(totalProgressText)

        if stageTimeLeft == None:
            stageTimeLeftText = gettext('unknown')
        else:
            stageTimeLeftText = util.stringFromTimePeriod(stageTimeLeft)

        if totalTimeLeft == None:
            totalTimeLeftText = gettext('unknown')
        else:
            totalTimeLeftText = util.stringFromTimePeriod(totalTimeLeft)

        substitutions = {
            'action':        action,
            'stageProgress': stageProgressText,
            'stageTimeLeft': stageTimeLeftText,
            'totalProgress': totalProgressText,
            'totalTimeLeft': totalTimeLeftText,
            'emptyString':   ''}

        for label, template, noTimeTemplate in self.progressLabels:
            if stageTimeLeft == None or totalTimeLeft == None:
                label.set_text(noTimeTemplate % substitutions)
            else:
                label.set_text(template % substitutions)

        return True   # This method should be called again.
Example #7
0
 def testPositive(self):
     """Tests the function with positive values."""
     for n, trim, nontrim in self.TESTS:
         self.assertEqual(util.stringFromFloat(n, 2, True),  trim)
         self.assertEqual(util.stringFromFloat(n, 2, False), nontrim)
Example #8
0
 def cellDataRounder(column, renderer, model, iterator):
     value = model.get_value(iterator, index)
     text = util.stringFromFloat(value, fractionalDigits, trimTrailingZeros)
     renderer.set_property('text', text)