Added first bit of timing code
This commit is contained in:
parent
6b484c1308
commit
9a9b38f98d
29
DataStore.py
29
DataStore.py
@ -96,7 +96,7 @@ VALUES (?, ?, ?)
|
||||
''', (nextid, projectid, taskname))
|
||||
c.close()
|
||||
self.conn.commit()
|
||||
return True
|
||||
return nextid
|
||||
|
||||
def getNextId(self, table):
|
||||
c = self.conn.cursor()
|
||||
@ -147,3 +147,30 @@ GROUP BY projects.id
|
||||
c.close()
|
||||
self.conn.commit()
|
||||
return hours
|
||||
|
||||
def setTaskHours(self, taskid, date, secs):
|
||||
c = self.conn.cursor()
|
||||
c.execute('''
|
||||
UPDATE hours
|
||||
SET seconds = ?
|
||||
WHERE taskid = ?
|
||||
AND date = ?
|
||||
''', (secs, taskid, str(date)))
|
||||
c.close()
|
||||
self.conn.commit()
|
||||
return secs
|
||||
|
||||
def addTaskHours(self, taskid, date, secs):
|
||||
c = self.conn.cursor()
|
||||
c.execute('''
|
||||
SELECT seconds
|
||||
FROM hours
|
||||
WHERE taskid = ?
|
||||
AND date = ?
|
||||
''', (taskid, date))
|
||||
for row in c:
|
||||
print "%d %d" % (secs, row[0])
|
||||
secs += row[0]
|
||||
c.close()
|
||||
self.conn.commit()
|
||||
return self.setTaskHours(taskid, date, secs)
|
||||
|
20
Window.py
20
Window.py
@ -7,8 +7,8 @@ class Window:
|
||||
def __init__(self, progName, ds):
|
||||
self.ds = ds
|
||||
self.shown_projects = []
|
||||
now = datetime.now()
|
||||
self.monday = now.date() - timedelta(now.weekday())
|
||||
self.taskStart = datetime.now()
|
||||
self.monday = self.taskStart.date() - timedelta(self.taskStart.weekday())
|
||||
|
||||
# Top-level Window creation
|
||||
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
@ -30,6 +30,7 @@ class Window:
|
||||
# Projects Table
|
||||
self.projects_present = False
|
||||
self.currProject = 0
|
||||
self.currTask = 0
|
||||
self.projects_container = gtk.VBox()
|
||||
self.updateProjects()
|
||||
|
||||
@ -266,6 +267,7 @@ class Window:
|
||||
pnum = 0
|
||||
if pnum:
|
||||
self.shown_projects.append(pnum)
|
||||
self.project_select_event(pname)
|
||||
self.updateProjects()
|
||||
|
||||
def project_key_press_event(self, widget, event, data=None):
|
||||
@ -299,6 +301,11 @@ class Window:
|
||||
tnum = self.getTaskNum(tname)
|
||||
elif len(tname.strip()):
|
||||
tnum = self.ds.createTask(self.currProject, tname)
|
||||
else:
|
||||
tnum = 0
|
||||
if tnum:
|
||||
self.tasks = self.ds.getTasks(self.currProject)
|
||||
self.task_select_event(tname)
|
||||
self.updateProjects()
|
||||
|
||||
def task_key_press_event(self, widget, event, data=None):
|
||||
@ -320,10 +327,19 @@ class Window:
|
||||
def task_select_event(self, taskName):
|
||||
tnum = self.getTaskNum(taskName)
|
||||
if tnum:
|
||||
self.updateCurrTaskHours()
|
||||
self.currTask = tnum
|
||||
print "Selected task '%s' (%d)" % (taskName, tnum)
|
||||
self.updateProjects()
|
||||
return True
|
||||
return False
|
||||
|
||||
def updateCurrTaskHours(self):
|
||||
nst = datetime.now()
|
||||
delta = nst - self.taskStart
|
||||
self.ds.addTaskHours(self.currTask, nst.date(), delta.seconds)
|
||||
self.taskStart = nst
|
||||
|
||||
def delete_event(self, widget, event, data=None):
|
||||
return False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user