How to create a taskbar icon using wxPHP in Ubuntu / Unity?

After some struggle, I compiled a PHP module for wxPHP and wrote some scripts to see what it can do. My first demo creates a window and a taskbar icon, and I can't get the latter to work.

I am running this on Ubuntu 14.04 LTS.

Here is the script I am using:

<?php // Create an icon (does not appear on Ubuntu 14.04 LTS) $icon = new wxTaskBarIcon(); echo "Task bar available: " . (wxTaskBarIcon::IsAvailable() ? 'Yes' : 'No') . "\n"; echo "Create task bar icon: " . ($icon ? 'OK' : 'Failed') . "\n"; $wxIcon = new wxIcon('icon.ico'); $ok = $icon->setIcon($wxIcon); echo "Set image for icon: " . ($ok ? 'OK' : 'Failed') . "\n"; // Create a window (works fine) $main = new wxFrame(null, wxID_TOP, "Title" ); $main->Show(); wxEntry(); 

Now I would suggest that the "taskbar" in Unity is the top panel with the clock, sound and network controls, and not the application panel on the left. I get a blank gray app icon in the dock when the PHP task is running, but this is the status icon at the top, which I follow.

The console outputs from the above script show that everything is in order:

 Task bar available: Yes Create task bar icon: OK Set image for icon: OK 

I tried changing icon.ico to a nonexistent file, and this brings up the backtrace dialog, which shows that the icon I'm using is loading successfully (and presumably from an acceptable format).

Edit: Further studies show that:

Thus, I am assuming that my code would work if it weren't for Unity preventing the operation, and that it would be immediately on other distributions such as Mint.

I found this guide that explains how to use the whitelist on Ubuntu 14, but this is most unsatisfactory; to do something so trivial, you don’t have to change the list of trusted repos. If I want to distribute an application written in wxPHP, users will (and should) find it unacceptable.

There are several research opportunities that I now ask for advice:

  • Do something different in wxPHP if it (or up wxWidgets) supports AppIndicators (I think it is not)
  • Detecting if AppIndicators is running, and if it sends DBus messages using PHP to create an icon (although I looked for a DBus message specification for AppIndicators in vain)

Edit again: since this is a pretty niche question, and since Ask Ubuntu contains a number of programming questions for the Ubuntu platform, I asked a question specific to DBus on this site.

+5
source share
1 answer

In general, it is not possible to create a taskbar icon on Ubuntu, at least through wxPHP or wxWidgets. This is a deliberate design decision from the Ubuntu usability team to represent consistency and accessibility in the use of application-level status icons.

I raised this as an error and received a lot of useful information from the accompanying wxPHP. I agree with him that this feature will be better upstream in wxWidgets, but from the comments on the Internet it doesn't seem like there is a lot of appetite to add it there.

My short-term solution would be to configure the Python process to use its own App indicator ( python-appindicator in the Ubuntu repo) and establish a connection between the two processes (from PHP to Python to change the icon, from Python to PHP to send menu selection events). I expect to start by using wxFileSystemWatcher as a simple communication system, as it works well inside the wxWidgets event loop.

A better solution would be to have appindicator bindings for PHP, but that sounds more active, so I will leave it for now.

+1
source

Source: https://habr.com/ru/post/1236516/


All Articles