Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Tulip python does not follow python idioms #33

Closed
rgiot opened this issue Jan 17, 2018 · 6 comments
Closed

Tulip python does not follow python idioms #33

rgiot opened this issue Jan 17, 2018 · 6 comments

Comments

@rgiot
Copy link
Contributor

rgiot commented Jan 17, 2018

In python, the natural syntax to test the existance of a thing in a container is to use the keyword in.
Sadly, it seems it is not the case with tulip bindings in python.

The following code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tulip import *

g = tlp.newGraph()
n1 = g.addNode()
n2 = g.addNode()
n3 = tlp.node()
e = g.addEdge(n1, n2)

# C++ way of life
assert g.isElement(n1)
assert g.isElement(n2)
assert g.isElement(e)
assert not g.isElement(n3)

# Python way of life ...
l = [n1, n2, e]
assert n1 in l
assert n2 in l
assert e in l
assert not n3 in l

# ... not compatible with tulip
assert n1 in g
assert e in g

is expected to work.

However assert n1 in g raises the following error:

Traceback (most recent call last):
  File "pythontest.py", line 28, in <module>
    assert n1 in g
TypeError: Graph.__getitem__(): argument 1 has unexpected type 'int'

I do not know at all sip, but I'm sure the error comes from Graph.sip where some cases are not taken into account in __getitem__.
No idea if it is technically feasible to fix this unexpected behavior.

By the way type(n1) gives <class '_tulip.node'> and not int as the error message suggest

anlambert added a commit to anlambert/talipot that referenced this issue Jan 17, 2018
@anlambert
Copy link
Contributor

Hi Romain,

Good catch! I have just created PR #34 fixing the issue.

Cheers!

@rgiot
Copy link
Contributor Author

rgiot commented Jan 17, 2018

@anlambert Thanks for proposing a patch so quickly. I have to admit that I'm surprised the solution is so short

p-mary added a commit that referenced this issue Jan 18, 2018
@p-mary
Copy link
Contributor

p-mary commented Jan 18, 2018

Thanks to both of you.

@rgiot
Copy link
Contributor Author

rgiot commented Jun 27, 2019

In the same vein, addNodes accepts a tulip iterator, but not a list. It should be practical to allow such notation:

g.addNodes([node1, node2, node3])

where node1,node2 and node3 are valid nodes.

edit: here is the error message

    sg.addNodes(duplicated)
TypeError: Graph.addNodes(): arguments did not match any overloaded call:
  overload 1: argument 1 has unexpected type 'list'
  overload 2: argument 1 has unexpected type 'list'
  overload 3: argument 1 has unexpected type 'list'

@rgiot
Copy link
Contributor Author

rgiot commented Jun 27, 2019

Sorry for the noise, tulip is able to add list of nodes without any issue...
I forget that my duplicated variable was a list of tuple instead of a list of nodes ...

However, the error message is misleading, as my variable was a list

@rgiot rgiot closed this as completed Jun 27, 2019
@anlambert
Copy link
Contributor

It seems that the API documentation is missing some methods, I will make a pass on it to add them.

I agree that the error message is confusing, I may have an idea to improve that.

p-mary referenced this issue in anlambert/talipot Jan 3, 2020
QOpenGL module is marked as deprecated since a while now so it is time
to remove its use from the Talipot codebase and promote the use of
QOpenGL* classes directly integrated in the QtGui module.

The big difference between QOpenGL and QtOpenGL from Qt5 is that all
rendering is performed in framebuffer objects, there is no more direct
rendering in the underlying os windows with its own OpenGL context.

Talipot OpenGL rendering also follows that idiom, all renderings are performed
offscreen using a shared OpenGL context. This also means that there is no
more QGLWidget as viewport for QGraphicsView. Talipot OpenGL scene are
now converted to QImage in order to display them using the default Qt raster
rendering engine. This should fixes the numerous rendering glitches observed
on MacOS.

First thing observed after the migration is a consequent performance boost
in OpenGL rendering when using an Intel GPU on a Linux host machine (especially
when selecting elements, it is now 10 times faster on debian stable).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants