AppTimeTrack.plug in.py :  » IDE » Boa-Constructor » boa-constructor-0.6.1 » Plug-ins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » Boa Constructor 
Boa Constructor » boa constructor 0.6.1 » Plug ins » AppTimeTrack.plug-in.py
""" Plugin that adds a simple time tracking view to Application Models """

import os, sys, time

import wx

import Preferences, Utils
from Utils import _

from Models import PythonControllers

from Explorers import Explorer
from Views.EditorViews import ListCtrlView
from Views.AppViews import TextInfoFileView

class AppTimeTrackView(ListCtrlView):
    viewName = 'Time Tracking'
    viewTitle = _('Time Tracking')
    def __init__(self, parent, model):
        ListCtrlView.__init__(self, parent, model, wx.LC_REPORT,
          ((_('Start'), self.OnStart, '-', ''),
           (_('End'), self.OnEnd, '-', ''),
           (_('Delete'), self.OnDelete, '-', ''),
          ), 1)

        self.InsertColumn(0, _('Start'), width=150)
        self.InsertColumn(1, _('End'), width=150)
        self.InsertColumn(2, _('Description'), width=350)

        self.sortOnColumns = [0, 1]

        self.times = []

        self.active = True
        self.model = model

    def refreshCtrl(self):
        ListCtrlView.refreshCtrl(self)
        try:
            self.times = self.readTimes()
        except Explorer.TransportLoadError:
            self.times = []
            #fn = self.getTTVFilename()
            #if not path.exists(fn): open(fn, 'w')

        i = 0
        modSort = self.model.modules.keys()
        modSort.sort()
        for start, end, desc in self.times:
            i = self.addReportItems(i,
                  (self.getTimeStr(start),
                   end and self.getTimeStr(end) or '',
                   desc) )

        self.pastelise()

    def getTimeStr(self, thetime):
        return time.strftime('%Y/%m/%d : %H:%M:%S', time.gmtime(thetime))

    def getTTVFilename(self):
        return os.path.splitext(self.model.filename)[0]+'.ttv'

    def writeTimeEntry(self, file, start, end, desc):
        file.write("(%s, %s, %s)\n" % (`start`, `end`, `desc`))

    def readTimes(self):
        from StringIO import StringIO
        transp = Explorer.openEx(self.getTTVFilename())
        data = StringIO(transp.load())

        return map(lambda line: eval(line), data.readlines())

    def writeTimes(self):
        from StringIO import StringIO
        timesFile = StringIO('')#open(self.getTTVFilename(), 'w')
        for start, end, desc in self.times:
            self.writeTimeEntry(timesFile, start, end, desc)
        timesFile.seek(0)

        uri = self.getTTVFilename()
        transp = Explorer.openEx(uri)
        transp.save(transp.currentFilename(), timesFile.read())

    def OnStart(self, event):
        self.times.append( (time.time(), 0, '') )
        #self.writeTimeEntry(open(self.getTTVFilename(), 'a'), time.time(), 0, '')

        self.writeTimes()
        self.refreshCtrl()

    def OnEnd(self, event):
        selIdx = self.getSelectedIndex()
        start, end, desc = self.times[selIdx]

        if not end:
            end = time.time()

        dlg = wx.TextEntryDialog(self, _('Start time :%s\nEnd time :%s\n\n'\
            'Enter a description for the time spent') % (self.getTimeStr(start),
              self.getTimeStr(end)), _('Time tracking'), desc)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                answer = dlg.GetValue()
                self.times[selIdx] = (start, end, answer)
                self.writeTimes()
                self.refreshCtrl()
        finally:
            dlg.Destroy()

    def OnDelete(self, event):
        selIdx = self.getSelectedIndex()

        if selIdx == -1:
            return

        dlg = wx.MessageDialog(self, _('Are you sure?'),
          'Delete', wx.OK | wx.CANCEL | wx.ICON_QUESTION)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                del self.times[selIdx]
                self.writeTimes()
                self.refreshCtrl()

        finally:
            dlg.Destroy()


class AppFEATURES_TIFView(TextInfoFileView):
    viewName = 'Features.txt'
    viewTitle = 'Features.txt'


#-------------------------------------------------------------------------------
PythonControllers.BaseAppController.AdditionalViews.insert(0, AppTimeTrackView)
PythonControllers.BaseAppController.AdditionalViews.append(AppFEATURES_TIFView)

from Models import EditorHelper
EditorHelper.internalFilesReg.append('.ttv')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.