I just started up with python.I lately got a project where I have to make a powerpoint slideshow.This has to be done using leap motion sdk and python.So my powerpoint will be gesture based.
How do I deploy this on my desktop in
such a away that I just need to click on my desktop app or the ppt file itself, I get
started with the powerpoint like on windows.
I need to detect the finger gestures using python and integrate it
to next - previous functionality.
Can I get some guidance on powerpoint with PPT?
I have got the API,Documentation,SDK and I am learning python too.
The pywin32 library has a win32com.client module that lets you use COM API to control PowerPoint.
For example, this code will add a slide with an oval in it:
import win32com.client
Application = win32com.client.Dispatch("PowerPoint.Application")
Presentation = Application.Presentations.Add()
Base = Presentation.Slides.Add(1, 12)
oval = Base.Shapes.AddShape(9, 100, 100, 100, 100)
This IPython notebook has step-by-step examples on how to create a PowerPoint presentation, add objects to it, and make those objects interact in PowerPoint.
While this will allow you to use PowerPoint as an output interface, you need a different mechanism for sending messages back from PowerPoint to Python. One way is to set up a Macro that runs on a click event that interacts with a COM server set up in Python.
The documentation for this is not fantastic. However, using win32com and the PowerPoint API, you should be able to accomplish what you want to do.
The relevant commands are:
import win32com.client
import time
app = win32com.client.Dispatch("PowerPoint.Application")
presentation = app.Presentations.Open(FileName=u'C:\\path\\to\\mypresenation.pptx', ReadOnly=1)
presentation.SlideShowSettings.Run()
time.sleep(1)
presentation.SlideShowWindow.View.Next()
time.sleep(1)
presentation.SlideShowWindow.View.Next()
time.sleep(1)
presentation.SlideShowWindow.View.Previous()
time.sleep(1)
presentation.SlideShowWindow.View.Exit()
app.Quit()
Once you have a reference to the presentation, you can use this inside the code/functions where you handle the gestures.
you can some some pointers on what you want to do from this guy https://github.com/sanand0
look at his https://github.com/sanand0/pptx-git repo you should definitely get some pointers.
Hope this helps
You might be interested in the Google Slides API. I did some looking around and found this by far the best documentation and easiest setup with regards to python and doing a slide show. Here is a nice quick start guide...
https://developers.google.com/slides/quickstart/python?authuser=1
Use can use win32com
Here is code for slide show run, next, and back slide.
import win32com.client
import time
Application = win32com.client.Dispatch("PowerPoint.Application")
Presentation = Application.Presentations.Open("D:\\dataset\\slide.pptx")
print(Presentation.Name)
Presentation.SlideShowSettings.Run()
time.sleep(3)
Presentation.SlideShowWindow.View.Next()
time.sleep(3)
Presentation.SlideShowWindow.View.Next()
time.sleep(3)
Presentation.SlideShowWindow.View.Previous()
time.sleep(3)
Application.Quit()
Reference: https://github.com/tuantdang/SlideControlUsingBioSigal
Related
Is it possible to create a script in Python or IronPython that automatically clicks on some widgets of an open WPF (C#) window? It would be a task that would solve my life but I have no idea where to start.
Thanks in advance.
Autoit, pyautogui, pywinauto and clicknium, all these libraries support automating WPF applications.
You may need to use tools like uispy and inspect to help you locate the control if you are using pyautogui and pywinauto.
Sample code for pywinauto looks like below:
from pywinauto.application import Application
app = Application(backend='uia').start("notepad.exe")
main = app.window(title='*Untitled - Notepad', control_type='Window')
closeBtn=main.child_window(title="Close", control_type='Button')
closeBtn.click_input()
You can install clicknium vscode extension to help you locate the control if you are using clicknium.
Sample code looks like below:
from clicknium import locator, ui
ui(locator.notepad.button_close).click()
Quick Google search revealed the following tutorial:
https://www.geeksforgeeks.org/mouse-keyboard-automation-using-python/
If you are dead set on using python or any code for that matter, a simple macro recorder may give you more faster:
https://www.macrorecorder.com/
This does not account for any deviation in the application or OS. If another popup or window is open, the script/macro will just continue happily. If you are after UI testing, you may want to look at professional UI test tools.
you can see this example, demonstrate one automation case for both desktop application and web application.
Does anyone know the trick to pywinauto's find_window function? I am building an application with kivy, and trying to use pywinauto to bring an .exe to the foreground, using the following code:
SetForegroundWindow(find_window(title='program.exe'))
I simply want to identify a currently open .exe, and bring it to the foreground. I have looked here https://pywinauto.github.io/docs/code/pywinauto.findwindows.html and it seems "title=" is what I want.
Does anyone know how to point to the .exe with pywinauto?
I think title is for window title (i.e. "python - Cannot find..." in case of this tab), are you sure it not more like "process='program.exe'" ?
if it needs to be and int then its pid (process id) and you can use this to get process id by title:
import win32gui,win32process
def get_window_pid(title):
hwnd = win32gui.FindWindow(None, title)
threadid,pid = win32process.GetWindowThreadProcessId(hwnd)
return pid
Eventually have at this answer as it contains really nice class for getting windows Python Window Activation, i dont want to copy paste, but use it and then you can do:
w = WindowMgr()
w.find_window_wildcard(".*Hello.*")
w.set_foreground()
find_window is low level function I wouldn’t recommend to use.
The right thing is Application object connected to the target process. It can be used so:
from pywinauto import Application
app = Application(backend=“uia”).connect(path=“program.exe”)
app.WindowTitle.set_focus()
If you have several app instances, there is a Desktop object to walk all the windows in the system:
from pywinauto import Desktop
Desktop(backend=“win32”).window(title=“Window Title”, found_index=0).set_focus()
You referred to the old docs for version 0.5.4, the latest one is 0.6.4 with two backends available and many bug fixes. The Getting Started Guide link on the main page is a good source to learn the main concept.
Hey everyone I'm having a hard time automating a specific application. Using pywinauto I want to automate clicking, keypresses, etc. to login and benchmark this application but for some reason I can't find any control identifiers for this application. Am I doing something wrong? I used this same method with task manager and other applications and this works fine.
Important Documentation:
Code Example
Class Doc
Code:
import pywinauto
app = pywinauto.application.Application()
window_handle = pywinauto.findwindows.find_windows(title = u'Name of application')
#print window_handle #makes sure to see if handle exists
window = app.window_(handle = window_handle[0])
print window.Children() #first approach
print app.top_window_()._ctrl_identifiers() #second approach
Output:
>>>[]
>>>{}
Has this happened to anyone before and has found a way around it? Should I just resort to using pywin32 instead? Thank you!
Turns out the application does have control identifiers I just needed to get past the first screen. Using window.TypeKeys("{TAB}{TAB}{ENTER}") I was able to navigate past the home screen with keypresses and into the actual application which had all the identifiers.
Useful Links if anyone encounters this problem.
What is a control Identifier?
I'm on OSX using Python 2.x, Selenium & Firefox
I'm automating testing a javascript webapp with Python & Selenium.
One of the links (Add File) in the application opens up a non-browser firefox window titled "File Upload" which looks like (/is?) a Finder window.
Is there a way that I could locate and control this window from my python script? I know Selenium can't do it, but I wondering if it might be possible with something like 'import applescript' and if so how?
I found atomac which allows me to control mac apps through their accessibility controls (which needed to be enabled on Mavericks for Aptana in System Preferences -> Security & Privacy -> Privacy -> Accessibility). Cool tool, but the documentation is pretty sparse. The examples provided on the page above got me to the point where I could close the window via the cancel button, but I had to review the function definitions in atomac's AXClasses.py to figure out the rest. Here's the solution.
import atomac, time
from atomac.AXKeyCodeConstants import *
# to allow me to make firefox frontmost while testing
time.sleep(5)
# get a reference to the running app
firefox = atomac.getAppRefByLocalizedName('Firefox')
# get the window of the reference
firefoxwindow = firefox.windowsR()[0]
# send key sequence to go to my home folder
firefoxwindow.sendKeyWithModifiers('h',[COMMAND,SHIFT])
# send key sequence to select first file there
firefoxwindow.sendKeyWithModifiers('a',[COMMAND])
# press the now active Open button
openbutton = firefoxwindow.buttons('Open')[0]
openbutton.Press()
It's theoretically possible, but really awkward. I'll give you a bunch of links--not ideal, I know, but you could write a book on this.
You'd need to start by enabling AppleScript control of the GUI. Then you'll want to read up on how to control the GUI from within Applescript. However, you wanted to use Python and not AppleScript, so then you'll need to install PyObjC, which is a Python to Cocoa bridge. You'd need to use the Scripting Bridge framework and figure out (from the extremely thin documentation) how to translate the AppleScript docs to Python.
I am currently using the Python Webkit DOM Bindings to interact with a website programmatically and that's working for me.
The only problem is that it insists on opening a GTK window to display the page. Has somebody figured out a way to prevent it from opening a window? I.e. to use it in a headless way?
I'm initializing the view like this:
wv = pywebkitgtk.WebView(1024, 768, url=url)
which implicitly opens the GTK window and then I have an onload event-handler to manipulate the DOM.
I first thought of subclassing WebView, but that's not possible because it is a compiled class.
Any other ideas?
I'm the developer responsible for pythonwebkit, and I have a great deal of expertise covering these areas across several platforms. Realistically, you really, really want a completely "headless" WebKit port. In pythonwebkit that actually shouldn't be too hard to do, as there are only three "entry point" functions (one for window, one for document, and one for XMLHTTPRequest).
Really, somebody should do a proper "completely headless" port of WebKit. There already is an example program which is pretty close in WebKit's source tree, maybe that will get you started.
I've been using PyQT. PyQTWebView runs on Webkit and works great. Check out Ghost.py to get started, or use PyQT's API directly. Runs fully headless, and supports a decently recent build of Webkit.
You could try using Xvfb. I like using the command line and setting my display manually, but if you don't like that you could use this: http://cgoldberg.github.io/xvfbwrapper/
Can you get a handle to the GTK window and then call window.hide()? Otherwise, you might just have to use the full Webkit library.
Create a window and add the webview there, and never show the window..
I have webviews running without showing them, and can call a show_all if I need to show them.
web_view = pywebkitgtk.WebView()
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
sw = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
sw.add(web_view)
window.add(sw)
#window.show_all()