Skip to content

Commit

Permalink
fixing Review Comments
Browse files Browse the repository at this point in the history
CURA-10770
  • Loading branch information
saumyaj3 committed Jul 25, 2023
1 parent 79a2ceb commit 81931ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ resources/.DS_Store
plugins/UraniumExample*Plugin
/conanbuildinfo.txt
/graph_info.json
/venv/
38 changes: 25 additions & 13 deletions UM/Qt/Bindings/ShakeDetector.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty

from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty, pyqtSlot

from typing import Optional

class ShakeDetector(QObject):

shakeDetected = pyqtSignal()
def __init__(self, parent = None):
pointChanged = pyqtSignal()

def getPoint(self) -> Optional["QPoint"]:
return self._curr_pos

def setPoint(self, point: "QPoint"):
self._curr_pos = point
self.pointChanged.emit()

position = pyqtProperty('QPoint', fget=getPoint, fset=setPoint, notify=pointChanged)

def __init__(self, _parent = None):
super().__init__()
self.prev_pos = None
self.threshold = 5

self._curr_pos = None
self._prev_pos = None
self.threshold = 50
self.shake_count = 0
self.number_of_shakes = 0

@pyqtSlot(int, int)
def checkForShake(self, x, y):
self.pointChanged.connect(self._checkForShake)

if self.prev_pos is not None:
def _checkForShake(self):
if self._prev_pos is not None:
# Calculate the distance moved between the previous and current positions
distance = ((x - self.prev_pos[0]) ** 2 + (y - self.prev_pos[1]) ** 2) ** 0.5
distance = ((self._curr_pos.x() - self._prev_pos.x()) ** 2 + (self._curr_pos.y() - self._curr_pos.y()) ** 2) ** 0.5
# If the distance is greater than a threshold, emit the shakeDetected signal
if distance > self.threshold:
self.shake_count += 1
if self.shake_count > 3:
if self.shake_count > 10:
self.shake_count = 0
self.number_of_shakes +=1
self.number_of_shakes += 1
self.shakeDetected.emit()

# Update the previous position with the current one
self.prev_pos = (x, y)
self._prev_pos = self._curr_pos

@pyqtProperty(int, notify = shakeDetected)
def shakeIsdetected(self):
Expand Down

0 comments on commit 81931ec

Please sign in to comment.