def convert (self, amt1, unit1, unit2): density=None #if self.useDensityCheckButton.get_active(): density=self.densitySpinButton.get_value() if density <= 0 or not self.expander1.get_expanded(): density = None conversion = self.conv.convert_fancy(unit1, unit2, density=density) message = "" if conversion: amt2 = amt1 * conversion if amt2 < (0.05): retAmt = "%1.3e"%amt2 else: retAmt = convert.float_to_frac(amt2) result = "%s %s = <b>%s</b> %s"%(convert.float_to_frac(amt1), unit1, retAmt, unit2) else: result = _("Cannot convert %s to %s")%(unit1,unit2) if not density: message= _("Need density information.") if not self.expander1.get_expanded(): self.expander1.set_expanded(True) self.changed() self.itemComboBox.activate() self.resultLabel.set_text(result) self.resultLabel.set_use_markup(True) self.resultLabel.set_line_wrap(True) self.messageLabel.set_text("<i>%s</i>"%message) self.messageLabel.set_use_markup(True)
def create_rmodel (self): debug("create_rmodel (self):",5) mod = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING, gobject.TYPE_STRING) for r,mult in self.recs.values(): iter = mod.append(None) mod.set_value(iter,0,r) mod.set_value(iter,1,r.title) mod.set_value(iter,2,convert.float_to_frac(mult)) return mod
def testFractionGenerator(self): for d in [2, 3, 4, 5, 6, 8, 10, 16]: self.assertEqual( convert.float_to_frac(1.0 / d, fractions=convert.FRACTIONS_ASCII), ('1/%s' % d))
def testFractionGenerator (self): for d in [2,3,4,5,6,8,10,16]: self.assertEqual( convert.float_to_frac(1.0/d,fractions=convert.FRACTIONS_ASCII), ('1/%s'%d) )