From 3799e3d03a1a2e40582c40ec4e1ed702a7c1885b Mon Sep 17 00:00:00 2001 From: Agustin Zubiaga Date: Wed, 22 Aug 2012 16:02:48 +0000 Subject: Fixing a lot of bugs Change: * Using gettext * More clear log * Using markup in combos Signed-off-by: Agustin Zubiaga Signed-off-by: Cristhofer Travieso --- diff --git a/activity.py b/activity.py index 5ae66c0..abb88b7 100644 --- a/activity.py +++ b/activity.py @@ -1,4 +1,4 @@ -#Copyright (C) 2012 Cristhofer Travieso +# Copyright (C) 2012 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 @@ -25,7 +25,10 @@ from sugar.activity.widgets import ActivityToolbarButton from sugar.graphics.toolbarbox import ToolbarBox from sugar.graphics.radiotoolbutton import RadioToolButton +from gettext import gettext as _ + SCREEN_WIDTH = gtk.gdk.screen_width() +ENTER_KEY = 65293 class ConvertActivity(activity.Activity): @@ -38,27 +41,37 @@ class ConvertActivity(activity.Activity): self._canvas = gtk.VBox() hbox = gtk.HBox() - self.combo1 = gtk.combo_box_new_text() + self._liststore1 = gtk.ListStore(str) + self.combo1 = gtk.ComboBox(self._liststore1) + cell = gtk.CellRendererText() + self.combo1.pack_start(cell, True) + self.combo1.add_attribute(cell, 'markup', 0) self.combo1.connect('changed', self._call) flip_btn = gtk.Button() flip_btn.connect('clicked', self._flip) flip_btn.add(gtk.image_new_from_file('icons/flip.svg')) - self.combo2 = gtk.combo_box_new_text() + self._liststore2 = gtk.ListStore(str) + self.combo2 = gtk.ComboBox(self._liststore1) + cell = gtk.CellRendererText() + self.combo2.pack_start(cell, True) + self.combo2.add_attribute(cell, 'markup', 0) self.combo2.connect('changed', self._call) + self.label_box = gtk.HBox() self.adjustment = gtk.Adjustment(1.0, 1.0, 10000.0, 0.1, 1.0) self.spin = gtk.SpinButton(self.adjustment, 0.0, 1) self.label = gtk.Label() + self.label._size = 12 self.label.connect('expose-event', self.resize_label) - self.convert_btn = gtk.Button(' Convert ') + self.convert_btn = gtk.Button(_('Convert')) self.convert_btn.connect('clicked', self._call) - self.label_info = gtk.Label('convert:\n') + self.label_info = gtk.Label() self.label_info.modify_font(pango.FontDescription('12')) self._canvas.pack_start(hbox, False, False, 20) @@ -93,41 +106,41 @@ class ConvertActivity(activity.Activity): self._lenght_btn = RadioToolButton() self._lenght_btn.connect('clicked', lambda w: self._update_combo(convert.lenght)) - self._lenght_btn.set_tooltip('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(convert.volume)) - self._volume_btn.set_tooltip('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(convert.area)) - self._area_btn.set_tooltip('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(convert.weight)) - self._weight_btn.set_tooltip('Weight') + 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(convert.speed)) - self._speed_btn.set_tooltip('Speed') + self._speed_btn.set_tooltip(_('Speed')) self._speed_btn.props.icon_name = 'speed' self._speed_btn.props.group = self._lenght_btn self._time_btn = RadioToolButton() self._time_btn.connect('clicked', lambda w: self._update_combo(convert.time)) - self._time_btn.set_tooltip('Time') + self._time_btn.set_tooltip(_('Time')) self._time_btn.props.icon_name = 'time' self._time_btn.props.group = self._lenght_btn @@ -151,16 +164,19 @@ class ConvertActivity(activity.Activity): self.show_all() def _update_label(self): - spin_value = str(self.spin.get_value()) - decimals = str(len(spin_value.split('.')[-1])) - new_value = locale.format('%.' + decimals + 'f', float(spin_value)) + try: + spin_value = str(self.spin.get_value()) + decimals = str(len(spin_value.split('.')[-1])) + new_value = locale.format('%.' + decimals + 'f', float(spin_value)) - convert_value = str(self.convert()) - decimals = str(len(convert_value.split('.')[-1])) - new_convert = locale.format('%.' + decimals + 'f', float(convert_value)) + convert_value = str(self.convert()) + decimals = str(len(convert_value.split('.')[-1])) + new_convert = locale.format('%.' + decimals + 'f', float(convert_value)) - a = '%s ~ %s' % (new_value, new_convert) - self.label.set_text(a) + text = '%s ~ %s' % (new_value, new_convert) + self.label.set_text(text) + except KeyError: + pass def _call(self, widget=None): _unit = self._get_active_text(self.combo1) @@ -170,13 +186,17 @@ class ConvertActivity(activity.Activity): self.show_all() def _update_combo(self, data): - for x in self.dic.keys(): - self.combo1.remove_text(0) - self.combo2.remove_text(0) + self._liststore1.clear() + self._liststore2.clear() self.dic = data for x in self.dic.keys(): - self.combo1.append_text(x) - self.combo2.append_text(x) + symbol = '' + if len(self.dic[x]) == 3: + symbol = self.dic[x][-1] + symbol = '%s' % symbol + + self._liststore1.append(['%s%s' % (x, symbol)]) + self._liststore2.append(['%s%s' % (x, symbol)]) self.combo1.set_active(0) self.combo2.set_active(0) self._call() @@ -187,7 +207,10 @@ class ConvertActivity(activity.Activity): active = combobox.get_active() if active < 0: return None - return model[active][0] + text = model[active][0] + if '' in text: + text = text.split('')[1].split('')[0] + return text def _flip(self, widget): active_combo1 = self.combo1.get_active() @@ -198,29 +221,28 @@ class ConvertActivity(activity.Activity): self._call() def update_label_info(self, util=None, to_util=None): - value = self.dic[util][0] * self.dic[to_util][1] - self.label_info.set_text(' Convert: \n %s x %s = %s' % (str(util), - str(value), str(to_util))) + try: + value = self.dic[util][0] * self.dic[to_util][1] + self.label_info.set_text(' %s: \n %s x %s = %s' % (_('Convert'), + str(util), + str(value), str(to_util))) + except KeyError: + pass def resize_label(self, widget, event): num_label = len(self.label.get_text()) - size = str((60 * SCREEN_WIDTH / 100) / num_label) try: - self.label.modify_font(pango.FontDescription(size)) + size = str((60 * SCREEN_WIDTH / 100) / num_label) + if not size == self.label._size: + self.label.modify_font(pango.FontDescription(size)) + self.label._size = size except ZeroDivisionError: pass def convert(self): - number = float(self.spin.get_text().replace(",", ".")) + number = float(self.spin.get_text().replace(',', '.')) unit = self._get_active_text(self.combo1) to_unit = self._get_active_text(self.combo2) return convert.convert(number, unit, to_unit, self.dic) - def recut(self, num): - num = str(num) - before_dot = num.split('.')[0] - then_dot = num.split('.')[1] - - short_num = before_dot + '.' + then_dot[:2] - return float(short_num) diff --git a/convert.py b/convert.py index 638e355..603c763 100644 --- a/convert.py +++ b/convert.py @@ -1,8 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# convert.py by: -# Cristhofer Travieso +# Copyright (C) 2012 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 @@ -18,78 +14,92 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -lenght = {'Meters[m]': (1, 1), 'Kilometers[km]': (1000, 0.001), - 'Centimeter[cm]': (0.01, 100), - 'Cables': (185.0, 0.00540540540541), - 'Milimeters[mm]': (0.001, 1000), 'Decimeter[dm]': (0.1, 10), - 'Decameter': (10, 0.1), - 'Hectometers[cm]': (100, 0.01), - 'Chains': (20.1, 0.0497512437811), 'Ell': (1.14, 0.877192982456), - 'Ems(pica)': (0.00422, 236.966824645), - 'Fathoms': (1.83, 0.546448087432), - 'Foot': (0.3048, 3.280839895013123), - 'Furlongs': (201.0, 0.00497512437811), - 'Inches[in]': (0.0254, 39.3700787402), - 'Micrometers': (0.000001, 1000000.0), - 'Scandinavian mile': (10000, 0.0001), - 'Yards': (0.914, 1.09409190372) +from gettext import gettext as _ + +lenght = {_('Meters (m)'): (1, 1), + _('Kilometers (km)'): (1000, 0.001), + _('Centimeter (cm)'): (0.01, 100), + _('Cables'): (185.0, 0.00540540540541), + _('Milimeters (mm)'): (0.001, 1000), + _('Decimeter (dm)'): (0.1, 10), + _('Decameter'): (10, 0.1), + _('Hectometers (hm)'): (100, 0.01), + _('Chains'): (20.1, 0.0497512437811), + _('Ell'): (1.14, 0.877192982456), + _('Ems (Pica)'): (0.00422, 236.966824645), + _('Fathoms'): (1.83, 0.546448087432), + _('Foot'): (0.3048, 3.280839895013123), + _('Furlongs'): (201.0, 0.00497512437811), + _('Inches (in)'): (0.0254, 39.3700787402), + _('Micrometers'): (0.000001, 1000000.0), + _('Scandinavian mile'): (10000, 0.0001), + _('Yards'): (0.914, 1.09409190372) } -area = {'Meter2': (1, 1), 'Foot2': (0.092903, 10.763915051182416), - 'Yard2': (0.836127, 1.1959905612424908), - 'Inch2': (0.00064516, 1550.0031000062002), - 'Kilometer2': (1000000, 0.000001), - 'Mile2': (2589990, 3.8610187684122333e-7), - 'Centimeter2': (0.0001, 10000), 'milimeter2': (0.000001, 1000000), - 'Micrometer2': (1e-12, 1000000000000), - 'Acre': (4046.86, 0.00024710516301527604) +area = {_('Meter'): (1, 1, 2), + _('Foot'): (0.092903, 10.763915051182416, 2), + _('Yard'): (0.836127, 1.1959905612424908, 2), + _('Inch'): (0.00064516, 1550.0031000062002, 2), + _('Kilometer'): (1000000, 0.000001, 2), + _('Mile'): (2589990, 3.8610187684122333e-7, 2), + _('Centimeter'): (0.0001, 10000, 2), + _('milimeter'): (0.000001, 1000000, 2), + _('Micrometer'): (1e-12, 1000000000000, 2), + _('Acre'): (4046.86, 0.00024710516301527604) } -weight = {'Gram': (1, 1), 'Kilogram': (1000, 0.001), - 'Miligram': (0.001, 1000.0000000000001), 'Ton': (1000000, 0.000001), - 'Pound': (453.592, 0.0022046244201837776), - 'Ounce': (28.3495, 0.03527399072294044), 'Carrat': (0.2, 5) +weight = {_('Gram'): (1, 1), + _('Kilogram'): (1000, 0.001), + _('Miligram'): (0.001, 1000.0000000000001), + _('Ton'): (1000000, 0.000001), + _('Pound'): (453.592, 0.0022046244201837776), + _('Ounce'): (28.3495, 0.03527399072294044), + _('Carrat'): (0.2, 5) } -volume = {'Meter3': (1, 1), 'Foot3': (0.0283168, 35.31472482766414), - 'Yard3': (0.764555, 1.307950376362721), - 'Inch3': (0.0000163871, 61023.61003472243), - 'Kilometer3': (1000000000, 1e-9), - 'Mile3': (4168180000, 2.399128636479231e-10), - 'Centimeter3': (0.000001, 1000000), - 'Milimeter': (1e-9, 999999999.9999999), 'Liter': (0.001, 1000), - 'Milliliter': (0.000001, 1000000), - 'Pint': (0.000473176, 2113.378531455526), - 'Quart': (0.000946353, 1056.6881491367385), - 'Gallon': (0.00378541, 264.172176857989) +volume = {_('Meter'): (1, 1, 3), + _('Foot'): (0.0283168, 35.31472482766414, 3), + _('Yard'): (0.764555, 1.307950376362721, 3), + _('Inch'): (0.0000163871, 61023.61003472243, 3), + _('Kilometer'): (1000000000, 1e-9, 3), + _('Mile'): (4168180000, 2.399128636479231e-10, 3), + _('Centimeter'): (0.000001, 1000000, 3), + _('Milimeter'): (1e-9, 999999999.9999999), + _('Liter'): (0.001, 1000), + _('Milliliter'): (0.000001, 1000000), + _('Pint'): (0.000473176, 2113.378531455526), + _('Quart'): (0.000946353, 1056.6881491367385), + _('Gallon'): (0.00378541, 264.172176857989) } -speed = {'Kilometers/Hour': (1, 1), - 'Centimeter/Minute': (0.000679856115108, 1470.8994709), - 'Centimeter/Second': (0.0359712230216, 27.8), - 'Foot/Hour': (0.000304676258993, 3282.17237308), - 'Feet/Minute': (0.018273381295, 54.7244094488), - 'Feet/Second': (1.09712230216, 0.911475409836), - 'Iches/Second': (0.0913669064748, 10.9448818898), - 'Kilometers/Second': (3597.12230216, 0.000278), - 'Knots': (1.84892086331, 0.540856031128), - 'Mach': (1194.24460432, 0.00083734939759), - 'Meter/Second': (3.59712230216, 0.278), +speed = {_('Kilometers/Hour'): (1, 1), + _('Centimeter/Minute'): (0.000679856115108, 1470.8994709), + _('Centimeter/Second'): (0.0359712230216, 27.8), + _('Foot/Hour'): (0.000304676258993, 3282.17237308), + _('Feet/Minute'): (0.018273381295, 54.7244094488), + _('Feet/Second'): (1.09712230216, 0.911475409836), + _('Inches/Second'): (0.0913669064748, 10.9448818898), + _('Kilometers/Second'): (3597.12230216, 0.000278), + _('Knots'): (1.84892086331, 0.540856031128), + _('Mach'): (1194.24460432, 0.00083734939759), + _('Meter/Second'): (3.59712230216, 0.278), } -time = {'day': (1, 1), 'Week': (7, 0.14285714285714285), - 'Month': (30.4375, 0.03285420944558522), - 'Year': (365.25, 0.0027378507871321013), - 'Hour': (0.041666666666666664, 24), - 'Minute': (0.0006944444444444445, 1440), - 'Second': (0.000011574074074074073, 86400), - 'Millisecond': (1.1574074074074074e-8, 86400000), - 'Microsecond': (1.1574074074074074e-11, 86400000000), - 'Nanosecond': (1.1574074074074075e-14, 86400000000000), - 'Picosecond': (1.1574074074074074e-17, 86400000000000000), +time = {_('Day'): (1, 1), + _('Week'): (7, 0.14285714285714285), + _('Month'): (30.4375, 0.03285420944558522), + _('Year'): (365.25, 0.0027378507871321013), + _('Hour'): (0.041666666666666664, 24), + _('Minute'): (0.0006944444444444445, 1440), + _('Second'): (0.000011574074074074073, 86400), + _('Millisecond'): (1.1574074074074074e-8, 86400000), + _('Microsecond'): (1.1574074074074074e-11, 86400000000), + _('Nanosecond'): (1.1574074074074075e-14, 86400000000000), + _('Picosecond'): (1.1574074074074074e-17, 86400000000000000), } def convert(number, unit, to_unit, dic): main_unit = number * dic[unit][0] return main_unit * dic[to_unit][1] + diff --git a/po/Convert.pot b/po/Convert.pot new file mode 100644 index 0000000..45a1f10 --- /dev/null +++ b/po/Convert.pot @@ -0,0 +1,294 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-08-22 14:42+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: activity/activity.info:2 activity.py:60 activity.py:208 +msgid "Convert" +msgstr "" + +#: activity.py:98 +msgid "Lenght" +msgstr "" + +#: activity.py:104 +msgid "Volume" +msgstr "" + +#: activity.py:111 +msgid "Area" +msgstr "" + +#: activity.py:118 +msgid "Weight" +msgstr "" + +#: activity.py:125 +msgid "Speed" +msgstr "" + +#: activity.py:132 +msgid "Time" +msgstr "" + +#: convert.py:19 +msgid "Meters (m)" +msgstr "" + +#: convert.py:20 +msgid "Kilometers (km)" +msgstr "" + +#: convert.py:21 +msgid "Centimeter (cm)" +msgstr "" + +#: convert.py:22 +msgid "Cables" +msgstr "" + +#: convert.py:23 +msgid "Milimeters (mm)" +msgstr "" + +#: convert.py:24 +msgid "Decimeter (dm)" +msgstr "" + +#: convert.py:25 +msgid "Decameter" +msgstr "" + +#: convert.py:26 +msgid "Hectometers (hm)" +msgstr "" + +#: convert.py:27 +msgid "Chains" +msgstr "" + +#: convert.py:28 +msgid "Ell" +msgstr "" + +#: convert.py:29 +msgid "Ems (Pica)" +msgstr "" + +#: convert.py:30 +msgid "Fathoms" +msgstr "" + +#: convert.py:31 convert.py:40 convert.py:61 +msgid "Foot" +msgstr "" + +#: convert.py:33 +msgid "Inches (in)" +msgstr "" + +#: convert.py:34 +msgid "Micrometers" +msgstr "" + +#: convert.py:35 +msgid "Scandinavian mile" +msgstr "" + +#: convert.py:36 +msgid "Yards" +msgstr "" + +#: convert.py:39 convert.py:60 +msgid "Meter" +msgstr "" + +#: convert.py:41 convert.py:62 +msgid "Yard" +msgstr "" + +#: convert.py:42 convert.py:63 +msgid "Inch" +msgstr "" + +#: convert.py:43 convert.py:64 +msgid "Kilometer" +msgstr "" + +#: convert.py:44 convert.py:65 +msgid "Mile" +msgstr "" + +#: convert.py:45 convert.py:66 +msgid "Centimeter" +msgstr "" + +#: convert.py:46 +msgid "milimeter" +msgstr "" + +#: convert.py:47 +msgid "Micrometer" +msgstr "" + +#: convert.py:48 +msgid "Acre" +msgstr "" + +#: convert.py:51 +msgid "Gram" +msgstr "" + +#: convert.py:52 +msgid "Kilogram" +msgstr "" + +#: convert.py:53 +msgid "Miligram" +msgstr "" + +#: convert.py:54 +msgid "Ton" +msgstr "" + +#: convert.py:55 +msgid "Pound" +msgstr "" + +#: convert.py:56 +msgid "Ounce" +msgstr "" + +#: convert.py:57 +msgid "Carrat" +msgstr "" + +#: convert.py:67 +msgid "Milimeter" +msgstr "" + +#: convert.py:68 +msgid "Liter" +msgstr "" + +#: convert.py:69 +msgid "Milliliter" +msgstr "" + +#: convert.py:70 +msgid "Pint" +msgstr "" + +#: convert.py:71 +msgid "Quart" +msgstr "" + +#: convert.py:72 +msgid "Gallon" +msgstr "" + +#: convert.py:75 +msgid "Kilometers/Hour" +msgstr "" + +#: convert.py:76 +msgid "Centimeter/Minute" +msgstr "" + +#: convert.py:77 +msgid "Centimeter/Second" +msgstr "" + +#: convert.py:78 +msgid "Foot/Hour" +msgstr "" + +#: convert.py:79 +msgid "Feet/Minute" +msgstr "" + +#: convert.py:80 +msgid "Feet/Second" +msgstr "" + +#: convert.py:81 +msgid "Inches/Second" +msgstr "" + +#: convert.py:82 +msgid "Kilometers/Second" +msgstr "" + +#: convert.py:83 +msgid "Knots" +msgstr "" + +#: convert.py:84 +msgid "Mach" +msgstr "" + +#: convert.py:85 +msgid "Meter/Second" +msgstr "" + +#: convert.py:88 +msgid "Day" +msgstr "" + +#: convert.py:89 +msgid "Week" +msgstr "" + +#: convert.py:90 +msgid "Month" +msgstr "" + +#: convert.py:91 +msgid "Year" +msgstr "" + +#: convert.py:92 +msgid "Hour" +msgstr "" + +#: convert.py:93 +msgid "Minute" +msgstr "" + +#: convert.py:94 +msgid "Second" +msgstr "" + +#: convert.py:95 +msgid "Millisecond" +msgstr "" + +#: convert.py:96 +msgid "Microsecond" +msgstr "" + +#: convert.py:97 +msgid "Nanosecond" +msgstr "" + +#: convert.py:98 +msgid "Picosecond" +msgstr "" + +#: convert.py:32 +msgid "Furlongs)" +msgstr "" -- cgit v0.9.1