Linux endline
Fabien Hénon
ffjhenon at club-internet.fr
Sat Mar 16 06:30:05 EST 2002
Here is the complete application
from Tkinter import *
from tkFileDialog import askopenfilename, asksaveasfilename
import sys, os, string
plat=sys.platform
class mainWin:
def __init__(self,tkRoot):
self.tkRoot=tkRoot
self.createWidgets()
return None
class App:
## ---------------------- Create GUI ----------------------
def __init__(self, master):
## ---------------------- Mainframe ----------------------
mframe = Frame(master)
mframe.pack(expand=1, fill=BOTH)
frame_input=Frame(mframe)
## ---------------------- Menu ----------------------
menubar=Menu(frame_input)
filemenu=Menu(menubar,tearoff=0)
filemenu.add_command(label="New",command=self.clr)
filemenu.add_command(label="Open",command=self.enter_text)
filemenu.add_command(label="Save",command=self.save)
filemenu.add_command(label="Save As")
filemenu.add_separator()
filemenu.add_command(label="Quit",command=sys.exit)
menubar.add_cascade(label="File",menu=filemenu)
editmenu=Menu(menubar,tearoff=0)
editmenu.add_command(label="Cut")
editmenu.add_command(label="Copy")
editmenu.add_command(label="Paste")
menubar.add_cascade(label="Edit",menu=editmenu)
rendermenu=Menu(menubar,tearoff=0)
rendermenu.add_command(label="Render", command=self.render)
menubar.add_cascade(label="Render",menu=rendermenu)
root.config(menu=menubar)
## ---------------------- Buttons ----------------------
frame_buttons=Frame(mframe)
self.button_open = Button(frame_buttons, text="Open..", fg="blue",
command=self.enter_text)
self.button_open.pack(side=LEFT)
self.button_render = Button(frame_buttons, text="Render..", fg="red",
command=self.render)
self.button_render.pack(side=LEFT)
self.button_render = Button(frame_buttons, text="Command line..",
fg="blue", command=self.parameters_)
self.button_render.pack(side=LEFT)
frame_buttons.pack(expand=0, fill=BOTH)
## ---------------------- Editor ----------------------
self.text = Text(frame_input)
self.yscroll_i = Scrollbar(frame_input,orient=VERTICAL,
command=self.text.yview)
self.yscroll_i.pack(side=RIGHT, fill=Y)
self.text['yscrollcommand']=self.yscroll_i.set
self.text.pack(side=LEFT,expand=1, fill=BOTH)
self.text.bind("<KeyPress>", self.keyPress)
self.yscroll_i.pack(side=RIGHT, fill=Y)
frame_input.pack(expand=1, fill=BOTH)
## ---------------------- Output ----------------------
frame_output=Frame(mframe)
self.text_out = Text(frame_output,state=DISABLED,height=6)
self.text_out.pack(side=LEFT,expand=1, fill=BOTH)
self.scroll = Scrollbar(frame_output, command=self.text_out.yview)
self.text_out.configure(yscrollcommand=self.scroll.set)
self.scroll.pack(side=RIGHT, fill=Y)
frame_output.pack(expand=0, fill=BOTH)
## ---------------------- Status Bar ----------------------
frame_status_bar=Frame(mframe)
self.status = Label(frame_status_bar, bd=1, relief=SUNKEN,
textvariable=affi_Ligne)
self.status.pack(side=RIGHT, fill=NONE, expand=0,anchor=E)
frame_status_bar.pack(expand=0, fill=NONE)
## ---------------------- Open file ----------------------
def enter_text(self):
if plat=="win32":
l=1
self.filename = askopenfilename()
if self.filename:
self.text.delete(1.0, END)
fd = open(self.filename)
for line in fd.readlines():
l=l+1
self.text.insert(END, line)
fd.close()
elif plat=="linux-i386":
l=1
self.filename = askopenfilename()
if self.filename:
self.text.delete(1.0, END)
fd = open(self.filename)
for line in fd.readlines():
l=l+1
self.text.insert(END, line) # self.text.insert(END, line[:-1])
fd.close()
## ---------------------- Clear ----------------------
def clr(self):
self.text.delete(1.0, END)
## ---------------------- Saveas ----------------------
def save(self, forPrt=None):
script = self.text.get(1.0, END)
if script:
if forPrt:
file = 'prt.tmp'
else:
self.filename = file = asksaveasfilename(initialfile= \
self.filename)
fd = open(self.file, 'w')
for line in string.split(script, '\n'):
fd.write(line)
fd.write('\n')
fd.close
## ---------------------- Render ----------------------
def render(self):
os.system("povray +i/home/f/povray35/scenes/advanced/chess2.pov +w320
+h240 -f +dgt")
## ---------------------- Top-Level Command line ----------------------
def parameters_(self):
self.tl=Toplevel()
self.lb=Label(self.tl, text="Render parameters:")
self.cl=Entry(self.tl,width=40)
self.ok=Button(self.tl, text="OK", fg="red",
command=self.get_parameters)
self.ok.pack(side=BOTTOM)
self.cl.pack(side=RIGHT)
self.lb.pack()
def get_parameters(self):
params=self.cl.get()
print params
## ---------------------- Prints the current line number and contents
----------------------
## Line number
def lin(self):
tindex = self.text.index(INSERT)
Ligne, column = map(int, string.split(tindex, "."))
valeur="Line : %d" %int((Ligne))
affi_Ligne.set(valeur)
## ---------------------- Called when a key is pressed
----------------------
def keyPress(self,event):
self.lin()
root = Tk()
affi_Ligne=StringVar()
#params=StringVar()
larg = root.winfo_screenwidth()
haut = root.winfo_screenheight()
root.maxsize()
# root.geometry("%dx%d+0+0" % (larg,haut))
app = App(root)
root.mainloop()
Fabien Hénon a écrit :
> I am writing a POV-RAY editor which can be used with Windows or Linux.
>
> 1° When I use it under Linux I would like to get rid of the \r which
> appears at the end of each line. ( I know there is a difference of
> endline between Windows, Mac and Linux).
>
> I added a slice, but it doesn't seem to work.
> I tried to use
> self.text.insert(END, line[:-1])
> But it does not help
> In short how do I get rid of endline in *nix
>
> ----
> def enter_text(self):
> if plat=="win32":
> l=1
> self.filename = askopenfilename()
> if self.filename:
> self.text.delete(1.0, END)
> fd = open(self.filename)
> for line in fd.readlines():
> l=l+1
> self.text.insert(END, line)
> fd.close()
> elif plat=="linux-i386":
> l=1
> self.filename = askopenfilename()
> if self.filename:
> self.text.delete(1.0, END)
> fd = open(self.filename)
> for line in fd.readlines():
> l=l+1
> self.text.insert(END, line) # self.text.insert(END, line[:-1])
> fd.close()
> -----------
>
> 2° One more thing, I'd like to add syntax highlighting with braces,
> parentheses,.... matching.
> I'd like to know it is feasible to implement it.
>
> 3° Is there a way to fire up an external application (like POV or a
> modeler) in background or as a sub-thread :
> When I start POV from within the application, I have to wait for the
> raytracing to be over to use the editor again.
>
> I use
> os.system("application_to_run")
>
> Thanks for any help
More information about the Python-list
mailing list