Page 1 of 2

alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 12:43 pm
by glenn9
Dear all

I'm wanting to alter textstyle as I type and although I've solved it with a 'kludge', I was wondering if there was a better way of achieving this?

Specifically what I'm wanting to achieve is that if a specific character is entered then the colour of that character is then changed.

I've managed to achieve this with the following code:

Code: Select all

     on rawkeyup
        if the last char of fld"Notes" is "z" then
        set the forecolor of the last char of fld"Notes" to red
  else
     	set the forecolor of the last char of fld"Notes" to black
  end if
   end rawkeyup
This works to a degree but if I then alter already typed text to the specified text, then of course this doesn't work!

I guess what I want to code is something like this (which of course doesn't work!)...

Code: Select all

...
if rawkeyup is "z" then 
set the forecolor of rawkeyup to red
...

Grateful for any ideas...

Thanks,

Glenn

Re: alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 12:52 pm
by Klaus
Hi Glenn,
This works to a degree but if I then alter already typed text to the specified text, then of course this doesn't work!
sorry, don't understand?


Best

Klaus

Re: alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 12:55 pm
by jmburnod
Hi,
You may use keyup instead rawkeyup (rawkeyup return a integer)
Something like that

Code: Select all

on keyup pKey
if pKey = "z" then
   set the forecolor of the last char of fld "Notes" to red
end if	
end keyup
Best regards
Jean-Marc

Re: alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 3:25 pm
by glenn9
Klaus wrote:
Sun Mar 06, 2022 12:52 pm
Hi Glenn,
This works to a degree but if I then alter already typed text to the specified text, then of course this doesn't work!
sorry, don't understand?


Best

Klaus
Hi Klaus,

apologies for the awkward wording.

if the last character I type is a 'z' then the code will as expected change the colour of the 'z' to red.

If however I go back to text that is already in the field, and change one of characters to a 'z', the colour of the 'z' wont of course change, but the last char of the field (whatever it might be) will change to red!

I guess what I'm looking for is a way of scripting 'keyup' to change the textstyle of a char as its typed, independent of where it is in the field, as at the moment I can only do this for the last char of a field?

Hope this makes sense!

Thanks,

Glenn

Re: alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 3:44 pm
by Klaus
Aha, thanks, get it now! :-)

Re: alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 5:46 pm
by jmburnod
Hi Glen,
This works for an insertion, not for a selection

Code: Select all

on keyUp pk
   put the selectedchunk into tSC
   put the value of word 4 of tSC into tNumC
   if pk = "z" then
      set the forecolor of char tNumC of fld "notes" to red
   else
      set the forecolor of char tNumC of fld "notes" to black
   end if
end keyUp

Re: alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 6:46 pm
by Klaus
Cool!

but no need to use VALUE!

Code: Select all

...
put word 4 of tSC into tNumC
...
Will do.

Re: alter textstyle 'on the fly'

Posted: Sun Mar 06, 2022 8:20 pm
by glenn9
jmburnod wrote:
Sun Mar 06, 2022 5:46 pm
Hi Glen,
This works for an insertion, not for a selection

Code: Select all

on keyUp pk
   put the selectedchunk into tSC
   put the value of word 4 of tSC into tNumC
   if pk = "z" then
      set the forecolor of char tNumC of fld "notes" to red
   else
      set the forecolor of char tNumC of fld "notes" to black
   end if
end keyUp
Hi Jean-Marc,

Many thanks, this works perfectly and exactly how I was imagining it.

Initially I couldn't understand at all why it worked but on checking the dictionary and going into debug mode I now see why it works and why 'word 4' is important.

after now seeing how this works I can only echo Klaus's comment... very cool!

Thank you again.

Regards,

Glenn

Re: alter textstyle 'on the fly'

Posted: Mon Mar 07, 2022 10:33 am
by jmburnod
Hi Glenn,
Glad when I can help
This version below works with a selection

Code: Select all

on keyUp pk
   put the selectedchunk into tSC
   put  word 2 of tSC into tStart
   put  word 4 of tSC into tEnd 
   if tStart > tEnd then
      put tEnd into tNumS
   else
      put tStart into tNumS
   end if
   if pk = "z" then
      set the forecolor of char tNumS of fld "notes" to red
   else
      set the forecolor of char tNumS of fld "notes" to black
   end if
end keyUp
P.S: I'm curious to know why you need it.
Best
Jean-Marc

Re: alter textstyle 'on the fly'

Posted: Mon Mar 07, 2022 11:14 am
by glenn9
Thanks Jean-Marc,

The background is that I'm often in a position where I am taking almost verbatim typed notes during a conversation, and if there are any points raised that require further clarification, rather than interrupt the conversation flow, I simply type a quick marker after the item raised, usually a '(' rather than the 'z'!, so that I can then revisit the item at the end of the conversation and add more details.

If the notes are lengthy I've sometimes nearly overlooked the points that I wanted more detail on, and so having the marker in red makes it easier for me to spot!

Hope of interest.

Regards,

Glenn

Re: alter textstyle 'on the fly'

Posted: Mon Mar 07, 2022 3:01 pm
by dunbarx
Fun stuff. I would make the "markers" more prominent than simply making a single char red. Maybe change the textSize of that char?

Craig

Re: alter textstyle 'on the fly'

Posted: Tue Mar 08, 2022 3:55 pm
by jmburnod
Hi Glenn,
Thank you for your message.
Interessant challenge
I wonder if using metadata property would be useful in your "scribe" position.
Just an idea
When you type your marker char you can select a keyword among a list which become the metadata of the previous word.

Best regards
Jean-Marc

Re: alter textstyle 'on the fly'

Posted: Tue Mar 08, 2022 5:52 pm
by dunbarx
Jean-Marc.

The "metaData" of a char or word is way cool. I have never used it, but wish I had a reason to. It is sort of like a custom property, but assigned to chunks.

But how would that stand out when the reader is trying to locate specific locations in a body of text that are of interest?

Craig

Re: alter textstyle 'on the fly'

Posted: Tue Mar 08, 2022 5:58 pm
by dunbarx
Well, one way would be to set, say, the backColor of the chunk of interest so it can be found easily, and if the lockText of the field is set:

Code: Select all

on mouseUp
   answer the metaData of the clickchunk
end mouseUp
The metaData being a text string of any length. This can be written when the "special" char or word is typed. An "ask" dialog can pop up where the user can enter a notation, and set the metaData to that text.

Craig

Re: alter textstyle 'on the fly'

Posted: Tue Mar 08, 2022 6:51 pm
by jmburnod
Hi Craig,
But how would that stand out when the reader is trying to locate specific locations in a body of text that are of interest?
Why not set the textstyle of target word to "link" ?

Jean-Marc