Python ncurses
From Openmoko
Line 9: | Line 9: | ||
<nowiki> | <nowiki> | ||
+ | <pre><code> | ||
# very helpful: http://www.amk.ca/python/howto/curses/curses.html#SECTION000300000000000000000 | # very helpful: http://www.amk.ca/python/howto/curses/curses.html#SECTION000300000000000000000 | ||
Line 58: | Line 59: | ||
curses.nocbreak(); stdscr.keypad(0); curses.echo() | curses.nocbreak(); stdscr.keypad(0); curses.echo() | ||
curses.endwin() | curses.endwin() | ||
+ | </code></pre> | ||
</nowiki> | </nowiki> |
Revision as of 22:15, 26 August 2007
Writing python apps for the neo that use ncurses
To get started, visit Repositories and add ScaredyCat's repository to your list. Then:
ipkg update ipkg install python-base python-curses
Then I've put together a simple ncurses based app that'll sit in a loop waiting for input, and use ssh to execute xmms remote commands on the host computer. The full source is below:
<pre><code> # very helpful: http://www.amk.ca/python/howto/curses/curses.html#SECTION000300000000000000000 import os import curses stdscr = curses.initscr() curses.noecho() curses.cbreak() stdscr.keypad(1) host = "192.168.1.200" user = "jadams" MESSAGE_X = 0 MESSAGE_Y = 5 def send_xmms_arg(char): os.system('ssh ' + user + '@' + host + ' "xmms -' + char + '"') def write_instructions(): stdscr.addstr(0, 0, "c: play/pause; b: next; z: prev") stdscr.refresh() def write_message(message): stdscr.addstr(MESSAGE_Y, MESSAGE_X, message) # clear out stdscr.refresh() def do_play_pause(): send_xmms_arg('u') write_message("XMMS was paused / unpaused") def do_next(): send_xmms_arg('f') write_message("Skipped to the next song.") def do_prev(): send_xmms_arg('r') write_message("Skipped to the previous song.") write_instructions() while 1: c = stdscr.getch() if c == ord('q'): break elif c == ord('c'): do_play_pause() elif c == ord('b'): do_next() elif c == ord('z'): do_prev() curses.nocbreak(); stdscr.keypad(0); curses.echo() curses.endwin() </code></pre>