[racket] Help with racket/gui and framework

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Feb 17 19:49:38 EST 2014

Sorry for the long delay in replying.

Here's some that deals with issues #1 and #3.  For issue #2, it depends on
what you want to do, I suppose. One thing you can do is override the
frame's get-editor% method to use a completely different class than the
default one and then you have lots of options.

hth,
Robby

#lang racket/gui
(require framework)
(application:current-app-name "Sanskrit editor") ;;framework
(define main-frame (new frame:text% [height 400]))

(send main-frame show #t)
(define main-area (send main-frame get-area-container))
(define h-panel (new horizontal-panel%
                     [parent main-area]
                     [stretchable-height #f]
                     [alignment '(left top)]))
(send main-area change-children reverse)

(define msg (new message%
                 [parent main-area]
                 [label "NO EVENTS SO FAR... "]))
(define button-font (make-object font% 12 "Consolas" 'default 'normal 'bold
))
(define button-1 (new button%
                      [parent h-panel][font button-font]
                      [label "Apply Sandhi"]
                      ; Callback procedure for a button click:
                      [callback (lambda (button event)
                                  (send msg set-label "TEST Apply Sandhi
Test"))]))

(define button-2 (new button% [parent h-panel][font button-font]
                      [label "HK-->Unicode"]

                      ; Callback procedure for a button click:
                      [callback (lambda (button event)
                                  (send msg set-label "TEST Converted
HK-->Unicode"))]))

(send (send main-frame get-editor) set-max-undo-history 'forever)


On Tue, Feb 4, 2014 at 5:29 PM, Harry Spier <vasishtha.spier at gmail.com>wrote:

> Thanks Robby,
> When I use (define main-frame (new frame:text%)) case 1 below it gives me
> save, save all, print etc. in the file menu but now:
> a) the panel with the buttons I define is at the bottom not the top.
> b) I can't figure out how to modify the initial editor characteristics
> when the application starts (different font, different size etc.) or the
> editor-canvas% characteristics (different background) as I was able to when
> I used (define main-frame (new frame:standard-menus%))
> c) I can't figure out how to now apply set-max-undo-history so I can use
> the undo feature.
>
>
> How do I get the horizontal-panel with my buttons to display at the top ?
> How do I access and set the characteristics of the editor% and the
> editor-canvas% ?
> How do I set se-max-undo-history ?
>
> CASE 1 using  (define main-frame (new frame:text%))  Menus OK but issues
> stated above.
>
> ----------------------------------------------------------------------------------------
> #lang racket/gui
> (require framework)
> (application:current-app-name "Sanskrit editor") ;;framework
> (define main-frame (new frame:text% ))
>
> (send main-frame show #t)
> (define main-area (send main-frame get-area-container))
> (define h-panel (new horizontal-panel% [parent
> main-area][stretchable-height #f][alignment '(left top)]))
>
> (define msg (new message% [parent main-area][label "NO EVENTS SO FAR...
> "]))
> (define button-font (make-object font% 12 "Consolas" 'default 'normal
> 'bold ))
> (define button-1 (new button% [parent h-panel][font button-font]
>       [label "Apply Sandhi"]
>        ; Callback procedure for a button click:
>      [callback (lambda (button event)
>                      (send msg set-label "TEST Apply Sandhi Test"))]))
>
> (define button-2 (new button% [parent h-panel][font button-font]
>           [label "HK-->Unicode"]
>
>            ; Callback procedure for a button click:
>            [callback (lambda (button event)
>                     (send msg set-label "TEST Converted HK-->Unicode"))]))
>
> CASE 2 using (define main-frame (new frame:text% )) The panel with my
> buttons is correctly placed at top and I can change editor% and
> editor-canvas% properties but no "save" and "save all" and "new" doesn't
> work correctly in "file" menu.
>
> --------------------------------------------------------------------------------------
> #lang racket/gui
> (require framework)
> (application:current-app-name "Sanskrit editor")
>
> (define main-frame (new frame:standard-menus% [label "Sanskrit editor"]))
>
> (send main-frame show #t)
> (define main-area (send main-frame get-area-container))
> (define h-panel (new horizontal-panel% [parent
> main-area][stretchable-height #f]))
> (define msg (new message% [parent main-area][label "NO EVENTS SO FAR...
> "]))
> (define button-font (make-object font% 12 "Consolas" 'default 'normal
> 'bold))
> (define button-1 (new button% [parent h-panel][font button-font]
>       [label "Apply Sandhi"]
>       ; Callback procedure for a button click:
>       [callback (lambda (button event)
>        (send msg set-label "TEST Apply Sandhi Test"))]))
>
> (define button-2 (new button% [parent h-panel][font button-font]
>      [label "HK-->Unicode"]
>     ; Callback procedure for a button click:
>     [callback (lambda (button event)
>     (send msg set-label "TEST Converted HK-->Unicode"))]))
>
>
> (define main-text-editor (new text%))
>
> (define default-delta (make-object style-delta%) )
> (send default-delta set-delta-face "Consolas")
> (send default-delta set-size-add 6)
> (send main-text-editor change-style default-delta)
> (send main-text-editor set-max-undo-history 400)
> (send main-text-editor auto-wrap #t)
>
> (define main-canvas (new editor-canvas% [parent main-area]))
> (define WhiteSmokeColor (send the-color-database find-color "WhiteSmoke"))
> (send main-canvas set-canvas-background WhiteSmokeColor)
> (send main-canvas set-editor main-text-editor)
>
> -----------------------------------------------
>
>
> On Tue, Feb 4, 2014 at 5:41 AM, Robby Findler <robby at eecs.northwestern.edu
> > wrote:
>
>> I think you want this for main-frame:
>>
>> (define main-frame (new frame:text%))
>>
>> But for the other, it looks not so simple. The framework isn't abstracted
>> out in the right ways to have two different lists of recently opened files.
>> It probably should be, tho. Patches welcome! :)
>>
>> Robby
>>
>>
>> On Tue, Feb 4, 2014 at 1:25 AM, Harry Spier <vasishtha.spier at gmail.com>wrote:
>>
>>> A clarification about point 1 below:  If I open a file or select "new"
>>> in the file menu it creates a new window and I'm able to save the text from
>>> that new window.  Its just when I run the program and type text into the
>>> visible frame of the original window that there are no "save","save
>>> as","print" etc. menu items in the file menu.
>>>
>>> Thanks,
>>> Harry
>>>
>>>
>>> On Mon, Feb 3, 2014 at 11:00 PM, Harry Spier <vasishtha.spier at gmail.com>wrote:
>>>
>>>> I'm building a small text editing application based around an editor
>>>> built with racket/gui and framework..  The idea is that it has the usual
>>>> text editing features but also buttons where I select text and then based
>>>> on which button I click on the selected text is manipulated in different
>>>> ways.  I'm just building the gui part now.  I started using just racket/gui
>>>> but then tried to implement some things in "framework" but I'm having
>>>> trouble with a few things and I can't figure out how to do them from the
>>>> documentation.
>>>>
>>>> In the code below:
>>>> 1) How do I add a "Save" feature to the file menu.
>>>> 2) The "Open recent" menu item in the file menu opens my DrRacket
>>>> "recently opened files".  How do I get it to look at its own history
>>>> instead of DrRackets.
>>>> 3) Where I define main-frame as a frame:standard-menus% object in the
>>>> code below, I tried to define it as a frame:editor% object but I couldn't
>>>> get that to work.  Could someone show me how to do that.
>>>>
>>>> Thanks,
>>>> Harry
>>>> -------------------------------------
>>>> #lang racket/gui
>>>> (require framework)
>>>> (application:current-app-name "Sanskrit editor")
>>>>
>>>> (define main-frame (new frame:standard-menus% [label "Sanskrit
>>>> editor"]))
>>>>
>>>> (send main-frame show #t)
>>>> (define main-area (send main-frame get-area-container))
>>>> (define h-panel (new horizontal-panel% [parent
>>>> main-area][stretchable-height #f]))
>>>> (define msg (new message% [parent main-area][label "NO EVENTS SO FAR...
>>>> "]))
>>>> (define button-font (make-object font% 12 "Consolas" 'default 'normal
>>>> 'bold ))
>>>> (define button-1 (new button% [parent h-panel][font button-font]
>>>>     [label "Apply Sandhi"]
>>>>     ; Callback procedure for a button click:
>>>>     [callback (lambda (button event)
>>>>            (send msg set-label "TEST Apply Sandhi Test"))]))
>>>>
>>>> (define button-2 (new button% [parent h-panel][font button-font]
>>>>     [label "HK-->Unicode"]
>>>>     ; [style '(border)]
>>>>     ; Callback procedure for a button click:
>>>>     [callback (lambda (button event)
>>>>            (send msg set-label "TEST Converted HK-->Unicode"))]))
>>>>
>>>>
>>>> (define main-text-editor (new text%))
>>>>
>>>> (define default-delta (make-object style-delta%) )
>>>> (send default-delta set-delta-face "Consolas")
>>>> (send default-delta set-size-add 4)
>>>> (send main-text-editor change-style default-delta)
>>>> (send main-text-editor set-max-undo-history 400)
>>>> (send main-text-editor auto-wrap #t)
>>>>
>>>> (define main-canvas (new editor-canvas% [parent main-area]))
>>>> (define WhiteSmokeColor (send the-color-database find-color
>>>> "WhiteSmoke"))
>>>> (send main-canvas set-canvas-background WhiteSmokeColor)
>>>> (send main-canvas set-editor main-text-editor)
>>>>
>>>> --------------------------------------------------
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> .
>>>>
>>>>
>>>
>>> ____________________
>>>   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/20140217/f9fb15e0/attachment.html>

Posted on the users mailing list.