|
Post by ptitjoz on Jan 4, 2021 18:33:49 GMT 1
Hello. I'm looking for a way to write in an Edit at a particular location if in my Edit there are 10 lines, I would like to be able to write, for example, on the 8th line where there is the cursor. Is it possible ? How else to get the exhaustive list of properties and methods of the different components? (widgets?) Best regards
|
|
|
Post by Pjot on Jan 4, 2021 19:46:20 GMT 1
Hi ptitjoz, The HUG context does not provide such functionality by default. The design of HUG is to narrow down and simplify the use of GTK-based widgets. Such simplification comes with a penalty, namely, it does not allow a convenient way of doing sophisticated stuff. Having said that, of course there is a way. Probably you are interested in using the GTK function gtk_text_buffer_insert_at_cursor. To use this function, you need to know the underlying GtkTextBuffer. You can quick-and-dirty try to access HUG's internals by looking into the associative variable "hug_widget_s_widget". Something like this (untested): myedit = EDIT(300, 300) buffer = hug_widget_s_widget(STR$(myedit)) CALL gtk_text_buffer_insert_at_cursor(buffer, "This is a text", -1)
HTH, Peter
|
|
|
Post by ptitjoz on Jan 5, 2021 10:01:47 GMT 1
Hello Peter Thanks for taking time to respond to me I understand what you want to explain but I am not able to code using your example. I went to see the link and the contents of hug.bac but it remains confused for me Also I don't know the C, which doesn't help Couldn't someone code me a simple example? that would be nice. Best regards
|
|
|
Post by rikky on Jan 5, 2021 16:29:23 GMT 1
I took gtk_text_buffer_set_text() for I cannot get gtk_text_buffer_insert_at_cursor even to compile. But even then I get an error during running : (edit:13634): Gtk-CRITICAL **: IA__gtk_text_buffer_set_text: assertion 'GTK_IS_TEXT_BUFFER (buffer)' failedBut at least it compiles. INCLUDE "hug.bac"
SUB edit_demo()
edit_text$ = GRAB$(My_edit)
IF AMOUNT(edit_text$,NL$) = 3 THEN 'do this only once IF NOT(toggle) THEN toggle = 1 'gtk_text_buffer_insert_at_cursor(My_edit, "This is a text", 14) 'gtk_text_buffer_set_text (My_edit, "This is a text" & NL$, -1) gtk_text_buffer_set_text (My_edit,"This is a text" & NL$,15) END IF END IF
PRINT edit_text$
END SUB
Mainwin = WINDOW( "BaCon entry", 250,200) My_edit = EDIT(200,150) ATTACH( Mainwin, My_edit, 10, 10 ) CALLBACK(My_edit, edit_demo)
DISPLAY
|
|
|
Post by Pjot on Jan 5, 2021 18:19:05 GMT 1
This would be the most simple demonstration:
INCLUDE "hug.bac"
lib$ = HUGLIB$("gtk")
IMPORT "gtk_text_buffer_insert_at_cursor(long,char*,int)" FROM lib$ TYPE void
Mainwin = WINDOW( "BaCon entry", 250,200) My_edit = EDIT(200,150)
buffer = hug_widget_s_widget(STR$(My_edit)) CALL gtk_text_buffer_insert_at_cursor(buffer, "This is a text", -1)
ATTACH( Mainwin, My_edit, 10, 10 )
DISPLAY
HTH Peter
|
|
|
Post by rikky on Jan 5, 2021 20:11:33 GMT 1
Or this one: INCLUDE "hug.bac"
Mainwin = WINDOW( "BaCon entry", 250,200) My_edit = EDIT(200,150)
TEXT(My_edit,"text")
ATTACH( Mainwin, My_edit, 25, 25 )
DISPLAY
|
|
|
Post by Pjot on Jan 5, 2021 21:07:33 GMT 1
That's the default way, of course. However, it is not what ptitjoz is looking for. Hello. I'm looking for a way to write in an Edit at a particular location if in my Edit there are 10 lines, I would like to be able to write, for example, on the 8th line where there is the cursor. Is it possible ? The "gtk_text_buffer_insert_at_cursor" function will write text at the position of the cursor. BR Peter
|
|
|
Post by rikky on Jan 5, 2021 22:12:23 GMT 1
Of course you're right.
But to be honest, all the gtk functions are so difficult. I have no idea if something is a void or a long or a char or a char* . What type is a backgroundcolor for example.
en plus, there is not a function to determine where the cursor actually is. Or I must mislook.
So to see where the cursor is, you must get hold of the changes in the grabbed text anyway.
type my name is pti in the editbox:
INCLUDE "hug.bac"
SUB timeout text$ = GRAB$(My_edit) IF RIGHT$(text$,3) = "pti" THEN text$ = text$ & "tjoz" TEXT(My_edit,"") TEXT(My_edit,text$) END IF ENDSUB
Mainwin = WINDOW( "BaCon entry", 250,200) My_edit = EDIT(200,150)
TEXT(My_edit,"text")
ATTACH( Mainwin, My_edit, 25, 25 ) TIMEOUT(100,timeout) FOCUS(My_edit) DISPLAY Getting something on the eight line, when you change there something is likewise, I suppose.
|
|
|
Post by ptitjoz on Jan 6, 2021 9:21:03 GMT 1
Hello and thank you for your explanation!
This is what I get and which seems to work correctly.
Do you think this code is correctly implemented?
when I execute I have this message
Another small detail when I insert a text, the cursor disappears. how to fix it (but it's not a big worry for me)
EDIT I added the FOCUS instruction which seems to fix the problem
SUB SubBouttonInsert FOCUS (My_edit) CALL gtk_text_buffer_insert_at_cursor (buffer, GRAB $ (Entry1), -1) END SUB
Best regards. REM test insertion texte dans un edit à la position du curseur INCLUDE "./../lib/hug.bac" lib$ = HUGLIB$("gtk")
IMPORT "gtk_text_buffer_insert_at_cursor(long,char*,int)" FROM lib$ TYPE void SUB SubBouttonInsert CALL gtk_text_buffer_insert_at_cursor(buffer, GRAB$(Entry1), -1) END SUB
Mainwin = WINDOW( "BaCon entry", 400,300) My_edit = EDIT(200,150) buffer = hug_widget_s_widget(STR$(My_edit)) ATTACH(Mainwin,Entry1, 545, 10 )
TEXT(My_edit,"hello"&NL$) TEXT(My_edit,"world"&NL$)
ATTACH( Mainwin, My_edit, 10, 10 )
Entry1=ENTRY("text à insérer", 250, 30) ATTACH(Mainwin,Entry1, 250, 10 )
BouttonInsert= BUTTON("Insérer", 80, 25) ATTACH(Mainwin, BouttonInsert, 10, 200 ) CALLBACK(BouttonInsert,SubBouttonInsert)
DISPLAY
|
|
|
Post by rikky on Jan 6, 2021 9:57:24 GMT 1
Ah, now I see why you need to insert at the cursor. Indeed you cannot do this with only the TEXT( I'm a slow thinker, is yet proven again. Je m'excuse.. With the FOCUS on now it works for me. Rik.
|
|
|
Post by bigbass on Jan 7, 2021 23:33:00 GMT 1
Hello ptitjoz
and thanks for asking the question
It was a good question how to add advanced options to hug
Thanks Peter for the how to for advanced hug support registering new functions with hug.bac
those warnings are very low level ones there are many type checks and I was able to quiet them in pure gtk3 c code because the headers are defined and you have to type cast everything (a real pain but that's gtk)
*I think the warnings are harmless here but Peter has the final word with hug and how it works and if they could be removed or not
when you include hug.bac we need to go about things differently by IMPORTing the functions
and getting most of the needed gtk to do what hug does well for you without needing to know how gtk works on the low level and that's good hug makes coding clean and easy
I added a few macros that may be useful for a demo Joe
REM test insertion texte dans un edit à la position du curseur
'INCLUDE "./../lib/hug.bac" INCLUDE "hug.bac" lib$ = HUGLIB$("gtk")
DECLARE buffer TYPE long DECLARE message TYPE char*
IMPORT "gtk_text_buffer_insert_at_cursor(long,char*,int)" FROM lib$ TYPE void IMPORT "gtk_text_view_set_buffer(long,long)" FROM lib$ TYPE void IMPORT "gtk_text_view_get_buffer(long)" FROM lib$ TYPE long
'---new buffer INSERT macro DEF FN BUF_INS(b,t) = gtk_text_buffer_insert_at_cursor(b,t,-1)
'---register with HUG GET buffer macro fixed DEF FN GET_BUF(v) = hug_widget_s_widget(STR$(v))
'--- new SET buffer macro DEF FN SET_BUF(b,s) = gtk_text_buffer_set_text(b,s, -1)
SUB SubBouttonInsert
'--- buffer get,set, insert at cursor buffer = GET_BUF(My_edit) message = GRAB$(Entry1) & NL$ CALL BUF_INS(buffer,message) END SUB
Mainwin = WINDOW( "BaCon entry at cursor", 400,300) My_edit = EDIT(380,150)
TEXT(My_edit,"hello"&NL$) TEXT(My_edit,"world"&NL$)
buffer = GET_BUF(My_edit) SET_BUF(buffer, "MESSAGE EN HAUT" & NL$)
ATTACH( Mainwin, My_edit, 10, 10 )
Entry1=ENTRY("text à insérer", 380, 30) ATTACH(Mainwin,Entry1, 10, 170 )
BouttonInsert= BUTTON("Insérer", 80, 25) ATTACH(Mainwin, BouttonInsert, 10, 210 ) CALLBACK(BouttonInsert,SubBouttonInsert)
DISPLAY
|
|
|
Post by ptitjoz on Jan 13, 2021 8:33:34 GMT 1
Hello, and thank you for taking the time to look at my problem. However when I try your example I always have warnings is this normal? can I take it that it doesn't matter? Best regards
(test_insersion:2295): Gtk-CRITICAL **: 08:27:37.063: IA__gtk_widget_set_size_request: assertion 'GTK_IS_WIDGET (widget)' failed
(test_insersion:2295): Gtk-CRITICAL **: 08:27:37.063: IA__gtk_fixed_put: assertion 'GTK_IS_WIDGET (widget)' failed
|
|
|
Post by Pjot on Jan 13, 2021 17:45:54 GMT 1
Hi ptitjoz,
This is not normal. The reason is an error in your code. Please look at the line pointed to by the arrow:
REM test insertion texte dans un edit à la position du curseur INCLUDE "./../lib/hug.bac" lib$ = HUGLIB$("gtk")
IMPORT "gtk_text_buffer_insert_at_cursor(long,char*,int)" FROM lib$ TYPE void SUB SubBouttonInsert CALL gtk_text_buffer_insert_at_cursor(buffer, GRAB$(Entry1), -1) END SUB
Mainwin = WINDOW( "BaCon entry", 400,300) My_edit = EDIT(200,150) buffer = hug_widget_s_widget(STR$(My_edit)) ATTACH(Mainwin,Entry1, 545, 10 ) <---------------------- why this line???
TEXT(My_edit,"hello"&NL$) TEXT(My_edit,"world"&NL$)
ATTACH( Mainwin, My_edit, 10, 10 )
Entry1=ENTRY("text à insérer", 250, 30) ATTACH(Mainwin,Entry1, 250, 10 )
BouttonInsert= BUTTON("Insérer", 80, 25) ATTACH(Mainwin, BouttonInsert, 10, 200 ) CALLBACK(BouttonInsert,SubBouttonInsert)
DISPLAY
In the indicated line you are trying to add "Entry1" to Mainwin. But at that point, the "Entry1" is not defined. The program defines "Entry1" a few lines later.
So you have to delete that erroneous line and the error is gone.
HTH Peter
|
|
|
Post by bigbass on Jan 13, 2021 18:27:55 GMT 1
Hello Peter thanks for the code fix for the user side part of the HUG code excellent debugging skills! (I totally overlooked that ATTACH part in the wrong location since I copied and pasted the original code and only focused on the macros and IMPORTS and "thought" it was missing a typecast for GTK_TEXT_BUFFER and we dont use the gtk2 headers and no way of faking the typecast in the low level code ) I did get this working in gtk3 basic-converter.proboards.com/post/13919but lost the steam to press on with HUG gtk2 debugging of this buffer example thanks again I already applied your fix to the users side of the HUG code above Joe
|
|
|
Post by ptitjoz on Jan 14, 2021 10:37:41 GMT 1
Hello Oh really sorry I made a duplicate line.
In any case, thank you for your help which is very precious to me!
Thank you for your respective contributions. I do not master much and English is an additional obstacle.
Best regards !
|
|