@ -1,5 +1,7 @@
import curses
from library . exceptions import LibrarianException
from copy import copy
import library . database as db
class TextEntry :
@ -121,6 +123,7 @@ class FormWindow:
left = 0
top = 2
row = 2
buttononly = False
caption = " Form "
blabel = " Done "
labels = [ " label1 " ]
@ -144,8 +147,12 @@ class FormWindow:
def event_loop ( self ) :
self . w . keypad ( 1 )
self . refresh ( )
self . hl = 0 ;
self . entries [ self . hl ] . gain_focus ( )
self . hl = 0
if self . buttononly :
self . bt = 1
self . _highlight_button ( )
else :
self . entries [ self . hl ] . gain_focus ( )
ch = self . w . getch ( )
while ch != 27 :
@ -215,6 +222,7 @@ class FormWindow:
self . w . chgat ( self . brow , 1 , self . mx - 2 , curses . A_NORMAL )
def _mv_focus ( self , delta ) :
if self . buttononly : return
if self . bt == - 1 :
self . entries [ self . hl ] . lose_focus ( )
else :
@ -224,7 +232,6 @@ class FormWindow:
self . hl = new
if new == len ( self . labels ) :
self . bt = 1
self . bt = min ( self . bt , 1 )
self . _highlight_button ( )
else :
self . bt = - 1
@ -308,6 +315,24 @@ class BookForm(FormWindow):
else :
FormWindow . handle_input ( self , ch )
class BookView ( BookForm ) :
blabel = " Done "
buttononly = True
labels = [ " ISBN " , " LCCN " , " Title " , " Subtitle " , " Authors " , " Edition " ,
" Publisher " , " Publish Date " , " Publish Year " , " Publish Month " , " Publish location " ,
" Pages " , " Pagination " , " Weight " , " Categories " , " Status " ]
def __init__ ( self , window , helpbar , book , width = 50 ) :
book = copy ( book )
book [ " categories " ] = " - " . join ( [ cat [ " category " ] for cat in db . getBookCategories ( book ) ] )
status = db . get_checkout_status ( book [ " id " ] )
if status :
book [ " status " ] = " Checked out by %s ( %s ) " % ( status [ " uwid " ] , status [ " date_out " ] )
else :
book [ " status " ] = " On shelf "
self . caption = " Viewing Book " + str ( book [ " id " ] )
super ( ) . __init__ ( window , helpbar , book , width )
class CategoryForm ( FormWindow ) :
caption = " Add a Category "
blabel = " Add "
@ -316,21 +341,13 @@ class CategoryForm(FormWindow):
def _return_values ( self ) :
return self . entries [ 0 ] . value
class DummyTextEntry ( TextEntry ) :
def redraw ( self ) : pass
class ErrorForm ( FormWindow ) :
caption = " Error "
blabel = " OK "
buttononly = True
def __init__ ( self , window , helpbar , errortext , width = 50 ) :
self . labels = errortext . split ( " \n " )
super ( ) . __init__ ( window , helpbar , width = width )
self . bt = 1
def _make_entries ( self ) :
self . entries = [ ]
for e in range ( len ( self . labels ) ) :
self . entries . append ( DummyTextEntry ( self . w ) )
def redraw ( self ) :
self . w . box ( )
@ -339,7 +356,6 @@ class ErrorForm(FormWindow):
for l in self . labels :
c = 2
self . w . addstr ( r + self . top , c , l )
self . entries [ r ] . redraw ( )
r + = 1
self . w . addstr ( self . brow , self . bcol [ 1 ] , " < " + self . blabel + " > " )
self . w . chgat ( self . brow , self . bcol [ 1 ] , len ( self . blabel ) + 2 , curses . A_REVERSE )