Made sizes of windows better, and easier to change
authorJohn Ladan <jladan@uwaterloo.ca>
Sun, 27 Oct 2013 21:04:35 +0000 (17:04 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sun, 27 Oct 2013 21:04:35 +0000 (17:04 -0400)
browser.py
form.py
librarian.py

index 6c14617..8a1b21f 100644 (file)
@@ -14,14 +14,14 @@ class browserWindow:
     # column definitions are in (label, weight, specified width) triples
     columnDefs = [('something',1,None)]
     mx = my = 0
-    cx = cy = 0
     # for searches
     last_search = ""
     found_index = 0
 
-    def __init__(self,window,helpbar):
+    def __init__(self,window,helpbar, height=50, width=80):
         self.w = window
         self.hb = helpbar
+        self.w.resize(height,width)
         self.updateGeometry()
         self.commands = self.cs+self.commands
 
@@ -32,9 +32,6 @@ class browserWindow:
 
     def updateGeometry(self):
         (self.my,self.mx)=self.w.getmaxyx()
-        (y,x) = self.w.getbegyx()
-        self.cx = x + self.mx//2
-        self.cy = y + self.my//2
         self.pageSize = self.my-4
         self.calcColWidths()
 
@@ -70,8 +67,9 @@ class browserWindow:
         self.w.refresh()
 
     def centreChild(self,child):
-        (y,x)=child.getmaxyx()
-        child.mvwin(self.cy-y//2,self.cx-x//2)
+        (y,x) = self.w.getbegyx()
+        (r,c) = child.getmaxyx()
+        child.mvwin( y+(self.my-r)//2,x+(self.mx-c)//2)
 
 
     def displayHeader(self):
@@ -238,8 +236,8 @@ class browserWindow:
             else:
                 self.hb.display(self.last_search+' not found')
         elif ch == 270: # F6 Sorts
-            w = curses.newwin(40,20,20,20)
-            cl = columnSelector(w,self.hb)
+            w = curses.newwin(1,1)
+            cl = columnSelector(w,self.hb,40,20)
             self.centreChild(w)
             col = cl.eventLoop()
             cl.clear()
@@ -265,8 +263,8 @@ class trashBrowser(browserWindow):
     # redefinable functions
     def viewSelection(self,book):
         bookid = book['id']
-        w=curses.newwin(1,1,20,20)
-        bf = BookForm(w,self.hb,book)
+        w=curses.newwin(1,1)
+        bf = BookForm(w, self.hb, book, width=self.mx-10)
         self.centreChild(w)
         bf.caption='Viewing Book '+str(bookid)
         bf.blabel='done'
@@ -332,7 +330,7 @@ class bookBrowser(browserWindow):
         bookid = book['id']
         
         w=curses.newwin(1,1)
-        bf=BookForm(w,self.hb,book)
+        bf = BookForm(w,self.hb,book, width=self.mx-20)
         self.centreChild(w)
         bf.caption='Update Book '+str(bookid)
         bf.blabel='update'
@@ -343,8 +341,8 @@ class bookBrowser(browserWindow):
 
     def viewSelection(self,book):
         bookid = book['id']
-        w=curses.newwin(1,1,20,20)
-        bf = BookForm(w,self.hb,book)
+        w=curses.newwin(1,1)
+        bf = BookForm(w,self.hb,book, width=self.mx-20)
         self.centreChild(w)
         bf.caption='Viewing Book '+str(bookid)
         bf.blabel='done'
@@ -352,8 +350,8 @@ class bookBrowser(browserWindow):
         bf.clear()
 
     def categorizeSelection(self,book):
-        w = curses.newwin(40,20,20,20)
-        cs = categorySelector(w,self.hb)
+        w = curses.newwin(1,1)
+        cs = categorySelector(w,self.hb,40,40)
         self.centreChild(w)
         cs.book = book
         cs.refreshCategories()
@@ -530,10 +528,10 @@ class columnSelector(browserWindow):
             {'column': 'publish location'}, {'column': 'pages'}, {'column': 'pagination'}, 
             {'column': 'weight'}, {'column': 'last updated'}]
 
-    def __init__(self,window,helpbar):
+    def __init__(self,window,helpbar,height=40,width=20):
         self.selected = [False,False,False,False,False,False,False,
                          False,False,False,False,False,False,False,False]
-        browserWindow.__init__(self,window,helpbar)
+        browserWindow.__init__(self,window,helpbar,height,width)
 
 
     def eventLoop(self):
diff --git a/form.py b/form.py
index 76b814d..912d55f 100644 (file)
--- a/form.py
+++ b/form.py
@@ -130,9 +130,9 @@ class FormWindow:
 
 
     # Public functions
-    def __init__(self,window,helpbar,book={}):
+    def __init__(self,window,helpbar,book={}, width=50):
         self.w = window
-        self.w.resize(len(self.labels)+6,50)
+        self.w.resize(len(self.labels)+6,width)
         self.hb = helpbar
         self._make_entries()
         self._update_geometry()
index 13ebef7..dfc3e04 100755 (executable)
@@ -82,7 +82,7 @@ def redrawMenu(w,items,highlight):
 def addForm():
     w=curses.newwin(1,1)
     (my,mx)=stdscr.getmaxyx()
-    bf = form.BookForm(w,hb)
+    bf = form.BookForm(w,hb,width=mx-20)
     (r,c)=w.getmaxyx()
     w.mvwin((my-r)//2,(mx-c)//2)
     bf.lookup_isbn=book_data.openLibrary_isbn
@@ -101,28 +101,34 @@ def updateMenu():
 
 def trashMenu():
     (my,mx)=stdscr.getmaxyx()
-    w=curses.newwin(20,80,(my-20)//2,(mx-80)//2)
-    b = browser.trashBrowser(w,hb)
+    w=curses.newwin(3,5)
+    b = browser.trashBrowser(w,hb,my-10,mx-10)
+    (r,c) = w.getmaxyx()
+    w.mvwin((my-r)//2 -2, (mx-c)//2)
     b.refreshBooks()
     b.eventLoop()
     b.clear()
 
 def browseMenu():
     (my,mx)=stdscr.getmaxyx()
-    w=curses.newwin(20,80,(my-20)//2,(mx-80)//2)
-    b = browser.bookBrowser(w,hb)
+    w=curses.newwin(3,5)
+    b = browser.bookBrowser(w,hb, my-10, mx-10)
+    (r,c) = w.getmaxyx()
+    w.mvwin((my-r)//2 -2, (mx-c)//2)
     b.refreshBooks()
     b.eventLoop()
     b.clear()
 
 def catMenu():
     (my,mx)=stdscr.getmaxyx()
-    w=curses.newwin(10,40,(my-10)//2,(mx-40)//2)
-    c = browser.categoryBrowser(w,hb)
-    c.refreshCategories()
-    c.sortByColumn('category')
-    c.eventLoop()
-    c.clear()
+    w=curses.newwin(3,5)
+    cat = browser.categoryBrowser(w,hb, 10,40)
+    (r,c) = w.getmaxyx()
+    w.mvwin((my-r)//2 -2, (mx-c)//2)
+    cat.refreshCategories()
+    cat.sortByColumn('category')
+    cat.eventLoop()
+    cat.clear()
 
 
 m = [("Browse Library", browseMenu),
@@ -132,3 +138,5 @@ m = [("Browse Library", browseMenu),
      ("",exit),
      ("Exit", exit)]
 curses.wrapper(menutest, m)
+
+