Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions mal_gui/object_explorer/attacker_item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from PySide6.QtGui import QColor
from PySide6.QtCore import QTimer
from PySide6.QtWidgets import QGraphicsItem
from shiboken6 import isValid

from .item_base import ItemBase

Expand All @@ -19,7 +21,7 @@ def __init__(
self.attacker_toggle_state = False

self.timer = QTimer()
self.status_color = QColor(0, 255, 0)
self.status_color = QColor(0, 255, 0)
self.attacker_toggle_state = False
self.timer.timeout.connect(self.update_status_color)
self.timer.start(500)
Expand All @@ -29,7 +31,7 @@ def __init__(
def update_type_text_item_position(self):
super().update_type_text_item_position()
# For Attacker make the background of type As Red
self.asset_type_background_color = QColor(255, 0, 0) #Red
self.asset_type_background_color = QColor(255, 0, 0) # Red

def update_name(self):
"""Update the name of the attacker"""
Expand All @@ -43,13 +45,30 @@ def get_item_attribute_values(self):
}

def update_status_color(self):
# Object may already be deleted on C++ side
if not isValid(self):
return

# Still check if removed from scene
if self.scene() is None:
if self.timer.isActive():
self.timer.stop()
return

self.attacker_toggle_state = not self.attacker_toggle_state
if self.attacker_toggle_state:
self.status_color = QColor(0, 255, 0) # Green
self.status_color = QColor(0, 255, 0) # Green
else:
self.status_color = QColor(255, 0, 0) # Red
self.status_color = QColor(255, 0, 0) # Red
self.update()

def itemChange(self, change, value):
"""Override to stop timer when item is removed from scene"""
if change == QGraphicsItem.ItemSceneChange:
if value is None and self.timer.isActive():
self.timer.stop()
return super().itemChange(change, value)

def serialize(self):
return {
'title': self.title,
Expand Down