s_federici wrote:
You are really doing an incredible job blob thanks a lot for all this!
Why thank you! have you been trying it?
Offline
Jwosty wrote:
Well this looks pretty interesting; another reason to learn Python xD
Absolutely! Python's pretty nice; although I suspect Ruby's slightly nicer. And the Construct library is awesome for parsing stuff.
Offline
I want to integrate kurt into a script that can generate projects based on input from the user. More specifically, a Python web-server who uses forms to pass data to Kurt, then allows the user to download the final .sb.
Offline
It's certainly possible; what kind of input, and what kind of projects?
Offline
I'll give an example. I make an sb (in Scratch, not Kurt) of an empty sprite saying the text "__INPUT1__". I would like a user to upload an image and input some text. The image would be written as the sprites costume, and the text would replace the text __INPUT1__. Then, Kurt would output the new sb. (without overwriting the old one)
Offline
You can do something like this (leaving out the web stuff):
from kurt.files import * from kurt import Form # (just do a single `from kurt import *` if you prefer) picture_path = "users_picture.png" text = """User's text. Can be multiple lines, but doesn't have to be. One issue is that Scratch doesn't seem to automatically wrap the text (ie. you have to insert line breaks yourself in all the right places, which is quite hard without rendering the text yourself at some point. """ text = text.replace("\r\n", "\n") text = text.replace("\r", "\n") text_lines = [unicode(line+"\r") for line in text.split("\n")] # Format text for Scratch costume — I need to add something like this to # Kurt itself at some point project = ScratchProjectFile("original_project.sb") image = project.sprites[0].costumes[0] # Adjust as necessary image.textBox.lines = text_lines image.form = Form.load_png(picture_path) # Replace costume with new image.compositeForm = None # Scratch keeps a copy of the text rendered onto # the image — deleting this will force Scratch # to redraw the image project.save("new_project.sb") # pass a path argument to save() saves with new name, so won't overwrite old # project. FYI, subsequent calls to project.save() will use the new path.
Offline
I'll play around with that, thanks.
Offline
Just a quick note — you'll need to grab the dev branch of Kurt for now. It has loads of new stuff, like images; and I haven't quite gotten round to merging it back to master yet.
Offline
blob8108 wrote:
Just a quick note — you'll need to grab the dev branch of Kurt for now. It has loads of new stuff, like images; and I haven't quite gotten round to merging it back to master yet.
Oh, kay.
Offline
File "/kurt/fixed_objects.py", line 663, in load_png
TypeError: can only extend array with array (not "int")
Offline
I just checked it again; it definitely works for me. What platform are you using? Are you sure it's a PNG file?
Offline
I used a different file, and that message isn't there, but kurt just hangs.
Offline
What traceback do you see if you Ctrl+C? Which platform are you using, again?
Are you sure it's the latest version of Kurt? (Try the version off PyPI.) Are you sure Construct and PyPNG are updated?
Offline
Wait! That's not true! It doesn't hang. It just takes a tremendously large time to process. The original file was 13 KB, and the image was a half a megabyte.
The output file was 31 megs.
Last edited by bobbybee (2012-06-14 16:13:04)
Offline
Update: the image was too big for kurt to handle, thus causing the compression issues. It works fine with smaller files. Kurt should refuse to load files above X number of bytes.
Offline
bobbybee wrote:
Wait! That's not true! It doesn't hang. It just takes a tremendously large time to process. The original file was 13 KB, and the image was a half a megabyte.
The output file was 31 megs.
How big is the image, dimensions-wise? Can you link it?
The Scratch format uses run-length encoding to compress the images. Kurt decompresses the images fine, but I haven't got it to compress them yet. If you open them in Scratch and save, it should fix.
* This means it stores the whole image in memory while it's processing it. That might be the cause of the delay...
I'll admit this isn't great for what you're trying to do; I hope to do some work on fixing it soon.
Last edited by blob8108 (2012-06-14 16:23:56)
Offline
Dimensions? (gulps) Erm...in the thousands.
With this fix down, I have gotten the sprites costumes to change right. How do I access the stages costumes?
Last edited by bobbybee (2012-06-14 16:25:11)
Offline
bobbybee wrote:
Dimensions? (gulps) Erm...in the thousands.
Why on earth would you want an image larger than 480x360 in a Scratch project...?
With this fix down, I have gotten the sprites costumes to change right. How do I access the stages costumes?
project.stage.backgrounds
Pro tip: .images (rather than .costumes or .backgrounds) works for both sprites and stage, if you prefer.
Last edited by blob8108 (2012-06-14 16:39:44)
Offline
blob8108 wrote:
bobbybee wrote:
Dimensions? (gulps) Erm...in the thousands.
Why on earth would you want an image larger than 480x360 in a Scratch project...?
I'm crazy... (well, I didn't resize the image)With this fix down, I have gotten the sprites costumes to change right. How do I access the stages costumes?
project.stage.backgrounds
Pro tip: .images (rather than .costumes or .backgrounds) works for both sprites and stage if you prefer.
Thanks.
Offline
For some reason, the PNGs I make in PhotoShop are incompatible with Kurt (it was what was causing the original error)
Offline
Weird. Maybe PyPNG has issues with them. Did you try "Save for Web"?
Offline
I just tried. Didn't seem to make a difference
Offline
That is extremely strange. Could you send me an example offending file? Thanks!
Last edited by blob8108 (2012-06-14 17:12:36)
Offline
Sure...
Offline