From f0f090315ae9ce1a909c510d4cb2755730be9c40 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Mon, 6 Dec 2021 13:22:34 -0500 Subject: [PATCH] replace keydown with textinput in painter --- painter.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/painter.py b/painter.py index 95e4b06..454d26b 100644 --- a/painter.py +++ b/painter.py @@ -40,7 +40,7 @@ class Painter(Widget): # init keyboard self.keyboard = Window.request_keyboard(None,self,"text") - self.keyboard.bind(on_key_down=self.on_key_down,on_key_up=self.on_key_up) + self.keyboard.bind(on_key_down=self.on_key_down,on_key_up=self.on_key_up,on_textinput=self.on_textinput) def reset(self): @@ -80,7 +80,7 @@ class Painter(Widget): # respond to keyboard def on_key_down(self, keyboard, keycode, text, modifiers): - # check that command_prompt is not focused + # check the command_prompt is not focused if not self.app.command_prompt.insert: if keycode[1]=="shift": if not 's' in self.modifiers: @@ -93,8 +93,12 @@ class Painter(Widget): self.selected=[] self.draw() + # respond to keyboard (text input is modifier-sensitive, i.e. one can use shift) + def on_textinput(self, window, text): + # check the command_prompt is not focused + if not self.app.command_prompt.insert: # select all - elif keycode[1]=="a": + if text=="a": for particle in self.particles: particle.selected=True self.selected=self.particles.copy() @@ -102,7 +106,7 @@ class Painter(Widget): self.draw() # toggle grid - elif keycode[1]=="g": + elif text=="g": for particle in self.selected: if particle.grid==0: particle.grid=1 @@ -111,13 +115,13 @@ class Painter(Widget): self.draw() # zoom - elif keycode[1]=="+": + elif text=="+": # increment by 10% self.set_zoom(Square_element.size/50*1.1) - elif keycode[1]=="-": + elif text=="-": # decrease by 10% self.set_zoom(Square_element.size/50*0.9) - elif keycode[1]=="=": + elif text=="=": # reset self.set_zoom(1)