replace keydown with textinput in painter
This commit is contained in:
parent
b0d6178271
commit
f0f090315a
18
painter.py
18
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user