English 中文(简体)
Looking for advice on how to develop applets for Gnome / Ubuntu
原标题:

I am a linux (mostly ubuntu) user with a reasonable understanding of how the system works (although I am certainly not a linux guru!). In the past I have developed small cross-platform desktop applications in python/GTK and I delivered them to clients as self-contained filetrees, so that the only dependencies were Python itself and GTK.

Now I would like to develop a small applet for ubuntu, that I would like to release under GPL 2 or 3.

In particular these are the new steps I know I must learn in order to achieve my goal (it is very possible there are a few more that I am unaware of, though!):

  • Integrating with gnome: I want my application to be available as an applet in the taskbar.
  • Using D-bus: In particular I want my applet to use the new osd-notification framework for ubuntu, but communication with other applets is also a possible feature for a second iteration.
  • Packaging: I would like to setup a public PPA as soon as the application will reach alpha stage, but I also would like to use dependencies from existing packages in the official repos, rather than include the libraries again in my own package.

Of course official documentation will be my first source of knowledge, but - basing my judgment on the very useful answers that I received on another topic here on SO - I decided to turn to the SO community to collect additional advice like for example:

  1. Are there additional steps to those I outlined before, that I have to learn in order to be able to implement my project?
  2. Based on your own experience, would you advise me to learn those steps in advance (as the knowledge of those will influence my way of coding the core functionality) or would you consider integration with gnome / d-bus and packaging as "higher encapsulating levels" that can be added on top of core functionality afterwards (note: D-bus will be used at first just for pushing data. Input data will be retrieved with a webservice)?
  3. Would you advise me to separate my application in two packages (back-end and front-end) or to keep it together in a single package?,
  4. Do you know of any useful resource that you would advise me to look at, for learning any of the things that I have to?
  5. Are you aware of any common "beginner s mistakes" that I should be aware of?

These questions are not meant to be exhaustive, though: if you feel that I am missing something from the general picture, you are more than welcomed to point me in the right direction!

PS: Should I have failed in explaining my final goal, take a look at project hamster: what I want to achieve is similar in terms of user interface (meaning: the applet should display the status and clicking on it should open the application itself, from which you could both configure the applet and perform various operations).

最佳回答

When I asked this question two years ago Ubuntu and Gnome were much closer to each other than they are today. At present (end of 2011) gnome adopted the gnome-shell, while Canonical decided to develop their very own UI (unity)...

Part of the tension that brought to the split specifically involved libappindicator, which makes the way I formulated this question (and probably part of the answers) obsolete.

Besides, there is now AskUbuntu on stack exchange, that would probably be a much better forum to ask about ubuntu-specific question.

问题回答

Well, you list python, so you ll want to have pynotify in your arsenal. It wraps DBus, and gives you a direct api for manipulating the osd-notification system.

>>> import pynotify
>>> pynotify.init("Lil  Applet")
True
>>> note = pynotify.Notification(
...            pynotify.get_app_name(), 
...            "Lil  Applet wants you to know something s up.", 
...            "/usr/share/icons/Human/48x48/status/dialog-information.png")
>>> note.show()
True

This displays a notification that looks like this:

[    ] **Lil  Applet**
[ICON]
[    ] Lil  Applet wants you to know something s up.

As you already know, your first and best friend will be the code written by others - copy, paste, dissect, understand. Luckily there are a few projects that do what you intend to achieve. I can recommend conduit s code as a prime reference how to do things in a clean fashion. I think they also have stuff on dbus. Others to keep an eye on, would be deskbar-applet, hamster (heh), and any other app you remember having feature X. Sometimes it might require some C code deciphering though (like the applet button bit - i suggest you better take it from hamster as i was having some major time getting the thing straight)

Then the "devhelp" app will be of great assistance - it allows you to read and search in man pages fast and easy. Make sure that you also have the -doc packages for all the modules you intend to use. For user interface i strongly suggest using glade, as that will allow you to change interface later much easier. Where you can t use glade - add and alignment box and add the widget in the box in the code. There certainly will be quirks and things that you will learn the hard way. Should not be too hard though!

The packaging, especially the autotools will be bit of a struggle, but you will get it right. For how to do debians (and from there to PPA), you can dig in the hamster s repository history. There was once a "debian" folder.

I would suggest to start small - see if you can get a window. Then put a button on it. You don t have to do it "right" the first time. For first time it will be ok, if something works at all.

As for the separation - i would not bother about it until you get there. Splitting up into two parts and have a core, should not be too hard later. But that all depends on your priorities.

Last thing - getting friends who know the field helps too. And one way to get new friends, is by taking part in other projects, heh.

There are some very good recommendations here already, but let me suggest that you develop your applet not so much "for Ubuntu" as "for Gnome". It doesn t take much extra effort to also make RPM packages for distributions such as Fedora, and Arch Linux packages, to name two examples. There is one major disadvantage though -- to stay compatible with Debian stable you have to stick to ancient versions of GTK and GLib, or at least make any functionality depending on newer versions optional. It s painful, but apparently Debian stable users appreciate it.

I d also suggest setting up a source code management system somewhere as early as possible. You may not be worried about your disk crashing, but sometimes it saves you a lot of trouble just to be able to revert everything you did since the last commit.

Here s the link to the documentation on the official Gnome Panel Applet library. I don t know if it has Python bindings or not.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签