Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.86 KB | None | 0 0
  1. __version__ = '1.0'
  2. from kivy.app import App
  3. from kivy.uix.widget import Widget
  4. from kivy.core.window import Window
  5. from kivy.clock import Clock
  6. Window.clearcolor = (1, 1, 1, 1)
  7. from kivy.uix.listview import ListItemButton
  8. from kivy.properties import StringProperty, ListProperty, NumericProperty
  9. from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
  10. from kivy.graphics.vertex_instructions import Ellipse
  11. import os
  12. from functools import partial
  13. from kivy.uix.carousel import Carousel
  14. from kivy.uix.image import AsyncImage
  15. # from kivy.config import config
  16. from kivy.core.text import LabelBase
  17. import pyobjus.debug
  18. from pyobjus.pyobjus import autoclass
  19. import random
  20. LabelBase.register(name="Varela",
  21. fn_regular="data/varela-round-v6-latin-regular.ttf",
  22. fn_bold="data/varela-round-v6-latin-regular.ttf",
  23. fn_italic="data/varela-round-v6-latin-regular.ttf",
  24. fn_bolditalic="data/varela-round-v6-latin-regular.ttf")
  25. KIVY_DEFAULT_FONT = 'Varela'
  26. DEFAULT_FONT = KIVY_DEFAULT_FONT
  27. TEXT_SIZE = 36
  28. TROLL_SIZE = 50
  29. COUNT_BY = .055
  30.  
  31.  
  32. secCounter = 0
  33. secCounterTtl = 0
  34. repCounter = 0
  35. repCounterRd = 0
  36. rdCounter = 1
  37. repDummy = 0
  38. frcCounter = 0
  39. frcCounterRd = 0
  40. rdGoal = False
  41. countRound = False
  42. trollEnergy = 100
  43.  
  44. trollDiff = 1
  45.  
  46. class Workouts(Screen):
  47. pass
  48.  
  49. class TrollLevel(Screen):
  50. def set_troll_diff(self, *args):
  51. global trollDiff
  52. if self.ids.diff_slider.value == 0:
  53. trollDiff = .1
  54. else:
  55. trollDiff = self.ids.diff_slider.value / 5
  56. self.manager.current = 'troll'
  57.  
  58.  
  59. class Troll(Screen):
  60. def start_clock(self, widget):
  61. global secCounter
  62. secCounter+=.01
  63. ls = [i for i in range(0,7)]
  64. for i in ls:
  65. i2 = 5 - i
  66. Clock.schedule_once(partial(self.change_start_text, i2), i)
  67.  
  68. def count_round(self, widget):
  69. global countRound
  70. countRound=True
  71.  
  72.  
  73. def change_start_text(self,index, *args):
  74. self.ids.start_button.text = str(int(index)) + '...'
  75. if index < 1:
  76. self.ids.start_button.text = 'GO!!!'
  77. if index < 0:
  78. self.ids.start_button.pos_hint = {'center_x': 100, 'center_y': 100}
  79. self.ids.start_button.text = 'START'
  80. self.ids.troll_img.pos_hint = {'center_x': .5, 'center_y': .5}
  81. Clock.schedule_interval(self.ticks.update_clock, .05)
  82.  
  83. def troll_hurt(self, *args):
  84. self.ids.troll_img.source = 'data/troll.png'
  85.  
  86. def troll_dead(self, *args):
  87. self.ids.troll_img.source = 'data/troll.png'
  88. self.ids.troll_img.height = 40
  89.  
  90. def stop_clock(self):
  91. global secStart, secCounter, repCounter, repDummy, frcCounter
  92. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter
  93. self.disp_sec = secCounter = 0
  94. self.disp_rep = repCounter = 0
  95. self.disp_rep_rd = repCounterRd = 0
  96. self.disp_frc = frcCounter = 0
  97. self.disp_frc_rd = frcCounterRd = 0
  98. self.disp_troll_energy = trollEnergy = 100
  99. self.disp_sec_ttl = str(0)
  100. secCounterTtl = 0
  101.  
  102. rdCounter = 0
  103. self.ids.disp_rds.text = str(rdCounter)
  104. self.e2_end = 180
  105. self.e1_end = 0
  106. self.ids.troll_img.height = 40
  107. Clock.unschedule(self.ticks.update_clock)
  108. self.ids.start_button.pos_hint = {'center_x': .5, 'center_y': .5}
  109. self.ids.eaten_txt.pos_hint = {'center_x': 100, 'center_y': 100}
  110. self.manager.current = 'workouts'
  111.  
  112. class TicksTroll(Widget):
  113. def __init__(self, **kwargs):
  114. super(TicksTroll, self).__init__(**kwargs)
  115. self.bind(pos=self.update_clock)
  116. self.bind(size=self.update_clock)
  117.  
  118. def update_clock(self, *args):
  119. def reset_color(*args):
  120. self.parent.flash_color = '#F7F7F7'
  121. global secStart, secCounter, repCounter, repDummy, frcCounter, countRound
  122. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter, rdGoal
  123. global trollDiff, trollEnergy
  124. self.canvas.clear()
  125. self.parent.disp_sec = round(secCounter,1)
  126. if secCounterTtl > 60:
  127. mins = int(secCounterTtl / 60)
  128. secs = secCounterTtl % 60
  129. secs = str(round(secs,1))
  130. if len(secs)< 4:
  131. secs = '0'+secs
  132. self.parent.disp_sec_ttl = str(mins) + ':' + secs
  133. else:
  134. self.parent.disp_sec_ttl = str(round(secCounterTtl,1))
  135. if secCounter>0:
  136. with self.canvas:
  137. secCounter+=COUNT_BY
  138. secCounterTtl+=COUNT_BY
  139. repDummy+=COUNT_BY
  140. ran = random.random()
  141. if ran < .1:
  142. trollDiff
  143. self.parent.ids.troll_img.height = self.parent.ids.troll_img.height+(10*trollDiff)
  144. if repDummy > 3:
  145. repCounter+=1
  146. repCounterRd+=1
  147. frcCounter+=22
  148. frcCounterRd+=22
  149. trollEnergy-=22
  150. self.parent.flash_color = '#98DCB6'
  151. Clock.schedule_once(reset_color, .25)
  152. self.parent.disp_rep = repCounter
  153. self.parent.disp_rep_rd = repCounterRd
  154. self.parent.disp_frc = frcCounter
  155. self.parent.disp_frc_rd = frcCounterRd
  156. self.parent.disp_troll_energy = trollEnergy
  157. repDummy=0
  158. self.parent.ids.troll_img.height = self.parent.ids.troll_img.height-20
  159. self.parent.ids.troll_img.source = 'data/troll_hurt.png'
  160. Clock.schedule_interval(self.parent.troll_hurt, .5)
  161. degrees = (secCounter / 60) * 360
  162. if trollEnergy < 0:
  163.  
  164.  
  165. rdCounter+=1
  166. self.parent.disp_troll_energy = trollEnergy = 100
  167. self.parent.ids.disp_rds.text = str(rdCounter)
  168. self.parent.e1_end = 0
  169. self.parent.e2_end = 180
  170. # secCounter=0.00001
  171. repCounterRd=0
  172. # self.parent.e2_start = 0
  173. # self.parent.e2_end = 0
  174. # countRound=False
  175. self.parent.disp_rep = repCounter
  176. self.parent.disp_rep_rd = repCounterRd
  177. # self.parent.disp_frc = frcCounter
  178. # self.parent.disp_frc_rd = frcCounterRd
  179. self.parent.ids.troll_img.source = 'data/troll_dead.png'
  180. Clock.schedule_once(self.parent.troll_dead, .25)
  181.  
  182. if self.parent.ids.troll_img.height > 250:
  183. self.parent.ids.troll_img.pos_hint = {'center_x': 100, 'center_y': 100}
  184. self.parent.ids.eaten_txt.pos_hint = {'center_x': .5, 'center_y': .5}
  185. self.disp_sec = secCounter = 0
  186. self.disp_rep = repCounter = 0
  187. self.disp_rep_rd = repCounterRd = 0
  188. self.disp_frc = frcCounter = 0
  189. self.disp_frc_rd = frcCounterRd = 0
  190. rdCounter = 0
  191. self.parent.ids.disp_rds.text = str(rdCounter)
  192. Clock.unschedule(self.update_clock)
  193. else:
  194. self.parent.e1_end = degrees
  195.  
  196. class Free(Screen):
  197. def start_clock(self, widget):
  198. global secCounter
  199. secCounter+=.01
  200. ls = [i for i in range(0,7)]
  201. for i in ls:
  202. print('i:',i)
  203. i2 = 5 - i
  204. print('i2:',i2)
  205. Clock.schedule_once(partial(self.change_start_text, i2), i)
  206.  
  207. def count_round(self, widget):
  208. global countRound
  209. countRound=True
  210.  
  211.  
  212. def change_start_text(self,index, *args):
  213. print('index:', index)
  214. self.ids.start_button.text = str(int(index)) + '...'
  215. if index < 1:
  216. self.ids.start_button.text = 'GO!!!'
  217. if index < 0:
  218. self.ids.start_button.pos_hint = {'center_x': 100, 'center_y': 100}
  219. Clock.schedule_interval(self.ticks.update_clock, .05)
  220. self.ids.start_button.text = 'START'
  221. self.ids.count_rd_button.pos_hint = {'center_x': .5, 'center_y': .7}
  222. self.ids.done_button.pos_hint = {'center_x': .5, 'center_y': .3}
  223.  
  224.  
  225. def stop_clock(self):
  226. global secStart, secCounter, repCounter, repDummy, frcCounter
  227. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter
  228. print(self.ids.keys())
  229. self.disp_sec = secCounter = 0
  230. self.disp_rep = repCounter = 0
  231. self.disp_rep_rd = repCounterRd = 0
  232. self.disp_frc = frcCounter = 0
  233. self.disp_frc_rd = frcCounterRd = 0
  234. rdCounter = 0
  235. self.ids.disp_rds.text = str(rdCounter)
  236. self.e2_end = 180
  237. self.e1_end = 0
  238. Clock.unschedule(self.ticks.update_clock)
  239. self.ids.start_button.pos_hint = {'center_x': .5, 'center_y': .5}
  240. self.manager.current = 'workouts'
  241.  
  242. class TicksFree(Widget):
  243. def __init__(self, **kwargs):
  244. super(TicksFree, self).__init__(**kwargs)
  245. self.bind(pos=self.update_clock)
  246. self.bind(size=self.update_clock)
  247.  
  248. def update_clock(self, *args):
  249. def reset_color(*args):
  250. self.parent.flash_color = '#F7F7F7'
  251. global secStart, secCounter, repCounter, repDummy, frcCounter, countRound
  252. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter, rdGoal
  253. self.canvas.clear()
  254. self.parent.disp_sec = round(secCounter,1)
  255. if secCounterTtl > 60:
  256. mins = int(secCounterTtl / 60)
  257. secs = secCounterTtl % 60
  258. secs = str(round(secs,1))
  259. if len(secs)< 4:
  260. secs = '0'+secs
  261. self.parent.disp_sec_ttl = str(mins) + ':' + secs
  262. else:
  263. self.parent.disp_sec_ttl = str(round(secCounterTtl,1))
  264. if secCounter>0:
  265. with self.canvas:
  266. secCounter+=COUNT_BY
  267. secCounterTtl+=COUNT_BY
  268. repDummy+=COUNT_BY
  269. if repDummy > 3:
  270. repCounter+=1
  271. repCounterRd+=1
  272. frcCounter+=53
  273. frcCounterRd+=53
  274. self.parent.flash_color = '#98DCB6'
  275. Clock.schedule_once(reset_color, .25)
  276. self.parent.disp_rep = repCounter
  277. self.parent.disp_rep_rd = repCounterRd
  278. self.parent.disp_frc = frcCounter
  279. self.parent.disp_frc_rd = frcCounterRd
  280. repDummy=0
  281. degrees = (secCounter / 60) * 360
  282. if countRound:
  283. rdCounter+=1
  284. self.parent.ids.disp_rds.text = str(rdCounter)
  285. self.parent.e1_end = 0
  286. self.parent.e2_end = 180
  287. secCounter=0.00001
  288. frcCounterRd=0
  289. repCounterRd=0
  290. self.parent.e2_start = 0
  291. self.parent.e2_end = 0
  292. countRound=False
  293. self.parent.disp_rep = repCounter
  294. self.parent.disp_rep_rd = repCounterRd
  295. self.parent.disp_frc = frcCounter
  296. self.parent.disp_frc_rd = frcCounterRd
  297. else:
  298. self.parent.e1_end = degrees
  299.  
  300. class EMOM(Screen):
  301. def start_clock(self, widget):
  302. global secCounter
  303. secCounter+=.01
  304. ls = [i for i in range(0,7)]
  305. for i in ls:
  306. print('i:',i)
  307. i2 = 5 - i
  308. print('i2:',i2)
  309. Clock.schedule_once(partial(self.change_start_text, i2), i)
  310.  
  311. def change_start_text(self,index, *args):
  312. print('index:', index)
  313. self.ids.start_button.text = str(int(index)) + '...'
  314. if index < 1:
  315. self.ids.start_button.text = 'GO!!!'
  316. if index < 0:
  317. self.ids.start_button.pos_hint = {'center_x': 100, 'center_y': 100}
  318. self.ids.work_flag.text = 'WORK'
  319. Clock.schedule_interval(self.ticks.update_clock, .05)
  320. self.ids.start_button.text = 'START'
  321.  
  322.  
  323. def stop_clock(self):
  324. global secStart, secCounter, repCounter, repDummy, frcCounter
  325. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter
  326. print(self.ids.keys())
  327. self.ids.work_flag.text = ''
  328. self.disp_sec = secCounter = 0
  329. self.disp_rep = repCounter = 0
  330. self.disp_rep_rd = repCounterRd = 0
  331. self.disp_frc = frcCounter = 0
  332. self.disp_frc_rd = frcCounterRd = 0
  333. rdCounter = 0
  334. self.ids.disp_rds.text = str(rdCounter)
  335. self.e2_end = 180
  336. self.e1_end = 0
  337. Clock.unschedule(self.ticks.update_clock)
  338. self.ids.start_button.pos_hint = {'center_x': .5, 'center_y': .5}
  339. self.manager.current = 'workouts'
  340.  
  341.  
  342. class TicksEMOM(Widget):
  343. def __init__(self, **kwargs):
  344. super(TicksEMOM, self).__init__(**kwargs)
  345. self.bind(pos=self.update_clock)
  346. self.bind(size=self.update_clock)
  347.  
  348. def update_clock(self, *args):
  349. def reset_color(*args):
  350. self.parent.flash_color = '#F7F7F7'
  351. global secStart, secCounter, repCounter, repDummy, frcCounter
  352. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter, rdGoal
  353. self.canvas.clear()
  354. self.parent.disp_sec = round(secCounter,1)
  355. self.parent.disp_sec_ttl = round(secCounterTtl,1)
  356. if secCounter>0:
  357. with self.canvas:
  358. secCounter+=COUNT_BY
  359. secCounterTtl+=COUNT_BY
  360. repDummy+=COUNT_BY
  361. if repDummy > 3:
  362. repCounter+=1
  363. repCounterRd+=1
  364. frcCounter+=53
  365. frcCounterRd+=53
  366. self.parent.flash_color = '#98DCB6'
  367. Clock.schedule_once(reset_color, .25)
  368. self.parent.disp_rep = repCounter
  369. self.parent.disp_rep_rd = repCounterRd
  370. self.parent.disp_frc = frcCounter
  371. self.parent.disp_frc_rd = frcCounterRd
  372. repDummy=0
  373. degrees = (secCounter / 60) * 360
  374. if repCounterRd == 8 and not rdGoal:
  375. rdGoal=True
  376. self.parent.e2_start = degrees
  377. self.parent.e2_end = degrees
  378. self.parent.ids.work_flag.text = 'REST'
  379.  
  380. elif degrees >= (360-.05):
  381. rdCounter+=1
  382. self.parent.ids.disp_rds.text = str(rdCounter)
  383. self.parent.e1_end = 0
  384. self.parent.e2_end = 180
  385. secCounter=0.00001
  386. frcCounterRd=0
  387. repCounterRd=0
  388. self.parent.ids.work_flag.text = 'WORK'
  389. self.parent.e2_start = 0
  390. self.parent.e2_end = 0
  391. rdGoal=False
  392. elif repCounterRd >= 8:
  393. self.parent.e2_end = degrees
  394. else:
  395. self.parent.e1_end = degrees
  396.  
  397. class OnOff(Screen):
  398. def start_clock(self, widget):
  399. global secCounter
  400. secCounter+=.01
  401. ls = [i for i in range(0,7)]
  402. for i in ls:
  403. print('i:',i)
  404. i2 = 5 - i
  405. print('i2:',i2)
  406. Clock.schedule_once(partial(self.change_start_text, i2), i)
  407.  
  408. def change_start_text(self,index, *args):
  409. print('index:', index)
  410. self.ids.start_button.text = str(int(index)) + '...'
  411. if index < 1:
  412. self.ids.start_button.text = 'GO!!!'
  413. if index < 0:
  414. self.ids.start_button.pos_hint = {'center_x': 100, 'center_y': 100}
  415. self.ids.work_flag.text = 'WORK'
  416. Clock.schedule_interval(self.ticks.update_clock, .05)
  417. self.ids.start_button.text = 'START'
  418.  
  419.  
  420. def stop_clock(self):
  421. global secStart, secCounter, repCounter, repDummy, frcCounter
  422. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter
  423. print(self.ids.keys())
  424. self.ids.work_flag.text = ''
  425. self.disp_sec = secCounter = 0
  426. self.disp_rep = repCounter = 0
  427. self.disp_rep_rd = repCounterRd = 0
  428. self.disp_frc = frcCounter = 0
  429. self.disp_frc_rd = frcCounterRd = 0
  430. rdCounter = 0
  431. self.ids.disp_rds.text = str(rdCounter)
  432. self.e2_end = 180
  433. self.e1_end = 0
  434. Clock.unschedule(self.ticks.update_clock)
  435. self.ids.start_button.pos_hint = {'center_x': .5, 'center_y': .5}
  436. self.manager.current = 'workouts'
  437.  
  438.  
  439. class Ticks(Widget):
  440. def __init__(self, **kwargs):
  441. super(Ticks, self).__init__(**kwargs)
  442. self.bind(pos=self.update_clock)
  443. self.bind(size=self.update_clock)
  444.  
  445. def update_clock(self, *args):
  446. def reset_color(*args):
  447. self.parent.flash_color = '#F7F7F7'
  448. global secStart, secCounter, repCounter, repDummy, frcCounter
  449. global secCounterTtl, repCounterRd, frcCounterRd, rdCounter
  450. self.canvas.clear()
  451. self.parent.disp_sec = round(secCounter,1)
  452. self.parent.disp_sec_ttl = round(secCounterTtl,1)
  453. if secCounter>0:
  454. with self.canvas:
  455. secCounter+=COUNT_BY
  456. secCounterTtl+=COUNT_BY
  457. repDummy+=COUNT_BY
  458. if repDummy > 3:
  459. repCounter+=1
  460. repCounterRd+=1
  461. frcCounter+=53
  462. frcCounterRd+=53
  463. self.parent.flash_color = '#98DCB6'
  464. Clock.schedule_once(reset_color, .25)
  465. self.parent.disp_rep = repCounter
  466. self.parent.disp_rep_rd = repCounterRd
  467. self.parent.disp_frc = frcCounter
  468. self.parent.disp_frc_rd = frcCounterRd
  469. repDummy=0
  470. degrees = (secCounter / 60) * 360
  471. if degrees >= (360-.05):
  472. rdCounter+=1
  473. self.parent.ids.disp_rds.text = str(rdCounter)
  474. self.parent.e1_end = 0
  475. self.parent.e2_end = 180
  476. secCounter=0.00001
  477. frcCounterRd=0
  478. repCounterRd=0
  479. self.parent.ids.work_flag.text = 'WORK'
  480. elif degrees >= 180.5:
  481. self.parent.e2_end = degrees
  482. self.parent.ids.work_flag.text = 'REST'
  483. else:
  484. self.parent.e1_end = degrees
  485.  
  486. class Login(Screen):
  487. def do_login(self, loginText, passwordText):
  488. app = App.get_running_app()
  489.  
  490. app.username = loginText
  491. app.password = passwordText
  492.  
  493. self.manager.transition = SlideTransition(direction="left")
  494. self.manager.current = 'workouts'
  495.  
  496. app.config.read(app.get_application_config())
  497. app.config.write()
  498.  
  499. def resetForm(self):
  500. self.ids['login'].text = ""
  501. self.ids['password'].text = ""
  502.  
  503. class ForceApp(App):
  504. username = StringProperty(None)
  505. password = StringProperty(None)
  506. data = ListProperty(["Item #{0}".format(i) for i in range(50)])
  507.  
  508. def build(self):
  509. manager = ScreenManager()
  510.  
  511. manager.add_widget(Login(name='login'))
  512. manager.add_widget(Workouts(name='workouts'))
  513. manager.add_widget(OnOff(name='onoff'))
  514. manager.add_widget(EMOM(name='emom'))
  515. manager.add_widget(Free(name='free'))
  516. manager.add_widget(TrollLevel(name='troll_level'))
  517. manager.add_widget(Troll(name='troll'))
  518.  
  519. return manager
  520.  
  521. def get_application_config(self):
  522. if(not self.username):
  523. return super(ForceApp, self).get_application_config()
  524.  
  525. conf_directory = self.user_data_dir + '/' + self.username
  526.  
  527. if(not os.path.exists(conf_directory)):
  528. os.makedirs(conf_directory)
  529.  
  530. return super(ForceApp, self).get_application_config(
  531. '%s/config.cfg' % (conf_directory)
  532. )
  533.  
  534.  
  535.  
  536. if __name__ == '__main__':
  537. ForceApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement