|
Post by bigbass on May 20, 2020 16:35:43 GMT 1
Hello There are several ways to use gtk in BaCon Let's just call them different coding styles which means one style may be more useful or not depending on what you want/need to do there are many different styles in this thread and here's one more the important part is they all compile in BaCon ! Recently BaCon has the ability to use gtk which is built into the bacon binary now and this idea uses a GTK_TYPE basic-converter.proboards.com/post/13109To understand how things are connected together I will show a stand alone widget my demo is not the "simple way" but is a very powerful way once it is understood we are using g_object directly! I'll get back to the point and show the code Joe '--- using the GTK_TYPE and g_object '--- to understand the lowest level of gtk '--- OBJECTIVE to see another way to get signals and callbacks directly '--- bigbass May 20 2020 PRAGMA OPTIONS `pkg-config --cflags gtk+-2.0` PRAGMA LDFLAGS `pkg-config --libs gtk+-2.0`
PRAGMA INCLUDE <gtk-2.0/gtk/gtk.h> PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-implicit
'--- show smoke and mirrors at the low level OPTION PARSE FALSE
DECLARE window TYPE GtkWindow* DECLARE button TYPE GtkWidget* '========================== SUB hello '========================== PRINT "Hello BaCon" END SUB
'========================== SUB delete_event '========================== PRINT "That's all folks!" END END SUB
'========================== SUB end_program '========================== PRINT "end" END END SUB
gtk_init(0, 0) window = g_object_new(GTK_TYPE_WINDOW, "title", "Using a g_object window", "border-width", 10, "default-height", 100, "default-width", 400, NULL)
'---SIGNAL HANDLERS for the window g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), NULL) g_signal_connect(window, "destroy", G_CALLBACK(end_program), NULL)
'--- create a button as a GTK_TYPE_BUTTON button = g_object_new(GTK_TYPE_BUTTON, "label", "_Hello, BaCon!\nClick Here.","use-underline", TRUE, NULL) '---SIGNAL HANDLERS for button g_signal_connect(button, "clicked", G_CALLBACK(hello),NULL) '---PACK THE BUTTON into the window gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(button)) gtk_widget_show_all(GTK_WIDGET(window)) gtk_main()
|
|
|
Post by vovchik on May 20, 2020 18:31:40 GMT 1
Dear Joe,
Thanks. It's always good for people to see what goes on behind the scenes, and this is very much like the code you would write in C, but without the semi-colons everywhere.
With kind regards, vovchik
|
|
|
Post by bigbass on May 20, 2020 19:18:31 GMT 1
ok vovchik in my attempt to be transparent maybe I was too transparent this time only aliased but we did not have any examples before with g_object using GTK_TYPE like the new GUI uses (PS I was thinking about connecting those low level signals in GUIDEFINE) Joe '--- using the GTK_TYPE and g_object '--- to understand the lowest level of gtk '--- OBJECTIVE to see another way to get signals and callbacks directly '--- bigbass May 20 2020 PRAGMA OPTIONS `pkg-config --cflags gtk+-2.0` PRAGMA LDFLAGS `pkg-config --libs gtk+-2.0`
PRAGMA INCLUDE <gtk-2.0/gtk/gtk.h> PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-implicit
'--- show smoke and mirrors at the low level OPTION PARSE FALSE
ALIAS g_object_new TO GUI ALIAS GTK_TYPE_WINDOW TO WINDOW ALIAS G_CALLBACK TO CALLBACK ALIAS GTK_TYPE_BUTTON TO BUTTON ALIAS GTK_WIDGET TO WIDGET ALIAS gtk_init TO INIT ALIAS g_signal_connect TO HANDLERS ALIAS gtk_widget_show_all TO SHOW ALIAS gtk_main TO DISPLAY
ALIAS gtk_container_add TO ATTACH ALIAS GTK_CONTAINER TO CONTAINER
DECLARE window TYPE GtkWindow* DECLARE button TYPE GtkWidget* '========================== SUB hello '========================== PRINT "Hello BaCon" END SUB
'========================== SUB delete_event '========================== PRINT "That's all folks!" END END SUB
'========================== SUB end_program '========================== PRINT "end" END END SUB
INIT(0, 0) window = GUI(WINDOW, "title", "Using a g_object window", "border-width", 10, "default-height", 100, "default-width", 400, NULL)
'---SIGNALS HANDLERS for the window HANDLERS(window, "delete-event", CALLBACK(delete_event), NULL) HANDLERS(window, "destroy", CALLBACK(end_program), NULL)
'--- create a button as a GTK_TYPE_BUTTON button = GUI(BUTTON, "label", "_Hello, BaCon!\nClick Here.","use-underline", TRUE, NULL) '---SIGNALS HANDLERS for button HANDLERS(button, "clicked", CALLBACK(hello),NULL) '---PACK THE BUTTON into the window ATTACH(CONTAINER(window), WIDGET(button)) SHOW(WIDGET(window)) DISPLAY
|
|
|
Post by vovchik on May 20, 2020 20:00:15 GMT 1
Dear Joe,
Thanks. A few more aliases would also be useful - e.g. SETPROPERTY, GETPROPERTY and HIDE/SHOW (for widgets), and a SNYC to refresh the display. AND GtkFixed.
I think we have, as the result of your earlier work, most of that for GK2 and GK3.
With kind regards, vovchik
|
|
|
Post by bigbass on May 21, 2020 7:32:47 GMT 1
in another post we were getting callbacks from dialogs here is also another way and we have callbacks now documentation to change the dialogs basic-converter.proboards.com/post/1988Joe P.S vovchik thanks for the suggestions I will add those also to a demo PRAGMA OPTIONS `pkg-config --cflags gtk+-2.0` PRAGMA LDFLAGS `pkg-config --libs gtk+-2.0`
PRAGMA INCLUDE <gtk-2.0/gtk/gtk.h> PRAGMA OPTIONS -Wno-implicit OPTION PARSE FALSE
'documentation 'https://basic-converter.proboards.com/post/1988
DECLARE dialog TYPE GtkDialog* gtk_init(0, 0)
dialog = gtk_message_dialog_new(0, 0, 0, GTK_BUTTONS_YES_NO,"Greetings from BaCon!")
RES = gtk_dialog_run(dialog)
SELECT RES CASE GTK_RESPONSE_NONE PRINT "NONE" CASE GTK_RESPONSE_REJECT PRINT "REJECT" CASE GTK_RESPONSE_ACCEPT PRINT "ACCEPT" CASE GTK_RESPONSE_DELETE_EVENT PRINT "DELETE" CASE GTK_RESPONSE_OK PRINT "OK" CASE GTK_RESPONSE_CANCEL PRINT "CANCEL" CASE GTK_RESPONSE_CLOSE PRINT "CLOSE" CASE GTK_RESPONSE_YES PRINT "YES" CASE GTK_RESPONSE_NO PRINT "NO" CASE GTK_RESPONSE_APPLY PRINT "APPLY" CASE GTK_RESPONSE_HELP PRINT "HELP" ENDSELECT
|
|
|
Post by Pjot on May 21, 2020 7:51:20 GMT 1
Thanks Joe, Your samples indeed really boils down to the essence of GTK. There are a lot of (convenience-)functions in GTK which make life easy for us! ButI wonder how we could do this in FLTK I studied it for the GUI-stuff but I wasn't able to find generic functions similar to 'XtCreateManagedWidget' (libXt) or 'gtk_widget_new' (GTK). Neither settings properties in a generic way like 'XtVaSetValues' or 'g_object_set' seem to be possible... Best regards Peter
|
|
|
Post by bigbass on May 21, 2020 19:54:59 GMT 1
Hello Peter for two reasons I think it would be better to start clean for fltk with a new GUI design "if possible" I like using fltk so this is just my personal 2 cents worth on the idea 1.) fltk uses real OO programming in c++ and we don't need all the ugly hacks (what I mean here is Xlib and gtk are written in OO code style but have many hacks to make it all work like c++ but using c ) 2.) fltk goes right to Xlib directly already (not using the Xt approach) and would mirror Xlib exactly only in c++ functions and classes that are already written for us and fltk has already a x.H ready made to see what happens and in Fl_x.cxx the port from Xlib also we already have many working ported examples so its not a theory it already works it all comes down to you have to code it the way that feels most comfortable to you one tester is already on the list Joe
|
|
|
Post by vovchik on May 21, 2020 20:09:11 GMT 1
Dear Joe and Peter, Make that two. With kind regards, vovchik
|
|
|
Post by rikky on May 21, 2020 22:39:45 GMT 1
Make that two. :) Well, I would love to make that three, but I'm simply lacking the skills, to make valuable contributions, other then I don't like the color. But, All the examples work so far on my system, If that's what you want to know, and I like the GTK (colors etc) most :°) Rik.
|
|
|
Post by alexfish on May 22, 2020 2:12:59 GMT 1
Hi All My 2 p . re FLTK from what I can remember AKA FLTK uses the aka Xforms:: not the 'html one' that can be programmed in c & c++ Correct me if I be wrong :: HEREJust had to check:: my version is 1.2.3 BR Alex Picky Attachments:
|
|
|
Post by bigbass on May 22, 2020 17:34:42 GMT 1
Hello Alex Thanks for postings the docs for xforms they are very well written and explains very clearly how the code works since this is the base idea of fltk many of that still applies now ( wish I read that before jumping onto fltk first) it would have cleared up the why some things are the way they are ( like reading a book that starts on chapter two without ever seeing chapter one ) just a foot note now chapter two www.fltk.org/doc-1.3/intro.htmlagain Alex I want to stress the documentation you posted for xforms is excellent and anyone that wants a clear idea how the code works should read it since a large part of fltk was based of this I am reading it and enjoying I will probably dig into this for a few pleasant hours thanks Joe
|
|
|
Post by alexfish on May 22, 2020 18:54:52 GMT 1
Hi Joy
Enjoy
but looking at Peter's latest project :: GUI by proxy and the method's
I would have thought Xforms fit that Criterion
IE Form and an object by description + Loop
Xform Demo
int main( int argc, char * argv[ ] ) { FL_FORM *form; FL_OBJECT *yes;
fl_initialize( &argc, argv, "FormDemo", 0, 0 );
form = fl_bgn_form( FL_UP_BOX, 320, 120 );
fl_add_box( FL_NO_BOX, 0, 10, 320, 40, "Do you want to quit?" ); yes = fl_add_button( FL_NORMAL_BUTTON, 40, 70, 80, 30," Yes" ); fl_add_button( FL_NORMAL_BUTTON, 200, 70, 80, 30, "No" );
fl_end_form( );
fl_show_form( form, FL_PLACE_MOUSE, FL_TRANSIENT, "Question" );
while ( 1 ) { if ( fl_do_forms( ) == yes ) { fprintf( stderr, "\"Yes\" has been pushed\n" ); break; } else fprintf( stderr, "No is pushed\n" ); }
fl_finish( ); return 0; }
BR Alex
|
|
|
Post by bigbass on May 23, 2020 7:00:39 GMT 1
Hello Peter porting that idea to fltk but in c++ fltk attributes/properties are real OO style
porting these lines from gtk to fltk
WIN = g_object_new(GTK_TYPE_WINDOW, "title", "BaCon demo", "border-width", 10, "default-height", 100, "default-width", 400, NULL)
or
WIN = gtk_widget_new(GTK_TYPE_WINDOW, "title", " BaCon demo", "border-width", 10, "default-height", 100, "default-width", 400, NULL)
in fltk looks like but adding more attributes /properties
{ WIN = new Fl_Double_Window(400, 100, "BaCon demo"); // we set properties differently in fltk WIN->box(FL_FLAT_BOX); WIN->color(FL_BACKGROUND_COLOR); WIN->selection_color(FL_BACKGROUND_COLOR); WIN->labeltype(FL_NO_LABEL); WIN->labelfont(0); WIN->labelsize(14); WIN->labelcolor(FL_FOREGROUND_COLOR); WIN->align(Fl_Align(FL_ALIGN_TOP)); WIN->when(FL_WHEN_RELEASE); WIN->end(); } WIN->show();
I'm sure you will find a better way
Joe
|
|
|
Post by Pjot on May 23, 2020 8:20:25 GMT 1
@ alex: thanks, the good old XForms library is an old flame I have used it for GTK-server as well and I know the API pretty well. There are some possibilities there. @ joe: indeed, that seems the problem. So embedding the FLTK API into generic calls seem to be impossible... Regards Peter
|
|
|
Post by bigbass on May 26, 2020 17:26:45 GMT 1
Hello Peter @ joe: indeed, that seems the problem. So embedding the FLTK API into generic calls seem to be impossible... difficult maybe, yes, because we leave the c compiler behind and start using the C++ compiler using my demo above but using "real code" that compiles now to explain better I'm not giving up so easily on fltk because I think you can still make it happen with a new GUI in C++ and memory management is better in C++ with the new command if we can't its not a problem I have adjusted to using the c++ syntax and the docs to glue it together 100% fltk style but compiles in bacon don't stop here there is a second part below! win.bac PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H>
PRAGMA OPTIONS -Wno-deprecated PRAGMA LDFLAGS -lfltk PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
DECLARE WIN TYPE Fl_Double_Window*
WIN = new Fl_Double_Window(400, 100, "BaCon demo") ' we set properties differently in fltk WIN->box(FL_FLAT_BOX) WIN->color(FL_BACKGROUND_COLOR) WIN->selection_color(FL_BACKGROUND_COLOR) WIN->labeltype(FL_NO_LABEL) WIN->labelfont(0) WIN->labelsize(14) WIN->labelcolor(FL_FOREGROUND_COLOR) WIN->align(Fl_Align(FL_ALIGN_TOP)) WIN->when(FL_WHEN_RELEASE) WIN->end() WIN->show() Fl::run()
now the BaCon looking syntax modeled after HUG that I call stage 3 of porting code (vovchik calls it fltk-hug) and handles it as a include file but I think it could be done the same way you made the original hug but thinking that now you are using the C++ compiler instead which may be easier but still not easy by any means but doable win2.bac PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Box.H>
PRAGMA LDFLAGS -lfltk PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wno-deprecated OPTION PARSE FALSE
'=============================================
DEF FN WINDOW(t, x, y) = new Fl_Double_Window(x, y, t) DECLARE WIN TYPE Fl_Double_Window*
DEF FN BOX(t, x, y) = new Fl_Box(20, 20, x, y, t) DEF FN SETPROPERTY(arg1,arg2,arg3) = arg1->arg2(arg3) DEF FN GET(arg1,arg2) = arg1->arg2() DEF FN SET(w,x) = w->value(x)
DEF FN ALIGN(w,x) = w->align(x) DEF FN SETEVENT(w,x) = w->when(x) DEF FN SHOW(w) = w->show() ALIAS Fl::run TO DISPLAY '=============================================
WIN = WINDOW("BaCon demo", 400,100) box = BOX("SOMETEXT", 300, 80) '--- we can force set set properties differently for BaCon in C++ SETPROPERTY(WIN, box, FL_DOWN_BOX) SETPROPERTY(WIN, color, FL_RED) SETPROPERTY(WIN, selection_color, FL_BACKGROUND_COLOR) SETPROPERTY(WIN, labeltype, FL_NO_LABEL) SETPROPERTY(WIN, labelfont, 0) SETPROPERTY(WIN, labelsize, 14) SETPROPERTY(WIN, labelcolor, FL_BLUE) ALIGN(WIN, FL_ALIGN_TOP) SETEVENT(WIN,FL_WHEN_RELEASE) WIN->end() SHOW(WIN) DISPLAY
|
|