Re: How to get a tool button showing up a label (Linux)
Posted: Sat Apr 05, 2014 9:11 pm
Your premises are simply wrong! You expected to receive a GtkToolButton from ToolBarImageButton() although PB's help doesn't state any return value for this function! And the error messageuwekel wrote:It seems that i have missed something. Can anyone help?
should already have given you the hint that ToolBarImageButton() doesn't return a GtkToolButton.assertion 'GTK_IS_TOOL_BUTTON(button)' failed
In these cases it is always helpful to analyse the widget structures PB is using. The following code (which is a slightly modified version of my Widget Explorer already posted here) demonstrates that although PB uses a GtkToolbar, it doesn't use GtkToolItems nor GtkToolButtons but a standard GtkButton with a GtkImage or a GtkLabel:
Code: Select all
GtkWindow
|
-- GtkVBox
|
-- GtkToolbar
|
-- GtkButton
|
-- GtkVBox
|
-- GtkImage
|
-- GtkLabel
Code: Select all
EnableExplicit
ImportC ""
g_type_check_instance_is_a(*Instance.GTypeInstance, *Type.GTypeClass)
EndImport
Define SubnodeLevel.I
NewList FallbackSubnodeLevel.I()
Procedure.I GetChildren(*Widget.GtkWidget)
Shared FallbackSubnodeLevel.I()
Shared SubnodeLevel.I
Protected *Child.GtkWidget
Protected ChildrenCount.I
Protected *ChildrenList.GList
Protected i.I
Protected *WidgetName
If g_type_check_instance_is_a(*Widget\object\parent_instance\g_type_instance,
gtk_container_get_type_()) = #False
If ListSize(FallbackSubnodeLevel()) > 0
LastElement(FallbackSubnodeLevel())
SubnodeLevel = FallbackSubnodeLevel()
DeleteElement(FallbackSubnodeLevel())
EndIf
Else
*ChildrenList = gtk_container_get_children_(*Widget)
ChildrenCount = g_list_length_(*ChildrenList)
If ChildrenCount > 0
For i = 0 To ChildrenCount - 1
*Child = g_list_nth_data_(*ChildrenList, i)
*WidgetName = gtk_widget_get_name_(*Child)
AddGadgetItem(0, -1, PeekS(*WidgetName, -1, #PB_UTF8), 0, SubnodeLevel)
LastElement(FallbackSubnodeLevel())
AddElement(FallbackSubnodeLevel())
FallbackSubnodeLevel() = SubnodeLevel
SubnodeLevel + 1
GetChildren(*Child)
If i = ChildrenCount - 1
If ListSize(FallbackSubnodeLevel()) > 0
LastElement(FallbackSubnodeLevel())
SubnodeLevel = FallbackSubnodeLevel()
DeleteElement(FallbackSubnodeLevel())
EndIf
EndIf
Next i
EndIf
EndIf
EndProcedure
Procedure ExamineWindows()
Shared FallbackSubnodeLevel.I()
Shared SubnodeLevel.I
Protected *Child.GtkWidget
Protected i.I
Protected *WidgetName
Protected WindowCount.I
Protected *Window.GtkWindow
Protected *WindowList.GList
ClearGadgetItems(0)
*WindowList = gtk_window_list_toplevels_()
WindowCount = g_list_length_(*WindowList)
If WindowCount > 0
For i = 0 To WindowCount - 1
*Window = g_list_nth_data_(*WindowList, i)
AddGadgetItem(0, -1, "GtkWindow", 0, 0)
ClearList(FallbackSubnodeLevel())
SubnodeLevel = 1
GetChildren(*Window)
Next i
EndIf
gtk_tree_view_expand_all_(GadgetID(0))
EndProcedure
OpenWindow(0, 100, 100, 460, 300, "Widget Explorer")
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 60)
CreateToolBar(0, WindowID(0))
; ----- Create tool button image
CreateImage(0, 16, 16)
StartDrawing(ImageOutput(0))
Box(1, 1, 14, 14, $FF)
StopDrawing()
; ----- Create a standard tool button with an image
ToolBarImageButton(0, ImageID(0))
ExamineWindows()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Update 2: I have removed the display of a compiler error when compiling in Unicode mode and modified the example to work in ASCII and Unicode mode.
I have modified your example to display your toolbar button with a label:
Code: Select all
ImportC ""
gtk_tool_button_new(*Icon.GtkWidget, Label.P-UTF8)
EndImport
If OpenWindow(0, 0, 0, 300, 250, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
*tb = CreateToolBar(0, WindowID(0))
;create tool button image
*im = CreateImage(0, 16, 16)
StartDrawing(ImageOutput(0))
Box(1, 1, 14, 14, $FF)
StopDrawing()
;create an API tool button with an image and a label
ImageWidget = gtk_image_new_from_pixbuf_(*im)
*bt = gtk_tool_button_new(ImageWidget, "Hello")
gtk_toolbar_set_style_(*tb, #GTK_TOOLBAR_BOTH)
gtk_toolbar_insert_(*tb, *bt, -1)
gtk_widget_show_all_(WindowID(0))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf