|
Post by bigbass on Apr 29, 2020 18:34:53 GMT 1
Hello we now have motif built in to BaCon While Peter is working hard to make it happen as a GUI toolkit and showing the complete app demos there is a lot of great progress to follow First ,It inspired me to understand and see how motif widgets work in BaCon porting them from their native c code syntax if I don't do this step first I would be lost I will focus on documenting motif stand alone widgets so we can test just the widgets no full apps here in this thread I hope by seeing how the widgets work alone all the pieces will come together quickly so we can start doing something with motif P.S a tech note the call backs needed an extra (void*) cast for them to work ... and they work Joe '--- file-chooser.bac '--- stand alone widgets '--- so you can see how they work and test them '--- in a simple way then combine what you need to make your GUI PRAGMA INCLUDE <Xm/FileSB.h>
PRAGMA LDFLAGS Xm PRAGMA LDFLAGS Xt PRAGMA LDFLAGS X11 OPTION PARSE FALSE DECLARE toplevel TYPE Widget DECLARE dialog TYPE Widget DECLARE app TYPE XtAppContext DECLARE label TYPE XmString
DECLARE args[2] TYPE Arg
'========================== SUB leave() '========================== END END SUB
toplevel = XtVaAppInitialize (&app, "Demos", \ NULL, 0, &argc, argv, NULL, NULL)
dialog = XmCreateFileSelectionDialog (toplevel, "BaCon Motif file chooser", NULL, 0) XtAddCallback (dialog, XmNcancelCallback,(void*) leave, NULL) XtAddCallback (dialog, XmNokCallback, (void*)echo_file, NULL) XtManageChild (dialog)
XtAppMainLoop (app)
'===================================================== SUB echo_file(widget, client_data, call_data) '===================================================== DECLARE filename TYPE char* LOCAL cbs TYPE XmFileSelectionBoxCallbackStruct* cbs = call_data
IF (XmStringGetLtoR (cbs->value, XmSTRING_DEFAULT_CHARSET, &filename)) != 1 THEN PRINT "ERROR1" END IF IF *filename == 1 THEN PRINT "No file selected." XtFree( filename) PRINT "ERROR2" END IF
PRINT filename FORMAT "%s\n" XtFree (filename)
END SUB
terminal output /home/pi/Desktop/STAND_ALONE/test1.txt
|
|
|
Post by Pjot on May 2, 2020 12:03:24 GMT 1
Thanks Joe, The Motif widget set is already very versatile and well-developed. Some interesting information can be found here. While reading through Motif documents, I found that Motif can use a separate GUI design language called "UIL" ( User Interface Language). It is a descriptive language which can describe the interface separately from the main program. That would save code even more. This UIL not only can define Motif widgets, but also can handle foreign widgets like Xaw/Xaw3d. I will study it a bit more and see if it also can be made available through BaCon. Best regards Peter
|
|
|
Post by bigbass on May 3, 2020 5:56:22 GMT 1
Hello Peter
A big thanks for those links I have a lot of homework to do just reading through the docs and will port some of those along the way a lot of the c code demos could be reduced and simplified for bacon use
Joe
|
|
|
Post by Pjot on May 3, 2020 10:29:59 GMT 1
Hi Joe, I was able to implement the MRM/UIL mechanics, it wasn't too difficult after all. The UIL code below (based on the the demonstration UIL code from here) now works with the below program. If you want to test it, please get the latest BaCon from fossil. First, you have to compile the "uil" file into a "uid" file: # uil -o hello_world.uid hello_world.uil
This is the UIL code, save it as "hello_world.uil". Note that the top widget must be called "main": /* hello_world.uil -- Illustrate basic UIL programming concepts */
module hello_world !objects = { XmPushButton = gadget; }
value form_margin : 3.0; ! Value for all-around form margins.
object main : XmForm { controls { XmLabel world; XmPushButton hello; }; arguments { XmNshadowThickness = 0; XmNresizePolicy = XmRESIZE_GROW; }; };
value hello_string : "Hello, World!"; hello_font : font ('-adobe-helvetica-medium-r-*-*-*-140-*'); world_icon : icon ( ' ****** ', ' ** *** ** ', ' *** ** * * ', ' **** *** * ', ' * ********* ** ', '* ****** *** ***', '* ********* **', '* ********* **', '* ******** **', '* **** * *', '* ** * *', ' * ** * ', ' * ***** * ', ' * ******* * ', ' ********** ', ' ****** ' );
procedure quit (string);
object world : XmLabel { arguments { XmNlabelType = XmPIXMAP; XmNlabelPixmap = world_icon;
! Form constraint resources XmNleftAttachment = XmATTACH_FORM; XmNtopAttachment = XmATTACH_FORM; XmNbottomAttachment = XmATTACH_FORM; }; } ;
object hello : XmPushButton { arguments { XmNlabelString = hello_string; XmNfontList = hello_font; XmNmarginHeight = 2; XmNmarginWidth = 3;
! Form constraint resources XmNleftAttachment = XmATTACH_WIDGET; XmNleftWidget = world; XmNtopAttachment = XmATTACH_FORM; XmNbottomAttachment = XmATTACH_FORM; XmNrightAttachment = XmATTACH_FORM; }; callbacks { XmNactivateCallback = procedure quit("my_button"); }; };
end module;
Then compile the BaCon program as usual. Note that we have to set the UIDPATH environment variable to make sure that MRM can find the created "uid" file. The GUIDEFINE directive now also allows 'uid' to specify the required "uid" file. The 'callback' in GUIDEFINE points to the procedure definition in de UIL file. OPTION GUI TRUE PRAGMA GUI uil
' Where to look for the uid file SETENVIRON "UIDPATH", DIRNAME$(ME$) & "/%U.uid"
id = GUIDEFINE("{ type=window name=window callback=quit uid=hello_world XmNtitle=\"Demo\" XmNwidth=200 XmNheight=50 }")
WHILE TRUE event$ = GUIEVENT$(id)
SELECT event$ CASE "my_button" PRINT "Button clicked!" ENDSELECT WEND
Best regards Peter Attachments:
|
|
|
Post by vovchik on May 3, 2020 10:53:14 GMT 1
Dear Peter, Everything on Mint compiled fine at first, but no widgets are showing. Any idea why? I have the x fonts installed. I get this at runtime in the terminal: X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 19 (X_DeleteProperty) Resource id in failed request: 0x0 Serial number of failed request: 131 Current serial number in output stream: 143 UPDATE: And now I get this: Converting 'hello_uil.bac'... done, 17 lines were processed in 0.004 seconds. Compiling 'hello_uil.bac'... cc -c hello_uil.bac.c Makefile.bacon:6: recipe for target 'hello_uil.bac.o' failed
./hello_uil.bac.gui.h:31:19: error: ‘uid’ undeclared (first use in this function); did you mean ‘id’?
In file included from /usr/include/Xm/Xm.h:59:0, from /usr/include/Xm/XmAll.h:27, from hello_uil.bac:2, from hello_uil.bac.c:2: ./hello_uil.bac.gui.h: In function ‘__b2c__guiDefine’: ./hello_uil.bac.gui.h:31:19: error: ‘uid’ undeclared (first use in this function); did you mean ‘id’? XtSetArg(args[n], uid,hello_world); n++; ^ ./hello_uil.bac.gui.h:31:19: note: each undeclared identifier is reported only once for each function it appears in ./hello_uil.bac.gui.h:31:23: error: ‘hello_world’ undeclared (first use in this function) XtSetArg(args[n], uid,hello_world); n++; ^ make: *** [hello_uil.bac.o] Error 1 With kind regards, vovchik Attachments:
|
|
|
Post by Pjot on May 3, 2020 12:20:10 GMT 1
Thanks vovchik,
Believe it or not, but it already looks good!
However, as you were really fast with testing the UIL mechanics, you may have missed the update in fossil right after I posted the code above.
From the error I can see BaCon doesn't recognize 'uid' and this is in that last update.
If you have time, please fetch the update and try again - looking at the error and screenshot I am pretty sure it will work for you.
Best regards Peter
|
|
|
Post by vovchik on May 3, 2020 13:57:14 GMT 1
Dear Peter, I think I may have jumped the gun last time. Now I get only the X windows error message (as above), using the latest beta. I got the window, without widgets, with the preceding beta. Weird, but almost there I think... With kind regards, vovchik
|
|
|
Post by bigbass on May 3, 2020 17:16:53 GMT 1
Hello Peter and vovchik It will work with the latest fossil and the callback too P.S I see you fixed several errors in the source code that the docs point to the original c code had errors in both demos ok I see the object main is what you were talking about Joe
|
|
|
Post by Pjot on May 3, 2020 20:34:06 GMT 1
Hi vovchik,
I debugged the code on a fresh Linux Mint and I see the same X error - weird!
After a while I discovered that the resulting binary demonstrated a wrong order of linked libraries, though the Makefile has them in correct order.
As a workaround, you can force the program to work from the command line as follows:
# export LD_PRELOAD="libMrm.so libXm.so libXt.so libX11.so" # ./the_program
This worked for me on Mint 19.3. As you can see, the order of libraries is exactly the same as the order used by BaCon (omitting libXmu here but this didnt make a difference anyway).
HTH Peter
|
|
|
Post by vovchik on May 3, 2020 21:50:01 GMT 1
Dear Peter, Thanks for investigating and providing a fix. I do not understand why that is happening either. Very weird. In any case, it is working nicely now, if launched as you suggest. With kind regards, vovchik Attachments:
|
|
|
Post by bigbass on May 4, 2020 2:12:46 GMT 1
Hello Peter and vovchik porting was a lot of work and a lot more code but at least I know it could be done stand alone for studying what is happening at every step I used the same hello_world.uil except object hello_main : XmForm { works with object hello_main since I did all testing first with c hello-uil.tar.gz (852 B) Joe there is one pesky usec but I need some coffee first '--- ported from c and fixed errors to BaCon by bigbass PRAGMA INCLUDE <Xm/Xm.h> PRAGMA INCLUDE <Mrm/MrmPublic.h>
PRAGMA INCLUDE <stdlib.h> PRAGMA LDFLAGS Mrm PRAGMA LDFLAGS Xm PRAGMA LDFLAGS Xt PRAGMA LDFLAGS X11 OPTION PARSE FALSE
DECLARE toplevel ,hello_main TYPE Widget DECLARE app_context TYPE XtAppContext DECLARE status TYPE Cardinal DECLARE uid_file_list[] = { "hello_world" } TYPE static String DECLARE hierarchy TYPE MrmHierarchy DECLARE class_code TYPE MrmType
USEC void leave(); MrmRegisterArg callback_list[] = {{ "quit", (XtPointer) leave },}; ENDUSEC
'================================================ SUB THE_ERROR (char* message) '================================================
EPRINT "hello_world: " , message FORMAT "%s%s\n" END
END SUB
'================================================ SUB leave(w, client_data, call_data) '================================================ PRINT client_data FORMAT "%s\n" END SUB
MrmInitialize() '--- args in XtVaAppInitialize() '--- 1 application context '--- 2 application class name '--- 3 command line options '--- 4 argc and argv '--- 5 fallback resources '--- 6 arg list toplevel = XtVaAppInitialize(&app_context,"Demos", NULL, 0, &argc, argv, NULL, NULL)
'--- args in MrmOpenHierarchy() '--- num files '--- file list '--- OS data '--- hierarchy status = MrmOpenHierarchy ( XtNumber (uid_file_list), uid_file_list, NULL, &hierarchy)
IF status != MrmSUCCESS THEN PRINT "Unable to open hello_world.uid file." END IF
status = MrmRegisterNames (callback_list, XtNumber (callback_list))
IF status != MrmSUCCESS THEN PRINT "Unable to register callback functions with Mrm." END IF '--- args in MrmFetchWidget() '--- hierarchy to search '--- object name '--- parent '--- widget created '--- widget's class code status = MrmFetchWidget (hierarchy, "hello_main", toplevel, &hello_main, &class_code)
IF status != MrmSUCCESS THEN PRINT "Unable to create interface from UID file" END IF MrmCloseHierarchy (hierarchy) XtManageChild (hello_main) XtRealizeWidget (toplevel) XtAppMainLoop (app_context)
|
|
|
Post by Pjot on May 4, 2020 17:08:32 GMT 1
Thanks Joe, That looks all right to me. Your commenting also is very helpful. In the meantime, I found the root-cause for the Linux Mint compiling problems which vovchik is facing. It turns out that the Ubuntu repos use a GCC version where a presumed "optimization" has been enabled permanently. I mean the '--as-needed' compile flag. The GNU linker '--as-needed' flag forces the linker to verify if certain functions can be resolved through other libraries, or that they should be resolved by libraries provided on the command line. As mentioned in the LD man page: So, the linked libraries provided by the command line only are added to the list of "NEEDED" when the required functions cannot be resolved through other ways. This causes the compiled binary in Mint (and other Ubuntu-like distributions) to put the Motif library below the Xt library. Because the required Motif stuff can be resolved through the MRM library which is on top of the list. But then the most important remark in the same man page: --no-as-needed restores the default behaviour.
Thing is, that Motif requires to be mentioned in the list of dependencies before libXt. However, when '--as-needed' is enabled, the linker thinks that Motif calls can be resolved through libMrm so it puts the Motif library somewhere down below the dependency list. Why has Ubuntu chosen to use the '--as-needed' flag as a default for the linker? It is not the default. So it is a good question and other people are wondering the same thing. Other software packages run into problems also. In any case, we can solve the issue by using the '--no-as-needed' flag on the command line. So if you are using an Ubuntu derivative, then the following will compile and link the program correctly: # bacon -l -Wl,--no-as-needed myprogram.bac
It would be nice if this can be set in our BaCon program. I had to adjust the linker parts and updated BaCon further (code in fossil). With the new version we can add the following line on top of the program: PRAGMA LDFLAGS -Wl,--no-as-needed
This will make sure that the binary has a correct dependency list so it should work. BR Peter
|
|
|
Post by bigbass on May 4, 2020 17:35:35 GMT 1
thanks for the info about the order of the libs I ran into problems myself with what I thought to be working code then had to juggle around the lib list to get things to compile and values in the headers to be seen I just thought it to be some quirk and moved on when it finally worked and now I see why with your explanation nice detective work ! why don't they leave things alone when they work this will be golden when I run into that again PRAGMA LDFLAGS -Wl,--no-as-needed
hello-uil.tar.gz (852 B) fixed :there was a problem before because bacon has a keyword quit and the callback was called quit I got some color going in the small earth too and see what this is all about without having to recompile the source code only edit the uil then recompile that and run again the source *.bac and *uil are included
|
|
|
Post by bigbass on May 5, 2020 5:39:41 GMT 1
Hello Peter in your last change at fossil
my compile order gets flipped
'---reverse priority list now least to most important '---will compile -lMrm -lXm -lXt -lX11 -lm PRAGMA LDFLAGS X11 PRAGMA LDFLAGS Xt PRAGMA LDFLAGS Xm PRAGMA LDFLAGS Mrm OPTION PARSE FALSE
I can fix my code but all older code will fail now
what I posted works but logically I start with the most important
*removed code now works with latest fossil
I will rebuild fossil again may be an update I missed
I am using this
using geany while testing source code I compile in c like this and works correctly gcc -Wall -c "%f" -lMrm -lXm -lXt -lXaw -lX11 gcc -Wall -o "%e" "%f" -lMrm -lXm -lXt -lXaw -lX11 Joe
maybe some type of warning or a gcc check first I know fossil is beta code its not a problem to test ideas and make it work for everyone
and I will provide any feedback you need from a RPI3 user --------------- gcc -dumpspecs | grep 'as-needed' --------------- gives a very large output but this is the needed line
%{static|static-libgcc|static-pie:-lgcc -lgcc_eh}%{!static:%{!static-libgcc:%{!static-pie:%{!shared-libgcc:-lgcc --push-state --as-needed -lgcc_s --pop-state}%{shared-libgcc:-lgcc_s%{!shared: -lgcc}}}}}
|
|
|
Post by Pjot on May 5, 2020 8:09:05 GMT 1
Hi Joe,
Thanks for testing. I have adapted the library flags so we need an 'insert flag' at the end in case something has to be added in front.
For example:
PRAGMA LDFLAGS -Wl,--no-as-needed TRUE
The TRUE means 'insert' before before all the other stuff.
Your code now should remain compatible with this new build, hope it works for you.
By the way, instead of writing:
PRAGMA LDFLAGS Mrm PRAGMA LDFLAGS Xm PRAGMA LDFLAGS Xt PRAGMA LDFLAGS X11
...you can also write the following, saving some space in your code:
PRAGMA LDFLAGS Mrm Xm Xt X11
BR Peter
|
|