|
Post by vovchik on Sept 25, 2017 20:57:43 GMT 1
Dear Joe, Thanks for updating all the examples and for the very clear presentation. I am wondering whether the html shouldn't also be available as a downloadable pdf, so that people can use it offline in much the same way as the documentation.pdf for BaCon. Just an idea... With kind regards, vovchik Attachments:baacon-and-hug.pdf (416.77 KB)
|
|
|
Post by bigbass on Sept 26, 2017 4:26:22 GMT 1
Hey vovchik
Looks like you had the same Problem when converting to PDF That happened to me The images of the widgets shrink very small maybe I will try another app to do the conversion Also all the code goes double spaced ?
*To clear up what I said I tried libre office at first and it double spaced all code But it can adjust the image size
I Agree if we can get a pdf Like a book format that woud be even better I didnt have much luck with the conversion to pdf
Edited to focus on the pdf
Looking for a better app to Work on html to pdf
Yes it would be better For a download
And as always vovchik you Are kind and helpful Thanks!
Joe
|
|
|
Post by rikky on Jan 27, 2018 20:30:15 GMT 1
Since the professionals are working on FLTK Gui's which are way above my head, but I want to contribute something, I decided to make a new example widget for this old tutorial. Since it took me 2 days to figure this out, I suppose this might be helpful for new newbies. It's all already there in bits and pieces on the forum, and mostly stolen from an example of Alexfish. But there was not an example sec, only for FILEDIALOG So here it is. (added a show hidden files checkbox) INCLUDE hug.bac
GTK$= HUGLIB$("gtk")
set_filename$ = GETENVIRON$("HOME") & "/test.bac" fileselect_action = 1 : ' "Open File” (0), "Save File" (1), "Select Folder" (2) or "Create Folder" (3). ask_overwrite = TRUE add_shortcut_folders$ = GETENVIRON$("HOME") & "/Documents " & GETENVIRON$("HOME") & "/Pictures"
IF fileselect_action = 2 OR fileselect_action = 3 THEN set_filename$ = DIRNAME$(set_filename$) END IF
SELECT fileselect_action CASE 0 title$ = "Open File" CASE 1 title$ = "Save File" CASE 2 title$ = "Select Folder" CASE 3 title$ = "Create Folder" END SELECT IMPORT "gtk_file_chooser_add_filter(long,long)" FROM GTK$ TYPE long IMPORT "gtk_file_filter_add_pattern(long,char*)" FROM GTK$ TYPE long IMPORT "gtk_file_filter_new" FROM GTK$ TYPE long IMPORT "gtk_file_filter_set_name(long,char*)" FROM GTK$ TYPE void IMPORT "gtk_file_chooser_set_show_hidden(long,int)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_file_chooser_set_do_overwrite_confirmation(long,int)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_file_chooser_set_create_folders(long,int)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_file_chooser_add_shortcut_folder(long,char*,void*)" FROM "libgtk-x11-2.0.so" TYPE int IMPORT "gtk_file_chooser_remove_shortcut_folder(long,char*,void*)" FROM "libgtk-x11-2.0.so" TYPE int : ' doesnt work IMPORT "gtk_file_chooser_set_extra_widget(long,long)" FROM "libgtk-x11-2.0.so" TYPE void
SUB File_Dialog(NUMBER dialog, int button)
HIDE(dialog) IF button = GTK_RESPONSE_CANCEL THEN 'PRINT "GTK_RESPONSE_CANCEL" END 1 END IF 'following doesnt work, GTK_RESPONSE_CLOSE = -7 IF button = GTK_RESPONSE_CLOSE THEN 'PRINT "GTK_RESPONSE_CLOSE" END 1 END IF IF button = -4 THEN : ' THE REAL GTK_RESPONSE_CLOSE 'PRINT "GTK_RESPONSE_CLOSE" END 1 END IF files$ = GRAB$(dialog) PRINT files$ QUIT END SUB
SUB check_demo() this_check = GET(My_check) gtk_file_chooser_set_show_hidden(fileselec,this_check) SYNC END SUB 'INIT : ' The INIT command is automatically executed when including hug.bac, see the remark of Peter further on. fileselec = FILEDIALOG(title$, "Ok", 600, 400, fileselect_action) My_check = CHECK("show hidden files", 120, 25) FOR i$ IN add_shortcut_folders$ gtk_file_chooser_add_shortcut_folder(fileselec,i$,NULL) NEXT i$ IF fileselect_action = 0 OR fileselect_action = 1 THEN filter1 = gtk_file_filter_new() gtk_file_filter_set_name(filter1, "BaCon source files (*.bac)") gtk_file_filter_add_pattern(filter1, "*.bac") filter2 = gtk_file_filter_new() gtk_file_filter_set_name(filter2, "backup files (*.bak)") gtk_file_filter_add_pattern(filter2, "*.bak") filter3 = gtk_file_filter_new() gtk_file_filter_set_name(filter3, "All files (*)") gtk_file_filter_add_pattern(filter3, "*")
gtk_file_chooser_add_filter(fileselec, filter1) gtk_file_chooser_add_filter(fileselec, filter2) gtk_file_chooser_add_filter(fileselec, filter3) END IF CALLBACK(fileselec, File_Dialog) CALLBACK(My_check, check_demo) gtk_file_chooser_set_extra_widget(fileselec,My_check) gtk_file_chooser_set_filename(fileselec,set_filename$) gtk_file_chooser_set_do_overwrite_confirmation(fileselec,ask_overwrite) gtk_file_chooser_set_create_folders(fileselec,TRUE) SHOW(fileselec)
DISPLAY
With kind regards: Rik
|
|
|
Post by bigbass on Jan 27, 2018 22:07:16 GMT 1
Hello rikky Thanks for posting it compiled cleanly and ran on my 64 bit box I just want to note without a long winded answer that I like HUG and the idea behind it and Peter did an excellent job with it ! there are some reasons we tried different ideas 1.) HUG is gtk2 stable but many things are now in gtk3 also 2.) we wanted to use gtk3 too 3.) there are new widgets we wanted to port This idea and syntax is very much alive vovhik and I are trying to do the same idea as HUG because we like it and as all good things they grow adapt and continue (nobody could do it better than Peter but he has other things he is busy with ) and if he decided to do a HUG fltk that would be excellent here are some more widgets basic-converter.proboards.com/post/10420and more info here basic-converter.proboards.com/post/10420/threadJoe
|
|
|
Post by Pjot on Jan 28, 2018 10:42:06 GMT 1
Thanks Rik! Well done, you clearly understand the mechanism in GTK programming and how it all works with callbacks Just one remark: the INIT() function automatically is executed when the 'hug.bac' is included. I discovered that on some systems, it might even cause a crash to use INIT() one more time. So it is better to omit it. But if you would have compiled the 'hug.bac' context as a shared object (providing 'hug.so'), and then would have imported the HUG functions from that library, in that case an explicit call to INIT() is required in your program. Regarding GTK3, as it does support Wayland next to X, and more and more distributions are moving to Wayland as their default graphical environment, porting HUG to GTK3 will be inevitable. The problem with GTK3 is however, that intermediate releases kept changing the API for some widgets. Therefore I did not take the effort to port HUG to GTK3. Best regards Peter
|
|
|
Post by rikky on Feb 27, 2018 18:11:02 GMT 1
Next example, also mostly stolen from Alexfish: basic-converter.proboards.com/post/7552/threadCleaned everything not connected to vte_terminal away, and added a command button. VTE terminal : INCLUDE hug.bac
VTE$ = "libvte.so.9" GTK$= HUGLIB$("gtk")
IMPORT gtk_widget_realize(long) FROM GTK$ TYPE void
IMPORT "vte_terminal_new (void)" FROM VTE$ TYPE long IMPORT "vte_terminal_fork_command(long, char*, char*, char*, char*, int, int,int)" FROM VTE$ TYPE void IMPORT "vte_terminal_feed_child(long,char*,long)" FROM "libvte.so.9" TYPE void
SUB TERMEXEC()
vte_terminal_fork_command(term, NULL, NULL, NULL, NULL, 0, 0, 0)
END SUB FUNCTION TERMINAL (int hug_xsize, int hug_ysize)
' create vte terminal emulator term = vte_terminal_new()
' Create scrolled window scrolled = gtk_scrolled_window_new(0, 0) gtk_scrolled_window_set_policy(scrolled, 1, 1) gtk_scrolled_window_set_shadow_type(scrolled, 3) gtk_container_add(scrolled, term)
gtk_widget_show_all(scrolled)
hug_widget_xsize(STR$(scrolled)) = hug_xsize hug_widget_ysize(STR$(scrolled)) = hug_ysize hug_widget_signal(STR$(scrolled)) = 5
g_signal_connect_data(term,"realize",TERMEXEC,0,0,0)
RETURN scrolled
ENDFUNCTION
SUB do_command
command$ = "foo=\"hello Bacon\"" & NL$ length = LEN(command$) vte_terminal_feed_child(term,command$, length) command$ = "echo $foo" & NL$ length = LEN(command$) vte_terminal_feed_child(term,command$, length) END SUB
win = WINDOW("VTE",600,400)
terminal=TERMINAL(590,360) ATTACH(win,terminal,5,5) command_button = BUTTON("command",80, 25) ATTACH(win,command_button,515, 370) CALLBACK(command_button,do_command) DISPLAY
Rik.
|
|
|
Post by vovchik on Feb 27, 2018 18:33:39 GMT 1
Dear Rik, Thanks. It works fine, and is nice and tidy. I got a warning from this line: IMPORT gtk_widget_realize(long) FROM GTK$ TYPE void since it is already in my HUG and doesn't need importing. Apart from that, it compiles fine and works nicely. The next enhancement could be piping input from the command line or a script, for which you will need to use INPUT$ and/or ARGUMENT$. With kind regards, vovchik
|
|
|
Post by rikky on Feb 27, 2018 19:10:05 GMT 1
Aj, yah, now I see. Me too I got a duplicate symbol error It is that I have seen so much letters, that I don't notice anymore. Done, program blablabla ready is all I look for. Time to take a break. What is INPUT$ The reason I want vte-terminal is for I am in the process of making a gui for Omxplayer for the raspberry pi. VLC and other players are far too slow for this little machine, and kino turns your mouse into an elephant that you have to drag trough the mud on its trunk. Only you can not execute omxplayer from out of Bacon. SYSTEM "omxplayer & " stucks, for some reason. So I use the linux screen command to start omxplayer, with the extra side effect, that now I am able to send keystrokes to the player, as well as dbus commands, witch is nice. However, now I have a program, as good as ready, that is half not Bacon, so I thought to use vte terminal. But first the break. Thanks. Rik.
|
|
|
Post by vovchik on Feb 27, 2018 19:27:24 GMT 1
Dear Rik,
I see what you are after. I am also interested, since I have a Raspberry PI3, too (and fltk and hug-fltk run on it, too). INPUT$ is a BaCon command. You might want to capture piped info into the terminal and BaCon's INPUT$ function is what I have used for that purpose in the past in writing filters.
With kind regards, vovchik
|
|
|
Post by bigbass on Jun 23, 2018 8:11:31 GMT 1
multiple checkbox that waits until you decide from the options what you want to select when you are happy with your choices then press Get resultsI was thinking about a list of packages to install but it waits until you confirm before any action is made ' checkbox2.bac
INCLUDE "hug.bac"
' we want to "echo out" which checkbox was pressed ' this could launch another app
'-------------------- SUB checkbox_demo '-------------------- '--- clean terminal and EDIT CLEAR TEXT(My_Edit,"")
IF GET(My_checkbox) == TRUE THEN TEXT(My_Edit,GRAB$(My_checkbox)&NL$) selected$ = GRAB$(My_checkbox) PRINT selected$ END IF IF GET(My_checkbox2) == TRUE THEN TEXT(My_Edit,GRAB$(My_checkbox2)&NL$) selected$ = GRAB$(My_checkbox2) PRINT selected$ END IF
IF GET(My_checkbox3) == TRUE THEN TEXT(My_Edit,GRAB$(My_checkbox3)&NL$) selected$ = GRAB$(My_checkbox3) PRINT selected$ END IF
IF GET(My_checkbox4) == TRUE THEN TEXT(My_Edit,GRAB$(My_checkbox4)&NL$) selected$ = GRAB$(My_checkbox4) PRINT selected$ END IF
IF GET(My_checkbox5) == TRUE THEN TEXT(My_Edit,GRAB$(My_checkbox5)&NL$) selected$ = GRAB$(My_checkbox5) PRINT selected$ END IF
END SUB
window = WINDOW("multiple checkboxes", 450, 200 )
My_checkbox = CHECK("checkbox 1", 120, 25) My_checkbox2 = CHECK("checkbox 2", 120, 25) My_checkbox3 = CHECK("checkbox 3", 120, 25) My_checkbox4 = CHECK("checkbox 4", 120, 25) My_checkbox5 = CHECK("checkbox 5", 120, 25)
My_ok = BUTTON("Get results", 120, 25) My_Edit=EDIT(200,100)
ATTACH( window, My_checkbox, 20, 10 ) ATTACH( window, My_checkbox2, 20, 40 ) ATTACH( window, My_checkbox3, 20, 70 ) ATTACH( window, My_checkbox4, 20, 100 ) ATTACH( window, My_checkbox5, 20, 130 ) ATTACH( window, My_ok, 280, 140 ) ATTACH( window,My_Edit,200,10)
CALLBACK(My_ok, checkbox_demo) DISPLAY
|
|
|
Post by vovchik on Jun 23, 2018 13:35:18 GMT 1
Dear Joe,
Nice and clean - and useful. Thanks...
With kind regards, vovchik
|
|
|
Post by bigbass on Apr 3, 2019 16:05:38 GMT 1
Hey Guys with some new development using HUG going on I thought to up date this thread with new widgets I will add to HUG what I mean by "add" is to work with the original unedited hug.bac but IMPORT widgets so that we have new widgets to choose from in 2019 Joe
'--- a working generic template made from linkbutton.c '--- Ported from the gtk3 gnome offical demo to BaCon IMPORTS in (gtk2) by bigbass '--- updated to compile with HUG finally !!!
INCLUDE hug.bac GTK$ = HUGLIB$("gtk")
'--- auto generated a short IMPORTS list of gtk function with args HUG styled IMPORT "gtk_container_add(long,long)" FROM GTK$ TYPE void IMPORT "gtk_link_button_new(char*)" FROM GTK$ TYPE long IMPORT "gtk_link_button_set_uri(long,char*)" FROM GTK$ TYPE void IMPORT "gtk_widget_show_all(long)" FROM GTK$ TYPE void IMPORT "gtk_window_set_default_size(long,int,int)" FROM GTK$ TYPE void IMPORT "gtk_window_set_title(long,char*)" FROM GTK$ TYPE void
'--- auto generated a short IMPORTS list of gtk/ gdk functions with args HUG styled '--- we need these always IMPORT "gtk_init(int*,void*)" FROM GTK$ TYPE void IMPORT "gtk_main" FROM GTK$ TYPE void IMPORT "gtk_main_quit(int)" FROM GTK$ TYPE void IMPORT "gtk_window_new(int)" FROM GTK$ TYPE long
'===================== SUB exit_prog '===================== gtk_main_quit(0) END SUB
SUB RunLink() SHOW(mes) '--- embed a ported gtk3 to gtk2 then used in HUG gtk_init(0, 0) window =gtk_window_new(0)
gtk_window_set_title (window, "BaCon LinkButton") gtk_window_set_default_size (window, 250, 50)
linkbutton = gtk_link_button_new ("Link to The BaCon Website!") gtk_link_button_set_uri (linkbutton, "http://www.basic-converter.org/") gtk_container_add (window, linkbutton) gtk_widget_show_all (window) gtk_main END SUB
window = WINDOW("WINDOW",300,200) but = BUTTON("link button",100,20) mes = MSGDIALOG("The link button was ported from gtk3 \n and is now used in HUG! ", 300, 100, 0, 0) ATTACH (window,but,0,10) CALLBACK(but,RunLink) DISPLAY
|
|
|
Post by bigbass on Apr 4, 2019 15:48:36 GMT 1
Hey Guys I decided to take a step back and finish some work I started a very long time ago to add some widgets to compile in BaCon using PROTO but now add the widgets so the work together with HUG when we include hug.bac what this means is hug.bac stays unchanged and official and I will post stand alone code you can add as you need this way everything stays stable and easy to modify here is the gtk2 official fileselect now ported to work with HUG fileselect-gtk2-import.bac
INCLUDE hug.bac
'--- Ported and modified to work for HUG by bigbass
GTK$= HUGLIB$("gtk")
PRAGMA OPTIONS -Wno-implicit OPTION PARSE FALSE IMPORT "gtk_file_selection_complete(long,char*)" FROM GTK$ TYPE void IMPORT "gtk_file_selection_get_filename(long)" FROM GTK$ TYPE char* IMPORT "gtk_file_selection_set_filename(long,char*)" FROM GTK$ TYPE void IMPORT "gtk_init(int*,void*)" FROM GTK$ TYPE void IMPORT "gtk_main" FROM GTK$ TYPE void IMPORT "gtk_widget_show(long)" FROM GTK$ TYPE void IMPORT "gtk_file_selection_new(char*)" FROM GTK$ TYPE long IMPORT "gtk_main_quit" FROM GTK$ TYPE void IMPORT "gtk_dialog_run(long)" FROM GTK$ TYPE int IMPORT "gtk_widget_destroy(long)" FROM GTK$ TYPE void IMPORT "gtk_exit(int)" FROM GTK$ TYPE void
PROTO g_timeout_add
'--- low level button signals CONST GTK_RESPONSE_OK = -5 CONST GTK_RESPONSE_CANCEL = -6 CONST GTK_RESPONSE_CLOSE = -7 CONST GTK_RESPONSE_DELETE_EVENT = -4
'===================== SUB exit_prog() '=====================
PRINT "HERE" gtk_exit(0) END SUB
'===================== SUB file_ok_sel() '===================== '--- Get the selected filename and print it to the console
PRINT "you got to the call back file_ok_sel" selected$ = (char *)gtk_file_selection_get_filename (filew) PRINT selected$ END SUB
'--- Create a new file selection widget filew = gtk_file_selection_new ("File selection")
'--- Lets set the filename, as if this were a save dialog, and we are giving a default filename gtk_file_selection_set_filename (filew, "penguin.png")
'--- GTK_RESPONSE_OK '--- major work around to connect buttons using the reponses '--- after a modified callback using just the callback name IF gtk_dialog_run(filew ) = GTK_RESPONSE_OK THEN PRINT "The low level OK button was pressed " file_ok_sel END IF
'--- GTK_RESPONSE_CANCEL '--- major work around to connect buttons using the reponses '--- after a modified callback using just the callback name IF gtk_dialog_run(filew ) = GTK_RESPONSE_CANCEL THEN PRINT "The low level CANCEL button was pressed " PRINT "close main window" exit_prog
END IF
g_signal_connect_data(filew, "destroy", exit_prog, 0, 0, 0)
SHOW(filew) DISPLAY
|
|
|
Post by bigbass on Apr 4, 2019 16:54:03 GMT 1
we could use a menu too for a HUG widget and a simple demo for it
INCLUDE hug.bac
'--- Ported and modified to work for HUG by bigbass '--- we needed a menu widget GTK$= HUGLIB$("gtk")
PRAGMA OPTIONS -Wno-implicit OPTION PARSE FALSE
IMPORT "gtk_box_pack_start(long,long,int,int,int)" FROM GTK$ TYPE void IMPORT "gtk_container_add(long,long)" FROM GTK$ TYPE void IMPORT "gtk_init(int*,void*)" FROM GTK$ TYPE void IMPORT "gtk_main" FROM GTK$ TYPE void IMPORT "gtk_menu_item_set_submenu(long,long)" FROM GTK$ TYPE void IMPORT "gtk_menu_shell_append(long,long)" FROM GTK$ TYPE void IMPORT "gtk_widget_show_all(long)" FROM GTK$ TYPE void IMPORT "gtk_widget_show(long)" FROM GTK$ TYPE void IMPORT "gtk_window_set_position(long,int)" FROM GTK$ TYPE void IMPORT "gtk_window_set_default_size(long,int,int)" FROM GTK$ TYPE void IMPORT "gtk_window_set_title(long,char*)" FROM GTK$ TYPE void IMPORT "gtk_menu_bar_new" FROM GTK$ TYPE long IMPORT "gtk_menu_item_new_with_label(char*)" FROM GTK$ TYPE long IMPORT "gtk_menu_new" FROM GTK$ TYPE long IMPORT "gtk_vbox_new(int,int)" FROM GTK$ TYPE long IMPORT "gtk_window_new(int)" FROM GTK$ TYPE long IMPORT "gtk_main_quit" FROM GTK$ TYPE void
' get the needed missing values CONST GTK_WINDOW_TOPLEVEL = 0 CONST GTK_WIN_POS_CENTER = 1
'===================== SUB exit_prog '===================== gtk_main_quit(0) END SUB
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_position(window, GTK_WIN_POS_CENTER) gtk_window_set_default_size(window, 450, 200) gtk_window_set_title(window, "Menu Demo") g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0)
vbox = gtk_vbox_new(FALSE, 0) gtk_container_add(window, vbox)
menubar = gtk_menu_bar_new() filemenu = gtk_menu_new()
file = gtk_menu_item_new_with_label("File") quit = gtk_menu_item_new_with_label("Quit")
gtk_menu_item_set_submenu(file, filemenu) gtk_menu_shell_append(filemenu, quit) gtk_menu_shell_append(menubar, file) gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 3)
g_signal_connect_data(quit, "activate",exit_prog, 0, 0, 0) gtk_widget_show_all(window)
DISPLAY
|
|
|
Post by bigbass on Apr 5, 2019 18:20:17 GMT 1
I know you Guys like a challenge for the lack of a complete working demo code example in the docs to follow ( Didn't find any other 100% HUG example ) we have to piece somethings together using gtk at times .I tried to do this with all official code but had to improvise to get the signal on this one it works but should work without an IMPORT www.basic-converter.org/hugdoc.html#FILEDIALOGbut connecting the signals to the call back is confusing even when you know how do it to work in pure gtk I almost got it 100% HUG code except one IMPORT I had to use to get the event working maybe some one could remove that one IMPORT and get it to work the correct way I saw that Alex had the same problem converting it to 100% HUG in another post I tried this but no luck now I see why this wont work we need a wait 'IF GET(My_filedialog ) == GTK_RESPONSE_ACCEPT THEN so had to IMPORT "gtk_dialog_run(long)" FROM GTK$ TYPE int its maybe something really easy I overwlooked or still don't understand well or we need the import developer.gnome.org/gtk2/stable/GtkDialog.html#gtk-dialog-run INCLUDE hug.bac
GTK$= HUGLIB$("gtk")
IMPORT "gtk_dialog_run(long)" FROM GTK$ TYPE int
win = WINDOW("WINDOW",250,250)
SUB FILE_DIALOG() LOCAL File_name LOCAL File_name$ PRINT "you got to the call back FILE_DIALOG()" 'FILEDIALOG("title", "caption", xsize, ysize, action) 'Creates a dialog with a filebrowser. Depending on <action> 'the dialog maybe used for '"Open File” = (0), '"Save File" = (1), '"Select Folder" = (2) '"Create Folder"= (3).
'By default the dialog will be hidden. Use the SHOW 'function to make it visible. Returns the ID of the created dialog
My_filedialog = FILEDIALOG("File Open demo","Open",200,200,0) SHOW(My_filedialog)
'--- major work around to connect buttons using the reponses '--- after a modified callback using just the callback name
'IF GET(My_filedialog ) == GTK_RESPONSE_ACCEPT THEN IF gtk_dialog_run(My_filedialog ) == GTK_RESPONSE_ACCEPT THEN
'--- figure out what signal is sent then remove uneeded 'IF gtk_dialog_run(My_filedialog ) = GTK_RESPONSE_YES '||GTK_RESPONSE_ACCEPT || GTK_RESPONSE_OK || GTK_RESPONSE_APPLY THEN
PRINT "gtk_dialog_run test the sent signal " PRINT "The low level OK button was pressed " file_name$ = GRAB$(My_filedialog) PRINT file_name$ HIDE(My_filedialog)
END IF END SUB
My_button = BUTTON("File",70,30) ATTACH(win,My_button,36,52) CALLBACK(My_button,FILE_DIALOG)
DISPLAY
|
|