Browse Source

[Viewer] Add tool control with numpad

- Using numpad to switch between tools
- 1 for arrow tool, 2 for line.
- +/- Increase/decrease current tool thickness
master
octogene 3 years ago
parent
commit
1d32fae162
2 changed files with 18 additions and 2 deletions
  1. +14
    -0
      hadaly/app.py
  2. +4
    -2
      hadaly/painter.py

+ 14
- 0
hadaly/app.py View File

@ -562,3 +562,17 @@ class Manager(ScreenManager):
self.get_screen('viewer').carousel.current_slide.viewer.lock()
elif key == 100 and modifier == ['ctrl'] and self.current == 'viewer':
self.get_screen('viewer').carousel.current_slide.viewer.painter.canvas.clear()
elif key == 257 and self.current == 'viewer':
current_slide = self.get_screen('viewer').carousel.current_slide
current_slide.viewer.painter.current_tool = 'arrow'
elif key == 258 and self.current == 'viewer':
current_slide = self.get_screen('viewer').carousel.current_slide
current_slide.viewer.painter.current_tool = 'line'
elif key == 268 and self.current == 'viewer':
current_slide = self.get_screen('viewer').carousel.current_slide
painter = current_slide.viewer.painter
painter.tools[painter.current_tool]['thickness'] -= 0.1
elif key == 270 and self.current == 'viewer':
current_slide = self.get_screen('viewer').carousel.current_slide
painter = current_slide.viewer.painter
painter.tools[painter.current_tool]['thickness'] += 0.1

+ 4
- 2
hadaly/painter.py View File

@ -23,7 +23,8 @@ class Painter(Widget):
with self.canvas:
Color(*color, mode='rgba')
touch.ud['line'] = Line(points=(touch.x, touch.y), width=thickness, cap='round', joint='miter')
touch.ud['arrowhead'] = Line(width=thickness, cap='square', joint='miter')
if self.current_tool == 'arrow':
touch.ud['arrowhead'] = Line(width=thickness, cap='square', joint='miter')
touch.ud['initial_pos'] = touch.pos
else:
return False
@ -60,7 +61,8 @@ class Painter(Widget):
return (v1, v2)
def on_touch_up(self, touch):
if not self.locked and touch.grab_current == self and self.collide_point(*touch.pos):
if not self.locked and touch.grab_current == self and \
self.collide_point(*touch.pos) and self.current_tool == 'arrow':
try:
arrowhead = self.arrowhead(touch.ud['initial_pos'], touch.pos)
except KeyError:


Loading…
Cancel
Save