Active Topics

 


Reply
Thread Tools
helex's Avatar
Posts: 543 | Thanked: 802 times | Joined on Apr 2010 @ Germany
#1
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?!
__________________
I was a Qt Ambassador!

Please DONATE if you like my work!
It's the best way to motivate me to create more stuff for your Device.
 
Posts: 235 | Thanked: 339 times | Joined on Nov 2010
#2
'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
 

The Following User Says Thank You to jstokes For This Useful Post:
helex's Avatar
Posts: 543 | Thanked: 802 times | Joined on Apr 2010 @ Germany
#3
Originally Posted by jstokes View Post
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.
__________________
I was a Qt Ambassador!

Please DONATE if you like my work!
It's the best way to motivate me to create more stuff for your Device.
 
Alfred's Avatar
Posts: 855 | Thanked: 612 times | Joined on Oct 2010 @ Germany
#4
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...
__________________
Reps are just one click away: Extras | Extras-Testing | Extras-Devel | My-Maemo | CSSU |
Transform your lock screen into a weather forecast Thanks button ================>
 

The Following User Says Thank You to Alfred For This Useful Post:
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#5
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
 

The Following 3 Users Say Thank You to MohammadAG For This Useful Post:
helex's Avatar
Posts: 543 | Thanked: 802 times | Joined on Apr 2010 @ Germany
#6
Originally Posted by Alfred View Post
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.

Sadly, if I do it using the command os.system("conky") it starts every time a new instance of conky.
__________________
I was a Qt Ambassador!

Please DONATE if you like my work!
It's the best way to motivate me to create more stuff for your Device.
 
helex's Avatar
Posts: 543 | Thanked: 802 times | Joined on Apr 2010 @ Germany
#7
Originally Posted by MohammadAG View Post
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.
__________________
I was a Qt Ambassador!

Please DONATE if you like my work!
It's the best way to motivate me to create more stuff for your Device.
 

The Following User Says Thank You to helex For This Useful Post:
Posts: 235 | Thanked: 339 times | Joined on Nov 2010
#8
Originally Posted by helex View Post
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
 

The Following 2 Users Say Thank You to jstokes For This Useful Post:
helex's Avatar
Posts: 543 | Thanked: 802 times | Joined on Apr 2010 @ Germany
#9
Originally Posted by jstokes View Post
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...
__________________
I was a Qt Ambassador!

Please DONATE if you like my work!
It's the best way to motivate me to create more stuff for your Device.

Last edited by helex; 2011-04-09 at 21:35.
 
Posts: 235 | Thanked: 339 times | Joined on Nov 2010
#10
Originally Posted by helex View Post
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

Last edited by jstokes; 2011-04-10 at 08:34.
 

The Following 3 Users Say Thank You to jstokes For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 04:34.