#! /usr/bin/env python # -*- coding: ISO-8859-1 -*- try: import psyco psyco.full() except: pass import wx import wx.stc as stc import os,sys,popen2,time from kws import * from IDS import * import select import locale import stat #import string wxpyvon_dir = os.path.join(os.getcwd(), sys.argv[0]) thisDir = os.path.normpath(os.path.dirname(wxpyvon_dir)) InsertDir = os.path.join(thisDir, 'Insert') homedir = os.path.expanduser('~') wxpyvon_root = homedir+"/.wxpyvon" try: os.mkdir(wxpyvon_root) except: pass # test if kde is used or not test_window_mgr=os.read(popen2.Popen4("env | grep -i kde").fromchild.fileno(),os.O_NONBLOCK) if test_window_mgr.rfind("kde")!=-1:Windows_MGR="kde" else:Windows_MGR="unknown" """ file_params : 0 = EDITOR index 1 = file_name" ie "02.pov", 2 = path to file ie /home/fabien 3 = saved status ie 0 or 1 4 = render status ie 0 or 1 5 = PID number ie 0 or 1 6 = paused status ie 0 or 1 """ home_dir = os.path.expanduser('~') #global current_tab file_types = "PovRay files (*.pov)|*.pov|"\ "Include files (*.inc)|*.inc|" \ "All files (*.*)|*.*" file_params=[] file_params = ["", \ "", \ home_dir, \ 0, \ 0, \ 0, \ 0] Files_Index=[] Files_Index.append(file_params) # ============================================================================ # PLATFORM INDEPENDENCY DECLARATIONS # ============================================================================ #TODO # set automatic margin width for line numbers : self.SetMarginWidth(1,40) -> utiliser GetNumberOfLines(self) # problem with directive not recognized # utiliser un flush pour fin de pipe en rendu faces = { 'times': 'Arial', 'mono' : 'Courier', 'helv' : 'Helvetica', 'other': 'new century schoolbook', 'size' : 12, 'size2': 12, } global ID_NUM_INSERT ID_NUM_INSERT=3000 all_keywords.sort() strings_keywords =" ".join(all_keywords) class Editor(stc.StyledTextCtrl): def __init__(self, parent, ID): stc.StyledTextCtrl.__init__(self, parent, ID,style = wx.NO_FULL_REPAINT_ON_RESIZE) # set up lexer and keywords type self.SetLexer(stc.STC_LEX_POV) self.SetKeyWords(1, " ".join(words)) # keywords self.SetKeyWords(2, " ".join(objbolds)) self.SetKeyWords(3, " ".join(patterns)) self.SetKeyWords(4, " ".join(directives)) self.UsePopUp(1) #self.SetMarginType(1, wx.stc.STC_MARGIN_SYMBOL) # margin settings self.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER) self.SetMarginWidth(0,40) self.SetMarginWidth(1,0) #zoom in and out of the Editor ( CTRL b or N ) #self.CmdKeyAssign(ord('+'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) #self.CmdKeyAssign(ord('+'), stc.STC_SCMOD_CTRL, self.Zoom_in) #self.CmdKeyAssign(ord('-'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT) self.StyleClearAll() # Global default styles for all languages self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(times)s,size:%(size)d" % faces) # ECLIPSE styles # Default self.StyleSetSpec(stc.STC_POV_DEFAULT, "fore:#0000FF,face:%(times)s,size:%(size)d" % faces) # comments self.StyleSetSpec(stc.STC_POV_COMMENTLINE, "fore:#008200,face:%(times)s,size:%(size)d" % faces) # multilinecomments self.StyleSetSpec(stc.STC_POV_COMMENT, "fore:#008200,face:%(times)s,size:%(size)d" % faces) # keywords self.StyleSetSpec(stc.STC_POV_WORD2, "fore:#840084,face:%(times)s,size:%(size)d" % faces) # bold keywords self.StyleSetSpec(stc.STC_POV_WORD3, "fore:#5D00A4,face:%(times)s,bold,size:%(size)d" % faces) # patterns self.StyleSetSpec(stc.STC_POV_WORD4, "fore:#895511,face:%(times)s,bold,size:%(size)d" % faces) # directives self.StyleSetSpec(stc.STC_POV_WORD5, "fore:#753B93,face:%(times)s,bold,size:%(size)d" % faces) # baddirectives self.StyleSetSpec(stc.STC_POV_BADDIRECTIVE, "fore:#753B93,face:%(times)s,bold,size:%(size)d" % faces) # numbers and opertors self.StyleSetSpec(stc.STC_POV_NUMBER, "fore:#008284,face:%(times)s,size:%(size)d" % faces) # strings self.StyleSetSpec(stc.STC_POV_STRING, "fore:#FF0000,face:%(times)s,size:%(size)d" % faces) # braces self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, #self.StyleSetSpec(stc.STC_POV_OPERATOR, "fore:#FF000F,back:#F4F400,face:%(times)s,size:%(size)d" % faces) # removes braces self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, #self.StyleSetSpec(stc.STC_POV_OPERATOR, "fore:#000000,back:#FFFFFF,face:%(times)s,size:%(size)d" % faces) # braces POVRAY #self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, self.StyleSetSpec(stc.STC_POV_OPERATOR, "fore:#000000,back:#FFFFFF,face:%(times)s,size:%(size)d" % faces) class MyFrame(wx.Frame): def __init__(self, parent, ID, title): wx.Frame.__init__(self, parent, ID, title) self.SetIcon(wx.Icon('povray.png', wx.BITMAP_TYPE_PNG)) #self.ShowFullScreen(self) self.current_tab=0 def MenuInsertFunc(self,dirname,menu_level): listeobjets = os.listdir(dirname) for x in listeobjets: longname = os.path.join(dirname,x) (shortname, extension) = os.path.splitext(x) if os.path.isdir(longname) : submenuname = shortname submenuname = wx.Menu() menu_level.AppendMenu(203, shortname, submenuname) #menu_insert_popup.add_cascade(label=x,menu=menu1) MenuInsertFunc(self,longname,submenuname) if os.path.isfile(longname) : menu_level.AppendMenu(3000,shortname,None) filemenu = wx.Menu() filemenu.Append(ID_NEW, "&New\tCTRL+N","CTRL+N") filemenu.Append(ID_OPEN, "&Open\tCTRL+O","CTRL+O") self.Bind(wx.EVT_MENU, self.open_file, id=ID_OPEN) filemenu.AppendSeparator() filemenu.Append(ID_SAVE, "&Save\tCTRL+S","CTRL+S") self.Bind(wx.EVT_MENU, self.save_file, id=ID_SAVE) filemenu.Append(ID_SAVE_AS, "Save &As","--") self.Bind(wx.EVT_MENU, self.save_file_as, id=ID_SAVE_AS) filemenu.AppendSeparator() filemenu.Append(ID_CLOSE, "&Close","--") filemenu.Append(ID_CLOSE_ALL, "Close A&ll","--") filemenu.AppendSeparator() filemenu.Append(ID_EXIT, "E&xit","CTRL q") editmenu = wx.Menu() editmenu.Append(ID_UNDO, "&Undo","CTRL Z") editmenu.Append(ID_REDO, "&Redo","CTRL Y") editmenu.AppendSeparator() editmenu.Append(ID_CUT, "C&ut","CTRL X") editmenu.Append(ID_COPY, "&Copy","CTRL C") editmenu.Append(ID_PASTE, "&Paste","CTRL V") editmenu.Append(ID_SELECT_ALL, "Select &All","CTRL A") editmenu.AppendSeparator() editmenu.Append(ID_FIND, "&Find","CTRL F") editmenu.Append(ID_REPLACE, "&Replace","CTRL H") insertmenu = wx.Menu() MenuInsertFunc(self,InsertDir,insertmenu) optionsmenu = wx.Menu() # menu2 optionsmenu.Append(ID_POV_OPTIONS,"&Pov-Ray Options") #Save before rendering submenu self.submenu_S_B_R = wx.Menu() self.submenu_S_B_R.Append(ID_S_B_R_Y,"Yes","",wx.ITEM_RADIO) self.submenu_S_B_R.Append(ID_S_B_R_N,"No","",wx.ITEM_RADIO) optionsmenu.AppendMenu(ID_S_B_R,"&Save Before Render",self.submenu_S_B_R) #keep on top submenu self.submenu_K_O_T = wx.Menu() self.submenu_K_O_T.Append(ID_KEEP_ON_TOP_YES,"Yes","",wx.ITEM_RADIO) self.submenu_K_O_T.Append(ID_KEEP_ON_TOP_NO,"No","",wx.ITEM_RADIO) optionsmenu.AppendMenu(ID_KEEP_ON_TOP,"&Render window on top",self.submenu_K_O_T) optionsmenu.Append(ID_FONT_COLORS,"&Fonts and Colors") optionsmenu.Append(ID_ZOOM_IN,"Zoom &In\tCTRL++","Zoom In") self.Bind(wx.EVT_MENU, self.Zoom_in, id=ID_ZOOM_IN) optionsmenu.Append(ID_ZOOM_OUT,"Zoom &Out\tCTRL+-","Zoom Out") self.Bind(wx.EVT_MENU, self.Zoom_out, id=ID_ZOOM_OUT) menubar = wx.MenuBar() menubar.Append(filemenu,"&File") menubar.Append(editmenu,"&Edit") menubar.Append(insertmenu,"&Insert") menubar.Append(optionsmenu,"&Options") self.SetMenuBar(menubar) self.CreateStatusBar() S_button_box = wx.BoxSizer(wx.HORIZONTAL) # * * * * * * * * Assign pictures to buttons self.png_new=wx.Bitmap("new.png", wx.BITMAP_TYPE_PNG) self.png_open=wx.Bitmap("open.png", wx.BITMAP_TYPE_PNG) self.png_save=wx.Bitmap("save.png", wx.BITMAP_TYPE_PNG) self.png_close=wx.Bitmap("close.png", wx.BITMAP_TYPE_PNG) self.png_render=wx.Bitmap("render.png", wx.BITMAP_TYPE_PNG) self.png_stop=wx.Bitmap("stop.png", wx.BITMAP_TYPE_PNG) self.png_pause=wx.Bitmap("pause.png", wx.BITMAP_TYPE_PNG) self.png_resume=wx.Bitmap("resume.png", wx.BITMAP_TYPE_PNG) self.png_view_plus = wx.Bitmap("viewmag+.png", wx.BITMAP_TYPE_PNG) self.png_view_moins = wx.Bitmap("viewmag-.png", wx.BITMAP_TYPE_PNG) # * * * * * * * * Creation of buttons self.btn_NEW = wx.BitmapButton(self,wx.ID_ANY,self.png_new ,None, (50, 50)) self.btn_OPEN = wx.BitmapButton(self,wx.ID_ANY,self.png_open ,None, (50, 50)) self.btn_SAVE = wx.BitmapButton(self,wx.ID_ANY,self.png_save ,None, (50, 50)) self.btn_CLOSE = wx.BitmapButton(self,wx.ID_ANY,self.png_close ,None, (50, 50)) self.btn_RENDER = wx.BitmapButton(self,wx.ID_ANY,self.png_render ,None, (50, 50)) self.btn_PAUSE = wx.BitmapButton(self,wx.ID_ANY,self.png_pause ,None, (50, 50)) self.btn_VIEW_PLUS = wx.BitmapButton(self,wx.ID_ANY,self.png_view_plus ,None, (50, 50)) self.btn_VIEW_MOINS = wx.BitmapButton(self,wx.ID_ANY,self.png_view_moins ,None, (50, 50)) # * * * * * * * * Predefind resolutions box_Resol = wx.StaticBox(self, -1, "Resolutions") S_box_Resol = wx.StaticBoxSizer(box_Resol, wx.VERTICAL ) choices = [ '320x240', '640x480', '800x600', '1024x768', '1280x1024' ] self._combo_resol = wx.ComboBox(self, 500, "320x240",(0,0), (100, 40), choices, wx.CB_DROPDOWN | wx.CB_READONLY) S_box_Resol.Add(self._combo_resol,0, wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 10) # * * * * * * * * Qualitiy settings box_Quality = wx.StaticBox(self, -1, "Quality") S_box_Quality = wx.StaticBoxSizer(box_Quality, wx.VERTICAL ) self._slider = wx.Slider(self,-1, 9, 0, 9,size=(100, 40), style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS) S_box_Quality.Add(self._slider, 0, wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 10) # * * * * * * * * Fast preview box_Preview = wx.StaticBox(self, -1, "Fast preview") S_box_Preview = wx.StaticBoxSizer(box_Preview, wx.VERTICAL ) self._fast_preview = wx.CheckBox(self, -1 ,size=(100,50)) S_box_Preview.Add(self._fast_preview, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL,10 ) # * * * * * * * * Bind actions to buttons self.Bind(wx.EVT_BUTTON, self.new, self.btn_NEW) self.Bind(wx.EVT_BUTTON, self.open_file, self.btn_OPEN) self.Bind(wx.EVT_BUTTON, self.save_file, self.btn_SAVE) self.Bind(wx.EVT_BUTTON, self.close_file, self.btn_CLOSE) self.Bind(wx.EVT_BUTTON, self.render, self.btn_RENDER) self.Bind(wx.EVT_BUTTON, self.pause_resume, self.btn_PAUSE) self.Bind(wx.EVT_BUTTON, self.Zoom_in, self.btn_VIEW_PLUS) self.Bind(wx.EVT_BUTTON, self.Zoom_out, self.btn_VIEW_MOINS) # self.Bind(wx.EVT_COMBOBOX, self.Resol_choice, self._combo_resol) # * * * * * * * * Add buttons to layout S_button_box.Add(self.btn_NEW, 0, wx.SHAPED) S_button_box.Add(self.btn_OPEN, 0, wx.SHAPED) S_button_box.Add(self.btn_SAVE, 0, wx.SHAPED) S_button_box.Add(self.btn_CLOSE, 0, wx.SHAPED) S_button_box.Add(self.btn_RENDER, 0, wx.SHAPED) S_button_box.Add(self.btn_PAUSE, 0, wx.SHAPED) S_button_box.Add(S_box_Resol, 0, wx.SHAPED) S_button_box.Add(S_box_Quality, 0, wx.SHAPED) S_button_box.Add(S_box_Preview, 0, wx.SHAPED) S_button_box.Add(self.btn_VIEW_PLUS, 0, wx.SHAPED) S_button_box.Add(self.btn_VIEW_MOINS, 0, wx.SHAPED) #self.layout_button_box.Add(btn_OPEN, 0, wx.SHAPED) #s.Add(btn1, 0, wx.SHAPED) # line of parameters S_parameters_line = wx.BoxSizer(wx.HORIZONTAL) parameters_line_label = wx.StaticText(self, -1, "Parameters :") self.parameters_line_entry = wx.TextCtrl(self, -1, "") S_parameters_line.Add(parameters_line_label,0 , wx.SHAPED | wx.ALIGN_CENTER_VERTICAL ) S_parameters_line.Add(self.parameters_line_entry,1) # self._Splitter_Hor self._Splitter_Hor = wx.SplitterWindow(self, wx.ID_ANY, style = wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D) self._Splitter_Hor.SetMinimumPaneSize(160) # notebook -> editor self._notebook = wx.Notebook( self._Splitter_Hor, wx.ID_ANY, style = wx.TAB_TRAVERSAL) self.Bind(wx.EVT_BUTTON, self.Zoom_out, self.btn_VIEW_MOINS) self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED , self.page_change, self._notebook) Files_Index[0][0] = Editor(self._notebook, wx.ID_ANY) self._notebook.AddPage(Files_Index[0][0],Files_Index[self.current_tab][1]) self._Splitter_Ver = wx.SplitterWindow(self._Splitter_Hor, wx.ID_ANY, style = wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D) Panel_stats = wx.Panel(self._Splitter_Ver,-1) Stats_label = wx.StaticText(Panel_stats, -1, "STATS :") Stats_label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) #Stats_label.SetColor('#0000FF') self.stats = wx.TextCtrl(Panel_stats, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.BORDER_SUNKEN ) S_Panel_stats = wx.BoxSizer(wx.VERTICAL) S_Panel_stats.Add(Stats_label,0,wx.EXPAND) S_Panel_stats.Add(self.stats,1,wx.EXPAND) Panel_stats.SetSizer(S_Panel_stats) Panel_stats.SetAutoLayout(True) Panel_errors = wx.Panel(self._Splitter_Ver,-1) Errors_label = wx.StaticText(Panel_errors, -1, "ERRORS :") Errors_label .SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) self.errors = wx.TextCtrl(Panel_errors, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.BORDER_SUNKEN ) S_Panel_errors = wx.BoxSizer(wx.VERTICAL) S_Panel_errors.Add(Errors_label,0,wx.EXPAND) S_Panel_errors.Add(self.errors,1,wx.EXPAND) Panel_errors.SetSizer(S_Panel_errors) Panel_errors.SetAutoLayout(True) self._Splitter_Ver.SplitVertically(Panel_stats, Panel_errors) #self._Splitter_Ver.SetSashPosition(1024, True) # couleur de fond #self.stats.SetBackgroundColour("#FBECB7") self._Splitter_Hor.SplitHorizontally(self._notebook, self._Splitter_Ver) self._Splitter_Hor.SetSashPosition(1024, True) #self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUi, Files_Index[self.current_tab][0]) #self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUi, Files_Index[self.current_tab][0]) S_total = wx.BoxSizer(wx.VERTICAL) S_total.Add(S_button_box,0,wx.EXPAND) S_total.Add(S_parameters_line,0,wx.EXPAND) S_total.Add(self._Splitter_Hor,1,wx.EXPAND) # S_total.Add(self._Splitter_Ver,1,wx.EXPAND) S_total.SetMinSize((800,600)) self.SetSizer(S_total) S_total.Fit(self) #self._Splitter_Hor.SetSizeHints(-1,-1,-1,-1) #self.SetAutoLayout(1) # utile ? #self.Show(True) #Files_Index[self.current_tab].SetCodePage(65001) self.page_change(None) #text.index(INSERT).split('.', 1) # cb = event.GetEventObject() # print cb.GetString(cb.GetSelection()) # #print self._combo_resol def Zoom_in(self,event): Files_Index[self.current_tab][0].SetZoom(Files_Index[self.current_tab][0].GetZoom()+1) #-10 -> +20 def Zoom_out(self,event): Files_Index[self.current_tab][0].SetZoom(Files_Index[self.current_tab][0].GetZoom()-1) #-10 -> +20 def page_change(self,event): self.Refresh() self.current_tab=self._notebook.GetSelection() #Files_Index[self.current_tab][0].SetFocus() #Files_Index[0][0] # print '7',Files_Index[self.current_tab][0] # print '88',Files_Index[self.current_tab][1] #self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUi, Files_Index[self.current_tab][0]) #self.Bind(stc.EVT_STC_CHARADDED, self.OnCharacterAdded, Files_Index[self.current_tab][0]) self.Bind(stc.EVT_STC_MODIFIED, self.OnUpdateUi, Files_Index[self.current_tab][0]) def open_file(self, event): dlg = wx.FileDialog( self, style=wx.OPEN | wx.FILE_MUST_EXIST | wx.CHANGE_DIR | wx.HIDE_READONLY ,wildcard=file_types ) dlg.ShowModal() self.filename=dlg.GetFilename() self.dirname=dlg.GetDirectory() try: f=open(os.path.join(self.dirname, self.filename),'r') # if current text is empty if Files_Index[self.current_tab][0].GetText()=="" \ and Files_Index[self.current_tab][1]=="": Files_Index[self.current_tab][1]=dlg.GetFilename() Files_Index[self.current_tab][2]=dlg.GetDirectory() self._notebook.SetPageText(self.current_tab,dlg.GetFilename()) else: self.current_tab=self.current_tab+1 file_params = ["","","",0,0,0,0] Files_Index.append(file_params) Files_Index[self.current_tab][1]=dlg.GetFilename() Files_Index[self.current_tab][2]=dlg.GetDirectory() Files_Index[self.current_tab][0] = Editor(self._notebook, wx.ID_ANY) self._notebook.AddPage(Files_Index[self.current_tab][0], Files_Index[self.current_tab][1]) #wx.CallAfter(Files_Index[self.current_tab][0].SetFocus()) #wx.FutureCall(1000, Files_Index[self.current_tab][0].SetFocus) self._notebook.SetSelection(self.current_tab) Files_Index[self.current_tab][0].InsertText(0,unicode(f.read(),locale.getpreferredencoding())) Files_Index[self.current_tab][1]=dlg.GetFilename() Files_Index[self.current_tab][2]=dlg.GetDirectory() except: pass def new(self, event): self._notebook.AddPage(Files_Index[self.current_tab], "page2") def save_file(self, event): if Files_Index[self.current_tab][1]=="": self.save_file_as(None) else: f=open(os.path.join(Files_Index[self.current_tab][2], Files_Index[self.current_tab][1]),'w') # print Files_Index[self.current_tab][0].GetText() f.write(Files_Index[self.current_tab][0].GetText()) f.close Files_Index[self.current_tab][3]=1 self._notebook.SetPageText(self.current_tab,Files_Index[self.current_tab][1]) def save_file_as(self, event): dlg = wx.FileDialog( self, style=wx.SAVE | wx.OVERWRITE_PROMPT | wx.CHANGE_DIR ,wildcard=file_types ) dlg.ShowModal() self.filename=dlg.GetFilename() self.dirname=dlg.GetDirectory() try: f=open(os.path.join(self.dirname, self.filename),'w') f.write(Files_Index[self.current_tab][0].GetText()) f.close self._notebook.SetPageText(self.current_tab,dlg.GetFilename()) Files_Index[self.current_tab][1]=dlg.GetFilename() Files_Index[self.current_tab][2]=dlg.GetDirectory() Files_Index[self.current_tab][3]=1 self._notebook.SetPageText(self.current_tab,Files_Index[self.current_tab][1]) except: pass def close_file(self,event): # if there is no words in the current tab and current filename = "" : is empty # and there is only one tab left if Files_Index[self.current_tab][0].GetText()=="" \ and Files_Index[self.current_tab][1]=="" \ and self._notebook.GetPageCount()==1: pass # if there is something in the tab, but the file is saved elif Files_Index[self.current_tab][0].GetText()!="" \ and Files_Index[self.current_tab][3]==1: Files_Index[self.current_tab][0].ClearAll() self._notebook.SetPageText(self.current_tab,"") file_params[1] = "" file_params[2] = "" file_params[3] = 0 file_params[4] = 0 file_params[5] = 0 file_params[6] = 0 Files_Index.append(file_params) self._notebook.SetSelection(self.current_tab) # prevent from destroying the last tab #if self._notebook.GetPageCount()>1: self._notebook.DeletePage(self.current_tab) #else: # pass del Files_Index[self.current_tab] # if there is something in the tab, but the file is not saved elif Files_Index[self.current_tab][0].GetText()!="" \ and Files_Index[self.current_tab][3]==0: dlg=wx.MessageBox("File not saved\nDo you want to save it\nbefore closing ?", "Warning", wx.YES_NO | wx.CANCEL, self)#.ShowModal() if dlg == wx.NO: Files_Index[self.current_tab][0].ClearAll() self._notebook.SetPageText(self.current_tab,"") elif dlg == wx.YES: self.save_file_as(None) else: pass else: pass def pause_resume(self, event): # stop : kill -19 if Files_Index[self.current_tab][6]==0: if Files_Index[self.current_tab][4]==1: os.kill(Files_Index[self.current_tab][5],19) Files_Index[self.current_tab][6]=1 self.btn_PAUSE.SetBitmapLabel(self.png_resume) self.timer.Stop() #resume : kill -18 elif Files_Index[self.current_tab][6]==1: os.kill(Files_Index[self.current_tab][5],18) Files_Index[self.current_tab][6]=0 self.btn_PAUSE.SetBitmapLabel(self.png_pause) self.timer.Start() def stop_render(self, event): os.kill(Files_Index[self.current_tab][5],9) Files_Index[self.current_tab][5]=0 Files_Index[self.current_tab][4]=0 self.btn_RENDER.SetBitmapLabel(self.png_render) self.btn_PAUSE.SetBitmapLabel(self.png_pause) self.timer.Stop() def render(self, event): """ check whether file should be saved before rendering or not """ if self.submenu_S_B_R.IsChecked(ID_S_B_R_Y):self.save_file(None) """ check whether render window is to be kept on top """ # print self.submenu_K_O_T.IsChecked(ID_KEEP_ON_TOP_YES) if self.submenu_K_O_T.IsChecked(ID_KEEP_ON_TOP_YES)==True and Windows_MGR=="kde":Keep_on_Top="kstart --ontop " else:Keep_on_Top="" f=open(os.path.join(wxpyvon_root, "err.txt"),'w') f.write("") f.close() self.errors.Clear() # print "statut : ",Files_Index[self.current_tab][4] if Files_Index[self.current_tab][4]==1: self.stop_render(None) else: # get resolution combobox value width_resol=self._combo_resol.GetValue().split("x",1)[0] height_resol=self._combo_resol.GetValue().split("x",1)[1] Combo_Resol="+w"+width_resol+" +h"+height_resol+" " #get fast preview yes or no if self._fast_preview.GetValue()==True:Fast_Preview="+sp64 +ep2 " else :Fast_Preview="" # get quality setting Quality_setting="+q"+str(self._slider.GetValue())+" " # print Keep_on_Top # add path to current directory Current_Dir="-l"+Files_Index[self.current_tab][2]+" " print Current_Dir #kstart --ontop file_to_render=Keep_on_Top+"povray Input_File_Name="+"\""+os.path.join(Files_Index[self.current_tab][2], \ Files_Index[self.current_tab][1]) total = file_to_render\ +"\" "\ +Combo_Resol\ +Fast_Preview\ +Quality_setting\ +Current_Dir\ +"+GF${HOME}/.wxpyvon/err.txt "\ +self.parameters_line_entry.GetValue() self.child = popen2.Popen4(total,1) print total wx.EVT_TIMER(self,-1,self.ecoute) self.timer = wx.Timer(self, -1) self.timer.Start(1000) self.PID= self.child.pid self.btn_RENDER.SetBitmapLabel(self.png_stop) Files_Index[self.current_tab][4]=1 Files_Index[self.current_tab][5]=self.PID # print Files_Index[self.current_tab][5] def error_found(self): if os.stat(os.path.join(wxpyvon_root, "err.txt"))[6]!=0: # print 'test' f=open(os.path.join(wxpyvon_root, "err.txt"),'r') err=f.read() self.errors.write(err) self.errors.SetInsertionPointEnd() self.timer.Stop() Files_Index[self.current_tab][4]=0 Files_Index[self.current_tab][5]=0 self.btn_RENDER.SetBitmapLabel(self.png_render) f.close() self.timer.Stop() def ecoute(self,event): self.error_found() if self.child.poll()==-1: procf=open('/proc/%d/status' % self.PID,'r') proc=procf.read() fd = self.child.fromchild.fileno() s_in,s_out,s_err= select.select([fd],[fd],[fd],0) line = "" if proc.rfind("renderning")!=-1: try: line = os.read(s_in[0],os.O_NONBLOCK) self.stats.write(line)#+'\r') self.stats.SetInsertionPointEnd() # print "(renderning)" except: pass elif proc.rfind("sleeping")!=-1: self.timer.Stop() self.btn_RENDER.SetBitmapLabel(self.png_render) Files_Index[self.current_tab][4]=0 # print "(sleeping)" procf.close() else: self.btn_RENDER.SetBitmapLabel(self.png_render) Files_Index[self.current_tab][4]=0 def OnCharacterAdded(self,event): Files_Index[self.current_tab][3]=0 self._notebook.SetPageText(self.current_tab,Files_Index[self.current_tab][1]+"*") def OnUpdateUi(self,event): self.Matching_operators() self.Matching_keywords() self.OnCharacterAdded(None) def Matching_operators(self): #print 'curr tab ',self.current_tab braceAtCaret = -1 braceOpposite = -1 charBefore = None caretPos = Files_Index[self.current_tab][0].GetCurrentPos() # caretPos= emplacement curseur #------print 'caretPos',caretPos if caretPos > 0: charBefore = Files_Index[self.current_tab][0].GetCharAt(caretPos - 1) styleBefore = Files_Index[self.current_tab][0].GetStyleAt(caretPos - 1) #print 'charavant',charBefore #print 'style',styleBefore #check before if charBefore and chr(charBefore) in "[]{}()<>" and styleBefore == wx.stc.STC_POV_OPERATOR: braceAtCaret = caretPos - 1 #check after if braceAtCaret < 0: self.charAfter = Files_Index[self.current_tab][0].GetCharAt(caretPos) #print 'ici', charAfter self.styleAfter = Files_Index[self.current_tab][0].GetStyleAt(caretPos) if self.charAfter and chr(self.charAfter) in "[]{}()<>" and self.styleAfter == wx.stc.STC_POV_OPERATOR: #print '// \\', charAfter,chr(charAfter) braceAtCaret = caretPos if braceAtCaret >= 0: braceOpposite = Files_Index[self.current_tab][0].BraceMatch(braceAtCaret) if braceAtCaret != -1 and braceOpposite == -1: Files_Index[self.current_tab][0].BraceBadLight(braceAtCaret) else: Files_Index[self.current_tab][0].BraceHighlight(braceAtCaret, braceOpposite) #print braceAtCaret,braceOpposite def Matching_keywords(self): pos_actu=Files_Index[self.current_tab][0].GetCurrentPos() #2 pos_depart=Files_Index[self.current_tab][0].WordStartPosition(pos_actu, 1) #2 # print Files_Index[self.current_tab][0].GetStyleAt(pos_actu),Files_Index[self.current_tab][0].GetStyleAt(pos_actu-1) if Files_Index[self.current_tab][0].GetStyleAt(pos_actu)==0: # and Files_Index[self.current_tab].GetStyleAt(pos_actu-1)==0: #2 if (pos_actu - pos_depart > 1):#3 #to_find=text.get(kw_loc_start,INSERT) to_find = Files_Index[self.current_tab][0].GetTextRange(pos_depart,pos_actu) #4 matching_keywords=[] #4 for i in all_keywords:#4 if i[0:len(to_find)]==to_find:#5 matching_keywords.append(i)#6 # print 'matchk',len(matching_keywords) # print "style at pos :",Files_Index[self.current_tab][0].GetStyleAt(pos_actu) if Files_Index[self.current_tab][0].GetStyleAt(pos_actu)==0 and len(matching_keywords)!=1: matching_keywords.sort()#5 matching_list_string = " ".join(matching_keywords)#5 Files_Index[self.current_tab][0].AutoCompSetAutoHide(1)#5 Files_Index[self.current_tab][0].AutoCompShow(pos_actu - pos_depart,matching_list_string)#5 else: pass app = wx.PySimpleApp() frame = MyFrame(None, -1, "WxPyvon") frame.Show() app.MainLoop()