[opencoffee-devel] Segundo parche calculadora |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opencoffee-devel Archives
]
- To: opencoffee-devel@xxxxxxxxxxxxxxxxxxx
- Subject: [opencoffee-devel] Segundo parche calculadora
- From: "Jose Arcangel Salazar Delgado" <arcangel.salazar@xxxxxxxxx>
- Date: Sat, 1 Sep 2007 19:59:25 -0500
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=IPSBh9eGqP4dn8u2ZlHf9xcxBnWktCuYqsxeY0hI0K3BoS42e0FbNOd/FCqAA6ifze96bymTRkgB65jQmquTsm1d6sy9AAPbaAcdzi97XXPGoQo2tQXt+XGoZau6epZALHuVzRIXdEN0PhW4tvoT6rP5VfCLxj6D1BjUPQJxXhs=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=I+3CsYO44uWv0lb9nb5vu7idxVummXE4Rrb82O4994mnfkN2cQp3Ohk8pqP4pghyBH8DHAtt+Df6NHpaYChycNcVNk11meZwzCeMx91c2eFmLX9kUxhIyYENsemLrAtFN3GwRgkdSR7gr+AwSn6Qf6bmdH7Dlo2l/cs3bnGSUr0=
Aquí está el segundo parche para la calculadora hecho para el snapshot
231, que corrige los siguientes bugs:
* Problema de inexactitud en las operaciones de punto flotante.
* Eliminación del punto decimal cuando el resultado es entero.
Espero que ya no halla más bugs y que sea de utilidad.
P.D. estoy a la espera de alguna otra tarea.
diff -u -r -x .svn -x .project -x .pydevproject -x .pyc -x db opencoffee-server/core/tools/calc.py workspace/opencoffee-server/core/tools/calc.py
--- opencoffee-server/core/tools/calc.py 2007-08-31 18:26:25.000000000 -0500
+++ workspace/opencoffee-server/core/tools/calc.py 2007-09-01 19:16:59.000000000 -0500
@@ -21,8 +21,6 @@
# Contact: Gustavo DÃaz, GDNet Projects - www.gdnet.com.ar | Email:gdiaz@xxxxxxxxxxxx
-## TODO: Implementar los shorcuts de las teclas.
-
import sys
import os
from PyQt4.QtCore import *
@@ -41,7 +39,7 @@
self.gui = gui
- ## Definimos la conexiones de los botones de funciones
+ #Definimos la conexiones de los botones de funciones
self.connect(self.gui.key_clear, SIGNAL("clicked()"), self.onKeyClearClicked)
self.connect(self.gui.key_clearAll, SIGNAL("clicked()"), self.onKeyClearAllClicked)
self.connect(self.gui.key_comma, SIGNAL("clicked()"), self.onKeyCommaClicked)
@@ -49,7 +47,7 @@
self.connect(self.gui.key_PlusMinus, SIGNAL("clicked()"), self.onKeyPlusMinusClicked)
- ## Definimos la conexiones de los botones numéricos
+ #Definimos la conexiones de los botones numéricos
self.connect(self.gui.key_0, SIGNAL("clicked()"), self.onDigitClicked)
self.connect(self.gui.key_1, SIGNAL("clicked()"), self.onDigitClicked)
self.connect(self.gui.key_2, SIGNAL("clicked()"), self.onDigitClicked)
@@ -62,7 +60,7 @@
self.connect(self.gui.key_9, SIGNAL("clicked()"), self.onDigitClicked)
- ## Definimos la conexiones de los botones de operaciones
+ #Definimos la conexiones de los botones de operaciones
self.connect(self.gui.key_plus, SIGNAL("clicked()"), self.onKeyOperationClicked)
self.connect(self.gui.key_minus, SIGNAL("clicked()"), self.onKeyOperationClicked)
self.connect(self.gui.key_multi, SIGNAL("clicked()"), self.onKeyOperationClicked)
@@ -70,7 +68,8 @@
self.connect(self.gui.key_equal, SIGNAL("clicked()"), self.onKeyEqualClicked)
self.connect(self.gui.key_percent, SIGNAL("clicked()"), self.onKeyPercentClicked)
- ## Definimos las conexiones de los botones de operaciones de la memoria
+
+ #Definimos las conexiones de los botones de operaciones de la memoria
self.connect(self.gui.key_clearMemory, SIGNAL("clicked()"), self.onKeyOperationMemoryClicked)
self.connect(self.gui.key_readMemory, SIGNAL("clicked()"), self.onKeyOperationMemoryClicked)
self.connect(self.gui.key_setToMemory, SIGNAL("clicked()"), self.onKeyOperationMemoryClicked)
@@ -82,6 +81,7 @@
def onKeyClearClicked(self):
self.gui.calcDisplay.setText("0")
+
@QtCore.pyqtSignature("")
def onKeyClearAllClicked(self):
self.onKeyClearClicked()
@@ -89,12 +89,14 @@
self.lastNum = 0
self.operationType = "="
+
@QtCore.pyqtSignature("")
def onKeyCommaClicked(self):
if (not self.gui.calcDisplay.text().contains(".")):
calc_text = self.gui.calcDisplay.text() + "."
self.gui.calcDisplay.setText(calc_text)
+
@QtCore.pyqtSignature("")
def onKeyBackspaceClicked(self):
calc_text = self.gui.calcDisplay.text()
@@ -105,6 +107,7 @@
calc_text = "0"
self.gui.calcDisplay.setText(calc_text)
+
@QtCore.pyqtSignature("")
def onKeyPlusMinusClicked(self):
calc_text = self.gui.calcDisplay.text()
@@ -114,7 +117,7 @@
calc_text.push_front("-")
self.gui.calcDisplay.setText(calc_text)
-
+
## Definimos las funciones de los botónes numericos al presionarlos
@QtCore.pyqtSignature("")
def onDigitClicked(self):
@@ -128,41 +131,44 @@
else:
calc_text = self.gui.calcDisplay.text() + self.sender().text()
self.gui.calcDisplay.setText(calc_text)
-
+
## Definimos las funciones de los botónes de operaciones al presionarlos
def onKeyOperationClicked(self):
- self.lastNum = self.gui.calcDisplay.text().toFloat()
+ self.lastNum = self.gui.calcDisplay.text().toDouble()
self.waitingForOperant = True
self.operationType = self.sender().text()
+
def onKeyEqualClicked(self):
self.waitingForOperant = True
#Debido a que el resultado de la función toFloat es una tupla, se tiene que poner el [0].
if (self.operationType == "+"):
- calc_text = self.lastNum[0] + self.gui.calcDisplay.text().toFloat()[0]
+ calc_text = self.lastNum[0] + self.gui.calcDisplay.text().toDouble()[0]
elif(self.operationType == '-'):
- calc_text = self.lastNum[0] - self.gui.calcDisplay.text().toFloat()[0]
+ calc_text = self.lastNum[0] - self.gui.calcDisplay.text().toDouble()[0]
elif(self.operationType == 'x'):
- calc_text = self.lastNum[0] * self.gui.calcDisplay.text().toFloat()[0]
+ calc_text = self.lastNum[0] * self.gui.calcDisplay.text().toDouble()[0]
#Se valida la división por cero
elif(self.gui.calcDisplay.text().toFloat()[0] != 0):
- calc_text = self.lastNum[0] / self.gui.calcDisplay.text().toFloat()[0]
+ calc_text = self.lastNum[0] / self.gui.calcDisplay.text().toDouble()[0]
else:
return
- self.gui.calcDisplay.setText(str(calc_text))
+ self.gui.calcDisplay.setText(QtCore.QString.number(calc_text))
+
def onKeyPercentClicked(self):
self.waitingForOperant = True
if(self.operationType == "x"):
- calc_text = self.lastNum[0] * self.gui.calcDisplay.text().toFloat()[0] / 100
+ calc_text = self.lastNum[0] * self.gui.calcDisplay.text().toDouble()[0] / 100
else:
- calc_text = self.lastNum[0] * self.gui.calcDisplay.text().toFloat()[0] / 100
+ calc_text = self.lastNum[0] * self.gui.calcDisplay.text().toDouble()[0] / 100
+
+ self.gui.calcDisplay.setText(QtCore.QString.number(calc_text))
- self.gui.calcDisplay.setText(str(calc_text))
def onKeyOperationMemoryClicked(self):
operation = self.sender().text()
@@ -170,11 +176,12 @@
if(operation == "MC"):
self.memory =0
elif(operation == "MR"):
- self.gui.calcDisplay.setText(str(self.memory))
+ self.gui.calcDisplay.setText(QtCore.QString.number(self.memory))
self.waitingForOperant = True
elif(operation == "MS"):
- self.memory = self.gui.calcDisplay.text().toFloat()[0]
+ self.memory = self.gui.calcDisplay.text().toDouble()[0]
self.waitingForOperant = True
elif(operation == "M+"):
- self.memory = self.memory + self.gui.calcDisplay.text().toFloat()[0]
- self.waitingForOperant = True
\ No hay ningún carácter de nueva lÃnea al final del fichero
+ self.memory = self.memory + self.gui.calcDisplay.text().toDouble()[0]
+ self.waitingForOperant = True
+
\ No hay ningún carácter de nueva lÃnea al final del fichero