From b7e06a31417b35d7ea6282a0a7681aff51399ce6 Mon Sep 17 00:00:00 2001 From: Cristhofer Travieso Date: Wed, 08 Aug 2012 21:00:07 +0000 Subject: Cree un archivo convert.py para realizar la conversion en un archivo aparte y un convertline.py una interfas de linea --- diff --git a/activity.py b/activity.py index d27b7f8..7385f31 100644 --- a/activity.py +++ b/activity.py @@ -28,28 +28,6 @@ from sugar.graphics.toolbarbox import ToolbarBox from sugar.graphics.radiotoolbutton import RadioToolButton -lenght = {'Meter': 1, 'Kilometer': 0.001, 'Centimeter': 100, 'Yard': 1.09361, - 'Foot': 3.28084, 'Fathoms': 0.5468, 'mm': 1000, 'dm': 10, 'dam': 0.1, - 'hm': 0.01} - -speed = {'Km/H': 1} - -area = {'Meter2': 1, 'Kilometer2': 0.001, 'Centimeter2': 100, 'Yard2': 1.09361, - 'Foot2': 3.28084, 'Fathoms2': 0.5468, 'mm2': 1000, 'dm2': 10, - 'dam2': 0.1, 'hm2': 0.01} - -weight = {'Gram': 1, 'hg': 0.01, 'dag': 0.1, 'dg': 10, 'cg': 100, 'mg': 1000, - 'Kilogram': 1000} - -volume = {'Meter3': 1, 'Kilometer3': 0.001, 'Centimeter3': 100, - 'Yard3': 1.09361, 'Foot3': 3.28084, 'Fathoms3': 0.5468, 'mm3': 1000, - 'dm3': 10, 'dam3': 0.1, 'hm3': 0.01, 'Liter': 1, 'Kiloliter': 0.001, - 'Centiliter': 100, 'ml': 1000, 'dl': 10, 'dal': 0.1, 'hl': 0.01} - - -temp = {'Celsius': 1} - - class ConvertActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle, True) @@ -114,41 +92,41 @@ class ConvertActivity(activity.Activity): # RadioToolButton self._lenght_btn = RadioToolButton() self._lenght_btn.connect('clicked', - lambda w: self._update_combo(lenght)) + lambda w: self._update_combo(convert.lenght)) self._lenght_btn.set_tooltip('Lenght') self._lenght_btn.props.icon_name = 'lenght' self._volume_btn = RadioToolButton() self._volume_btn.connect('clicked', - lambda w: self._update_combo(volume)) + lambda w: self._update_combo(convert.volume)) self._volume_btn.set_tooltip('Volume') self._volume_btn.props.icon_name = 'volume' self._volume_btn.props.group = self._lenght_btn self._area_btn = RadioToolButton() self._area_btn.connect('clicked', - lambda w: self._update_combo(area)) + lambda w: self._update_combo(convert.area)) self._area_btn.set_tooltip('Area') self._area_btn.props.icon_name = 'area' self._area_btn.props.group = self._lenght_btn self._weight_btn = RadioToolButton() self._weight_btn.connect('clicked', - lambda w: self._update_combo(weight)) + lambda w: self._update_combo(convertweight)) self._weight_btn.set_tooltip('Weight') self._weight_btn.props.icon_name = 'weight' self._weight_btn.props.group = self._lenght_btn self._speed_btn = RadioToolButton() self._speed_btn.connect('clicked', - lambda w: self._update_combo(speed)) + lambda w: self._update_combo(convert.speed)) self._speed_btn.set_tooltip('Speed') self._speed_btn.props.icon_name = 'speed' self._speed_btn.props.group = self._lenght_btn self._temp_btn = RadioToolButton() self._temp_btn.connect('clicked', - lambda w: self._update_combo(temp)) + lambda w: self._update_combo(convert.temp)) self._temp_btn.set_tooltip('Temperature') self._temp_btn.props.icon_name = 'temp' self._temp_btn.props.group = self._lenght_btn @@ -170,12 +148,12 @@ class ConvertActivity(activity.Activity): toolbarbox.toolbar.insert(stopbtn, -1) self.set_toolbar_box(toolbarbox) - self._update_combo(lenght) + self._update_combo(convert.lenght) self.show_all() def _update_label(self): self.label.set_text('%s ~ %s' % (str(self.spin_btn.get_value()), - str(self._convert()))) + str(self.convert()))) def _update_combo(self, data): for x in self.dic.keys(): @@ -197,7 +175,6 @@ class ConvertActivity(activity.Activity): return None return model[active][0] - #idea para cambiar los valores de los combos def _flip(self, widget): active_combo1 = self.combo1.get_active() active_combo2 = self.combo2.get_active() @@ -206,26 +183,25 @@ class ConvertActivity(activity.Activity): self.spin_btn.set_value(float(self.label.get_text().split(' ~ ')[1])) self._update_label() - def _update_label_info(self, igual=False, util=None, to_util=None): + def update_label_info(self, igual=False, util=None, to_util=None): if igual: value = 1 else: - value = round(self.dic[util] * self.dic[to_util], 2) + value = self.dic[util] * self.dic[to_util], 2 self.label_info.set_text(' Convert \n %s x %s = %s' % (str(util), str(value), str(to_util))) - def _convert(self): + def resize_label(self, widget, event): + num_label = len(self.label.get_text()) + self.label.modify_font(pango.FontDescription(str(720 / num_label))) + + def convert(self): number = self.spin_btn.get_value() unit = self._get_active_text(self.combo1) to_unit = self._get_active_text(self.combo2) - if unit == to_unit: - self._update_label_info(True, unit, to_unit) - return self._round(number) - else: - self._update_label_info(False, unit, to_unit) - return self._round(number * self.dic[unit] * self.dic[to_unit]) + convert.convert(number, unit, to_unit, ) - def _round(self, num): + def recut(self, num): num = str(num) before_dot = num.split('.')[0] then_dot = num.split('.')[1] @@ -233,8 +209,3 @@ class ConvertActivity(activity.Activity): short_num = before_dot + '.' + then_dot[:2] return float(short_num) - - def resize_label(self, widget, event): - num_label = len(self.label.get_text()) - self.label.modify_font(pango.FontDescription(str(num_label))) - print 'lechuga' diff --git a/convert.py b/convert.py new file mode 100644 index 0000000..147df97 --- /dev/null +++ b/convert.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# convert.py by: +# Cristhofer Travieso + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +lenght = {'Meter': 1, 'Kilometer': 0.001, 'Centimeter': 0.01, 'Yard': 1.09361, + 'Foot': 3.28084, 'Fathoms': 0.5468, 'mm': 0.001, 'dm': 0.1, 'dam': 10, + 'hm': 100} + +speed = {'Km/H': 1} + +area = {'Meter2': 1, 'Kilometer2': 0.001, 'Centimeter2': 100, 'Yard2': 1.09361, + 'Foot2': 3.28084, 'Fathoms2': 0.5468, 'mm2': 1000, 'dm2': 10, + 'dam2': 0.1, 'hm2': 0.01} + +weight = {'Gram': 1, 'hg': 0.01, 'dag': 0.1, 'dg': 10, 'cg': 100, 'mg': 1000, + 'Kilogram': 1000} + +volume = {'Meter3': 1, 'Kilometer3': 0.001, 'Centimeter3': 100, + 'Yard3': 1.09361, 'Foot3': 3.28084, 'Fathoms3': 0.5468, 'mm3': 1000, + 'dm3': 10, 'dam3': 0.1, 'hm3': 0.01, 'Liter': 1, 'Kiloliter': 0.001, + 'Centiliter': 100, 'ml': 1000, 'dl': 10, 'dal': 0.1, 'hl': 0.01} + + +temp = {'Celsius': 1} + +dic = lenght + + +def convert(number, unit, to_unit): + return number * dic[unit] * dic[to_unit] + + +# def convert(self): +# number = self.spin_btn.get_value() +# unit = self._get_active_text(self.combo1) +# to_unit = self._get_active_text(self.combo2) +# if unit == to_unit: +# self.update_label_info(True, unit, to_unit) +# return self.recut(number) +# else: +# self.update_label_info(False, unit, to_unit) +# return self.recut(number * self.dic[unit] * self.dic[to_unit]) +# diff --git a/convertline.py b/convertline.py new file mode 100644 index 0000000..5e923b4 --- /dev/null +++ b/convertline.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# convert.py by: +# Cristhofer Travieso + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import convert + +print '*********convert*********' +print convert.lenght.keys() +unit = raw_input('Ingresa una medida: ') +to_unit = raw_input('Ingresa la tra medida: ') +number = input('Ingresa el numero: ') + +print convert.convert(number, unit, to_unit) -- cgit v0.9.1