Reading and using data from external file in Etoys

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

Reading and using data from external file in Etoys

L'Valente
Hi all,

I have a project where I need to read data that is in an external file, that file will be in CSV or XML format. I don't know how to do this nor if it is possible in Etoys? Who can give ma a hand with a detailed explanation?
Thank you,


All the best,
Luís Valente


Reply | Threaded
Open this post in threaded view
|

Re: Reading and using data from external file in Etoys

Karl Ramberg
That is very much possible, but you must use Smalltalk, the language Etoys are built from. 

Karl


On Mon, Apr 29, 2013 at 10:51 PM, Luis Valente <[hidden email]> wrote:
Hi all,

I have a project where I need to read data that is in an external file, that file will be in CSV or XML format. I don't know how to do this nor if it is possible in Etoys? Who can give ma a hand with a detailed explanation?
Thank you,


All the best,
Luís Valente






Reply | Threaded
Open this post in threaded view
|

Re: Reading and using data from external file in Etoys

Ben Coman
In reply to this post by L'Valente
Luis Valente wrote:
Hi all,

I have a project where I need to read data that is in an external file,
that file will be in CSV or XML format. I don't know how to do this nor if
it is possible in Etoys? Who can give ma a hand with a detailed explanation?
Thank you,


All the best,
Luís Valente
www.valente.org.pt

  


I've used Sven Van Caekenberghe's NeoCSV in Pharo 1.4 and found it quite powerful and straight forward.
Sorry I'm not sure of its Squeak compatibility.

cheers -ben


Reply | Threaded
Open this post in threaded view
|

Re: Reading and using data from external file in Etoys

Ricardo Moran
In reply to this post by L'Valente
Hi Luis,

For CSV files you can see that Physical Etoys includes Skeleton with a few changes that allow a spreadsheet to import/export csv data from external files. If you want to use that in Etoys you can load this file: http://source.squeak.org/etoysinbox/Skeleton-Richo.10.mcz and look for the "data i/o" category on the Skeleton spreadsheet.

For XML, I'm afraid you'll have to get your hands dirty and write some smalltalk code :)
I don't know your smalltalk knowledge, but here it's a simple example that might help you get started, let me know if you need more help:

xml := XMLDOMParser parseDocumentFrom: '
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don''t forget me this weekend!</body>
</note>' readStream.
xml explore.

Cheers,
Richo


On Mon, Apr 29, 2013 at 5:51 PM, Luis Valente <[hidden email]> wrote:
Hi all,

I have a project where I need to read data that is in an external file, that file will be in CSV or XML format. I don't know how to do this nor if it is possible in Etoys? Who can give ma a hand with a detailed explanation?
Thank you,


All the best,
Luís Valente






Reply | Threaded
Open this post in threaded view
|

Re: Reading and using data from external file in Etoys

Darius Clarke
It may not be obvious how to call Smalltalk code from Etoys. It's rather simple.

Any object's script can be changed to Smalltalk text and then more Smalltalk code can be added and saved there. 

For example, attached are photos of the button script that moves a Star object to a position on the World coordinates.
Inline image 1

Selecting the White menu button in the top right corner you get this menu:

Inline image 2 

Choose "show code textually" and you get the Smalltalk equivalent. 

Inline image 3

Now you can replace the Smalltalk code that moves the star with the Smalltalk code you want to execute to load the CSV file ... into some text object for example.

- Darius 



On Tue, Apr 30, 2013 at 12:59 PM, Ricardo Moran <[hidden email]> wrote:
Hi Luis,

For CSV files you can see that Physical Etoys includes Skeleton with a few changes that allow a spreadsheet to import/export csv data from external files. If you want to use that in Etoys you can load this file: http://source.squeak.org/etoysinbox/Skeleton-Richo.10.mcz and look for the "data i/o" category on the Skeleton spreadsheet.

For XML, I'm afraid you'll have to get your hands dirty and write some smalltalk code :)
I don't know your smalltalk knowledge, but here it's a simple example that might help you get started, let me know if you need more help:

xml := XMLDOMParser parseDocumentFrom: '
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don''t forget me this weekend!</body>
</note>' readStream.
xml explore.

Cheers,
Richo


On Mon, Apr 29, 2013 at 5:51 PM, Luis Valente <[hidden email]> wrote:
Hi all,

I have a project where I need to read data that is in an external file, that file will be in CSV or XML format. I don't know how to do this nor if it is possible in Etoys? Who can give ma a hand with a detailed explanation?
Thank you,


All the best,
Luís Valente










Reply | Threaded
Open this post in threaded view
|

Re: Reading and using data from external file in Etoys

Darius Clarke

There's also a simple CSV parser on SqueakSource:

After you import it into your image, be sure to save that image file and distribute it to all your students instead of the standard .image file.

___

Attached are the files you'll need.

Drag and drop the SUnit-Kernel.st file into your Etoys image first. Select "load" from the popup menu.
Drag and drop the CSV-JohnnyT.10.mcz file next into your Etoys World. Select "load" from the popup menu.
Save your image with the Alt-, menu. (Hold down alt and the comma).
Select "do..." in the menu.
Select "Smalltalk saveAsNewVersion" in the "Common Requests" menu.

Remove the version number added to the generated file etoys.1.image and etoys.1.changes and replace your original etoys.image and etoys.changes files and distribute those to your students as part of your modified Etoys distribution.

Now you can access Smalltalk from Etoys tiles as I mentioned above. 

Something like:

| pal csvParser csvMorph rowMorph |
pal := (FileDirectory on: 'C:')
/ 'Pal' / 'data' / 'InFile'.

csvParser := CSVParser parse: (FileDirectory default readOnlyFileNamed: (pal pathName, '\Pal.INV.csv')).
 csvMorph := AlignmentMorph newColumn. csvMorph borderWidth: 1. csvParser rows do: [:row | rowMorph := AlignmentMorph newRow. rowMorph borderWidth: 1. row do: [:text | rowMorph addMorph: (((RectangleMorph new) addMorph:((StringMorph contents: text) borderWidth: 1)) borderColor: Color black). ]. csvMorph addMorph: rowMorph copy. ]. csvMorph openCenteredInWorld.




CSV-JohnnyT.10.mcz (6K) Download Attachment
SUnit-Kernel.st (59K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Reading and using data from external file in Etoys

L'Valente
In reply to this post by Darius Clarke
Hi All,
It's wonderful all the help I got. Thank you. Skeleton solves my needs for now!
And my knowledge about smalltalk isn't enough to go further with xml in Etoys, although I think it could be a nice matter to learn
Cheers,
Luis


2013/4/30 Darius Clarke <[hidden email]>
It may not be obvious how to call Smalltalk code from Etoys. It's rather simple.

Any object's script can be changed to Smalltalk text and then more Smalltalk code can be added and saved there. 

For example, attached are photos of the button script that moves a Star object to a position on the World coordinates.
Inline image 1

Selecting the White menu button in the top right corner you get this menu:

Inline image 2 

Choose "show code textually" and you get the Smalltalk equivalent. 

Inline image 3

Now you can replace the Smalltalk code that moves the star with the Smalltalk code you want to execute to load the CSV file ... into some text object for example.

- Darius 



On Tue, Apr 30, 2013 at 12:59 PM, Ricardo Moran <[hidden email]> wrote:
Hi Luis,

For CSV files you can see that Physical Etoys includes Skeleton with a few changes that allow a spreadsheet to import/export csv data from external files. If you want to use that in Etoys you can load this file: http://source.squeak.org/etoysinbox/Skeleton-Richo.10.mcz and look for the "data i/o" category on the Skeleton spreadsheet.

For XML, I'm afraid you'll have to get your hands dirty and write some smalltalk code :)
I don't know your smalltalk knowledge, but here it's a simple example that might help you get started, let me know if you need more help:

xml := XMLDOMParser parseDocumentFrom: '
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don''t forget me this weekend!</body>
</note>' readStream.
xml explore.

Cheers,
Richo


On Mon, Apr 29, 2013 at 5:51 PM, Luis Valente <[hidden email]> wrote:
Hi all,

I have a project where I need to read data that is in an external file, that file will be in CSV or XML format. I don't know how to do this nor if it is possible in Etoys? Who can give ma a hand with a detailed explanation?
Thank you,


All the best,
Luís Valente














--
All the best,
Luís Valente