laurent.orseau
2021-8-2 08:52:35

@robby Is there a way to create a new DrRacket window from within a quickscript and obtain the frame% object? I chased the File\|New to frame.rkt and it calls (handler:edit-file #f) but when I try this it opens a new GRacket window instead of a drracket frame. So I guess the handler must be set somewhere to something else. Any clue?


laurent.orseau
2021-8-2 08:56:21

I can call (send the-current-drracket-frame file-menu:new-callback) but this won’t give me the new frame% object


laurent.orseau
2021-8-2 08:59:42

The end goal is to move a tab to a new window


robby
2021-8-2 12:01:25

I think unit.rkt should have the callback.


laurent.orseau
2021-8-2 14:00:35

Right, I got there, but I must say my understanding of units is fairly limited (after reading the docs), and drracket is not exactly the toy example of the guide :slightly_smiling_face:

Is it possible to obtain this callback without instantiating the unit again?

My failed attempt so far: This fails with unbond id frame:basics<%> which I tried to chase but couldn’t get rid of this message. #lang racket/base (require quickscript racket/class racket/unit drracket/private/unit drracket/private/drsig framework) (define-values/invoke-unit/infer unit@) (drracket:unit:open-drscheme-window #f) ; unbound id frame:basics<%> (define-script move-to-new-window #:label "Move tab to new window" (λ (selection #:frame fr) #;(handler:edit-file #f) ; GRacket by default, not what we want #;(send fr file-menu:new-callback #f #f) ; does not return the handle (drracket:unit:open-drscheme-window #f) #f)) But I suspect there’s a lot more stuff to do to be able to use the unit…


robby
2021-8-2 15:19:18

The exports of the unit are all already available to scripts, I believe.


laurent.orseau
2021-8-2 15:20:44

Since the script is evaluated within the tool’s namespace, I believe they should be. But they are dynamic-required, so they should still compile on their own


robby
2021-8-2 15:21:31

Did you try calling drracket:unit:open-drscheme-window?


laurent.orseau
2021-8-2 15:21:40

Yes, as you can see above


robby
2021-8-2 15:22:01

Without invoking the unit, I mean.


laurent.orseau
2021-8-2 15:22:42

then I get unbound id


laurent.orseau
2021-8-2 15:23:51

(assuming that commenting out the define-values/invoke-unit/infer line s what you meant)


robby
2021-8-2 15:24:10

Did you require drracket/tool?


robby
2021-8-2 15:24:24

no, that’s not the right one. One sec.


robby
2021-8-2 15:25:30

Looks like drracket/tool-lib is the one you want.


laurent.orseau
2021-8-2 15:26:02

I can’t require this one, because it opens a DrRacket frame immediately, on which I have no control (also it’s messed up)


robby
2021-8-2 15:26:29

I think that migth be because of the namespace stuff that quickscript is doing.


robby
2021-8-2 15:26:53

That’s the library that exports all of the things described in the drracket tools manual.


laurent.orseau
2021-8-2 15:27:31

Yeah, that was my first attempt. But even if you write a standalone module that requires drracket/tool-lib it will start a Drr instance


robby
2021-8-2 15:27:49

Not if DrRacket is already started and you’re in the correct namespace, it won’t.


robby
2021-8-2 15:27:56

You’ll just get the one that’s already started.


robby
2021-8-2 15:28:11

I think that quickscript is creating a new namespace


robby
2021-8-2 15:28:24

So when you require that in the new namespace it will start up a new DrRacket.


robby
2021-8-2 15:28:40

(Which won’t work unless you set up the rest of the environment properly.)


robby
2021-8-2 15:29:05

It might be the right approach for quickscript to share that module with the namespaces it is creating.


laurent.orseau
2021-8-2 15:30:35

the script itself runs in the same namespace as the main drracket’s, but a new namespace is created to read the submodules of the quickscript that contain the menu info and stuff


laurent.orseau
2021-8-2 15:31:07

Though when I reload the menu, it doesn’t start a new drr instance, so that seems to be fine


robby
2021-8-2 15:32:05

when a module is loaded, the value of current-namespace is consulted and, if the module has already been loaded, then you’ll get that module that was already loaded. The main drracket namespace is the one you want active when drracket/tool-lib is required.


robby
2021-8-2 15:32:20

So that way you’ll get the existing drracket instead of starting a new one.


laurent.orseau
2021-8-2 15:34:06

Actually you’re right, a new namespace is created to obtain the procedures from the script, and then the procedure is called within the drracket’s namespace, so indeed the require drracket/tool-lib is different


robby
2021-8-2 15:35:17

It might make sense to share the drracket/tool-lib library with that new namespace that’s used to load the script. I’m not sure, tho. Depends what else is going on.


laurent.orseau
2021-8-2 15:36:07

How do you share with dynamic-require?


robby
2021-8-2 15:36:24

The sharing works with the namespace.


robby
2021-8-2 15:36:37

Not the the particular require form you’re using.


robby
2021-8-2 15:37:01

So the value of current-namespace will be some namespace.


laurent.orseau
2021-8-2 15:37:02

I see


laurent.orseau
2021-8-2 15:37:18

with namespace-attach-module?


robby
2021-8-2 15:37:20

That’s the one that’s consulted, regardless if you’re doing dynamic-require or whateve else it might be.


robby
2021-8-2 15:37:35

Right, namespace-attach-module is how you share modules between two namespaces.


robby
2021-8-2 15:37:45

Note that it shares everything that is depended on.


robby
2021-8-2 15:38:01

In this case, that means anything that drracket/tool-lib depends on will also be shared.


robby
2021-8-2 15:38:06

(which is a lot of stuff)


laurent.orseau
2021-8-2 15:41:07

That works!!


laurent.orseau
2021-8-2 15:41:17

Thanks a bunch robby!


robby
2021-8-2 15:41:17

:slightly_smiling_face:


laurent.orseau
2021-8-2 15:41:47

Wonderful, that should make quickscript much more capable now :slightly_smiling_face:


robby
2021-8-2 15:41:58

sweet!


laurent.orseau
2021-8-2 15:45:31

all the tests pass, so that’s a good start


laurent.orseau
2021-8-2 15:45:44

Can you think of something that may go horribly wrong due to sharing?


laurent.orseau
2021-8-2 16:03:22

> override < method-not-found >



laurent.orseau
2021-8-2 16:03:27

weird


sorawee
2021-8-2 16:10:50

I thought I had all of them in https://github.com/racket/gui/issues/185


sorawee
2021-8-2 16:12:45

https://github.com/racket/drracket/commit/5d6b658d048afeace4defc090df53ae80da1f53a in particular should have fixed the problem with set-filename


robby
2021-8-3 00:52:39

One thing to make sure is that all of the evaluation is happening on the eventspace handler thread of drracket; lots can go wrong if that’s not the case.