This is my little Python programm Using Vpython
I want to rotate a box.
I want to use the boxes axis and not the one of the scene.
so for example if its rotated to the right and then i want to get the "nose" down, i want to do this in the view of the box...
imagine i was a jet ;)
BTW: I´m a python 3
from visual import *
a=box(size=(5,1,3),axis=(1,0,0))
def tasten():
"Looooopings "
if scene.kb.keys: #action on keyboard?
druck=scene.kb.getkey() #save to cache
if druck=='left':
a.rotate(angle=-1/100, axis=(1,0,0)) #links drehen
if druck=='right':
a.rotate(angle=1/100, axis=(1,0,0)) #rechts drehen
if druck=='up':
a.rotate(angle=-1,axis=(0,0,1)) #nose down
while True:
tasten()
I would recommend creating a box class that stores the orientation, as martineau is suggesting. The class would have a vector that stores its orientation, then a method to rotate it in whatever way required.
Related
I want to find the exact coordinates of the following parts of widgets as shown in the image in blue circles. I cannot figure out how to do this I have tried the following:
self.winfo_x()
self.winfo_y()
self.winfo_xy()
All of these will not give the answer and I do not know any other ways after any of my research. I am making a custom way to drag widgets and I am creating a containment system and need the beginning and end points.
Image(I could not show, I don't have the reputation needed):https://i.stack.imgur.com/ID3kX.png
EDIT:
Here is the picture of my code, I implemented the answer below by using hypothetical button called s:
https://i.stack.imgur.com/mnIaf.png
You can use the method winfo_x to get the x coordinate of the window relative to its parent. You can use winfo.parent to get the name of the parent window, and the method nametowidget to convert that to a widget. The solution is to combine those to recursively get the x or y coordinate of the widget and every parent.
It might look something like this:
def absolute_x(widget):
if widget == widget.winfo_toplevel():
# top of the widget hierarchy for this window
return 0
return widget.winfo_x() + absolute_x(widget.nametowidget(widget.winfo_parent()))
I am developing a tool in QGIS 3.16.2 and python 3.7 where i want to make a tool where i can identify any arbitrary point on the map canvas layer, which i already achieved. But when i select any point on the map canvas i want the drop down to only show points and not line and polygons too (see pictures further down).
The code i used to make map identify tool working is as follows:
def choose_a_point(self):
self.canvas = self.iface.mapCanvas()
self.identify_vector = QgsMapToolIdentify(self.canvas)
self.identify_vector.canvasReleaseEvent = self.store_m_value
self.canvas.setMapTool(self.identify_vector)
# Execute function that stores identified point info
def store_m_value(self, event):
result = self.identify_vector.identify(event.x(), event.y(), [], QgsMapToolIdentify.DefaultQgsSetting)
# Check if the selected feature is a point!
if result[0].mFeature.geometry().type() == QgsWkbTypes.PointGeometry:
if result:
pass # Do something useful here
When i click on a point in the map canvas i get following dropdown (seams like this function is built in to the QgsMapToolIdentify:
But i want to get the following result, so the lines and polygons are removed from the dropdown list:
I tried looking at the documentation for QgsMapToolIdentify on this page QT documentation - , but with no luck.
Hope someone can help me fix this problem.
I use OCC with python to visualize .igs and .stl format. In .stl file I have a mesh on my model and I want to know what vertex on this mesh was clicked. At least to get some kind of id. I see that the model that I choose automatically highlights without any settings, so I guess there is a way to do this. But I couldn’t find any information about it.
Okay, found it. In case someone else will need it:
display = self.occWidget._display
display.SetSelectionModeVertex() # This is the required function
display.register_select_callback(recognize_clicked)
where recognize_clicked is
def recognize_clicked(shp, *kwargs):
""" This is the function called every time
a face is clicked in the 3d view
"""
for shape in shp:
print("Face selected: ", shape)
Face selection - SetSelectionModeFace()
Vertex selection - SetSelectionModeVertex()
Edge selection - SetSelectionModeEdge()
Shape selection - SetSelectionModeShape()
Neutral (default) selection - SetSelectionModeNeutral()
That is all the modes that I've found in other examples. Please, if you find more, write in a comment that resource.
I'm new to tkiinter and i didn't manage to find a solution to my problem on internet.
First thing I need to draw a sort of table with triangles similar to the one in this picture (https://www.tilelook.com/system/tile_picture/resource/4973584/d3d_default_RE04MC017.png).
Then the user can choose a color somewhere (from a list or something similar) and change the color of a triangle by clicking on it. The most important thing is that i need to retrieve these information in the code (for each trinagle I need to know which color the user choosed).
Edit:
I still didn't write any code, but i know how to draw the table with Canvas and more or less how to handle the coloring part. The hard part for me is how to retrieve the informations in the code, I think it's like considering each element of the table like an independent object or something like that, but i have no idea how to do it.
I won't give you a complete solution but you may find the below a helpful starting point
import tkinter as tk
from random import choice
def getRandomColor():
return choice(['red','blue','green','yellow','white','goldenrod'])
def click(event):
print(vars(event))
item = event.widget.find_withtag('current')
event.widget.itemconfig(item,fill=getRandomColor())
root = tk.Tk()
root.grid()
c = tk.Canvas(root,width=300,height=300,bg='black')
c.grid()
c.create_polygon(0,0,100,0,50,100,fill='blue',tag='tri_1')
c.create_polygon(100,0,50,100,150,100,fill='yellow',tag='tri_2')
c.bind('<Button-1>',click)
root.mainloop()
This will create two triangles. If you click on a triangle it will change to a random color (from a small list of colors).
This will give you some ideas about
a. drawing polygons on a tkinter canvas
b. binding a function to a click
c. changing the properties of a canvas item
Hope you find this helpful
Hi guys I am relatively new to PyQt. I am trying create a custom plugin for Qgis which enables the user to select some features by drawing polygon on the canvas using mouse clicks and then performs intersection of the selected features with another layer. What I want to do is that when user right clicks on the canvas the polygon selection should stop. For this I have to identify between the right and left mouse signals. I have made a dummy function just to test this functionality:
def mousePressEvent(self):
print "code enters mousePressEvent function"
if event.buttons() == "Qt::LeftButton"
print"Left button pressed"
I am calling this function as follows:
QObject.connect(self.clickTool,SIGNAL("canvasClicked(QMouseEvent,Qt::MouseButton)"),self.mousePressEvent)
But I am unable to call the function. I guess I am doing something wrong in canvasClicked section. Any help in this matter would be much appreciated. Thanks in advance :)
The best way to achieve this is to use the QgsMapToolEmitPoint object. An example would be:
In your code, create a variable called emitPoint and in the run() function set it:
self.emitPoint = QgsMapToolEmitPoint(self.mapCanvas)
QObject.connect(
self.emitPoint,
SIGNAL("canvasClicked(const QgsPoint &, Qt::MouseButton)"),
self.clickedOnMap)
and create a function:
def clickedOnMap(self, pointOnMap, buttonUsed):
if (button==Qt.LeftButton):
....
the buttonUsed parameter has one of the values in the enum Qt::MenuButtons (as you can see in the link: http://doc.qt.io/qt-4.8/qt.html#MouseButton-enum).