定制个人的todo list

   年纪大了,就越来越倚重一些工具辅助记忆了,比如一些日常要进行的工作。使用的ubunut,一直感觉conky不错,幸而conky也支持类似todo list的功能,只需在.conky.rc中添加

${color FF0000}${font WenQuanYi ZenHei:size=18}${execpi 120 cat ~/.todo.txt}${font}

其中todo.txt为存放todo项目文件。为了日常管理方便,又增加了python小程序处理todo list的增添删除等

'''
Created on Jul 31, 2013
@author: yisi
'''
import  sys
class todoManager:
    __TODOFILE = ''
    __fd = -1
    __buf = []
                
    def __init__(self, name=None):
        self.setFileName(name)
        try:
            self.__fd = open(self.__TODOFILE, 'r+w')
            self.initBuf()
        except IOError as e:
            print "Can't open {0},error({1}):{2}".format(self.__TODOFILE, e.errno, e.strerror)
    def getFileName(self):
        return self.__TODOFILE
    def setFileName(self, name):
        if name == None:
            self.__TODOFILE = "todo.txt"
        else:
            self.__TODOFILE = name
                
    def initBuf(self):
        self.__fd.seek(0)
        self.__buf = []
        for i in self.__fd:
            self.__buf.append(i.strip())
        self.__fd.seek(0)
                    
    def readBuf(self):
        print self.__buf
                            
    def readTodo(self):
        if len(self.__buf) != 0:
            lineNums = 1
            for i in self.__buf:
                print "{0}: {1}".format(lineNums, i)
                lineNums += 1
        else:
            print "Nothing to do ~"
                            
    def addItems(self, item):
        for i in item:
            self.__buf.append(i)
                    
    def delItems(self, index):
        list.sort(index)
        counter = 1
        for i in index:
            intI = int(i) - counter
            self.__buf.remove(self.__buf[intI])
            counter += 1
    def writeToFile(self):
        try:
            self.__fd.truncate()
        except IOError as e:
            print "Truncate error({0}): {1}".format(e.errno, e.strerror)
        except :
            print sys.exc_info()[0]
            raise
        for i in self.__buf:
            try:
                self.__fd.write(i + '\n')
            except IOError as e:
                print "Write error({0}): {1}".format(e.errno, e.strerror)
                            
        self.initBuf()
                
    def closeFile(self):
        self.__fd.close()

以上为管理类,下为具体操作

#!/usr/bin/env python
# coding=utf-8
'''
Created on Jul 31, 2013
@author: yisi
'''
import todoManager
FILE = "/home/yisi/.todo.txt"
t = todoManager.todoManager(FILE)
flag = 1
def printHelp(t=None):  # @UnusedVariable
    print "-" * 10 + "todo_tools" + "-" * 10
    print "\t" + "1. 显示当前todo list"
    print "\t" + "2. 删除todo项目"
    print "\t" + "3. 增加todo项目"
    print "\t" + "4. 保存todo项目"
    print "\t" + "5. 显示帮助信息"
    print "\t" + "6. 退出todo_tools"
    print "-" * 10 + "todo_tools" + "-" * 10
            
def printCurTodo(t):
    t.readTodo()
def insertItem(t):
    itemS = raw_input("Please input something to do:")
    item = itemS.split(' ')
    while '' in item:
        item.remove('')
    t.addItems(item)
def delItem(t):
    indexS = raw_input("Please input index to delete:")
    index = indexS.split(' ')
    while '' in index:
        index.remove()
    t.delItems(index)
            
def saveItem(t):
    t.writeToFile()
def exitProg(t):
    t.closeFile()
    global flag
    flag = 0
         
SW = {
            '1':printCurTodo,
            '2':delItem,
            '3':insertItem,
            '4':saveItem,
            '5':printHelp,
            '6':exitProg}  
def mainProg():
    global  flag
    while  flag:
        numProg = raw_input("Please input num(1-6):")
        SW[numProg](t)
                
           
if __name__ == "__main__":
    printHelp()
    mainProg()

哈哈,最后,上图


本文出自 “不材神木” 博客,请务必保留此出处http://ouroboros.blog.51cto.com/2468486/1261912

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值