Difference between revisions of "Make and run simple PND"

From Pandora Wiki
Jump to: navigation, search
(cat)
(merged Pnd.sh which has been deleted)
Line 1: Line 1:
 
Feel free to use this as a start for your own PND!  This is pretty much the simplest PND possible.  It will show a black screen for 2 seconds and then quit.  Unfortunately, due to a bug in MiniMenu, this PND can only (as of HF5) be launched from XFCE.
 
Feel free to use this as a start for your own PND!  This is pretty much the simplest PND possible.  It will show a black screen for 2 seconds and then quit.  Unfortunately, due to a bug in MiniMenu, this PND can only (as of HF5) be launched from XFCE.
  
== Overview ==
+
== MAKING SIMPLE PND ==
  
 
The PND has 2 files.  First, "simplepytest.py", which is our executable application, and "PXML.xml" which the Pandora uses to launch the application correctly.
 
The PND has 2 files.  First, "simplepytest.py", which is our executable application, and "PXML.xml" which the Pandora uses to launch the application correctly.
Line 75: Line 75:
 
# Re-insert your SD card.
 
# Re-insert your SD card.
 
# The "Simple Py Test" game should appear in the Arcade Game folder.
 
# The "Simple Py Test" game should appear in the Arcade Game folder.
 +
 +
==LAUNCHING A PND FROM TERMINAL==
 +
It would be good to have basic shell scripting knowledge before proceeding with this article.
 +
 +
== Usage ==
 +
Usage:
 +
  pnd_run.sh -p file.pnd -e cmd [-a args] [-b pndid] [-s path] [-c speed] [-d [path]] [-x] [-m] [-u]
 +
    -p file.pnd : Specify the pnd file to execute
 +
    -e cmd : Command to run
 +
    -a args : Arguments to the command
 +
    -b pndid : name of the directory mount-point (/mnt/utmp/pndid) (Default: name of the pnd file)
 +
    -s path : Directory in the union to start the command from
 +
    -o speed : Set the CPU speed
 +
    -d [path] : Use path as source of the overlay. (Default: pandora/appdata/pndid)
 +
    -x : Stop X before starting the apps
 +
    -m : Only mount the pnd, dont run it (-e become optional)
 +
    -u : Only umount the pnd, dont run it (-e become optional)
 +
 +
== Arguments ==
 +
It is possible to execute the content of your pnd using arguments. This can be done by passing -a to pnd_run.sh with arguments quoted
 +
-a "--arg 1"
 +
 +
== Creating a launch script for PND ==
 +
For a PND to function normally, you usually need to pass the appdata or PND ID (via -b) and correct executable (via -e) to the pnd_run.sh script. These can be found by examining PXML data that is appended in PNDs, or alternatively you can find IDs by using various package managers and executable paths by checking the .desktop files generated by the PND system. For the PND ID you would use the "appdata" entry of the PXML.xml, and, if absent, the application id. This will also determine the directory in pandora/appdata which will be used as base for the overlay. (As of this writing, the -d parameter is not evaluated.) For the -e parameter, you look for the "exec command" in the PXML.xml. This will determine the executable, which would be especially important in a multi-app-pnd.
 +
pnd_run.sh -p /media/SD1/pandora/menu/Chromium.pnd -e "chrome.sh" -b "chromium" -a "$*"
 +
 +
Where chromium is the PND's ID found from PXML, and chrome.sh is the application found from .desktop file.
 +
 +
== Modifying PNDs launch script(s) to accept arguments ==
 +
With the Chromium.pnd it's not possible to use any additional arguments for the browser by default.
 +
This is because the launch script it uses does not expect arguments to be passed to it, and therefore does not pass them to chrome binary.
 +
 +
For example, the original chrome.sh from Chromium.pnd (as time of writing), looks like this:
 +
#!/bin/sh
 +
# /mnt/utmp/chromium/chrome.sh
 +
HOME="/tmp"
 +
mkdir ./Default
 +
mkdir /tmp/chromium
 +
cp "First Run" /tmp/chromium/
 +
ln -s /mnt/utmp/chromium/Default /tmp/chromium/Default
 +
export HOME
 +
export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH
 +
export XDG_CONFIG_HOME=$HOME
 +
./chrome
 +
rm -r /tmp/chromium
 +
 +
Notice that it launches ./chrome and does not give any arguments for it.
 +
 +
As the original launch script resides in PND that is read-only file system, you can't modify it directly.
 +
However you can copy the script to that PND's appdata directory, which overrides the files of PND when mounted.
 +
 +
So copy it and modify this part:
 +
./chrome $@
 +
 +
So it should look like this in the end:
 +
#!/bin/sh
 +
# /media/SD1/pandora/appdata/chromium/chrome.sh
 +
HOME="/tmp"
 +
mkdir ./Default
 +
mkdir /tmp/chromium
 +
cp "First Run" /tmp/chromium/
 +
ln -s /mnt/utmp/chromium/Default /tmp/chromium/Default
 +
export HOME
 +
export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH
 +
export XDG_CONFIG_HOME=$HOME
 +
./chrome $@
 +
rm -r /tmp/chromium
 +
 +
There probably exists many more PNDs that don't expect arguments, and it's problematic when you actually need to pass them arguments, or make them as launchers for some file types. So you need to learn how to modify them.
 +
 +
== Making Chromium the default browser of XFCE using the PND ==
 +
Create launch script such as:
 +
#!/bin/sh
 +
# /media/SD1/launchers/chromium.sh
 +
/usr/pandora/scripts/pnd_run.sh -p /media/SD1/pandora/menu/Chromium.pnd -e "chrome.sh" -b "chromium" -a "$*"
 +
 +
Save the script somewhere and make it as executable:
 +
chmod +x /media/SD1/launchers/chromium.sh
 +
 +
Then go to Settings > Desktop > Preferred Applications, and point the Web Browser to your script.
 +
When opening URLs in XFCE environment, they should open in Chromium now.
 +
  
 
[[Category:PND]]
 
[[Category:PND]]
 
[[Category:Tutorial]]
 
[[Category:Tutorial]]
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 12:47, 19 August 2013

Feel free to use this as a start for your own PND! This is pretty much the simplest PND possible. It will show a black screen for 2 seconds and then quit. Unfortunately, due to a bug in MiniMenu, this PND can only (as of HF5) be launched from XFCE.

MAKING SIMPLE PND

The PND has 2 files. First, "simplepytest.py", which is our executable application, and "PXML.xml" which the Pandora uses to launch the application correctly.

First, create a "simplepytest" folder in one of your application folders (i.e., "/pandora/menu").

SimplePyTest.py

This file is the actual application that the Pandora executes.

Create a file called "simplepytest.py" and put the following contents in it. This will display a black screen for 2 seconds at the current screen resolution, using Python and Pygame.

#! /usr/bin/python

import pygame, pygame.locals
import time

pygame.init()

vidInfo = pygame.display.Info()
resolution = (vidInfo.current_w, vidInfo.current_h)

pygame.display.set_mode(resolution, pygame.locals.FULLSCREEN)

time.sleep(2)

PXML.xml

This file contains the information the Pandora needs to figure out where to display your game and how to execute it.

Create a file called "PXML.xml" and put the following contents in it:

<?xml version="1.0" encoding="UTF-8">
<PXML xmlns="http://openpandora.org/namespaces/PXML">
        <package id="simplepytest">
        <version major="0" minor="0" release="0" build="1"/>
        <author name="YOUR NAME" email="YOUR EMAIL"/>        
                <title lang="en_US">Simple Py Test</title>
                <titles>
                        <title lang="en_US">Simple Py Test</title>
        </titles>
        </package>
    <application id="simplepytest">
        <title lang="en_US">Simple Py Test</title>
                <titles>
                        <title lang="en_US">Simple Py Test</title>
        </titles>
        <description lang="en_US">A Python and Pygame test program.
            </description>
        <version major="0" minor="0" release="0" build="1"/>
        <exec command="python simplepytest.py" />
        <author name="YOUR NAME" email="YOUR EMAIL"/>
                <licenses>
                        <license name="other"/>
                </licenses>
        <categories>
            <category name="Game">
                <subcategory name="ArcadeGame">
            </category>
        </categories>
    </application>
</PXML>

Running Your Game

  1. Save all the above files.
  2. Make sure your Pandora is running the XFCE Gui.
  3. Unmount, then remove your SD card.
  4. Re-insert your SD card.
  5. The "Simple Py Test" game should appear in the Arcade Game folder.

LAUNCHING A PND FROM TERMINAL

It would be good to have basic shell scripting knowledge before proceeding with this article.

Usage

Usage:

 pnd_run.sh -p file.pnd -e cmd [-a args] [-b pndid] [-s path] [-c speed] [-d [path]] [-x] [-m] [-u]
   -p file.pnd	: Specify the pnd file to execute
   -e cmd	: Command to run
   -a args	: Arguments to the command
   -b pndid	: name of the directory mount-point (/mnt/utmp/pndid) (Default: name of the pnd file)
   -s path	: Directory in the union to start the command from
   -o speed	: Set the CPU speed
   -d [path]	: Use path as source of the overlay. (Default: pandora/appdata/pndid)
   -x		: Stop X before starting the apps
   -m		: Only mount the pnd, dont run it (-e become optional)
   -u		: Only umount the pnd, dont run it (-e become optional)

Arguments

It is possible to execute the content of your pnd using arguments. This can be done by passing -a to pnd_run.sh with arguments quoted

-a "--arg 1"

Creating a launch script for PND

For a PND to function normally, you usually need to pass the appdata or PND ID (via -b) and correct executable (via -e) to the pnd_run.sh script. These can be found by examining PXML data that is appended in PNDs, or alternatively you can find IDs by using various package managers and executable paths by checking the .desktop files generated by the PND system. For the PND ID you would use the "appdata" entry of the PXML.xml, and, if absent, the application id. This will also determine the directory in pandora/appdata which will be used as base for the overlay. (As of this writing, the -d parameter is not evaluated.) For the -e parameter, you look for the "exec command" in the PXML.xml. This will determine the executable, which would be especially important in a multi-app-pnd.

pnd_run.sh -p /media/SD1/pandora/menu/Chromium.pnd -e "chrome.sh" -b "chromium" -a "$*"

Where chromium is the PND's ID found from PXML, and chrome.sh is the application found from .desktop file.

Modifying PNDs launch script(s) to accept arguments

With the Chromium.pnd it's not possible to use any additional arguments for the browser by default. This is because the launch script it uses does not expect arguments to be passed to it, and therefore does not pass them to chrome binary.

For example, the original chrome.sh from Chromium.pnd (as time of writing), looks like this:

#!/bin/sh
# /mnt/utmp/chromium/chrome.sh
HOME="/tmp"
mkdir ./Default
mkdir /tmp/chromium
cp "First Run" /tmp/chromium/
ln -s /mnt/utmp/chromium/Default /tmp/chromium/Default
export HOME
export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH
export XDG_CONFIG_HOME=$HOME
./chrome
rm -r /tmp/chromium

Notice that it launches ./chrome and does not give any arguments for it.

As the original launch script resides in PND that is read-only file system, you can't modify it directly. However you can copy the script to that PND's appdata directory, which overrides the files of PND when mounted.

So copy it and modify this part:

./chrome $@

So it should look like this in the end:

#!/bin/sh
# /media/SD1/pandora/appdata/chromium/chrome.sh 
HOME="/tmp"
mkdir ./Default
mkdir /tmp/chromium
cp "First Run" /tmp/chromium/
ln -s /mnt/utmp/chromium/Default /tmp/chromium/Default
export HOME
export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH
export XDG_CONFIG_HOME=$HOME
./chrome $@
rm -r /tmp/chromium

There probably exists many more PNDs that don't expect arguments, and it's problematic when you actually need to pass them arguments, or make them as launchers for some file types. So you need to learn how to modify them.

Making Chromium the default browser of XFCE using the PND

Create launch script such as:

#!/bin/sh
# /media/SD1/launchers/chromium.sh
/usr/pandora/scripts/pnd_run.sh -p /media/SD1/pandora/menu/Chromium.pnd -e "chrome.sh" -b "chromium" -a "$*"

Save the script somewhere and make it as executable:

chmod +x /media/SD1/launchers/chromium.sh

Then go to Settings > Desktop > Preferred Applications, and point the Web Browser to your script. When opening URLs in XFCE environment, they should open in Chromium now.