diff options
author | Cristhofer Travieso <cristhofert97@gmail.com> | 2012-07-28 21:53:06 (GMT) |
---|---|---|
committer | Cristhofer Travieso <cristhofert97@gmail.com> | 2012-07-28 21:53:06 (GMT) |
commit | b0315584003f6a4df993e84e5a7d181d9d87c991 (patch) | |
tree | 4a1d91cfd03cf57be94c4eaa84721ed6ad95b499 | |
parent | 9e9b8e11a9cd058d71c2457d35137065e1c31da6 (diff) |
Hize que label_info se defina correctamente
-rw-r--r-- | activity.py | 160 | ||||
-rw-r--r-- | activity/icon.svg | 12 |
2 files changed, 95 insertions, 77 deletions
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 <cristhofert97@gmail.com> +# Cristhofer Travieso <cristhofert97@gmail.com> # 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 @@ <inkscape:perspective id="perspective3725" inkscape:persp3d-origin="0.5 : 0.33333333 : 1" inkscape:vp_x="0 : 0.5 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="1 : 0.5 : 1" sodipodi:type="inkscape:persp3d"/> <inkscape:perspective id="perspective3749" inkscape:persp3d-origin="0.5 : 0.33333333 : 1" inkscape:vp_x="0 : 0.5 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="1 : 0.5 : 1" sodipodi:type="inkscape:persp3d"/> </defs> - <sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="100.93097" inkscape:cy="24.216625" inkscape:document-units="px" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="804" inkscape:window-maximized="1" inkscape:window-width="1200" inkscape:window-x="0" inkscape:window-y="30" inkscape:zoom="3.77" pagecolor="#ffffff" showgrid="false"/> + <sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="100.93097" inkscape:cy="24.216625" inkscape:document-units="px" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="864" inkscape:window-maximized="1" inkscape:window-width="1200" inkscape:window-x="0" inkscape:window-y="0" inkscape:zoom="3.77" pagecolor="#ffffff" showgrid="false"/> <metadata id="metadata7"> <rdf:RDF> <cc:Work rdf:about=""> @@ -22,11 +22,9 @@ </rdf:RDF> </metadata> <g id="layer1" inkscape:groupmode="layer" inkscape:label="Capa 1" transform="translate(0,-997.36218)"> - <g id="g2993" transform="translate(0.65251986,-7.9575597)"> - <path d="m 18.832891,32.453583 c 0,4.101849 -3.087691,7.427056 -6.896552,7.427056 -3.8088599,0 -6.8965512,-3.325207 -6.8965512,-7.427056 0,-4.10185 3.0876913,-7.427056 6.8965512,-7.427056 3.808861,0 6.896552,3.325206 6.896552,7.427056 z" id="path3715" sodipodi:cx="11.936339" sodipodi:cy="32.453583" sodipodi:rx="6.8965516" sodipodi:ry="7.4270558" sodipodi:type="arc" style="fill:&stroke_color;;fill-opacity:1;stroke:&fill_color;;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" transform="translate(-2.6525199,997.09693)"/> - <path d="m 18.832891,32.453583 c 0,4.101849 -3.087691,7.427056 -6.896552,7.427056 -3.8088599,0 -6.8965512,-3.325207 -6.8965512,-7.427056 0,-4.10185 3.0876913,-7.427056 6.8965512,-7.427056 3.808861,0 6.896552,3.325206 6.896552,7.427056 z" id="path3715-1" sodipodi:cx="11.936339" sodipodi:cy="32.453583" sodipodi:rx="6.8965516" sodipodi:ry="7.4270558" sodipodi:type="arc" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" transform="translate(33.822215,995.95722)"/> - <path d="M 9.5490721,18.129974 C 18.742165,16.843962 28.832408,11.371249 36.07427,19.190982 l -3.448275,3.713527 9.283819,10e-7 3.183024,-9.814324 -5.039787,3.713528 C 29.885058,8.2785342 19.717065,13.624849 9.5490721,18.129974 z" id="path3739" inkscape:connector-curvature="0" sodipodi:nodetypes="ccccccc" style="fill:&stroke_color;;fill-opacity:1;stroke:&fill_color;;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" transform="translate(0,997.36218)"/> - <path d="m 46.023806,1045.3826 c -9.193093,1.286 -19.283336,6.7587 -26.525198,-1.061 l 3.448275,-3.7135 -9.283819,0 -3.183024,9.8143 5.039787,-3.7135 c 10.167993,8.5251 20.335986,3.1788 30.503979,-1.3263 z" id="path3739-9" inkscape:connector-curvature="0" sodipodi:nodetypes="ccccccc" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/> - </g> + <path d="m 18.832891,32.453583 a 6.8965516,7.4270558 0 1 1 -13.7931032,0 6.8965516,7.4270558 0 1 1 13.7931032,0 z" id="path3715" sodipodi:cx="11.936339" sodipodi:cy="32.453583" sodipodi:rx="6.8965516" sodipodi:ry="7.4270558" sodipodi:type="arc" style="fill:&stroke_color;;fill-opacity:1;stroke:&fill_color;;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" transform="translate(-1.734748,990.20038)"/> + <path d="m 18.832891,32.453583 a 6.8965516,7.4270558 0 1 1 -13.7931032,0 6.8965516,7.4270558 0 1 1 13.7931032,0 z" id="path3715-1" sodipodi:cx="11.936339" sodipodi:cy="32.453583" sodipodi:rx="6.8965516" sodipodi:ry="7.4270558" sodipodi:type="arc" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" transform="translate(34.739987,989.06067)"/> + <path d="m 10.201592,1007.0041 c 9.193093,-1.286 19.283336,-6.7587 26.525198,1.061 l -3.448275,3.7135 9.283819,0 3.183024,-9.8143 -5.039787,3.7135 c -10.167993,-8.52515 -20.335986,-3.1788 -30.503979,1.3263 z" id="path3739" inkscape:connector-curvature="0" sodipodi:nodetypes="ccccccc" style="fill:&stroke_color;;fill-opacity:1;stroke:&fill_color;;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/> + <path d="m 47.737334,1040.3428 c -9.193093,1.286 -19.283336,6.7587 -26.525198,-1.061 l 3.448275,-3.7135 -9.283819,0 -3.183024,9.8143 5.039787,-3.7135 c 10.167993,8.5251 20.335986,3.1788 30.503979,-1.3263 z" id="path3739-9" inkscape:connector-curvature="0" sodipodi:nodetypes="ccccccc" style="fill:&fill_color;;fill-opacity:1;stroke:&stroke_color;;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/> </g> </svg>
\ No newline at end of file |