Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am developing a program using quickly. I am using an indicator which can hide/show the main window.

But when I launch the application from the launcher it starts a new instance of that application (so an additional indicator will be shown). Rather than just showing the main window of the previous running app.

What's the usual way of forcing only one indicator?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

First, make sure you have a good reason to do this. People expect applications to work as you describe in your post. Even though you personally might not like it.

But, to answer your question, one of the easiest ways to do it is by making a file (for example in the configuration directory) at startup, which you remove when your application exits. Before starting the application, you check in your code if another instance is already active, and if so, you exit directly. If you also want to focus the active application, you need a way to do inter process communication. For example via a socket. See http://docs.python.org/library/ipc.html for more info.

share|improve this answer
1  
I would add that you should put your application's process ID in that file, then not only check that the file exists, but check that the process exists and matches your application. Otherwise a force-quit of your application may leave behind the file even when it's not running. –  mhall119 Jun 24 '12 at 20:17
    
thank you, a great idea! –  Nick Lemaire Jun 24 '12 at 20:20
add comment

I have found an even better solution (little more complicated though). You can verify not only whether your process is running but also provide some input to it if it's already launched. Please check out this solution.

share|improve this answer
    
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  jokerdino Sep 28 '12 at 12:46
    
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Peachy Sep 28 '12 at 12:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.