Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
    def __init__(self, parent, ID):
        wx.TreeCtrl.__init__(self, parent, ID, size=wx.Size(-1,-1),
                             style=wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_FULL_ROW_HIGHLIGHT)
        
        self._d_imgs = wx.ImageList(16,16)
        self._bmp_class = self._d_imgs.Add( getArchiveBitmap() )
        self._bmp_class_open = self._d_imgs.Add( getArchiveBitmap() )
        self._bmp_module = self._d_imgs.Add( getPythonBitmap() )
        self.SetImageList(self._d_imgs)

        self._d_model = Model()
        self._d_controller = Controller()
        self._d_mainframe = self._d_controller.getMainFrame()

        self._d_root = self.AddRoot("root")
        self.SetPyData(self._d_root, (None,None))
        self._logger = self._d_controller.getLogger()


        #Add all archives:
        archives = self._d_model.openURI("zip://")
        for archive_uri in archives:
            uri_list = self._d_model.openURI(archive_uri)
            archive_name = getArchive(archive_uri)
            arch_item = self.AppendItem(self._d_root, archive_name)
            self.SetPyData(arch_item, ("Archive", archive_uri) )
            self.SetItemImage(arch_item, self._bmp_class, wx.TreeItemIcon_Normal)
            self.SetItemImage(arch_item, self._bmp_class_open, wx.TreeItemIcon_Expanded)

            for file_uri in uri_list:
                file_name = getPyFile(file_uri)
                file_item = self.AppendItem(arch_item, file_name)
                self.SetPyData(file_item, ("File", file_uri))
                self.SetItemImage(file_item, self._bmp_module, wx.TreeItemIcon_Normal)
                self.SetItemImage(file_item, self._bmp_module, wx.TreeItemIcon_Expanded)
        
        # FIXME self._d_mainframe.bindNewArch(self.NewArchive)

        # Events:
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelection)
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate)
        self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
Exemplo n.º 4
0
 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)