Re: [racket-users] Re: mouse selection on a text-field%

2016-04-09 Thread Robby Findler
On Sat, Apr 9, 2016 at 11:40 AM, FERREC Romain  wrote:
> Le 09/04/2016 15:44, Robby Findler a écrit :
>>
>> You could write a little loop to keep the functions in the keymap and
>> remove all the keybindings and then add back in the bindings you
>> wanted. That way you could avoid duplicating code?
>
>
> Ah yes it is possible, I have not seen some functions in the documentation..
> but honestly this can be improved, i'll try to work on it when I'll have
> some times.
>
> For now I have made this little function :
>
> (define (generate-keymap funcsList)
>   (define keymap (keymap:get-global))
>   (send keymap add-function "void" void)
>   (for ([(key value) (in-hash (send keymap get-map-function-table))])
> (unless (list? (member value funcsList))
>(send keymap map-function (symbol->string key) "void")))
>   keymap)
>
> It returns a keymap. "funcsList" contains list of function names from
> keymap:get-global, and keep the keybindings. Of course, it would have been
> better if we could remove the keybinding+function directly from the keymap.

Well, removing them could affect other code that uses them, so making
a copy is best.

Robby

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: mouse selection on a text-field%

2016-04-09 Thread FERREC Romain

Le 09/04/2016 15:44, Robby Findler a écrit :

You could write a little loop to keep the functions in the keymap and
remove all the keybindings and then add back in the bindings you
wanted. That way you could avoid duplicating code?


Ah yes it is possible, I have not seen some functions in the 
documentation.. but honestly this can be improved, i'll try to work on 
it when I'll have some times.


For now I have made this little function :

(define (generate-keymap funcsList)
  (define keymap (keymap:get-global))
  (send keymap add-function "void" void)
  (for ([(key value) (in-hash (send keymap get-map-function-table))])
(unless (list? (member value funcsList))
   (send keymap map-function (symbol->string key) "void")))
  keymap)

It returns a keymap. "funcsList" contains list of function names from 
keymap:get-global, and keep the keybindings. Of course, it would have 
been better if we could remove the keybinding+function directly from the 
keymap.


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: mouse selection on a text-field%

2016-04-09 Thread Robby Findler
You could write a little loop to keep the functions in the keymap and
remove all the keybindings and then add back in the bindings you
wanted. That way you could avoid duplicating code?

Robby


On Sat, Apr 9, 2016 at 8:32 AM, mazert  wrote:
> Le 09/04/2016 15:15, Robby Findler a écrit :
>>
>> Does this code help?
>
>
>
> It works, but the problem is there is no ways to choose which funcs I want
> to include in a keymap, I must include them all :, and I don't want emacs or
> open/save file keybindings...
>
> I finally took some codes from the link i've posted, to only add
> one-word-selection. I think these keymaps should be included by default in
> text% objects (framework:get-editor and mouse selections).
>
> However my problem is now fixed, thanks you and Matthew Flatt.
>
>
> ---
>
> (define textField%
>   (class text-field%
> (super-new)
> (define keymap (keymap:get-editor))
>
> ;; Useful mouse functions
> (define (region-click edit event f)
>   (when (and (send event button-down?)
>  (is-a? edit text%))
> (let ([x-box (box (send event get-x))]
>   [y-box (box (send event get-y))]
>   [eol-box (box #f)])
>   (send edit global-to-local x-box y-box)
>   (let ([click-pos (send edit find-position
>  (unbox x-box)
>  (unbox y-box)
>  eol-box)]
> [start-pos (send edit get-start-position)]
> [end-pos (send edit get-end-position)])
> (let ([eol (unbox eol-box)])
>   (if (< start-pos click-pos)
>   (f click-pos eol start-pos click-pos)
>   (f click-pos eol click-pos end-pos)))
> (define (select-click-word edit event)
>   (region-click edit event
> (lambda (click eol start end)
>   (let ([start-box (box click)]
> [end-box (box click)])
> (send edit find-wordbreak
>   start-box
>   end-box
>   'selection)
> (send edit set-position
>   (unbox start-box)
>   (unbox end-box))
>
> (define (select-all edit event)
>   (send edit select-all))
> (keymap:setup-editor keymap)
>
> ;; Adding functions to keymap object
> (send keymap add-function "select-click-word" select-click-word)
> (send keymap map-function "leftbuttondouble" "select-click-word")
> (send keymap add-function "select-all" select-all)
> (send keymap map-function "leftbuttontriple" "select-all")
>
>
> (send (send this get-editor) set-keymap keymap)))
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: mouse selection on a text-field%

2016-04-09 Thread mazert

Le 09/04/2016 15:15, Robby Findler a écrit :

Does this code help?



It works, but the problem is there is no ways to choose which funcs I 
want to include in a keymap, I must include them all :, and I don't want 
emacs or open/save file keybindings...


I finally took some codes from the link i've posted, to only add 
one-word-selection. I think these keymaps should be included by default 
in text% objects (framework:get-editor and mouse selections).


However my problem is now fixed, thanks you and Matthew Flatt.


---

(define textField%
  (class text-field%
(super-new)
(define keymap (keymap:get-editor))

;; Useful mouse functions
(define (region-click edit event f)
  (when (and (send event button-down?)
 (is-a? edit text%))
(let ([x-box (box (send event get-x))]
  [y-box (box (send event get-y))]
  [eol-box (box #f)])
  (send edit global-to-local x-box y-box)
  (let ([click-pos (send edit find-position
 (unbox x-box)
 (unbox y-box)
 eol-box)]
[start-pos (send edit get-start-position)]
[end-pos (send edit get-end-position)])
(let ([eol (unbox eol-box)])
  (if (< start-pos click-pos)
  (f click-pos eol start-pos click-pos)
  (f click-pos eol click-pos end-pos)))
(define (select-click-word edit event)
  (region-click edit event
(lambda (click eol start end)
  (let ([start-box (box click)]
[end-box (box click)])
(send edit find-wordbreak
  start-box
  end-box
  'selection)
(send edit set-position
  (unbox start-box)
  (unbox end-box))

(define (select-all edit event)
  (send edit select-all))
(keymap:setup-editor keymap)

;; Adding functions to keymap object
(send keymap add-function "select-click-word" select-click-word)
(send keymap map-function "leftbuttondouble" "select-click-word")
(send keymap add-function "select-all" select-all)
(send keymap map-function "leftbuttontriple" "select-all")

(send (send this get-editor) set-keymap keymap)))



--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: mouse selection on a text-field%

2016-04-09 Thread Robby Findler
Does this code help?

#lang racket/gui
(require framework)

(define f (new frame%
   [label "Select"]
   [width 300]))

(define t (new text-field%
   [parent f]
   [label #f]))

(define k (send (send t get-editor) get-keymap))
(send k chain-to-keymap (keymap:get-global) #t)

(send f show #t)




On Sat, Apr 9, 2016 at 6:04 AM, mazert  wrote:
> Le 08/04/2016 20:27, Matthew Flatt a écrit :
>> At Fri, 8 Apr 2016 18:50:09 +0200, mazert wrote:
>>> I try to find an easy way to add the general mouse selection system
>>> (double click on a word will select it for example) on a text-field gui
>>> component.
>>
>> In the case of double-click to select a word, you could implement it
>> via the keymap in a text-field's editor:
>
> Hmm, your solution do not select a word but the entire text-field% content
> (equivalent of triple left click).
>
> I found something called "select-click-word" on the framework
> http://docs.racket-lang.org/framework/Keymap.html#%28def._%28%28lib._framework%2Fmain..rkt%29._keymap~3asetup-global%29%29
> but I can't access it directly without setting all keymaps of
> keymap:get-global.
>
> By looking the procedure on the source code of this framework, I found some
> interesting methods of text% who can be useful (find-wordbreaks,
> set-position..), but after some experiments i cant make it working.. :p :
> https://searchcode.com/codesearch/view/7268171/
>
>
>> For more complex behavior, you may need to use an `editor-canvas%` plus
>> `text%`. A `text-field%` widget combines an `editor-canvas%` with a
>> `text%` for you, but it doesn't give you an opportunity to subclass
>> `text%`, which may be necessary for some tasks.
>
> I did it by creating a new class heriting of text-field%, and I work
> directly on the edit%, but you are right and it is surely a proper way to do
> that.
>
> ; Keybindings for basic edition
> (define textField%
> (class text-field%
> (super-new)
> (define keymap (keymap:get-editor))
> (send (send this get-editor) set-keymap keymap)))
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: mouse selection on a text-field%

2016-04-09 Thread mazert

Le 08/04/2016 20:27, Matthew Flatt a écrit :
> At Fri, 8 Apr 2016 18:50:09 +0200, mazert wrote:
>> I try to find an easy way to add the general mouse selection system
>> (double click on a word will select it for example) on a text-field gui
>> component.
>
> In the case of double-click to select a word, you could implement it
> via the keymap in a text-field's editor:

Hmm, your solution do not select a word but the entire text-field% 
content (equivalent of triple left click).


I found something called "select-click-word" on the framework
http://docs.racket-lang.org/framework/Keymap.html#%28def._%28%28lib._framework%2Fmain..rkt%29._keymap~3asetup-global%29%29
but I can't access it directly without setting all keymaps of 
keymap:get-global.


By looking the procedure on the source code of this framework, I found 
some interesting methods of text% who can be useful (find-wordbreaks, 
set-position..), but after some experiments i cant make it working.. :p 
: https://searchcode.com/codesearch/view/7268171/



> For more complex behavior, you may need to use an `editor-canvas%` plus
> `text%`. A `text-field%` widget combines an `editor-canvas%` with a
> `text%` for you, but it doesn't give you an opportunity to subclass
> `text%`, which may be necessary for some tasks.

I did it by creating a new class heriting of text-field%, and I work 
directly on the edit%, but you are right and it is surely a proper way 
to do that.


; Keybindings for basic edition
(define textField%
(class text-field%
(super-new)
(define keymap (keymap:get-editor))
(send (send this get-editor) set-keymap keymap)))



--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] [racket][typed] static-contracts/instantiate.rkt:64:2. car: contract violation.

2016-04-09 Thread WarGrey Gyoudmon Ju
This bug happened to appear two days ago and never disappear (both in
version 6.4.0.13 and 6.5.0.1) in my codebase, however if I copy the minimal
relative code into a fresh file, it disappears. In the original one's REPL,
it disappears too.

(define-type Card%
  (Class #:implements Darc-Card%
 [change (-> (Instance Snip%) Void)]))

(define card% : Card%
  (class darc-card% ;;; this is a pasteboard%
(super-new)
(define/public (change snip)
  (void

(define card : (Instance Darc-Card%) (make-object darc-card%)) ;;; this is
okay.
(define card : (Instance Card%) (make-object card%))  ;;; this raises the
contract error.

It is also easy to bypass as long as I do not do instantiating in module
level (as a static member of a class).

So, is it safe to just ignore the non-paired value in instantiate.rkt?
Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.