From b0315584003f6a4df993e84e5a7d181d9d87c991 Mon Sep 17 00:00:00 2001 From: Cristhofer Travieso Date: Sat, 28 Jul 2012 21:53:06 +0000 Subject: Hize que label_info se defina correctamente --- diff --git a/activity.py b/activity.py index c7fae71..5058475 100644 --- a/activity.py +++ b/activity.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # activity.py by: -# Cristhofer Travieso +# 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 @@ -28,14 +28,14 @@ from sugar.graphics.toolbarbox import ToolbarBox from sugar.graphics.radiotoolbutton import RadioToolButton -lenght = {"Metro": 1, "Km": 1000, "cm": 0.01, "Yarda": 1.09361, "Pie": 3.28084, - "Brazas": 0.5468} -speed = {"km/hs": 1} -area = {"m2": 1} -weight = {"g": 1, "Kg": 1000} -volume = {"m3": 1} -time = {"hs": 1} -temp = {"C": 1} +lenght = {"Meter": 1, "Kilometer": 0.001, "Centimeter": 0.01, "Yard": 1.09361, + "Foot": 3.28084, "Fathoms": 0.5468} +speed = {"Km/H": 1} +area = {"M2": 1} +weight = {"Gram": 1, "Kilogram": 1000} +volume = {"M3": 1} +time = {"Hour": 1} +temp = {"Celsius": 1} class ConvertActivity(activity.Activity): @@ -44,6 +44,40 @@ class ConvertActivity(activity.Activity): self.dic = {} + #Canvas + self.canvas = gtk.VBox() + + self.set_canvas(self.canvas) + + hbox = gtk.HBox() + self.canvas.pack_start(hbox, False, padding=5) + self.combo1 = gtk.combo_box_new_text() + hbox.pack_start(self.combo1, False, True, 2) + + flip_btn = gtk.Button() + flip_btn.add(gtk.image_new_from_file("icons/flip.svg")) + hbox.pack_start(flip_btn, True, False) + + self.combo2 = gtk.combo_box_new_text() + hbox.pack_end(self.combo2, False, True, 2) + + adjustment = gtk.Adjustment(1.0, 0.1, 1000, 0.1, 0.1, 0.1) + spin_box = gtk.HBox() + self.spin_btn = gtk.SpinButton(adjustment, 1.0, 1) + self.spin_btn.connect("value-changed", self._update_label) + spin_box.pack_start(self.spin_btn, True, False) + self.canvas.pack_start(spin_box, False, False, 5) + + self.label = gtk.Label() + self.label.set_text("%s ~ %s" % (str(self.spin_btn.get_value()), + str(self.spin_btn.get_value()))) + self.label.modify_font(pango.FontDescription('80')) + self.canvas.pack_start(self.label, True, True, 5) + + self.label_info = gtk.Label(" Convert \n000 x 000 = 000") + self.canvas.pack_start(self.label_info, True, True, 5) + + #Toolbar toolbarbox = ToolbarBox() activity_button = ActivityToolbarButton(self) @@ -57,43 +91,50 @@ class ConvertActivity(activity.Activity): # RadioToolButton self._lenght_btn = RadioToolButton() - self._lenght_btn.connect("clicked", lambda w: self.update_combo(lenght)) - self._lenght_btn.set_tooltip("lenght") + self._lenght_btn.connect("clicked", + lambda w: self._update_combo(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)) - self._volume_btn.set_tooltip("volume") + self._volume_btn.connect("clicked", + lambda w: self._update_combo(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)) - self._area_btn.set_tooltip("area") + self._area_btn.connect("clicked", + lambda w: self._update_combo(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)) - self._weight_btn.set_tooltip("weight") + self._weight_btn.connect("clicked", + lambda w: self._update_combo(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(speed)) - self._speed_btn.set_tooltip("speed") + self._speed_btn.connect("clicked", + lambda w: self._update_combo(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(time)) - self._time_btn.set_tooltip("time") + self._time_btn.connect("clicked", + lambda w: self._update_combo(time)) + self._time_btn.set_tooltip("Time") self._time_btn.props.icon_name = "time" self._time_btn.props.group = self._lenght_btn self._temp_btn = RadioToolButton() - self._temp_btn.connect("clicked", lambda w: self.update_combo(temp)) - self._temp_btn.set_tooltip("temperature") + self._temp_btn.connect("clicked", + lambda w: self._update_combo(temp)) + self._temp_btn.set_tooltip("Temperature") self._temp_btn.props.icon_name = "temp" self._temp_btn.props.group = self._lenght_btn @@ -115,68 +156,47 @@ class ConvertActivity(activity.Activity): toolbarbox.toolbar.insert(stopbtn, -1) self.set_toolbar_box(toolbarbox) - - #Canvas - self.canvas = gtk.VBox() - - self.set_canvas(self.canvas) - - hbox = gtk.HBox() - self.canvas.pack_start(hbox, False, padding=5) - self.combo1 = gtk.combo_box_new_text() - hbox.pack_start(self.combo1, False, True, 2) - - flip_btn = gtk.Button() - flip_btn.add(gtk.image_new_from_file("icons/flip.svg")) - hbox.pack_start(flip_btn, True, False) - - self.combo2 = gtk.combo_box_new_text() - hbox.pack_end(self.combo2, False, True, 2) - - adjustment = gtk.Adjustment(1.0, 0.1, 1000, 0.1, 0.1, 0.1) - spin_box = gtk.HBox() - self.spin_btn = gtk.SpinButton(adjustment, 1.0, 1) - self.spin_btn.connect("button-press-event", self.update_label) - spin_box.pack_start(self.spin_btn, True, False) - self.canvas.pack_start(spin_box, False, False, 5) - - self.label = gtk.Label() - self.label.set_text("%s ~ %s" % (str(self.spin_btn.get_value()), - str(self.spin_btn.get_value()))) - self.label.modify_font(pango.FontDescription('80')) - self.canvas.pack_start(self.label, True, True, 5) - - label_info = gtk.Label(" Convert \n000 x 000 = 000") - self.canvas.pack_start(label_info, True, True, 5) - - #self.dic = lenght + self._update_combo(lenght) self.show_all() - def update_label(self, widget, data=None): - self.label.set_text("%s ~ %s" % (str(self.spin_btn.get_value()), - self.convert())) + def _update_label(self, widget): + self.label.set_text("%s ~ %s" % (str(widget.get_value()), + self._convert())) - def update_combo(self, data): + def _update_combo(self, data): for x in self.dic.keys(): - print x self.combo1.remove_text(0) self.combo2.remove_text(0) self.dic = data for x in self.dic.keys(): self.combo1.append_text(x) self.combo2.append_text(x) + self.combo1.set_active(0) + self.combo2.set_active(0) self.show_all() - def get_active_text(self, combobox): + def _get_active_text(self, combobox): model = combobox.get_model() active = combobox.get_active() if active < 0: return None return model[active][0] - def convert(self): - _number = self.spin_btn.get_value() - _unit = self.get_active_text(self.combo1) - _to_unit = self.get_active_text(self.combo2) - _value = _number * self.dic[_unit] - return _value * self.dic[_to_unit] + def _update_label_info(self, igual=False, text1=None, text2=None): + if igual: + value = 1 + else: + value = self.dic[text1] * self.dic[text2] + self.label_info.set_text("%s x %s = %s" % (str(text1), str(value), + str(text2))) + + 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(igual=True, text1=unit, text2=to_unit) + return number + else: + self._update_label_info(igual=False, text1=unit, text2=to_unit) + return number * self.dic[unit] * self.dic[to_unit] diff --git a/activity/icon.svg b/activity/icon.svg index dbb4838..d55cd86 100644 --- a/activity/icon.svg +++ b/activity/icon.svg @@ -11,7 +11,7 @@ - + @@ -22,11 +22,9 @@ - - - - - - + + + + \ No newline at end of file -- cgit v0.9.1