Gnome-Screensaver with Python? - python

I've created a little screensaver-type program with Python, and I'd like to get it working properly under gnome-screensaver. The documentation is all written for C, and there don't appear to be libraries for Python. Is there any way to get this working?

gnome-screensaver doesn't integrate with the screensavers any more than with a small config file that sets the name, some other properties, and a command to execute to start the screensaver. This is documented in the gnome-screensaver FAQ.
The program that gets started needs to get the Window ID from the environment (XSCREENSAVER_WINDOW), and start displaying on that window. This is the tricky part, as it's not always obvious how to do that. Most toolkits should have methods to get a handle on an already existing window by giving the ID, so search your GUI-toolkit documentation for something like that.

Related

Python GUI without 'video system'

I'm currently at a crossroads. I'm somewhat versed in Python (2.7) and would really like to start getting into GUI to give my (although mini) projects some more depth and versibility.
For the most part, my scripts don't use anything graphical so this is the first time I'm dipping my toes in this water.
That said, I've tried using pygame and tkinter but seem to fail at every turn to get something up and running (although I had some slight success with pygame)
Am I correct to understand that for both I need X started in order to generate any type of interface, and with that, so I need X to get any type of input (touchscreen presses)?
Thanks in advance!
In order to use tkinter, you must have a graphics system running. For Windows and OSX that simply means you need to be logged in (ie: can't run as a service). For linux and other unix-like systems that means that you must have X running.
Neither tkinter nor any of the other common GUI toolkits will write directly to the screen.
I'm gonna give an alternative answer. If you know HTML, CSS and Javascript (or have time to give it a try) I would recommend using Flask, http://flask.pocoo.org/.
With flask you can create websites but you can also (as I am using it) let it be your GUI. It will work on any device and looks really good :).

Trying to embed a native WINDOWS command line in my Tkinter/Python app

I've done a bit of research and I've played with different graphical kits and was wondering if there was a way to display a native windows command line in my application. So, it'd be something like the command line in Jetbrains products (I think eclipse has one too), but the goal is to have 4 of them.
I've found a piece of linux software demonstrating the core concept of what I want to do and I've attached it at the bottom. Basically, I just want four terminals, and I'm going to have the app handle specific key bindings for "ease of access" tasks. I've used the linked software before and like it, but I thought as I'm exploring python it'd be a good learning experience to write something like this for windows as well!
Thanks in advance!
Edit - Google searching "Windows Tkinter Command Line" and the likes haven't been fruitful :) I promise I googled a LOT before posting here.
I dont know if there is anything readymade for this. Basically, you will need to have a text widget and simulate the output with the subprocess module to directly pass user input to run system commands and append results to the same text widget. You could also consider two windows - one for text input and one for result output.
Here is a link: Calling an external command in Python

Need a way to retrieve the current playing song from Zune and Windows Media Player with Python

An Application of mine retrieves the current playing song from a multitude of music players. However, I'm having great trouble implementing Zune and Windows Media Player.
I've done a lot of googling on the subject, unfortunately it's only confusing me more and more.
What I would normally do for my other applications:
Iterate over all open windows every 4 seconds
Get the title of all windows
Check title for a pattern (Ie, " - Spotify ")
If it's there, adjust the title for output.
WMP Does not have the current playing song in the title.
Zune does, but it's rotating every few seconds between title, album and artist. Which is heavily unreliable to track with my current method, albeit possible.
Windows Media Player
I've also tried using the COM component for windows media player.
import win32com.client
wmp = win32com.client.gencache.EnsureDispatch('WMPlayer.OCX')
# some function I don't have here, it retrieves the current playing song
# and other data
The big problem with that it requires you to start WMP programmatically, which would be extremely user unfriendly
So, what have I found? This SO post redirects to WMP.dll. But as far as I've read, it has the same problem as the COM, you have to start it programmatically. If not, I would really like some directions on how to work with that dll in python.
There would be another a little less hacky solution, which is to write a plugin for WMP, let my users download that plugin and retrieve the data from that plugin. I'd rather not go there, since I have no experience with any of the C languages, nor do I feel like digging into plugin documentations for this.
Zune
A method would be to cycle through the three title states, determine which state it's currently at and find the position of the other two.
IE:
First 5 seconds the title is: Super_song
Next 5 seconds the title is: By Power_artist
Next 5 seconds the title is: Good_album (date)
So I could determine when the album title is by making a regex for the date (which is always there) and then find the title and artist by waiting a few seconds.
This is obviously not a great solution, since it'll take a while and it's not very reliable either, (what if the song name contains a date for example)
The next problem is that it's not consistent either, sometimes the title just stays Zune for minutes long. No idea why.
So, move on to the next method.
There's this application called ZuneNowPlaying. This "somehow" gets the current playing song from Zune and puts it in the registry, this thing does not work with my sloppy title method, since it changes the registry the instant the song changes. Immediately.
This is the solution I had used in the working version of my program, but many users reported that it simply didn't work, nothing happened. And I checked the program and it doesn't reliably change the registry all the time. I don't know why, I don't know how to fix it. Therefor, this solution is also -scrapped-.
Is the fact that it is using the name "MsnMsgrUIManager"#000000">
causing the zune software to send it information about which song is
playing? Is there a way to get this information without this kind of
hack?
That is found in the discussion of the Zune Now Playing application. The source is not available unfortunately, at least I can't find it. Anyone got more on this?
Third method I had heard of was once again, a dll. ZuneShell.dll it's called. I don't remember where I read about it, nor can I find it via google, since all results are "Is ZuneShell.dll a virus?".
Once again, I run into the problem that I wouldn't know how to work with this even IF I had documentation on it, heck, if it's even what I have been looking for.
Alternate directions to maybe look into
While browsing about this subject, I've seen people talking about retrieving data directly from GUI's. I'm not sure how legit, possible or even how correct my memory of it is, but if it's possible could someone redirect me to more on this?
Anything else, really.
I have working code in C++ to print the name of media currently playing in WMP. It's a simple console application (78 lines of code).
Steps:
1) implements a basic COM object implementing IUnknown, IOleClientSite, IServiceProvider and IWMPRemoteMediaServices. This is straightforward (sort of, your mileage may vary) using the ATL template CComObjectRootEx. The only methods needing (simple) code are IServiceProvider::QueryService and IWMPRemoteMediaServices::GetServiceType. All other methods may return E_NOTIMPL
2) Instantiate the "WMPlayer.OCX" COM object (in my case, via CoCreateInstance)
3) Retrieve from the object an IOleObject interface pointer via QueryInterface
4) Instanciate an object from the class seen in 1) (I use the CComObject<>::CreateInstance template)
5) Use the SetClientSite method from the interface you got at 3), passing a pointer to your OleClientSite implementation.
6) During the SetClientSite call, WMP will callback you: fisrt asking for an IServiceProvider interface pointer, second calling the QueryService method, asking for an IWMPRemoteMediaServices interface pointer. Return your implementation of IWMPRemoteMediaServices and, third, you will be called again via GetServiceType. You must then return "Remote". You are now connected to the WMP running instance
7) Query the COM object for an IWMPMedia interface pointer
8) If 7) didn't gave NULL, read the the IWMPMedia::name property.
9) DONE
All the above was tested with VS2010 / Windows Seven, and with WMP running (if there is no Media Player process running, just do nothing).
I don't know if yoy can/want to implement COM interface and object in Python. If you are interested by my C++ code, let me know. You could use that code in a C++ DLL, and then call it from python.
I just found a cool Python tool which can query all the controls of any program.
Simple, straightforward, and easy to read. It's here:
http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html
With that you can get the info from the GUI.
You can also grab the loaded file list. It works for most media player.
You can get this information programmatically like this:
http://www.codeproject.com/Articles/18975/Listing-Used-Files
This is C++, but at that point you can wrap the native code.
This way you have to extract the ID3 tags yourself. Might worth the shot as it would be an universal solution.

wxpython wx.AboutBox single instance

I'm still in the process of learning more about WxPython and I ran into a simple problem.
I like the wx.AboutBox class that manages how credits, licensing and other info is displayed to the user...and I'm not looking forward to building my own from scratch...although I can.
The problem here is that let's say I click on a button which brings up an AboutBox...seems like if you keep on clicking that exact button then multiple instances of the same AboutBox is brought up...and you end up multiple windows that just looks awkward in my opinion. As far as I've looked into it...there's no way to call the ShowModal() function that would allow you to get the ID of the close button in the aboutbox template and do some processing to make sure that only one instance is running.
I want to know how to stop this issue from happening...I want a single instance of wx.AboutBox and if it's not possible with this class due to it's nature/limitations then I'll have to consider building my own as a last resort.
Thanks
Creating your own AboutBox dialog is pretty easy. Here's an article that shows one way to do it: http://www.blog.pythonlibrary.org/2008/06/11/wxpython-creating-an-about-box/ or you could just use a GenericMessageDialog too. See the wxPython demo or http://www.blog.pythonlibrary.org/2010/07/10/the-dialogs-of-wxpython-part-2-of-2/
It seems like you haven't solved this problem yet. In wxPython, there's a class called "SingleInstanceChecker". I think this is what you're looking for.
http://wxpython.org/Phoenix/docs/html/SingleInstanceChecker.html

Behind the scenes activity on python prompt load-up

What happens behind the scenes when we invoke the python prompt?
I am more interested in understanding how do the methods/functions like print, import and the likes load up in the interpreter?
EDIT: Some clarification on my question:
When we type python on our unix prompt/windows console and Hit enter, what are the libraries that get loaded. My specific interest is as to how the keywords like print and import are made available to the user.
Like you , I am very interested by the underlying mechanisms of Python.
I think you'll love this series:
http://tech.blog.aknin.name/category/my-projects/pythons-innards/
There are too many levels to that question. Here's a very rough sketch.
There's the whole C-level interpreter initialization, a bunch of in-the-interpreter tasks, reading the environment and options, customization of the interpreter session. All that defines what you see when you run python.
I know there's a good description of the whole process somewhere.

Categories

Resources