View source for Python ncurses
From Openmoko
You do not have permission to edit this page, for the following reasons:
You can view and copy the source of this page:
Return to Python ncurses.
You do not have permission to edit this page, for the following reasons:
You can view and copy the source of this page:
Return to Python 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:
# 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()