Hello
Is there anyone who have idea how to create a textinputfield in spec2/GUI in pharo and get the value from that text field. Cause i want to use LibC fuction to send the text field data to a BAT file. So need help to create a simple textfield that can get the value. I need guide line badly. Thanks for your kind Help -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html |
This code should give you a clue of how to do what you want. You can file it
in or type it in yourself. You can run it from the playground with the command - SimpleExample new openWithSpec. How it works - You need to subclass SpPresenter. You need to set up an instance method called initializePresenters to create a text input and a button. You then create aninstance method called connectPresenters to put a handler on to the button. You need a class side method called defaultSpec to layout the button and the text input That's it. Note that you have to hit enter to register any change in the text field. You will need the transcript open to see the results in this example. Hope this helps SpPresenter subclass: #SimpleExample instanceVariableNames: 'myButton myTextField' classVariableNames: '' package: 'KMP-SimpleSpecExample'! !SimpleExample methodsFor: 'as yet unclassified' stamp: 'KMP 7/28/2020 16:20'! initialize super initialize ! ! !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:31'! initializePresenters myButton := self newButton . myButton label:'Click Me'. myTextField := self newTextInput. ! ! !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:29'! connectPresenters "Put what you want to do when the button is clicked hhere" myButton whenActivatedDo: [ Transcript show: myTextField text].! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! SimpleExample class instanceVariableNames: ''! !SimpleExample class methodsFor: 'specs' stamp: 'KMP 7/28/2020 16:30'! defaultSpec ^ SpBoxLayout newVertical borderWidth: 10; spacing: 10; add: #myTextField expand: false; add: #myButton expand: false; yourself! ! -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html |
This post was updated on .
Hello KMO
i follow your step one by one and make the form but i want to run : connectPresenters myButton whenActivatedDo: [LibC system: 'a.bat', myTextField asString]. That means when i put any value in text field than press click me than that value need to send to my bat file as string. so i dont know is that ok or not. but if i write: myButton whenActivatedDo: [LibC system: 'a.bat 10']. than its work perfectly but my concern is to get the value from text field not the fixed value. SO i think i am doing in the wrong things. Please help me with this issue. Thanks a lot kmo wrote > This code should give you a clue of how to do what you want. You can file > it > in or type it in yourself. You can run it from the playground with the > command - > > SimpleExample new openWithSpec. > > How it works - You need to subclass SpPresenter. You need to set up an > instance method called initializePresenters to create a text input and a > button. You then create aninstance method called connectPresenters to put > a > handler on to the button. > > You need a class side method called defaultSpec to layout the button and > the > text input > > That's it. > > Note that you have to hit enter to register any change in the text field. > You will need the transcript open to see the results in this example. > > Hope this helps > > SpPresenter subclass: #SimpleExample > instanceVariableNames: 'myButton myTextField' > classVariableNames: '' > package: 'KMP-SimpleSpecExample'! > > !SimpleExample methodsFor: 'as yet unclassified' stamp: 'KMP 7/28/2020 > 16:20'! > initialize > super initialize ! ! > > > !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:31'! > initializePresenters > myButton := self newButton . > myButton label:'Click Me'. > myTextField := self newTextInput. > ! ! > > !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:29'! > connectPresenters > "Put what you want to do when the button is clicked hhere" > myButton whenActivatedDo: [ Transcript show: myTextField text].! ! > > "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! > > SimpleExample class > instanceVariableNames: ''! > > !SimpleExample class methodsFor: 'specs' stamp: 'KMP 7/28/2020 16:30'! > defaultSpec > > ^ SpBoxLayout newVertical > borderWidth: 10; > spacing: 10; > add: #myTextField expand: false; > add: #myButton expand: false; > yourself! ! > > > > > > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html |
Hi - you will get the most benefit by working through the problem yourself which is why folks are hesitant to “do it for you”, as you won’t learn meaningfully that way. Have you tried putting a break point in the code and using the debugger? (You can use the code “self halt.” If you can’t figure out breakpoints (but I’m sure you can find docs on the debugger). Then see what the state of things are. Step into code and see what it’s doing. You can also evaluate expressions and get results to check things (if you can’t figure that out - assign some temp variables). This is how you will learn how to help yourself, and it will make you more productive in the long run. Hope this helps, Tim > On 29 Jul 2020, at 04:44, shawon58 <[hidden email]> wrote: > > > Hello KMO > i follow your step one by one and make the form but i want to run : > > connectPresenters > myButton whenActivatedDo: [LibC system: 'a.bat', myTextField asString]. > > That means when i put any value in text field than press click me than that > value need to send to my bat file as string. so i dont know is that ok or > not. but if i write: > > myButton whenActivatedDo: [LibC system: 'a.bat 10']. > > than its work perfectly but my concern is to get the value from text field > not the fixed value. > SO i think i am doing in the wrong things. Please help me with this issue. > > Thanks a lot > kmo wrote >> This code should give you a clue of how to do what you want. You can file >> it >> in or type it in yourself. You can run it from the playground with the >> command - >> >> SimpleExample new openWithSpec. >> >> How it works - You need to subclass SpPresenter. You need to set up an >> instance method called initializePresenters to create a text input and a >> button. You then create aninstance method called connectPresenters to put >> a >> handler on to the button. >> >> You need a class side method called defaultSpec to layout the button and >> the >> text input >> >> That's it. >> >> Note that you have to hit enter to register any change in the text field. >> You will need the transcript open to see the results in this example. >> >> Hope this helps >> >> SpPresenter subclass: #SimpleExample >> instanceVariableNames: 'myButton myTextField' >> classVariableNames: '' >> package: 'KMP-SimpleSpecExample'! >> >> !SimpleExample methodsFor: 'as yet unclassified' stamp: 'KMP 7/28/2020 >> 16:20'! >> initialize >> super initialize ! ! >> >> >> !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:31'! >> initializePresenters >> myButton := self newButton . >> myButton label:'Click Me'. >> myTextField := self newTextInput. >> ! ! >> >> !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:29'! >> connectPresenters >> "Put what you want to do when the button is clicked hhere" >> myButton whenActivatedDo: [ Transcript show: myTextField text].! ! >> >> "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! >> >> SimpleExample class >> instanceVariableNames: ''! >> >> !SimpleExample class methodsFor: 'specs' stamp: 'KMP 7/28/2020 16:30'! >> defaultSpec >> >> ^ SpBoxLayout newVertical >> borderWidth: 10; >> spacing: 10; >> add: #myTextField expand: false; >> add: #myButton expand: false; >> yourself! ! >> >> >> >> >> >> -- >> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html > > > > > > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html > |
In reply to this post by shawon58
Let's see: 'a.bat 10' works but 'a.bat', myTextField asString does NOT work.
There's clearly something wrong with 'a.bat', myTextField asString - but what? As Tim says, you have to investigate. Tim has suggested a couple of ways you could investigate. Here's another - You have my code that writes the stuff typed in to myTextField to the Transcript when you click the button. Did you get it working? Did you try it out? Are you happy you understood it? The Transcript is not perhaps the best way to debug but in this case you have it readily available. Amend that code so that it writes out 'a.bat', myTextField asString to the Transcript. Do you get what you expect? If not, why is that? When you see what you are getting it should give you a good clue as to what is wrong. Keep experimenting with the code until you get precisely what you want appearing in the Transcript. Then you can go back and change the code to use LibC Hope this helps -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html |
On Wed, 29 Jul 2020 at 23:57, kmo <[hidden email]> wrote:
> > Let's see: 'a.bat 10' works but 'a.bat', myTextField asString does NOT work. > There's clearly something wrong with 'a.bat', myTextField asString - but > what? As Tim says, you have to investigate. > > Tim has suggested a couple of ways you could investigate. Here's another - > > You have my code that writes the stuff typed in to myTextField to the > Transcript when you click the button. Did you get it working? Did you try it > out? Are you happy you understood it? The Transcript is not perhaps the best > way to debug but in this case you have it readily available. > > Amend that code so that it writes out 'a.bat', myTextField asString to the > Transcript. Do you get what you expect? If not, why is that? > > When you see what you are getting it should give you a good clue as to what > is wrong. Keep experimenting with the code until you get precisely what you > want appearing in the Transcript. Then you can go back and change the code > to use LibC This is good advice, and to clarify further... If this works... myButton whenActivatedDo: [LibC system: 'a.bat 10']. and this doesn't... myButton whenActivatedDo: [LibC system: 'a.bat', myTextField asString]. and you can't see why, then you likely have an assumption about what you think is happening, that is blinding you what is actually happening, which you need to expose :) i.e. you need to know *exactly* what string is being passed in the #system: call. One way to do that is to replace "LibC system:" with "Transcript:show:" in your code. cheers -ben. myButton whenActivatedDo: [ Transcript show: myTextField text] |
In reply to this post by kmo
Hello KMO
i solve that issue but can you help me one thing. i want to add a label infront of text field. Can you tell me how to do that, in code where i need to change ? Thanks <http://forum.world.st/file/t372453/form.jpg> kmo wrote > This code should give you a clue of how to do what you want. You can file > it > in or type it in yourself. You can run it from the playground with the > command - > > SimpleExample new openWithSpec. > > How it works - You need to subclass SpPresenter. You need to set up an > instance method called initializePresenters to create a text input and a > button. You then create aninstance method called connectPresenters to put > a > handler on to the button. > > You need a class side method called defaultSpec to layout the button and > the > text input > > That's it. > > Note that you have to hit enter to register any change in the text field. > You will need the transcript open to see the results in this example. > > Hope this helps > > SpPresenter subclass: #SimpleExample > instanceVariableNames: 'myButton myTextField' > classVariableNames: '' > package: 'KMP-SimpleSpecExample'! > > !SimpleExample methodsFor: 'as yet unclassified' stamp: 'KMP 7/28/2020 > 16:20'! > initialize > super initialize ! ! > > > !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:31'! > initializePresenters > myButton := self newButton . > myButton label:'Click Me'. > myTextField := self newTextInput. > ! ! > > !SimpleExample methodsFor: 'initialization' stamp: 'KMP 7/28/2020 16:29'! > connectPresenters > "Put what you want to do when the button is clicked hhere" > myButton whenActivatedDo: [ Transcript show: myTextField text].! ! > > "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! > > SimpleExample class > instanceVariableNames: ''! > > !SimpleExample class methodsFor: 'specs' stamp: 'KMP 7/28/2020 16:30'! > defaultSpec > > ^ SpBoxLayout newVertical > borderWidth: 10; > spacing: 10; > add: #myTextField expand: false; > add: #myButton expand: false; > yourself! ! > > > > > > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html |
You need to do two things. Firstly, you need to create a label. Secondly, you
need to add it to the layout. The first bit is easy. You create the label in the initializePresenters method just like you did the button and the text field. There's a method that creates a label. If you open a system browser (CTRL+O+B) on SpPresenter and have look at the methods you will see which one to use. It's obvious, really. To lay out the field and the label the way you want you need to add the label to the layout in the class method defaultSpec. However, the existing SpBoxLayout there can only lay out the controls either vertically or horizontally. So you can have the controls going from top to bottom or left to right but that's all. If you want to have the label and the field on one line and the button underneath you will have to replace the SpBoxLayout with a SpGridLayout. This lays out things in a grid of columns and rows. Then you add the controls like this: add: #myTextField at: 2@1 This places the control in column 2 of row 1. You don't have to define or size the columns - the SpGridLayout does it all for you. Hope this helps. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html |
Free forum by Nabble | Edit this page |