From: Piotr B. <pio...@gm...> - 2009-09-07 10:46:47
|
> Dears, > I've a problem integrating VPython5 with PyQt4. If anyone can help > me... > thanks a lot! > > > Here is the problem: > > The following code should show a PyQt4 form together with a VPython > scene. > Using VPython3 it works correctly, while useing VPython5 it crashes. > Does anyone has experience on facing this problem? > I would be very grateful if anyone can help me. > > from visual import * > from PyQt4 import QtCore, QtGui > import sys > > class MainWindow(QtGui.QMainWindow): > def __init__(self): > QtGui.QDialog.__init__(self) > > scene.visible = 1 > b = box() > > app = QtGui.QApplication(sys.argv) > window = MainWindow() > window.show() > sys.exit(app.exec_()) > > > replacing > > scene.visible = 1 > > > with > > scene.visible = 0 > > > it works and the Qt window is shown also with VPython5 (but the scene > can't be obviously seen!). Hi Matteo, Recently, I also tried to embed VPython window into QT using PyQT, but also with no luck :( Have you discovered anything new on that matter? Below is my code: from PyQt4 import QtCore, QtGui from visual import * class Ball(QtGui.QGraphicsItem): def __init__(self): super(Ball, self).__init__() self.shape = sphere(pos=(17.047, 14.099, 3.625),radius=1) if __name__ == '__main__': app = QtGui.QApplication(sys.argv) scene_qt = QtGui.QGraphicsScene() scene_qt.setSceneRect(-300, -300, 600, 600) scene_qt.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) # scene2 = display(title='Graph of position', width=600, height=200, center=(5,0,0), background=(0,1,1)) ball = Ball() scene_qt.addItem(ball) # ball = sphere(pos=(17.047, 14.099, 3.625),radius=1) view = QtGui.QGraphicsView(scene_qt) view.show() sys.exit(app.exec_()) Best, Piotr Byzia |
From: Jacob S. <sch...@ro...> - 2009-09-09 20:03:25
|
Sorry for sending this to the list, but I couldn't finding any other way of contacting the author of the vpython embedding code. On the website it claims: [quote] Remove Caption and Frame For real docking we want to remove the caption and the frame of the VPython window, so the user can't control the buttons and mouse actions on the caption and frame-borders. In windows this is not possible at all, because the frame settings can only be set at the time of creation of the window, of which we've no control at all. But with a trick we can realize the same effect, by the correct positioning and sizing of the window in a container. [/quote] But in reality it is quite plausible to change the caption and frame-borders in windows after the window is created. Google SetWindowLong and check out all of the constants that start with WS in the win32api (or MSDN) SetWindowLong allows you to change the style dword of a window after it has been created. Jacob Schmidt |
From: Stef M. <s.m...@ru...> - 2009-09-09 20:22:20
|
hi Jacob, I'm the author of those notes. thanks for the tip, I'll try it as soon as I've some more time. cheers, Stef Jacob Schmidt wrote: > Sorry for sending this to the list, but I couldn't finding any other way > of contacting the author of the vpython embedding code. On the website > it claims: > > [quote] > Remove Caption and Frame > > For real docking we want to remove the caption and the frame of the > VPython window, so the user can't control the buttons and mouse actions > on the caption and frame-borders. In windows this is not possible at > all, because the frame settings can only be set at the time of creation > of the window, of which we've no control at all. But with a trick we can > realize the same effect, by the correct positioning and sizing of the > window in a container. > [/quote] > > But in reality it is quite plausible to change the caption and > frame-borders in > windows after the window is created. > > Google SetWindowLong and check out all of the constants that start with > WS in > the win32api (or MSDN) > > SetWindowLong allows you to change the style dword of a window after it > has been > created. > > Jacob Schmidt > > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > > > |
From: Matteo M. <mat...@it...> - 2009-09-07 11:14:01
|
Hi, no good news. I have tried to create an independent thread to manage only VPython, but it didn't work :-) I really don't know how to solve the preblem. Thank you Matteo Piotr Byzia ha scritto: >> Dears, >> I've a problem integrating VPython5 with PyQt4. If anyone can help me... >> thanks a lot! >> >> >> Here is the problem: >> >> The following code should show a PyQt4 form together with a VPython >> scene. >> Using VPython3 it works correctly, while useing VPython5 it crashes. >> Does anyone has experience on facing this problem? >> I would be very grateful if anyone can help me. >> >> from visual import * >> from PyQt4 import QtCore, QtGui >> import sys >> >> class MainWindow(QtGui.QMainWindow): >> def __init__(self): >> QtGui.QDialog.__init__(self) >> >> scene.visible = 1 >> b = box() >> >> app = QtGui.QApplication(sys.argv) >> window = MainWindow() >> window.show() >> sys.exit(app.exec_()) >> >> >> replacing >> >> scene.visible = 1 >> >> >> with >> >> scene.visible = 0 >> >> >> it works and the Qt window is shown also with VPython5 (but the scene >> can't be obviously seen!). > > Hi Matteo, > > Recently, I also tried to embed VPython window into QT using PyQT, but > also with no luck :( > Have you discovered anything new on that matter? > > Below is my code: > > from PyQt4 import QtCore, QtGui > > from visual import * > > class Ball(QtGui.QGraphicsItem): > def __init__(self): > super(Ball, self).__init__() > > self.shape = sphere(pos=(17.047, 14.099, 3.625),radius=1) > > > if __name__ == '__main__': > > app = QtGui.QApplication(sys.argv) > > scene_qt = QtGui.QGraphicsScene() > scene_qt.setSceneRect(-300, -300, 600, 600) > scene_qt.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) > > # scene2 = display(title='Graph of position', width=600, > height=200, center=(5,0,0), background=(0,1,1)) > > ball = Ball() > scene_qt.addItem(ball) > > # ball = sphere(pos=(17.047, 14.099, 3.625),radius=1) > > view = QtGui.QGraphicsView(scene_qt) > view.show() > > sys.exit(app.exec_()) > > > > Best, > Piotr Byzia -- ------------------------------------------------------- Matteo Malosio, Eng. Researcher ITIA-CNR (www.itia.cnr.it) Institute of Industrial Technologies and Automation National Research Council via Bassini 15, 20133 MILANO, ITALY Ph: +39 0223699978 Fax: +39 0223699925 e-mail: mat...@it... ------------------------------------------------------- |
From: Stef M. <s.m...@ru...> - 2009-09-07 15:14:43
|
Bruce Sherwood wrote: > I myself don't know anything about these other environments into which people > want to embed Visual, so someone other than me will have to look for a solution. > I thought that there had been some discussion a few months ago in this list by > people who had successfully embedded Visual in some larger environment? > > yep in wxPython, see http://mientki.ruhosting.nl/data_www/pylab_works/pw_vpython_docking.html cheers, Stef > Bruce Sherwood > > Matteo Malosio wrote: > >> Hi, >> no good news. I have tried to create an independent thread to manage >> only VPython, but it didn't work :-) >> >> I really don't know how to solve the preblem. >> >> Thank you >> >> Matteo >> >> >> >> Piotr Byzia ha scritto: >> >>>> Dears, >>>> I've a problem integrating VPython5 with PyQt4. If anyone can help me... >>>> thanks a lot! >>>> >>>> >>>> Here is the problem: >>>> >>>> The following code should show a PyQt4 form together with a VPython >>>> scene. >>>> Using VPython3 it works correctly, while useing VPython5 it crashes. >>>> Does anyone has experience on facing this problem? >>>> I would be very grateful if anyone can help me. >>>> >>>> from visual import * >>>> from PyQt4 import QtCore, QtGui >>>> import sys >>>> >>>> class MainWindow(QtGui.QMainWindow): >>>> def __init__(self): >>>> QtGui.QDialog.__init__(self) >>>> >>>> scene.visible = 1 >>>> b = box() >>>> >>>> app = QtGui.QApplication(sys.argv) >>>> window = MainWindow() >>>> window.show() >>>> sys.exit(app.exec_()) >>>> >>>> >>>> replacing >>>> >>>> scene.visible = 1 >>>> >>>> >>>> with >>>> >>>> scene.visible = 0 >>>> >>>> >>>> it works and the Qt window is shown also with VPython5 (but the scene >>>> can't be obviously seen!). >>>> >>> Hi Matteo, >>> >>> Recently, I also tried to embed VPython window into QT using PyQT, but >>> also with no luck :( >>> Have you discovered anything new on that matter? >>> >>> Below is my code: >>> >>> from PyQt4 import QtCore, QtGui >>> >>> from visual import * >>> >>> class Ball(QtGui.QGraphicsItem): >>> def __init__(self): >>> super(Ball, self).__init__() >>> >>> self.shape = sphere(pos=(17.047, 14.099, 3.625),radius=1) >>> >>> >>> if __name__ == '__main__': >>> >>> app = QtGui.QApplication(sys.argv) >>> >>> scene_qt = QtGui.QGraphicsScene() >>> scene_qt.setSceneRect(-300, -300, 600, 600) >>> scene_qt.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) >>> >>> # scene2 = display(title='Graph of position', width=600, >>> height=200, center=(5,0,0), background=(0,1,1)) >>> >>> ball = Ball() >>> scene_qt.addItem(ball) >>> >>> # ball = sphere(pos=(17.047, 14.099, 3.625),radius=1) >>> >>> view = QtGui.QGraphicsView(scene_qt) >>> view.show() >>> >>> sys.exit(app.exec_()) >>> >>> >>> >>> Best, >>> Piotr Byzia >>> >> -- >> ------------------------------------------------------- >> Matteo Malosio, Eng. >> Researcher >> ITIA-CNR (www.itia.cnr.it) >> Institute of Industrial Technologies and Automation >> National Research Council >> via Bassini 15, 20133 MILANO, ITALY >> Ph: +39 0223699978 >> Fax: +39 0223699925 >> e-mail: mat...@it... >> ------------------------------------------------------- >> >> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > > > |
From: Bruce S. <Bru...@nc...> - 2009-09-07 14:53:03
|
I myself don't know anything about these other environments into which people want to embed Visual, so someone other than me will have to look for a solution. I thought that there had been some discussion a few months ago in this list by people who had successfully embedded Visual in some larger environment? Bruce Sherwood Matteo Malosio wrote: > Hi, > no good news. I have tried to create an independent thread to manage > only VPython, but it didn't work :-) > > I really don't know how to solve the preblem. > > Thank you > > Matteo > > > > Piotr Byzia ha scritto: >>> Dears, >>> I've a problem integrating VPython5 with PyQt4. If anyone can help me... >>> thanks a lot! >>> >>> >>> Here is the problem: >>> >>> The following code should show a PyQt4 form together with a VPython >>> scene. >>> Using VPython3 it works correctly, while useing VPython5 it crashes. >>> Does anyone has experience on facing this problem? >>> I would be very grateful if anyone can help me. >>> >>> from visual import * >>> from PyQt4 import QtCore, QtGui >>> import sys >>> >>> class MainWindow(QtGui.QMainWindow): >>> def __init__(self): >>> QtGui.QDialog.__init__(self) >>> >>> scene.visible = 1 >>> b = box() >>> >>> app = QtGui.QApplication(sys.argv) >>> window = MainWindow() >>> window.show() >>> sys.exit(app.exec_()) >>> >>> >>> replacing >>> >>> scene.visible = 1 >>> >>> >>> with >>> >>> scene.visible = 0 >>> >>> >>> it works and the Qt window is shown also with VPython5 (but the scene >>> can't be obviously seen!). >> >> Hi Matteo, >> >> Recently, I also tried to embed VPython window into QT using PyQT, but >> also with no luck :( >> Have you discovered anything new on that matter? >> >> Below is my code: >> >> from PyQt4 import QtCore, QtGui >> >> from visual import * >> >> class Ball(QtGui.QGraphicsItem): >> def __init__(self): >> super(Ball, self).__init__() >> >> self.shape = sphere(pos=(17.047, 14.099, 3.625),radius=1) >> >> >> if __name__ == '__main__': >> >> app = QtGui.QApplication(sys.argv) >> >> scene_qt = QtGui.QGraphicsScene() >> scene_qt.setSceneRect(-300, -300, 600, 600) >> scene_qt.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) >> >> # scene2 = display(title='Graph of position', width=600, >> height=200, center=(5,0,0), background=(0,1,1)) >> >> ball = Ball() >> scene_qt.addItem(ball) >> >> # ball = sphere(pos=(17.047, 14.099, 3.625),radius=1) >> >> view = QtGui.QGraphicsView(scene_qt) >> view.show() >> >> sys.exit(app.exec_()) >> >> >> >> Best, >> Piotr Byzia > > -- > ------------------------------------------------------- > Matteo Malosio, Eng. > Researcher > ITIA-CNR (www.itia.cnr.it) > Institute of Industrial Technologies and Automation > National Research Council > via Bassini 15, 20133 MILANO, ITALY > Ph: +39 0223699978 > Fax: +39 0223699925 > e-mail: mat...@it... > ------------------------------------------------------- > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > > > ------------------------------------------------------------------------ > > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |
From: Bruce S. <Bru...@nc...> - 2009-09-09 00:50:42
|
I've put a link to your web site in the "Contributed" section of vpython.org, and mentioned this in the FAQ. Bruce Stef Mientki wrote: > > Bruce Sherwood wrote: >> I myself don't know anything about these other environments into which people >> want to embed Visual, so someone other than me will have to look for a solution. >> I thought that there had been some discussion a few months ago in this list by >> people who had successfully embedded Visual in some larger environment? >> >> > yep in wxPython, see > http://mientki.ruhosting.nl/data_www/pylab_works/pw_vpython_docking.html > > cheers, > Stef >> Bruce Sherwood >> >> Matteo Malosio wrote: >> >>> Hi, >>> no good news. I have tried to create an independent thread to manage >>> only VPython, but it didn't work :-) >>> >>> I really don't know how to solve the preblem. >>> >>> Thank you >>> >>> Matteo >>> >>> >>> >>> Piotr Byzia ha scritto: >>> >>>>> Dears, >>>>> I've a problem integrating VPython5 with PyQt4. If anyone can help me... >>>>> thanks a lot! >>>>> >>>>> >>>>> Here is the problem: >>>>> >>>>> The following code should show a PyQt4 form together with a VPython >>>>> scene. >>>>> Using VPython3 it works correctly, while useing VPython5 it crashes. >>>>> Does anyone has experience on facing this problem? >>>>> I would be very grateful if anyone can help me. >>>>> >>>>> from visual import * >>>>> from PyQt4 import QtCore, QtGui >>>>> import sys >>>>> >>>>> class MainWindow(QtGui.QMainWindow): >>>>> def __init__(self): >>>>> QtGui.QDialog.__init__(self) >>>>> >>>>> scene.visible = 1 >>>>> b = box() >>>>> >>>>> app = QtGui.QApplication(sys.argv) >>>>> window = MainWindow() >>>>> window.show() >>>>> sys.exit(app.exec_()) >>>>> >>>>> >>>>> replacing >>>>> >>>>> scene.visible = 1 >>>>> >>>>> >>>>> with >>>>> >>>>> scene.visible = 0 >>>>> >>>>> >>>>> it works and the Qt window is shown also with VPython5 (but the scene >>>>> can't be obviously seen!). >>>>> >>>> Hi Matteo, >>>> >>>> Recently, I also tried to embed VPython window into QT using PyQT, but >>>> also with no luck :( >>>> Have you discovered anything new on that matter? >>>> >>>> Below is my code: >>>> >>>> from PyQt4 import QtCore, QtGui >>>> >>>> from visual import * >>>> >>>> class Ball(QtGui.QGraphicsItem): >>>> def __init__(self): >>>> super(Ball, self).__init__() >>>> >>>> self.shape = sphere(pos=(17.047, 14.099, 3.625),radius=1) >>>> >>>> >>>> if __name__ == '__main__': >>>> >>>> app = QtGui.QApplication(sys.argv) >>>> >>>> scene_qt = QtGui.QGraphicsScene() >>>> scene_qt.setSceneRect(-300, -300, 600, 600) >>>> scene_qt.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) >>>> >>>> # scene2 = display(title='Graph of position', width=600, >>>> height=200, center=(5,0,0), background=(0,1,1)) >>>> >>>> ball = Ball() >>>> scene_qt.addItem(ball) >>>> >>>> # ball = sphere(pos=(17.047, 14.099, 3.625),radius=1) >>>> >>>> view = QtGui.QGraphicsView(scene_qt) >>>> view.show() >>>> >>>> sys.exit(app.exec_()) >>>> >>>> >>>> >>>> Best, >>>> Piotr Byzia >>>> >>> -- >>> ------------------------------------------------------- >>> Matteo Malosio, Eng. >>> Researcher >>> ITIA-CNR (www.itia.cnr.it) >>> Institute of Industrial Technologies and Automation >>> National Research Council >>> via Bassini 15, 20133 MILANO, ITALY >>> Ph: +39 0223699978 >>> Fax: +39 0223699925 >>> e-mail: mat...@it... >>> ------------------------------------------------------- >>> >>> >>> ------------------------------------------------------------------------ >>> >>> ------------------------------------------------------------------------------ >>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >>> trial. Simplify your report design, integration and deployment - and focus on >>> what you do best, core application coding. Discover what's new with >>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>> >>> >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Visualpython-users mailing list >>> Vis...@li... >>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> >> >> > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |
From: Michele M. <mat...@gm...> - 2009-09-09 09:02:58
|
Hi All, I would like to add my two cents on this matter. If I understood correctly there is a growing need to integrate visual window with a bigger library, that can be QT, GTK, WxPython or you named it. Until now the approach that most of us has taken is to use something similar to the one pointed out in the previous mail and now in the FAQ. Shortly in this approach there are two threads running: (i) visual thread, that is a gtk thread which manage the display with the related zoom and rotate action. (ii) application thread which manage to run the library of choice with the application (e.g.: Another GTK thread, a QT one or wxPython.) This is all good until you want to do something different than zoom or rotate the object. Let's take the click example: http://vpython.org/contents/docs/visual/mouse_click.html What is suggested is to enter a while True loop which will exit only if that action will happen. This is called busy waiting and this is bad. This is bad because the CPU is constantly checking if something has been clicked. This happens every cycle making the computer unresponsive and degrading the performance of the program. It's acceptable for smaller program, it's completely cumbersome for bigger one. To avoid the loss of performance somebody has proposed to use a timer, as pointed out in the FAQ and the link above is one of the possible solution; but this is not a workaround and just move the problem to the update time of the timer without solving the problem. So the question is: Why am I able to rotate or to zoom the objects without wasting CPU and not to click on the objects? At the end of the day it's the same window and it's the same objects! Shortly because the first two events are embedded in the visual threads, and the GTK (as all the major UI library) is event driven. Only if an event happens, the main loop will respond, checking if the event is known and acts; otherwise nothing will happen. The last one comes from outside the main visual loop and because our event is not recorded in the visual loop, we need to: - Lock the application with a while true - Wait until our user click on the object. If our user does not click on the object and change his mind we can't do anything about it. He can only click. However he can still rotate and zoom because this event are managed (and recognised) by the visual main loop. What is the solution? Deploy a proper visual widget that can be integrated in GTK, QT, wxPython, windows and MAc. The code starti the display: http://visualpython.cvs.sourceforge.net/viewvc/visualpython/vpython-core2/src/gtk2/display.cpp?revision=1.57&view=markup should be divided in two chunks: - One class with all the visual goodness - Several class which extend the first class and provide a GTK widget, wxPython widget and Qt widget (and I guess windows and Mac.) This will give the possibility to insert visual in the main thread of any bigger application and and experienced developer can make a full use of the visual abilities registering as many event he wants (so the click, the rotate, the zoom, the selection of objects). For the beginner developer we have just to write a wrapper for the widget that will start the application and then everything can be used as before. This is what I understood looking with the code and developing a bit with visual (that is really great piece of software Thanks! :) ) Do you think is the right way to go? Cheers, Michele On Wed, Sep 9, 2009 at 1:50 AM, Bruce Sherwood<Bru...@nc...> wrote: > I've put a link to your web site in the "Contributed" section of vpython.org, > and mentioned this in the FAQ. > > Bruce > > Stef Mientki wrote: >> >> Bruce Sherwood wrote: >>> I myself don't know anything about these other environments into which people >>> want to embed Visual, so someone other than me will have to look for a solution. >>> I thought that there had been some discussion a few months ago in this list by >>> people who had successfully embedded Visual in some larger environment? >>> >>> >> yep in wxPython, see >> http://mientki.ruhosting.nl/data_www/pylab_works/pw_vpython_docking.html >> >> cheers, >> Stef >>> Bruce Sherwood >>> >>> Matteo Malosio wrote: >>> >>>> Hi, >>>> no good news. I have tried to create an independent thread to manage >>>> only VPython, but it didn't work :-) >>>> >>>> I really don't know how to solve the preblem. >>>> >>>> Thank you >>>> >>>> Matteo >>>> >>>> >>>> >>>> Piotr Byzia ha scritto: >>>> >>>>>> Dears, >>>>>> I've a problem integrating VPython5 with PyQt4. If anyone can help me... >>>>>> thanks a lot! >>>>>> >>>>>> >>>>>> Here is the problem: >>>>>> >>>>>> The following code should show a PyQt4 form together with a VPython >>>>>> scene. >>>>>> Using VPython3 it works correctly, while useing VPython5 it crashes. >>>>>> Does anyone has experience on facing this problem? >>>>>> I would be very grateful if anyone can help me. >>>>>> >>>>>> from visual import * >>>>>> from PyQt4 import QtCore, QtGui >>>>>> import sys >>>>>> >>>>>> class MainWindow(QtGui.QMainWindow): >>>>>> def __init__(self): >>>>>> QtGui.QDialog.__init__(self) >>>>>> >>>>>> scene.visible = 1 >>>>>> b = box() >>>>>> >>>>>> app = QtGui.QApplication(sys.argv) >>>>>> window = MainWindow() >>>>>> window.show() >>>>>> sys.exit(app.exec_()) >>>>>> >>>>>> >>>>>> replacing >>>>>> >>>>>> scene.visible = 1 >>>>>> >>>>>> >>>>>> with >>>>>> >>>>>> scene.visible = 0 >>>>>> >>>>>> >>>>>> it works and the Qt window is shown also with VPython5 (but the scene >>>>>> can't be obviously seen!). >>>>>> >>>>> Hi Matteo, >>>>> >>>>> Recently, I also tried to embed VPython window into QT using PyQT, but >>>>> also with no luck :( >>>>> Have you discovered anything new on that matter? >>>>> >>>>> Below is my code: >>>>> >>>>> from PyQt4 import QtCore, QtGui >>>>> >>>>> from visual import * >>>>> >>>>> class Ball(QtGui.QGraphicsItem): >>>>> def __init__(self): >>>>> super(Ball, self).__init__() >>>>> >>>>> self.shape = sphere(pos=(17.047, 14.099, 3.625),radius=1) >>>>> >>>>> >>>>> if __name__ == '__main__': >>>>> >>>>> app = QtGui.QApplication(sys.argv) >>>>> >>>>> scene_qt = QtGui.QGraphicsScene() >>>>> scene_qt.setSceneRect(-300, -300, 600, 600) >>>>> scene_qt.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) >>>>> >>>>> # scene2 = display(title='Graph of position', width=600, >>>>> height=200, center=(5,0,0), background=(0,1,1)) >>>>> >>>>> ball = Ball() >>>>> scene_qt.addItem(ball) >>>>> >>>>> # ball = sphere(pos=(17.047, 14.099, 3.625),radius=1) >>>>> >>>>> view = QtGui.QGraphicsView(scene_qt) >>>>> view.show() >>>>> >>>>> sys.exit(app.exec_()) >>>>> >>>>> >>>>> >>>>> Best, >>>>> Piotr Byzia >>>>> >>>> -- >>>> ------------------------------------------------------- >>>> Matteo Malosio, Eng. >>>> Researcher >>>> ITIA-CNR (www.itia.cnr.it) >>>> Institute of Industrial Technologies and Automation >>>> National Research Council >>>> via Bassini 15, 20133 MILANO, ITALY >>>> Ph: +39 0223699978 >>>> Fax: +39 0223699925 >>>> e-mail: mat...@it... >>>> ------------------------------------------------------- >>>> >>>> >>>> ------------------------------------------------------------------------ >>>> >>>> ------------------------------------------------------------------------------ >>>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >>>> trial. Simplify your report design, integration and deployment - and focus on >>>> what you do best, core application coding. Discover what's new with >>>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>>> >>>> >>>> ------------------------------------------------------------------------ >>>> >>>> _______________________________________________ >>>> Visualpython-users mailing list >>>> Vis...@li... >>>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>>> >>> ------------------------------------------------------------------------------ >>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >>> trial. Simplify your report design, integration and deployment - and focus on >>> what you do best, core application coding. Discover what's new with >>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>> _______________________________________________ >>> Visualpython-users mailing list >>> Vis...@li... >>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>> >>> >>> >> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: Bruce S. <Bru...@nc...> - 2009-09-09 16:21:55
|
It is interesting that VPython has recently become of interest to a community of expert programmers who would like to embed it in larger environments. I myself don't feel competent to think through or implement mechanisms to make this feasible (and currently I'm overcommitted to other work having to do with a major revision of a textbook and associated supplementary materials), and David Scherer, who does have the necessary competence, is not available, so what needs to happen is for someone or someones to step forward and try something. Bruce Sherwood Michele Mattioni wrote: > Hi All, > > I would like to add my two cents on this matter. > > If I understood correctly there is a growing need to integrate visual > window with a bigger library, that can be QT, GTK, WxPython or you > named it. > > Until now the approach that most of us has taken is to use something > similar to the one pointed out in the previous mail and now in the > FAQ. > > Shortly in this approach there are two threads running: > (i) visual thread, that is a gtk thread which manage the display with > the related zoom and rotate action. > (ii) application thread which manage to run the library of choice with > the application (e.g.: Another GTK thread, a QT one or wxPython.) > > This is all good until you want to do something different than zoom or > rotate the object. > > Let's take the click example: > http://vpython.org/contents/docs/visual/mouse_click.html > What is suggested is to enter a while True loop which will exit only > if that action will happen. This is called busy waiting and this is > bad. > > This is bad because the CPU is constantly checking if something has > been clicked. This happens every cycle making the computer > unresponsive and degrading the performance of the program. It's > acceptable for smaller program, it's completely cumbersome for bigger > one. > > To avoid the loss of performance somebody has proposed to use a timer, > as pointed out in the FAQ and the link above is one of the possible > solution; but this is not a workaround and just move the problem to > the update time of the timer without solving the problem. > > So the question is: > Why am I able to rotate or to zoom the objects without wasting CPU and > not to click on the objects? At the end of the day it's the same > window and it's the same objects! > > Shortly because the first two events are embedded in the visual > threads, and the GTK (as all the major UI library) is event driven. > Only if an event happens, the main loop will respond, checking if the > event is known and acts; otherwise nothing will happen. > > The last one comes from outside the main visual loop and because our > event is not recorded in the visual loop, we need to: > - Lock the application with a while true > - Wait until our user click on the object. > > If our user does not click on the object and change his mind we can't > do anything about it. He can only click. However he can still rotate > and zoom because this event are managed (and recognised) by the visual > main loop. > > What is the solution? > > Deploy a proper visual widget that can be integrated in GTK, QT, > wxPython, windows and MAc. > > The code starti the display: > http://visualpython.cvs.sourceforge.net/viewvc/visualpython/vpython-core2/src/gtk2/display.cpp?revision=1.57&view=markup > > should be divided in two chunks: > - One class with all the visual goodness > - Several class which extend the first class and provide a GTK widget, > wxPython widget and Qt widget (and I guess windows and Mac.) > > This will give the possibility to insert visual in the main thread of > any bigger application and and experienced developer can make a full > use of the visual abilities registering as many event he wants (so the > click, the rotate, the zoom, the selection of objects). > > For the beginner developer we have just to write a wrapper for the > widget that will start the application and then everything can be used > as before. > > This is what I understood looking with the code and developing a bit > with visual (that is really great piece of software Thanks! :) ) > > Do you think is the right way to go? > > Cheers, > Michele > |