How do I make powerpoint play presentations/load up ppts automatically? - python

I was wondering how I can make a script load powerpoint file, advance slides automatically and put it on full screen. Is there a way to make windows do that? Can I just load powerpoint.exe and maybe use some sort of API/Pipe to give commands from another script.
To make a case: I'm making a script that automatically scans a folder in windows (using python) and loads up the powerpoint presentations and keeps playing them in order.

One solution for you would be to use the PowerPoint Viewer program instead. PPT Viewer is set to open a PowerPoint file straight away in Presentation mode.
Alternatively, you can use the argument /s to start Powerpoint.
"powerpoint.exe /s <filename>.ppt"
This will be equivalent to telling PowerPoint to straight away open up in Presentation mode.

As previously stated, this is more StackOverflow geared, but this can easily be achieved with Python and AutoHotkey.
On the Python side of things, as a general idea on how to go about this (I'm kind of rusty, beware!):
Find files using os.walk()
Append each to a list, then iterate over the list, opening each one with os.system("powerpoint.exe /s filename"). The next one should not open until the previous closes.
AutoHotkey wise:
Once opened, use #IfWinActive to detect an open Powerpoint window, and send mouse clicks to change slides at a set interval
I don't know what you mean by "order", you'll have to determine that in your Python script. If you want them alphabetical, sort the list alphabetically then iterate. If you want them sorted by creation date, then sort by date and iterate and so on.

Save the file with the extension ".pps". That will make powerpoint open the file in presentation mode.
The presentaion needs to designed to advance slides, else you will have to script that part.

If you want more control over the powerpoint slide, you could write something in VB.Net (or other .Net languages) according to this MS support article.
If you wanted direct control from Python, you could probably use pywin32 or comtypes to invoke directly the same interfaces as described in the MS article. My guess is this is the most powerful solution and would probably provide the smoothest transitions between presentations, but is probably a lot more work than using subprocess to call into PowerPoint.

Related

Automatically import new SVGs to Inkscape

I want to write an extension or find some way to automatically import to an Inkscape document the new files that appear in a given folder. I don't want to simply update the SVG/XML document because Inkscape has to be open for another extension (AxiDraw) to work.
My problem is that I cannot find a way to make my extension work "in the background", either it goes into an infinite loop that crashes the program or, if I use for example the Timer from threading it just stops after the first execution.
Also using the command line doesn't seems to work since there is not an import command and verbs don't work in shell mode.
Is there some relatively easy way to work around these problems without having to dig into the c++ source code?
Well, turned out it is not possible. From the answer to my same question on the Inkscape forum:
Python extensions currently work by 'halting' the Inkscape main
process. Then they modify the document, which is then loaded back into
Inkscape.
So this cannot work. You'd need to run it manually in regular
intervals, or set up some 'click bot' that does that for you.

Excel Python API

Does anyone know of a way of accessing MS Excel from Python? Specifically I am looking to create new sheets and fill them with data, including formulae.
Preferably I would like to do this on Linux if possible, but can do it from in a VM if there is no other way.
xlwt and xlrd can read and write Excel files, without using Excel itself:
http://www.python-excel.org/
Long time after the original question, but last answer pushed it top of feed again. Others might benefit from my experience using python and excel.
I am using excel and python quite bit. Instead of using the xlrd, xlwt modules directly, I normally use pandas. I think pandas uses these modules as imports, but i find it much easier using the pandas provided framework to create and read the spreadsheets. Pandas's Dataframe structure is very "spreadsheet-like" and makes life a lot easier in my opinion.
The other option that I use (not in direct answer to your problem) is DataNitro. It allows you to use python directly within excel. Different use case, but you would use it where you would normally have to write VBA code in Excel.
there is Python library to read/write Excel 2007 xlsx/xlsm files http://pythonhosted.org/openpyxl/
I wrote python class that allows working with Excel via COM interface in Windows http://sourceforge.net/projects/excelcomforpython/
The class uses win32com to interact with Excel. You can use class directly or use it as example. A lot of options implemented like array formulas, conditional formatting, charts etc.
It's surely possible through the Excel object model via COM: just use win32com modules for Python. Can't remember more but I once controlled the Media Player through COM from Python. It was piece of cake.
Its actually very simple. You can actually run anything from any program. Just see a way to reach command prompt from that program. In case of Excel, create a user defined function by pressing Alt+F11 and paste the following code.
Function call_cmd()
Shell "CMD /C Notepad", vbNormalFocus
End Function
Now press ctrl+s and go back to Excel, select a cell and run the function =call_cmd(). Here I ran Notepad. In the same way, you can see where python.exe is installed and run it. If you want to pass any inputs to python, then save the cells as file in local directory as csv file and read them in python using os.system().

A way to "listen" for changes to a file system from Python on Linux?

I want to be able to detect whenever new files are created or existing files are modified or deleted within a given directory tree (or set of trees). The brute force way to do this would be to just rescan the tree looking for changes, but I'm looking for a more "interrupt driven" solution where the file system tells my code what changed when it changes, rather than my code having to "poll" by continuously scanning through thousands of files looking for changes.
A way to do this in Python is preferred, but if I have to write a native module in C that's ok as a last resort.
pyinotify is IMHO the only way to get system changes without scanning the directory.
twisted.internet.inotify! It's much more useful to have an event loop attached than just free-floating inotify. Using twisted also gives you filepath for free, which is a nice library for more easily manipulating file paths in python.

How do I create a set of image files from a PowerPoint file file?

I'm creating a "slideshow room" web page. The user will upload a PowerPoint file that my server will use to generate a set of .jpg image files representing the slides to present in a custom "gallery viewer".
I'm an experienced Python developer but I cannot find anything useful.
How can I do that?
Off the top of my head, the way I'd do it:
Use OpenOffice.org to convert the .ppt file into a PDF. (OO.o has a very rich Java API. Rich and bloody difficult to use, mind, but once you figure out how to get it to do the task you need, you're all set. Dunno if you can do anything useful with it via Python; not my language.)
Use ImageMagick to convert the PDF into .jpg files. (Though I've been told converting the PDF into a PS file before turning it into images gives better results.) (IM's command line interface is damn near a language unto itself -- though again, once you figure out how to get it to do what you want, you're all set.)
Dunno if that's the most efficient/reliable way to do it. But fundamentally, I'd be on Google trolling for open-source third party tools that do all the dirty work for me.
Apache POI and Jython. POI, even has an ImageExtractor class, but having just glanced at the Javadocs, I suspect it is incomplete.
Are you doing this on Windows? If so win32 com:
import win32com.client
Application = win32com.client.Dispatch("PowerPoint.Application")
Application.Visible = True
Presentation = Application.Presentations.Open(pathToPPT)
Presentation.Slides[1].Export("C:/path/to/jpg.jpg", "JPG", 800, 600);
etc...

What's a way to create flash animations with Python?

I'm having a set of Python scripts that process the photos. What I would like is to be able to create some kind of flash-presentation out of those images.
Is there any package or 'framework' that would help to do this?
I don't know of any Python-specific solutions but there are multiple tools to handle this:
You can create a flash file with dummy pictures which you then replace using mtasc, swfmill, SWF Tools or similar. This way means lots of trouble but allows you to create a dynamic flash file.
If you don't need dynamic content, though, you're better off creating a video with ffmpeg. It can create videos out of multiple images, so if you're somehow able to render the frames you want in the presentation, you could use ffmpeg to make a video out of it.
If you only want charts, use SWF Charts.
You could use external languages that have a library for creating flash files.
And finally there was another script language that could be compiled into several other languages, where swf waas one of the targets, but I can't remember its name right now.
You should generate a formated list with the data to your photos, path and what else you need in your presentation.
That data you load into a SWF, where your presentation happens.
Like that you can let python do what it does and flash what flash does best.
You might find allready made solutions for flash galleries / slideshows. http://airtightinteractive.com/simpleviewer/ is a famous one. You can load your custom xml in it.
Check out Ming, it seems to have Python bindings.
Ming is powerful but you might not find it pythonic to work with.
I prefer Haxe for Flash work. (It's the successor of MTASC)

Categories