replace keydown with textinput in painter

This commit is contained in:
Ian Jauslin 2021-12-06 13:22:34 -05:00
parent b0d6178271
commit f0f090315a

View File

@ -40,7 +40,7 @@ class Painter(Widget):
# init keyboard # init keyboard
self.keyboard = Window.request_keyboard(None,self,"text") 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): def reset(self):
@ -80,7 +80,7 @@ class Painter(Widget):
# respond to keyboard # respond to keyboard
def on_key_down(self, keyboard, keycode, text, modifiers): 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 not self.app.command_prompt.insert:
if keycode[1]=="shift": if keycode[1]=="shift":
if not 's' in self.modifiers: if not 's' in self.modifiers:
@ -93,8 +93,12 @@ class Painter(Widget):
self.selected=[] self.selected=[]
self.draw() 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 # select all
elif keycode[1]=="a": if text=="a":
for particle in self.particles: for particle in self.particles:
particle.selected=True particle.selected=True
self.selected=self.particles.copy() self.selected=self.particles.copy()
@ -102,7 +106,7 @@ class Painter(Widget):
self.draw() self.draw()
# toggle grid # toggle grid
elif keycode[1]=="g": elif text=="g":
for particle in self.selected: for particle in self.selected:
if particle.grid==0: if particle.grid==0:
particle.grid=1 particle.grid=1
@ -111,13 +115,13 @@ class Painter(Widget):
self.draw() self.draw()
# zoom # zoom
elif keycode[1]=="+": elif text=="+":
# increment by 10% # increment by 10%
self.set_zoom(Square_element.size/50*1.1) self.set_zoom(Square_element.size/50*1.1)
elif keycode[1]=="-": elif text=="-":
# decrease by 10% # decrease by 10%
self.set_zoom(Square_element.size/50*0.9) self.set_zoom(Square_element.size/50*0.9)
elif keycode[1]=="=": elif text=="=":
# reset # reset
self.set_zoom(1) self.set_zoom(1)