maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Python / GTK / Hildon: start application / bring to foreground if running (https://talk.maemo.org/showthread.php?t=71934)

helex 2011-04-09 19:12

Python / GTK / Hildon: start application / bring to foreground if running
 
Hi Developers!

I don't know if this is possible at maemo, at all. But perhaps someone has a solution for this:

I want to check in a small python application if a other application is already running.

If it is currently running I would like to bring it to the foreground. If it isn't running I would like to start this application.

Has anybody a Idea?
Does Hildon provide this thru the API?! :confused:

jstokes 2011-04-09 19:51

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
'lo there,

Are both the programs to be run yours? If so, you can make use of D-Bus. If you have control over both programs, you can make this much easier for yourself by only pretty much involving D-Bus; when I "wrote" a Media Player widget for Diablo, I had to use a mix of D-Bus and X stuff because the Diablo media player didn't implement its top_application method properly

helex 2011-04-09 19:56

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
Quote:

Originally Posted by jstokes (Post 984707)
Are both the programs to be run yours?

No, the Application is Conky. I'm personally not able to modify it's source... and I haven't asked the Maintainer. I'm searching for a universal solution.

Alfred 2011-04-09 20:05

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
What i am going to write can be so much dumb, but it looks like a n00b solution to me. When you start an app, say click an icon, and then go to dashboard and to the desktop and again click the icon it just brings back your opened window. So (i suppose) if you would like a your Py App to open another app, he would open a window(if it is already open) or open it from the start... Please correct me if i am wrong...

MohammadAG 2011-04-09 20:45

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
Code:

run-standalone.sh dbus-send --type=method_call --dest=com.nokia.HildonDesktop.AppMgr /com/nokia/HildonDesktop/AppMgr com.nokia.HildonDesktop.AppMgr.LaunchApplication string:conky

helex 2011-04-09 20:50

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
Quote:

Originally Posted by Alfred (Post 984713)
What i am going to write can be so much dumb, but it looks like a n00b solution to me. When you start an app, say click an icon, and then go to dashboard and to the desktop and again click the icon it just brings back your opened window. So (i suppose) if you would like a your Py App to open another app, he would open a window(if it is already open) or open it from the start... Please correct me if i am wrong...

This was exactly my idea. :D

Sadly, if I do it using the command os.system("conky") it starts every time a new instance of conky. :(

helex 2011-04-09 20:56

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
Quote:

Originally Posted by MohammadAG (Post 984729)
Code:

run-standalone.sh dbus-send --type=method_call --dest=com.nokia.HildonDesktop.AppMgr /com/nokia/HildonDesktop/AppMgr com.nokia.HildonDesktop.AppMgr.LaunchApplication string:conky

Yay! THANKS!

This code works. Thanks a lot! :)

Sadly, if it is currently the application in the foreground I see the "flip window" animation.
Am I able to check what application is currently on top?

But it is a great step in the right direction. Exactly what i searched for. :)

jstokes 2011-04-09 21:02

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
Quote:

Originally Posted by helex (Post 984739)
Am I able to check what application is currently on top?

You can, but it involves X calls from what I know. I don't know how you do it in Python, though. If you have xprop installed, you can invoke "xprop -root" and look at the _NET_ACTIVE_WINDOW or _MB_CURRENT_APP_WINDOW. The numbers represent a Window ID (XID). You can use them to get the WMCLASS or the title of an application :)

I'd be personally interested to know if there's a simpler way

helex 2011-04-09 21:32

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
Quote:

Originally Posted by jstokes (Post 984745)
You can, but it involves X calls from what I know. I don't know how you do it in Python, though. If you have xprop installed, you can invoke "xprop -root" and look at the _NET_ACTIVE_WINDOW or _MB_CURRENT_APP_WINDOW. The numbers represent a Window ID (XID). You can use them to get the WMCLASS or the title of an application :)

Ah, thanks. I haven't known about this. But it seems more as a tool for developers... and after looking at the package I guess it is not a good idea to investigate how this works using python: Package

It would end with some wasted time. :( I'm trying to develop a application and if it works as I imagine myself at the moment I like to upload it to extra-devel and push it to extra-testing as soon as it works without errors.

But depending on this package this would never happen. So it couldn't be a solution for normal applications. Or am I wrong?

As you already stated, there should be a simpler way... :confused:

jstokes 2011-04-10 08:26

Re: Python / GTK / Hildon: start application / bring to foreground if running
 
Quote:

Originally Posted by helex (Post 984758)
Ah, thanks. I haven't known about this. But it seems more as a tool for developers... and after looking at the package I guess it is not a good idea to investigate how this works using python: Package

Sorry, I didn't mean use xprop in the application... I meant use it to figure out the way X properties work etc. and create an implementation in Python. Thankfully, since you're using GTK, the GDK wrapper around X makes this really easy (in Python anyway ;)); look at this:

Code:

#!/usr/bin/env python
import gtk

screen = gtk.gdk.screen_get_default()
root = screen.get_root_window()
#active_window = screen.get_active_window()
x = root.property_get("_MB_CURRENT_APP_WINDOW")[2]
num = int(''.join(map(str,x))) #http://stackoverflow.com/questions/489999/python-convert-list-of-ints-to-one-number
#print "0x0%lx" % num
active_window = gtk.gdk.window_foreign_new(num)

#if not active_window is None:
wmclass = active_window.property_get("WM_CLASS")[2].split('\x00')[0]
print wmclass

Add error checking as required. :) Now I can remove Python from my N800 ;)


All times are GMT. The time now is 08:35.

vBulletin® Version 3.8.8