Code changes - Python - Piphone - Raspberry Pi - python

Right now I'm working hard to finish a project named Pihpone; I've been following the adafruit tutorial and I've also bought all the items that were suggested by them
The problem is that..the code was written for 2,8" while I have a 3.5" screen
I've succeeded in making some changes like modifying the 320x240 with 480x320
Still not enough but I dont know what to do further; pls come with any suggestion;
Here are the screenshots:
Before
After
https://github.com/climberhunt/Piphone/archive/master.zip
From there you can download the code made by Adafruit; you can find the code in piphone.py.

The code in piphone.py appears to be using the pygame module to do the graphics. The problem is all the hardcoded coordinates and sizes for things like the Buttons. To fix this, the values must be computed at run-time and depend on the display resolution. Line 255 sets the display mode.
screen = pygame.display.set_mode(modes[0], FULLSCREEN, 16)
After doing that, you can get a video display information object from pygame.display.Info() and obtain the width and height of the current video mode, then use those values to scale and position the buttons.
You may also need to create different sets of image files for the various sizes of display you want the program to support.

Related

How to make a Kivy app maintain consistent size, when dragging between two screens of different pixel density?

I am experimenting with the sample code in the kivy_examples package. On a Macbook Pro with a Retina display, that is also connected to an external monitor with standard pixel density.
When I launch any of the example apps, the window first appears on the built-in Retina display and looks fine. When I then drag that window over to the external monitor, suddenly all of the widgets blow up in size.
There are a number of existing StackOverflow questions which deal with Kivy and pixel density. But the questions and answers all seem to deal with single-screen use cases. You don't know what the density of your target screen might be, so here's how to use the dp(...) function to configure for that screen at application startup, etc.
However, I can't find any discussion that deals with a multiple-monitor use case. Is there any way to have a Kivy app respond dynamically to pixel density changes, as the app is moved around between multiple monitors? As opposed to just configuring for a fixed density level at startup time?

How can I use python to identify a certain state of a graphic on the screen?

Let me make my question more clear. I am making a program where the program simulates a certain set of keypresses in a video game when a certain 'graphic' fully 'charges' up. This graphic is basically a vertical bar that fills up all the way to the top. How can I use python to interpret this graphic and return some info when the bar is visually fully charged up. The position of the graphic on the screen is always consistent and the state of the bar when it is indeed fully charged up, is always the same.
Probably the easiest way to achieve that is to use the ImageGrab module from Pillow.
And then use some pixels in the snapshot to determine if the bar is filling.
Pillow docs - https://pillow.readthedocs.io/en/3.0.x/reference/ImageGrab.html

Pygame/MoviePy - The video displays with a terrible framerate and the window size is bigger than my screen [duplicate]

This question already has answers here:
How to load and play a video in pygame
(3 answers)
Closed last year.
I've been looking around for a while trying to find a way to display videos in Pygame because of a new story video-game project. I finally stumbled across Moviepy which works alright...except that the video displays showing only one of the 24 frames each second and the window it displays in is bigger than by screen.
(on a Windows 10 laptop with an 11inch(I think) screen)
The sound is alright but the video also goes too fast so is out of sync.
I've tried the resize function as said on the docs but it gives no effect.
And I can't find anything to do with the framerate.
So I need a way to make the window smaller and correct the framerate.
This is the code I used:
from moviepy.editor import VideoFileClip
from moviepy.video.fx.resize import resize
import pygame
pygame.display.set_caption('My video!')
clip = VideoFileClip('Eleeza Crafter And The Cloud Colours Trailer.mp4')
clip.fx(resize, width=240)
clip.preview(fps=24)
pygame.quit()
Any help would be appreciated. Thanks :)
EDIT: I tested a different video at the same framerate and it works perfectly?
Then again it was just a simple line flying around the screen.
A 2 seconds google gave me this link.
It states :
A clip can be previewed as follows
my_clip.preview() # preview with default fps=15
my_clip.preview(fps=25)
my_clip.preview(fps=15, audio=False) # don't generate/play the audio.
my_audio_clip.preview(fps=22000)
Also (depending of your import method:
This way you can use clip.resize(width=240) instead of the longer clip.fx( resize, width=240).
Still from the documentation:
For advanced image processing you will need one or several of these packages. For instance using the method clip.resize requires that at least one of Scipy, PIL, Pillow or OpenCV are installed.
I don't know if this is the problem, but for screen size you should use pygame.display.set_mode((WIDTH, HEIGHT)) (change the WIDTH value to your desired width and the HEIGHT value to your desired height. Also, something I have noticed with pygame is that the big windows have lots of lag, so maybe a smaller window size would be recommended. I find that 500x500 is the maximum size for no lag (at least on my laptop)

Is there a way to paint/manipulate_pixels on the live PC screen using python?

I'm looking for a way to produce the output of my program in a way that the output appears on the live screen (output is typically a color filled shape) instead of appearing on a new window like it does for most Python programs.
I've attached an example of what I'm trying to achieve where only a part of the screen had its colors inverted (and will remain so as long as the script runs) and the rest remained as it is. NOTE:I've made the example using Photoshop.
I've tried PIL,OpenCV, Mss,curses.....but all these modules produce an output on a separate window.
Is what I'm trying to achieve even possible? If not with Python is it possible with C++? or is this something beyond the abilities of a programming language and needs to be done at the Operating System level itself?
An example illustration of what I'm trying to achieve

Pyautogui - Problems with Changing Screenshots

ok, I've got into programming with python and thus far was having a fair amount of success. I've typed up a program that uses pyautogui to automates atask I need to do on a monthly basis.
I took Screenshots of where I needed the mouse to click and when all was done I had a working program that searched the screen for the button to clicked, controlled the mouse that location, and printed out the report I needed. So, all I needed to do was plug it into the task scheduler and it would do the work for me!
Several days afterwards, I decided to go ahead and schedule it. I ran the program again, and it crashed! Long Story short, the screen shots didn't match. I took a screen shot again, and zoomed both images 800% in Paint, and check the pixel next to the "I" in The two different images and sure enough the rgb values are different.
I tried several other places to, and while they looked the same... The rgb values are different by maybe one or two points! I'm curious as to why is this happening!
Use confidence, default value is 0.999. Reason is pyscreeze is actually used by pyautogui which has the confidence value which most likely represents a percentage from 0% - 100% for a similarity match. Looking through the code with my amateur eyes reveals that OpenCV and NumPy are required for confidence to work otherwise a different function would be used that doesn't have the confidence value.
for example:
by doing pyautogui.locateCenterOnScreen('foo.png', confidence=0.5) will set your confidence to 0.5, which means 50%.

Categories

Resources