logo       

CVS: BitTorrent btdownloadcurses.py,1.6,1.7 btlaunchmanycurses.py,1.3,1.4 b: msg#00185

network.bit-torrent.general

Subject: CVS: BitTorrent btdownloadcurses.py,1.6,1.7 btlaunchmanycurses.py,1.3,1.4 btmakemetafile.py,1.16,1.17

Update of /cvsroot/bittorrent/BitTorrent
In directory sc8-pr-cvs1:/tmp/cvs-serv1591

Modified Files:
btdownloadcurses.py btlaunchmanycurses.py btmakemetafile.py
Log Message:

btdownloadcurses.py:
- Display all errors after quit -- including usage instructions
- use addnstr instead of addstr, since addstr kills us if the error is
larger than our width
- Handle SIGWINCH gracefully
- Die without puking a stack trace on the terminal when ^C is hit.

btlaunchmanycurses.py:
- Handle SIGWINCH gracefully

btmakemetafile.py:
- Use '\r' to end the percentage counting in order to print the next
percentage on the same line.


Index: btdownloadcurses.py
===================================================================
RCS file: /cvsroot/bittorrent/BitTorrent/btdownloadcurses.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** btdownloadcurses.py 17 Mar 2003 19:26:39 -0000 1.6
--- btdownloadcurses.py 26 Mar 2003 03:45:24 -0000 1.7
***************
*** 1,3 ****
! #!/usr/bin/env python

# Written by Henry 'Pi' James
--- 1,3 ----
! #!/usr/bin/env python2.2

# Written by Henry 'Pi' James
***************
*** 7,10 ****
--- 7,11 ----
from threading import Event
from os.path import abspath
+ from signal import signal, SIGWINCH
from sys import argv, version, stdout
assert version >= '2', "Install Python 2.0 or greater"
***************
*** 38,43 ****
return size

class CursesDisplayer:
! def __init__(self):
self.done = 0
self.file = ''
--- 39,63 ----
return size

+ def winch_handler(signum, stackframe):
+ global scrwin, scrpan, labelwin, labelpan, fieldw, fieldwin, fieldpan
+ # SIGWINCH. Remake the frames!
+ ## Curses Trickery
+ curses.endwin()
+ # delete scrwin somehow?
+ scrwin.refresh()
+ scrwin = curses.newwin(0, 0, 0, 0)
+ scrh, scrw = scrwin.getmaxyx()
+ scrpan = curses.panel.new_panel(scrwin)
+ labelh, labelw, labely, labelx = scrh - 2, 9, 1, 2
+ labelwin = curses.newwin(labelh, labelw, labely, labelx)
+ labelpan = curses.panel.new_panel(labelwin)
+ fieldh, fieldw, fieldy, fieldx = scrh - 2, scrw - 2 - labelw - 3, 1,
labelw + 3
+ fieldwin = curses.newwin(fieldh, fieldw, fieldy, fieldx)
+ fieldpan = curses.panel.new_panel(fieldwin)
+ prepare_display()
+
+
class CursesDisplayer:
! def __init__(self, mainerrlist):
self.done = 0
self.file = ''
***************
*** 50,53 ****
--- 70,74 ----
self.upRate = '---'
self.errors = []
+ self.globalerrlist = mainerrlist

def finished(self):
***************
*** 65,68 ****
--- 86,90 ----
def error(self, errormsg):
self.errors.append(errormsg)
+ self.globalerrlist.append(errormsg)
self.display()

***************
*** 85,100 ****

fieldwin.erase()
! fieldwin.addstr(0, 0, self.file, curses.A_BOLD)
! fieldwin.addstr(1, 0, self.fileSize)
! fieldwin.addstr(2, 0, self.downloadTo)
if self.progress:
! fieldwin.addstr(3, 0, self.progress, curses.A_BOLD)
! fieldwin.addstr(4, 0, self.status)
! fieldwin.addstr(5, 0, self.downRate)
! fieldwin.addstr(6, 0, self.upRate)

if self.errors:
for i in range(len(self.errors)):
! fieldwin.addstr(7 + i, 0, self.errors[i], curses.A_BOLD)
else:
fieldwin.move(7, 0)
--- 107,122 ----

fieldwin.erase()
! fieldwin.addnstr(0, 0, self.file, fieldw, curses.A_BOLD)
! fieldwin.addnstr(1, 0, self.fileSize, fieldw)
! fieldwin.addnstr(2, 0, self.downloadTo, fieldw)
if self.progress:
! fieldwin.addnstr(3, 0, self.progress, fieldw, curses.A_BOLD)
! fieldwin.addnstr(4, 0, self.status, fieldw)
! fieldwin.addnstr(5, 0, self.downRate, fieldw)
! fieldwin.addnstr(6, 0, self.upRate, fieldw)

if self.errors:
for i in range(len(self.errors)):
! fieldwin.addnstr(7 + i, 0, self.errors[i], fieldw,
curses.A_BOLD)
else:
fieldwin.move(7, 0)
***************
*** 111,127 ****
return saveas

! def run(params):
! d = CursesDisplayer()
! download(params, d.chooseFile, d.display, d.finished, d.error, Event(),
fieldw)
if not d.done:
d.failed()

def prepare_display():
! scrwin.hline(0, 1, '-', scrw - 2)
! scrwin.hline(scrh - 1, 1, '-', scrw - 2)
! scrwin.vline(1, 0, '|', scrh - 2)
! scrwin.vline(1, scrw - 1, '|', scrh - 2)
! # yes, i know there is curses.win.box(), i would like to use it, too, but
! # somehow it sucks in cygwin due to some shortcomings of it's curses port
labelwin.addstr(0, 0, 'file:')
labelwin.addstr(1, 0, 'size:')
--- 133,148 ----
return saveas

! def run(mainerrlist, params):
! d = CursesDisplayer(mainerrlist)
! try:
! download(params, d.chooseFile, d.display, d.finished, d.error,
Event(), fieldw)
! except KeyboardInterrupt:
! # ^C to exit..
! pass
if not d.done:
d.failed()

def prepare_display():
! scrwin.border('|','|','-','-',' ',' ',' ',' ')
labelwin.addstr(0, 0, 'file:')
labelwin.addstr(1, 0, 'size:')
***************
*** 163,172 ****
prepare_display()

if __name__ == '__main__':
try:
! run(argv[1:])
!
finally:
curses.nocbreak()
curses.echo()
curses.endwin()
--- 184,200 ----
prepare_display()

+ signal(SIGWINCH, winch_handler)
+
if __name__ == '__main__':
+ mainerrlist = []
try:
! run(mainerrlist, argv[1:])
finally:
curses.nocbreak()
curses.echo()
curses.endwin()
+ if len(mainerrlist) != 0:
+ print "These errors occurred during execution:"
+ for error in mainerrlist:
+ print error
+

Index: btlaunchmanycurses.py
===================================================================
RCS file: /cvsroot/bittorrent/BitTorrent/btlaunchmanycurses.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** btlaunchmanycurses.py 17 Mar 2003 19:26:40 -0000 1.3
--- btlaunchmanycurses.py 26 Mar 2003 03:45:25 -0000 1.4
***************
*** 13,16 ****
--- 13,17 ----
from sys import argv, version, stdout, exit
from time import sleep
+ from signal import signal, SIGWINCH
import traceback

***************
*** 48,51 ****
--- 49,89 ----
pass

+ def winch_handler(signum, stackframe):
+ global scrwin, mainwin, mainwinw, headerwin, totalwin, statuswin
+ global scrpan, mainpan, headerpan, totalpan, statuspan
+ # SIGWINCH. Remake the frames!
+ ## Curses Trickery
+ curses.endwin()
+ # delete scrwin somehow?
+ scrwin.refresh()
+ scrwin = curses.newwin(0, 0, 0, 0)
+ scrh, scrw = scrwin.getmaxyx()
+ scrpan = curses.panel.new_panel(scrwin)
+ ### Curses Setup
+ scrh, scrw = scrwin.getmaxyx()
+ scrpan = curses.panel.new_panel(scrwin)
+ mainwinh = scrh - 5 # - 2 (bars) - 1 (debugwin) - 1 (borderwin) - 1
(totalwin)
+ mainwinw = scrw - 4 # - 2 (bars) - 2 (spaces)
+ mainwiny = 2 # + 1 (bar) + 1 (titles)
+ mainwinx = 2 # + 1 (bar) + 1 (space)
+ # + 1 to all windows so we can write at mainwinw
+ mainwin = curses.newwin(mainwinh, mainwinw+1, mainwiny, mainwinx)
+ mainpan = curses.panel.new_panel(mainwin)
+
+ headerwin = curses.newwin(1, mainwinw+1, 1, mainwinx)
+ headerpan = curses.panel.new_panel(headerwin)
+
+ totalwin = curses.newwin(1, mainwinw+1, scrh-3, mainwinx)
+ totalpan = curses.panel.new_panel(totalwin)
+
+ statuswin = curses.newwin(1, mainwinw+1, scrh-2, mainwinx)
+ statuspan = curses.panel.new_panel(statuswin)
+ mainwin.scrollok(0)
+ headerwin.scrollok(0)
+ totalwin.scrollok(0)
+ statuswin.addstr(0, 0, 'window resize: %s x %s' % (scrw, scrh))
+ statuswin.scrollok(0)
+ prepare_display()
+
ext = '.torrent'
wininfo = {}
***************
*** 213,221 ****

def prepare_display():
! scrwin.hline(0, 1, '-', scrw - 2)
! scrwin.hline(scrh - 1, 1, '-', scrw - 2)
! scrwin.vline(1, 0, '|', scrh - 2)
! scrwin.vline(1, scrw - 1, '|', scrh - 2)
!
headerwin.addnstr(0, 0, 'Filename', mainwinw - 25, curses.A_BOLD)
headerwin.addnstr(0, mainwinw - 24, 'Size', 4);
--- 251,256 ----

def prepare_display():
! global mainwinw, scrwin, headerwin, totalwin
! scrwin.border('|','|','-','-',' ',' ',' ',' ')
headerwin.addnstr(0, 0, 'Filename', mainwinw - 25, curses.A_BOLD)
headerwin.addnstr(0, mainwinw - 24, 'Size', 4);
***************
*** 245,268 ****
print 'Textmode GUI initialization failed, cannot proceed.'
exit(-1)
! scrh, scrw = scrwin.getmaxyx()
! scrpan = curses.panel.new_panel(scrwin)
! mainwinh = scrh - 5 # - 2 (bars) - 1 (debugwin) - 1 (borderwin) - 1
(totalwin)
! mainwinw = scrw - 4 # - 2 (bars) - 2 (spaces)
! mainwiny = 2 # + 1 (bar) + 1 (titles)
! mainwinx = 2 # + 1 (bar) + 1 (space)
! # + 1 to all windows so we can write at mainwinw
! mainwin = curses.newwin(mainwinh, mainwinw+1, mainwiny, mainwinx)
! mainpan = curses.panel.new_panel(mainwin)

! headerwin = curses.newwin(1, mainwinw+1, 1, mainwinx)
! headerpan = curses.panel.new_panel(headerwin)

! totalwin = curses.newwin(1, mainwinw+1, scrh-3, mainwinx)
! totalpan = curses.panel.new_panel(totalwin)

! statuswin = curses.newwin(1, mainwinw+1, scrh-2, mainwinx)
! statuspan = curses.panel.new_panel(statuswin)
! try:
! try:
mainwin.scrollok(0)
headerwin.scrollok(0)
--- 280,305 ----
print 'Textmode GUI initialization failed, cannot proceed.'
exit(-1)
! try:
! try:
! signal(SIGWINCH, winch_handler)
! ### Curses Setup
! scrh, scrw = scrwin.getmaxyx()
! scrpan = curses.panel.new_panel(scrwin)
! mainwinh = scrh - 5 # - 2 (bars) - 1 (debugwin) - 1 (borderwin)
- 1 (totalwin)
! mainwinw = scrw - 4 # - 2 (bars) - 2 (spaces)
! mainwiny = 2 # + 1 (bar) + 1 (titles)
! mainwinx = 2 # + 1 (bar) + 1 (space)
! # + 1 to all windows so we can write at mainwinw
! mainwin = curses.newwin(mainwinh, mainwinw+1, mainwiny, mainwinx)
! mainpan = curses.panel.new_panel(mainwin)

! headerwin = curses.newwin(1, mainwinw+1, 1, mainwinx)
! headerpan = curses.panel.new_panel(headerwin)

! totalwin = curses.newwin(1, mainwinw+1, scrh-3, mainwinx)
! totalpan = curses.panel.new_panel(totalwin)

! statuswin = curses.newwin(1, mainwinw+1, scrh-2, mainwinx)
! statuspan = curses.panel.new_panel(statuswin)
mainwin.scrollok(0)
headerwin.scrollok(0)

Index: btmakemetafile.py
===================================================================
RCS file: /cvsroot/bittorrent/BitTorrent/btmakemetafile.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** btmakemetafile.py 17 Mar 2003 19:26:40 -0000 1.16
--- btmakemetafile.py 26 Mar 2003 03:45:25 -0000 1.17
***************
*** 123,127 ****

def prog(amount):
! print '%.1f%% complete' % (amount * 100)

if __name__ == '__main__':
--- 123,127 ----

def prog(amount):
! print '%.1f%% complete\r' % (amount * 100),

if __name__ == '__main__':



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/xaxhjB/hdqFAA/xGHJAA/dkFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
BitTorrent-unsubscribe@xxxxxxxxxxxxxxx



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise