diff --git a/Window.py b/Window.py
index cb080ed..78f5528 100644
--- a/Window.py
+++ b/Window.py
@@ -29,14 +29,10 @@ class Window:
# Projects Table
self.projects_present = False
+ self.currProject = 0
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')
@@ -55,13 +51,19 @@ 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)
def updateProjects(self):
+ def projTblCell(text, pnum):
+ lbl = gtk.Label(text)
+ e = gtk.EventBox()
+ e.add(lbl)
+ if pnum == self.currProject:
+ e.set_state(gtk.STATE_SELECTED)
+ return e
+
if self.projects_present:
self.projects_container.remove(self.projects_table)
self.projects = self.ds.getProjects()
@@ -73,13 +75,17 @@ class Window:
for p in project_week_hours:
projects_to_show[p] = 1
+ self.tasks = self.ds.getTasks(self.currProject)
+ self.task_hour_labels = {}
+
# Header row
col_headers = ('Project',
'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun', 'Tot')
- rows = 3 + len(projects_to_show)
+ rows = 3 + len(projects_to_show) + len(self.tasks)
columns = len(col_headers)
self.projects_table = gtk.Table(rows = rows, columns = columns)
+ row = 0
for i in range(len(col_headers)):
l = gtk.Label()
l.set_markup('%s' % col_headers[i])
@@ -88,24 +94,22 @@ class Window:
l.set_size_request(60, -1)
else:
l.set_size_request(40, -1)
- self.projects_table.attach(l, i, i + 1, 0, 1)
+ self.projects_table.attach(l, i, i + 1, row, row + 1)
- row = 1
+ row += 1
pnames_to_show = map(lambda x: self.projects[x], projects_to_show)
pnames_to_show.sort()
for pname in pnames_to_show:
pnum = self.getProjectNum(pname)
- l = gtk.Label(pname)
- l.set_alignment(0.0, 0.0)
- e = gtk.EventBox()
- e.add(l)
+ e = projTblCell(pname, pnum)
+ e.get_child().set_alignment(0.0, 0.0)
e.add_events(gtk.gdk.BUTTON_PRESS_MASK)
e.connect("button-press-event", self.project_click_event)
self.projects_table.attach(e, 0, 1, row, row + 1)
self.project_hour_labels[pnum] = {}
for i in range(8):
- l = gtk.Label()
- self.projects_table.attach(l, i + 1, i + 2, row, row + 1)
+ e = projTblCell(" ", pnum)
+ self.projects_table.attach(e, i + 1, i + 2, row, row + 1)
self.project_hour_labels[pnum][i] = l
row += 1
@@ -113,7 +117,8 @@ class Window:
l = gtk.Label()
l.set_markup('Total')
l.set_alignment(0.0, 0.0)
- self.projects_table.attach(l, 0, 1, rows - 2, rows - 1)
+ self.projects_table.attach(l, 0, 1, row, rows + 1)
+ row += 1
# Add project row
self.new_project_combobox = gtk.combo_box_entry_new_text()
@@ -129,8 +134,55 @@ class Window:
hbox = gtk.HBox()
hbox.pack_start(self.new_project_combobox, expand = False)
hbox.pack_start(self.add_project_button, expand = False)
- self.projects_table.attach(hbox, 0, columns, rows - 1, rows)
+ self.projects_table.attach(hbox, 0, columns, row, row + 1)
self.projects_table.set_row_spacings(3)
+ row += 1
+
+ # Add Tasks information of we have a current project
+ if self.currProject > 0:
+ l = gtk.Label()
+ l.set_markup('Tasks')
+ self.projects_table.attach(l, 0, 1, row, row + 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.projects_table.attach(e, 0, 1, row, row + 1)
+ self.task_hour_labels[tnum] = {}
+ for i in range(8):
+ l = gtk.Label()
+ self.projects_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('Total')
+ l.set_alignment(0.0, 0.0)
+ self.projects_table.attach(l, 0, 1, row, row + 1)
+ row += 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.projects_table.attach(hbox, 0, columns, row, row + 1)
+ self.projects_table.set_row_spacings(3)
+ row += 1
self.projects_container.pack_start(self.projects_table)
self.projects_present = True
@@ -138,72 +190,6 @@ 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 = {}
-
- # 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('%s' % 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('Total')
- 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):
@@ -256,10 +242,13 @@ class Window:
pname = self.new_project_combobox.get_active_text()
if pname in self.projects.values():
pnum = self.getProjectNum(pname)
- else:
+ elif len(pname.strip()):
pnum = self.ds.createProject(pname)
- self.shown_projects.append(pnum)
- self.updateProjects()
+ else:
+ pnum = 0
+ if pnum:
+ self.shown_projects.append(pnum)
+ self.updateProjects()
def project_key_press_event(self, widget, event, data=None):
if event.keyval == gtk.gdk.keyval_from_name("Return"):
@@ -282,7 +271,7 @@ class Window:
if pnum:
print "Selected project '%s' (%d)" % (projectName, pnum)
self.currProject = pnum
- self.updateTasks()
+ self.updateProjects()
return True
return False
@@ -290,9 +279,9 @@ class Window:
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()
+ elif len(tname.strip()):
+ tnum = self.ds.createTask(self.currProject, tname)
+ self.updateProjects()
def task_key_press_event(self, widget, event, data=None):
if event.keyval == gtk.gdk.keyval_from_name("Return"):