How can i rotate a specific screen with python? - python

Im trying to make a arduino based rotation of the monitor detection and i have a problem because i cannot find how to change a specific screen rotation.
My code:
import rotatescreen
screen = rotatescreen.get_primary_display()
screen.set_landscape()

Related

exporting python turtle drawing to video

Is there a way to export a python turtle drawing to a video?
The video should contain the real-time drawing process.
In particular I'm not interested in a screen-recording workaround, but a solution that would work in a headless system like a cloud environment.
Here's an example of a turtle drawing
import turtle
tr = turtle.Turtle()
rad = 80
tr.circle(rad)
turtle.done()

Overlay all screens and draw rectangle with a mouse

I am working on tiny program to capture screen print, I want to do it in a similar fashion that Win Snipping Tool is working. First I need to overlay all screens with a 50% opacity layer and then, using the mouse, draw a rectangle and read vertices coordinates. Honestly, I have no idea how to bite this. I tried with win32api / gui and it is great to get mouse coordinates, but still was unable to draw a rectangle. My idea (one of many) is to (using PIL / ImageGrab) take shots of both displays, put an overlay and print them as a full screen on all windows, but I failed while doing this. Other idea is to take img grab and create two new windows using BeeWare / Toga (that is GUI framework I am using) in full screen, but I was unable to find any method to open window on second display. Any ideas and hints will be greatly appreciated, I am really counting on you, as I feel I reached dead end.
Well,It is very easy to use tkinter.
Ok,It is the principle when I make my screenshot application:
User presses the button to start.
Make a new window whose width and height should full cover all the screens,and hide the title bar(If it is had to achieve,maybe use width=9999 and height=9999).
Take a screenshot of all the desktop(You can use ImageGrab.grab((),all_screens=True)) to do that.
Make the screenshot showed in a Canvas(I know that toga have this widget).
Start your mouse listener thread and save the position of pressed.
When user moves his mouse,create a rectangle(toga's Canvas have a function rect()).Maybe use this rect(pressed_x,pressed_y,move_x,move_y).And delete the last rectangle(Then it will always show only one rectangle).
When user released his mouse,save the position of released.And use ImageGrab.grab((pressed_x,pressed_y,released_x,released_y),all_screens=True) to crop the selected area.
If you want to show it in application interface.toga has a widget called ImageView.You can put the image in it.

Pyglet/OpenGL point sprites

I decided to use pyglet and opengl to make a 3D FPS game. I am trying to create a Doom-like effect where certain images are kept 2D (always face the camera) in a 3D environment. A few google searches later, and I come across point sprites. Currently trying to implement these. Here is my code:
playerimg = pyglet.image.load(r"img\front.png").texture
glBindTexture(GL_TEXTURE_2D, playerimg.id)
glEnable(GL_POINT_SPRITE)
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)
x,y,z = 0,1,0
glBegin(GL_POINTS)
glVertex3f(x+2,y,z)
glVertex3f(x,y,z)
glVertex3f(x,y+2,z)
glVertex3f(x+2,y+2,z)
glEnd()
I get no errors when I use this code, however, the image does not appear anywhere on screen. I have already implemented (camera) movement and rotation, but I never see the image.

saving modified screens in python/pygame for later use

When using python and pygame: after loading the screen with the background image and blitting new objects (Text, circles, rectangles, etc.), is there a way to save the modified screen so as to be recalled later in the program? Specifically, I am setting the background and blitting new objects and would like to save the screen image with all of the blits in intact so it can be used later in the program as a new background upon which sprites can be manipulated. Any suggestions welcomed!
Blitting works both ways, meaning you can blit something onto the display screen, but you can also blit the screen onto another surface. So simply make a new surface the same size of your display surface and blit the screen onto that surface for later use.
found a solution and it works better than I expected:
after blitted my raw background onto my surface and then adding numerous circles, rectangles and text to make an image with multiple dial, gauges and labels I ran the following:
pygame.display.update()
window = pygame.display.set_mode((800,480),0,32)
pygame.image.save(TFT,"screen_update.jpg")
the new image is saved to disk(XDcard on my RPi2) as "screen_update.jpg"
then I simply change the name to "ANAL_update.jpg" and use that as the background on my next program run. I commented out all of the code used to create the rectangles, circles and labels and it works. I will add an selectable "update" routine to the program and move all of extra drawing and labelling to that routine to be used when I wish to change the layout of he background. I like the fact that the program creates a new updated file that just needs to be renamed for use and for copying the background to other machines.
note: This is working on my RaspberryPi 2B with HDMI output to a 42" HD tv for development, but it is intended to run on an RPi3B with he official RPi 7 inch TFT display. Thanks to all of you that responded and to the others who left pertinent code for previous questions similar to mine.

Getting windows (client coordinates) for python window

I have loaded an image using Tkinter in Python. It opens up in a python window. If I try to get coordinates of a part of the image, it gives me coordinates relative to the python window that opened up. However, I would like to actually be able to find the client coordinates of that part of the image i.e. coordinates in relation to the actual computer screen.
I looked into using win32gui and somehow trying to get coordinates from the device context, however I could not figure out a way.
Any help is much appreciated!
You can use root.winfo_rootx() and root.winfo_rooty() to get the coordinates of the top left corner of the tkinter window. You can add those to the event.x and event.yto get the screen coordinates.

Categories