Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. import sublime, sublime_plugin
  2. import threading
  3. import time
  4. import winsound
  5. import csv
  6. from datetime import datetime
  7.  
  8. i=0
  9. pomodoro_value=0
  10.  
  11. def show_notification():
  12. global pomodoro_value
  13. winsound.PlaySound('C:/Users/kiril/AppData/Roaming/Sublime Text 3/Packages/MyPlugin/Sound_11330.wav', winsound.SND_FILENAME)
  14. sublime.message_dialog("Eat pomodoro and press [Ctrl+Alt+t]")
  15. pomodoro_value+=1
  16. sublime.status_message("Ok, let's move on, press [Ctrl+Alt+t]")
  17.  
  18. def save_pomodoro():
  19. global pomodoro_value
  20. with open('C:/Users/kiril/AppData/Roaming/Sublime Text 3/Packages/MyPlugin/pom.csv', 'a', newline="") as csvfile:
  21. writer=csv.writer(csvfile)
  22. date=datetime.strftime(datetime.now(), "%Y.%m.%d %H:%M:%S")
  23. writer.writerow([date, pomodoro_value])
  24. pomodoro_value=0
  25.  
  26. def write_time():
  27. sublime.status_message(time_manage(i))
  28.  
  29. def time_manage(time_number):
  30. time_str=' time: '+str(int(time_number/60))+'min '+str(time_number%60)+'s'
  31. return time_str
  32.  
  33. class timer(threading.Thread):
  34. def __init__(self, num, interval):
  35. threading.Thread.__init__(self)
  36. self.thread_num = num
  37. self.interval = interval
  38. self.thread_stop = False
  39. def run(self):
  40. global i
  41. while not self.thread_stop:
  42. sublime.set_timeout(write_time, 1)
  43. i+=1
  44. if i % 30 == 0:
  45. show_notification()
  46. self.pause()
  47. time.sleep(self.interval)
  48. def pause(self):
  49. self.thread_stop = True
  50.  
  51. def zeroing(self):
  52. global i
  53. i=0
  54. save_pomodoro()
  55.  
  56. def showStatus(self):
  57. global i
  58. sublime.status_message(time_manage(i))
  59.  
  60.  
  61.  
  62. thread1 = timer(1, 1)
  63.  
  64.  
  65.  
  66.  
  67.  
  68. class gtimerCommand(sublime_plugin.TextCommand):
  69. def run(self, edit):
  70. global thread1
  71. thread=timer(1,1)
  72. if not thread1.isAlive():
  73. thread.start()
  74. thread1=thread
  75.  
  76.  
  77. class gtimerpauseCommand(sublime_plugin.TextCommand):
  78. def run(self, edit):
  79. global thread1
  80. thread1.pause()
  81.  
  82. class gtimerzeroCommand(sublime_plugin.TextCommand):
  83. def run(self, edit):
  84. global thread1
  85. thread1.zeroing()
  86.  
  87. class gtimerstatusCommand(sublime_plugin.TextCommand):
  88. def run(self, edit):
  89. global thread1
  90. thread1.showStatus()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement