Adding a widget to a PB WIndow?

Linux specific forum
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Adding a widget to a PB WIndow?

Post by Justin »

It is possible to add a widget to a PB window? I can't get the gtkFixed widget if it's what PB uses, i found this code on the forum but does not work, any ideas?

Code: Select all

EnableExplicit

Define.i win, fixedBox, widget

win = OpenWindow(#PB_Any, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
fixedBox = g_list_nth_data_(gtk_container_get_children_(gtk_bin_get_child_(WindowID(win))), 0)
Debug fixedBox
widget = gtk_drawing_area_new_()
Debug widget
gtk_fixed_put_(fixedBox, widget, 0, 0) ;ERROR NOT GTKFIXED

Repeat
Until	 WaitWindowEvent() = #PB_Event_CloseWindow
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Adding a widget to a PB WIndow?

Post by Oma »

Hi Justin,

this only works on gtk2-subsystem and only for widgets like fixed backgrounds etc.

The hierarchy for a real PB-Gadget is on gtk2:
GtkWindow > GtkVBox > GtkFixed > GADGET

On gtk3-subsystem (to get it compatible as much as possible to gtk2-fixed-position-and-size system ):
GtkWindow > GtkVBox > GtkScrolledWindow > GtkViewport > GtkFixed > GADGET

I think you get a lot of work :wink:

Regards, Charly

ps: hierarchy corrected, Sun Aug 13, 2017 6:12 pm
Last edited by Oma on Sun Aug 13, 2017 6:13 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
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Adding a widget to a PB WIndow?

Post by Justin »

Thanks for the info. I found a workaround, just put a container, is already a gtkFixed, you can use gtk_fixed_put_() directly on it.
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Adding a widget to a PB WIndow?

Post by Justin »

My workaround did not work as expected, i needed the widget in the main window, it works in the first gtkFixed, going to the second gives errors, are you sure it is the correct hierarchy?

Code: Select all

EnableExplicit

Define.i win, FixedBox, widget

win = OpenWindow(#PB_Any, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
;GtkWindow > GtkVBox > GtkScrolledWindow > GtkViewport > GtkFixed > GtkScrolledWindow > GtkViewport > GtkFixed >

FixedBox = g_list_nth_data_(gtk_container_get_children_(WindowID(win)), 0) ;GtkVBox
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkScrolledWindow
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkViewport
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed WORKS
Debug FixedBox

; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkScrolledWindow
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkViewport
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed ;ERROR
; Debug FixedBox

widget = gtk_button_new_with_label_("TEST")

gtk_fixed_put_(fixedBox, widget, 0, 0) 
gtk_widget_show_(widget)

Repeat
Until	 WaitWindowEvent() = #PB_Event_CloseWindow
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Adding a widget to a PB WIndow?

Post by Oma »

Sorry! :oops:
Of course it was a mistake (taken from an older demo and forgot to remove the GtkScrolledWindow in which all Gadget-Types was placed to debug the structure)
The hierarchy above has been corrected!

Now the 1. button should be visible ...

Code: Select all

ImportC ""
	gtk_widget_get_name(*widget.GtkWidget)
EndImport

Define.i win, FixedBox, widget

win = OpenWindow(#PB_Any, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
;GtkWindow > GtkVBox > GtkScrolledWindow > GtkViewport > GtkFixed > GtkScrolledWindow > GtkViewport > GtkFixed >

;gtk3
; FixedBox = g_list_nth_data_(gtk_container_get_children_(WindowID(win)), 0) ;GtkVBox
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkScrolledWindow
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkViewport
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed WORKS
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; Debug FixedBox

;gtk2
FixedBox = g_list_nth_data_(gtk_container_get_children_(WindowID(win)), 0) ;GtkVBox
Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed ;ERROR
Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
Debug FixedBox

widget = gtk_button_new_with_label_("TEST")

gtk_fixed_put_(fixedBox, widget, 0, 0)
gtk_widget_show_(widget)

Repeat
Until    WaitWindowEvent() = #PB_Event_CloseWindow
ps: To avoid problems in the future ...
For all API commands which uses parameters which are not of the type integer or long, you should use 'ImportC' with the proper types. Here ...

Code: Select all

ImportC ""
	gtk_button_new_with_label(text.p-utf8)
EndImport
Only a few non-integer-parameters was adapted correctly in the PB API calls.
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Adding a widget to a PB WIndow?

Post by Justin »

Great. Thank you.
Post Reply