base64
Jay
first180 at gmail.com
Thu Apr 13 03:16:23 EDT 2006
I don't know whether it is right yet but it dues what I wanted it to
do now so thank you all,
Oh and sorry for my bad grammar.
One last thing though is that I would like to be able to split the
string up into lines of 89 carictors, I have lookd through the split
methods and all I can find is splitting up words and splitting at a
pacific caricature, I can not see how you split after a number of
caricatures
.......................START......................
from Tkinter import *
from base64 import *
#####################################################################
#####################################################################
# Module: Base64 Encoder / Decoder.py
# Author: Jay Dee
# Date: 08/04/2006
# Version: Draft 0.1
# Coments: A Base64 Encoder / Decoder for converting files into Base64
strings
#####################################################################
#####################################################################
class App:
def __init__(self, root):
root.title("Base64 Encoder / Decoder")
#####################################################################
# Menu Bar
#####################################################################
self.menubar = Menu(root)
# create a pulldown menu, and add it to the menu bar
self.filemenu = Menu(self.menubar, tearoff=0)
self.filemenu.add_command(label="Display!",
command=self.Display)
self.filemenu.add_separator()
self.filemenu.add_command(label="Quit!", command=root.quit)
self.menubar.add_cascade(label="File", menu=self.filemenu)
# display the menu
root.config(menu=self.menubar)
#####################################################################
# Display B64 Text
#####################################################################
# File Input
self.FileInputFrame = Frame(root)
self.FileInputFrame.pack(side=TOP, fill=X)
self.FileInputLine = Entry(self.FileInputFrame,
bg="white",
width=70)
self.FileInputLine.pack(side=LEFT, fill=X, expand=1)
# Display Area
self.DisplayFrame = Frame(root)
self.DisplayFrame.pack(side=TOP, fill=BOTH, expand=1)
self.DisplayText = Text(self.DisplayFrame,
bg="lightblue",
width=95,
height=40)
self.DisplayText.pack(side=LEFT, fill=BOTH, expand=1)
root.bind("<Return>",self.Encode)
def Encode(self,event):
'''
Take's the file name from (self.FileInputLine),
opens file,
converts it to base64 then desplays it in (self.DisplayText)
'''
self.DisplayText.delete(1.0,END)
info = self.FileInputLine.get()
if info == "":
self.DisplayText.insert(END, "...Please enter file...")
else:
try:
file = open(info,"rb")
try:
Data = file.read()
Encode = b64encode(Data)
Encode = Encode.split()
self.DisplayText.insert(END, Encode)
except:
self.DisplayText.insert(END, "...Data Erra...")
except:
self.DisplayText.insert(END, "...No Sutch File...")
def Display(self):
'''
Take's the string from (self.DisplayText), Creats a topleval
frame and displays the Data as an image,if that fales it
displays it as text.
'''
info = self.DisplayText.get(1.0,END)
# Display as Image
try:
self.DisplayImage = Toplevel()
self.InfoDisplay = PhotoImage(data=info)
PhotoSize =
[self.InfoDisplay.width(),self.InfoDisplay.height()]
self.DisplayImageCanvas = Canvas(
self.DisplayImage,
width=150,
height=PhotoSize[1] + 15)
self.DisplayImageCanvas.pack(fill=BOTH, expand=1)
self.InfoDisplay2 = self.DisplayImageCanvas.create_image(
PhotoSize[0] / 2 + 10,
PhotoSize[1] / 2 + 10,
image=self.InfoDisplay)
self.InfoDisplay2 = self.DisplayImageCanvas
# Display as Text
except:
self.DisplayBase64Text = Text(
self.DisplayImage,
width=70,
height=30)
self.DisplayBase64Text.pack(fill=BOTH, expand=1)
Decode = b64decode(info)
self.DisplayImageText.insert(END, Decode)
root = Tk()
app = App(root)
root.mainloop()
More information about the Python-list
mailing list