cris2000.espinoza677
2020-11-22 13:53:07

hello i have this (define-syntax (on-delete stx) (syntax-parse stx [m:id (raise-syntax-error 'on-delete "bad syntax, use like begin" stx #'m)] [(_ x ...) #:with name (format-id stx "on-delete") #:with (arg ...) (map (lambda (k) (format-id stx "~a" k)) '(entry)) #'(begin (define (name arg ...) x ...) (provide name))])) how do i make it throw a better error if i write something like (define (on-delete) (void))


soegaard2
2020-11-22 13:54:43

Which error do you get now?


soegaard2
2020-11-22 13:56:15

(define (on-delete) (void)) Looks like perfectly fine definition. Do you even get an error now?


cris2000.espinoza677
2020-11-22 13:57:45

wait… nevermind, im actually really stupid


cris2000.espinoza677
2020-11-22 14:42:36

what was the correct way to escape tiple-dots in macros that generate macros? i believed it to be ... ... but it wasn’t, i think this a common question, but i can’t seem to know what terms to use for google to throw me an answer, so i guess #,'... could work?


soegaard2
2020-11-22 14:43:47

(... ...) will work.

I sometimes do: (with-syntax ([ooo #'(... ...)]) (syntax/loc stx yada yada ooo more yada yada))


cris2000.espinoza677
2020-11-22 14:53:45

oh i see thank you!


sorawee
2020-11-22 15:32:08

Since you use syntax-parse, there’s no need to use with-syntax. You can just add #:with ooo (quote-syntax ...).


sorawee
2020-11-22 15:45:12

But what are you trying to do? I don’t think (define (on-delete) (void)) is gonna work since define is expanded first, so on-delete wouldn’t be expanded at all.


cris2000.espinoza677
2020-11-22 16:58:20

nono, they were different issues, first was me not paying attention to what i was doing, second came up when automating something related to the first, and yes i am using #:with but thank you for asking :)


phanthero
2020-11-22 17:34:53

thank you!!


phanthero
2020-11-22 17:34:58

thank you!!


kokou.afidegnon
2020-11-22 18:01:05

can you please clarify for me: does it means an https://docs.racket-lang.org/gui/editor-canvas_.html\|editor-canvas% handle objects that are i.e vectors, images etc.. and  https://docs.racket-lang.org/gui/editor-snip_.html\|editor-snip% handle text editor ?


cris2000.espinoza677
2020-11-22 18:35:23

editor-canvas% is a canvas<%> (a subwindow/control) that shows an editor<%>

editor-snip% is a snip% (an object% with special functionality to be used inside an editor<%>) that contains an editor<%>

editor<%>: the ones provided by racket/gui are pasteboard% and text%


cris2000.espinoza677
2020-11-22 18:37:23

text% provides functionality for text edition, pasteboard% is more for vectors and the such.


kokou.afidegnon
2020-11-22 18:37:50

i have been trying hard to have a mental picture of the whole concept


cris2000.espinoza677
2020-11-22 18:40:11

i see, is not easy to use editor&lt;%&gt; , you might want to check <https://alex-hhh.github.io/tags/racket.html|Alex Harsányi posts about racket> that include some tutorials about using pasteboard% , you might also want to read the <https://docs.racket-lang.org/framework/index.html|framework module> though that is more sophisticated and it depends on what you want to do.


kokou.afidegnon
2020-11-22 18:40:40

i have been reading his posts too


kokou.afidegnon
2020-11-22 18:44:25

wel, in the nutshell, i’m trying to build a wireframe editor, i have started my hand with a rectangle vector, i want to be able to either create a new rectangle or create an inner rectangle, which in turn will generate a code/dom node


kokou.afidegnon
2020-11-22 18:46:46

but i’m wondering where to start from and what are the appropriate modules to use


cris2000.espinoza677
2020-11-22 18:50:44

ah i see, well you got me, that seems a little hard to do efficiently. from what i get from the chess tutorial by alex, those kind of interactions are done at the editor level/pasteboard i believe?

you overwrite the mouse event handlers, when clicking check if a bounding box of a underlying rectangle is colliding with your new rectangle, and have a children list in each rectangle-snip% , i think you could just use racket/gui


kokou.afidegnon
2020-11-22 18:52:40

this is what i have done so far and i’m stuck


cris2000.espinoza677
2020-11-22 19:01:31

huh i see, but how does this tie to your questions? mainly, what are the snip% classes to be read/of interest. also what is the setup for the editor-canvas% ?


kokou.afidegnon
2020-11-22 19:03:29

well, i tried following some examples where i have faint understanding on some of the concept,


kokou.afidegnon
2020-11-22 19:03:36

no, wait that’ snot the code


kokou.afidegnon
2020-11-22 19:03:40

hold a sec


kokou.afidegnon
2020-11-22 19:04:28

here is the appropriate code,


kokou.afidegnon
2020-11-22 19:04:33

#lang racket (require racket/gui racket/draw pict) (define board (new pasteboard%)) (define toplevel (new frame% [label "My board"] [width 500] [height 500])) (define canvas (new editor-canvas% [parent toplevel] [editor board])) (send toplevel show #t) (define my-snip-class (new (class snip-class% (super-new) (send this set-classname "my-snip")))) (send (get-the-snip-class-list) add my-snip-class) (define rectangle-snip% (class snip% (init-field w h) (super-new) (send this set-snipclass my-snip-class) (define/override (get-extent dc x y width height . other) (when width (set-box! width w)) (when height (set-box! height h))) (define/override (draw dc x y . other) (draw-pict (rectangle w h) dc x y)))) (send board insert (new rectangle-snip% [w 30] [h 80]) 100 300)


kokou.afidegnon
2020-11-22 19:21:35

I have come accrosss handles-all-mouse-events and on-event but how do i coordinate with them? I needed to click on the rectangle object to generate a new rectangle


cris2000.espinoza677
2020-11-22 19:22:17

wrote before your last comment: well for starters i am going to assume you want to create more rectangles with left click, subclass pasteboard% and override https://docs.racket-lang.org/gui/pasteboard_.html#%28meth._%28%28%28lib._mred%2Fmain..rkt%29._pasteboard~25%29._on-default-event%29%29\|on-default-event which receives a https://docs.racket-lang.org/gui/mouse-event_.html\|mouse-event%


kokou.afidegnon
2020-11-22 19:24:16

ok, let’s assume, a key-combination instead


kokou.afidegnon
2020-11-22 19:25:14

ok, i’m reading on on-default event, i think mouse event is ok,


cris2000.espinoza677
2020-11-22 19:25:39

i have not used it, but for that i think that keymap% is the way? if you need a combination of mouse + keyboard


kokou.afidegnon
2020-11-22 19:26:26

ok


kokou.afidegnon
2020-11-22 19:31:18

so, in the nutshell (define board (new pasteboard%) (super-new) (new mouse-event% [event-type 'enter ] [[middle-down #t ]] ) ) is it correct ?


cris2000.espinoza677
2020-11-22 19:38:24

why the double brackets?


kokou.afidegnon
2020-11-22 19:39:31

i think there is a typo somehwhere


cris2000.espinoza677
2020-11-22 19:39:45

also, i suggest reading the <https://docs.racket-lang.org/guide/classes.html|Classes and Objects in the Racket Guide> . to subclass you use the class* form


cris2000.espinoza677
2020-11-22 19:40:32

also you don’t create mouse-event% manually, they are handed to you through the handlers like on-default-event


kokou.afidegnon
2020-11-22 19:41:04

can you please post an example ?


kokou.afidegnon
2020-11-22 19:42:03

i think there must be a function that will create a new rectangle snip too


cris2000.espinoza677
2020-11-22 19:42:34

(class* pasteboard% () (init) (super-new) (define/override (on-default-event evt) (do-something evt)))


cris2000.espinoza677
2020-11-22 19:42:45

yeah that would be handy


kokou.afidegnon
2020-11-22 19:43:29

what’s the difference between class and class* ?


cris2000.espinoza677
2020-11-22 19:44:39

class just omits the part where you put the interfaces, so you dont need to (class* object% () (super-new)) see those empty brackets, you dont have to put them with class


kokou.afidegnon
2020-11-22 19:46:17

this is much simpler :slightly_smiling_face:


kokou.afidegnon
2020-11-22 19:50:18

from the above code, (do-something evt) will be called to generate a new snip, right ?


kokou.afidegnon
2020-11-22 19:53:18

I’ve added the new class but the rectangle is not drawn. how do i configure the event ?

#lang racket (require racket/gui racket/draw pict) (class* pasteboard% () (init) (super-new) (define/override (on-default-event evt) (new-rect evt))) (define board (new pasteboard%)) (define toplevel (new frame% [label "My board"] [width 500] [height 500])) (define canvas (new editor-canvas% [parent toplevel] [editor board])) (send toplevel show #t) (define my-snip-class (new (class snip-class% (super-new) (send this set-classname "my-snip")))) (send (get-the-snip-class-list) add my-snip-class) (define rectangle-snip% (class snip% (init-field w h) (super-new) (send this set-snipclass my-snip-class) (define/override (get-extent dc x y width height . other) (when width (set-box! width w)) (when height (set-box! height h))) (define/override (draw dc x y . other) (draw-pict (rectangle w h) dc x y)))) (define (new-rect) (send board insert (new rectangle-snip% [w 30] [h 80]) 100 300))


cris2000.espinoza677
2020-11-22 19:55:44

ok so, class forms return classes value, so the pattern is (define my-pasteboard% (class pasteboard% ...)) i recommend reading the racket guide


cris2000.espinoza677
2020-11-22 19:56:22

(define board (new pasteboard%)) then would be (define board (new my-pasteboard%))


cris2000.espinoza677
2020-11-22 19:58:42

how do i find all modules from the base package? i keep missing things like the data module, etc.


soegaard2
2020-11-22 20:11:13

@cris2000.espinoza677 You can see a list here: https://github.com/racket/racket/tree/master/racket/collects


cris2000.espinoza677
2020-11-22 20:11:37

oh thank you!


soegaard2
2020-11-22 20:11:40

(if I guessed correctly about the meaning of “base package”)


cris2000.espinoza677
2020-11-22 20:12:22

when you open a module doc, you can see the (require &lt;name&gt;) and to the left package: base


cris2000.espinoza677
2020-11-22 20:12:29

so i guess yes :smile:


kokou.afidegnon
2020-11-22 20:14:01

what about the events?


cris2000.espinoza677
2020-11-22 20:16:08

on-default-event accepts one argument that is of type mouse-event% from mouse-event% you can use things like (send evt get-x) to get x, etc. all methods are in the mouse-event% documentation


kokou.afidegnon
2020-11-22 20:17:23

i have been reading about them but i’m always confused, i need some guidance about them. I’m still a novice in racket


cris2000.espinoza677
2020-11-22 20:17:48

are you a novice with programming too or just racket?


kokou.afidegnon
2020-11-22 20:18:58

just racket, I know now to instantiate class, override class etc.. in other languages, i.e python, C++ but i’m still struggling with racket


cris2000.espinoza677
2020-11-22 20:29:16

(i suggest reading htdp book or the racket guide, although i just read beautiful racket instead of that)

ok so the thing goes, racket most of the time treats things as first class features that is one of the great things you can get from a lisp, most stuff can be easily implemented as a first class citizen in the language.

• <https://docs.racket-lang.org/racket-cheat/index.html|racket cheatsheet> the class system in racket i admit is kind of weird, again if you read the racket guide entry about classes and objects many of the doubts you have may disappear, also the racket reference has the nitty gritty details.

to subclass just bind the value of the class /class* form to an identifier with letor define . eg. (define my-object% (class object% (super-new)))

to call a method, also known as sending a message (i believe this comes from smalltalk) use the send form.

for overriding, augmenting, etc methods in a subclass read https://docs.racket-lang.org/reference/createclass.html#%28part._clmethoddefs%29\|this because honestly i still dont quite understand it completely.


kokou.afidegnon
2020-11-22 20:36:59

well, i’m having some slight notions about classes in racket, but, it’s easier in Qt to implement GUI as well, as graphics, but racket, i guess due to its lipsy nature, and there are lack of examples to follow which left to wonder the modules responsibilities and when to use them


cris2000.espinoza677
2020-11-22 20:39:02

it’s less complex than Qt, i find the window classes to be easier and more straightforward, but again the editor&lt;%&gt; classes are not that easy, you have to do more lower level stuff…

*lower level in comparison to what other frameworks let you do.


kokou.afidegnon
2020-11-22 20:41:28

my confusions lies within, editor&lt;%&gt;, pasteboards, snips


cris2000.espinoza677
2020-11-22 20:44:53

editor&lt;%&gt; is an interface implemented by pasteboard% , in which you can insert snip% by using the insert method.

snips are just an object that represent a thing inside editor&lt;%&gt; so it saves its bounding box, how it’s drawn, and maybe some other data, but their positions are controlled by the editor&lt;%&gt; object


cris2000.espinoza677
2020-11-22 20:49:32

i really think you should complete the chessboard tutorial by alex if you havent already


kokou.afidegnon
2020-11-22 20:52:11

i’m still reading it


kokou.afidegnon
2020-11-22 20:55:40

i hope i will pick up soon, there is a project i need to implement urgently, I have build part of it already in elisp, but I need to integrate the GUI aspect that’s why i needed to use Racket,


cris2000.espinoza677
2020-11-22 20:56:38

i wish you good luck


kokou.afidegnon
2020-11-22 20:56:45

thanks,


kokou.afidegnon
2020-11-22 20:59:03

a quick one, how do i keep record of the generated rectangle snips? I need to duplicate and build some additional properties/labels around them. i.e the, the xml properties they will hold


cris2000.espinoza677
2020-11-22 21:01:23

you could use mutation and a list inside of your class definition (define snip-list '()) (define (register-snip snip) (set! snip-list (cons snip snip-list))) for the properties see init init-field


cris2000.espinoza677
2020-11-22 21:20:33

very buggy but like is it something like this that you want?


cris2000.espinoza677
2020-11-22 21:21:21

kokou.afidegnon
2020-11-22 21:21:50

yes, this one step,


kokou.afidegnon
2020-11-22 21:22:06

but i will need to refine it though,


kokou.afidegnon
2020-11-22 21:22:12

but it’s a good start



kokou.afidegnon
2020-11-22 21:25:08

thanks, however i have little questions, even though i’ve read them over and over, can you please clarify the use of box and set-box ?


cris2000.espinoza677
2020-11-22 21:49:46

my computer died when i was about to answer: that is really a quirk of the library, i suppose it’s not have so many values returned as part of the function. box is like a 1 item list in python, it just literally a data structure (mutable in this case) that contains one element.


kokou.afidegnon
2020-11-22 21:50:48

ok, noted,


kokou.afidegnon
2020-11-22 21:51:11

playing with the code you’ve sent me, you’ve helped a lot,


cris2000.espinoza677
2020-11-22 21:51:56

you’re welcome, it is quite daunting when you have no examples…


kokou.afidegnon
2020-11-22 22:14:06

will you be around tomorrow?


cris2000.espinoza677
2020-11-22 22:14:47

gah i promise nothing, im quite busy this week… but folks here might be glad to help


kokou.afidegnon
2020-11-22 22:15:03

ok,


kokou.afidegnon
2020-11-22 22:15:47

there is a little bug here, when i create a new rectangle and drag it, it duplicates


kokou.afidegnon
2020-11-22 22:17:00

i think a new rectangle gets created based on the previous location info


cris2000.espinoza677
2020-11-22 22:17:47

yeah, the thing with my overriding of on-default-event is that it calls the super method without checking cases where i dont want certain behavior to occur, you can see in the gif that if you drag a rectangle it will create another underneath, that is because my code only checks if is the first left click and the release.



kokou.afidegnon
2020-11-22 22:19:11

ok


kokou.afidegnon
2020-11-22 22:19:55

could we constrain that event on mouse-click alone ? i think event seems to be global


kokou.afidegnon
2020-11-22 22:20:12

we might need to specify on-right-click or something


cris2000.espinoza677
2020-11-22 22:25:09

you could do that


kokou.afidegnon
2020-11-23 07:27:03