Skip to content

Commit

Permalink
Merge pull request #31 from openalea/visualea
Browse files Browse the repository at this point in the history
Visualea, Emit problem
  • Loading branch information
pradal authored Feb 23, 2023
2 parents 915b925 + bdc38b2 commit 38ef408
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/openalea/visualea/compositenode_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def set_autonomous(self):
def run_node(self):
self.node.eval_as_expression(self.sender().id)


def open_widget(self):
operator = GraphOperator(graph=self.node)
operator.vertex_open(self.sender().id)
Expand Down
3 changes: 2 additions & 1 deletion src/openalea/visualea/dataflowview/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from openalea.core import node
from openalea.core import compositenode
import openalea.grapheditor.base as grapheditorbase
from qtpy import QtWidgets

class GraphAdapter(grapheditorbase.GraphAdapterBase):
"""An adapter to openalea.core.compositenode"""
Expand Down Expand Up @@ -81,7 +82,7 @@ def add_vertex(self, vertex, position=None):
vertex.get_ad_hoc_dict().set_metadata("position", position)
return vid
except node.RecursionError:
mess = QtGui.QMessageBox.warning(self, "Error",
mess = QtWidgets.QMessageBox.warning(self, "Error",
"A graph cannot be contained in itself.")

def remove_vertex(self, vertex):
Expand Down
12 changes: 8 additions & 4 deletions src/openalea/visualea/graph_operator/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ def port_send_to_console(self):
QtWidgets.QMessageBox.Ok)
if overwrite == QtWidgets.QMessageBox.Ok:
interpreter.locals[result]=data
data = str(data)
data = data[:500]+"[...truncated]" if len(data)>500 else data
print(result + ": " + data)

# print the instance name and content as if the user type its name in a shell
# this is only to make obvious the availability of the instance in the
try:
interpreter.runsource(result, hidden=False, interactive=True)
except:
interpreter.runsource("%s\n" % result)
# try:
# interpreter.runsource(result, hidden=False, interactive=True)
# except:
# interpreter.runsource("%s\n" % result)

#setFocus()
14 changes: 10 additions & 4 deletions src/openalea/visualea/node_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ def call_notify (self, sender, event=None):
@param event : the data associated to the notification
"""

# Don't see the point of self.qobj().emit because anyway we manage
# ourselves the notification with self.notify
try:
self.qobj().emit(QtCore.Signal("notify"), sender, event)
except Exception as e:
# fix_print_with_import
print(("Cannot emit Qt Signal : ", e))
self.notify(sender, event)
except:
pass
# try:
# self.qobj().emit(QtCore.Signal("notify"), sender, event)
# except Exception as e:
# # fix_print_with_import
# print(("Cannot emit Qt Signal : ", e))
# self.notify(sender, event)



Expand Down
Empty file.
147 changes: 147 additions & 0 deletions test/dataflow/dataflow_test/__wralea__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@

# This file has been generated at Wed Feb 22 14:27:28 2023

from openalea.core import *


__name__ = 'dataflow_test'

__editable__ = True
__version__ = '0.0.1'
__license__ = 'Cecill-C'
__authors__ = 'OpenAlea Consortium'
__institutes__ = 'INRIA/CIRAD'
__description__ = 'test simple data flow'
__url__ = 'https://github.com/openalea'
__icon__ = ''
__alias__ = []


__all__ = ['addition']



addition = CompositeNodeFactory(name='addition',
description='simple addition',
category='category test',
doc='',
inputs=[],
outputs=[],
elt_factory={ 2: ('pkg_test', 'float'),
3: ('pkg_test', 'float'),
4: ('pkg_test', '+'),
5: ('openalea.flow control', 'annotation'),
6: ('openalea.flow control', 'annotation'),
7: ('pkg_test', 'float')},
elt_connections={ 140604922288400: (3, 0, 4, 0),
140604922288432: (2, 0, 4, 1),
140604922288464: (4, 0, 7, 0)},
elt_data={ 2: { 'block': False,
'caption': '2.1',
'delay': 0,
'hide': True,
'id': 2,
'lazy': True,
'port_hide_changed': set(),
'posx': -245.9709450619092,
'posy': -111.85872859148041,
'priority': 0,
'use_user_color': False,
'user_application': None,
'user_color': None},
3: { 'block': False,
'caption': '1.2',
'delay': 0,
'hide': True,
'id': 3,
'lazy': True,
'port_hide_changed': set(),
'posx': -320.3252070658707,
'posy': -111.0109722906813,
'priority': 0,
'use_user_color': False,
'user_application': None,
'user_color': None},
4: { 'block': False,
'caption': '+',
'delay': 0,
'hide': True,
'id': 4,
'lazy': True,
'port_hide_changed': set(),
'posx': -314.20270829939903,
'posy': -34.466726410245506,
'priority': 0,
'use_user_color': False,
'user_application': False,
'user_color': None},
5: { 'id': 5,
'posx': -364.22435123884213,
'posy': -140.49860060790175,
'txt': 'inputs'},
6: { 'id': 6,
'posx': -381.13154273993564,
'posy': -60.87669916942594,
'txt': 'addition'},
7: { 'block': False,
'caption': '3.3',
'delay': 0,
'hide': True,
'id': 7,
'lazy': True,
'port_hide_changed': set(),
'posx': -311.29505256125043,
'posy': 14.841906066585054,
'priority': 0,
'use_user_color': False,
'user_application': True,
'user_color': None},
'__in__': { 'block': False,
'caption': 'In',
'delay': 0,
'hide': True,
'id': 0,
'lazy': True,
'port_hide_changed': set(),
'posx': 0,
'posy': 0,
'priority': 0,
'use_user_color': True,
'user_application': None,
'user_color': None},
'__out__': { 'block': False,
'caption': 'Out',
'delay': 0,
'hide': True,
'id': 1,
'lazy': True,
'port_hide_changed': set(),
'posx': 0,
'posy': 0,
'priority': 0,
'use_user_color': True,
'user_application': None,
'user_color': None}},
elt_value={ 2: [(0, '2.1')],
3: [(0, '1.2')],
4: [],
5: [],
6: [],
7: [],
'__in__': [],
'__out__': []},
elt_ad_hoc={ 2: {'position': [-245.9709450619092, -111.85872859148041], 'userColor': None, 'useUserColor': False},
3: {'position': [-320.3252070658707, -111.0109722906813], 'userColor': None, 'useUserColor': False},
4: {'position': [-314.20270829939903, -34.466726410245506], 'userColor': None, 'useUserColor': False},
5: {'position': [-364.22435123884213, -140.49860060790175], 'text': 'inputs', 'textColor': None, 'rectP2': (176.7140917324355, 69.32013223357238), 'color': None, 'visualStyle': 1},
6: {'position': [-381.13154273993564, -60.87669916942594], 'text': 'addition', 'textColor': None, 'rectP2': (-1, -1), 'color': None, 'visualStyle': 1},
7: {'position': [-311.29505256125043, 14.841906066585054], 'userColor': None, 'useUserColor': False},
'__in__': {'position': [0, 0], 'userColor': None, 'useUserColor': True},
'__out__': {'position': [0, 0], 'userColor': None, 'useUserColor': True}},
lazy=True,
eval_algo='LambdaEvaluation',
)




2 changes: 1 addition & 1 deletion test/test_helpwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def test_helpwidget():



test_rst2alea()
# test_rst2alea()
#test_helpwidget()

54 changes: 54 additions & 0 deletions test/test_widget_composite_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from openalea.core import logger, CompositeNodeFactory
from openalea.visualea.mainwindow import MainWindow
from openalea.core.pkgmanager import PackageManager
from qtpy import QtWidgets, QtCore
from openalea.core.alea import *

def open_window(factory):

dialog = QtWidgets.QDialog()
widget = factory.instantiate_widget(autonomous=True)

dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
widget.setParent(dialog)

vboxlayout = QtWidgets.QVBoxLayout(dialog)
vboxlayout.setContentsMargins(3,3,3,3)
vboxlayout.setSpacing(5)
vboxlayout.addWidget(widget)

dialog.setWindowTitle(factory.name)

return dialog

def test_addition_composite_node():
# Allow to test DisplayGraphWidget from openalea.visualea.compositenode_widget
app = QtWidgets.QApplication(sys.argv)

p = PackageManager()
p.init(verbose=False)

factory, node = get_node(('dataflow_test', 'addition'), {}, pm=p)

win = open_window(factory)

# get the button 'Run', there is only one for the node 7 which is user marked
for ch in win.findChildren(QtWidgets.QPushButton):
if ch.text() == 'Run':
ch.click()
break
# get the new caption of node 7, originally set to '0'
output = win.children()[0].node.node(7).caption
win.close()

res = run(('dataflow_test', 'addition'), {}, pm = p, vtx_id = 4)


assert output == str(res[0])

def test_call_mainwindow():
# test the basic call to openalea.visualea.mainwindow
app = QtWidgets.QApplication(sys.argv)
win = MainWindow(None)

# def test_remove_one_edge():

0 comments on commit 38ef408

Please sign in to comment.