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, |
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:
|
In reply to this post by 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 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 |
In reply to this post by L'Valente
Hi Luis, 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:
|
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.
Selecting the White menu button in the top right corner you get this menu: Choose "show code textually" and you get the Smalltalk equivalent.
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:
|
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. |
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]>
All the best, Luís Valente |
Free forum by Nabble | Edit this page |