[plt-scheme] GUI editor simple example

From: Hugh Myers (hsmyers at gmail.com)
Date: Sat Jul 4 20:54:45 EDT 2009

Fascinating! What a wonderful thing you have done. It makes my efforts
to translate from the score of a chess game to the positions reached
along the way look pretty mundane.

--hsm

On Sat, Jul 4, 2009 at 12:13 PM, Philippos Apolinarius<phi500ac at yahoo.ca> wrote:
> What called my attention to PLT scheme was its editor, and unicode
> processing facilities.  I am a very poor writer. Therefore, since I know
> Ancient Greek, my teachers suggested reading and translating Homer to
> improve my writing skills. Homer wrote in a kind of language that has many
> similarities with Ancient Greek. The first step was to write an editor to
> deal with Homer's language (there aren't many of them around, you know :-) I
> tried to write the editor in Clean. However, Clean does not deal with
> Unicode strings at all. I switched to Bigloo. Although Bigloo has tools  to
> work with unicode, these tools are awkward, and I failed.
>
> To my surprise, PLT worked almost flawlessly with the Homeric text. I mean,
> the IDE didn't work correctly, but the resulting program is almost perfect.
> Interesting enough, the only charcter that the editor does not renders well
> is ... lambda, the symbol of functional programming.  Below, you will find a
> simplified version of the module that produces a latex document from a
> unicode edition of the Odyssey (www.perseus.tufts..edu). Here are the first
> two lines of the Odyssey, with latex produced by the program:
>
> ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
> πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν:
>
>>'andra moi >'ennepe, mo\~usa, pol'utropon, <`oc m'ala poll`a\\
> pl'agqjh, >epe`i Tro'ihc <ier`on ptol'iejron >'epersen;
>
>
>
>
> (module greekfilter scheme/gui
>
>   (define (geragreek b n)
>     (cond ( (< n 1) '())
>           ( (cons (list b (list->string
>                             (list(integer->char b))))
>                   (geragreek (+ b 1) (- n 1))))))
>
>   (define (gb b n)
>     (geragreek b n))
>
>   (define gcod
>      '(
>         (913 "A") (914 "B") (915 "G") (916 "D")(917 "E")
>         (918 "Z") (919 "H") (920 "J") (921 "I") (922 "K")
>         (923 "L") (924 "M") (925 "N") (926 "X") (927 "O")
>         (928 "P") (929 "R") (931 "S") (932 "T") (933 "U")
>         (934 "F") (935 "X") (936 "Y") (937 "W")
>         (945 "a") (946 "b") (947 "g") (948 "d") (949 "e")
>         (950 "z") (951 "h") (952 "j") (953 "i") (954 "k")
>         (955 "l") (956 "m") (957 "n") (958 "x") (959 "o")
>         (960 "p") (961 "r") (962 "c") (963 "s") (964 "t")
>         (965 "u") (966 "f") (967 "q") (968 "y") (969 "w")
>         ;; ἀἁἂἃ ἄἅἆἇ ἈἉἊἋ ἌἍἎἏ
>         (7936 ">a") (7937 "<a") (7938 ">`a") (7939 "<`a")
>         (7940 ">'a") (7941 "<'a") (7942 "{\\char 146}")
>         (7943 "\\char 145")
>         (7944 ">A") (7945 "<A") (7946 ">`A") (7947 "<'A")
>         (7948 ">'A") (7949 "<'A") (7950 "\\~>A") (7951 "\\~<A")
>          ;; ἐἑἒ ἓἔἕ
>         (7952 ">e") (7953 "<e") (7954 ">`e")
>         (7955 "<`e") (7956 ">'e") (7957 "<'e")
>         ;; ἘἙἚ  ἛἜἝ
>         (7960 ">E") (7961 "<E") (7962 ">`E")  (7963 "<`E") (7964 ">'E")
> (7965 "<'E")
>         ;; ἠἡἢἣ ἤἥἦἧ ἨἩἪἫ ἬἭἮἯ
>         (7968 ">h") (7969 "<h") (7970 ">`h") (7971 "<`h")
>         (7972 ">'h") (7973 "<'h") (7974 "{\\ese}") (7975 "{\\hee}")
>         (7976 ">H") (7977 "<H") (7978 ">`H") (7979 "<`H")
>         (7980 ">'H") (7981 "<'H") (7982 "\\~>H")
>         (7983 "\\~<H")
>         ;;
>         (8032 ">w") (8033 "<w") (8034 ">`w") (8035 "<`w")
>         (8036 ">'w") (8037 "<'w") (8038 "{\\w}")  (8039 "{\\hw}")
>         (8040 ">W") (8041 "<W") (8042 ">`W")  (8043 "<`W")
>         (8044 ">'W") (8045 "<'W") (8046 "\\~>W") (8047 "\\~<W")
>         (8000 ">o") (8001 "<o") (8002 ">`o") (8003 "<`o")(8004 ">'o")(8005
> "<'o")
>         (8008 ">O")(8009 "<O") (8010 ">`O") (8011 "<`O") (8012 ">'O") (8013
> "<'O")
>
>         (8016 ">u") (8017 "<u") (8018 ">`u") (8019 "<`u") (8020 ">'u") (8021
> "<'u")
>         (8022 "{\\usu}") (8023 "{\\huu}") (8025 "<U")(8027 "<`U")(8029
> "<'U")
>         (8031 "\\~<U") (8160 "\\u u") (8161 "\\=u")
>         (8162 "`u"); ῢ
>         (8163 "'u"); ΰ
>         (8164 ">r") (8165 "<r") (8166 "\\~u")
>         (8167 "\\~u") ;ῧ
>         (8168 "U") ; Ῠ
>         (8169 "U") ; Ῡ
>         (8170 "`U") (8171 "'U") (8172 "<R") (8048 "`a") (8049 "'a") (8050
> "`e")
>         (8051 "'e") (8052 "`h") (8053 "'h") (8054 "`i") (8055 "'i") (8056
> "`o")
>         (8057 "'o") (8058 "`u") (8059 "'u") (8060 "`w") (8061 "'w") (7984
> ">i")
>         (7985 "<i") (7986 ">`i") (7987 "<`i") (7988 ">'i")
>         (7989 "<'i") (7990 "{\\ii}")  (7991 "{\\hii}") (7992 ">I")
>         (7993 "<I") (7994 ">`I")  (7995 "<`I") (7996 ">'I")
>         (7997 "<'I") (7998 "\\~>") (7999 "\\~<") (8125 "\\e")
>         (8178 "`w|") (8179 "w|") (8180 "'w|")   (8182 "\\~w")
>         (8183 "{\\wi}")        (8184 "`O")  (8185 "'O")        (8186
> "`W")
>         (8187 "'W")        (8188 "Wi")  (8128 "\\~")        (8130 "`h|")
>         (8131 "h|")        (8132 "'h|")   (8134 "\\~h") (8135 "{\\eei}")
>         (8136 "`E") (8137 "'E") (8138 "`H") (8139 "'H")
>         (8140 "Hi") (8141 "{>`}") (8142 "{>'}")   (8143 "\\~>") (8144 "{\\u
> i}")
>         (8145 "{\\=i}")
>         (8146 "`i") ;;ῒ
>         (8147 "'i") ;;ΐ
>         (8150 "\\~i")
>         (8151 "\\~i") ;;ῗ
>         (8152 "I")  ;;Ῐ
>         (8153 "\\=I") ;;Ῑ
>         (8154 "`I") (8155 "'I")
>         (8220 "{\\oq}") (8221 "{\\cq}")  (8064 ">a|") (8065 "<a|")
>         (8066 ">`a|") (8067 "<`a|") (8068 ">'a|") (8069 "<'a|")
>         (8070 "{\\char 150}") (8071 "{\\char 149}")
>         (8080 ">h|") (8081 "<h|")  (8082 ">`h|") (8083 "<`h|")
>         (8084 ">'h|") (8085 "<'h|")  (8086 "{\\esei}") (8087 "{\\heei}")
>
>         (8096 ">w|") (8097 "<w|")   (8098 ">`w|") (8099 "<`w|")
>         (8100 ">'w|") (8101 "<'w|")  (8102 "{\\wswi}") (8103 "{\\hwi}")
>         (8104 ">Wi") (8105 "<Wi")  (8106 ">`Wi") (8107 "<`Wi")
>         (8108 ">'Wi") (8109 "<'Wi")  (8110 "\\~>Wi") (8111 "\\~<Wi")
>         (8112 "\\u a") (8113 "\\=a") (8114 "`a|") (8115 "a|")
>         (8116 "'a|") (8118 "\\~a")  (8119 "{\\ai")
>         (8122 "`A") (8123 "'A")   (970 "{\\\"i}")
>      )
>   )
>
>   (define (convert1 c)
>     (cond ( (equal? c #\newline) "\\\\\n")
>           ( (equal? c #\:) ";")
>           ( (< (char->integer c) 255) c)
>           (else (let ((x (assoc (char->integer c) gcod)))
>                      (if x (cadr x) "*")))  ))
>
>   (define diálogo
>     (new dialog% (label "GreekFilter")))
>
>   (define txt
>     (new text%))
>
>   (define edtxt
>     (new editor-canvas% [parent diálogo]
>          [editor txt]
>          (min-height 200)
>          (min-width 500)))
>
>   (define painel (new horizontal-panel% [parent diálogo]
>                       (alignment '(center center))))
>
>   (define pasteButton
>     (new button% [parent painel] (label "Paste")
>          (callback (lambda(b e) (send txt paste )))))
>
>   (define cpyButton
>     (new button% [parent painel] (label "Cut")
>          (callback (lambda(b e) (send txt cut )))))
>
>   (define (convert b e)
>      (send txt insert
>        (with-output-to-string
>          (lambda()
>            (let ((s (send txt get-text)))
>              (newline)(newline)
>             (do ( (i 0 (+ i 1)))
>                 ( (>= i (string-length s)))
>                (display (convert1 (string-ref s i)))))))))
>
>   (define prtFirst
>     (new button% [parent painel] (label "2TEX")
>          (callback convert)))
>
>   (send diálogo show #t)
> )
>
>
>
>
>
> --- On Sat, 7/4/09, Matthew Flatt <mflatt at cs.utah.edu> wrote:
>
> From: Matthew Flatt <mflatt at cs.utah.edu>
> Subject: Re: [plt-scheme] GUI editor simple example
> To: "Hugh Myers" <hsmyers at gmail.com>
> Cc: plt-scheme at list.cs.brown.edu
> Received: Saturday, July 4, 2009, 7:47 AM
>
> At Sat, 4 Jul 2009 01:44:42 -0600, Hugh Myers wrote:
>> Given:
>>
>> (define f (new frame% [label "Simple Edit"]
>>                         [width 200]
>>                         [height 200]))
>>   (define c (new editor-canvas% [parent f]))
>>   (define t (new text%))
>>   (send c set-editor t)
>>
>> How do I control the initial font?
>
> Setting the font is more complicated than it should be. You have to
> create a `style-delta%' (which has a poor API), and then apply the
> style delta with `change-style'.
>
> For example, to change the font to size 20:
>
> (send t change-style (make-object style-delta% 'change-size 20))
>
> To set the font to "Times":
>
> (send t change-style (send (make-object style-delta%)
>                             set-delta-face "Times"))
>
>> How do I insert a line of text?
>
> (send t insert "Hello\n")
>
>> Lines?
>
> (send t insert "Hello\n")
> (send t insert "Goodbye\n")
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> ________________________________
> Be smarter than spam. See how smart SpamGuard is at giving junk email the
> boot with the All-new Yahoo! Mail
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>

Posted on the users mailing list.