*

Welcome, Guest. Please login or register.

Get your own OLPC - Buy an XO laptop on eBay!
Pages: [1] 2 3
Print
Author Topic: Activity Developer Q&A  (Read 26480 times)

Activity Developer Q&A

david_kw
Moderator
Contributor
***
Posts: 57


WWW
March 01, 2008, 01:12:44 AM

If you have a question and/or answer about developing an activity for the OLPC XO, try it out here.  Even if the answer is a link to somewhere else this is the place to put it.

david_kw
Logged

#1 Re: Activity Developer Q&A

davewa
Master Contributor
***
Posts: 352


G1G1D1P4


WWW
March 04, 2008, 12:11:32 PM

Okay, I've got one:

My Activity needs to control the foreground and background color of its canvas.  I seem to have code that does that, but the code also affects the color of button text in toolbars.  Why is the device context "bleeding" outside the canvas?  This is especially egrigeous in that some of the controls are ToggleButtons.  White on white is hard to read!
Logged

#2 Re: Activity Developer Q&A

davewa
Master Contributor
***
Posts: 352


G1G1D1P4


WWW
April 04, 2008, 08:10:21 AM

Here's another:

I've got a large data structure defined (around 1500 lines of Python).  Can I break this out as a separate file and import it?  The Python tutorial talks about imported files as containing function definitions.  Is it permissible to have an imported file that just consists of an array declaration and initialization, e.g.:

data = [ 1, 2, 3]

in a file "dat.py" and then in "code.py" include

import dat

Or am I being too C-ish here and trying to make "import" work like "#include"?
Logged

#3 Re: Activity Developer Q&A

tdang
Senior Contributor
**
Posts: 166


April 04, 2008, 09:17:55 AM

I've got a large data structure defined (around 1500 lines of Python).  Can I break this out as a separate file and import it?

I don't know, but I'd say give it a try and see if it works.

Alternatively, it should be easy (I think) to define a new class for that structure. And you can definitely import a class.

-Timothy
Logged

My XO
If in your neighborhood, I'll appear as "Abiyoyo".

#4 Re: Activity Developer Q&A

juanslayton
Commenter

Posts: 19


April 16, 2008, 03:15:23 PM

     Question:  How can one download activities directly from the internet, when the downloads disappear into the XO database and do not show up in the file system?

     It's easy enough to download to a memory stick on my desktop and use that to transfer to the XO, but there's gotta be a more direct way.
« Last Edit: April 18, 2008, 07:47:32 PM by juanslayton » Logged

#5 Re: Activity Developer Q&A

anna
Master Contributor
***
Posts: 326


April 16, 2008, 03:17:03 PM

Have to tried to cd where you want the file to go, then use wget?
Logged

#6 Re: Activity Developer Q&A

juanslayton
Commenter

Posts: 19


April 16, 2008, 03:32:17 PM

Son of a gun, it works!
Thank you very much.
John
Logged

#7 Re: Activity Developer Q&A

davewa
Master Contributor
***
Posts: 352


G1G1D1P4


WWW
May 16, 2008, 11:05:38 AM

Here's another:

I've got a large data structure defined (around 1500 lines of Python).  Can I break this out as a separate file and import it?  The Python tutorial talks about imported files as containing function definitions.  Is it permissible to have an imported file that just consists of an array declaration and initialization, e.g.:

data = [ 1, 2, 3]

in a file "dat.py" and then in "code.py" include

import dat

Or am I being too C-ish here and trying to make "import" work like "#include"?

Okay, I figured out the answer.  If you make a file "foo.py" and it contains an array called "data" (and it apparently can't be named anything else!), your code can then say
"import foo"
and refer to "foo.data[n]".  It's a little inconvenient; if you need multiple arrays you apparently have to put them in separate files, so you wind up with code like:
import foo, bar

x = foo.data[3]
y = bar.data[8]
Logged

#8 Re: Activity Developer Q&A

PiForEver
Contributor
*
Posts: 60


I like pi(e)


May 16, 2008, 01:04:59 PM

what is your activity, Sorry about being off topic
Logged

Me+Pie+Linux= Smiley

#9 Re: Activity Developer Q&A

davewa
Master Contributor
***
Posts: 352


G1G1D1P4


WWW
May 16, 2008, 01:26:14 PM

StarChart.  I'm trying to split the catalog data off from the algorithms so the code's easier for me to navigate when editing.
Logged

#10 Re: Activity Developer Q&A

hazelday
Commenter

Posts: 6


May 17, 2008, 01:03:16 AM


Okay, I figured out the answer.  If you make a file "foo.py" and it contains an array called "data" (and it apparently can't be named anything else!), your code can then say
"import foo"
and refer to "foo.data[n]".  It's a little inconvenient; if you need multiple arrays you apparently have to put them in separate files, so you wind up with code like:
import foo, bar

x = foo.data[3]
y = bar.data[8]

It's a lot easier than that. In python, when you import a module (any file.py can be thought of as a module) you can specify names within that module that you want to make local to yours (think of it as a selective #include)

from foo import data

and you can expand that, in case you have data1, data2, data3:

from foo import data data1 data2 data3

now you can say
x = data[0]
y = data2[1]
etc.

Since you're using a python module to just store data, though, you're going to want to be able to access as much data as you want without having to think about the consequences of each addition. That can be done like this:

from foo import *

and that'll bring in everything.

-Peter


« Last Edit: May 17, 2008, 01:04:49 AM by hazelday » Logged

#11 Re: Activity Developer Q&A

davewa
Master Contributor
***
Posts: 352


G1G1D1P4


WWW
May 19, 2008, 09:45:32 AM

Thanks, Peter.  I'll have to experiment some more.

But for my particular purpose, having separate filenames was actually a help; I've now got the star catalog in one file and the constellation figures coordinates in another.  Since everybody sees the same stars but different cultures group them differently, separate files seemed like a good thing.
Logged

#12 Re: Activity Developer Q&A

davewa
Master Contributor
***
Posts: 352


G1G1D1P4


WWW
August 01, 2008, 08:36:30 AM

In Search Of SVG Editor

I'm running Update.1 (build 703).  I'm looking for a graphical tool I can install that will let me make SVG files (for icons) on my XO.  This seems like such an obvious thing to have as part of the Paint activity, but apparently Paint doesn't make SVGs even though it can read them.

I'm trying to flesh out the GUI for my StarChart activity and at the same time convert the current textual buttons to iconic buttons with tooltips and/or pallets so the toolbars won't get truncated when the screen is rotated.
Logged

#13 Re: Activity Developer Q&A

AuntiMame
Master Contributor
***
Posts: 418



WWW
August 01, 2008, 09:41:44 AM

davewa,

Inksape  ( http://www.inkscape.org/) is the open source SVG editor of choice. Closed source, you can use Adobe Illustrator or Corel Draw.

[Edit: Inkscape has a simple feature that lets you import bitmaps and then "trace" a vector. Also there are loads of ready-made icons SVGs in the wikimedia Commons  http://commons.wikimedia.org/wiki/SVG#SVGs_in_MediaWiki ]


But sugar icons (for the "desktop") have to be further tweaked to get the user's colors recognized by the icon. http://wiki.laptop.org/go/Making_SVG_Icons_for_Sugar

can you tell I spend A lot of time tweaking icons?  Grin  http://xoexplosion.com/index.php?main_page=index&cPath=18_19

Aunti

« Last Edit: August 01, 2008, 09:46:22 AM by AuntiMame » Logged

Shop for XO accessories and swag at www.XOExplosion.com

Life is a banquet, and most poor suckers are starving to death!

#14 Re: Activity Developer Q&A

davewa
Master Contributor
***
Posts: 352


G1G1D1P4


WWW
August 01, 2008, 10:01:03 AM

davewa,

Inksape


But sugar icons (for the "desktop") have to be further tweaked to get the user's colors recognized by the icon. http://wiki.laptop.org/go/Making_SVG_Icons_for_Sugar

Aunti



Okay, thanks.  Inkscape plus a text editor it is, I guess.  At least until somebody sees fit to make an IDE for XO developers.

I just downloaded the Windows version of Inkscape.  I'll see what kind of a mess I can get myself into over the weekend.
Logged
Pages: [1] 2 3
Print
Jump to:  

Members
Total Members: 2406
Latest: sembik
Stats
Total Posts: 31943
Total Topics: 3843
Online Today: 28
Online Ever: 238
(April 18, 2011, 09:48:50 PM)
Users Online
Users: 0
Guests: 13
Total: 13