Ubuntu Opportunistic Developers Week March 2010 - Building in Application Indicator support - Sense Hofstede - Mar 1 2010
(02:01:05 PM) qense: thank you rickspencer3! (02:01:09 PM) qense: Hello everyone! I'm Sense Hofstede and during the next hour I hope to learn you a bit about using Application Indicators in your application. (02:01:28 PM) qense: [SLIDE 1] (02:01:30 PM) qense: The slides for this session are located at <https://people.ubuntu.com/~qense/appind-session.pdf>. (02:01:36 PM) qense: If you've got a question, don't hesitate to ask in #ubuntu-classroom-chat. Start your question with 'QUESTION:' so it can be found. (02:02:00 PM) qense: [SLIDE 2] (02:02:05 PM) qense: First I'll talk a bit about what Indicator Application is and why you should use it. (02:02:18 PM) qense: After that we'll take a look at an example in Python, which I'm going to use to tell you about the way AppInd works. (02:02:28 PM) qense: Then I'll quickly explain the differences for other languages. (02:02:50 PM) qense: At the end of the session there will be time for questions. If you want to port your or someone else's application to Application Indicator and got a question about that, please save those for then. (02:03:14 PM) qense: It seems that I gave the wrong URL for the slides, people.ubuntu.comd eosn't suppoprt HTTPS, you want <http://people.ubuntu.com/~qense/appind-session.pdf> instead. (02:03:39 PM) qense: Everyone can get the slides now? (02:03:51 PM) qense: [SLIDE 3] (02:04:09 PM) qense: The purpose of Indicator Application is to give you a clean and consistent system tray. (02:04:22 PM) qense: This is done by taking the drawing of the status icon and its menu away from the applications and make them request the Indicator Application service to do it for them instead. (02:04:49 PM) qense: We are very strict, the only action allowed at the moment is the left mouse click, which spawns a menu. That is all, although we might see support for scroll events in the future. (02:05:27 PM) qense: For more information I would like to point you to the links some of you can already see at the slides: (02:05:31 PM) qense: https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators (02:05:44 PM) qense: That is the most important source of information. (02:05:48 PM) qense: And you've got: (02:05:49 PM) qense: https://wiki.ubuntu.com/CustomStatusMenuDesignGuidelines (02:05:53 PM) qense: and https://launchpad.net/indicator-application (02:07:01 PM) qense: [SLIDE 4] (02:07:16 PM) qense: Why should you all use Indicator Application? (02:07:24 PM) qense: One of the reasons is that the protocol we use is an implementation of the notification specification as proposed by KDE and as implemented in KNotify. (02:07:35 PM) qense: This means that KDE applications using KNotify will show up in GNOME with native GTK+ menus and that applications using Indicator Application will show up in KDE with native Qt menus. (02:07:57 PM) qense: The most important thing, however, is that the tray is now under control of one application, which is much easier to configure and theme. (02:08:06 PM) qense: The behaviour of the tray icons is now consistent so users know what to expect. (02:08:18 PM) rickspencer3 left the room. (02:08:18 PM) qense: If there are any questions about what I've just told, now is the time to ask. (02:08:56 PM) qense: If I'm going too fast, please let me know as well. ;) (02:09:27 PM) ClassBot: stefodestructo asked: does this work in windows and osx? (02:10:24 PM) qense: No, this works only on Ubuntu at the moment, and it could be built on other Linuxes as well. However, there is no port for Windows or Mac OS X and there is nothing like that planned either. (02:11:20 PM) ClassBot: titeuf_87 asked: is this an applet in the gnome-panel or does it actually use the "normal" system tray to display? (02:11:51 PM) qense: titeuf_87: AppIndicator uses the Indicator Applet that was introduced in Ubuntu with the Karmic release. (02:12:32 PM) ClassBot: PaulGit asked: If my application communicates with the indicator applet does it mean it will only run on Ubuntu and not other distros? (02:13:53 PM) qense: PaulGit: Good question. AppIndicator uses the standard KDE proposed at FreeDesktop. This means that anything implementing that standard will support it. At the moment this just are KDE 4 and Ubuntu Lucid. For other distributions you'll need a fall-back, which is integrated in the library. (02:14:51 PM) qense: one last question (02:14:58 PM) ClassBot: liems asked: Is it expected that this will be integrated into other distros? (02:15:35 PM) qense: This depends on the other distributions. The developers are actively working with GNOME upstream, so we'll have to wait what the outcome of that will be. (02:15:53 PM) qense: more on fallback, categories and your other questions later this session (02:15:57 PM) qense: [SLIDE 5] (02:16:25 PM) qense: We're now going to take a closer look at the way Indicator Applications work. (02:16:48 PM) qense: Karmic users wanting to see what's coming next in action need to install AppIndicator from a PPA: ppa:indicator-applet-developers/indicator-core-ppa (02:16:52 PM) qense: https://launchpad.net/~indicator-applet-developers/+archive/indicator-core-ppa/ (02:17:26 PM) qense: We're going to walk through an example to get a better understanding of the applet. (02:17:29 PM) qense: At the wiki there are several examples in different languages. I've taken the Python example, adapted it a bit and uploaded it to (02:17:32 PM) qense: http://people.ubuntu.com/~qense/appind-example.py (02:19:10 PM) qense: First we import appindicator module in Python: (02:19:10 PM) qense: import appindicator (02:19:26 PM) qense: The we start with initialising the indicator: (02:19:27 PM) qense: ind = appindicator.Indicator ("example-simple-client", "indicator-messages", appindicator.CATEGORY_APPLICATION_STATUS) (02:19:57 PM) qense: The first argument is a unique identifier for the application. It is used in the file ~/.config/indicators/application/lru-file.json -- where a few details of the application are saved -- to identify it. (02:20:10 PM) qense: The second argument is the name of the icon that's to be used. (02:20:23 PM) qense: The third argument is a category that at the moment is just saved, but in the future Indicator Application could be extended to present the icons in a better way using that information. (02:21:18 PM) qense: We could e.g. sort the icons on category. Since we communicate with the applet over DBus other applications can listen in as well and process the tray icons if they would wish to. The categories are a possible filter. (02:21:36 PM) qense: However, at the moment the category not used. (02:21:49 PM) qense: You can find a list of possible categories at the wiki page. (02:22:05 PM) qense: The next line of code sets the status: (02:22:06 PM) qense: ind.set_status (appindicator.STATUS_ACTIVE) (02:22:27 PM) qense: There are three possible statuses, STATUS_ACTIVE, STATUS_PASSIVE and STATUS_ATTENTION, their meaning is: show, hide, show with the attention icon, which is set on the next line: (02:22:55 PM) qense: ind.set_attention_icon ("indicator-messages-new") (02:23:22 PM) qense: Again we're using an icon name, at the moment it is not yet possible to set the icon path in the Python bindings, but the developers are working on that bug. (02:24:04 PM) qense: In C# you can provide a path as the fourth argument of the constructor, in C you use the function app_indicator_new_with_path() . (02:24:15 PM) qense: By default we look in the icon theme for the icon. (02:24:45 PM) qense: Next thing we do in the code is creating a GtkMenu, we will later give it to the indicator. (02:25:06 PM) ClassBot: M58 asked: Does it support pixmaps for icons? (02:25:40 PM) qense: M58: It does not, the design team has chosen not to do so in order to make sure the icons blend nicely with the theme. (02:26:00 PM) qense: Again we're taking a bit power away from the application to make sure it integrates a bit nicer into the desktop. (02:26:36 PM) qense: Back to the menu: we tell appindicator about our menu with the following line of code. (02:26:39 PM) qense: ind.set_menu(menu) (02:26:45 PM) qense: Simple, not? (02:26:59 PM) qense: You can reuse existing menus if you want. (02:27:35 PM) AndChat is now known as Guest59271 (02:27:42 PM) qense: Signals connected to the menu items will be sent to their handlers like they would do when the menu was a part of the application. (02:28:00 PM) ClassBot: nadako70 asked: is gtkmenu actually used or is it only a sugar for creating some internal menu structure, so it can be recreated in qt by KDE applet? (02:30:11 PM) qense: nadako70: The menu is sent to libappindicator as GtkMenu and there it is processed as a GtkMenu, but it is sent over DBus in a structure that is toolkit-agnostic so it is drawn by the native GUI toolkit in both GNOME and KDE. (02:30:26 PM) qense: Don't forget to show() the menu items! (02:31:05 PM) qense: The little code I've pasted in this channel are about all method calls you have to make in order to set up an icon in the tray. (02:31:16 PM) qense: Are there any questions about what I've shown so far? (02:31:47 PM) qense: No? (02:32:12 PM) ClassBot: Fredo asked: Are there only two possible icons for an application? (02:32:43 PM) qense: Fredo: Yes, you can chose a default icon and another icon for when you want attention from the user. (02:33:16 PM) qense: There was some discussion about adding a basic function to the library for showing numbers, e.g. on the icon, but I'm not sure if that will get implemented. (02:33:29 PM) ClassBot: dael99 asked: what about adding items and connecting them with functions? (02:34:03 PM) qense: dael99: First you create just a regular GtkMenu like you would do for a GtkStatusIcon, you can often reuse the old menu when porting an application. (02:34:23 PM) qense: You add items, connect signals and then add the menu to the indicator. (02:35:15 PM) qense: [SLIDE 6] (02:35:30 PM) qense: The use of AppInd in other languages is pretty much the same, (02:35:46 PM) qense: in C you initialise the indicator with 'app_indicator_new(const gchar*, const gchar*, AppIndicatorCategory)', in C# with 'new ApplicationIndicator(string, string, AppIndicator.Category). (02:36:06 PM) qense: or, if you want to provide an icon path, you can use app_indicator_new_with_path() in C (02:36:19 PM) qense: You should be able to pass the icon path as the fourth argument of the C# constructor. (02:36:38 PM) ClassBot: NilsR47 asked: Is user choice of having the tray icon or not built in, or do we have to code that ourselves? (02:37:53 PM) qense: NilsR47: Good you mention this. The design guidelines for the use of the AppIndicator ( https://wiki.ubuntu.com/CustomStatusMenuDesignGuidelines ) say that it is preferable to give the user the possibility to hide the icon from the tray. (02:38:01 PM) qense: However, this is not implemented in the applet. (02:38:26 PM) qense: You're kindly asked to provide that option to the user by yourself. (02:39:02 PM) qense: However, since the tray is now controlled by one application it shouldn't be too hard to make it possible for the user to block an application there. (02:39:20 PM) qense: Back to the bindings in C and C# (02:39:22 PM) qense: In C you need to include the following header file: (02:39:25 PM) qense: #include <libappindicator/app-indicator.h> (02:39:31 PM) qense: The pkg-config name of the C bindings is 'appindicator-0.1'. (02:40:01 PM) qense: The package libappindicator-doc contains the documentation for the C library. (02:40:07 PM) qense: In C# you need to import the AppIndicator assambly: (02:40:12 PM) qense: 'using AppIndicator;' (02:40:15 PM) qense: The pkg-config name of the C# bindings is 'appindicator-sharp-0.1'. (02:40:31 PM) qense: Code examples for Python, C and C# -- the only three languages we're providing bindings for at the moment, work on Vala bindings is still ongoing -- can be found at the wiki page I mentioned a few times before already: (02:40:36 PM) ClassBot: bananeweizen asked: I'd like to use the API from Java. What's my best chance to get that working? Implementing a JNI wrapper around the C library? (02:41:29 PM) qense: bananeweizen: I'm not familiar with the procedure of generating Java bindings, so I'm afraid I can't help you with that. I do know that there is no one working on creating them at the moment. (02:41:50 PM) ClassBot: dscassel asked: What's the relationship with the Indictator Applet? Are they going to be folded into Application Indicators? If I just want to say "Hey, there's new stuff!" should I use Indicator Applet or Application Indicators? (02:43:15 PM) qense: dscassel: Although the the Indicator Applet listens to the Indicator Application service (and the users of KNotify) and is responsible for drawing the icons, we haven't put the tray in the indicator applet's envelope. (02:43:36 PM) qense: They're drawn next to it, on the left. (02:44:06 PM) qense: A great resource for all three available bindings for libappindicator is its main wiki page (02:44:07 PM) qense: https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators (02:44:52 PM) qense: it contains an example for all three bindings and an example of Autotools code you can add to your project's configure.ac (02:45:39 PM) qense: Earlier I heard someone ask about the fallback support I mentioned earlier this hour. (02:46:44 PM) qense: For the occasions where the Indicator Applet isn't reachable or when the user has chosen to remove it from her or his panel we provide a default fallback in two functions that can be overriden for those that want to implement a custom fallback. (02:49:08 PM) qense: These functions are in C "fallback()" and "unfallback()" and in C# "ApplicationIndicator.Fallback()" and "ApplicationIndicator.Unfallback()" (02:49:26 PM) qense: However, overriding the ApplicationClass in C# isn't possible at the moment. This is a known bug and we're working on it. (02:49:51 PM) qense: [SLIDE 7] (02:49:52 PM) qense: I've told everything I wanted to tell. Now I'm going to do a little Q&A. If your question doesn't get answered, or if you think of one later, please come to the #ayatana channel. (02:51:33 PM) qense: If you want to use AppIndicator in your application, but need help, now is the time to ask. Later you can also ask in the #ayatana channel or in #ubuntu-app-devel . At 23.00 UTC every night this week there will be a hacking party on #ubuntu-app-devel, that is also a good place to ask. (02:51:46 PM) ClassBot: liems asked: how long until the python bindings are feature-equivalent with the c/c# bindings? (02:52:59 PM) qense: liems: Of course it is impossible to say when specific bugs are fixed and features are ready. However, when the Python bindings lack in comparison with the C/C# bindings that is a bug and I would like to ask you to file it whenever you come across such a thing. (02:53:55 PM) ClassBot: nadako70 asked: offtop: was it inspired by osx? i remember there was some consistency in top panel indicators provided by ichat, their network manager, etc. (02:55:14 PM) qense: nadako70: It is certainly possible that some individuals partaking in the design process were influenced by what they saw on the Mac. However, I'm not aware that this is based on Mac OS's tray or was heavily inspired by. (02:56:14 PM) qense: The inspiration for this was the fact that the tray is too cluttered and doesn't go well with your theme, often. (02:56:28 PM) ClassBot: liems asked: Specifically, I'm interested in knowing when we can expect to be able to specify an icon path in python, and override fallback functions (02:57:36 PM) qense: liems: The goal is to fix as many of these bugs before the release of Lucid. I would recommend you to take a look at the indicator-application project on Launchpad. There is at least a bug report about the icon-theme-path not being supported by the Python bindings. (02:57:49 PM) ClassBot: Fredo asked: So is something like Rhythmbox’ tray icon, with several states like play, pause, stop, etc. out of the scope of AppInd? (02:58:37 PM) qense: Fredo: Rhythmbox is already using AppIndicators. There are different icons used to display the state of the player. For that we use the app_indicator_set_icon() function (02:59:05 PM) qense: You can also call the app_indicator_set_menu() function again when you've updated the menu. (02:59:19 PM) qense: My time's up! (02:59:22 PM) qense: Thank you all for listening! (02:59:53 PM) qense: And next is the incredible doctormo who will tell you more about Ground Control, you've heard a bit about that project already in the previous session.