diff --git a/command_prompt.py b/command_prompt.py index 170c0cb..2b112e0 100644 --- a/command_prompt.py +++ b/command_prompt.py @@ -295,6 +295,11 @@ class Command_prompt(Label): # parse command line self.parse_argv() + # commands that cannot be compounded + if self.argv[0]=="set": + self.run_set(self.argv) + return + # single letter commands (which can be combined) # write if self.argv[0]=="w" or self.argv[0]=="w!" or self.argv[0]=="wq": @@ -306,7 +311,53 @@ class Command_prompt(Label): if self.argv[0]=="q" or self.argv=="wq": self.app.stop() - # wrie to file + # set properties of particles + def run_set(self,argv): + if len(argv)<3: + self.message="error: 'set' command was run with too few arguments -- usage: 'set '" + return + + if argv[1]=="color": + self.run_set_color(argv) + return + else: + self.message="error: unrecognized command '"+argv[1]+"'" + return + + def run_set_color(self,argv): + if argv[2]=="blue": + self.app.painter.set_color((0,0,1)) + elif argv[2]=="green": + self.app.painter.set_color((0,1,0)) + elif argv[2]=="red": + self.app.painter.set_color((1,0,0)) + elif argv[2]=="cyan": + self.app.painter.set_color((0,1,1)) + elif argv[2]=="magenta": + self.app.painter.set_color((1,0,1)) + elif argv[2]=="yellow": + self.app.painter.set_color((1,1,0)) + elif argv[2]=="white": + self.app.painter.set_color((1,1,1)) + elif argv[2]=="black": + self.app.painter.set_color((0,0,0)) + elif argv[2]=="gray": + self.app.painter.set_color((0.5,0.5,0.5)) + else: + color_str=argv[2].split(",") + # error if improperly formatted + if len(color_str)!=3: + self.message="error: unrecognized color specification '"+argv[2]+"'; supported format is 'r,g,b' or one of red|green|blue|cyan|magenta|yellow|white|black|gray" + return + try: + color=(float(color_str[0]),float(color_str[1]),float(color_str[2])) + except: + self.message="error: unrecognized color specification '"+argv[2]+"'; supported format is 'r,g,b' or one of red|green|blue|cyan|magenta|yellow|white|black|gray" + return + self.app.painter.set_color(color) + + + # write to file def run_write(self,argv): if len(argv)>2: self.message="error: could not write to file: too many arguments -- usage: ':w [path to file]'" @@ -335,6 +386,7 @@ class Command_prompt(Label): # update status bar self.app.status_bar.draw() + # edit file def run_edit(self,argv): if len(argv)>2: self.message="error: could not open file: too many arguments -- usage: ':e '" @@ -363,4 +415,3 @@ class Command_prompt(Label): self.app.openfile=argv[1] # update status bar self.app.status_bar.draw() - diff --git a/painter.py b/painter.py index 81d35c5..b8feba6 100644 --- a/painter.py +++ b/painter.py @@ -250,6 +250,14 @@ class Painter(Widget): return self.adjust_move_element(newdelta,element,recursion_depth+1) + # set color of selected particles + def set_color(self,color): + for particle in self.selected: + particle.color=color + # redraw + self.draw() + + # write configuration to file def write(self,file): ff=open(file,"w")