Getting started with sample widgets
Most of the examples have been converted from the gtk3 official examples
ported to BaCon code
as a reference only to make it easier to see
how to code it with BaCon
'--- updated to work wih 64 bit mint 20.1 April 26 2021'--- set up for compiling embedded library GTKPRAGMAOPTIONS`pkg-config--cflagsgtk+-3.0`PRAGMALDFLAGS`pkg-config--libsgtk+-3.0`PRAGMAINCLUDE<gtk-3.0/gtk/gtk.h>PRAGMACOMPILERgccPRAGMAOPTIONS-Wno-implicit-Wno-deprecated-declarationsOPTIONPARSEFALSEPROTOgtk_initPROTOgtk_window_newPROTOgtk_mainPROTOgtk_main_quitPROTOgtk_window_set_titlePROTOgtk_container_addPROTOgtk_toggle_button_set_activePROTOgtk_widget_show_allPROTOgtk_window_set_default_sizePROTOgtk_window_set_titlePROTOgtk_application_newPROTOgtk_application_window_newPROTOgtk_check_button_new_with_labelPROTOg_signal_connect_dataPROTOgtk_toggle_button_get_activePROTOgtk_main_quitDECLAREwindowTYPEvoid*DECLAREcheckbuttonTYPEvoid*'=====================SUBexit_prog'=====================gtk_main_quitENDSUB'====================SUBtoggled_cb'===================='--- signal handler for "toggled" signal of the CheckButton TBUT=gtk_toggle_button_get_active(checkbutton)IFTBUT=1THENgtk_window_set_title(window,"CheckButton Example")ELSEgtk_window_set_title(window,"Callback working")ENDIFPRINTTBUTENDSUBgtk_init(0,0)window=gtk_window_new(0)gtk_window_set_title(window,"CheckButton Example")gtk_window_set_default_size(window,300,100)g_signal_connect_data(window,"delete-event",exit_prog,0,0,0)checkbutton=gtk_check_button_new_with_label("Show Title")gtk_toggle_button_set_active(checkbutton,TRUE)g_signal_connect_data(checkbutton,"notify::active",toggled_cb,0,0,0)gtk_container_add(window,checkbutton)gtk_widget_show_all(window)gtk_main
'--- updated to work wih 64 bit mint 20.1 April 26 2021'--- set up for compiling embedded library GTKPRAGMAOPTIONS`pkg-config--cflagsgtk+-3.0`PRAGMALDFLAGS`pkg-config--libsgtk+-3.0`PRAGMAINCLUDE<gtk-3.0/gtk/gtk.h>PRAGMACOMPILERgccPRAGMAOPTIONS-Wno-implicit-Wno-deprecated-declarationsOPTIONPARSEFALSEPROTOgtk_initPROTOgtk_window_newPROTOgtk_mainPROTOgtk_main_quitPROTOgtk_window_set_titlePROTOgtk_widget_show_allPROTOg_signal_connect_dataPROTOgtk_spinner_newPROTOgtk_spinner_startPROTOgtk_spinner_stopPROTOgtk_container_addPROTOgtk_window_set_default_sizePROTOgtk_box_newPROTOgtk_box_set_homogeneousPROTOgtk_box_pack_startPROTOgtk_radio_action_set_groupDECLAREwindowTYPEvoid*DECLAREspinnerTYPEvoid*DECLAREboxTYPEvoid*DECLAREradio1TYPEvoid*DECLAREradio2TYPEvoid*DECLAREactionTYPEvoid*'=====================SUBexit_prog'=====================gtk_main_quitENDSUB'=====================SUBradio_clicked()'=====================CLEARPRINT"button1"gtk_spinner_start(spinner)ENDSUB'=====================SUBradio_clicked2()'=====================CLEARPRINT"button2"gtk_spinner_stop(spinner)ENDSUBgtk_init(0,0)window=gtk_window_new(0)gtk_window_set_default_size(window,250,200)gtk_window_set_title(window,"Spinner test")g_signal_connect_data(window,"delete-event",exit_prog,0,0,0)box=gtk_box_new(GTK_ORIENTATION_VERTICAL,2)gtk_box_set_homogeneous(box,TRUE)spinner=gtk_spinner_new()'---Create a radio button1 with a labelradio1=gtk_radio_button_new_with_label_from_widget(radio1,"Start spinner.")g_signal_connect_data(radio1,"clicked",radio_clicked,0,0,0)'---Create a radio button2 with a labelradio2=gtk_radio_button_new_with_label_from_widget(radio2,"Stop spinner.")g_signal_connect_data(radio2,"clicked",radio_clicked2,0,0,0)'---Pack them into a box, then show all the widgetsgtk_box_pack_start(box,radio1,TRUE,TRUE,2)gtk_box_pack_start(box,radio2,TRUE,TRUE,2)gtk_box_pack_start(box,spinner,TRUE,TRUE,2)gtk_container_add(window,box)gtk_widget_show_all(window)gtk_main
'--- updated to work wih 64 bit mint 20.1 April 26 2021'--- set up for compiling embedded library GTKPRAGMAOPTIONS`pkg-config--cflagsgtk+-3.0`PRAGMALDFLAGS`pkg-config--libsgtk+-3.0`PRAGMAINCLUDE<gtk-3.0/gtk/gtk.h>PRAGMACOMPILERgccOPTIONPARSEFALSEPROTOgtk_initPROTOgtk_window_newPROTOgtk_mainPROTOgtk_main_quitPROTOg_signal_connect_dataPROTOgtk_box_set_homogeneousPROTOgtk_box_newPROTOgtk_box_pack_startPROTOgtk_container_addPROTOgtk_widget_show_allDECLAREwindowTYPEvoid*DECLAREboxTYPEvoid*DECLAREradio1TYPEvoid*DECLAREradio2TYPEvoid*DECLAREradio3TYPEvoid*'=====================SUBexit_prog'=====================gtk_main_quitENDSUB'=====================SUBradio_clicked()'=====================CLEARPRINT"button1"ENDSUB'=====================SUBradio_clicked2()'=====================CLEARPRINT"button2"ENDSUB'=====================SUBradio_clicked3()'=====================CLEARPRINT"button3"ENDSUBgtk_init(0,0)window=gtk_window_new(GTK_WINDOW_TOPLEVEL)gtk_window_set_title(GTK_WINDOW(window),"Radio 2021")gtk_window_set_default_size(GTK_WINDOW(window),330,70)box=gtk_box_new(GTK_ORIENTATION_VERTICAL,2)gtk_box_set_homogeneous(box,TRUE)g_signal_connect_data(window,"delete-event",exit_prog,0,0,0)'---Create a radio button1 with a labelradio1=gtk_radio_button_new_with_label_from_widget(radio1,"I'm the first radio button.")g_signal_connect_data(radio1,"clicked",radio_clicked,0,0,0)'---Create a radio button2 with a labelradio2=gtk_radio_button_new_with_label_from_widget(radio2,"I'm the second radio button.")g_signal_connect_data(radio2,"clicked",radio_clicked2,0,0,0)'---Create a radio button3 with a labelradio3=gtk_radio_button_new_with_label_from_widget(radio3,"I'm the third radio button.")g_signal_connect_data(radio3,"clicked",radio_clicked3,0,0,0)'---Pack them into a box, then show all the widgetsgtk_box_pack_start(box,radio1,TRUE,TRUE,2)gtk_box_pack_start(box,radio2,TRUE,TRUE,2)gtk_box_pack_start(box,radio3,TRUE,TRUE,2)gtk_container_add(window,box)gtk_widget_show_all(window)gtk_main
'--- updated to work wih 64 bit mint 20.1 April 26 2021'--- set up for compiling embedded library GTKPRAGMAOPTIONS`pkg-config--cflagsgtk+-3.0`PRAGMALDFLAGS`pkg-config--libsgtk+-3.0`PRAGMAINCLUDE<gtk-3.0/gtk/gtk.h>PRAGMACOMPILERgccPRAGMAOPTIONS-Wno-implicit-Wno-deprecated-declarationsOPTIONPARSEFALSEPROTOgtk_initPROTOgtk_window_newPROTOgtk_mainPROTOgtk_main_quitPROTOg_signal_connect_dataPROTOgtk_container_addPROTOgtk_container_set_border_widthPROTOgtk_scrolled_window_set_policyPROTOgtk_text_view_set_wrap_modePROTOgtk_widget_show_allPROTOgtk_window_set_default_sizePROTOgtk_window_set_titlePROTOgtk_application_newPROTOgtk_application_window_newPROTOgtk_scrolled_window_newPROTOgtk_text_buffer_newPROTOgtk_text_view_new_with_bufferDECLAREwindowTYPEvoid*DECLAREbufferTYPEvoid*DECLAREtext_viewTYPEvoid*DECLAREscrolled_windowTYPEvoid*'=====================SUBexit_prog'=====================gtk_main_quitENDSUBgtk_init(0,0)'--- Create a window with a title, and a default size window=gtk_window_new(0)gtk_window_set_title(window,"TextView Example GTK3 2021")gtk_window_set_default_size(window,400,200)g_signal_connect_data(window,"delete-event",exit_prog,0,0,0)'--- The text buffer represents the text being edited buffer=gtk_text_buffer_new(NULL)'--- Text view is a widget in which can display the text buffer. '--- The line wrapping is set to break lines in between words.text_view=gtk_text_view_new_with_buffer(buffer)gtk_text_view_set_wrap_mode(text_view,GTK_WRAP_WORD)'--- Create the scrolled window. Usually NULL is passed for both parameters so '--- that it creates the horizontal/vertical adjustments automatically. Setting '--- the scrollbar policy to automatic allows the scrollbars to only show up '--- when needed. scrolled_window=gtk_scrolled_window_new(NULL,NULL)gtk_scrolled_window_set_policy(scrolled_window,GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC)'--- The function directly below is used to add children to the scrolled window '--- with scrolling capabilities (e.g text_view), otherwise, '--- gtk_scrolled_window_add_with_viewport() would have been usedgtk_container_add(scrolled_window,text_view)gtk_container_set_border_width(scrolled_window,5)gtk_container_add(window,scrolled_window)gtk_widget_show_all(window)gtk_main
'--- updated to work wih 64 bit mint 20.1 April 26 2021'--- set up for compiling embedded library GTKPRAGMAOPTIONS`pkg-config--cflagsgtk+-3.0`PRAGMALDFLAGS`pkg-config--libsgtk+-3.0`PRAGMAINCLUDE<gtk-3.0/gtk/gtk.h>PRAGMACOMPILERgccPRAGMAOPTIONS-Wno-implicit-Wno-deprecated-declarationsOPTIONPARSEFALSEPROTOgtk_initPROTOgtk_window_newPROTOgtk_mainPROTOgtk_main_quitPROTOg_signal_connect_dataPROTOgtk_container_addPROTOgtk_widget_show_allPROTOgtk_switch_newPROTOgtk_window_set_titlePROTOgtk_window_set_default_sizePROTOgtk_container_set_border_widthPROTOgtk_switch_set_activePROTOgtk_grid_set_column_spacingPROTOgtk_grid_attachDECLAREswitch1TYPEvoid*DECLAREwindowTYPEvoid*DECLAREgridTYPEvoid*DECLARElabelTYPEvoid*'=====================SUBexit_prog'=====================gtk_main_quitENDSUB'=====================SUBswitch_clicked()'=====================CLEARPRINT"switch button1"SW1=gtk_switch_get_active(switch1)PRINTSW1ENDSUBgtk_init(0,0)'---Create a window with a set title and default size.'---Also, set a border width for the amount of space'---to leave inside the windowwindow=gtk_window_new(0)gtk_window_set_title(window,"Switch Example")gtk_window_set_default_size(window,300,100)gtk_container_set_border_width(window,10)g_signal_connect_data(window,"delete-event",exit_prog,0,0,0)'---Create a label---'label=gtk_label_new("Title")'---Create a switch with a default active stateswitch1=gtk_switch_new()gtk_switch_set_active(switch1,TRUE)'---Create a grid and set the column spacing,'---attach the label'---switch onto the grid'---position them accordinglygrid=gtk_grid_new()gtk_grid_set_column_spacing(grid,10)gtk_grid_attach(grid,label,0,0,1,1)gtk_grid_attach(grid,switch1,1,0,1,1)'---Connecting the clicked signal to the callbackg_signal_connect_data(switch1,"notify::active",switch_clicked,0,0,0)gtk_container_add(window,grid)gtk_widget_show_all(window)gtk_main
'--- updated to work wih 64 bit mint 20.1 April 26 2021'--- set up for compiling embedded library GTKPRAGMAOPTIONS`pkg-config--cflagsgtk+-3.0`PRAGMALDFLAGS`pkg-config--libsgtk+-3.0`PRAGMAINCLUDE<gtk-3.0/gtk/gtk.h>PRAGMACOMPILERgccOPTIONPARSEFALSEPROTOgtk_label_set_textPROTOgtk_container_addPROTOgtk_container_set_border_widthPROTOgtk_grid_attachPROTOgtk_grid_set_column_homogeneousPROTOgtk_grid_set_column_spacingPROTOgtk_widget_set_hexpandPROTOgtk_widget_show_allPROTOgtk_window_set_default_sizePROTOgtk_window_set_titlePROTOgtk_adjustment_newPROTOgtk_application_newPROTOgtk_window_newPROTOgtk_grid_newPROTOgtk_label_newPROTOgtk_spin_button_get_value_as_intPROTOgtk_spin_button_newPROTOgtk_initPROTOgtk_mainPROTOg_signal_connect_dataPROTOgtk_main_quit'--- Declare variablesDECLAREwindowTYPEvoid*DECLARElabelTYPEvoid*DECLAREgridTYPEvoid*DECLAREspin_buttonTYPEvoid*DECLAREadjustmentTYPEvoid*'==============SUBEXIT_PROG'==============gtk_main_quitENDSUB'--- This is the callback function.'--- It is a handler function which reacts to the signal.'--- In this case, it will notify the user the value of their spinbutton'==============SUBspin_clicked'==============value=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_button))PRINTvalueENDSUBgtk_init(0,0)'--- Create a window with a title, a border width, and a default sizewindow=gtk_window_new(GTK_WINDOW_TOPLEVEL)gtk_window_set_title(GTK_WINDOW(window),"SpinButton Example 2021")gtk_window_set_default_size(GTK_WINDOW(window),330,70)gtk_container_set_border_width(GTK_CONTAINER(window),5)'---Connecting the clicked signal to the callback functiong_signal_connect_data(window,"destroy",EXIT_PROG,0,0,0)'--- Create a label to be shown in the windowlabel=gtk_label_new("Press enter to get the value")'--- Create an adjustment representing an adjustable bounded valueadjustment=gtk_adjustment_new(0,0,100,1,0,0)'--- Create a spin button that is to be as wide as possiblespin_button=gtk_spin_button_new(adjustment,1,0)gtk_widget_set_hexpand(spin_button,TRUE)'--- Connecting the "value-changed" signal for the spinbutton'--- to the appropriate callback function.g_signal_connect_data(spin_button,"activate",spin_clicked,0,0,0)'--- Create a grid and arrange everything accordinglygrid=gtk_grid_new()gtk_grid_set_column_spacing(GTK_GRID(grid),10)gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE)gtk_grid_attach(GTK_GRID(grid),spin_button,0,0,1,1)gtk_grid_attach(GTK_GRID(grid),label,0,1,1,1)gtk_container_add(GTK_CONTAINER(window),grid)gtk_widget_show_all(window)gtk_main
This is how to add a timeout to GTK3
and use it with PROTO
now the progressbar auto updates automatically
there wasn't a complete simple example so I had to make one
I had to add a few void* casts for 64 bit machines
Example code: progress-gtk3-proto.bac
'--- updated to work with 64 bit mint 20.1 April 26 2021'--- set up for compiling embedded library GTKPRAGMAOPTIONS`pkg-config--cflagsgtk+-3.0`PRAGMALDFLAGS`pkg-config--libsgtk+-3.0`PRAGMAINCLUDE<gtk-3.0/gtk/gtk.h>PRAGMACOMPILERgccOPTIONPARSEFALSEPROTOgtk_initPROTOgtk_window_newPROTOgtk_main_quitPROTOgtk_mainPROTOgtk_container_addPROTOgtk_grid_attachPROTOgtk_grid_attach_next_toPROTOgtk_progress_bar_pulsePROTOgtk_widget_show_allPROTOgtk_window_set_titlePROTOgtk_application_newPROTOgtk_button_new_with_labelPROTOgtk_grid_newPROTOgtk_progress_bar_newPROTOgtk_window_newPROTOg_signal_connect_dataPROTOgtk_progress_bar_set_fractionPROTOgtk_progress_bar_get_fractionPROTOgtk_window_set_default_sizePROTOg_timeout_add'--- Declare variablesDECLAREwindowTYPEvoid*DECLAREprogress_barTYPEvoid*DECLAREgridTYPEvoid*DECLAREbuttonTYPEvoid*fraction=0.1'---How to use a time out to update a progress bar'=============================FUNCTIONtimeout_callbackTYPEint'=============================gtk_progress_bar_pulse(progress_bar)'---Increase the bar by 10% each time this function is called'---Fill in the bar with the new fractiongtk_progress_bar_set_fraction(progress_bar,fraction)fraction=fraction+0.1IFfraction>=1THENfraction=0ENDIFRETURNTRUEENDFUNCTION'==============SUBEXIT_PROG'==============gtk_main_quitENDSUBgtk_init(0,0)'---Create the window and set a titlewindow=gtk_window_new(0)gtk_window_set_title(window,"Progress Example")gtk_window_set_default_size(window,270,70)g_signal_connect_data(window,"destroy",EXIT_PROG,0,0,0)'---Create a button with a labelbutton=gtk_button_new_with_label("QUIT")'---Create the progress barprogress_bar=gtk_progress_bar_new()'---Create a grid and attach the button and progress bar accordinglygrid=gtk_grid_new()gtk_grid_attach(grid,button,1,1,1,1)gtk_grid_attach_next_to(grid, \
progress_bar, \
button, \
GTK_POS_BOTTOM,1,1)'---Connecting the clicked signal to the callback functiong_signal_connect_data(button,"clicked",EXIT_PROG,0,0,0)g_timeout_add(500,(void*)timeout_callback,NULL)gtk_container_add(window,grid)gtk_widget_show_all(window)gtk_main
Embed GTK3 in BaCon
updated to work on mint 20.1 xfce 64bit 2021
Summary Convert GTK3 official examples to BaCon
The official site is http://www.basic-converter.org/
The official forum is http://basic-converter.proboards.com/
Getting started with sample widgets
Most of the examples have been converted from the gtk3 official examples
ported to BaCon code
as a reference only to make it easier to see
how to code it with BaCon
and there are more demos here
Page 2 demos
Page 3 demos
Page 4 demos
Page 5 demos
Page 6 demos
Page 7 demos
Last edit: big-bass 2021-05-05
CHECK
how to convert official examples to Simplified embedded gtk ones in BaCon
using this official example code as the reference
https://developer.gnome.org/gnome-devel-demos/stable/checkbutton.c.html.en
Example code: check-gtk3-proto.bac
Last edit: big-bass 2021-04-28
SPINNER
original code was not complete to show callbacks and a fully working example
https://developer.gnome.org/gnome-devel-demos/stable/spinner.c.html.en
had to add callbacks , buttons and signals
Example code: spinner-gtk3-proto.bac
Last edit: big-bass 2021-04-28
RADIO
https://developer.gnome.org/gnome-devel-demos/stable/radiobutton.c.html.en
Example code: radio-gtk3-proto.bac
Last edit: big-bass 2021-04-28
TEXT
another official example
https://developer.gnome.org/gnome-devel-demos/stable/textview.c.html.en
Example code: text-gtk3-proto.bac
Last edit: big-bass 2021-04-28
SWITCH
Example code: switch-gtk3-proto.bac
Last edit: big-bass 2021-04-28
SPINBUTTON3
original code ported and modified
https://developer.gnome.org/gnome-devel-demos/stable/spinbutton.c.html.en]
Example code: spinbutton-gtk3-proto.bac
Last edit: big-bass 2021-04-28
PROGRESS
This is how to add a timeout to GTK3
and use it with PROTO
now the progressbar auto updates automatically
there wasn't a complete simple example so I had to make one
I had to add a few void* casts for 64 bit machines
Example code: progress-gtk3-proto.bac
Last edit: big-bass 2021-04-28