I have a high poly object drawn in a QOpenGLWidget, and I want to do a feature so when I press a key this widget is drawn on another window, and the other one to be left in the back (so still visible). So I would need a way to duplicate it, without redrawing, because redrawing a high poly object takes time. Is there a way I can achieve this?
Related
I'm using Glade to design a UI, and I'm struggling to figure out how to reorder elements such that one element is on top of the other vertically. As an example, I added a draw element after a slider, picture, but I want to still be able to touch the slider through the draw element. Beyond reordering things manually in the XML/.glade file, how would I move things around such that the draw element gets "drawn" first with the slider on top of it?
Die clarification. So far i See from the picture (I dont understand the Text), you create radio buttons and in one type of it, you want to dynamically letting a new window area appearing with a slider in it when clicking?
I've essentially recreated the matlab data cursor on my custom pyplot figure tool. It allows dragging and left/right arrow key presses to update an annotation box's position along a line, etc. My problem comes from when there are a large number of lines. The data cursor still works, but dragging its position around is a nightmare and is extremely slow. The problem stems, I'm rather certain, from my canvas.draw() calls since it's redrawing the entire figure every time the data cursor moves.
I'm working towards implementing options like blit() and "restore_region()", but I'm having great difficulty implementing them. Can anyone provide even a shell of how to make this work? I can't include actual code due to the classification of the code itself, but I can give a small pseudo-code example.
def create_anno(self):
# Do annotation creation stuff here
self.background = self.figure.canvas.copy_from_bbox(self.axis.bbox)
def key_press(self):
self.figure.canvas.restore_region(self.background)
# Do update position/text stuff here
self.figure.canvas.blit(self.axis.bbox)
self.figure.canvas.flush_events()
The key_press function is called normally, but the annotation box doesn't move anymore. Most examples use draw_artist() between their restore_region() and blit() calls, but annotation doesn't have that. I just want to update a little annotation box's position across a figure without having to redraw the entire axis. Any ideas?
Thanks!
I've got a matplotlib plot in which I've modified the toolbar/status bar information much as in this question. This works just fine and the necessary information is displayed as I need it.
However, I often need to update the plot (which is done by calling draw() on the canvas object) with new data. What happens though is that the toolbar/status bar information won't update until the mouse is moved again. I'd like this information to update as soon as the canvas is redrawn because some of this information is pertinent to the new plot.
My attempt at making this happen was to force a mouse motion event to trigger. I've tried to trigger the event from the canvas via self.canvas.motion_notify_event(0,0) but that doesn't seem to work well. I can see that the toolbar itself has a mouse_move method, but I don't know how to trigger it (or even if it's what I want to trigger).
How can I force the toolbar/status bar information to update during a plot redraw without requiring the user to move their mouse slightly?
Did a lot of digging and figured it out. The motion_notify_event method was what I was looking for, I was just using it wrong. You can fake matplotlib out and trigger a MouseEvent by using this function, which will then make matplotlib call all functions that respond to MouseEvents, including updating the toolbar/status bar information.
The key here is that I needed to trigger the MouseEvent as if it happened within the axes object, not the entire figure. The input to the function is the (x,y) pixel position of the event with respect to the lower left corner of the figure window. By using (0,0) as I did in my question, I was saying the mouse event happened at the lower left corner of the figure window, not on the axes itself. Matplotlib does not show toolbar/status bar information unless the cursor is on the axes.
What you can do then is pick some random pixel position on the axes and use that as the position. A simple way to pick such a pixel position is using matplotlib transformations.
The following now works for me:
canvas.motion_notify_event(*ax.transAxes.transform([0,0]))
Of course in my case I'm not displaying the data coordinates of the mouse, so your use cases may vary.
I have some color cyling of sprites I'm handling in some animations. I break each frame (child) of the animation into a subsurface of a sprite sheet (parent), and I want to color cycle the parent and have the chldren color cycle as a result. Looking at the pygame documentation, it seems like the palettes of the subsurfaces are independent of the parent. How would you go about this, without handling each frame individually. Thanks
You can't... You answered your own question. The only way that this is possible without cycling through each one manually is to create a class, a method or something else of your choice.
So I'm going to put all of the frames or children into an array.
children = [pygame.Surface((200, 200))]
I'm only going to have one cause I'm lazy and you were too with how little work and effort you showed that you put into it.
So here is the method to update color.
def updateColor(color):
parent.set_pallet(color)
for child in children:
child.set_pallete(color)
That's the easiest way that I can think of.
Other than that no, no you can not.
Suppose I have drawn simple text (say just the letter 'x') with some font parameters (like size 20 font, etc.) onto an (x,y) location in a QLabel that holds a QPixmap. What are the relevant methods that I will need to override in order to detect a mouse event when a click occurs "precisely" over one of these drawn x's.
My first instinct is to lookup the stored (x,y) locations of drawn points and if the mouse current position is inside a tiny box around that (x,y) position, then I will execute some functionality, like allowing the user to adjust that point, and if not then execute normal mouse event functionality. However, the points I am interacting with are tracked features on human faces, like eyes, etc. Often, when someone is turning at an odd angle with the camera, etc., two distinct tracked points can be pretty much right on top of each other. Thus, no matter how well the user focuses on the desired key point, if there is some tolerance in the logic criteria in mouse event handling, there will be cases where the logic believes two different points are being clicked.
I want to minimize this sort of issue without making unreasonable precision of the click criteria. Is there some fundamentally different way to interpret selection of text (as in, when text is drawn to a pixmap, does there become any sort of attribute of that pixmap that is aware that text has been drawn at (x,y) and so that's what the user must be trying to click on?)
Any advice or examples of this sort of thing in PyQT would be greatly appreciated.
Although you alluded to your plans for user interaction in your previous question, it is now clear that the Graphics View Framework may be more appropriate for what you are trying to do.
This is distinctly different from drawing in a widget. With this framework, you create a scene composed of graphic items (QGraphicsItem subclasses) and then assigne the scene to a view. Through the view, you can interact with the items in the scene. They can generate click events and even be dragged around. The documentation is extensive and looks complicated but conceptually, I think it is easier to understand.