Last active
August 29, 2015 14:22
-
-
Save Cheaterman/908e3a750338dc51fb6e to your computer and use it in GitHub Desktop.
Kivylator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.pyc | |
.*.sw[a-z] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is the Kivylator bliblibli ^__^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:import Clock kivy.clock.Clock | |
#:import NumPad numpad.NumPad | |
BoxLayout: | |
orientation: 'vertical' | |
Label: | |
id: ti | |
color: (1, 1, 1, 1) | |
background_color: (0, 0, 0, 1) | |
font_size: '35dp' | |
size_hint_x: .975 | |
size_hint_y: None | |
height: self.font_size * 4 | |
text_size: self.size | |
halign: 'right' | |
valign: 'middle' | |
canvas.before: | |
Color: | |
rgba: self.color | |
Rectangle: | |
size: (self.font_size / 50., self.font_size * 1.5) if(app.blink) else (0, 0) | |
pos: (self.right + 2, self.center_y - self.font_size * .75) | |
BoxLayout: | |
size_hint_y: .1 | |
Button: | |
disabled: True | |
size_hint_x: .70 | |
Button: | |
clear_clock: None | |
text: 'DELETE' | |
size_hint_x: .30 | |
background_normal: self.background_disabled_normal | |
on_press: | |
self.clear_clock = Clock.schedule_once(app.clear, .5) | |
on_release: | |
Clock.unschedule(self.clear_clock) | |
ti.text = ti.text[:-1] | |
NumPad: | |
text_input: ti | |
size_hint_y: 1 | |
cols: 4 | |
rows: 4 | |
layout: | |
( \ | |
'7', '8', '9', '/', \ | |
'4', '5', '6', 'x', \ | |
'1', '2', '3', '-', \ | |
'.', '0', '=', '+' \ | |
) | |
colors: | |
( \ | |
1, 1, 1, 0, \ | |
1, 1, 1, 0, \ | |
1, 1, 1, 0, \ | |
1, 1, 0, 0 \ | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.clock import Clock | |
from kivy.properties import BooleanProperty | |
from kivy.config import Config | |
Config.set('graphics', 'width', 400) | |
Config.set('graphics', 'height', 800) | |
class Kivylator(App): | |
blink = BooleanProperty(False) | |
def on_start(self, *args): | |
Clock.schedule_interval(self.update_blink, .5) | |
def update_blink(self, dt): | |
self.blink = not self.blink | |
def clear(self, *args): | |
self.root.ids.ti.text = '' | |
Kivylator().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.properties import ObjectProperty, ListProperty | |
from kivy.uix.button import Button | |
from kivy.uix.gridlayout import GridLayout | |
class NumPad(GridLayout): | |
text_input = ObjectProperty(None) | |
layout = ListProperty(None) | |
colors = ListProperty(None) | |
def on_layout(self, instance, value): | |
if(isinstance(value, list)): | |
self.clear_widgets() | |
for button in value: | |
self.add_widget(Button( | |
text=button, | |
font_size='50dp', | |
on_release=self.on_keypress, | |
)) | |
def on_colors(self, instance, value): | |
if(isinstance(value, list)): | |
i = len(value) | |
for color in value: | |
i -= 1 | |
if(not color): | |
child = self.children[i] | |
child.background_normal = child.background_disabled_normal | |
def on_keypress(self, instance): | |
if(self.text_input): | |
ti = self.text_input | |
button = instance.text | |
if(button != '='): | |
ti.text += button | |
else: | |
operation = ti.text.replace('x', '*') | |
try: | |
ti.text = str(eval(operation)) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment