Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sebastian Steinlechner
pykat
Commits
ad82f792
Commit
ad82f792
authored
Mar 04, 2014
by
Daniel Brown
Browse files
updating gui on object removal
parent
fde8c507
Changes
3
Hide whitespace changes
Inline
Side-by-side
pykat/finesse.py
View file @
ad82f792
...
...
@@ -821,7 +821,13 @@ class kat(object):
if
obj
.
removed
:
raise
pkex
.
BasePyKatException
(
"{0} has already been removed"
.
format
(
obj
.
name
))
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
[
obj
.
name
]
self
.
__del_component
(
obj
)
...
...
@@ -837,6 +843,11 @@ class kat(object):
if
obj
in
self
.
__blocks
[
b
].
contents
:
self
.
__blocks
[
b
].
contents
.
remove
(
obj
)
if
self
.
pykatgui
!=
None
:
self
.
pykatgui
.
_onComponentRemoved
(
obj
,
nodes
)
del
nodes
import
gc
print
gc
.
get_referrers
(
obj
)
...
...
pykat/gui/graphics.py
View file @
ad82f792
...
...
@@ -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
):
QGraphicsSvgItem
.
__init__
(
self
,
svgfile
)
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
self
.
setFlags
(
QGraphicsItem
.
ItemSendsGeometryChanges
)
...
...
@@ -170,7 +176,7 @@ class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
self
.
setHandlesChildEvents
(
True
)
@
property
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
],
pykat
.
components
.
space
):
conn
[
1
].
getQGraphicsItem
().
refresh
()
...
...
pykat/gui/gui.py
View file @
ad82f792
...
...
@@ -70,6 +70,29 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
itm
.
refresh
()
itm
.
setCacheMode
(
QGraphicsItem
.
NoCache
)
self
.
__scene
.
addItem
(
itm
)
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
:
itm
.
refresh
()
self
.
__scene
.
removeItem
(
itm
)
for
n
in
nodes
:
for
cc
in
self
.
_kat
.
nodes
.
getNodeComponents
(
n
):
print
"refresh"
,
cc
if
cc
!=
None
:
ccitm
=
cc
.
getQGraphicsItem
()
if
ccitm
!=
None
:
ccitm
.
refresh
()
def
exportToSVG
(
self
):
self
.
statusbar
.
showMessage
(
"Saving to 'output.svg'..."
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment