0

I would like to know how I can make the self.show() instruction at the end of my Vispy.app.Canvas init() dependant on the fact the canvas is basically run in a Vispy app or as a QWidget in a QMainWindow.

So I have a Python3 Vispy app that run and shows directly a Canvas. At the end of the init call of the Canvas, there is a mandatory self.show(). This works fine.

Now I want to use also this canvas as the central widget in a QMainWindow. This works ONLY if I comment out the self.show() command.

I would like to make this call dependant of something (canvas.native.parent... or something, to execute it only when run outside of a QMainWindow:

if SOME_CONDITION_TELLING_ME_I_M_OUT_OF_QMAINWINDOW:
    self.show()

This would help me factorize this canvas class instead of having two versions just for this self.show() call.

I hope this very first question is clear.

Full code available here: https://github.com/gregvds/grayscott

Thanks,

Greg

GregVDS
  • 13
  • 4

1 Answers1

0

You don't need to have the self.show() in the __init__ method of the class. You could call it from the module that is using it, after the Canvas is created:

canvas = Canvas(...)
canvas.show()

That way you only need to call .show() from the uses where the Canvas is its own window.

djhoese
  • 3,567
  • 1
  • 27
  • 45
  • Oh Man!!! :facepalm... It simply was that simple! – GregVDS Jan 20 '22 at 23:05
  • Sometimes you are to caught up in the problem to see the simple solution. Happens to everyone. Don't forget to accept this answer. – djhoese Jan 20 '22 at 23:28
  • Done! This is my very first use of stackoverflow as an active user, so I don't have yet all the good reflexes :-). Thanks again for the help! – GregVDS Jan 20 '22 at 23:33
  • No problem. Glad it was a simple solution. For future vispy help feel free to check out our gitter chat room or github issue tracker. I was quick to answer this question this time, but sometimes stackoverflow gets away from me. – djhoese Jan 21 '22 at 01:44
  • Noted! I was a bit at loss about where and how to obtain help. I reached directly one of the guy who developed some examples, but I did not want to bother him all the time with noob questions... – GregVDS Jan 21 '22 at 11:20