Icon/native image options in Linux

Linux specific forum
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Icon/native image options in Linux

Post by Vera »

Keya wrote:I call Oma's ButtonImages_Activate() also... do you get the error in my version too? in my version i only call it after initialising them (ive got no idea if that makes a difference or not - perhaps youve just found the answer, i just moved it to the end as it felt right, lol), so if you move that call down towards the end does that fix this problem?
No - hopefully yes - yes ;-)

Sorry I didn't check back that it worked fine with your first version.
And I can confirm that it is only the position of ButtonImages_Activate() within Oma's code that triggers the warning. Commenting or placeing it at the end of the whole gui-build will run the code without warning.

Seems you had a good feeling ~ and now you surely do :D

Oma wrote:@Vera:
Sprichst Du noch mit mir? :oops:
Of course - I thought I'd never stopped
... and I'd be happy if we can pick it up again Image
The Property "gtk-button-images" exists in gtk2- and gtk3-GtkSettings :?:
I missed to say thanks about the "gdk-pixbuf-query-loaders" - console tip. I had no idea it could be done and it too showed me a long list of supported formats for gtk2 [no gtk3 installed over here]

cheers ~ Vera
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Icon/native image options in Linux

Post by Keya »

Vera wrote:
Keya wrote:I call Oma's ButtonImages_Activate() also... do you get the error in my version too? in my version i only call it after initialising them (ive got no idea if that makes a difference or not - perhaps youve just found the answer, i just moved it to the end as it felt right, lol), so if you move that call down towards the end does that fix this problem?
No - hopefully yes - yes ;-)

Sorry I didn't check back that it worked fine with your first version.
And I can confirm that it is only the position of ButtonImages_Activate() within Oma's code that triggers the warning. Commenting or placeing it at the end of the whole gui-build will run the code without warning.

Seems you had a good feeling ~ and now you surely do :D
lol! it just had a vibe :D
and it too showed me a long list of supported formats for gtk2 [no gtk3 installed over here]
so this method works on Gtk2 also?!? fantastic!
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Icon/native image options in Linux

Post by Oma »

Hello Keya,

Concerning filenames...
it's possible that Linux Filename encoding isn't really fix, but Desktop systems like Ubuntu etc. with Glib/gtk handle it with UTF8.
In functions like g_file_read_link() you can read "...The returned string is in the encoding used for filenames. Use g_filename_to_utf8() to convert it to UTF-8"
I'm sure there are filenames which can't be properly handled in Ascii so UTF8 poses the least risk.
Interesting regarding the error you encountered during the formats enumeration ... is that problem solved if we have a window and messageloop? *fingers crossed*
Yes! But i made a similar test to yours and thought (due to the error messages) the commands are not available in the current PureBasic.
I never had problems with short test-snippets on PB. But it seems that any use of gtk-commands need a window and event loop OR a MessageRequester.
Maybe, only this way PB calls an gtk_init() etc. Otherwise the functions are unknown to PB?

And it's a bit strange that the PixbufEnumeration does't list "svg" on my Xubuntu as "gdk-pixbuf-query-loaders" in a terminal does. But vectorgraphics works well like bitmap formats according to my tests.

Concern DevHelp-Dokumentation:
I should more often take a look at the online documentation because the 'gdk_pixbuf_format..' and 'gdk_pixbuf_loader' are not included like so many other gtk/gdk-functions.
ps. Oma what is the reason your original button demo has ButtonImages_Activate commented out? (i couldnt see any icons until i uncommented it)
Only a very few distributions like Mint with -X-themes don't show separator lines, frames and images on buttons on their 'very empty' surfaces. They are disabled/hided by default. (Edit: Just saw that in Mint 17.2 (updated this weekend) the images or visible without activation!)
On the most distributions this widgets are visible without a change of the setting.
I think if a user chooses the theme, he doesn't want to see this decorations.
I placed it as a hint to the programmer, to see the possiblity to override the theme-default-setting or to solve the "this sh.. programm is not working"-problem. Or (maybe) the programmer thinks it's always necessary to see them.
Perhaps it would be better to place a comment about the theme problem in the library code?

And you could check the button images system setting this way (not tested on Mint) ...

Code: Select all

ImportC ""
	g_object_get_property(*widget.GtkWidget, property.p-utf8, *gval)
EndImport

Global.i gEvent, gQuit
#G_TYPE_BOOLEAN  = 20

Procedure ButtonImages_isActivated()
	Protected   gVal.GValue
	Protected.i Ret
	
	g_value_init_(@gval, #G_TYPE_BOOLEAN)
	g_object_get_property(gtk_settings_get_default_(), "gtk-button-images", @gval)
	Ret= g_value_get_boolean_(@gval)
	g_value_unset_(@gval)
 ProcedureReturn Ret
EndProcedure

If OpenWindow(0, 300, 200, 500, 200, "Check ButtonImagesState", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TextGadget(0, 5, 5, 490, 40, "")
	If ButtonImages_isActivated()
		SetGadgetText(0, "ButtonImages are shown on this system")
	Else
		SetGadgetText(0, "ButtonImages aren't shown on this system. Use ButtonImages_Activate(Show)")
	EndIf
	
	Repeat
		If WaitWindowEvent() = #PB_Event_CloseWindow
			gQuit= #True
		EndIf
	Until gQuit
EndIf

@Vera
I'll send you a mail the next days or weekend. :D

So, back to the real word
Bye, Charly
Last edited by Oma on Tue Sep 22, 2015 5:16 pm, edited 1 time in total.
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Icon/native image options in Linux

Post by Oma »

Hello Keya (once more),
a small addendum to your Enumerate supported image formats.

The missing image format svg in my list has left me no rest and i had a look at the loop conditions in the code:
> And voila. In this way, the last entry will be omitted.

I've changed the loop in your code this way (so the last format in the list is also included):

Code: Select all

EnableExplicit

ImportC ""
  gdk_pixbuf_get_formats()
  gdk_pixbuf_format_is_writable(pdata)
EndImport

Procedure GdkEnumPixbufFormats()
  Protected sAccess.s, *gdkfmts.GSList = gdk_pixbuf_get_formats()
  If *gdkfmts
    Repeat
      If gdk_pixbuf_format_is_writable(*gdkfmts\data): sAccess = "RW:": Else: sAccess = "R:": EndIf
      Debug( sAccess + #TAB$ + PeekS(PeekI(*gdkfmts\data),-1,#PB_Ascii) )
      *gdkfmts = *gdkfmts\next    ;linked list
    Until *gdkfmts = 0
  EndIf
EndProcedure
 
GdkEnumPixbufFormats()
MessageRequester("Done","Finished enumerating, see Debug window")
Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Icon/native image options in Linux

Post by Keya »

Oma wrote:And you could check the button images system setting this way (not tested on Mint) ...
That code answered my next question heehee :) yes i was wondering how on earth we could detect whether or not the activate was required
I tested it on my Mint and it correctly said that it needed activate, nice work and thanks for solving that problem :)
Also good catch with that pixbuf formats loop! That poor last element, always getting forgotten :( i updated my code

ps. dont forget to move your ButtonImages_Activate() call down after the rest of the gtk code, as my vibe detected and Vera confirmed, lol :)
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Icon/native image options in Linux

Post by Oma »

ps. dont forget to move your ButtonImages_Activate() call down after the rest of the gtk code, as my vibe detected and Vera confirmed, lol
Do you mean above the OpenWindow?
The curious thing: I've tested it with Lubuntu, Xubuntu, Ubuntu, Kubuntu and Mint 17.2 (all gtk2/gtk3) without any warning.

Bye
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Icon/native image options in Linux

Post by Keya »

I didnt notice any errors either, but Vera confirmed that the placement of the activate call was the problem on their system at least ... moving it lower down in the code after all the other gdk stuff resolved it. I can't really say any more about it :)
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Icon/native image options in Linux

Post by Keya »

im just wondering if anyone has an example using image gadget instead of button?
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Icon/native image options in Linux

Post by Oma »

Hello Keya!
Since i'm too dumb :| to put a link to a single posting:
Go to page 2 and scroll to the mid.
Line 84 in this code creates a
ImageGadget(#ImG1, 200, 110, 16, 16, GetGadgetPixbuf(?Img4, ?Img5-?Img4))
or did I misunderstand you?

Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Icon/native image options in Linux

Post by Keya »

Oma wrote:Hello Keya!
Since i'm too dumb :| to put a link to a single posting:
I see your dumbness and raise you an I'm so dumb I didn't even realise all we had to do was SetGadgetState(#Image, *pixbuf), lol :D
But it was seeing your GetGadgetPixbuf() routine that made me realise that, thankyou! :)
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Icon/native image options in Linux

Post by Keya »

Load PNG into ImageGadget (native API instead of UsePNGDecoder)

Code: Select all

EnableExplicit
 
ImportC ""
	gdk_pixbuf_loader_new.i()
	gdk_pixbuf_loader_write.l(*loader, buf.a, *count, _gerror.i=0)
	gdk_pixbuf_loader_get_pixbuf.i(*loader)	
	gdk_pixbuf_loader_close(*loader, *gerror)	
EndImport
 
#Image1=1
 
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 200, 200, "Linux Image Control")  
   Define hFile.i, *pimg, iLen.i, *pixbuf, *gerr, *loader
   hFile.i = ReadFile(#PB_Any, #PB_Compiler_Home + "/examples/sources/Data/world.png")
   If hFile = 0
     MessageRequester("Error","Couldnt readfile PNG")
   Else
     iLen = Lof(hFile)
     *pimg = AllocateMemory(iLen+8)
     ReadData(hFile, *pimg, iLen)
     CloseFile(hFile)
     Define *loader = gdk_pixbuf_loader_new()
     gdk_pixbuf_loader_write(*loader, *pimg, iLen, 0)
     gdk_pixbuf_loader_close(*loader, *gerr)
     *pixbuf = gdk_pixbuf_loader_get_pixbuf(*loader)
   EndIf      
   ImageGadget(#Image1, 20, 20, 100, 100, *pixbuf)
   ;or to set an existing imagegadget:  SetGadgetState(#Image1, *pixbuf)
EndIf
 
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Post Reply