def GetEditor(parent, model, filename=None): """ """ path = os.path.join(model.model_path, ZipManager.Zip.GetPluginFile(model.model_path)) if not filename else filename name = os.path.basename(path) ### editor frame for the text of plug-ins editorFrame = Editor.GetEditor(None, \ wx.ID_ANY, \ _("%s - Plug-ins Editor")%os.path.basename(model.model_path), \ model, \ file_type = 'block') editorFrame.AddEditPage(name, path) return editorFrame
def OnEdit(self, event): """ """ index = self.currentItem path = self.GetPath(index) if self.IsSelected(index) and path and path.endswith('.py'): name = os.path.basename(path) module = self.GetPyData(index)[0] ### editor frame for the text of plug-ins editorFrame = Editor.GetEditor(None, \ wx.NewIdRef(), \ _("%s - Plug-ins Editor")%name, \ module, \ file_type = 'block') editorFrame.AddEditPage(name, path) editorFrame.Show() ### for .pyc file else: pass
def OnEdit(self, event): """ """ for i in range(self.GetItemCount()): module = self.GetPyData(i)[0] if self.IsSelected(i) and module: path = module.__file__ if path.endswith('.py'): name = os.path.basename(path) ### editor frame for the text of plug-ins editorFrame = Editor.GetEditor(None, \ wx.NewIdRef(), \ _("%s - Plug-ins Editor")%name, \ module, \ file_type = 'block') editorFrame.AddEditPage(name, path) editorFrame.Show() ### for .pyc file else: pass
def OnStrategies(event): ''' Event Handler for the strategies definition ''' global shape #obj = event.GetEventObject() #canvas = obj.GetParent() ### .amd file amd = zipfile.ZipFile(shape.model_path, 'a') ### test if strategies file is zipped if 'strategies.py' not in amd.namelist(): try: amd.writestr(zipfile.ZipInfo('strategies.py'), '') finally: amd.close() else: amd.close() editorFrame = Editor.GetEditor(None, wx.ID_ANY, _('Strategies definition')) editorFrame.AddEditPage("Strategies",os.path.join(shape.model_path, 'strategies.py')) editorFrame.Show()
def OnEditor(self, event): """ Method that edit the python code of associated devs model of the Block """ from Container import ShapeCanvas python_path = self.python_path model_path = os.path.dirname(python_path) name = os.path.basename(python_path) ### trying to get parent window mainW = GetActiveWindow(event) if isinstance(mainW, ShapeCanvas): mainW = mainW.GetParent() if __builtin__.__dict__['LOCAL_EDITOR'] and not zipfile.is_zipfile(model_path) and not python_path.startswith('http'): dial = wx.MessageDialog(mainW, _('Do you want to use your local programmer software?\n\n If you always want use the DEVSimPy code editor\n change the option in Editor panel preferences.'), name, wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) val = dial.ShowModal() else: val = wx.ID_NO ### if local editor if val == wx.ID_YES: ### open with local editor if wx.Platform == '__WXMAC__': os.system("open " + python_path) elif "wxMSW" in wx.PlatformInfo: os.startfile(python_path) elif "wxGTK" in wx.PlatformInfo: ### with gnome if os.system('pidof gnome-session') != 256: try: soft = which('gnome-open') except: sys.stdout.write(_("Local programmer software not found!\n")) else: os.system(soft+" openURL " + python_path) ### with kde elif os.system('pidof ksmserver') != 256: try: soft = which('kfmclient') except: sys.stdout.write(_("Local programmer software not found!\n")) else: os.system(soft+" openURL " + python_path) else: sys.stdout.write(_("Unknown Windows Manager!\n")) elif val != wx.ID_CANCEL: # loading file in editor windows (self.text) try: editorFrame = Editor.GetEditor(None, wx.ID_ANY, name, obj=self, file_type='block') # if zipfile.is_zipfile(model_path): # importer = zipimport.zipimporter(model_path) # text = importer.get_source(os.path.splitext(name)[0]) if not zipfile.is_zipfile(model_path): ### if file is localized on the net if python_path.startswith('http'): ### with internet python file, the editorFrame is read only editorFrame.SetReadOnly(True) printOnStatusBar(editorFrame.statusbar, {0:_('read only')}) ### parse url to extract the path(/devsimpy/domain...) and the network location (lcapocchi.free.fr) o = urlparse(python_path) ### open connection c = httplib.HTTPConnection(o.netloc) ### request with GET mode c.request('GET', o.path) ### get response of request r = c.getresponse() ### convert file into string text = r.read() else: ### if python_path is not found (because have an external origin) if not os.path.exists(python_path): if os.path.basename(DOMAIN_PATH) in python_path.split(os.sep): python_path = os.path.join(HOME_PATH, python_path[python_path.index(os.path.basename(DOMAIN_PATH)):].strip('[]')) self.python_path = python_path # ### only with python 2.6 # with codecs.open(python_path, 'r', 'utf-8') as f: # text = f.read() name = os.path.basename(python_path) editorFrame.AddEditPage(name, python_path) editorFrame.Show() printOnStatusBar(editorFrame.statusbar,{1:''}) return editorFrame except Exception, info: dlg = wx.MessageDialog(mainW, _('Editor frame not instanciated: %s\n'%info), name, wx.OK|wx.ICON_ERROR) dlg.ShowModal() return False