It is currently Sun Jan 24, 2021 9:26 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Setting the program's icon in Linux
PostPosted: Sun Jun 08, 2014 7:31 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 12, 2013 1:55 pm
Posts: 1058
Location: just outside of Ferguson
The code below works in 64 bit, but only when a small .png file present in the run directory.
I am using a 48 pixel square image.
I thought that after I compile the code into an executable,
then the .png data is available at runtime just as if the local file were there.
But after creating an executable, I can only get it to work properly with the png file in the same folder.
Code:
ImportC ""
   gtk_window_set_icon_from_file(a.l, b.l, c.l)
EndImport

DataSection
LINUXICON:
IncludeBinary "S48.png"
EndDataSection

Procedure SETLINUXICON(iWindow.i)
   Protected.l lError
   gtk_window_set_icon_from_file_(WindowID(iWindow),"S48.png",lError)
EndProcedure

OpenWindow(0,100,100,300,200,"SOFTWARE",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SETLINUXICON(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Replacing the call in the code snippet above with the following line:
gtk_window_set_icon_from_file_(WindowID(iWindow),?LINUXICON,lError)
and then running yields the error: Failed to open file (random garbage)PNG
(garbage) No such file or directory.

The documentation at https://developer.gnome.org/ states:
gtk_window_set_icon_from_file (GtkWindow *window,
const gchar *filename,
GError **err);


Sets the icon for window . Warns on failure if err is NULL.

This function is equivalent to calling gtk_window_set_icon() with a pixbuf created by loading the image from filename .
Parameters:
window - a GtkWindow
filename - location of icon file. [type filename]
err - location to store error, or NULL.[allow-none]


Does anyone know how to accomplish setting the GTK icon, without having the file actually existing in a folder?

_________________
Keep it BASIC.


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Sun Jun 08, 2014 7:45 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3698
Location: Italy
Try this, I'm on Win so not tested.

Code:

UsePNGImageDecoder()

DataSection
 LINUXICON:
 IncludeBinary "S48.png"
EndDataSection

OpenWindow(0,100,100,300,200,"SOFTWARE",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

icon = CatchImage(#PB_Any, ?LINUXICON)

gtk_window_set_icon_(WindowID(0), ImageID(icon))

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Sun Jun 08, 2014 7:48 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 12, 2013 1:55 pm
Posts: 1058
Location: just outside of Ferguson
luis wrote:
Try this, I'm on Win so not tested.

Code:

UsePNGImageDecoder()

DataSection
 LINUXICON:
 IncludeBinary "S48.png"
EndDataSection

OpenWindow(0,100,100,300,200,"SOFTWARE",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

icon = CatchImage(#PB_Any, ?LINUXICON)

gtk_window_set_icon_(WindowID(0), ImageID(icon))

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Thanks luis, it worked like a charm!
Now I just have to grok the use of CatchImage in this context.

This make my little game project almost finished.
All I really need now is for my kids to finish their artwork and for me to register with a file hosting outfit.
And of course to flesh out the comments while the stuff is still fresh in my mind.
luis you in particular, and this forum in general, are a much needed and appreciated PB programmer's resource.
-------------------
The first snippet above will only work on my 32 bit system if I name a local file "S".
It almost seems as if only the first character of the filename is used by the x86 version of this function.

_________________
Keep it BASIC.


Last edited by heartbone on Sun Jun 08, 2014 8:05 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Sun Jun 08, 2014 8:03 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3698
Location: Italy
heartbone wrote:
The first snippet above will only work on my 32 bit system if I name a local file "S".


Try that one with ascii and see if it works, you are using unicode right ?

Maybe there is something wrong the way pb imports it ?

Try this

Code:
ImportC "" 
   gtk_window_set_icon_from_file_(*win, file.p-utf8, *err) As "gtk_window_set_icon_from_file"
EndImport

Procedure SETLINUXICON(iWindow)
   Protected iError   
   gtk_window_set_icon_from_file_(WindowID(iWindow), "s48.png", @iError)
EndProcedure

OpenWindow(0,100,100,300,200,"SOFTWARE",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SETLINUXICON(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End


This should override PB import and force the conversion of the string to UTF8, so it will work in ascii and unicode
See pseudotypes in the help for more info (a very nice feature).

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Sun Jun 08, 2014 8:18 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 12, 2013 1:55 pm
Posts: 1058
Location: just outside of Ferguson
luis wrote:
Try that one with ascii and see if it works, you are using unicode right ?
I'm running the defaults there and I see two seperate seemingly independently places in the IDE to toggle the compile.
FILE > Preferences > Compiler > Defaults > Create unicode executable [checkbox]
and
Compiler > Compiler Options... > Create unicode executable [checkbox]

Quote:
Maybe there is something wrong the way pb imports it ?

Try this

Code:
ImportC "" 
   gtk_window_set_icon_from_file_(*win, file.p-utf8, *err) As "gtk_window_set_icon_from_file"
EndImport

Procedure SETLINUXICON(iWindow)
   Protected iError   
   gtk_window_set_icon_from_file_(WindowID(iWindow), "s48.png", @iError)
EndProcedure

OpenWindow(0,100,100,300,200,"SOFTWARE",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SETLINUXICON(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End

This should override PB import and declare the string as UTF8, see pseudotypes in the help for more info.

I will look into it sir, but since your correction above allows the IncludeBinary to function the way that I wanted,
I'll delay that investigation until after I finish my immediate tasks.
I suppose that need to learn about the effects of unicode on programs.

_________________
Keep it BASIC.


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Mon Aug 04, 2014 3:25 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 12, 2013 1:55 pm
Posts: 1058
Location: just outside of Ferguson
luis wrote:
heartbone wrote:
The first snippet above will only work on my 32 bit system if I name a local file "S".


Try that one with ascii and see if it works, you are using unicode right ?

Maybe there is something wrong the way pb imports it ?

Try this

Code:
ImportC "" 
   gtk_window_set_icon_from_file_(*win, file.p-utf8, *err) As "gtk_window_set_icon_from_file"
EndImport

Procedure SETLINUXICON(iWindow)
   Protected iError   
   gtk_window_set_icon_from_file_(WindowID(iWindow), "s48.png", @iError)
EndProcedure

OpenWindow(0,100,100,300,200,"SOFTWARE",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SETLINUXICON(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End


This should override PB import and force the conversion of the string to UTF8, so it will work in ascii and unicode
See pseudotypes in the help for more info (a very nice feature).
I apologize for being negligent in getting back to testing this.
I tested it in UBUNTU x86 and the unicode executable compiles and runs without error.
However it doesn't set the icon when using either single (S.png) or multi character (S48.png) filenames, the grey question mark remains.
Because the following solution seems to work well, implementing this is not an issue.
Code:
;;; SETUP LINUX ICON CREATION
UsePNGImageDecoder()   ;;;
ImportC ""   ;;;
   gtk_window_set_icon(a.l,b.l,c.l)  ;;;
EndImport   ;;;
InitSprite()
OpenWindow(0,0,0,800,600,"SOFTWARE",#PB_Window_ScreenCentered)
ICON= CatchImage(#PB_Any,?LINUXICON)   ;;;
gtk_window_set_icon_(WindowID(0),ImageID(ICON))   ;;;
Delay(5000)
End
LINUXICON: : IncludeBinary "linux.png"   ;;;

_________________
Keep it BASIC.


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Mon Nov 03, 2014 1:10 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 11, 2009 1:56 pm
Posts: 858
Location: Essen (Germany)
Hello,
after extensive searching and testing many codes, I finally was lucky to have found a way to get a program icon showing for good. :D

With all examples from here or from [Linux] Window icon creator I always experience the same issue:
- the tray-icon always shows
- the title-icon only shows once in a while in the actual IDE-compilation, but never if I'd run the pb-compilation.out nor ever in any compiled executable.

If anybody has an idea why that is, please let me know.
[Maybe it's Suse 11.1 missing a lib or alike. But even years ago nothing had worked out.]

Now, in case someone else has similar issues, I'd like to share my solution using "gtk_window_set_default_icon_from_file". And benefitting from the codes around me, I managed to make it work for both ASCII and Unicode compilations.
Code:
; **********
; Linux - Program Icon via "...default_icon_from_file"
; ASCII and Unicode compilation
; **********

EnableExplicit

Enumeration
  #MainWin = 0
  #Tex1    = 0
EndEnumeration

Global *err, compil, IconPath.s

; Adjust your icon path here ...
IconPath.s = #PB_Compiler_Home + "examples/sources/Data/world.png"


CompilerIf #PB_Compiler_Unicode
compil = 1
ImportC ""
  gtk_window_set_default_icon_from_file(file.p-utf8, *err) As "gtk_window_set_default_icon_from_file"
EndImport
;  gtk_window_set_default_icon_from_file("/home/path/to.png", @*err)
gtk_window_set_default_icon_from_file(IconPath, @*err)
CompilerElse
;  gtk_window_set_default_icon_from_file_(@"/home/path/to.png", @*err)
gtk_window_set_default_icon_from_file_(@IconPath, @*err)
CompilerEndIf


If OpenWindow(#MainWin, 300, 200, 200, 100, "show prog icon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(#Tex1, 50, 30, 140, 25, "")
  If compil = 1 : SetGadgetText(#Tex1, "unicode")
    Else :: SetGadgetText(#Tex1, "ASCII") : EndIf

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
 
EndIf

thanks :) nd greetings ~ Vera

_________________
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi

Missing a download-file on the forums? ~ check out this backup page.


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Fri Nov 07, 2014 10:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Mar 10, 2013 3:01 pm
Posts: 704
Location: Portugal
Why can't Freddy code an automatic icon adding in Linux such as the one for Windows?


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Sat Nov 08, 2014 12:17 am 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 11, 2009 1:56 pm
Posts: 858
Location: Essen (Germany)
marcoagpinto wrote:
Why can't Freddy code an automatic icon adding in Linux such as the one for Windows?

I think that's because there couldn't be a single solution for all Unix based OSs but countless for all the distributions. please see freak's comment

Still it would be nice if the PB-help gave some hints here and there where to look to find such specific solutions.

Luckily a lot is shared on the forums :-)

_________________
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi

Missing a download-file on the forums? ~ check out this backup page.


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Tue Jan 08, 2019 10:40 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1181
Location: Portugal
I think this is the same problem. I wanted to create a desktop icon on linux to launch my programme.

Eventually wrote this only of use in LINUX

Code:
CreateFile(0,GetUserDirectory(#PB_Directory_Desktop) + "World Stamp Collector.desktop")
WriteString(0,"[Desktop Entry]")
WriteString(0,"Type=Application")
WriteString(0,"Name=World Stamp Collector")
WriteString(0,"Terminal=false")
WriteString(0,"Exec=" + #DQUOTE$ + "/home/davemach/Programmes/World Stamp Collector/World Stamp Collector" + #DQUOTE$)
WriteString(0,"Icon=/home/davemach/Programmes/World Stamp Collector/Collection.png")

CloseFile(0)


This creates a file in the users desktop with it's own desktop icon and when clicked lauches that application.

I enclose this in if compiler is linux then ask user create a desktop icon?

Change the E$XEC line for your own application and the Icon line to point at your own png file for the icon.

Just need to crack setting permissions on file to Run as application now without user intervention.

Any ideas.

Hope this helps someone.

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Tue Jan 08, 2019 2:03 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1181
Location: Portugal
I was just looking at the first post and thought of this.

Code:
UsePNGImageDecoder()

ImportC ""
  gtk_window_set_icon_from_file(a.l, b.l, c.l)
  gtk_window_set_icon(a.l,b.l)
EndImport

DataSection
LINUXICON:
IncludeBinary "Collection.png"
EndDataSection


CatchImage(0,?LINUXICON)


Procedure SETLINUXICON(iWindow.i)
   Protected.l lError
  ; gtk_window_set_icon_from_file_(WindowID(iWindow),ImageID(0),lError)
   gtk_window_set_icon(WindowID(iWindow), ImageID(0));
EndProcedure

OpenWindow(0,100,100,300,200,"SOFTWARE",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SETLINUXICON(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
End


icon in exe?

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Tue Jan 08, 2019 4:34 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Dec 17, 2009 12:00 pm
Posts: 212
Location: Llangadog, Wales, UK
Here's what I do to embed the icon in the exe. Very simple if you want the same icon in every window of the program. Just a variation on the above post really.
Code:
ImportC ""
    gtk_window_set_default_icon(a.l)
EndImport

CatchImage(#Image_Icon,?ProgIcon)
gtk_window_set_default_icon(ImageID(#Image_Icon))

DataSection
    ProgIcon: :     IncludeBinary "some_icon.png"
EndDataSection

My understanding about creating desktop launcher icons is that there are different ways for different Desktop Environments (but I'm no expert :? ). The Linux edition of my application isn't generally released yet and I don't do anything for the launcher icon, but I just tell my beta testers to look up the appropriate method for their installation. On some systems it appears to be a simple symbolic link, dragged to the desktop. For others it's a file, similar to the CreateFile post above. I do supply the icon .png in case it's needed. On my own XFCE desktop I just use the "Create Launcher" menu which is pretty easy.

_________________
www.deeproot.co.uk


Top
 Profile  
Reply with quote  
 Post subject: Re: Setting the program's icon in Linux
PostPosted: Thu Jan 17, 2019 1:03 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1181
Location: Portugal
Just found one drawback

After exploring all the ways i could find to create a desktop shortcut ( they all worked sort of) I found my programme would run but would find no records in the database.

Traced this to the currentdirectory() when run from a desktop shortcut it is set to the desktop. I had one area where I relied on g
GetCurrentDirectory() and some where I was opening a local file in the programme which then did not work as it had the wrong directory.

Getting there with linux.

Regards

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 36 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye