Commit ad82f792 authored by Daniel Brown's avatar Daniel Brown
Browse files

updating gui on object removal

parent fde8c507
......@@ -821,7 +821,13 @@ class kat(object):
if obj.removed:
raise pkex.BasePyKatException("{0} has already been removed".format(
nodes = None
# store nodes that this componet is attached to as a reference for gui
if isinstance(obj, Component):
nodes = self.nodes.getComponentNodes(obj)
if isinstance(obj, Component):
del self.__components[]
......@@ -837,6 +843,11 @@ class kat(object):
if obj in self.__blocks[b].contents:
if self.pykatgui != None:
self.pykatgui._onComponentRemoved(obj, nodes)
del nodes
import gc
print gc.get_referrers(obj)
......@@ -11,6 +11,7 @@ from PyQt4 import QtSvg
from PyQt4.QtSvg import QGraphicsSvgItem
import pykat.components
import exceptions
import weakref
nsize = 10
......@@ -143,10 +144,15 @@ class SpaceQGraphicsItem(QGraphicsLineItem):
class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
def __on_component_deleted(self, arg):
import gc
print gc.get_referrers(self)
def __init__(self, svgfile, component, nodes):
self.__nodeGraphics = []
self.__component = component
self.__component = weakref.ref(component, self.__on_component_deleted)
# this signals the itemChange() method when this item is moved
# used for refreshing the spaces between components
......@@ -170,7 +176,7 @@ class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
def component(self): return self.__component
def component(self): return self.__component()
def refresh(self):
for n in self.__nodeGraphics:
......@@ -179,10 +185,10 @@ class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
def itemChange(self, change, value):
# if the item is moved then update any spaces attached to it
if change == QGraphicsItem.ItemPositionHasChanged:
nodes = self.__component.nodes
nodes = self.component.nodes
for n in nodes:
conn = n.amIConnected(self.__component)
conn = n.amIConnected(self.component)
if conn[0] and isinstance(conn[1],
......@@ -70,6 +70,29 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
def _onComponentRemoved(self, comp, nodes):
When a component has been removed from the kat object this function should update
all gui objects.
comp - object that is removed
nodes - nodes that this comp was attached too, as that information may no longer be accessible
itm = comp.getQGraphicsItem()
if itm != None:
for n in nodes:
for cc in self._kat.nodes.getNodeComponents(n):
print "refresh", cc
if cc != None:
ccitm = cc.getQGraphicsItem()
if ccitm != None:
def exportToSVG(self):
self.statusbar.showMessage("Saving to 'output.svg'...")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment