Display inside PyQt4 window

222 views
Skip to first unread message

kanishka shami

unread,
Sep 1, 2017, 11:01:09 AM9/1/17
to VPython-users
how can i put the Vpython Display inside a PyQt4 window, i have developed a GUI in Pyqt4 and need Vpython for Display

Bruce Sherwood

unread,
Sep 1, 2017, 11:10:27 AM9/1/17
to VPython-users
I know nothing about PyQt4, but have you tried installing vpython (see vpython.org) and trying it? Briefly, when vpython detects that it is not running in a Jupyter notebook, it sets up http and websocket communication with a browser and makes the 3D display in the browser, using the GlowScript libraries that are based on WebGL.

Robert A. Knop Jr.

unread,
Sep 1, 2017, 11:26:19 AM9/1/17
to vpytho...@googlegroups.com
On Fri, Sep 01, 2017 at 08:01:09AM -0700, kanishka shami wrote:
> how can i put the Vpython Display inside a PyQt4 window, i have developed a
> GUI in Pyqt4 and need Vpython for Display

This can't be done with the current version of VPython. It will only
display to a web browser.

(I suppose it might somehow be possible to embed a web browser display,
which includes full WebGL support, in a QT widget, but I would be
surprised if such a thing exists.)

-Rob

--
--Rob Knop
E-mail: rk...@pobox.com
Home Page: http://www.sonic.net/~rknop/
Blog: http://www.galacticinteractions.org/
signature.asc

Doug Blank

unread,
Sep 1, 2017, 11:49:48 AM9/1/17
to vpytho...@googlegroups.com
There is a QT-based console for interacting with Jupyter Notebooks. You might see if that supports vpython, and if so, if you can use parts of that.


-Doug


--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruce Sherwood

unread,
Sep 1, 2017, 12:10:36 PM9/1/17
to VPython-users
Another possibility would be for you to modify the vpython file no_notebook.py, which sets up the HTTP and websocket communication with the browser. But the key point is that a browser must be involved, because the 3D display uses WebGL, which is a component of browsers.

Bruce Sherwood

unread,
Sep 1, 2017, 1:46:10 PM9/1/17
to VPython-users
I guess I should point out that the vpython module itself has convenient GUI widgets (button, checkbox, radio button, slider, pulldown menu). You can see an example here (which also runs in VPython 7):


ZYuan X

unread,
Dec 21, 2017, 10:08:20 AM12/21/17
to VPython-users
在 2017年9月1日星期五 UTC+8下午11:26:19,Rob Knop写道:

This can't be done with the current version of VPython.  It will only
display to a web browser.


What a pity.
I've been searching for a method to integrate VPython with some GUI programming tool, such as pyQT, wxPython, Tkinter. 

ZYuan X

unread,
Dec 30, 2017, 11:04:40 AM12/30/17
to VPython-users
Are you the respectable developer of VPython? 
I hope VPython7 can be integrated with some GUI programming tools, such as pyQT, wxPython, Tkinter and so on.
After several days' use, I don't think those GUI widgets of vpython is convenient enough. 
To cooperated with other excellent GUI tools (as VPython6 did) is a good way.

Bruce Sherwood

unread,
Dec 30, 2017, 12:06:17 PM12/30/17
to VPython-users
I am currently the main developer of VPython. It is not really true that VPython cannot work with tools such as wxPython. The following program is a very minor revision of the "Hello World" example given in the wxPython documentation. It displays a 3D box in a browser and also displays a wxPython window, where there is a menu option to change the color of the box. What is tricky is that wxPython, like other GUI modules, has its own app.MainLoop() that watches for events and dispatches them to handlers, whereas VPython animation statements need to run periodically to update the screen. Look at the last few lines of the program below and you will see that the usual app.MainLoop() call is not used. Instead, the wxPython machinery is called ("Dispatch") when there are events pending.

I don't actually know, but I doubt that wxPython or Tkinter or pyQT can embed a web page (containing a VPython animation) in their displays.

from vpython import *
import wx
b = box()

class HelloFrame(wx.Frame):
    """
    A Frame that says Hello World
    """

    def __init__(self, *args, **kw):
        # ensure the parent's __init__ is called
        super(HelloFrame, self).__init__(*args, **kw)

        # create a panel in the frame
        pnl = wx.Panel(self)

        # and put some text with a larger bold font on it
        st = wx.StaticText(pnl, label="Use File > Make box cyan", pos=(25,25))
        font = st.GetFont()
        font.PointSize += 10
        font = font.Bold()
        st.SetFont(font)

        # create a menu bar
        self.makeMenuBar()

        # and a status bar
        self.CreateStatusBar()
        self.SetStatusText("Welcome to wxPython!")


    def makeMenuBar(self):
        """
        A menu bar is composed of menus, which are composed of menu items.
        This method builds a set of menus and binds handlers to be called
        when the menu item is selected.
        """

        # Make a file menu with Hello and Exit items
        fileMenu = wx.Menu()
        # The "\t..." syntax defines an accelerator key that also triggers
        # the same event
        helloItem = fileMenu.Append(-1, "&Make box cyan\tCtrl-H",
                "Help string shown in status bar for this menu item")
        fileMenu.AppendSeparator()
        # When using a stock ID we don't need to specify the menu item's
        # label
        exitItem = fileMenu.Append(wx.ID_EXIT)

        # Now a help menu for the about item
        helpMenu = wx.Menu()
        aboutItem = helpMenu.Append(wx.ID_ABOUT)

        # Make the menu bar and add the two menus to it. The '&' defines
        # that the next letter is the "mnemonic" for the menu item. On the
        # platforms that support it those letters are underlined and can be
        # triggered from the keyboard.
        menuBar = wx.MenuBar()
        menuBar.Append(fileMenu, "&File")
        menuBar.Append(helpMenu, "&Help")

        # Give the menu bar to the frame
        self.SetMenuBar(menuBar)

        # Finally, associate a handler function with the EVT_MENU event for
        # each of the menu items. That means that when that menu item is
        # activated then the associated handler function will be called.
        self.Bind(wx.EVT_MENU, self.OnHello, helloItem)
        self.Bind(wx.EVT_MENU, self.OnExit,  exitItem)
        self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)


    def OnExit(self, event):
        """Close the frame, terminating the application."""
        self.Close(True)


    def OnHello(self, event):
        """Say hello to the user."""
        #wx.MessageBox("Hello again from wxPython")
        b.color = color.cyan


    def OnAbout(self, event):
        """Display an About Dialog"""
        wx.MessageBox("This is a wxPython Hello World sample",
                      "About Hello World 2",
                      wx.OK|wx.ICON_INFORMATION)

app = wx.App()
frm = HelloFrame(None, title='Hello World 2')
frm.Show()
evtloop = wx.GUIEventLoop()
while True:
    rate(100)
    if evtloop.Pending():
        evtloop.Dispatch()
    b.rotate(angle=0.01, axis=vec(0,1,0))

Reply all
Reply to author
Forward
0 new messages