Skip to content

Commit

Permalink
BF: hack to avoid a crash; maybe fixes psychopy#827
Browse files Browse the repository at this point in the history
- unsure the proper fix
- this works for me (deletes the row without crashing the app)
- no idea what else might happen (memory leak?)
  • Loading branch information
jeremygray committed Feb 4, 2015
1 parent bb6d7bb commit 73dd121
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions psychopy/app/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,52 @@ def onRemoveElement(self, event=None):
self.DeleteRow(row)
self.Layout()
self.parent.Fit()
def DeleteRow(self, row):
"""Deletes an entire row, destroying its objects (if any).
"""
# As for the vertically spanned objects in the given row,
# we'll need to move them somewhere safe (so that their objects
# won't be destroyed as we destroy the row itself) and respan
# them later with a reduced row span (decreased by 1 row).
# 1. Get a reference of the vertically spanned objects on this row and
# their span, decrementing their row span by 1.
_update_span = {}
for c in range(0, self.GetCols()):
item = self.FindItemAtPosition((row, c))
if item:
rs, cs = item.GetSpan().Get()
if rs > 1:
_update_span[item.GetWindow()] = (rs - 1, cs)
# 2. Unspan all objects.
objs = self._resetSpan()
# 3. Move the _update_span objects to an adjacent row somewhere safe.
for obj in _update_span.keys():
item = self.FindItem(obj)
org_r, org_c = item.GetPos().Get()
if org_r == row:
item.SetPos((org_r + 1, org_c))
# 4. Destroy all objects on this row.
for c in range(0, self.GetCols()):
item = self.FindItemAtPosition((row, c))
if item:
obj = item.GetWindow()
self.Detach(obj)
print obj, dir(obj)
del obj # JRG edited here; memory leaks?

This comment has been minimized.

Copy link
@jeremygray

jeremygray Feb 4, 2015

Author Owner

is this an acceptable substitution??


#obj.Destroy() # this line crashes python for me
# 5. Shift rows up.
self.ShiftRowsUp(row + 1)
# 6. Respan all objects.
objs.update(_update_span)
self._setSpan(objs)
# 7. Update references to growable rows.
grows = self.growableRows.keys()
for r in grows:
if r >= row:
self.RemoveGrowableRow(r)
if r > row:
self.AddGrowableRow(r - 1)
def getListOfDicts(self):
"""Retrieve the current list of dicts from the grid
"""
Expand Down

1 comment on commit 73dd121

@jeremygray
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @sloria, I copied your DeleteRow() method into PsychoPy. Is this going the right direction to fix the crash I get on Mac 10.9.5 with wx 3 (version '3.0.0.0 osx-cocoa (classic)')?

COS is awesome. Keep up the good work!

Please sign in to comment.