Are there any libraries to that can be used to write a screen capture in Python.
Can it be made to be cross-platform?
Is it possible to capture to video?
And if could that be in real-time?
Or would it be possible to directly
generate flash movies?
screen capture can be done with PIL thanks to the ImageGrab module
For generating Flash movies, you can have a look at ming. I am not sure that it has this capability but it worths a look.
you can try this also
may be this URL can help you out.
its castro !!! see the sample code below may be useful....
>>> from castro import Castro
>>> c = Castro()
>>> c.start()
>>> # Do something awesome!
>>> c.stop()
I don't know of any general purpose libraries. I did this for windows and used some codeproject.com code in a DLL, called from ctypes.
Video capture is probably harder; I took screenshots really fast using the trivial codeproject way and got maybe 8fps. If that's not sufficient you are probably going to need a library that is optimized to your use case; e.g. tightVNC or CamStudio or something. CamStudio can export flash and is OSS.
I've written a cross-platform screen capture tool in wxPython.
See download "GeneralScreenShotWX.py" in subtopic "A Flexible Screen Capture App"
under topic "WorkingWithImages"
# http://wiki.wxpython.org/WorkingWithImages#A_Flexible_Screen_Capture_App.
It's working on MSW, OS X and one Linux distro and requires no extra wxPython packages.
One way to capture a video of the user's screen (certainly for X11, not sure about Windows) is to use gstreamer with the ximagesrc plugin. There are Python bindings available here, though I haven't used gst-python before. I know Istanbul, an open source screencasting app, uses it - viewing its source might help you.
To capture static images, I've used PyGTK before on Linux to capture the user's screen. This should also work on Windows and Mac, though I haven't tried it. Here's a small snippet:
import gtk
win = gtk.gdk.get_root_window()
width, height = win.get_size()
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
pb = pb.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0, width, height)
pb.save('path to file', 'png')
See the GTK docs for more info.
Hope that helps!
I guess all possible ways to take Python controlled screenshots are covered at https://github.com/ponty/pyscreenshot
Related
I have a laser pointer that I'm using along with my webcam as a drawing tablet, but I'd like to use the extra buttons on it too. They seem to be bound to Page Up, Page Down, Escape, and Period. I can't seem to figure out a way to get the input(which is handled like it's a keyboard) without any windows being selected.
I've tried serial and pyusb, but I've had issues with both of those. I got it to work with Pygame, but as far as I know, you can't receive input without the window it creates being selected. Any ideas?
You could try making a python key-logger. However, it would be much easier to just use Pygame.
CodeSurgeon answered me in a comment.
Looks like there are a lot of youtube tutorials on the subject, surprisingly. This one shows a cross-platform approach using the pynput module, while this one looks to be using a windows-specific approach (pyhook and pythoncom). Can't vouch for either of these as I just found them through some searching, and I am sure there are others as well.
I found that pynput works for me. (Windows 10/Python 3.4)
I'm looking for a Python 3.x library that is able to allow interaction with other programs.
For example, I already have some sort of command-line interface which I have developed in python, and I
want to be able to enter, say "1", and have another program open. From here, I wish to hit another
input like "2" and have it manipulate the GUI that opens (for example, for it to "click" the Configurations
dropdown bar and select an option, perhaps modify a few settings, apply, and then possibly also automatically
enter some text). The reason I'm doing this is for test automation.
I've already tried using pywinauto, but I've found it to not be compatible for Python 3! :(
Is there another possible approach to this? Thanks in advance!!!
P.S. I may have forgotten to mention that I'm using Windows 7 but with Python32
You could look into sikuli. It lets you automate clicks and other actions based on region or matched graphic. Fairly smart. Is there a reason you're dead set on using py3?
Py3-compatible pywinauto released! New home page: http://pywinauto.github.io/
P.S. I'm maintainer of pywinauto.
Late answer, but have a look at pyautogui which enables you to move the mouse and press keys. I used it for the following snippet which launches an emulator and presses keys.
import pyautogui as pg
import os
import time
game_filepath = "../games/BalloonFight.zip"
os.system(f"fceux {game_filepath} &")
time.sleep(1)
keys_to_press = ['s', 's', 'enter']
for key_to_press in keys_to_press:
pg.keyDown(key_to_press)
pg.keyUp(key_to_press)
time.sleep(2)
im = pg.screenshot("./test.png", region=(0,0, 300, 400))
print(im)
A more detailed expalanation can be found here: Reinforcement learning to play Nintendo NES games
I created a pywinauto fork on GitHub that's compatible with Python 3:
https://github.com/Usonaki/sendkeys-py-si-python3
I only did basic testing, so there might still be some circular import related problems that I haven't found.
I'm developing a screen shot utility in Python. At the moment it is specifically for Linux. So far I have the ability to take a screen shot of the full desktop, and have it upload to Imgur, then copy the link to clipboard. Now I want to expand into functions such as screen shots of the active window, or of a specific selection. If anyone could help, I'd love to know what kind of module would work best for this, and how to implement such a module.
The functionality will depend on what you are using for image grabbing.
With PIL
http://effbot.org/imagingbook/imagegrab.htm
With GTK
To take a screenshot of active window :
http://faq.pygtk.org/index.py?req=show&file=faq23.039.htp
Also look at the pixbuf api
http://library.gnome.org/devel/gdk-pixbuf/
http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html
Off topic
There are some screen cast tools: http://pypi.python.org/pypi/castro/1.0.4
i want that upon opening my N73's camera cover,the camera software keeps working as usual,but that it is blocked by a black screen covering the whole screen so that it appears that the camera is not working... I know my requirement is weired but i need this.. ;)
Can anyone guide me to write a python script that does exactly this... i searched a lot over net for any existing apps but couldnot find one..
Thanks for helping..
I'm rather sceptical whether this can be achieved with PyS60. First of all, AFAIK for PyS60 program you'd need to start the interpreter environment first, autostarting when camera starts probably won't be possible.
Also, opening the camera cover probably does not have any callback so you won't be able to detect it from python however, you could try something like this presented in PyS60 1.4.5 doc (http://downloads.sourceforge.net/project/pys60/pys60/1.4.5/PythonForS60_1_4_5_doc.pdf):
>>> import appuifw
>>> import camera
>>> def cb(im):
... appuifw.app.body.blit(im)
...
>>> import graphics
>>> appuifw.app.body=appuifw.Canvas()
>>> camera.start_finder(cb)
Instead of blitting im you could just blit a black screen and store im. Or something. But seriously, this sounds like some very bad prank...
What is the best way to use PyGame (SDL) within a PyGTK application?
I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to manage both GTK and SDL events.
I've never attempted it myself, but hearing plenty about other people who've tried, it's not a road you want to go down.
There is the alternative of putting the gui in pygame itself. There are plenty of gui toolkits built specifically for pygame that you could use. Most of them are rather unfinished, but there are 2 big, actively maintained ones: PGU and OcempGUI. The full list on the pygame site is here.
You may be interested in this message thread. Looks like they recommend against it.
PyGame works much better when it can manage its own window, or even better, use the whole screen. GTK has flexible enough widgets to allow creation of a drawing area.
This page may help, though, if you want to try it.
There's a simple solution that might work for you.
Write the PyGTK stuff and PyGame stuff as separate applications. Then from the PyGTK application call the PyGame application, using os.system to call the PyGame application. If you need to share data between the two then either use a database, pipes or IPC.
http://faq.pygtk.org/index.py?file=faq23.042.htp&req=show mentions it all:
You need to create a drawing area and set the environment variable SDL_WINDOWID after it's realized:
import os
import gobject
import gtk
import pygame
WINX = 400
WINY = 200
window = gtk.Window()
window.connect('delete-event', gtk.main_quit)
window.set_resizable(False)
area = gtk.DrawingArea()
area.set_app_paintable(True)
area.set_size_request(WINX, WINY)
window.add(area)
area.realize()
# Force SDL to write on our drawing area
os.putenv('SDL_WINDOWID', str(area.window.xid))
# We need to flush the XLib event loop otherwise we can't
# access the XWindow which set_mode() requires
gtk.gdk.flush()
pygame.init()
pygame.display.set_mode((WINX, WINY), 0, 0)
screen = pygame.display.get_surface()
image_surface = pygame.image.load('foo.png')
screen.blit(image_surface, (0, 0))
gobject.idle_add(pygame.display.update)
window.show_all()
while gtk.event_pending():
# pygame/SDL event processing goes here
gtk.main_iteration(False)
I tried doing this myself a while ago, and I never got it to work perfectly. Actually I never got it to work at all under Windows, as it kept crashing the entire OS and I ran out of patience. I continued to use it though as it was only important it ran on Linux, and was only a small project. I'd strongly recommend you investigate alternatives. It always felt like a nasty hack, and made me feel dirty.
The Sugar project has several Activities built with PyGTK and PyGame.
They wrote a support lib to achieve this, called Sugargame. You should be able to modify it for regular PyGTK apps instead of Sugar.
Here's a chapter in Sugar's development book about how to use it.
The lib allows for communicating events between GTK and PyGame.
Enjoy!