Skip to content

Commit

Permalink
Merge pull request #1309 from HEXRD/interactive-canvas-patch
Browse files Browse the repository at this point in the history
added update to total angle from key input
  • Loading branch information
joelvbernier authored Nov 1, 2022
2 parents 19a7c5a + fdb6e75 commit 11e6850
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions hexrd/ui/interactive_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, parent=None):
self.img = None
self.shape = None
self.press = None
self.total_rotation = 0
self.total_rotation = 0.
self.translating = True
self.shape_styles = []
self.parent.setFocusPolicy(Qt.ClickFocus)
Expand Down Expand Up @@ -155,7 +155,7 @@ def completed(self):
self.img = None
self.shape = None
self.press = None
self.total_rotation = 0
self.total_rotation = 0.

def mask(self):
col, row = self.cropped_shape.T
Expand Down Expand Up @@ -317,11 +317,14 @@ def on_rotate(self, event):

def on_key_rotate(self, event):
angle = 0.00175
# !!! only catch arrow keys
if event.key == 'left' or event.key == 'up':
angle *= -1
angle *= -1.
elif event.key != 'right' and event.key != 'down':
return

angle *= 1.
# DEBUG
# print(f'In "on_key_rotate": {angle}')
self.total_rotation += angle
self.rotate_template(self.shape.xy, angle)
self.redraw()

Expand Down Expand Up @@ -359,14 +362,15 @@ def get_angle(self, e):
def on_rotate_release(self, event):
if self.press is None:
return

angle = self.get_angle(event)
self.total_rotation += angle
y, x = self.center
xy, xpress, ypress = self.press
self.press = None
self.rotate_template(xy, angle)
self.redraw()
# DEBUG
# print(f'In rotate release {angle}, {self.total_rotation}')

def disconnect_rotate(self):
self.parent.mpl_disconnect(self.button_press_cid)
Expand Down

0 comments on commit 11e6850

Please sign in to comment.