Event handling challenges

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Event handling challenges

Trygve
The figures were missing when this message reached me. I resend itwith the figures attached.
-------------------------------------

Hi Squeakers,
My SRE context browser is a tool for drawing a snapshot of a selected structure of interlinked objects where each object is shown as a rectangular symbol. This diagram shows an object with its class and superclass objects:


SRE has worked for years, last in 'Squeak3.10.2'. In 'Squeak5.3', the same program went into an infinite loop. It transpired that myClass>>processEvent: anEvent using: defaultDispatcher had become a new thing called an event filter and needed to return an Event or a Symbol. That problem fixed; the program still misbehaves. The problem seems to be with event handling. I have never been into that corner of Smalltalk but have read some Squeak documentation. I have not found any concrete code.  I realize that I will never understand Squeak's event handling by reading code, code comments, and even the documentation I have found. There has apparently been a significant increase in complexity lately. An example: In 3,10,2, class MorphicEventDispatcher has 4 methods. In 5,3, it has 16.

Here's the beginning of my challenges with 5.3: I find two anomalies in a diagram with just one symbol:
  1.     When I move some other window to a position within the diagram, the diagram grabs it and makes it a submorph of itself.  In 3.10.2, the diagram ignores it.
  2.     The cursor becomes a text cursor when I move the mouse across a symbol.
I have no explanation for either anomaly. My SRE code is a kludge and is almost unreadable. It is hard to formulate a question without the whole code as a background, and I have tried to reproduce them in a simple example. I managed to reproduce the first, but not the second anomaly. In a workspace, copy, select,  and do it. The XXX-symbol becomes attached to the cursor, and I place it in the blue background.
joe := PasteUpMorph new color: Color lightBlue.
joe bounds: (500@400 corner: 800@600).
joe dropEnabled: true.
joe openInWorld.
circle := CircleMorph new.
joe addMorphCentered: circle.
tex := TextMorphXX new
        contents: 'XXX';
        borderWidth: 1;
        color: Color red;
        extent: 100@100.
tex openInHand.

There is only one  method in class TextMorphXX (sco TextMorph):
processEvent: anEvent using: defaultDispatcher
    ^#rejected



I move some background window,  actually a collapsed Monticello thing, to Joe's position, Joe grabs it and makes it into a submorph. Any hints about how to proceed will be greatly appreciated.
--Trygve






--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 468 58 625




1: SRE Context Browser [3072DemoEllipseSRE Step mechanism.1.gif (11K) Download Attachment
2: SRE anomaly example.png (56K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Event handling challenges

K K Subbu
On 15/06/20 6:55 pm, Trygve Reenskaug wrote:

>     joe := PasteUpMorph new color: Color lightBlue.
>     joe bounds: (500@400 corner: 800@600).
>     joe dropEnabled: true.
...
> I move some background window,  actually a collapsed Monticello thing,
> to Joe's position, Joe grabs it and makes it into a submorph. Any hints
> about how to proceed will be greatly appreciated.

PasteUpMorph is designed to grab morphs. It overrides mouseDown: method
in Morph to try and grab whatever morph is dropped into it (unless it is
in PartsBin).

You could use RectangleMorph or BorderedMorph to avoid grabbing.

HTH .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: Event handling challenges

Trygve
In reply to this post by Trygve

Hi,
I'm grateful for your many responses to my cry for help. None of your suggestions gave a solution, but they gave useful entry points into very complex material. I made a small script that creates a light blue playfield, an instance of PasteUpMorphXX, a subclass of PasteUpMorph. It has 2 morphs inside it: a green CircleMorph and XXX, a TextMorphXX that is positioned by the user:

 

 

The example illustrates 2 problems:

 

1.    The playfield grabs the Workspace when it is positioned within it, but the playfield should have ignored it.
The problem requires that I must distinguish between friend and foe. I do not want to create subclasses of all friends, and have chosen to tag the friends instead:
    friend setProperty: #homeCanvas toValue: playfield   

       

        PasteUpMorphXX>>wantsDroppedMorph: aMorph event: evt
          ^(aMorph valueOfProperty: #homeCanvas ifAbsent: [nil]) == self

    PasteUpMorphXX>>rejectDropEvent: anEvent

          self dpsTrace: anEvent levels: 10
“see note  below”.
          ((self valueOfProperty: #homeCanvas ifAbsent: [nil]) == self)
                    ifTrue: [anEvent wasHandled: true].

2.    The TextMorphXX grabs the cursor, making it into a Text cursor.
StringMorph has an inst.var. 'hasFocus' that takes care of such problems.
This inst.var. is missing in TextMorph and this method seems to solve my problem
    TextMorphXX>>processEvent: anEvent using: defaultDispatcher
          ^#rejected

That's all. The small script works as specified, and it is time to revert to porting SRE. This is a prerequisite for porting Loke, a personal computer for laypeople living in the connected society. Their computer shall be equally available on their several devices. A proof-of-concept Loke exists in 'Squeak3.10.2' as a non-intrusive program. I want to make it generally available in a modern Squeak for people to play with.


Thanks for your help

--Trygve


Note: When dpsTrace:levels: was executed, the stack depth was 47. (I have attached it for your enjoyment). I thought I understood the principle of event handling: The Hand picks up a sensor event and passes it to the top-level morph. From there, it is passed down the submorphs until it is handled. In this case, the path is: World-aPasteUpMorphXX-aTextMorhXXX. Yet, the Morphic event handling manages to create a stack with a depth of 47 before it asks if it may drop a morph. Not easy to grok, IMO.

This open-access article describes Loke
https://doi.org/10.1007/s10270-019-00768-3

The SRE User Manual
http://folk.uio.no/trygver/2005/babyuml/tweakComponents.pdf




On 2020.06.15 15:25, Trygve Reenskaug wrote:
The figures were missing when this message reached me. I resend itwith the figures attached.
-------------------------------------

Hi Squeakers,
My SRE context browser is a tool for drawing a snapshot of a selected structure of interlinked objects where each object is shown as a rectangular symbol. This diagram shows an object with its class and superclass objects:


SRE has worked for years, last in 'Squeak3.10.2'. In 'Squeak5.3', the same program went into an infinite loop. It transpired that myClass>>processEvent: anEvent using: defaultDispatcher had become a new thing called an event filter and needed to return an Event or a Symbol. That problem fixed; the program still misbehaves. The problem seems to be with event handling. I have never been into that corner of Smalltalk but have read some Squeak documentation. I have not found any concrete code.  I realize that I will never understand Squeak's event handling by reading code, code comments, and even the documentation I have found. There has apparently been a significant increase in complexity lately. An example: In 3,10,2, class MorphicEventDispatcher has 4 methods. In 5,3, it has 16.

Here's the beginning of my challenges with 5.3: I find two anomalies in a diagram with just one symbol:
  1.     When I move some other window to a position within the diagram, the diagram grabs it and makes it a submorph of itself.  In 3.10.2, the diagram ignores it.
  2.     The cursor becomes a text cursor when I move the mouse across a symbol.
I have no explanation for either anomaly. My SRE code is a kludge and is almost unreadable. It is hard to formulate a question without the whole code as a background, and I have tried to reproduce them in a simple example. I managed to reproduce the first, but not the second anomaly. In a workspace, copy, select,  and do it. The XXX-symbol becomes attached to the cursor, and I place it in the blue background.
joe := PasteUpMorph new color: Color lightBlue.
joe bounds: (500@400 corner: 800@600).
joe dropEnabled: true.
joe openInWorld.
circle := CircleMorph new.
joe addMorphCentered: circle.
tex := TextMorphXX new
        contents: 'XXX';
        borderWidth: 1;
        color: Color red;
        extent: 100@100.
tex openInHand.

There is only one  method in class TextMorphXX (sco TextMorph):
processEvent: anEvent using: defaultDispatcher
    ^#rejected



I move some background window,  actually a collapsed Monticello thing, to Joe's position, Joe grabs it and makes it into a submorph. Any hints about how to proceed will be greatly appreciated.
--Trygve

--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
[hidden email]
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 468 58 625




stack-1.docx (21K) Download Attachment
000-EventExperiments.st (3K) Download Attachment