I am using Mayavi for a 3D visualization with TraitsUI. The scene is a trait of the type MlabSceneModel. I want to change the lighting and trying to access scene.light_manager in a function called on the activated event. However, scene.light_manager is always None.
Using mlab.figure() to creates a scene which has a light manager, but as I want the scene to be integrated in the UI and not in an additional window this is no option for me.
Good question which threw me for a loop at first.
Looking at the tvtk source, the light manager is added to the scene when the interactor is generated, which occurs after scene activation. Furthermore, the first thing I tried, which was to listen to 'scene:light_manager' doesn't work because the light manager is a Property trait that doesn't directly change. That said, if you listen to the object itself, which is referred to by the property, it will trigger a notification on creation. In other words, do this:
class Application(HasTraits):
scene=Instance(MlabSceneModel,())
...
#on_trait_change('scene:scene_editor:light_manager')
def muck_with_the_lights(self):
print self.scene.light_manager
Related
I am using Gtk and WebKit from gi.repository using python on X11 server (on raspbian).
I have a Gtk.OffscreenWindow with a WebKit.WebView widget in it and I am looking for a way to get a reference to the actual surface data of the OffscreenWindow.
Gtk.OffscreenWindow.get_surface returns a cairo.XlibSurface object but it doesn't seem there is a way to access pixel data of the surface (get_drawable is missing).
Gtk.OffscreenWindow.get_pixbuf returns a pixel buffer but to my understanding this is a copy of the actual surface data.
I used get_snapshot method of the WebKit.WebView but it creates a new cairo.ImageSurface.
My final goal is to use the reference to draw the surface using pi3d and get any surface updates without having to get a new snapshot of the OffscreenWindow (which is quite slow).
From the GTK3 developer reference,
GtkOffscreenWindow derives from GtkWindow only as an implementation detail. Applications should not use any API specific to GtkWindow to operate on this object.
GTKOffscreenWindows cannot or should not be operated on as windows, thus Cairo cannot be used on them.
#kapetanos, You are probably familiar with the pi3d.groups conversation here https://groups.google.com/forum/#!topic/pi3d/4x0fPerYKRU
and the subsequent integration into pi3d
https://github.com/pi3d/pi3d_demos/blob/master/GtkCube.py and https://github.com/pi3d/pi3d_demos/blob/master/PyQtCube.py
I realize this is too late for your original question but it might help someone arriving here from a google search!
I still don't understand why the X11 drawing surface system that works on other linux implementations doesn't work on the Raspberry Pi but other developers seem to resort to using libbcm_host.so
I have a PyQt4 application with a QMainWindow. From within that program I launch another QMainWindow that is used to draw a matplotlib plot. My approach is based on Eli Benderskys way of integrating matplotlib with PyQt.
class QtMatplotlibWindow(QtGui.QMainWindow):
"""Plot window to display data, is created by main application"""
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
If I instantiate QtMatplotlibWindow with parent=None the resulting window will be completely "independent", meaning that it has its own icon in the taskbar and is completely "detached" from the main application. So, for instance, I can bring anther application, say Internet Explorer, to the front and subsequently bring only the Matplotlib window to the front, the actual application staying in the background. However using parent=None results in the matplotlib window being thrown off the stack and closed without my willing to do so at some seemingly random point in time.
If, on the other hand, I pass the instance of the main application as the parent the two windows are "tied together", meaning that I cannot view them independently of each other.
How can I achieve the "best of both worlds"? I'd like to pass the instance of the main application as the parent, so that the generated plots will only be closed if I close the main application, but I would also like the plot windows to be entirely independent in showing and moving. I would expect there to be some property of QMainWindow that would allow me exactly that. I hope I could phrase my question clear enought, I feel like I lack the appropriate terminology.
The fact that your second window disappears at random time indicates that it has been garbage collected. You must keep a python reference to all your windows. For instance append your newly created window to a list somwhere in your application: windowlist.append(QtMatplotlibWindow())
I'm using: Maya2014 + pyqt4.8 + python2.7
I'm doing an application which allows you to speed up and simplify the selection of items in Maya. Is a selector which the user can attach to how the objects in the scene. Selection of objects in the window leads to the separation of objects in the scene. but on the contrary I can not find how to do.
How to catch an event that occurs when changing the selection of objects in the scene and process it further its program?
I really recommend if you doing a pretty heavy stuff then stay away from scriptjob. I prefer to go with API
def test(*args, **kwargs):
print "Fooo"
import maya.OpenMaya as OpenMaya
idx = OpenMaya.MEventMessage.addEventCallback("SelectionChanged", test)
#when ever you finish doing your stuff
OpenMaya.MMessage.removeCallback(idx)
You can use scriptJob command for this.
scriptJob let's you specify code or perform some action(s) when specified condition is met or a specified event is triggered.
For selection change, you'd use the event flag with "SelectionChanged" as parameter:
myScriptJobID = scriptJob(event=["SelectionChanged", your_function])
# You can later use this scriptJob's id to modify or delete it like so:
scriptJob(kill=myScriptJobID)
Check out the docs for more options.
until I found just such a solution based on maya api:
self.sJob = cmds.scriptJob(event=['SelectionChanged', self.myFnc])
This mechanism creates Maya event that calls my function when there is a change object selection.
Perhaps there is a more correct option. For example to get identifokator window maya and it make your event. Although I think that the use of maya api also not a bad option. The only downside is that you have to follow and remove scriptJob when closing a window, but it's a solvable problem.
I programmed a dot probe paradigm using the Standalone PsychoPy v1.80.03. After the dot probe I need a modified task that looks identical to the dot probe. I therefore pass the dot probe object in the 2nd task's constructor to re-use the window and the stimulus containers bound to this window.
Before the 2nd task starts I, however, need to input some information (e.g. the condition) using a gui.DlgFromDict. With the window from the dot probe still in fullscreen, the Dialog Box cannot be reached.
I tried to change the fullscreen to false by dotProbe.window.fullscr = False followed by a dotProbe.window.flip() but once the window is instantiated, changing this attribute doesn't seem to have an effect.
Closing the window with dotProbe.window.close() makes the Dialog accessible but there is no function that opens the window again to proceed in the 2nd task. Of course I could just construct a new window but as I said I need the identical setup with the stimuli at the exact same positions and all other parameters alike. Copying all parameters from one script to another to "manually" ensure them to look identical is undesired - as are workarounds like providing the input for the 2nd task prior to the dot probe since the scripts should be able be run independently (if no dot probe object is provided in the constructor, a new one is created to provide the default look).
Thanks for any help!
You don't want to close the window: that actually destroys the entire object, along with all of its stimuli and other attributes.
A solution to a similar problem was posted here: https://groups.google.com/forum/#!msg/psychopy-users/zq2E12vnYiI/6mXirJMlq3cJ
According to Jan Kramer there (and a subsequent improvement from jashubbard here: https://discourse.psychopy.org/t/bug-user-defined-gui-does-not-display-in-full-screen-on-mac-osx/2214/3), I think you want to use something like:
win.winHandle.minimize() # minimise the PsychoPy window
win.winHandle.set_fullscreen(False) # disable fullscreen
win.flip() # redraw the (minimised) window
This will hide the window away rather than closing it. Then restore it with:
win.winHandle.maximize()
win.winHandle.set_fullscreen(True)
win.winHandle.activate()
win.flip()
I have a Qt program with many buttons, user-interactable widgets, etc.
At one stage in the program, I would like all the widgets to temporarily 'stop working'; stop behaving to mouse clicks and instead pass the event on to one function.
(This is so the User can select a widget to perform meta operations. Part explanation here: Get variable name of Qt Widget (for use in Stylesheet)? )
The User would pick a widget (to do stuff with) by clicking it, and of course clicking a button must not cause the button's bound function to run.
What is the correct (most abstracted, sensible) method of doing this?
(which doesn't involve too much new code. ie; not subclassing every widget)
Is there anything in Qt designed for this?
So far, I am able to retrieve a list of all the widgets in the program (by calling
QObject.findChildren(QtGui.QWidget)
so the solution can incorporate this.
My current horrible ideas are;
Some how dealing with all the applications events all the time in one
function and not letting through the events when I need the
application to be dormant.
When I need dormancy, make a new transparent widget which recieves
mouse clicks and stretch it over the entire window. Take coordinates
of click and figure out the widget underneath.
Somehow create a new 'shell' instance of the window.
THANKS!
(Sorry for the terrible write-up; in a slight rush)
python 2.7.2
PyQt4
Windows 7
You can intercept events send to specific widgets with QObject::installEventFilter.
graphite answered this one first so give credit where credit is due.
For an actual example in PySide, here's an example you might draw some useful code from:
my_app.py
from KeyPressEater import KeyPressEater
if __name__ == "__main__":
app = QApplication(sys.argv)
eater = KeyPressEater()
app.installEventFilter(eater)
KeyPressEater.py
class KeyPressEater(QObject):
# subclassing for eventFilter
def eventFilter(self, obj, event):
if self.ignore_input:
# swallow events
pass
else:
# bubble events
return QObject.eventFilter(self,obj,event)