|
Post by Pjot on Apr 25, 2020 14:22:05 GMT 1
waits for a second click. Meaning that I have to click the Submit button twice to see the reaction This is fixed in the above code now. The original properties from Xaw have these names, I am not sure if we can get rid of them in all circumstances... but if it works for you, good! BR Peter
|
|
|
Post by Pjot on Apr 25, 2020 15:35:37 GMT 1
Hi rikky, The Motif widget set is a lot more complicated. I had to apply a few more adjustments to BaCon -again- but now we can create dialogs in Motif as well. In Motif, one widget can accepts multiple callbacks. However, the BaCon program must be able to see which signal occurred. Therefore, we can now specify a self-defined string for each callback. Just add a small text, comma-separated, after the callback signal. This text will then be returned in the event loop. The below code shows how it works in Motif (get the latest BaCon as well to run it successfully). Yes, even less code BR Peter OPTION GUI TRUE PRAGMA GUI motif
prompt = GUIDEFINE( " \ { type=window name=window XmNtitle=\"Information\" } \ { type=xmSelectionBoxWidgetClass name=dialog parent=window callback=XmNcancelCallback,cancel callback=XmNokCallback,ok XmNdialogType=XmDIALOG_PROMPT } \ ")
CALL GUISET(prompt, "dialog", XmNselectionLabelString, XmStringCreateLocalized("Enter term:"))
CALL GUISET(prompt, "Help", XmNsensitive, False)
DECLARE data$
WHILE TRUE event$ = GUIEVENT$(prompt) SELECT event$ CASE "ok" CALL GUIGET(prompt, "Text", XtNvalue, &data$) BREAK CASE "cancel" BREAK ENDSELECT WEND
PRINT "Broken the GUIEVENT loop to hide the dialog widget."
PRINT "Value is: ", data$
PRINT "Continue program here..."
Attachments:
|
|
|
Post by bigbass on Apr 25, 2020 19:20:07 GMT 1
working correctly I see that you are trying to pull the callbacks out of the low level code and into the bacon side of the memory what you did will make callbacks much easier (for me motif is actually better than athena for callbacks in athena I needed void * and int * for the callbacks to work when working with arrays) this may interest you having a full app and source code sourceforge.net/projects/nedit/ OPTION GUI TRUE PRAGMA GUI motif
'---------------------------------------- SUB name_print '----------------------------------------
PRINT "in the callback" PRINT "input is: ", data$ PRINT "event is: ", event$ END SUB
prompt = GUIDEFINE( " \ { type=window name=window XmNtitle=\"Information\" } \ { type=xmSelectionBoxWidgetClass name=dialog parent=window callback=XmNcancelCallback,cancel callback=XmNokCallback,ok XmNdialogType=XmDIALOG_PROMPT } \ ")
CALL GUISET(prompt, "dialog", XmNselectionLabelString, XmStringCreateLocalized("Enter term:"))
CALL GUISET(prompt, "Help", XmNsensitive, False)
DECLARE data$
WHILE TRUE event$ = GUIEVENT$(prompt) SELECT event$ CASE "ok" CALL GUIGET(prompt, "Text", XtNvalue, &data$) CALL name_print BREAK CASE "cancel" BREAK ENDSELECT WEND
PRINT "Broken the GUIEVENT loop to hide the dialog widget."
PRINT "Continue program here..."
|
|
|
Post by Pjot on May 2, 2020 11:54:00 GMT 1
All, Now a small real-world application which I actually am using myself to tune in to internet radio channels. It basically is a frontend to "mpg123" so make sure to have this binary available on your system. As I am very fond of classical music, I already added some channels in the configfile. Please create this file in your homedir as ".radio.cfg". Of course, you can add and set your own channels as well The program is a bit larger so it is attached as a file. Regards Peter Attachments:
.radio.cfg (1.41 KB)
radio-motif.bac (12.32 KB)
|
|
|
Post by vovchik on May 2, 2020 17:34:09 GMT 1
Dear Peter, MaNY thanks. Works perfectly on Mint and Pi4. And you supplied an excellent choice of stations, at least for me. With kind regards, vovchik Attachments:
|
|
|
Post by bigbass on May 3, 2020 5:37:46 GMT 1
Hello Peter Thanks working on the RPI3 also
seems we will be able to do a lot with this motif GUI and keep it light and practical
this was a practical demo of a simple cli utility with a GUI linux is full of those cli utilities that need a nice GUI
Joe
|
|
|
Post by Pjot on May 6, 2020 20:53:19 GMT 1
All, Some improvements to my internet radio: - Using asynchronous lookup of song titles using the FORK() function
- Got rid of the buttons, all is in a right-mouse-button popup now
As a side note, the new BaCon beta now also allows a callback to the main window.
Enjoy! Peter Attachments:radio-motif.bac (12.46 KB)
|
|
|
Post by vovchik on May 6, 2020 21:35:32 GMT 1
Dear Peter,
Thanks. Works perfectly on Mint and on the Pi4.
With kind regards, vovchik
|
|
|
Post by bigbass on May 7, 2020 2:03:53 GMT 1
A clean compile and runs well I like the idea of right click it just feels smoother and easier to use Thanks it's very useful Joe P.S there's an entry called KISS classical my first thoughts were Paul Stanley Gene Simmons
|
|
|
Post by Pjot on May 7, 2020 19:30:11 GMT 1
Thanks guys! Made some more improvements leading to version 1.3, but this will be my last change on this program for a while, as I am going to look into other things now - Start playing the station as soon you select it
- Enabled tear-off menu functionality (see screenshot)
- Some cosmetic improvements (this needs the latest BaCon beta to let X render the icon properly)
@ Joe: in the screenshot you can see that KISS has classical music too Best regards Peter Attachments:
radio-motif.bac (11.98 KB)
|
|
|
Post by alexfish on May 7, 2020 21:16:10 GMT 1
KISS has classical music too
there must be something wrong with my radio
BR Alex
|
|
|
Post by Pjot on May 13, 2020 19:49:52 GMT 1
All, The newly added GUI functions come down to the following ideas: - GUIDEFINE to create a GUI where all widgets can be defined in terms of their properties
- GUIEVENT mainloop which can return the name of a widget which caused the event
- GUIGET/GUISET to obtain or set certain properties during runtime
- GUIWIDGET to fetch the actual widgetID based on the name
The good old libXt, which is part of X-windows, and which is the foundation of Xaw and Motif, has an API which allows to implement this in a small and straightforward manner. So we can ask ourselves: can we not have this very same design philosophy with a toolkit like GTK as well? If our GUI functions can remain the same, why not also allow some other backend?
After studying GTK a bit, I discovered that there are some functions which can help us out (also thanks to my GTK-server-project ). A real problem was the GTK widget naming. We can set a name on a widget, but it seems GTK cannot retrieve the GtkWidget address based on that name. Another issue is the callback mechanics. This appeared to be quite different compared to libXt. Lastly, widgets in GTK do not carry their position as a property. But anyway, I could find solutions for these problems and have added GTK now as well. Honestly, I am not sure how far we can get in creating a nice GTK GUI using this approach. The below program is a working sample. As always, we need to specify a type for each widget. But all types in GTK start with "GTK_TYPE_" so we can leave this out, this will save some space. For the GTK guru's around here, please note this is beta stuff (all is in fossil). Feel free to test and come back with remarks. BR Peter OPTION GUI TRUE
' We can specify gtk3 too PRAGMA GUI gtk2
' Needed if we run this GTK2 sample in GTK3 'PRAGMA OPTIONS -Wno-deprecated-declarations
' Here, we can say type=WINDOW, or type=LABEL, etc. id = GUIDEFINE(" \ { type=GTK_TYPE_WINDOW name=window callback=delete-event title=\"BaCon\" width-request=300 } \ { type=GTK_TYPE_VBOX name=box parent=window } \ { type=GTK_TYPE_LABEL name=label parent=box height-request=50 use-markup=1 label=\"<big><i>Hello world</i></big>\" } \ { type=GTK_TYPE_HBUTTON_BOX name=bbox parent=box layout-style=GTK_BUTTONBOX_END } \ { type=GTK_TYPE_BUTTON name=button parent=bbox callback=clicked label=\"Exit\" }")
' To demonstrate that GUISET works too. CALL GUISET(id, "window", "window-position", GTK_WIN_POS_CENTER, "resizable", FALSE)
WHILE TRUE event$ = GUIEVENT$(id)
SELECT event$ CASE "window" END ENDSELECT WEND
Attachments:
|
|
|
Post by vovchik on May 13, 2020 20:34:06 GMT 1
Dear Peter, I grabbed the latest fossil and compiled. Great work (works on Pi4 and Mint 19.2). I like it. Thanks! With kind regards, vovchik Attachments:
|
|
|
Post by vovchik on May 14, 2020 13:19:03 GMT 1
Dear all, Just experimenting here. It works nicely! With kind regards, vovchik Attachments:
gtktest01.bac.tar.gz (1.65 KB)
|
|
|
Post by Pjot on May 14, 2020 16:52:35 GMT 1
Thanks vovchik, Your code is very intersting, I already wondered how we could add 2 buttons and outline each of them to the edges. Apparently, we need 'layout-style=GTK_BUTTONBOX_DEFAULT_STYLE' so that is good to know! Also, I see you're using variables in the GUIDEFINE and this seems to work. It may sound strange, but first I did not understand how this could work (though I programmed the whole thing myself). Now I see that the tokens for the properties are passed-as-they-are. And so it only works for global variables. The GUIDEFINE has problems with global string variables so that I will look into. Lastly, as a remark but you probably know, your GUISET commands can be merged if they relate to the same widget. So instead of this: CALL GUISET(id, "frame", "label", "Frame") CALL GUISET(id, "frame", "shadow-type", 1) CALL GUISET(id, "frame", "shadow", 1) CALL GUISET(id, "frame", "width-request", win_w - 8)
We can say this also to save some space CALL GUISET(id, "frame", "label", "Frame", "shadow-type", 1, "shadow", 1, "width-request", win_w - 8)
Most of these properties can be added to GUIDEFINE also, just know that the actual property names in GUIDEFINE are written without double quotes. Thanks again,
Regards Peter
|
|