Last active
October 6, 2016 19:49
-
-
Save ilovetogetspamed/71f060a34753130d4efc5b73493dedd0 to your computer and use it in GitHub Desktop.
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.config import Config | |
Config.set('kivy', 'log_level', 'debug') | |
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.factory import Factory | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.logger import Logger | |
from kivy.clock import Clock | |
kv = """ | |
#:import h2c kivy.parser.parse_color | |
<Test>: | |
id: 'color_change_screen' | |
BoxLayout: | |
orientation: 'vertical' | |
padding: 10 | |
Label: | |
text: 'Paint Colors to Change' | |
color: h2c('#3498DB') | |
font_size: 36 | |
markup: True | |
BoxLayout: | |
Label: | |
id: lbl_time_allowed_per_color | |
text: 'Time allowed per color: [color=#E67E22]10[/color] Minutes' | |
font_size: 32 | |
markup: True | |
BoxLayout: | |
Label: | |
text: 'Colors to change:' | |
font_size: 32 | |
size_hint_x: .5 | |
Slider: | |
id: sld_colors_to_change | |
left: 0 | |
size_hint_x: .25 | |
min: 1 | |
max: 15 | |
value: 1 | |
step: 1 | |
Label: | |
text: str(root.ids['sld_colors_to_change'].value) | |
color: h2c('#E67E22') | |
font_size: 32 | |
markup: True | |
size_hint_x: .25 | |
# value: str(int(root.ids['sld_colors_to_change'].value) if root.ids['sld_colors_to_change'].value else '0') | |
BoxLayout: | |
Label: | |
text: 'Time allowed:' | |
font_size: 32 | |
Label: | |
id: lbl_time_allowed | |
text: '10' | |
color: h2c('#E67E22') | |
font_size: 32 | |
# font_name: 'LCDMono' | |
markup: True | |
# value: '{0:02d}:{1:02d}:00'.format(*divmod( int(root.ids['sld_colors_to_change'].value) * root.ids['time_allowed_per_color'], 60 ) ) # this works | |
BoxLayout: | |
Label: | |
text: 'Elapsed:' | |
font_size: 32 | |
Label: | |
id: lbl_elapsed_time | |
color: h2c('#E67E22') | |
text: '00:00:00' | |
font_size: 36 | |
# font_name: 'LCDMono' | |
markup: True | |
BoxLayout: | |
spacing: 10 | |
Button: | |
id: btn_start | |
text: 'Start' | |
font_size:36 | |
background_normal: '' | |
background_color: h2c('#2ECC71') | |
padding: [250, 50] | |
on_release: root.btn_start_timer() | |
Button: | |
id: btn_stop | |
text: 'Cancel' | |
font_size: 36 | |
background_normal: '' | |
background_color: h2c('#C0392B') | |
padding: [250, 50] | |
on_release: root.btn_stop_cancel_timer() | |
""" | |
Builder.load_string(kv) | |
class Test(BoxLayout): | |
# timer variables | |
sw_started = False | |
sw_seconds = 0 | |
# time_allowed_per_color = NumericProperty() | |
# sld_colors_to_change = NumericProperty() | |
def __init__(self, *args, **kwargs): | |
super(Test, self).__init__(*args, **kwargs) | |
self.callback() | |
def callback(self): | |
pass | |
def btn_start_timer(self): | |
if not self.sw_started: | |
Logger.info('ThreadChangeScreen: Starting the Thread Change timer') | |
# start the timer | |
self.sw_started = True | |
self.sw_seconds = 0 | |
Clock.schedule_interval(self.ticktock, 0) # update the clock every clock cycle | |
# post data. Here we send the # of colors in elapsed_time. | |
# self.app.do_post(event_type=15, reason_code=str(self.ids['sld_colors_to_change'].value)) | |
# update the Start button | |
self.ids.btn_stop.text = 'Stop' | |
self.ids.btn_start.disabled = True | |
def btn_stop_cancel_timer(self): | |
if self.sw_started: | |
Logger.info('ThreadChangeScreen: Stopping the Color Change timer') | |
# turn off the timer | |
Clock.unschedule(self.ticktock) | |
self.sw_started = False | |
self.ids.btn_start.disabled = False | |
# post data. Here we send the elapsed time for the change. | |
# self.app.do_post(event_type=16, elapsed_time=int(self.sw_seconds)) | |
# reset the stop button and timer | |
self.ids.lbl_elapsed_time.text = '00:00:00' | |
self.parent.current = 'operator_panel_screen' | |
else: | |
# Return to Operator Panel Screen without doing anything | |
Logger.info('ThreadChangeScreen: Operator canceled the Color Change operation') | |
self.parent.current = 'operator_panel_screen' | |
def ticktock(self, nap): | |
# set the timer value | |
self.sw_seconds += nap | |
# convert the seconds to h, m s for displaying | |
m, s = divmod(self.sw_seconds, 60) | |
h, m = divmod(m, 60) | |
txt = '%d:%02d:%02d[/size].%02d' % (int(h), int(m), int(s), int(s * 100 % 100)) | |
self.ids.lbl_elapsed_time.text = txt | |
# self.ids.lbl_elapsed_time.text = ('%d:%02d:%02d[/size].%02d' % (int(h), int(m), int(s), int(s * 100 % 100))) | |
class TestApp(App): | |
def build(self): | |
return Test() | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment