[Nym3-commit] r140 - trunk/nym3/Client
jr at komite.net
jr at komite.net
Thu Dec 23 02:17:53 CET 2004
Author: jr
Date: 2004-12-23 02:17:52 +0100 (Thu, 23 Dec 2004)
New Revision: 140
Added:
trunk/nym3/Client/testcurses.py
Log:
- add a module that contains a curses display which enables to go through a list
of strings, with scrolling, beep when the ends of the list are reached and supporting resize
Added: trunk/nym3/Client/testcurses.py
===================================================================
--- trunk/nym3/Client/testcurses.py 2004-12-21 16:57:39 UTC (rev 139)
+++ trunk/nym3/Client/testcurses.py 2004-12-23 01:17:52 UTC (rev 140)
@@ -0,0 +1,93 @@
+import curses
+import curses.wrapper
+import curses.ascii
+
+month = ["Jan", "Fev", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
+ "Oct", "Nov", "Dec"]
+
+subj = [
+ "No limit!",
+ "Dis donc, t'as lache Medor?",
+ "\o/",
+ "Le pal serait trop doux.",
+ "Scritch le disque.",
+ "Enfin, du debian.",
+ "BNW, dm-crypt, gnougnouche.",
+ "Sodomisons les prudes avec des pelles a tarte.",
+ "Rituel",
+ "C'est beau la connerie quand c'est pur.",
+ "Get a clue!",
+ "Abus de notation."
+ ]
+
+def draw_line(stdscr, idx, line, maxcol, color):
+ stdscr.move(line, 0)
+ src = "%s %s" % (month[idx], subj[idx])
+ stdscr.addstr(src[0: maxcol], curses.color_pair(color))
+ stdscr.clrtoeol()
+
+def draw_emptyline(stdscr, line):
+ stdscr.move(line, 0)
+ stdscr.clrtoeol()
+
+def draw_picture(stdscr, index, fstindex, listrange, listsize, maxcol):
+ stdscr.move(0,0)
+ for i in range(0, listrange):
+ if fstindex + i < listsize:
+ if (fstindex + i == index):
+ j = 1
+ else:
+ j = 0
+ draw_line(stdscr, fstindex + i, i, maxcol, j)
+ else:
+ draw_emptyline(stdscr, i)
+ #if maxline >= 12:
+ # for i in range(12, maxline):
+ # stdscr.addstr("\n");
+
+ #print "%i %i\n" % (i, j)
+ stdscr.refresh()
+
+def func(stdscr):
+ curses.curs_set(0)
+ curses.raw()
+ #define here our colors pair
+ #cursor
+ curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
+ #status bar
+ curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLUE)
+
+ # init the variables
+ (maxline, maxcol) = stdscr.getmaxyx()
+ index = 0
+ fstindex = 0
+ listrange = maxline
+ listsize = 12
+
+ draw_picture(stdscr, index, fstindex, listrange, listsize, maxcol)
+ while 1:
+ c = stdscr.getch()
+ if c == curses.KEY_DOWN:
+ if index < listsize - 1:
+ index = index + 1
+ if (index == fstindex + listrange):
+ fstindex = index
+ else:
+ curses.beep()
+ elif c == curses.KEY_UP:
+ if index > 0:
+ index = index - 1
+ if (index == fstindex - 1):
+ fstindex = max(0, fstindex - listrange)
+ else:
+ curses.beep()
+ elif c == ord('q'):
+ break
+ elif c == curses.KEY_RESIZE:
+ (maxline, maxcol) = stdscr.getmaxyx()
+ listrange = maxline
+ if maxline != 0:
+ fstindex = index - index % maxline
+ draw_picture(stdscr, index, fstindex, listrange, listsize, maxcol)
+
+curses.wrapper(func)
More information about the Nym3-commit
mailing list