Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
debottamKundu committed Jan 13, 2021
1 parent 06da8aa commit 5584cb2
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"keys": ["ctrl+alt+p"], "command": "pomodoro_start",
"keys": ["ctrl+alt+r"], "command": "pomodoro_stop"
}
]
6 changes: 6 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"keys": ["ctrl+alt+p"], "command": "pomodoro_start",
"keys": ["ctrl+alt+r"], "command": "pomodoro_stop"
}
]
6 changes: 6 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"keys": ["ctrl+alt+p"], "command": "pomodoro_start",
"keys": ["ctrl+alt+r"], "command": "pomodoro_stop"
}
]
6 changes: 6 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"caption": "Pomodoro",
"command": "pomodoro_start"
}
]
117 changes: 117 additions & 0 deletions pomodoro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from datetime import datetime, timedelta
import sublime
from sublime_plugin import ApplicationCommand, TextCommand
import time

class PomodoroStartCommand(TextCommand):

"""todo: add support for user input if initiated using another shortcut"""
# optionsForInterval = ["15 minutes", "20 minutes", "25 minutes", "30 minutes"]
# optionsForBreak = ["5 minutes", "10 minutes"]
# cycles = 4
# optionsInSeconds = {
# 0: 15,
# 1: 1200,
# 2: 1500,
# 3: 1800,
# }
# breakTime = 15

intervalTimeinSeconds = 0
breakTimeinSeconds = 0
cycles = 4

def run(self, edit):
#for testing purposes
#sublime.pomodoro_clock = False

x = sublime.load_settings("pomodoro.sublime-settings")
intervalTime = x.get("base_time",25)
breakTime = x.get("breakTime",5)

PomodoroStartCommand.cycles = x.get("cycles",4)
PomodoroStartCommand.intervalTimeinSeconds = intervalTime*60
PomodoroStartCommand.breakTimeinSeconds = breakTime*60

if not hasattr(sublime, 'pomodoro_clock'):
sublime.pomodoro_clock = True
elif sublime.pomodoro_clock is True:
sublime.error_message('Pomodoro Clock is already running, wait for the previous to stop first.')
return
else:
sublime.pomodoro_clock = True

if sublime.pomodoro_clock is True:
PomodoroStartCommand.beginCycles(datetime.now(), timedelta(seconds = PomodoroStartCommand.intervalTimeinSeconds),PomodoroStartCommand.cycles)


@staticmethod
def beginCycles(startTime,countDownTime,cycles):
if sublime.pomodoro_clock == True:
PomodoroStartCommand.beginTimer(startTime,countDownTime)
timeElapsed = PomodoroStartCommand.intervalTimeinSeconds*1000 #delay in milliseconds
for c in range(1,cycles):
sublime.set_timeout(lambda: PomodoroStartCommand.beginBreak(datetime.now(),timedelta(seconds=PomodoroStartCommand.breakTimeinSeconds)),timeElapsed)
timeElapsed = timeElapsed + PomodoroStartCommand.breakTimeinSeconds*1000
# print(timeElapsed/60)
sublime.set_timeout(lambda: PomodoroStartCommand.beginTimer(datetime.now(),countDownTime),timeElapsed)
timeElapsed = timeElapsed + PomodoroStartCommand.intervalTimeinSeconds*1000
# print(timeElapsed/60)
sublime.set_timeout(lambda: PomodoroStartCommand.reset(),timeElapsed)


@staticmethod
def reset():
if (sublime.pomodoro_clock == False):
sublime.status_message("Your pomodoro timer has been cancelled")
else:
sublime.pomodoro_clock = False
sublime.status_message("Your pomodoro timer has ended. Please reset using shortcut.")
sublime.message_dialog("Your pomodoro timer has ended.")
return
# print("Everything ends")



@staticmethod
def beginTimer(startTime, countDownTime):
if sublime.pomodoro_clock is True:
timeLeft = (startTime - datetime.now()) + countDownTime
sublime.status_message("time: {0}".format(timeLeft.total_seconds()))
# breakTime = timedelta(seconds=20)
flag = 0
if timeLeft.total_seconds() > 0 and sublime.pomodoro_clock != False:
PomodoroStartCommand.printStats(timeLeft,flag)
sublime.set_timeout(lambda: PomodoroStartCommand.beginTimer(startTime, countDownTime),100)
else:
# print("Timer ends")
return -1

@staticmethod
def beginBreak(startTime,countDownTime):
if sublime.pomodoro_clock is True:
timeLeft = (startTime - datetime.now()) + countDownTime
sublime.status_message("time: {0}".format(timeLeft.total_seconds()))
flag = 1
if timeLeft.total_seconds() > 0 and sublime.pomodoro_clock != False:
PomodoroStartCommand.printStats(timeLeft,flag)
sublime.set_timeout(lambda: PomodoroStartCommand.beginBreak(startTime, countDownTime),100)
else:
# print("Break ends")
return -1

@staticmethod
def printStats(timeElapsed,flag):
seconds = timeElapsed.seconds
minutes, seconds = divmod(seconds, 60)
if flag==0:
sublime.status_message("WORK: You have {0} minutes and {1} seconds before your break".format(minutes, seconds))
else:
sublime.status_message("BREAK : You have {0} minutes and {1} seconds before your start working again".format(minutes, seconds))

class PomodoroStopCommand(TextCommand):
"""docstring for PomodoroStop"""
def run(self, edit):
sublime.pomodoro_clock=False
sublime.status_message("Pomodoro clock has been stopped")
return
8 changes: 8 additions & 0 deletions pomodoro.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
//setup default timings

"base_time":15,
"break_time":5,
"cycles":4

}

0 comments on commit 5584cb2

Please sign in to comment.