Sugar/Quick screenshot hack: Difference between revisions

From OLPC
Jump to navigation Jump to search
(New page: = Background = Cynthia from the learning lab asked me (~~~) to hack an XO so that taking a substantial number of screenshots and transferring them to her Mac is easy. Right now, it is ted...)
 
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The Sugar [[Keyboard_Shortcuts|keyboard shortcut]] alt + 1 on the XO captures the screen, and creates an entry in the journal that you can title and copy to a [[USB drive]]. The method is useful for a small number of screenshots, but does not scale.
= Background =


This page describes a more advanced procedure to deal with multiple screenshots.
Cynthia from the learning lab asked me ([[User:DanielDrake|DanielDrake]]) to hack an XO so that taking a substantial number of screenshots and transferring them to her Mac is easy. Right now, it is tedious to copy screenshots one-by-one to a USB stick and then transport the USB stick to another system.


= Requirements =
== Background ==

Cynthia from the learning lab asked me ([[User:DanielDrake|DanielDrake]]) to hack an XO so that taking a substantial number of screenshots and transferring them to her Mac is easy. Right now, it is tedious to copy screenshots one-by-one to a USB drive and then transport the USB drive to another system.

== Requirements ==


* An internet-connected XO running sugar
* An internet-connected XO running sugar
Line 11: Line 15:
The decision was made to store the screenshots on a remote server and access them through the remote server to allow for the XO's IP changing, different XO's being used on different days, etc. It would also be realistic to store the screenshots on the XO and have the target computer access them over SSH, and that would only be a simple modification below.
The decision was made to store the screenshots on a remote server and access them through the remote server to allow for the XO's IP changing, different XO's being used on different days, etc. It would also be realistic to store the screenshots on the XO and have the target computer access them over SSH, and that would only be a simple modification below.


= Creating SSH key and configuring remote server =
== Creating SSH key and configuring remote server ==


The XO needs to have passwordless access to the remote server. You need to create a ssh key pair. If you want to have multiple XOs set up like this, only one of them needs to create the key, then you can copy it to any more XOs that you want to use in this way.
The XO needs to have passwordless access to the remote server. You need to create a ssh key pair. If you want to have multiple XOs set up like this, only one of them needs to create the key, then you can copy it to any more XOs that you want to use in this way.
Line 26: Line 30:
#* <tt>exit</tt>
#* <tt>exit</tt>


= Setting up the XO =
== Setting up the XO ==


* At the terminal activity, create a local screenshots directory
* At the terminal activity, create a local screenshots directory
Line 33: Line 37:
#!/bin/bash
#!/bin/bash
scp $1 user@remote.server.com:screenshots
scp $1 user@remote.server.com:screenshots
* Be sure to modify this line to reflect your remote server information
* Mark it executable
* Mark it executable
** <tt>chmod a+x /home/olpc/cpscrn</tt>
** <tt>chmod a+x /home/olpc/cpscrn</tt>


= Modifying sugar =
== Modifying sugar ==


Sugar must be modified to save screenshots to disk, rather than to the journal.
Sugar must be modified to save screenshots to disk, rather than to the journal, and then copy them over SSH. The modifications are in three parts:
# place screenshots in a special directory, with the correct file type (a changed file_path),
# run the cpscrn script to copy the screenshot over SSH (an os.system call),
# avoid adding the screenshot to the journal (a premature return).


How to modify Sugar:
* Become root
* Become root
** <tt>sudo -s</tt>
** <tt>sudo -s</tt>
* Open /usr/share/sugar/shell/view/Shell.py in a text editor
* For Sugar 0.84, open /usr/share/sugar/extensions/globalkey/screenshot.py in a text editor
** <tt>nano /usr/share/sugar/extensions/globalkey/screenshot.py</tt>
** Find the handle_key_press function,
** <tt>ctrl + w handle_key_press</tt>
* For Sugar 0.82, open /usr/share/sugar/shell/view/Shell.py in a text editor
** <tt>nano /usr/share/sugar/shell/view/Shell.py</tt>
** <tt>nano /usr/share/sugar/shell/view/Shell.py</tt>
* Find the take_screenshot function, about 85% of the way through the file
** Find the take_screenshot function, about 85% of the way through the file
** <tt>ctrl + w take_screenshot</tt>
* Modify the top of the function so that it looks as follows:
* On the line after the function declaration (def), change how the file_path is prepared, the red line is the new text that replaces the old text:
** The bold line is the line that you need to change
def take_screenshot(self):
def handle_key_press(self):
<b>file_path = os.path.join("/home/olpc/screenshots", '%i.png' % time.time())</b>
<font color="#a00000">file_path = os.path.join("/home/olpc/screenshots", '%i.png' % time.time())</font>
window = gtk.gdk.get_default_root_window()
window = gtk.gdk.get_default_root_window()
* Approximately 10 lines below, add two lines of code
* About 10 or 11 lines below, after the call to screenshot.save, add two lines of code, the red lines are the lines that you need to add:
screenshot.save(file_path, "png")
** The bold lines are the lines that you need to add
<font color="#a00000">os.system("/home/olpc/cpscrn %s" % file_path)</font>
screenshot.save(file_path, "png")
<font color="#a00000">return</font>
<b>os.system("/home/olpc/cpscrn %s" % file_path)</b>
<b>return</b>
client = gconf.client_get_default()
try:
* Save the file and close the text editor
* Save the file and close the text editor


= Accessing remote server =
== Accessing remote server ==


* Configure your target computer to have access to the screenshots subdirectory on remote.server.com.
* Configure your target computer to have access to the screenshots subdirectory on remote.server.com.
** This is system-dependent.
** This is system-dependent.


= Taking screenshots =
== Taking screenshots ==


* Restart sugar so that your code changes take effect
* Restart sugar so that your code changes take effect
** ctrl + alt + erase (warning: will lose unsaved work!)
* Press Alt+1 to take a screenshot
* Press alt + 1 to take a screenshot
* The journal will no longer contain the screenshot
* The screenshot will be saved locally in /home/olpc/screenshots and also copied to the remote server
* The screenshot will be saved locally in /home/olpc/screenshots and also copied to the remote server
** It may take a few seconds for the screenshot to be saved, compressed, and uploaded over the internet
** It may take a few seconds for the screenshot to be saved, compressed, and uploaded over the internet
* You can then view the screenshot(s) on your target computer by opening the folder on the remote server
* You can then view the screenshot(s) on your target computer by opening the folder on the remote server

== Notes ==

=== After update of build ===
After you update the build, the ssh key will have been removed, and you must re-generate it.

* Generate a SSH key:
# <tt>ssh-keygen -t rsa</tt>
# <tt>ssh-copy-id -i .ssh/id_rsa.pub user@remote.server.com</tt>
# <tt>ssh user@remote.server.com</tt>
# <tt>mkdir screenshots</tt>
# <tt>exit</tt>

You will also need to reapply your changes to Shell.py or screenshot.py.

Latest revision as of 22:17, 14 January 2011

The Sugar keyboard shortcut alt + 1 on the XO captures the screen, and creates an entry in the journal that you can title and copy to a USB drive. The method is useful for a small number of screenshots, but does not scale.

This page describes a more advanced procedure to deal with multiple screenshots.

Background

Cynthia from the learning lab asked me (DanielDrake) to hack an XO so that taking a substantial number of screenshots and transferring them to her Mac is easy. Right now, it is tedious to copy screenshots one-by-one to a USB drive and then transport the USB drive to another system.

Requirements

  • An internet-connected XO running sugar
  • ssh access to a remote server on the internet, which we'll call remote.server.com (and your username is "user")
  • The internet-connected "target" computer

The decision was made to store the screenshots on a remote server and access them through the remote server to allow for the XO's IP changing, different XO's being used on different days, etc. It would also be realistic to store the screenshots on the XO and have the target computer access them over SSH, and that would only be a simple modification below.

Creating SSH key and configuring remote server

The XO needs to have passwordless access to the remote server. You need to create a ssh key pair. If you want to have multiple XOs set up like this, only one of them needs to create the key, then you can copy it to any more XOs that you want to use in this way.

  1. On the XO, launch a terminal activity
  2. Generate a SSH key:
    • ssh-keygen -t rsa
  3. Copy the public key to the remote server
    • ssh-copy-id -i .ssh/id_rsa.pub user@remote.server.com
  4. Log into the remote server (confirming that there is no prompt for password/passphrase) and create a screenshots directory
    • ssh user@remote.server.com
    • mkdir screenshots
  5. Logout of remote server
    • exit

Setting up the XO

  • At the terminal activity, create a local screenshots directory
    • mkdir screenshots
  • Create a script called at /home/olpc/cpscrn with the following contents:
#!/bin/bash
scp $1 user@remote.server.com:screenshots
  • Be sure to modify this line to reflect your remote server information
  • Mark it executable
    • chmod a+x /home/olpc/cpscrn

Modifying sugar

Sugar must be modified to save screenshots to disk, rather than to the journal, and then copy them over SSH. The modifications are in three parts:

  1. place screenshots in a special directory, with the correct file type (a changed file_path),
  2. run the cpscrn script to copy the screenshot over SSH (an os.system call),
  3. avoid adding the screenshot to the journal (a premature return).

How to modify Sugar:

  • Become root
    • sudo -s
  • For Sugar 0.84, open /usr/share/sugar/extensions/globalkey/screenshot.py in a text editor
    • nano /usr/share/sugar/extensions/globalkey/screenshot.py
    • Find the handle_key_press function,
    • ctrl + w handle_key_press
  • For Sugar 0.82, open /usr/share/sugar/shell/view/Shell.py in a text editor
    • nano /usr/share/sugar/shell/view/Shell.py
    • Find the take_screenshot function, about 85% of the way through the file
    • ctrl + w take_screenshot
  • On the line after the function declaration (def), change how the file_path is prepared, the red line is the new text that replaces the old text:
    def handle_key_press(self):
        file_path = os.path.join("/home/olpc/screenshots", '%i.png' % time.time())
        window = gtk.gdk.get_default_root_window()
  • About 10 or 11 lines below, after the call to screenshot.save, add two lines of code, the red lines are the lines that you need to add:
        screenshot.save(file_path, "png")
        os.system("/home/olpc/cpscrn %s" % file_path)
        return
        
        client = gconf.client_get_default()
  • Save the file and close the text editor

Accessing remote server

  • Configure your target computer to have access to the screenshots subdirectory on remote.server.com.
    • This is system-dependent.

Taking screenshots

  • Restart sugar so that your code changes take effect
    • ctrl + alt + erase (warning: will lose unsaved work!)
  • Press alt + 1 to take a screenshot
  • The journal will no longer contain the screenshot
  • The screenshot will be saved locally in /home/olpc/screenshots and also copied to the remote server
    • It may take a few seconds for the screenshot to be saved, compressed, and uploaded over the internet
  • You can then view the screenshot(s) on your target computer by opening the folder on the remote server

Notes

After update of build

After you update the build, the ssh key will have been removed, and you must re-generate it.

  • Generate a SSH key:
  1. ssh-keygen -t rsa
  2. ssh-copy-id -i .ssh/id_rsa.pub user@remote.server.com
  3. ssh user@remote.server.com
  4. mkdir screenshots
  5. exit

You will also need to reapply your changes to Shell.py or screenshot.py.