|
Post by bigbass on Apr 7, 2013 16:22:03 GMT 1
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Apr 8, 2013 1:29:28 GMT 1
Your Makefile generated the following error for me. jrs@laptop:~/BaCon/B30$ make Makefile:9: *** missing separator (did you mean TAB instead of 8 spaces?). Stop. jrs@laptop:~/BaCon/B30$ I was able to compile the example using gcc direct. gcc switch-c.c -o switch-c `pkg-config gtk+-3.0 --cflags --libs`
|
|
|
Post by bigbass on Apr 8, 2013 3:57:33 GMT 1
Hey jrs
Good to see that it compiles in C that shows that gtk is fine
*sorry about the make file posting in bbc code eats the tabs when you copy and paste so I uploaded the make file as a raw file
Joe
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Apr 8, 2013 16:32:16 GMT 1
Let me know if you figure out what the problem is/was with your original BaCon switch.bac. I like where you are going with that and hope you don't give up the fight.
|
|
|
Post by alexfish on Apr 8, 2013 17:22:47 GMT 1
Hi Joe & John I have Ubuntu 11.10 + gtk2+ and gtk3+ examples of gtk2 and gtk3 work without any mods to the configs. Nice PROTO demo's joe , BR Alex
|
|
|
Post by bigbass on Apr 9, 2013 6:45:19 GMT 1
having fun with this a different spin on the spinner experimenting with callbacks and mixing widgets spinner-gtk3-proto.bac
PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-3.0`
PROTO gtk_init PROTO gtk_window_new PROTO gtk_main PROTO gtk_main_quit PROTO gtk_window_set_title PROTO gtk_widget_show_all PROTO g_signal_connect_data PROTO gtk_spinner_new PROTO gtk_spinner_start PROTO gtk_spinner_stop PROTO gtk_container_add PROTO gtk_window_set_default_size PROTO gtk_box_new PROTO gtk_box_set_homogeneous PROTO gtk_box_pack_start
GTK_ORIENTATION_VERTICAL = 1
'===================== SUB exit_prog '===================== gtk_main_quit END SUB
'===================== SUB radio_clicked() '===================== CLEAR PRINT "button1" gtk_spinner_start (spinner) END SUB
'===================== SUB radio_clicked2() '===================== CLEAR PRINT "button2" gtk_spinner_stop (spinner) END SUB
gtk_init(0, 0)
window = gtk_window_new () gtk_window_set_default_size (window, 200, 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 label radio1 = 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 label radio2 = 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 widgets gtk_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
|
|
|
Post by bigbass on Apr 9, 2013 15:19:26 GMT 1
I guess seeing the output in the GUI gives the correct effect of turning on and off a light switch and shows how to connect the signal from the toggle to a widget Just something to think about It's not difficult to add the PROTO functions manually this has the advantage to see what you need to keep things transparent ( to make custom widgets)
but for the lazy it would be nice to have a parser automate all the needed PROTO functions there are still many widget examples to do first and test but the idea had been done with IMPORTS by *gatordog* so it should be even easier to do for PROTO
toggle-spinner-gtk3-proto.bac compile by using PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-3.0`
PROTO gtk_init PROTO gtk_window_new PROTO gtk_main PROTO gtk_main_quit PROTO g_signal_connect_data PROTO gtk_container_add PROTO gtk_widget_show_all PROTO gtk_switch_new PROTO gtk_window_set_title PROTO gtk_window_set_default_size PROTO gtk_container_set_border_width PROTO gtk_switch_set_active PROTO gtk_grid_set_column_spacing PROTO gtk_grid_attach PROTO gtk_spinner_new PROTO gtk_spinner_start PROTO gtk_spinner_stop
'===================== SUB exit_prog '===================== gtk_main_quit END SUB
'===================== SUB switch_clicked() '===================== CLEAR PRINT "switch button1" SW1 = gtk_switch_get_active (switch1) IF SW1 = 1 THEN gtk_spinner_start (spinner) ELSE gtk_spinner_stop (spinner) END IF PRINT SW1 END SUB
gtk_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 window
window = gtk_window_new () 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 ("Spin")
'---Create a switch with a default active state switch1 = gtk_switch_new () gtk_switch_set_active (switch1, FALSE)
spinner = gtk_spinner_new ()
'---Create a grid and set the column spacing, '---attach the label '---switch onto the grid '---position them accordingly grid = 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)
gtk_grid_attach (grid, spinner, 2, 0, 20, 20)
'---Connecting the clicked signal to the callback g_signal_connect_data(switch1, "notify::active",switch_clicked, 0, 0, 0)
gtk_container_add (window, grid) gtk_widget_show_all (window) gtk_main
|
|
|
Post by alexfish on Apr 9, 2013 17:50:46 GMT 1
Hi Joe
will this Help
Have done a quicky to help with this
Have saved the gtk-proto.bac and done a bit of coding.
Need to change the path and name to suit
try to stick with gtk conventions , have put button as a hint
INCLUDE hug.bac HUGOPTIONS("NOSCALING") ' CHANGE THE PATH AND NAME OF YOUR PROTO FILE PROTO_FILE$ = "/bacon/gtk-proto.bac"
SUB Button_1_Clicked
search$=GRAB$(Entry_1) IF (search$ > "") THEN TEXT(List_1,"") OPEN PROTO_FILE$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN txt$ FROM myfile txt$=CHOP$(txt$) IF INSTR(txt$,search$) THEN TEXT(List_1,txt$) END IF WEND CLOSE FILE myfile END IF END SUB
SUB List_1_Clicked
prot$= GRAB$(List_1) TEXT(Edit_1,prot$) TEXT(Edit_1,NL$) END SUB
Window_1=WINDOW("Proto",770 , 400)
Entry_1=ENTRY("gtk_button_",285 , 25) ATTACH(Window_1 , Entry_1, 5 , 355)
Edit_1=EDIT(475 , 330) ATTACH(Window_1 , Edit_1, 290 , 10)
List_1=LIST(275 , 330) ATTACH(Window_1 , List_1, 5 , 10) CALLBACK( List_1 , List_1_Clicked )
Button_1=BUTTON("Search",130 , 35) ATTACH(Window_1 , Button_1, 305 , 355) CALLBACK( Button_1 , Button_1_Clicked )
DISPLAY
if search is positive , then click on the required PROTO in the list , it should be available in the edit , can the use copy and paste
BR
Alex
|
|
|
Post by vovchik on Apr 9, 2013 19:32:21 GMT 1
@ Joe and Alex,
GREAT STUFF! THANKS.
With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Apr 9, 2013 22:01:48 GMT 1
I'm still in the doghouse with no BaCon bits to munch on. :-(
jrs@laptop:~/BaCon/B30$ ./toggle-spinner-gtk3-proto
(toggle-spinner-gtk3-proto:4264): Gtk-CRITICAL **: gtk_window_new: assertion `type >= GTK_WINDOW_TOPLEVEL && type <= GTK_WINDOW_POPUP' failed
(toggle-spinner-gtk3-proto:4264): Gtk-CRITICAL **: gtk_window_set_title: assertion `GTK_IS_WINDOW (window)' failed
(toggle-spinner-gtk3-proto:4264): Gtk-CRITICAL **: gtk_window_set_default_size: assertion `GTK_IS_WINDOW (window)' failed
(toggle-spinner-gtk3-proto:4264): Gtk-CRITICAL **: gtk_container_set_border_width: assertion `GTK_IS_CONTAINER (container)' failed
(toggle-spinner-gtk3-proto:4264): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(toggle-spinner-gtk3-proto:4264): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed Segmentation fault (core dumped) jrs@laptop:~/BaCon/B30$
|
|
|
Post by bigbass on Apr 10, 2013 5:58:53 GMT 1
Hey Alex Wow that's already very useful ! with just a little bit of time it would be an automatic parser but I like it as is Thank you! Joe
|
|
|
Post by alexfish on Apr 10, 2013 13:13:46 GMT 1
Hey Alex Wow that's already very useful ! with just a little bit of time it would be an automatic parser but I like it as is Thank you! Joe Hi Joe Would something like this do INCLUDE hug.bac
HUGOPTIONS("NOSCALING") ' CHANGE THE PATH AND NAME OF YOUR PROTO FILE PROTO_FILE$ = "/bacon/gtk-proto.bac"
SUB Button_1_Clicked LOCAL search$ search$=GRAB$(Entry_1) IF (search$ > "") THEN TEXT(List_1,"") OPEN PROTO_FILE$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN txt$ FROM myfile txt$=CHOP$(txt$) IF INSTR(txt$,search$) THEN TEXT(List_1,txt$) END IF WEND CLOSE FILE myfile END IF END SUB
SUB Edit_1_Clicked
LOCAL iter1,iter2,getlines LOCAL search$
iter1 = MEMORY(HUG_DEFAULT_WIDGET_SIZE) iter2 = MEMORY(HUG_DEFAULT_WIDGET_SIZE)
getlines = GET(Edit_1)-1
gtk_text_buffer_get_iter_at_line(hug_widget_font(STR$(Edit_1)),iter1,getlines) gtk_text_buffer_get_end_iter(hug_widget_font(STR$(Edit_1)), iter2) search$=gtk_text_buffer_get_text(hug_widget_font(STR$(Edit_1)), iter1,iter2,1)
search$=CHOP$(search$) IF (search$ > " ") THEN IF INSTR(search$,"_") THEN TEXT(List_1,"") OPEN PROTO_FILE$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN txt$ FROM myfile txt$=CHOP$(txt$) IF INSTR(txt$,search$) THEN TEXT(List_1,txt$) END IF WEND CLOSE FILE myfile END IF END IF FREE iter1 FREE iter2
END SUB
Window_1=WINDOW("Proto",770 , 400)
Entry_1=ENTRY("gtk_button_",285 , 25) ATTACH(Window_1 , Entry_1, 5 , 355)
Edit_1=EDIT(475 , 330) ATTACH(Window_1 , Edit_1, 290 , 10) CALLBACK( Edit_1 , Edit_1_Clicked )
List_1=LIST(275 , 330) ATTACH(Window_1 , List_1, 5 , 10) ' CALLBACK( List_1 , List_1_Clicked )
Button_1=BUTTON("Search",130 , 35) ATTACH(Window_1 , Button_1, 305 , 355) CALLBACK( Button_1 , Button_1_Clicked )
DISPLAY
Could be possible to improve this , Could even be done PROTO style + source code highlighting either for GTK or BaCon / could be switch-able could also add a compile button . Forgot : start by typing in the EDITOR to the right BR Alex
|
|
|
Post by bigbass on Apr 10, 2013 15:46:30 GMT 1
the cude basic idea is here in bash replace this /usr/share/BaCon/about-c.c with any c coded gtk file run it in the terminal to see what it does
lazy bash was just the first thing that comes to mind I know this can be done in bacon too
the signals
|
|
|
Post by vovchik on Apr 10, 2013 17:28:16 GMT 1
Dear Alex, The old PROTO you posted above works fine (and is great) but the new one is giving me problems. Don't know why yet. Also, I thought BaCon couldn't do this: IF (search$ > "") I was under the impression that it had to be something like: IF LEN(search$) > 0 and once wrote a fuction to make string comparisons (STRCMP). Learned something today. Thanks. With kind regards, vovchik
|
|
|
Post by alexfish on Apr 10, 2013 18:04:33 GMT 1
Hi Vovchik IF (search$ > "") This will though an err on linefeed or carriage return, so using space is a lazy mans hack , so be it , Hence IF (search$ > " ") but since looking for changes on key strokes = "_" , it does not matter about the space. hence will only return true , Update: Tried theIF LEN(search$) > 0 Did exactly what thought it would do , CRAAAASH . oh forget to change path since did a direct copy from the site , So no it did not crash. can use either or of the two , perhaps LEN option may be better in the long term.. try a miss-spell. @ Joe U mean parse a c file to a Bacon Proto that is easy in Bacon , can adapt the scripts I have done to do so. Bacon has REPLACE$ , CONCAT$ , EXTRACT$ etc etc But think Cheating on Homework , not good idea BR Alex
|
|