Added task listing, adding, and clicking
This commit is contained in:
parent
fd473958c2
commit
7955fa6145
119
Window.py
119
Window.py
@ -32,6 +32,11 @@ class Window:
|
||||
self.projects_container = gtk.VBox()
|
||||
self.updateProjects()
|
||||
|
||||
# Tasks Table
|
||||
self.tasks_present = False
|
||||
self.currProject = 0
|
||||
self.tasks_container = gtk.VBox()
|
||||
|
||||
# Bottom Control Bar
|
||||
self.mark_label = gtk.Label()
|
||||
adjust_button = gtk.Button('Adjust')
|
||||
@ -50,6 +55,8 @@ class Window:
|
||||
vbox.pack_start(self.menubar)
|
||||
vbox.pack_start(self.projects_container)
|
||||
vbox.pack_start(gtk.HSeparator())
|
||||
vbox.pack_start(self.tasks_container)
|
||||
vbox.pack_start(gtk.HSeparator())
|
||||
vbox.pack_start(hbox)
|
||||
|
||||
self.window.add(vbox)
|
||||
@ -124,7 +131,6 @@ class Window:
|
||||
hbox.pack_start(self.add_project_button, expand = False)
|
||||
self.projects_table.attach(hbox, 0, columns, rows - 1, rows)
|
||||
self.projects_table.set_row_spacings(3)
|
||||
self.projects_table.connect("button-press-event", self.project_click_event)
|
||||
|
||||
self.projects_container.pack_start(self.projects_table)
|
||||
self.projects_present = True
|
||||
@ -132,6 +138,78 @@ class Window:
|
||||
|
||||
self.updateProjectHours()
|
||||
|
||||
def updateTasks(self):
|
||||
if self.tasks_present:
|
||||
self.tasks_container.remove(self.tasks_table)
|
||||
self.tasks = self.ds.getTasks(self.currProject)
|
||||
self.task_hour_labels = {}
|
||||
# projects_to_show = {}
|
||||
# for p in self.shown_projects:
|
||||
# projects_to_show[p] = 1
|
||||
# project_week_hours = self.getProjectWeekHours()
|
||||
# for p in project_week_hours:
|
||||
# projects_to_show[p] = 1
|
||||
|
||||
# Header row
|
||||
col_headers = (self.projects[self.currProject],
|
||||
'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun', 'Tot')
|
||||
rows = 3 + len(self.tasks)
|
||||
columns = len(col_headers)
|
||||
self.tasks_table = gtk.Table(rows = rows, columns = columns)
|
||||
|
||||
for i in range(len(col_headers)):
|
||||
l = gtk.Label()
|
||||
l.set_markup('<b>%s</b>' % col_headers[i])
|
||||
if i == 0:
|
||||
l.set_alignment(0.0, 0.0)
|
||||
l.set_size_request(60, -1)
|
||||
else:
|
||||
l.set_size_request(40, -1)
|
||||
self.projects_table.attach(l, i, i + 1, 0, 1)
|
||||
|
||||
row = 1
|
||||
for tnum in self.tasks:
|
||||
l = gtk.Label(self.tasks[tnum])
|
||||
l.set_alignment(0.0, 0.0)
|
||||
e = gtk.EventBox()
|
||||
e.add(l)
|
||||
e.add_events(gtk.gdk.BUTTON_PRESS_MASK)
|
||||
e.connect("button-press-event", self.task_click_event)
|
||||
self.tasks_table.attach(e, 0, 1, row, row + 1)
|
||||
self.task_hour_labels[tnum] = {}
|
||||
for i in range(8):
|
||||
l = gtk.Label()
|
||||
self.tasks_table.attach(l, i + 1, i + 2, row, row + 1)
|
||||
self.task_hour_labels[tnum][i] = l
|
||||
row += 1
|
||||
|
||||
# Totals row
|
||||
l = gtk.Label()
|
||||
l.set_markup('<b>Total</b>')
|
||||
l.set_alignment(0.0, 0.0)
|
||||
self.tasks_table.attach(l, 0, 1, rows - 2, rows - 1)
|
||||
|
||||
# Add task row
|
||||
self.new_task_combobox = gtk.combo_box_entry_new_text()
|
||||
self.new_task_combobox.set_size_request(250, -1)
|
||||
self.new_task_combobox.connect("key-release-event",
|
||||
self.task_key_press_event)
|
||||
task_names = self.tasks.values()
|
||||
task_names.sort()
|
||||
for task in task_names:
|
||||
self.new_task_combobox.append_text(task)
|
||||
self.add_task_button = gtk.Button('Add')
|
||||
self.add_task_button.connect('clicked', self.add_task_event)
|
||||
hbox = gtk.HBox()
|
||||
hbox.pack_start(self.new_task_combobox, expand = False)
|
||||
hbox.pack_start(self.add_task_button, expand = False)
|
||||
self.tasks_table.attach(hbox, 0, columns, rows - 1, rows)
|
||||
self.tasks_table.set_row_spacings(3)
|
||||
|
||||
self.tasks_container.pack_start(self.tasks_table)
|
||||
self.tasks_present = True
|
||||
self.tasks_table.show_all()
|
||||
|
||||
def updateProjectHours(self):
|
||||
totals = {}
|
||||
for day in range(7):
|
||||
@ -174,6 +252,12 @@ class Window:
|
||||
return p
|
||||
return 0
|
||||
|
||||
def getTaskNum(self, tname):
|
||||
for t in self.tasks:
|
||||
if self.tasks[t] == tname:
|
||||
return t
|
||||
return 0
|
||||
|
||||
def add_project_event(self, button, data=None):
|
||||
pname = self.new_project_combobox.get_active_text()
|
||||
if pname in self.projects.values():
|
||||
@ -203,6 +287,39 @@ class Window:
|
||||
pnum = self.getProjectNum(projectName)
|
||||
if pnum:
|
||||
print "Selected project '%s' (%d)" % (projectName, pnum)
|
||||
self.currProject = pnum
|
||||
self.updateTasks()
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_task_event(self, button, data=None):
|
||||
tname = self.new_task_combobox.get_active_text()
|
||||
if tname in self.tasks.values():
|
||||
tnum = self.getTaskNum(tname)
|
||||
else:
|
||||
tnum = self.ds.createTask(tname)
|
||||
self.updateTasks()
|
||||
|
||||
def task_key_press_event(self, widget, event, data=None):
|
||||
if event.keyval == gtk.gdk.keyval_from_name("Return"):
|
||||
self.add_task_event(1)
|
||||
return True
|
||||
return False
|
||||
|
||||
def task_click_event(self, ebox, event, data=None):
|
||||
lbl = ebox.get_child()
|
||||
if lbl:
|
||||
if event.button == 1:
|
||||
return self.task_select_event(lbl.get_text())
|
||||
elif event.button == 3:
|
||||
print "Right Click"
|
||||
return True
|
||||
return False
|
||||
|
||||
def task_select_event(self, taskName):
|
||||
tnum = self.getTaskNum(taskName)
|
||||
if tnum:
|
||||
print "Selected task '%s' (%d)" % (taskName, tnum)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user