how to write a GUI for gforth

178 views Asked by At

I would like to learn GUI for linux gforth but documentation about that are , _from my point of view _ ,awful obsolete or both :) to be honest.

I already searched & tried many from all of https://www.reddit.com/r/Forth/comments/ypo3kd/what_is_the_best_way_to_make_lightwheight_guis_in/ but this didn't help.

I tried FFL/GTK solution https://github.com/irdvo/ffl/issues/10 for linux gforth GUI but FFL is no more maintained by his author he mentioned on his GitHub . So examples are a mess buggy-no more compatible and so on so I cannot learn from there.

I also tried to read from Minos tutorial provided by gforth package but this is not a tutorial at all just examples that do not really work in facts ... cannot exit from any of them for example Documentation about it is so empty I just cannot use it https://gforth.org/manual/MINOS2.html

PS: currently I use a TK use but that calls shell that itself calls TK for more or less each interaction this cannot be a solution for bigger applications that the example given as picture (even this one is working fine)

https://drive.google.com/file/d/1mA7MhjGiIiWimQ7rheeNQgockJ8vK_Dw/view?usp=sharing example pic is here

it is currently

\ needs to have tcl/tk wish installed
0 value tk-in
0 value tk-out
variable #clicks
0 #clicks !
: wish{ \ send command to wish
    tk-in to outfile-id 
;
: add-one 
    1 #clicks +! 
;   \ get an action as example here counting clicks 
: cleaning
    tk-in close-file tk-out close-file s" rm /dev/shm/tk-in /dev/shm/tk-out " system \ clear temprary files for a clean code
    cr 0 (bye)
;
: }wish \ finish command to wish
    tk-in flush-file throw stdout to outfile-id 
; 
: update-wish wish{ .\" .label configure -text \"clicks: " #clicks @ . .\" \"" cr }wish ;   \ redraw window 
: counting
    begin
        tk-out key-file
        dup 'q' = if 
            wish{ ." exit" }wish
            cleaning
        then    \ quit wish 
        dup '+' = if 
            add-one update-wish 
        then    \ add one if '+' received
        #clicks @ 5 > if
            wish{ ." exit" }wish    \ exit on 5 clicks 
            cleaning
        then
    4 = until 
;           
: initiating
    s" mkfifo /dev/shm/tk-in /dev/shm/tk-out" system    \ create temporary files here new version mignt use a memory block as file
    s" wish </dev/shm/tk-in >/dev/shm/tk-out &" system  \ manage how they are used input/output to the external interpreter
    s" /dev/shm/tk-in" w/o open-file throw to tk-in \ only input has to be writable
    s" /dev/shm/tk-out" r/o open-file throw to tk-out   \ so output is read only to get performances (how cares on modern PCs)
    wish{
        .\" wm protocol . WM_DELETE_WINDOW { puts 'q' } " cr    
        .\" wm title . \"forth count\"" cr
        .\" wm geometry . \"200x100+100+100\"" cr
        .\" label  .label -text \"There have been no clicks yet\" " cr
        .\" button .click -text \"click me\" -command \" puts '+' \" " cr 
        .\" button .exit -text \"EXIT\" -command \" puts 'q' \" " cr
        ." pack .label .click .exit" cr 
    }wish                   \ TK window management
;
: checkrunispossible 
    s" which wish 1> /dev/null" system  \ system bash exexute
    $? 0 > if               \ if TK wish tool is not installed quit
        cr 27 emit .\" [31;1m TCL-TK wish command must be installed." 
        27 emit .\" [0m" cr 0 (bye)
    then
;
: main
    checkrunispossible  initiating  counting    cleaning
;
main 

this is dirty solution and will be incredibly low performances solution if I write a bigger application because of the system calls & TCL/TK itself too..

It really seem to be a lake a documentations here I know forth is no more used as GUI application since 80's but it was so why not make my hobbyist scripts in gforth having GUI.

I m not currently interested in using another forth interpreter.

Does any have a real tutorial from a very very basic "application" like a few buttons one that is really documented and not just be given as-is to provide ? maybe with gtk or minos ?

1

There are 1 answers

2
ruvim On

Have a look at a more general question: Writing a GUI for a Forth application.

A promising way is to write (or generate) GUI in HTML and control it from Forth.

Use NW.js/HTML for GUI and communicate it via WebSockets from Gforth, or use a web-server in Gforth (see an outdated example, and another one) and control it via WebSockets too or plain HTTP, or use Gforth in SCGI.

A more hard way is to use Qt library. Try to create bindings using SWIG in Gforth.

If you want to dive deeper, you might find the library QtE5 useful, which is a Qt wrapper for easier access from other languages (such as Forth and D).