def OpenFlame(self, path): if self.tree.flamefiles: if path == self.tree.GetFilePath(): # File is already open dlg = wx.MessageDialog( self, "%s is already open. Do you want to revert to its saved status?" % path, 'Fr0st', wx.YES_NO | wx.CANCEL) if dlg.ShowModal() != wx.ID_YES: return elif self.tree.CheckForChanges() == wx.ID_CANCEL: # User cancelled when prompted to save changes. return # Parent needs to be selected to avoid a possible indexerror when # reducing the size of the tree. self.tree.SelectItem(self.tree.itemparent) if os.path.exists(path): # scan the file to see if it's valid flamestrings = fr0stlib.load_flamestrings(path) if not flamestrings: ErrorMessage( self, "%s is not a valid flame file." " Please choose a different file." % path) self.OnFlameOpen(None) return else: flamestrings = (self.MakeFlame().to_string(), ) # Add flames to the tree item = self.tree.SetFlames(path, *flamestrings) self.fh.AddFileToHistory(path) config["flamepath"] = path
def OpenFlame(self, path): if self.tree.flamefiles: if path == self.tree.GetFilePath(): # File is already open dlg = wx.MessageDialog(self, "%s is already open. Do you want to revert to its saved status?" % path, 'Fr0st',wx.YES_NO|wx.CANCEL) if dlg.ShowModal() != wx.ID_YES: return elif self.tree.CheckForChanges() == wx.ID_CANCEL: # User cancelled when prompted to save changes. return # Parent needs to be selected to avoid a possible indexerror when # reducing the size of the tree. self.tree.SelectItem(self.tree.itemparent) if os.path.exists(path): # scan the file to see if it's valid flamestrings = fr0stlib.load_flamestrings(path) if not flamestrings: ErrorMessage(self, "%s is not a valid flame file." " Please choose a different file." % path) self.OnFlameOpen(None) return else: flamestrings = (self.MakeFlame().to_string(),) # Add flames to the tree item = self.tree.SetFlames(path, *flamestrings) self.fh.AddFileToHistory(path) config["flamepath"] = path
def parse_file(self, path): if not os.path.exists(path): return ext = os.path.splitext(path)[1] if ext in (".flame", ".bak"): return ((re.search(' name="(.*?)"', string).group(1), Palette(etree.fromstring(string))) for string in load_flamestrings(path)) elif ext == ".map": with open(path,'r') as mf: lns = mf.readlines() # Each string in the list contains three ints # but possibly other stuff, so just take the first # three values data = [map(float, s.split()[0:3]) for s in lns] if len(data) != 256: raise ParsingError('Wrong number of palette entries specified: ' '%s != %s' % (256, len(lst))) p = Palette() p.data[:] = data return ((os.path.splitext(os.path.basename(path))[0], p),) elif ext == ".ugr": return list(_load_ugr_iter(path)) elif ext == ".xml": return list(_load_xml_iter(path))
def OnFlameSaveAs(self, e): path = self.tree.GetFilePath() flame = self.flame dlg = SaveDialog(self, path=path, name=flame.name) if dlg.ShowModal() == wx.ID_OK: newpath = dlg.GetPath() if IsInvalidPath(self, newpath): return flame.name = str(dlg.GetName()) if path == newpath: self.OnFlameNew(flame=flame) else: if os.path.exists(newpath): lst = fr0stlib.load_flamestrings(newpath) else: lst = [] lst.append(flame.to_string()) save_flames(newpath, *lst) dlg.Destroy()
def OnFlameSaveAs(self,e): path = self.tree.GetFilePath() flame = self.flame dlg = SaveDialog(self, path=path, name=flame.name) if dlg.ShowModal() == wx.ID_OK: newpath = dlg.GetPath() if IsInvalidPath(self, newpath): return flame.name = str(dlg.GetName()) if path == newpath: self.OnFlameNew(flame=flame) else: if os.path.exists(newpath): lst = fr0stlib.load_flamestrings(newpath) else: lst = [] lst.append(flame.to_string()) save_flames(newpath, *lst) dlg.Destroy()