Skip to content

Commit

Permalink
Fixed a bug where animation timers would continue to run even after a
Browse files Browse the repository at this point in the history
dialog was closed. Caused some weird cursor glitching when putting
mouse over parent dialog...
  • Loading branch information
isaacrobinson2000 committed Mar 30, 2020
1 parent cb746b7 commit c4b0104
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions gui/cursorhotspotedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ def _on_preview(self):
dialog = CursorPreviewDialog(self, self.current_cursor)
dialog.exec_()

def closeEvent(self, evt: QtGui.QCloseEvent):
super().closeEvent(evt)
self.accept()

@property
def current_cursor(self) -> AnimatedCursor:
return self._cursor
Expand Down
25 changes: 24 additions & 1 deletion gui/cursorpreviewdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, parent=None, cursor: AnimatedCursor=None):
self._frame.setLayout(self._box)
self._box.setMargin(0)

self._sub_layouts = []
self._viewers = []

for color in self._colors:
widget = QtWidgets.QWidget()
Expand All @@ -30,6 +30,7 @@ def __init__(self, parent=None, cursor: AnimatedCursor=None):

for size in cursor_util.DEFAULT_SIZES:
c_view = CursorDisplayWidget(cursor=cursor, size=size[0])
self._viewers.append(c_view)
hbox.addWidget(c_view)

widget.setLayout(hbox)
Expand All @@ -40,6 +41,16 @@ def __init__(self, parent=None, cursor: AnimatedCursor=None):
self.setLayout(self._main_layout)
self.setMinimumSize(self.sizeHint())

def closeEvent(self, evt: QtGui.QCloseEvent):
print("Closed!")
super().closeEvent(evt)

self._preview_panel.stop_and_destroy()
for cur_view in self._viewers:
cur_view.stop_and_destroy()

self.accept()


class PreviewArea(QtWidgets.QWidget):

Expand Down Expand Up @@ -103,3 +114,15 @@ def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
if(self._pressed):
self.mouseMoveEvent(event)
self._pressed = False

def stop_and_destroy(self):
""" Forcefully destroys this CursorPreviewAreas animation timer. """
if((self._animation_timer is not None) and (self._animation_timer.isActive())):
self._animation_timer.stop()

del self._animation_timer
self._animation_timer = None
self.setCursor(QtGui.Qt.ArrowCursor)

def __del__(self):
self.stop_and_destroy()
3 changes: 2 additions & 1 deletion gui/cursorviewedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
if(self.current_cursor is not None):
mod_hotspot = HotspotEditDialog(self.window(), self.current_cursor)
mod_hotspot.exec()
self.current_cursor = self.current_cursor
self.current_cursor = self.current_cursor
del mod_hotspot
11 changes: 11 additions & 0 deletions gui/cursorviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ def current_cursor(self, cursor: AnimatedCursor):
self._delays = [0]

self.moveStep()

def stop_and_destroy(self):
""" Forcefully destroys the cursor viewers animation timer by stopping it and deleting it. """
if((self.__animation_timer is not None) and (self.__animation_timer.isActive())):
self.__animation_timer.stop()

del self.__animation_timer
self.__animation_timer = None

def __del__(self):
self.stop_and_destroy()

0 comments on commit c4b0104

Please sign in to comment.