#-*- coding: cp949 -*-
# Name : py_email.py
# Author : chobocho.com
# Version :
# Copyright :
# Description : Simple template maker
#
from Tkinter import *
import tkMessageBox
import os.path
import glob
import re
class App:
def __init__ (self, master):
frame = Frame(master)
frame.pack()
# Text Area
f0 = Frame(frame, width = 100, height = 100)
f0.grid(row = 0, column = 0)
self.text_scrollbar = Scrollbar (f0, orient=VERTICAL)
self.text = Text(f0, width=80, height = 20, yscrollcommand=self.text_scrollbar.set)
self.text_scrollbar.config(command=self.text.yview)
self.text_scrollbar.pack(side=RIGHT, fill=Y)
self.text.pack()
# List Box area
f1 = Frame(frame, width = 100, height = 100)
f1.grid(row = 0, column = 1)
self.list_label = Label(f1, text="Template")
self.list_label.pack()
self.listbox_scrollbar = Scrollbar (f1, orient=VERTICAL)
self.listbox = Listbox(f1, height=19, yscrollcommand=self.listbox_scrollbar.set)
self.listbox_scrollbar.config(command=self.listbox.yview)
self.listbox_scrollbar.pack(side=RIGHT, fill=Y)
# 파일에서 템플릿을 읽어서 보여 줄 것
self.ReadTemplate()
self.listbox.bind("<Double-Button-1>", self.LoadFile)
self.listbox.pack(side=RIGHT)
# 보내는 사람과 받는 사람을 저장하는 부분
f3 = Frame(frame, width = 100, height = 40)
f3.grid(row = 1, column = 0)
self.label_From = Label(f3, text="From")
self.label_From.grid(row = 0, column = 0, sticky = W)
self.label_To = Label(f3, text="To")
self.label_To.grid(row = 1, column = 0, sticky = W)
self.input_from = Entry(f3)
self.input_from.grid(row = 0, column = 1)
self.input_to = Entry(f3)
self.input_to.grid(row = 1, column = 1)
# 버튼을 그려주는 부분
f4 = Frame(frame, width = 100, height = 40)
f4.grid(row = 1, column = 1)
#self.load_button = Button(f4, text="Load", command = self.LoadFile)
#self.load_button.grid(row = 0, column = 0)
self.clear_button = Button(f4, text="Clear", command = self.ClearText)
self.clear_button.grid(row = 0, column = 0)
self.info_button = Button(f4, text="Info", command = self.ShowInfo)
self.info_button.grid(row = 0, column = 1)
def ClearText(self):
self.text.delete(1.0, END)
def ShowInfo(self):
tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.2")
def GetFromTo(self):
self.sender = self.input_from.get()
self.receiver = self.input_to.get()
def ReadTemplate(self):
all_flist = glob.glob ("*.txt")
for f in all_flist:
if os.path.exists(f):
self.listbox.insert(END, f.decode('cp949'))
def LoadFile(self, event):
self.items = self.listbox.curselection()
self.el = self.listbox.get(self.items)
self.GetFromTo()
self.ClearText()
if os.path.exists(self.el):
self.fp = open(self.el, 'r')
self.tempFileData = self.fp.read()
self.fp.close()
self.text_data_1 = re.sub('\$SENDER_NAME_' , self.sender , self.tempFileData)
self.text_data = re.sub('\$RECEIVER_NAME_' , self.receiver , self.text_data_1)
self.text.insert(1.0, self.text_data.decode('cp949'))
#----------------------------------------------------------
# main
if __name__ == "__main__":
root = Tk()
app = App(root)
root.mainloop()
'Coding > Python 삽질기' 카테고리의 다른 글
Quick Sort (0) | 2010.06.10 |
---|---|
[Python] 짧은 코드 모음 (0) | 2010.01.22 |
[Python] 초간단 Lotto 생성기 소스 (0) | 2010.01.22 |