From 5384d9a964e31a0697439716db6b4064c4b7dd4a Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Wed, 21 Feb 2024 16:56:53 -0500 Subject: [PATCH] Save color in conf --- src/painter.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/painter.py b/src/painter.py index e116bd4..161b1b9 100644 --- a/src/painter.py +++ b/src/painter.py @@ -475,6 +475,7 @@ class Painter(Widget): else: ff.write("%shape=disk\n") ff.write("%zoom={:1.1f}\n".format(self.base_size/50)) + ff.write("%color={:d},{:d},{:d}\n".format(self.color[0],self.color[1],self.color[2])) if self.lattice != None: ff.write("%lattice="+self.lattice.type+':'+str(self.lattice.spacing)+"\n") for particle in self.particles: @@ -518,19 +519,28 @@ class Painter(Widget): # read options if line[0]=='%': + # ignore empty line + if len(line)==1: + continue [key,val]=line[1:].split('=',1) if key=="shape": self.app.command_prompt.run_set_shape(["set","shape",val]) elif key=="zoom": self.app.command_prompt.run_set_zoom(["set","zoom",val]) + elif key=="color": + color_str=val.split(',') + try: + self.set_color((float(color_str[0]),float(color_str[1]),float(color_str[2]))) + except: + print("warning: ignoring line "+str(i)+" in file '"+file+"': color '"+color_str+"' cannot be read",file=sys.stderr) continue entries=line.split(";") # skip line if improperly formatted if len(entries)>3: - print("warning: ignoring line "+str(i)+" in file '"+file+"': more than three ';' spearated entries in '"+line+"'",file=sys.stderr) + print("warning: ignoring line "+str(i)+" in file '"+file+"': more than three ';' separated entries in '"+line+"'",file=sys.stderr) if len(entries)<2: - print("warning: ignoring line "+str(i)+" in file '"+file+"': fewer than two ';' spearated entries in '"+line+"'",file=sys.stderr) + print("warning: ignoring line "+str(i)+" in file '"+file+"': fewer than two ';' separated entries in '"+line+"'",file=sys.stderr) continue # position