switching to new GUI, remove CmdWindow
This commit is contained in:
1 parent
9af4c655b1
commit
5fc2cb8a53
6 files changed
+23
-668
No files matched your search
@@ -3,11 +3,8 @@
|
||||
import os
|
||||
import sys
|
||||
import getopt
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from CmdWindow import CmdWindow
|
||||
from Command import Command
|
||||
from DataStore import DataStore, TaskRef
|
||||
from Window import *
|
||||
|
||||
PROGRAM_NAME = 'dwtt'
|
||||
|
||||
@@ -32,135 +29,8 @@ def main(argv):
|
||||
usage()
|
||||
sys.exit(3)
|
||||
|
||||
timedbfile = os.path.expanduser('~') + os.path.sep + '.dwtt.db'
|
||||
if len(args) >= 1:
|
||||
timedbfile = args[0]
|
||||
|
||||
ds = DataStore(timedbfile)
|
||||
|
||||
def handleActivated(cmdline, cw):
|
||||
if cmdline.strip() == '':
|
||||
return False
|
||||
ct = ds.getCurrentTask()
|
||||
if ct is not None:
|
||||
task = ds.getTaskByID(ct.taskid)
|
||||
status = 'Task: ' + ds.getTaskPath(task)
|
||||
if task.longname != '':
|
||||
status += ' (%s)' % task.longname
|
||||
cw.setStatus(status, ct.time)
|
||||
else:
|
||||
cw.setStatus('', None)
|
||||
cmd = Command(cmdline)
|
||||
res = processCommand(cmd, ds)
|
||||
if not res.keepwindow:
|
||||
return False
|
||||
cw.setError(res.error)
|
||||
cw.setFormatted(res.formatted)
|
||||
return True
|
||||
|
||||
cw = CmdWindow(handleActivated)
|
||||
ct = ds.getCurrentTask()
|
||||
if ct is not None:
|
||||
task = ds.getTaskByID(ct.taskid)
|
||||
status = 'Task: ' + ds.getTaskPath(task)
|
||||
if task.longname != '':
|
||||
status += ' (%s)' % task.longname
|
||||
cw.setStatus(status, ct.time)
|
||||
cw.main()
|
||||
|
||||
class Result:
|
||||
def __init__(self):
|
||||
self.keepwindow = False
|
||||
self.error = ''
|
||||
self.message = ''
|
||||
self.formatted = ''
|
||||
|
||||
def processStart(cmd, store):
|
||||
res = Result()
|
||||
task = store.getTaskByShortName(cmd.argstr)
|
||||
if task is None:
|
||||
parent = store.getParentTaskByShortName(cmd.argstr)
|
||||
if parent is None:
|
||||
res.error = 'Could not find task "%s"' % \
|
||||
(':'.join(cmd.argstr.split(':')[:-1]))
|
||||
res.keepwindow = True
|
||||
return res
|
||||
taskid = store.createTask(cmd.argstr.split(':')[-1], '', parent.taskid)
|
||||
else:
|
||||
taskid = task.taskid
|
||||
processOut(cmd, store)
|
||||
store.updateCurrentTask(TaskRef(taskid, cmd.time))
|
||||
return res
|
||||
|
||||
def processOut(cmd, store):
|
||||
res = Result()
|
||||
ct = store.getCurrentTask()
|
||||
if ct is None:
|
||||
res.error = 'No current task defined'
|
||||
res.keepwindow = True
|
||||
return res
|
||||
seconds = (cmd.time - ct.time).seconds
|
||||
if seconds > 0:
|
||||
store.addTime(cmd.time.strftime('%Y-%m-%d'), ct.taskid, seconds)
|
||||
store.clearCurrentTask()
|
||||
return res
|
||||
|
||||
def processTask(cmd, store):
|
||||
res = Result()
|
||||
res.keepwindow = True
|
||||
parts = cmd.argstr.split(',', 1)
|
||||
fullname = parts[0].strip()
|
||||
longname = '' if len(parts) < 2 else parts[1].strip()
|
||||
nameparts = fullname.split(':')
|
||||
task = store.getTaskByName(fullname)
|
||||
if task is not None:
|
||||
# the task already exists, update it
|
||||
store.updateTask(task.taskid, nameparts[-1], longname)
|
||||
res.message = 'Task "%s" updated' % fullname
|
||||
return res
|
||||
if len(nameparts) > 1:
|
||||
parenttask = store.getParentTaskByShortName(fullname)
|
||||
if parenttask is None:
|
||||
res.error = 'Parent task of "%s" not found' % fullname
|
||||
return res
|
||||
store.createTask(nameparts[-1].strip(), longname, parenttask.taskid)
|
||||
else:
|
||||
store.createTask(nameparts[-1].strip(), longname, None)
|
||||
res.message = 'Task "%s" created' % fullname
|
||||
return res
|
||||
|
||||
def processStatus(cmd, store):
|
||||
res = Result()
|
||||
res.keepwindow = True
|
||||
now = datetime.now()
|
||||
monday = now - timedelta(now.weekday())
|
||||
sunday = monday + timedelta(6)
|
||||
entries = store.getEntriesInDateRange(monday, sunday)
|
||||
prevtask = 0
|
||||
for ent in entries:
|
||||
if ent.taskid != prevtask:
|
||||
prevtask = ent.taskid
|
||||
task = store.getTaskByID(ent.taskid)
|
||||
print store.getTaskPath(task) + ':'
|
||||
hours = round(float(ent.seconds) / (60 * 60), 1)
|
||||
print ' %s: %0.1f' % (ent.date, hours)
|
||||
return res
|
||||
|
||||
COMMAND_HANDLERS = {
|
||||
'start' : processStart,
|
||||
'out' : processOut,
|
||||
'task' : processTask,
|
||||
'status' : processStatus
|
||||
}
|
||||
|
||||
# Returns boolean for whether the command prompt should be displayed again
|
||||
def processCommand(cmd, store):
|
||||
if cmd.command in COMMAND_HANDLERS:
|
||||
return COMMAND_HANDLERS[cmd.command](cmd, store)
|
||||
res = Result()
|
||||
res.error = 'Unknown command: %s' % cmd.command
|
||||
res.keepwindow = True
|
||||
return res
|
||||
w = Window()
|
||||
w.main()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
Reference in new issue
Block a user