Icon for Java/Python programs

Hello,

Most of the time Java or Python programs are launched via bash script in order to call the “java” or the “python3” commands.

So when an icon is attached to the bash script (which is launching the program), it’s well recognized at the “.sh” file level (“PC” icon for PyCharm below):

icon1

However once the program is launched, in the Deskbar we can see “java” or “python3” in the Deskbar with the default icon :

icon2

Would it be complex to have the possibility to override the Deskbar’s behavior, so that in some situations it will not display the “java” or “python3” name but instead the original script’s name which was called ?
Hence the correct icon would be displayed for the application.

What I did at one stage was write a little yab program that did little more than make a system call to the java app. Compile the yab app and you can give it an icon and a proper x-vnd app signature and so on with the FileTypes add-on. It then shows up in the Deskbar as a proper program. I suppose the same principle could apply with C++.

2 Likes

For Python scripts, one way to do it is how it is done for the monsterz game. Warning, can be addictive :slight_smile:

Edit: if your Python scripts give you troubles when you double click them to start, you might want to take a look at this part of the patchset for monsterz.

Edit2: weird, installed Monsterz on a new install, and it doesn’t starts. Complains about not being able to find pygame, despite it being installed. Sigh… will try to find out what got broken there. Not actually broken for anyone but for silly me.

1 Like

Yes. There is pretty much no way to obtain this information if launched like this.
It’s just an exec call then.

I am confused why you would need bash to execute any python scripts though…

Nice trick for Python !

Indeed it does the job.
I will check for java if it’s applicable.

pythonicon

And as noticed by nephele, I have removed the bash script and instead use at the beginning of the python program :
#!python3

Note : it’s working only when launched via the Tracker (via the Terminal, python3 and default icon will appear)

Are you calling it with > python3 foobar or just > foobar?

Just > foobar

For Java, the solution proposed by Michel is working partially :

A C++ app wrapper is calling the java app, so It can have a dedicated icon.

wrapper

The only compromise is to have the additional “java” entry in the Deskbar.

FWIW, haven’t been able to fix the pygame/Monsterz issue yet, but if one installs it with pkgman install -H monsterz (package ends up under $HOME/config/packages), it DOES works.

And yes… invoking it from Terminal only shows python3 and the generic icon. No idea if there’s any workaround for that, other than B_DONT_DO_THAT, and call it only from GUI, or writting a small c/c++ wrapper and adding the icon as a resource to it.

Edit: welp… the pygame/Monsterz not working was only a “me” thing. I had forgotten to remove a locally built Python 3.10.16 package (installed under $HOME) that I used for testing when I last updated that recipe. Sigh.

Well, there are a couple of things going on here.

  • launch process: As per any POSIX setup, files are executed according to the two byte “magic number” header, and “#!” is the code for “interpreted file where # is a comment”; the path to the interpreter follows, and you get a optional command line argument. (So for example, sh is usually just #!/bin/sh and the system then launches /bin/sh /boot/home/config/non-published/bin/shscript or whatever your file, but for awk you need #!/bin/awk -f, so awk will know what’s going on when it comes up /bin/awk -f /boot/home/config/.....) The point being, at any rate, it’s just like invoking the same full command from the command line. Even though the full command line is determined by the interpreted file, the command that gets launched is /bin/python3 ... or whatever, and that’s what counts here.
  • launch vs. exec: Check me on this, but I think this is an important difference here: the application icons, file types etc. happens at launch, and you can exec to whatever other executable image afterwards without disturbing that. I’m talking about the execve(2) system call.
  • application icons, file types etc.: - attributes of the file that’s launched. The file can have been compiled from any language, but not interpreted, so that level of Haiku integration is achieved by an interpreted program by an auxiliary component that either execs the interpreter after the application signature etc. has been established, or (conceivably I guess but not typically) is linked into the same image and just calls it. I believe things like receiving file refs from the launch can be done from the interpreter later, if it has wrapper access to the necessary BApplication functionality.

I could be off on some of this, as it has been years since I did anything with it (other than shell and awk scripts, of course.)

1 Like

Could you check if the next one works for you, used it already a few times on python scripts and saved (with tips from IRC) a “template” on my own wiki to quickly do a search for it.

This is used already for quite some recipes at haikuports:

2 Likes

“invoking it from Terminal only shows python3 and the generic icon”

The current workaround to this, is to use the “open” command when calling the python script from the Terminal.

Hence calling :

  • “python_script.sh” : will display the generic icon
  • “open python_script.sh” : will display the custom icon :slight_smile:
2 Likes

My best results so far to have icons for Java applications :

Squirrel & DBVisualizer

Icons in LaunchBox : ok each program is launching fine

2025-01-12_15-36_2

Process in tracker : Each application has an icon, but the child process (java) is still visible

2025-01-12_15-36_1

The solution used is to have a C++ wrapper calling the java part.

The C++ application has the below logic to quit :

  • Quitting the child java process also quit the main program
  • Quitting the main program, kill the child java process
2 Likes