In which I, Felix Bauckholt, assert my dominance

by changing the spacing.

Also by fixing the category window size.
This commit is contained in:
Felix Bauckholt 2016-01-24 01:27:47 -05:00
parent bc2d865520
commit 91f1ff9c55
7 changed files with 24 additions and 25 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

View File

@ -32,7 +32,7 @@ def menutest(s, l):
w = curses.newwin(15,40,(rows-10)//2, (cols-40)//2) w = curses.newwin(15,40,(rows-10)//2, (cols-40)//2)
menu(w, l) menu(w, l)
curses.curs_set(1) curses.curs_set(1)
# item is a list of (string, callable) tuples # item is a list of (string, callable) tuples
@ -157,7 +157,7 @@ def return_menu():
def catMenu(): def catMenu():
(my,mx)=stdscr.getmaxyx() (my,mx)=stdscr.getmaxyx()
w=curses.newwin(3,5) w=curses.newwin(3,5)
cat = browser.categoryBrowser(w,hb, 10,40) cat = browser.categoryBrowser(w,hb)
(r,c) = w.getmaxyx() (r,c) = w.getmaxyx()
w.mvwin((my-r)//2 -2, (mx-c)//2) w.mvwin((my-r)//2 -2, (mx-c)//2)
cat.refreshCategories() cat.refreshCategories()

View File

@ -178,7 +178,7 @@ INSERT INTO book_categories (id, cat_id) VALUES (?, ?), (?, ?), (?, ?), (?, ?);
def test_addBook(self): def test_addBook(self):
db_layer.addBook({'isbn': 8888888888888, 'title': 'New book'}) db_layer.addBook({'isbn': 8888888888888, 'title': 'New book'})
conn = sqlite3.connect(db_layer.dbFile) conn = sqlite3.connect(db_layer.dbFile)
with contextlib.closing(conn.cursor()) as c: with contextlib.closing(conn.cursor()) as c:
@ -186,7 +186,7 @@ INSERT INTO book_categories (id, cat_id) VALUES (?, ?), (?, ?), (?, ?), (?, ?);
SELECT title FROM books WHERE isbn = '8888888888888'; SELECT title FROM books WHERE isbn = '8888888888888';
''') ''')
rows = list(c) rows = list(c)
self.assertEqual(['New book'], [row[0] for row in rows]) self.assertEqual(['New book'], [row[0] for row in rows])
def test_updateBook(self): def test_updateBook(self):
@ -200,7 +200,7 @@ SELECT title FROM books WHERE isbn = '8888888888888';
SELECT title FROM books WHERE id = ?; SELECT title FROM books WHERE id = ?;
''', (self.book0_id,)) ''', (self.book0_id,))
rows = list(c) rows = list(c)
self.assertEqual(['Attack of the questionable code'], self.assertEqual(['Attack of the questionable code'],
[row[0] for row in rows]) [row[0] for row in rows])
@ -360,7 +360,7 @@ SELECT deleted FROM books WHERE id = ? OR id = ?;
'My second special category'] 'My second special category']
self.assertEqual(frozenset(expected_categories), self.assertEqual(frozenset(expected_categories),
frozenset(row[0] for row in rows)) frozenset(row[0] for row in rows))
db_layer.addCategory('My third special category') db_layer.addCategory('My third special category')
with contextlib.closing(conn.cursor()) as c: with contextlib.closing(conn.cursor()) as c:

View File

@ -24,7 +24,7 @@ Keys:
publish year - int (this kind of thing will have to be confirmed by cataloguer) publish year - int (this kind of thing will have to be confirmed by cataloguer)
publish month - int publish month - int
publish location - like publisher publish location - like publisher
pages - integer - just the number of pages pages - integer - just the number of pages
pagination - string eg. "xviii, 1327-1850" pagination - string eg. "xviii, 1327-1850"
weight - string (purely for interest's sake eg. "3lb." or "3 pounds" weight - string (purely for interest's sake eg. "3lb." or "3 pounds"
@ -134,4 +134,3 @@ def openLibrary_lccn(LCCN):
if "subtitle" in openBook: if "subtitle" in openBook:
book["subtitle"]=openBook["subtitle"] book["subtitle"]=openBook["subtitle"]
return book return book

View File

@ -123,7 +123,7 @@ class browserWindow:
self.unHighlight() self.unHighlight()
self.hl = new self.hl = new
self.highlight() self.highlight()
def scroll(self,delta): def scroll(self,delta):
self.unHighlight() self.unHighlight()
self.topline += delta self.topline += delta
@ -262,10 +262,10 @@ class trashBrowser(browserWindow):
('ISBN',0,13), ('ISBN',0,13),
('Authors',30,None), ('Authors',30,None),
('Title',60,None)] ('Title',60,None)]
cs = [(' r', 'restore selected'), (' d', 'delete selected')] cs = [(' r', 'restore selected'), (' d', 'delete selected')]
# redefinable functions # redefinable functions
def viewSelection(self,book): def viewSelection(self,book):
bookid = book['id'] bookid = book['id']
@ -327,14 +327,14 @@ class bookBrowser(browserWindow):
('ISBN',0,13), ('ISBN',0,13),
('Authors',30,None), ('Authors',30,None),
('Title',60,None)] ('Title',60,None)]
cs = [(' u', 'update'), (' d', 'delete selected')] cs = [(' u', 'update'), (' d', 'delete selected')]
# redefinable functions # redefinable functions
def updateSelection(self,book): def updateSelection(self,book):
bookid = book['id'] bookid = book['id']
w=curses.newwin(1,1) w=curses.newwin(1,1)
bf = BookForm(w,self.hb,book, width=self.mx-20) bf = BookForm(w,self.hb,book, width=self.mx-20)
self.centreChild(w) self.centreChild(w)
@ -363,7 +363,7 @@ class bookBrowser(browserWindow):
cs.refreshCategories() cs.refreshCategories()
cs.eventLoop() cs.eventLoop()
cs.clear() cs.clear()
def delSelected(self): def delSelected(self):
books = [] books = []
for sel,book in zip(self.selected, self.entries): for sel,book in zip(self.selected, self.entries):
@ -551,7 +551,7 @@ class columnSelector(browserWindow):
self.w.refresh() self.w.refresh()
ch = self.w.getch() ch = self.w.getch()
self.hb.refresh() self.hb.refresh()
def handleInput(self,ch): def handleInput(self,ch):
browserWindow.handleInput(self,ch) browserWindow.handleInput(self,ch)
return ch return ch

View File

@ -95,4 +95,3 @@ def return_procedure(w, hb, cy, cx, mx):
step1.clear() step1.clear()
if book_id: if book_id:
db.return_book(book_id) db.return_book(book_id)

View File

@ -6,7 +6,7 @@ class TextEntry:
"""A part of a window that handles text entry. """A part of a window that handles text entry.
Properties: Properties:
value holds the string that was entered value holds the string that was entered
Public Methods: Public Methods:
set_geom(row,column,width) Sets the geometry in the window set_geom(row,column,width) Sets the geometry in the window
set_value(string) Set the value and redraw set_value(string) Set the value and redraw
@ -53,7 +53,7 @@ class TextEntry:
self.cursor = 0 self.cursor = 0
self.start = 0 self.start = 0
self.redraw() self.redraw()
def handle_input(self,ch): def handle_input(self,ch):
if ch==curses.KEY_LEFT: if ch==curses.KEY_LEFT:
self._mv_cursor(-1) self._mv_cursor(-1)
@ -79,7 +79,7 @@ class TextEntry:
# Private functions # Private functions
def _mv_cursor(self,delta): def _mv_cursor(self,delta):
self._set_cursor(self.cursor + delta) self._set_cursor(self.cursor + delta)
def _set_cursor(self, new_c): def _set_cursor(self, new_c):
self.cursor = max(0, min(len(self.value), new_c)) self.cursor = max(0, min(len(self.value), new_c))
self.start = max(0,self.cursor-self.width+1) self.start = max(0,self.cursor-self.width+1)
@ -109,7 +109,7 @@ class TextEntry:
class FormWindow: class FormWindow:
"""General class for a Form Window. """General class for a Form Window.
To use, make the window for it, call the constructor, then call event_loop. To use, make the window for it, call the constructor, then call event_loop.
""" """
@ -270,8 +270,8 @@ class FormWindow:
if self.bt==-1: if self.bt==-1:
self.entries[self.hl].handle_input(ch) self.entries[self.hl].handle_input(ch)
class BookForm(FormWindow): class BookForm(FormWindow):
caption = "Add a Book" caption = "Add a Book"
@ -279,13 +279,13 @@ class BookForm(FormWindow):
labels = ["ISBN", "LCCN", "Title", "Subtitle", "Authors", "Edition", labels = ["ISBN", "LCCN", "Title", "Subtitle", "Authors", "Edition",
"Publisher", "Publish Date", "Publish Year", "Publish Month", "Publish location", "Publisher", "Publish Date", "Publish Year", "Publish Month", "Publish location",
"Pages", "Pagination", "Weight"] "Pages", "Pagination", "Weight"]
# redefineable functions lookup is called when 'enter' is pressed on ISBN # redefineable functions lookup is called when 'enter' is pressed on ISBN
# and returns the looked-up book. Default returns nothing # and returns the looked-up book. Default returns nothing
def lookup_isbn(self,isbn): def lookup_isbn(self,isbn):
return {'isbn':isbn} return {'isbn':isbn}
def lookup_lccn(self,lccn): def lookup_lccn(self,lccn):
return {'lccn':lccn} return {'lccn':lccn}