论坛首页 编程语言技术论坛

wxGDT - [Gmail同步未完成]

浏览 2818 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-01-26   最后修改:2010-01-26
wxGDT是我为自己写的一个简便的GDT工具,平时都用Gmail来做GDT管理。考虑到应该有个离线的GDT工具,而且也未找到适合自己风格的替代品,于是写了一个。功能欠缺Gmail同步模块,待增加!

数据保存:用pickle module保存于同目录文件下.
截图:


代码:

#!/usr/bin/python
'''
File: wxGTD.py
Author: Twilight
Description: Get Things Done tool coded with wxPython
'''

import wx
import pickle

category = {}

class NewFrame(wx.Frame):
    def __init__(self,main,id=-1,size=(100,200),type="Category",style=wx.CAPTION|wx.SYSTEM_MENU|wx.CLOSE_BOX):
	wx.Frame.__init__(self,main,-1,"New Things",(0,0),size,style=style)
	self.SetBackgroundColour(wx.WHITE)
	self.panel = wx.Panel(self,-1)
	self.CenterOnScreen()
	if type == "Category":	#Default "Category"
	    self.staticText = wx.StaticText(self.panel,-1,"Enter a category:",(5,25),(-1,20))
	    self.staticText.SetFont(main.font)
	    self.categoryText = wx.TextCtrl(self.panel,-1,pos=(100,20),size=(130,20))
	    self.categoryText.SetFont(main.font)
	    self.button = wx.Button(self.panel,-1,"New",pos=(235,20),size=(63,22))
	    self.button.SetFont(main.font)
	    self.Bind(wx.EVT_BUTTON,self.OnClick,self.button)
	    self.main = main
	elif type == "Item":	#pass parameter type "Item"
	    self.main = main
	    #Select category - combo box
	    self.cbox = wx.ComboBox(self.panel,2, "Select category",(270, 10), 
			    (120,-1),sorted(category.keys()),wx.CB_DROPDOWN)
	    self.cbox.SetFont(self.main.font)
	    self.Bind(wx.EVT_COMBOBOX, self.blah, self.cbox)

	    #Tittle
	    self.staticText = wx.StaticText(self.panel,-1,"Tittle",(10,10),(-1,20))
	    self.staticText.SetFont(main.font)
	    self.TittleText = wx.TextCtrl(self.panel,-1,pos=(50,10),size=(210,20))
	    self.TittleText.SetFont(main.font)
	    
	    #Content
	    self.ContentText = wx.TextCtrl(self.panel,-1,pos=(10,35),size=(380,200),
					    	style=wx.TE_MULTILINE)
	    self.ContentText.SetFont(main.font)
	    
	    #Create Button
	    self.createbutton = wx.Button(self.panel,-1,"Create",pos=(170,240),size=(63,22))
	    self.createbutton.SetFont(self.main.font)
	    self.Bind(wx.EVT_BUTTON,self.OnCreate,self.createbutton)
    
    def blah(self,eve):
        """docstring for blah"""
        pass

    def OnClick(self,event):
        """docstring for OnClick"""
	global category
        new_category = self.categoryText.GetValue()
	if category.get(new_category,None) == None:
	    category[new_category] = None
	    out = open("opps.ini","w")
	    pickle.dump(category,out)
	    out.close()
	    self.main.UpdateList()
	    self.Close()

    def OnCreate(self,event):
        """docstring for OnCreate"""
	global category
	title = self.TittleText.GetValue()
	cate = self.cbox.GetValue()
	content = self.ContentText.GetValue()
	if title == "" or cate == "Select category" or content == "":
	    wx.MessageBox("Some field is empty!sorry!")
	    return
	if category[cate] == None:
	    dict = {}
	    dict["tittle"] = title
	    dict["content"] = content
	    L = []
	    L.append(dict)
	    category[cate] = L
	    out = open("opps.ini","w")
	    pickle.dump(category,out)
	    out.close()
	else:
	    dict = {}
	    dict["tittle"] = title
	    dict["content"] = content
	    category[cate].append(dict)
	    out = open("opps.ini","w")
	    pickle.dump(category,out)
	    out.close()
	self.Close()


class Frame(wx.Frame):
    def __init__(self,id=-1,size=(500,600),style=wx.MINIMIZE_BOX|wx.CAPTION|wx.SYSTEM_MENU|wx.CLOSE_BOX):
        wx.Frame.__init__(self,None,-1,"Get Things Done",(0,0),size=size,style=style)
	self.panel = wx.Panel(self,-1)
	self.SetBackgroundColour(wx.WHITE)
	self.CenterOnScreen()

	#Create a font
	self.font = wx.Font(10,family=wx.DEFAULT,style=wx.NORMAL,weight=wx.NORMAL,faceName="Courier New")

	#Prepare the MenuBar
	menuBar = wx.MenuBar()
	
	#New menu
	new_Menu = wx.Menu()
	new_Menu.Append(101,"&New Category","A text")
	new_Menu.Append(102,"&New Item","A Text")
	new_Menu.Append(103,"E&xit","A text")
	menuBar.Append(new_Menu,"&New ")
	
	#Delete menu
	delete_menu = wx.Menu()

	#List Box
	self.listPos = (3,3)
	self.listRange = (120,227)
	self.listbox = wx.ListBox(self.panel,60,self.listPos,self.listRange,
				    sorted(category.keys()),wx.LB_SINGLE)
	self.listbox.SetFont(self.font)
	self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.listbox)
	
	#Combo Box
	l = []
	self.cb = wx.ComboBox(self.panel,2, "None Selected",(150, 3), 
			    (160,-1),l,wx.CB_DROPDOWN)
	self.cb.SetFont(self.font)
	self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.cb)
	
	#Tittle TextCtrl
	self.tittle = wx.TextCtrl(self.panel,-1,pos=(150,30),size=(300,20))
	self.tittle.SetFont(self.font)
	
	self.tittleText = wx.StaticText(self.panel,-1,"[ Tittle ]",(460,35),(-1,20))
	self.tittleText.SetFont(self.font)

	#Content TextCtrl
	self.content = wx.TextCtrl(self.panel,-1,pos=(150,55),size=(380,150),
				style=wx.TE_MULTILINE)
	self.content.SetFont(self.font)	
	
	#Delete Item
	self.delitembutton = wx.Button(self.panel,-1,"Delete Item",pos=(312,3),size=(110,23))
	self.delitembutton.SetFont(self.font)
	self.Bind(wx.EVT_BUTTON,self.OnDelItem,self.delitembutton)

	#Delete Category Button
	self.delcatebutton = wx.Button(self.panel,-1,"Delete Category",pos=(422,3),size=(110,23))
	self.delcatebutton.SetFont(self.font)
	self.Bind(wx.EVT_BUTTON,self.OnDel,self.delcatebutton)
    
	#Move to Combo box
	self.mtText = wx.StaticText(self.panel,-1,"Move To",(150,212),(-1,20))
	self.mtText.SetFont(self.font)

	self.mtcb = wx.ComboBox(self.panel,2, "Move To...",(205,208), 
			    (200,-1),sorted(category.keys()),wx.CB_DROPDOWN)
	self.mtcb.SetFont(self.font)
	self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.mtcb)

	#Apply the menubar
	self.SetMenuBar(menuBar)
	
	#Menu Events
	self.Bind(wx.EVT_MENU, self.Menu101, id=101)
	self.Bind(wx.EVT_MENU, self.Menu102, id=102)
	self.Bind(wx.EVT_MENU, self.Menu103, id=103)

    #Methods
    def EvtMoveTo(self,evt):
        """docstring for EvtMoveTo"""
	if self.mtcb != evt.GetEventObject():
	    return
        global category
        destcate = self.mtcb.GetValue()
	
	tittle_to_move = self.cb.GetValue()
	if tittle_to_move == "None Selected":
	    return 

	#first move to
	list = category[destcate]
	if list == None:
	    l = []
	    dict = {}
	    dict["tittle"] = self.tittle.GetValue()
	    dict["content"] = self.content.GetValue()
	    l.append(dict)
	    category[destcate] = l
	else:
	    dict = {}
	    dict["tittle"] = self.tittle.GetValue()
	    dict["content"] = self.content.GetValue()
	    category[destcate].append(dict)
	
	#second delete
	cate = self.listbox.GetStringSelection()
	list = category[cate]
	for dict in xrange(0,len(list)):
	    if list[dict]["tittle"] == tittle_to_move:
		del list[dict]
		out = open("opps.ini","w")
		pickle.dump(category,out)
		out.close()
		break
	self.ClearItemControll()
	
    def OnDelItem(self,evt):
        """docstring for OnDelItem"""
	global category
        tittle_to_delete = self.cb.GetValue()
	if tittle_to_delete == "None Selected":
	    return 
	cate = self.listbox.GetStringSelection()
	list = category[cate]

	for dict in xrange(0,len(list)):
	    if list[dict]["tittle"] == tittle_to_delete:
		del list[dict]
		out = open("opps.ini","w")
		pickle.dump(category,out)
		out.close()
		break
	self.ClearItemControll()
	wx.MessageBox("%s deleted successfully!"%tittle_to_delete)

    def OnDel(self,event):
	global category
	cate = self.listbox.GetStringSelection()
	if cate == "":
	    return
	del category[cate]
	out = open("opps.ini","w")
	pickle.dump(category,out)
	out.close()
	self.UpdateList()
	self.ClearItemControll()
    
    def ClearItemControll(self):
	#Clear Combo Box
	self.cb.Show(False)
	del self.cb
	self.cb = wx.ComboBox(self.panel,2, "None Selected",(150, 3), 
				    (160,-1),[],wx.CB_DROPDOWN)
	self.cb.SetFont(self.font)
	self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.cb)
	#Clear tittle and content controlls
	self.tittle.SetValue("")
	self.content.SetValue("")
	
    def EvtListBox(self,event):
	#clear up Tittle and Content controlls
	self.tittle.SetValue("")
	self.content.SetValue("")
	
	cate = event.GetString()
	list = category[cate]
	l = []
	if list == None or list == []:
	    self.cb.Show(False)
	    del self.cb
	    self.cb = wx.ComboBox(self.panel,2, "None Selected",(150, 3), 
				(160,-1),[],wx.CB_DROPDOWN)
	    self.cb.SetFont(self.font)
	    self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.cb)
	    return 

	for dict in list:
	    l.append(dict["tittle"])
	self.cb.Show(False)
	del self.cb
	self.cb = wx.ComboBox(self.panel,2, "None Selected",(150, 3), 
			    (160,-1),l,wx.CB_DROPDOWN)
	self.cb.SetFont(self.font)
	self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.cb)

    def EvtComboBox(self,event):
        """docstring for EvtComboBox"""
	self.EvtMoveTo(event)
	if self.cb != event.GetEventObject():
	    return
	tittle = event.GetString()
	if tittle == "None Selected":
	    return

	self.tittle.SetValue(tittle)
	cate = self.listbox.GetStringSelection()
	list = category[cate]
	for dict in list:
	    if dict["tittle"] == tittle:
		self.content.SetValue(dict["content"])
		break

    def UpdateList(self):
        """docstring for UpdateList"""
	self.listbox.Show(False)
        del self.listbox
	self.listbox = wx.ListBox(self.panel,60,self.listPos,self.listRange,
				sorted(category.keys()),wx.LB_SINGLE)
	self.listbox.SetFont(self.font)
	self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.listbox)
	
	self.mtcb.Show(False)
	del self.mtcb
	self.mtcb = wx.ComboBox(self.panel,2, "Move To...",(205,208), 
				 (200,-1),sorted(category.keys()),wx.CB_DROPDOWN)
	self.mtcb.SetFont(self.font)
	self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.mtcb)

    #New Category
    def Menu101(self,event):
        """docstring for Menu101"""
        new = NewFrame(size=(310,90),main=self)
	new.Show()
    #New Item
    def Menu102(self,event):
        """docstring for Menu102"""
	new = NewFrame(size=(400,300),main=self,type="Item")
	new.Show()
    #Exit Programe
    def Menu103(self,event):
        """docstring for Menu103"""
        self.Close()

class OwnApp(wx.App):
    def OnInit(self):
	global category
        #Read configuration from oops.ini file
	try:
	    infile = open("opps.ini","r")
	except IOError:
	    wx.MessageBox("IOError!")
	else:
	    category = pickle.load(infile)
	    infile.close()
	frame = Frame(size=(600,290))
	frame.Show()
	return True

if __name__ == '__main__':
    app = OwnApp()
    app.MainLoop()
  • 大小: 45.3 KB
   发表时间:2010-02-21  
挺不错的。以前用Java也实现过类似功能,现在不碰Java好多年……
0 请登录后投票
   发表时间:2010-05-18  
pipal 写道
挺不错的。以前用Java也实现过类似功能,现在不碰Java好多年……

Java我懂得很少,我自己学习C++
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics