[racket] how to tell, or trigger, on when an object is ready in tool on on startup

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri Jul 30 14:53:41 EDT 2010

Sorry for the long delay in replying. There isn't a good way to do
what you want (I'd hoped to find time to add one which is the reason
for the delay, but that's looking unlikely I'm sorry to say).

The best thing is probably to queue a low-priority callback from the
place where you're calling reload-my-tabs-from-file and have that do
the work. That way, you know that the objects will be completely
initialized.

You might also try calling that after you call super-init in a frame%
mixin, but you might get the same problems in that case.

Really, the best thing would be to change the code at the end of
drracket/private/main.rkt so that instead of calling make-basic it
called your function (perhaps when some preference was set).

hth,
Robby

On Tue, Jul 27, 2010 at 2:54 AM, Stephen De Gabrielle
<stephen.degabrielle at acm.org> wrote:
> Hi,
>
> I'm working on the tools facilities to build extensions for DrRacket,
> and I'm having some trouble;
>
> I think I'm getting the ''send: target is not an object: #<undefined>
> for method: is-shown?
> '' error on startup because the frame, tabs or text% is not yet
> finished starting up.
>
> I'd appreciate any help on how to run my method when DrRacket is ready?
>
> Cheers,
>
> Stephen
>
>
> --
> send: target is not an object: #<undefined> for method: is-shown?
>
>  === context ===
> /Applications/Racket
> v5.0/collects/racket/private/class-internal.rkt:4543:0: obj-error
> /Applications/Racket
> v5.0/collects/racket/private/class-internal.rkt:3786:0:
> find-method/who
> /Applications/Racket
> v5.0/collects/gui-debugger/debug-tool.rkt:1404:10:
> check-current-language-for-debugger method in
> ...ugger/debug-tool.rkt:1048:8
> /Applications/Racket
> v5.0/collects/gui-debugger/debug-tool.rkt:1393:10: on-tab-change
> method in ...ugger/debug-tool.rkt:1048:8
> /Applications/Racket v5.0/collects/drracket/syncheck.rkt:1027:8:
> on-tab-change method in ...rracket/syncheck.rkt:1019:6
> /Applications/Racket
> v5.0/collects/drracket/private/module-language-tools.rkt:58:6:
> on-tab-change method in ...e-language-tools.rkt:49:4
> /Applications/Racket v5.0/collects/drracket/private/tracing.rkt:168:6:
> on-tab-change method in .../private/tracing.rkt:163:4
> /Applications/Racket v5.0/collects/drracket/private/debug.rkt:1580:6:
> on-tab-change method in ...et/private/debug.rkt:1506:4
> /Applications/Racket v5.0/collects/drracket/private/unit.rkt:2847:8:
> change-to-tab method in ...ket/private/unit.rkt:1419:6
> /Applications/Racket v5.0/collects/drracket/private/unit.rkt:2817:10: core
> /Applications/Racket v5.0/collects/racket/private/map.rkt:45:11: for-each
> /Applications/Racket v5.0/collects/cosmonaut/tabs.rkt:26:6
> /Applications/Racket
> v5.0/collects/racket/private/class-internal.rkt:3596:0:
> continue-make-super
> /Applications/Racket v5.0/collects/gui-debugger/debug-tool.rkt:1048:8
> /Applications/Racket
> v5.0/collects/racket/private/class-internal.rkt:3596:0:
> continue-make-super
> /Applications/Racket v5.0/collects/macro-debugger/tool.rkt:118:6
> ...
>
>
> --
>
> #lang racket/gui
> (require racket/class
>         framework
>         racket/unit
>         racket/path
>         drracket/tool)
>
> (preferences:set-default
>  'ProjectManager:tabs "/Users/spdegabrielle/tabs.sp"
>  ; (path->string (build-path (find-system-path 'home-dir) "tabs.sp"))
>  string?)
>
> (provide tool@)
> (define tool@
>  (unit
>    (import drracket:tool^)
>    (export drracket:tool-exports^)
>    (define (phase1) (void))
>    (define (phase2) (void))
>    ;
>    ;    (define tab-mixin
>    ;      (mixin ()()
>    ;        (super-new)
>    ;        ))
>    (define (save/load-tabs-mixin super%)
>      (class super%
>        (inherit open-in-new-tab get-tabs)
>
>        ;        ;; 'ProjectManager:tabs ; path to tabs file
>        (field (saved-tabs-file (string->path "/Users/spdegabrielle/tabs.sp")))
>                                 ;(preferences:get 'ProjectManager:tabs))))
>        ;
>        ;; save-tabs : out-file tabs -> void
>        (define/private (save-tabs-file out-file tabs)
>          (call-with-output-file out-file; saved-tabs-file-path
>            (lambda (i) (write tabs i))
>            #:exists 'replace))
>        ;
>        ;; each-tab -> list of files
>        ;; return the paths for all tabs that have one
>        (define/private (get-tab-files)
>          (map path->string
>               (filter (lambda (filename) filename)
>                       (map
>                        (λ (t) (send (send t get-defs) get-filename))
>                        (get-tabs)))))
>        ;
>        (define (save-tabs-to-file-on-exit-callback)
>          (save-tabs-file saved-tabs-file (get-tab-files)))
>
>        ;
>        (super-new)
>        ;
>        ;; reload-tab-from-file : in-file -> void
>        (define/private (reload-my-tabs-from-file tabs-file)
>          (let ((list-of-files (call-with-input-file tabs-file read)))
>            (for-each (λ (f) (open-in-new-tab f)) list-of-files)))
>
>        ;; get-tab-filename a-drscheme:unit:tab? -> (or/c path-string? false/c)
>        ;; return #f if tab has no filename
>        (define (get-tab-filename tab)
>          (send (send tab get-defs) get-filename))
>
>        (reload-my-tabs-from-file saved-tabs-file)
>
>        (exit:insert-on-callback save-tabs-to-file-on-exit-callback)
>        ))
>
>    ;   (drracket:get/extend:extend-tab tab-mixin)
>    (drracket:get/extend:extend-unit-frame save/load-tabs-mixin)
>    ))
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>


Posted on the users mailing list.