Skip to content

Commit

Permalink
Merge pull request #128 from JonasLukasczyk/id_fixes
Browse files Browse the repository at this point in the history
cycle bug fix; improved input-input connections
  • Loading branch information
dhrogers authored Aug 15, 2024
2 parents 17c96e9 + 42c9721 commit 4a22766
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
5 changes: 2 additions & 3 deletions pycinema/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ def set(self, value, update=True, propagate_back=False):

# if old value is a port
if isinstance(self._value, Port):
if propagate_back and hasattr(self._value.parent.inputs,'value'):
# override ValueSource
self._value.parent.inputs.value.set(value,update,False)
if propagate_back:
self._value.set(value,update,True)
return
else:
# stop listing for push events
Expand Down
23 changes: 13 additions & 10 deletions pycinema/filters/TableView.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,36 @@ def _update(self):
selection = self.inputs.selection.get()
selection_indices = []
output_table = [[]]
id_column_idx = 0

selection_mode = QtWidgets.QAbstractItemView.ExtendedSelection

if input_is_image_list:
selection_indices = [i for i in range(0,len(table)) if table[0].meta['id'] in selection]
selection_indices = [i for i in range(0,len(table)) if table[i].meta['id'] in selection]
output_table = [table[i] for i in selection_indices]
else:
try: id_column_idx = table[0].index('id')
except ValueError: id_column_idx = -1

selection_mode = QtWidgets.QAbstractItemView.ExtendedSelection
if id_column_idx<0:
selection_mode = QtWidgets.QAbstractItemView.NoSelection

else:
selection_indices = [i for i in range(0,len(table)) if table[i][id_column_idx] in selection]
output_table = [table[0]]
for i in selection_indices:
output_table.append(table[i])
for w in self.widgets:
w.setSelectionMode(selection_mode)
output_table = [table[i] for i in [0]+selection_indices]
selection_indices = [i-1 for i in selection_indices]

# disable selection if no id column present
for w in self.widgets:
w.setSelectionMode(selection_mode)

self.outputs.table.set( output_table )

self.suppress_selection_update = True
self.selection_model.clear()
if id_column_idx<0:
self.selection_model.clear()
self.inputs.selection.set([])
else:
indices_ = [self.model.index(r-1, 0) for r in selection_indices]
indices_ = [self.model.index(r, 0) for r in selection_indices]
mode = QtCore.QItemSelectionModel.Select | QtCore.QItemSelectionModel.Rows
[self.selection_model.select(self.proxyModel.mapFromSource(i), mode) for i in indices_]
self.suppress_selection_update = False
Expand Down
16 changes: 12 additions & 4 deletions pycinema/theater/node_editor/Port.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def hoverLeaveEvent(self,event):
self.representation.setBrush(NES.COLOR_NORMAL)

def update_node_connection_line(self,ncl,p1):
x0 = ncl.p0.x()
y0 = ncl.p0.y()
x0 = ncl.p0_.x()
y0 = ncl.p0_.y()
x1 = p1.x()
y1 = p1.y()
path = QtGui.QPainterPath()
path.moveTo(ncl.p0)
path.moveTo(ncl.p0_)
dx = abs(x0 - x1)
if x0<x1: dx *= 0.5
if self.parentItem().port.is_input:
Expand All @@ -50,7 +50,7 @@ def update_node_connection_line(self,ncl,p1):
def mousePressEvent(self,event):
pos = self.mapToScene(self.boundingRect().center())
ncl = self.scene().node_connection_line
ncl.p0 = pos
ncl.p0_ = pos
self.update_node_connection_line(ncl,pos)
ncl.show()

Expand Down Expand Up @@ -95,6 +95,14 @@ def mouseReleaseEvent(self,event):
else:
s.set( t )
else:
# check if connection introduces cycle
temp = t
while temp.valueIsPort():
if temp._value == s:
return
temp = temp._value

# set port
s.set( t )

def mouseDoubleClickEvent(self,event):
Expand Down
1 change: 1 addition & 0 deletions pycinema/theater/views/NodeEditorView.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from PySide6 import QtCore, QtWidgets, QtGui

import pycinema
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"matplotlib==3.6.0",
"py==1.11.0",
"Pillow==9.4.0",
"moderngl==5.8.2",
"moderngl==5.10.0",
"opencv-python==4.7.0.68",
"ipycanvas==0.13.1",
"ipywidgets==8.0.6",
Expand Down

0 comments on commit 4a22766

Please sign in to comment.