I have dowloaded a python script that uses win32com module (project site) to start and control Google Earth aplication on Windows. The commands in the script can also be used to interactively control Google Earth from command line.
The code is here. It works, it is exciting, BUT...
I'd like to do the same ON LINUX (Ubuntu derivatives).
The problem is: this script uses the COM interface to pass commands to GoogleEarth via interprocess communication. On linux, instead of an .exe, there is googleearth-bin executable, and I don't know how it would or shoud be to use the same interprocess communication idea on Linux.
Since the program is most probably compiled to the different OSes from (mostly) the same source code, it "seems" to me that the functionality could be in there. Now about HOW to access it from a Python script, this goes way beyond my current knowledge.
Thanks for any help!
The Google Earth COM Api has been depreciated (see http://googlegeodevelopers.blogspot.co.uk/2010/08/sunset-for-google-earth-com-api.html) so writing code against it is going to be hard-work and there are no guarantees that your code will work in the future.
Google are suggesting that people use the Plugin version of Google Earth but unfortunately, to date, this isn't supported on Linux OSs so that is not an option for you in this case.
Anyhow, caveates aside, you could look at something like pygoogleearth
http://pypi.python.org/pypi/pygoogleearth/
This is a pythonic wrapper around the Google Earth COM Interface, it should allow you to work with the COM api in python or at the least give you some pointers on the set-up.
Related
I'm looking for an equivalent Python library that will work when I run my script on Raspberry Pi. I'm under the impression that pywinauto only works on windows machine.
I want to control some inputs to a GUI launched by my script, using my script. Apart from pywinauto I have no idea how to do this. I thought about using command line to control the software directly, but if there is a simpler way I would really appreciate knowing about it.
Thanks for your time.
ATSPI is an Linux accessibility technology to obtain GUI text/rectangle properties programmatically. See how to find and run ATSPI registry daemon and how to enable ATSPI for the most popular types of GUI apps. Usually it's
$ /usr/libexec/at-spi-registryd &
There is a Python bindings for ATSPI. See this answer for details:
How to install pyatspi?
The pyatspi package has too many dependencies like pygobject etc. It also requires some compilation during installation steps. We think this is not user friendly so we decided to use libatspi.so directly (without any dependencies). This work status can be tracked here: https://github.com/pywinauto/pywinauto/pull/449
There is no exact deadline for pywinauto 0.7.0 with this feature (it's a hobby project), but I would say this summer sounds realistic.
I want to develop a small Python app that interacts with the user via the console/command line. Are there any good libraries I can use to get user input and display the output in a nice-looking way? I tried searching but most of what I found was command-line argument processing, didn't see anything about user interaction in the shell.
It should be crossplatform (Windows and Linux)
A really excellent library is cmd which is part of the python standard library. It is cross platform Windows, Linux, Mac. You just have to implement one class and it offers so many great features:
provides list of supported commands(they end up being implemented as methods)
help command that can be called to explain one of your commands
handles the whole entering a command, checking syntax, and calling your method command loop cycle.
users can save the commands they have run in an interactive session and run them as a script. check out the example below.
If you take the turtle shell example and save it as turtleshell.py and save the below turtle script file as circles.txt
circle 20
circle 50
circle 100
bye
then you could run the turtle script with the following command:
cat circles.txt | ./turtleshell.py
so in the simple example shown in the docs the developer has essentially made a simple mini-language that can be used as an easier interface to to the turtle module making it even easier to introduce programming to kids. The examples above have been taken from the python3 docs because they have included a detailed example in their docs which wasn't there in the 2.7 docs, but cmd is available and fully functional in python 2.3 and later.
You can control the Unix terminal with the curses library. The library essentially lets you build a simple terminal GUI.
If you need more, take a look at Urwid as well. Urwid offers more complex GUI widgets for the discerning terminal GUI developer. :-)
Curses is the most widely used in the Unix environment according to the doc. For Windows you could look at Windows Console Driver, WConio - Windows CONsole I/O for Python or Wcurses. I couldn't find much on cross platform console libraries unfortuntaly.
If your Windows users are CLI users they probably have cygwin which has ncurse support so curses is still the best option if you ask me.
So I wrote a Python script which does some simple stuff. It was originally going to run on a Unix server but due to crappy network security settings which TPTB refuse to change, we need to run it on a Windows server instead. However, the administrators of said Windows server refuse to do anything helpful like install Python.
What are my options for running a Python script on Windows without Python?
Consideration 1:
Something like Py2Exe - I found this after a quick Google search and it seems promising. From what I can tell, it'll generate a bunch of files but we can just xcopy that directory to our Windows machine and it will be completely isolated and not have any external dependencies. Does anyone have any insight on how well this works? Obviously, it depends on my Python script but fortunately this script is quite simple and only uses built in Python libraries such as urllib2 and urlparse.
Consideration 2:
We can assume the Windows server has at least some version of the .NET Framework installed too, which brings IronPython to mind. I've never used this before, but I've always wanted to. From what I can tell, it will compile Python code into CLS compliant IL code which can be run natively under the .NET runtime. However, does this require additional .NET libraries to be installed on the server? Can I just bundle those DLLs with my program? Or, does it require I rewrite my Python script to call into .NET Framework specific classes instead of using things like urllib2 or urlparse?
Thanks!
PS - The ironic part: I actually barely know Python and I'm a .NET expert, but I wrote the script in Python because I was told it would run on a Unix server. Had I known we'd end up running this on a Windows server, I'd have written the thing in C# to begin with in about 1/10th of the time. Fail.
Will they let you copy executables onto the server at all? If so then you should be able to do a non-admin installation of Python or use Portable Python which can just be copied into a folder without any installation at all.
Nothing wrong with Py2exe, but it does mean you then have to build the script into a fresh executable each time you update it. Also Py2exe has a slightly longer startup time than a Python interpreter because it has to extract the Python dlls into a temporary folder each time it runs; that only matters of course if you run your script a lot.
I'm a Python programmer and I was wondering if there's any module or framework that would allow me to interact with native Windows/Linux applications using python.
Let's say on Windows I have MS Outlook, so would it be possible to let's say automate MS Outlook to compose or check new emails?
I understand that Linux and Windows are different, but what I'm trying to achieve is to let's say open up an application, click on a button programmatically, etc.
I'm not sure if all of these are at all possible using python, so please enlighten me regarding what you think is possible and practical.
For something like Outlook, the best bet is probably using Outlook's COM (Component Object Model) with Python COM libraries.
Most applications have some kind of API.
And most of those API's are accessible with C.
Therefore, Python offers ctypes.
That's the lowest common denominator. Other API's are available, but you have to use Google to find them. Sometimes they're on PyPi. It's best to be specific and search for the specific app because there may be app-specific Python bindings. You don't know until you search.
MacOSX offers more sophisticated tools than this (via AppleScript and AppScript) but it's unique to Mac OS X.
Here's an example in Windows:
Utilizing os.system will work to ping (a native command in Windows):
import os
os.system('ping google.com')
Alternatively, you can also you the recommended subprocess.Popen:
import subprocess
subprocess.Popen('echo "hello world"', shell=True)
New to python (and programming). What exactly do I need from Cygwin? I'm running python 2.6 on winxp. Can I safely download the complete Cygwin? It just seems like a huge bundle of stuff.
Well, I keep running into modules and functionality (i.e. piping output) which suggest downloading various cygwin components. Will cygwin change or modify any other os functionality or have any other side effects?
There are builds of python which don't require cygwin. For instance (from python.org):
link text
Also, there is the .NET version called Iron Python:
link text
cygwin is effectively a Unix subkernel. Setup and installed in its default manner it won't interrupt or change any existing Windows XP functionality. However, you'll have to start the cygwin equivalent of the command prompt before you can use its functionality.
With that said, some of the functionality you're talking about is available in Windows. Piping definitely is. For instance:
netstat -ano | findstr :1433
is a command line I use to make sure my SQL Server is listening on the default port. The output of netstat is being piped to findstr so I only have to see any lines containing :1433.
I would say the simplest option is to try a Linux Distro. I know if your new Linux can be intimidating, but when I looked at Ubuntu and started developing there my life was changed. Ubuntu is bloated (for linux) however, it comes with the things that I would expect a Microsoft based OS to come pre-packaged with. The limitless amount of free software written by creative minds for creative minds is a wonder. The open-source community is great to get involved in for learning and experience. I can vouch that programming on Linux in any language (except myabe . . . .NET ?) will be a much pleasurable experience from the go. One is windows paths, sure you can still create portable Python applications that will port to windows, it just requires another couple lines of replacing characters and escaping them. If they are personal apps this can be bothersome if you do not plan to distribute them.
I found Ubuntu to be a nice balance suited towards both general usability, and development.
Stock Distro:
Python 2.7
Perl
XTerm
MP3 Player that kills WMP and Winamp =+ V.3.0
E-Mail w/ Thunderbird ( much like outlook express by the makers of Fire Fox browser with add-on and extensions)
Empathy (Internet Chat Client for AIM, ICQ, FACEBOOK, MySpace, etc . . it also keeps all your contacts on one list and operates just like AIM for all accounts)
Gwibber (social networking app that compiles the posts made on your twitter and your Facebook wall into a nice desktop widget that also allows you to reply and comment right from the app.)
Multiple Desktop Support: You can change your "desktop view" by pressing a hot key. Each desktop only has the windows you want on it. So you can create a work space, a chat space, a web browsing space and alternate between them quickly. You can also move windows around between work spaces quickly as needed.
Global Hot-Key Mapper: In your administration options you have an OS wide hot-key map. You can launch programs, and many other tasks simply by assigning a hot-key through the default interface.
Bash, Terminal, Shell, XTerm: These CLI (command line interfaces) offer much more functionality as you found than can be generally found in windows. Yes you can pipe output in windows but that's not what this is about. These CLIs allow you to create scripts that can take user input and perform complex tasks that usually would have to be done manually. The BASH is somewhat a programming language of itself; allowing for the assignment of functions, variables, if statements, etc.
I was very surprised that not only was Ubuntu well and ready to handle the developer but it was also plenty user friendly for your grand-parents. It comes with everything you need out of the box (for an average user not a developer) and the developer only requires a few installs. You're also working in open-source software remember. So you are going to be dealing with bugs and you may be stuck waiting on a ticket to be resolved in Windows for some time. If ever.
Also, Ubuntu is boot-able from CD and you can check out the main interface just by doing so. You can also dual-boot it with a screen asking you which partition/disk to boot after POST boot. There is also a tutorial on running it off a thumb drive.
Linux and the speed of your computer: Linux compared to say Windows 7 is EXTREMELY lightweight. What is considered to be a MID level computer such as an AMD Phenom 955 Black Edition x4 and it will run like a high level computer. 1 gib of memory goes quite a bit further in Linux than it does in windows.
The best way to try a Linux distro is as follows. You do not have to install it on the system. You can sandbox it with a virtual environment if you like it and want the speed and overhead improvements of running it stand-alone maybe consider the dual-boot at first followed by the "change".
Download the Linux Dist ISO of your choosing. For new users again Ubuntu, Mint, something simple. Something debian. Mostly due to the ease of using a good package manager. Download Oracle Virtual Box . Follow the instructions, create a new virtual disk, then start the virtual disk with install media placed in DVD drive or virtual DVD drive and install like a normal OS.
In my experience unless it is essential that you be using windows all the time, there is no reason not to try a Linux Distro. Just be careful because something like ArchLinux or SlackWare may scare you off right away; where as distros like Ubuntu, Mint, and others have built in GUI right off the bat. Linux comes in many varieties. It is more loosely coupled than windows you for example you can use any desktop environment you want. Linux is just a kernal. The distros are collections of tools the group maintaining the distro thinks will fit their over-all goal and purpose. Desktop Environments, programming tools, package managers, and other freely licensed pieces of software.