def checkURI(self, uri): if isArchiveURI(uri): return uri in self._archive_list.keys() elif isPyFileURI(uri): (aname, fname) = splitPyFile(uri) try: archive = self._archive_list["zip://"+aname] except: return False return fname in archive.getFileList("*.py")
def addURI(self, uri): if self.getItemByURI(uri, self._d_root): return if isPyFileURI(uri): (ar, py) = splitPyFile(uri) item = self.getItemByURI("zip://"+ar, self._d_root) fitem = self.AppendItem(item, py) self.SetPyData(fitem, ("File", uri)) self.SetItemImage(fitem, self._bmp_module, wx.TreeItemIcon_Normal) self.SetItemImage(fitem, self._bmp_module, wx.TreeItemIcon_Expanded) elif isArchiveURI(uri): path = getArchive(uri) item = self.AppendItem(self._d_root, path) self.SetPyData(item, ("Archive",uri)) self.SetItemImage(item, self._bmp_class, wx.TreeItemIcon_Normal) self.SetItemImage(item, self._bmp_class_open, wx.TreeItemIcon_Expanded) else: raise Exception("Unkonw URI %s"%uri)
def deleteURI(self, uri): if isArchiveURI(uri): if not uri in self._archive_list.keys(): raise Exception("Unknown archive %s"%uri) aname = getArchive(uri) path = os.path.join(self._base_path, aname) os.unlink(path) del self._archive_list[uri] elif isPyFileURI(uri): (aname, fname) = splitPyFile(uri) if not "zip://"+aname in self._archive_list.keys(): raise Exception("Unknown archive zip://%s"%aname) archive = self._archive_list["zip://"+aname] if not fname in archive.getFileList("*.py"): raise Exception("Unknown file %s in zip://%s"%(fname, aname)) archive.deleteFile(fname) else: raise Exception("Invalid URI %s?"%uri)
def openURI(self, uri): # open "zip://" retunrs a list of all known zip files if uri == "zip://": return self._archive_list.keys() # open "zip://archive_name.zip" returns a list of pythonfiles of the # given archive elif uri in self._archive_list.keys(): archive = self._archive_list[uri] lst = archive.getFileList("*.py") for i in range(len(lst)): lst[i] = uri+"/"+lst[i] return lst # open "zip://archive-name.zip/path/to/python-file.py" returns the # content of the given python file. (aname, fname) = splitPyFile(uri) try: archive = self._archive_list["zip://"+aname] except: raise Exception("Archive zip://%s not known"%aname) return archive.readFile(fname)
def saveURI(self, uri, data=""): # save "zip://archive-name.zip" will creat a new archive if isArchiveURI(uri): if uri in self._archive_list.keys(): return archive = getArchive(uri) path = os.path.join(self._base_path, archive) ZipFile(path,"w") self._archive_list[uri] = eDevModelArchive(path) # save "zip://archive-name.zip/path/to/python-file.py creates a new # python file with given content or overrides existing ones elif isPyFileURI(uri): self._logger.debug("save pyfile %s"%uri) (aname, fname) = splitPyFile(uri) try: archive = self._archive_list["zip://"+aname] except: raise Exception("Archive zip://&s not found"%aname) if not fname in archive.getFileList("*.py"): archive.createFile(fname, data) else: archive.writeFile(fname, data) else: raise Exception("Unable to write %s: Invalid URI?"%uri)
def __init__(self, parent, ID, uri): stc.StyledTextCtrl.__init__(self, parent, ID, style=0) if uri == "zip://": modified = True title = "unsaved" else: modified = False (aname, title) = splitPyFile(uri) EditorInterface.__init__(self, parent, False, uri) self.setTitle(title) self._d_config = Config() self._d_controller = Controller() self._logger = self._d_controller.getLogger() self._d_mainframe = self._d_controller.getMainFrame() self._d_model = Model() self._d_notebook = self._d_controller.getNotebook() self._pyedit_component = ComponentManager().getComponent("pyeditor") self._archive_tree = self._pyedit_component.getArchiveTree() self.SetLexer(stc.STC_LEX_PYTHON) self.SetKeyWords(0, " ".join(keyword.kwlist)) # config: font = self._d_config.getEditorFont() fsize = self._d_config.getEditorFontSize() sdfsize = self._d_config.getEditorSecondFontSize() faces = {"times": font, "mono": font, "helv": font, "other": font, "size": fsize, "size2": sdfsize} self.SetTabWidth(self._d_config.getEditorTabSpace()) self.SetUseTabs(not self._d_config.getEditorExpandTab()) self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces) self.StyleClearAll() # Reset all to be like the default self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces) self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces) self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold") self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold") self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces) self.SetCaretForeground("BLUE") if isPyFileURI(uri): text = self._d_model.openURI(uri) else: text = "" self.SetText(text) self.EmptyUndoBuffer() self.Colourise(0, -1) self.Bind(stc.EVT_STC_CHANGE, self.OnModified)