[racket] Using GUI editor

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Sep 21 09:40:01 EDT 2013

Robby means something like this:

#lang racket/gui

(define f (new frame% [label "Notes"] [width 400] [height 600]))
(define my-canvas%
  (class canvas%
    (super-new)
    (define/override (on-char . x)
      (displayln x)
      (define dc (send this get-dc))
      (send dc set-scale 1 1)
      (send dc set-text-foreground "blue")
      (send dc draw-text "Use this window for notes" 10 10))))
(define c (new my-canvas% [parent f]))
(define t (new text%))
(send f show #t)
 
(define mb (new menu-bar% [parent f]))
(define m-edit (new menu% [label "Edit"] [parent mb]))
(define m-font (new menu% [label "Font"] [parent mb]))
(append-editor-operation-menu-items m-edit #f)
(append-editor-font-menu-items m-font)



On Sep 20, 2013, at 9:54 PM, Robby Findler wrote:

> A dc<%> object doesn't work like that. If you want to draw something into it, you have to set up a callback and draw during the dynamic extent of the callback. Also, if you do that, you probably want to use a canvas% object, not an editor-canvas%. The editor-canvas% objects already do a lot of work to control what gets drawn in there based on what is in the text% object.
> 
> Robby
> 
> 
> On Fri, Sep 20, 2013 at 8:40 PM, Alan Johnsey <a.johnsey at cox.net> wrote:
> Thanks. That will do for now, but it remains a mystery to me why my approach doesn’t work.
> 
> -Alan
> 
>  
> 
>  
> 
> From: Matthias Felleisen [mailto:matthias at ccs.neu.edu] 
> Sent: Friday, September 20, 2013 10:17 AM
> To: Alan Johnsey
> Cc: 'Racket Mailing List'
> Subject: Re: [racket] Using GUI editor
> 
>  
> 
>  
> 
> On Sep 20, 2013, at 1:05 PM, Alan Johnsey wrote:
> 
> 
> 
> 
> It looks like I’ve stumbled into another area where I’m lacking a basic understanding of what’s going on.  I’m trying to use the built-in editor in the gui package, but I need to put some initial content into the editor window. When I put the following in the editor pane and run it, I get the gui editor, but not the text. When I then
> 
> simply put the last line into the interactions window and execute it, I get the text in the gui editor window as desired. Why? What do I need to do to programmatically modify the text in the gui window?
> 
> -Alan
> 
>  
> 
> #lang racket/gui
> 
> (define f (new frame% [label "Notes"]
> 
>                       [width 400]
> 
>                       [height 600]))
> 
> (define c (new editor-canvas% [parent f]))
> 
> (define t (new text%))
> 
> (send c set-editor t)
> 
> (send f show #t)
> 
>  
> 
> (define mb (new menu-bar% [parent f]))
> 
> (define m-edit (new menu% [label "Edit"] [parent mb]))
> 
> (define m-font (new menu% [label "Font"] [parent mb]))
> 
> (append-editor-operation-menu-items m-edit #f)
> 
> (append-editor-font-menu-items m-font)
> 
>  
> 
> ; above pretty much straight out of the Design Doc
> 
>  
> 
>  
> 
> Do you want this
> 
>  
> 
>  (send t insert "Use this window for making notes" 10 10)
> 
>  
> 
> instead of the below? 
> 
>  
> 
> 
> 
> 
>  
> 
> (define dc (send c get-dc))
> 
> (send dc set-scale 1 1)
> 
> (send dc set-text-foreground "blue")
> 
> (send dc draw-text "Use this window for making notes" 0 0)
> 
>  
> 
>  
> 
> ____________________
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users
> 
>  
> 
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130921/abd28ed2/attachment.html>

Posted on the users mailing list.