Skip to content

Commit

Permalink
This is the python script that comprises the entire app.
Browse files Browse the repository at this point in the history
  • Loading branch information
josefski committed Apr 7, 2012
1 parent d12b008 commit 264fc51
Showing 1 changed file with 287 additions and 0 deletions.
287 changes: 287 additions & 0 deletions time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Tue Mar 20 19:58:17 2012


import wx

# begin wxGlade: extracode
# end wxGlade
import csv
import time
from time import strftime
import os.path

a = []
ot = []
oft = []
OnTask = ['On Task' ]
OffTask = ['Off Task' ]
off=[]
on=[]
ontotal=[]
offtotal=[]



class Task_Timer(wx.Dialog):
def __init__(self, *args, **kwds):
# begin wxGlade: Task_Timer.__init__
kwds["style"] = wx.DEFAULT_DIALOG_STYLE|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.STAY_ON_TOP
wx.Dialog.__init__(self, *args, **kwds)


self.sizer_1_staticbox = wx.StaticBox(self, -1, "")
self.welcome = wx.StaticText(self, -1, label="Welcome")
self.first_name = wx.StaticText(self, -1, "Enter First Name")
self.name_first = wx.TextCtrl(self, -1, "")
self.last_name = wx.StaticText(self, -1, "Enter Last Name")
self.name_last = wx.TextCtrl(self, -1, "")
self.generate_file = wx.Button(self, -1, "Press Here to Select Save Location")
self.time_task = wx.Button(self, -1, "TIME")
self.label_directions = wx.StaticText(self, -1, label="Write Notes Here. A green border means the timer is timing an on-task event\na red border means off-task. Gray means neither timer is running.")
self.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.TE_LINEWRAP|wx.TE_WORDWRAP)
self.save_quit = wx.Button(self, -1, "Save and Quit ")
self.about = wx.Button(self, -1, "About")

self.Bind(wx.EVT_BUTTON, self.filefunc, self.save_quit)
self.Bind(wx.EVT_BUTTON, self.time_event, self.time_task)
self.Bind(wx.EVT_BUTTON, self.header, self.generate_file)
self.Bind(wx.EVT_BUTTON, self.OnAboutBox, self.about)

self.time_task.Enable(False)

self.__set_properties()
self.__do_layout()
# end wxGlade

def __set_properties(self):
# begin wxGlade: Task_Timer.__set_properties
self.SetTitle("Time On Task")
self.text_ctrl_1.SetMinSize((390, 180))
self.about.SetMinSize((95, 28))

# end wxGlade

def __do_layout(self):
# begin wxGlade: Task_Timer.__do_layout
sizer_1 = wx.StaticBoxSizer(self.sizer_1_staticbox, wx.VERTICAL)
sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_1.Add(self.welcome, 0, wx.EXPAND, 0)
sizer_2.Add(self.first_name, 0, 0, 0)
sizer_2.Add(self.name_first, 1, wx.EXPAND, 0)
sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
sizer_3.Add(self.last_name, 0, 0, 0)
sizer_3.Add(self.name_last, 1, wx.EXPAND, 0)
sizer_1.Add(sizer_3, 1, wx.EXPAND, 0)
sizer_1.Add(self.generate_file, 0, wx.EXPAND, 0)
sizer_1.Add(self.time_task, 0, wx.EXPAND, 0)
sizer_1.Add(self.label_directions, 0, wx.EXPAND, 0)
sizer_1.Add(self.text_ctrl_1, 0, wx.EXPAND, 2)
sizer_4.Add(self.save_quit, 0, 0, 0)
sizer_4.Add((20, 20), 1, wx.EXPAND, 0)
sizer_4.Add(self.about, 0, 0, 0)
sizer_1.Add(sizer_4, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
# end wxGlade


def header(self, event, **dialogOptions):
dialog = wx.DirDialog(self, **dialogOptions)
if dialog.ShowModal() == wx.ID_OK:
self.dirname = dialog.GetPath()
dialog.Destroy()
directory = self.dirname
date_time = strftime("%Y-%m-%d %H:%M:%S")
first = self.name_first.GetValue()
last = self.name_last.GetValue()
text_file = open("%s\%s_%s.txt" % (directory, first, last), "w")
text_file.write("OBSERVATION REPORT FOR: %s %s " % (first, last))
text_file.write("%s" % (date_time))
text_file.write('\n')
text_file.write('----------------------------------------------------------------------------')
text_file.write('\n')
text_file.write('----------------------------------------------------------------------------')
text_file.write('\n')
text_file.write('\n')
self.time_task.Enable(True)
self.generate_file.Enable(False)
self.name_first.Enable(False)
self.name_last.Enable(False)


def time_event(self, event):
a.append(1)
countfinal = len(a)
if countfinal > 3:
del a[0:]
self.welcome.SetLabel("Indeterminate")
self.label_directions.SetLabel("Cick TIME to record on-task event")


if countfinal == 1:
on_start = time.time()
ot.append(on_start)
self.welcome.SetLabel("Timing On Task Event")
first = self.name_first.GetValue()
self.label_directions.SetLabel("Timing On Task Event")
self.SetBackgroundColour(wx.GREEN)
self.Refresh()
on.append(1)
size = 18
font = wx.Font(size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.label_directions.SetFont(font)
self.save_quit.Enable(False)

if countfinal == 2:
on_stop = time.time()
on_taskraw = on_stop - ot.pop()
on_task = round(on_taskraw, 2)
ontotal.append(on_task)
OnTask.append(on_task)
self.SetBackgroundColour(wx.LIGHT_GREY)
self.Refresh()
self.label_directions.SetLabel("Click TIME to record off-task event")
notes = self.text_ctrl_1.GetValue()
first = self.name_first.GetValue()
last = self.name_last.GetValue()
directory = self.dirname
text_file = open("%s\%s_%s.txt" % (directory, first, last), "a")
length = len(on)
date_time = strftime("%H:%M:%S")
text_file.write("\n")
text_file.write("ON TASK EVENT#%s, Interval Time: %s sec, Time of Day: %s" % (length, on_task, date_time))
text_file.write('\n')
text_file.write("==>%s" % (notes))
text_file.write('\n')
text_file.write("-----------------------------------------------------------")
text_file.write('\n')
self.text_ctrl_1.Clear()
self.save_quit.Enable(True)
self.SetBackgroundColour(wx.LIGHT_GREY)

if countfinal == 3:
start_off = time.time()
oft.append(start_off)
self.SetBackgroundColour(wx.RED)
self.Refresh()
first = self.name_first.GetValue()
self.welcome.SetLabel("Timing Off Task Event")
self.label_directions.SetLabel("Timing off-task event.\n Record Notes Below")
off.append(1)
self.save_quit.Enable(False)

if countfinal == 4:
stop_off = time.time()
off_taskraw = stop_off - oft.pop()
off_task = round(off_taskraw, 2)
offtotal.append(off_task)
OffTask.append(off_task)
self.SetBackgroundColour(wx.LIGHT_GREY)
self.Refresh()
notes2 = self.text_ctrl_1.GetValue()
self.welcome.SetLabel("Indeterminate")
first = self.name_first.GetValue()
last = self.name_last.GetValue()
directory = self.dirname
text_file = open("%s\%s_%s.txt" % (directory, first, last), "a")
length = len(off)
date_time = strftime("%H:%M:%S")
text_file.write("\n")
text_file.write("OFF TASK EVENT#%s Interval Time: %s sec Time of Day: %s" % (length, off_task, date_time))
text_file.write('\n')
text_file.write("==>%s" % (notes2))
text_file.write('\n')
text_file.write('-----------------------------------------------------------')
text_file.write('\n')
self.text_ctrl_1.Clear()
self.save_quit.Enable(True)


def filefunc(self, event):
firstname = self.name_first.GetValue()
lastname = self.name_last.GetValue()
directory = self.dirname
writefile = csv.writer(open('%s\%s_%s.csv' % (directory, firstname, lastname), 'wb'), delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
writefile.writerow(OnTask)
writefile.writerow(OffTask)
self.welcome.SetLabel("Saved")
total_off = sum(offtotal)
total_on = sum(ontotal)
final_notes = self.text_ctrl_1.GetValue()
first = self.name_first.GetValue()
last = self.name_last.GetValue()
directory = self.dirname
text_file = open("%s\%s_%s.txt" % (directory, first, last), "a")
text_file.write('\n')
text_file.write('FINAL OBSERVATION NOTES:')
text_file.write('\n')
text_file.write('\n')
text_file.write('%s' % (final_notes))
text_file.write('\n')
text_file.write('\n')
text_file.write('Total time on task: %s' % (total_on))
text_file.write('\n')
text_file.write('Total time off task: %s' % (total_off))
text_file.write('\n')


date_time = strftime("%Y-%m-%d %H:%M:%S")
text_file.write("END OF REPORT" '\n')
text_file.write("%s" % (date_time))
self.Close(True)
self.Destroy()

# end of class Task_Timer

def OnAboutBox(self, e):

description = """Time on Task is an application, written in Python,
designed to make Time on Task observations more accurate and official looking.
Its intended users are special educators and school psychologists. Time on Task
outputs to .csv and .txt so that the user will have access to the maximum number of
programs in which to manipulate their data. It is recommended the .txt file
be opened in either a word processor or text editor and that the .csv be
opened in a spreadsheet editor.
"""

licence = """Time on Task is free software; you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Time on Task is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. You should have
received a copy of the GNU General Public License along with Time on Task;
if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA"""


info = wx.AboutDialogInfo()


info.SetName('Time on Task')
info.SetVersion('1.0')
info.SetDescription(description)
info.SetCopyright('(C) 2012 - 2017 Josef Hoffman')
info.SetWebSite('http://www.puddletownindie.com')
info.SetLicence(licence)
info.AddDeveloper('Josef Hoffman')
info.AddDocWriter('Josef Hoffman')


wx.AboutBox(info)

if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
task = Task_Timer(None, -1, "")
app.SetTopWindow(task)
task.Show()
app.MainLoop()

0 comments on commit 264fc51

Please sign in to comment.