How can you transmit answers from one window to another?
Last updated at 4:28 pm UTC on 14 January 2006
Question: How can you transmit answers from one window to another?
Answer: From: How to save a part bin : Tuesday, January 06, 2004 2:13 AM
The situation: When a query window is executed, another window opens and displays the results the first window generates. How can the two windows transmit the arguments?
You do this:
In the first window, you collect the results.
Then you create a new object, and pass it the results to display.
You tell the newly created object to open a window.
It then displays those results.
Question: [First answer didn’t help...] I created two classes to represent the two windows: Query and Display. In the window "Query", there is a button "queryStart", and when it is pressed, another window "Display" opens.
(Display open: aCollection)?.
In Display, a selector "display:aCollection" is used to display the results. however, a selector "createWindow" is used to construct the window frame. So the problem is that the two selectors can not be used together.
> Please tell me how to transmit the arguments as the window is created.
Answer: I guess I don't understand what you're doing. Are you using Squeak? Are you using Morphic? Are you using the Pluggable widgets?
Do the query and display things need to be windows? What's
MorphicGUIDemo.cs.gz is a quick demo showing how one window can open another. I am not doing this here just to show you how one window can open another. You probably don't want to have windows be their own models unless you don't have any more than one window displaying a particular thing at a time. Usually, you have a separate model class; changes to the model generate #changed messages: #someAspect' (where #someAspect is different for each part of the model.) These messages are listened to by the pluggable widgets. Here, however, the QueryWindow is its own model. This demo is also listed below, in case you would perfer to enter it yourself.
SystemWindow subclass: #QueryWindow
instanceVariableNames: 'text1 text2'
"Create a new window (in this case, the same class) and open it."
((QueryWindow text1: text1 text2: text2)
extent: self extent) openInWorld
^Color blue muchLighter
"I am my own model. Except for very simple situations this is not
usually the case and there is a separate model."
^self defaultBackgroundColor darker darker
text1 := anObject.
text2 := anObject.
setLabel: 'Query Window';
addMorph: (PluggableTextMorph on: self text: #text1 accept: =#text1:) frame: (0@0 corner: firstname.lastname@example.org);
addMorph: (PluggableTextMorph on: self text: #text2 accept: =#text2:) frame: (email@example.com corner: firstname.lastname@example.org);
addMorph: ((SimpleButtonMorph newWithLabel: 'Push Me') target: =self; actionSelector: #buttonPushed)
frame: (email@example.com corner: firstname.lastname@example.org)
text1: s1 text2: s2
"Initialize a new instance with the given texts"
self text1: s1.
self text2: s2.
QueryWindow class methods
^(self text1: 'initial text1' text2: 'initial text2')
text1: stuff1 text2: stuff2
text1: stuff1 text2: stuff2;