Skip to content

Commit

Permalink
Remove buttons, add backspace button, delete sign button, set font si…
Browse files Browse the repository at this point in the history
…ze for operation text button
  • Loading branch information
sswm1975 committed May 18, 2021
1 parent cbf6f3e commit e2831d7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ install:
- export PATH=$PATH:~/.local/bin/
- yes | buildozer android debug
- gem install dpl --pre
- dpl releases --token $GITHUB_TOKEN --file "bin/calculator-0.3-armeabi-v7a-debug.apk" --tag_name "v.0.3"
- dpl releases --token $GITHUB_TOKEN --file "bin/calculator-0.4-armeabi-v7a-debug.apk" --tag_name "v.0.4"
- echo "END"
4 changes: 2 additions & 2 deletions buildozer.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[app]

# (str) Title of your application
title = Calculator
title = Калькулятор

# (str) Package name
package.name = calculator
Expand All @@ -28,7 +28,7 @@ source.dir = .
#source.exclude_patterns = license,images/*/*.jpg

# (str) Application versioning (method 1)
version = 0.3
version = 0.4

# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
Expand Down
59 changes: 36 additions & 23 deletions calculator.kv
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@
GridLayout:
cols: 4

Button:
text: "("
background_color: "lightblue"
on_release:
root.add_in_formula(self)
Button:
text: ")"
background_color: "lightblue"
on_release:
root.add_in_formula(self)
Button:
text: "C"
background_color: "red"
on_release:
root.clear_formula(self)
Button:
text: "<-"
font_size: "26sp"
background_color: "pink"
on_release:
root.delete_char(self)

Button:
text: "1"
on_release:
Expand All @@ -41,6 +63,7 @@
root.add_in_formula(self)
Button:
text: "+"
font_size: "26sp"
background_color: "grey"
on_release:
root.add_in_formula(self)
Expand All @@ -59,6 +82,7 @@
root.add_in_formula(self)
Button:
text: "-"
font_size: "26sp"
background_color: "grey"
on_release:
root.add_in_formula(self)
Expand All @@ -77,14 +101,15 @@
root.add_in_formula(self)
Button:
text: "x"
font_size: "26sp"
background_color: "grey"
on_release:
root.add_in_formula(self)

Button:
text: "+/-"
text: ""
on_release:
root.set_sign(self)
root.sqrt(self)
Button:
text: "0"
on_release:
Expand All @@ -94,28 +119,16 @@
on_release:
root.add_in_formula(self)
Button:
text: "/"
text: "÷"
font_size: "26sp"
background_color: "grey"
on_release:
root.add_in_formula(self)

Button:
text: "("
background_color: "lightblue"
on_release:
root.add_in_formula(self)
Button:
text: ")"
background_color: "lightblue"
on_release:
root.add_in_formula(self)
Button:
text: "C"
background_color: "red"
on_release:
root.clear_formula(self)
Button:
text: "="
background_color: "yellow"
on_release:
root.calc_result(self)
Button:
text: "="
font_size: "26sp"
background_color: "green"
size_hint_y: 0.2
on_release:
root.calc_result(self)
20 changes: 13 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ def add_in_formula(self, instance):
self.formula += str(instance.text)
self.label_input.text = self.formula

def set_sign(self, instance):
if self.formula[0] == '-':
self.formula = self.formula[1:]
else:
self.formula = '-' + self.formula
def sqrt(self, instance):
if self.formula == '':
return

self.formula += '^'
self.label_input.text = self.formula

def clear_formula(self, instance):
self.formula = ''
self.label_input.text = ''
self.label_info.text = ''

def delete_char(self, instance):
if self.formula == '':
return

self.formula = self.formula[:-1]
self.label_input.text = self.formula

def calc_result(self, instance):
if self.formula == '':
return

try:
calc = str(eval(self.formula.replace('x', '*')))
calc = str(eval(self.formula.replace('x', '*').replace('^','**')))
except:
self.label_info.color = 'red'
self.label_info.text = 'Error'
Expand All @@ -54,7 +60,7 @@ def calc_result(self, instance):
calc = calc[:-2]

self.label_input.text = calc
self.label_info.text = self.formula + ' ='
self.label_info.text = self.formula + '='
self.formula = calc


Expand Down

0 comments on commit e2831d7

Please sign in to comment.