import sys, os, string from string import split from os import spawnv, P_NOWAIT from Tkinter import * from tkFileDialog import askopenfilename, asksaveasfilename # remettre dans ligne de params les parametres # autosave avant render class mainWin: def __init__(self,tkRoot): self.tkRoot=tkRoot self.createWidgets() return None global params global filename plat=sys.platform class App: ## ---------------------- Create GUI ---------------------- def __init__(self, master): ## ---------------------- Mainframe ---------------------- mframe = Frame(master) # mframe.title(text"POV-RAY Editor") 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",command=self.saveas) 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..[Alt+g]", fg="red", command=self.render) 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("", self.keyPress) self.text.bind("", self.keyPress) self.text.bind("", self.render_kb) 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=NORMAL,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=1, fill=BOTH) ## ---------------------- Status Bar ---------------------- frame_status_bar=Frame(mframe) self.parameters = Label(frame_status_bar,text="Parameters : ", anchor="w",bg='gray70') self.parameters.pack(side='left') self.fill_params=Entry(frame_status_bar,bg='gray100') self.fill_params.insert(INSERT,"+w320 +h240 -f +dgt +p") self.fill_params.pack(side='left', expand=1, fill=BOTH) self.status_filename1 = Label(frame_status_bar,text="File : ",width=5, anchor="w",bg='gray70') self.status_filename1.pack(side=LEFT ) self.status_filename2 = Label(frame_status_bar,text="",width=20,relief=SUNKEN, anchor="w", bg="gray90") self.status_filename2.pack(side=LEFT) self.status_line = Label(frame_status_bar,padx=1, relief=SUNKEN,bg="gray90", width=10, anchor="w", textvariable=affi_Ligne) self.status_line.pack(side='right') self.status_linetext = Label(frame_status_bar,padx=1,bg='gray70', width=7, anchor="w", text="Line : ") self.status_linetext.pack(side='right') frame_status_bar.pack(side=LEFT,expand=1, fill='x') ## ---------------------- Open file ---------------------- def enter_text(self): filetypes = ( ( "Pov files","*.pov"), ( "Include files","*.inc"), ( "All","*")) self.filename = askopenfilename(filetypes=filetypes) if self.filename: self.text.delete(1.0, END) fd = open(self.filename) for line in fd.readlines(): if line.endswith("\r\n"): line = line[:-2] + "\n" self.text.insert(END, line) fd.close() self.status_filename2.config(text=os.path.split(self.filename)[1]) ## ---------------------- Clear ---------------------- def clr(self): self.text.delete(1.0, END) ## ---------------------- Save ---------------------- def save(self, forPrt=None): try: script = self.text.get(1.0, END) if script: fd = open(self.filename, 'w') for line in string.split(script, '\n'): fd.write(line) fd.write('\n') fd.close except: self.saveas() ## ---------------------- Saveas ---------------------- def saveas(self, forPrt=None): script = self.text.get(1.0, END) if script: # global filename # self.filename=".pov" self.filename = file = asksaveasfilename() fd = open(self.filename, 'w') for line in string.split(script, '\n'): fd.write(line) fd.write('\n') fd.close self.status_filename2.config(text=os.path.split(self.filename)[1]) ## ---------------------- Render button ---------------------- def render(self): global params params=self.fill_params.get() script = self.text.get(1.0, END) if script: fd = open(self.filename, 'w') for line in string.split(script, '\n'): fd.write(line) fd.write('\n') fd.close app = '/usr/bin/x-povray' # appli = split(app)[1] # os.spawnl(os.P_NOWAIT, app , params) # os.popen3(app +' '+params) # os.system("dir" +params+" > foo.txt 2>foo.error.txt") spawnv(P_NOWAIT, app , ('x-povray', "+i"+self.filename+" "+params)) ## ---------------------- Render keyboard ---------------------- def render_kb(self,event): global params params=self.fill_params.get() app = r"C:\perso\bureautique\Microsoft Office\Office\excel.exe" appli = split(app)[1] # os.spawnl(os.P_NOWAIT, app , params) # os.system(app +' '+params) # os.system(app) spawnv(P_NOWAIT, app, (appli, params)) ## ---------------------- Top-Level Command line button ---------------------- def parameters_button(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() ## ---------------------- Prints the current line number and contents ---------------------- def lin(self): tindex = self.text.index(INSERT) Ligne, column = map(int, string.split(tindex, ".")) valeur=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()