Skip to content

Instantly share code, notes, and snippets.

@rhysforyou
Created August 28, 2010 05:56
Show Gist options
  • Save rhysforyou/554787 to your computer and use it in GitHub Desktop.
Save rhysforyou/554787 to your computer and use it in GitHub Desktop.
import TaskModel
import sys
taskObjects = []
def init():
print "loading..."
return
# I won't bother with too much explanation here, it's fairly simple
def menu():
print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
print """
Welcome to TaskMan!
===================
1. Tasks
2. Log
3. Timetable
4. Exit
"""
choice = int(raw_input("Pick an option\n> "))
if choice == 1:
taskMenu()
elif choice == 2:
logMenu()
elif choice == 3:
timeTableMenu()
elif choice == 4:
sys.exit(0) # Exits with an error code of 0 (means it ran without a hitch)
def taskMenu():
print "\n\n\n\n\n\n\n\n\n\n\n\n\n"
print """
Task Menu
---------
1. View Tasks
2. New Task
3. New Project
4. New Area
5. Main Menu
"""
choice = int(raw_input("Pick an option\n> "))
if choice == 1:
viewTasks()
elif choice == 2:
newTask()
elif choice == 3:
newProject()
elif choice == 4:
newArea
elif choice == 5:
return
def newTask():
print "\n"*25
name = raw_input("Task Name: ")
taskObjects += Task(name)
init()
while True:
menu()
from datetime import *
# The Task class, this is the main part of the program and contains several
# methods which can be used to manage individual task objects
class Task:
# Creates a new instance of the the Task object
# We're only assigning a title here to keep with the philosophy of minimal
# time expendature in creating new tasks
def __init__(self, title):
self.title = title # The task's name
self.description = "" # Any notes relating to the task
self.date = date.today() # The creation date of the task
self.priority = 0 # The priority of the task (from 0-3)
self.due = None # The due date of this task
# Sets the due date of a task instance taking a string formatted
# "D[D]/M[M]/YYYY" as a parameter
def setDue(self, due):
# Bizarre wizardry to turn a string into a DateTime object
self.due = datetime.strptime(due, "%d/%m/%Y")
# Sets the task's description
def setDescription(self, description):
self.description = description
# Allows the user to set a priority with simple validation
def setPriority(self, priority):
if int(priority) >= 0 or int(priority) <= 3:
self.priority = int(priority)
else:
print "invalid priority"
# Change the title that was set upon the object's initialisation
def setTitle(self, title):
self.title = title
# Returns a nicely formatted string containing the due date
def getDue(self):
if self.due != None:
return self.due.strftime("%A, %B %d %Y")
else:
return "Not Set"
# Returns the Task's description
def getDescription(self):
if self.description != '':
return self.Description
else:
return "No Description Given"
# Returns a string containing the Task's properties
def display(self, simple = False):
if simple:
return "+ %s" % (self.title)
else:
return "+ %s\n Due: %s\n Priority: %s\n" % (self.title, self.getDue(), self.priorityAsString(self.priority).title())
# Returns a string stating the priority of an item
def priorityAsString(self, priority):
if priority == 0:
return'Not Set'
elif priority == 1:
return 'low'
elif priority == 2:
return 'moderate'
elif priority == 3:
return 'high'
def test(self):
print self.display(True)
self.setDue("5/6/2010")
self.setDescription("A simple task to test functionality")
self.setPriority(3)
self.setTitle("Test Task (updated)")
print self.display()
class Project:
tasks = []
def __init__(self, title):
self.title = title
self.due = None
def addtask(self, task):
self.tasks.append(task)
# Iterates through all the todos contained within itself
# Prefixed with the project name and indented
def display(self):
print "The Project", self.title, "contains:"
for task in self.tasks:
return " " ,task.display()
print "and nothing else"
class Area:
# Area is a parent object for several clases so we're using the parent / child
# naming convention here.
children = []
def __init__(self, title):
self.title = title
def addObject(self, object):
objects.append
def addObjects(self, object):
objects.append(object)
def display(self):
print "The Area", self.title, "contains:"
for object in self.objects:
print " ", object.display()
print "and nothing else"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment