Talk:PyGTK/Hello World Tutorial

From OLPC

Jump to: navigation, search

<James>

Thanks for the tutorial. I get as far as:

*  Run setup.py to create the content bundle

This gives the output:

# ./setup.py
: No such file or directory


Knowledge level: I'm a seasoned developer, but working with Linux is new to me.

I created the various *.py files on Windows, then copied them to the XO, into the folder /usr/share/activities/gtkactivity/

On the XO:

# cd /usr/share/activities/gtkactivity/
# find
.
/activity/activity-gtktest.svg
./activity/activity.info
e first line of the setup.py file is:
#!/usr/bin/env python

However, running find...

# find / -name python
/usr/bin/python

... shows that, on the XO, python is installed in /usr/bin/.

I tried changing the first line of setup.py to...

#!/usr/bin/python
#!/usr/bin/env python
#!python

... then tying again in the terminal:

# ./setup.py
:./setup.py: /usr/bin/python^M: bad interpreter: No such file or directory

I would be most grateful if someone could point out where I am going wrong.

</James>

Hey, I think the problem might be (and what I forgot to mention): You have to make the scripts (setup.py, gtktest.py) executable. 'chmod u+x *.py'. Then setup.py should output your .xo and you can install it on the XO Laptop via the journal. Crazy-chris 13:37, 25 January 2008 (EST)

<James> Thanks for your rapid response, Chris. I'm still having no joy:

# cd /usr/share/activities/gtkactivity/
# ls -aF
./   activity/     gtktest.glade*  manifest*
../  activity.py*  gtktest.py*     setup.py*
# chmod u+x *.py
# ./setup.py
: No such file or directory

</James>

Hey again. It seems to me that there are some problems with the filenames. Could you please post the output of 'ls -alh'? Thanks. In the meantime, you could also try 'python gtktest.py'. Crazy-chris 15:09, 25 January 2008 (EST)

chris, i believe most of your problems stem from the fact that since you've edited these files using windows, that the line endings in the files are CR or CRLF, if you have a program that can convert CR and CRLF line endings to LF line endings, i think this might help you

sorry, i mean james Nobody 16:06, 25 January 2008 (EST)


<James> Thanks again for your help. I'll look into the line ending issue. While you were providing your latest input, I was working on this:

# ls -alh
drwxrwxr-x  3 root root    0 Jan 26 01:41 .
drwxr-xr-x 35 root root    0 Jan 25 22:22 ..
drwxrwxr-x  2 root root    0 Jan 26 01:41 activity
-rwxr-xr-x  1 root root 1.1K Jan 25 22:22 activity.py
-rwxr-xr-x  1 root root 3.7K Jan 25 22:22 gtktest.glade
-rwxr-xr-x  1 root root 1.3K Jan 25 22:22 gtktest.py
-rwxr-xr-x  1 root root    0 Jan 25 22:22 manifest
-rwxr-xr-x  1 root root  379 Jan 26 03:12 setup.py

(Copied out old-school style, by hand. Is there a way to copy and paste this output?)


# python gtktest.py

... resulted (joy!) in a grey screen with the following buttons a quarter of the way from the bottom:


(  Who?  )        (Clean Up!)        ( >[] Quit )

>[] is meant to represent the icon of an open door with an arrow pointing at it.

Clicking on ( Who? ) shows...

  Hello
  World!

... centred in the top quarter. Clicking (Clean Up!) shows...

  Hello

... in the same position. Clicking Quit brings me back to the Terminal:

# python gtktest.py

(gtktest.py:2451): libglade-WARNING ** <property> element should be empty.  Found < span>.


(Actually, there's no space in , but if I don't add one, it gets treated as an HTML tag and doesn't appear in this page)

I also tried...

# python setup.py

... but Terminal replied...

WARNING: NEWS file missing

... then printed out a usage/help message.

I then tried...

# find / -name gtktest.xo

... but no such file was found. The manifest file remained empty. Thanks in advance for your valuable input.

</James>


The "file not found" error message you're looking at is the exact behavior I see when I try to run a shell script edited on a windows box without converting the line endings to the unix convention. Windows ends lines in its text files with <CR><LF>, but unix and its variants (including the OS on the OLPC) end lines with only an <LF>. This is a frequent cause of hilarity among those of us who have to work on both systems. A quick hacky fix for text files is:

  tr -d '\r' < original.windows.filename > fixed.unix.file
  mv fixed.unix.file original.windows.filename
  

You can of course dress this up in bash(1) to make it less error-prone and scary.

I had success by unzipping the .xo file to a directory in my ${HOME} (the directory you're in when you bring up the terminal activity), then cd ing into that directory and running "python setup.py dev".

  cd projects
  unzip /media/stick/pygtktest.xo
  cd pygtktest
  python setup.py dev

This will create a softlink in a directory called "${HOME}/Activities", and the icon et cetera will show up in the sugar window after you restart X windows with <ctrl><alt><erase>. If you need to re-do this or remove the activity from the activity toolbar, you should remove the softlink in ${HOME}/Activities:

  cd Activities
  rm pygtktest.activity

If you click on "remove" in the mouse hover menu, then the icon is removed from the toolbar, but near as I can tell that's the only action that takes place. At that point, the "setup.py dev" command will not put it back since it thinks it is already there.


Lack of a NEWS file will not cause any trouble besides the error message you saw. You can't make a MANIFEST file with the clever stuff in setup.py on the XO, because there "setup.py" detects "sugar.activity.bundlebuilder". You can make a MANIFEST file with bash after you've unzipped the pygtktest.xo file with the following command:

  cd pygtktest
  find . -print | sed -e 's,^./,pygtktest.activity/,' > MANIFEST


Also I noticed there was no pygtktest-activity.svg file in the activity directory in the tutorial. I hacked one together with InkScape by copying an svg file from the /usr/share/activities directory on the XO and editing it. I dunno how you could manage this on windows -- the Gimp and other image programs don't grok svg files.

You can find application logs in /home/olpc/.sugar/default/logs. If you have python language errors, they will show up in a file named for the "activity_name" in your activity.info file.

Hope this helps a little. I got the tutorial working just fine by cutting and pasting from the browser into the appropriate files from my ubuntu desktop.

Cshapiro 12:49, 5 February 2008 (EST)
Personal tools
  • Log in
  • Login with OpenID
About OLPC
About the laptop
About the tablet
Projects
OLPC wiki
Toolbox