denemo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Denemo-devel] Book with Denemo


From: Richard Shann
Subject: Re: [Denemo-devel] Book with Denemo
Date: Sun, 08 May 2016 08:47:51 +0100

On Sun, 2016-05-08 at 08:10 +0200, Andreas Schneider wrote:
> I have written the following code, borrowing parts from other commands:
> 
> ;;;StartBookpart
> (let ((tag "StartBookpart")(thetitle ""))
>   (d-DirectivePut-movementcontrol-override tag (logior
> DENEMO_OVERRIDE_GRAPHIC DENEMO_OVERRIDE_TAGEDIT))
>   (set! thetitle (d-GetUserInputWithSnippets (_ "Start Bookpart")(_
> "Give chapter title::") thetitle))
>   (disp thetitle)
>   (if thetitle
>   (begin
>     (d-DirectivePut-movementcontrol-prefix tag (string-append "
> \\bookpart { %start of
> bookpart\n  \\header {\n    title = {" thetitle "}\n  }\n"))
>     (d-SetSaved #f)
>   )
>     (d-InfoDialog "Cancelled")
>   )
> )
> 
> However, if I insert, e.g., Titletext in the dialog, it returns
> (Titletext . \line\large{Titletext}
> )
> (this is what (disp thetitle) outputs), and (string-append ) gives an
> error that that is not a string. How can I access the unprocessed input?

This is documented (just about!) in the manual:

GetUserInputWithSnippets. Takes up to three strings, title, prompt and
initial value. Shows these to the user with a text editor for the user
to return a string. Buttons are present to insert snippets which are
bracketed with section characters. Fourth parameter makes the dialog not
block waiting for input. Returns a pair comprising the user’s text and
formatted LilyPond syntax. 


So (car thetitle) is the text you want.


> 
> Moreover, when the user calls StartBookpart a second time I want to fill
> the input field with the previous title. To this end, the clean title
> has to be saved somewhere (or the generated code has to be parsed). How
> can that be done?

there is a field called data for this purpose. If you just want to store
the text and nothing more you can use

(d-DirectivePut-movementcontrol-data tag (car thetitle))

but in that case you could just use the "display" field to store it,
thus

(d-DirectivePut-movementcontrol-display tag (car thetitle))

which is good because the user would get presented with this "display"
field in some circumstances - it is a field designed for something to
display to the user.

But more generally you may want to store other data such as font size in
which case you create an association list(*) and store that as a string
containing executable scheme code which can be evaluated to re-create
the association list (from which the values can then be extracted).
Examples of this are in the Multi-Line text commands. The tricky part of
this comes with accented characters: guile 1.8 has a nasty behavior when
you use the (format ..) command to create the string to put in the data
field if some of the data is strings with accented characters. So if you
dig through that code you will find that the string to store is
laboriously constructed as a literal association list via 
(string-append "(list (cons 'title " (car thetitle) ")") type code.

 (This would be the association list (list (cons 'title "my title"))
stored as a string, the association list is got back then as the result
of (eval-string ...) on that string).

(I write from memory here).

HTH

Richard

(*) an association list is a list of pairs. You would use something
memorable like 'title for the first element of a pair and the actual
title for the second. Then 'fontsize with a number etc. to make a pair
for the second element. The order in the list is irrelevant.




> 
> Andreas
> 
> 
> Am 06.05.2016 um 15:32 schrieb Richard Shann:
> > On Thu, 2016-05-05 at 22:22 +0100, Richard Shann wrote:
> >> without having time to look at this tonight, it would seem clear that
> >> you could write
> >>
> >>  (d-DirectivePut-movementcontrol-prefix tag "\\bookpart { %start of
> >>  bookpart\n\\header { whatever is needed }\n")
> >>
> >>
> >> filling in "whatever is needed".
> > 
> > 
> > Having read that up, it looks like what you want is already do-able in
> > the way I described above. To make a nice system of commands for
> > handling the chapters in the book without the user seeing the underlying
> > LilyPond syntax would require some work however. I can help if you want
> > to do that.
> 
> 
> _______________________________________________
> Denemo-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/denemo-devel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]