Windows are drawn in better positions now
authorJohn Ladan <jladan@uwaterloo.ca>
Fri, 30 Mar 2012 17:00:23 +0000 (13:00 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Fri, 30 Mar 2012 17:00:23 +0000 (13:00 -0400)
browser.py
cursestest.py
librarian.py

index 04550b9..0bf8992 100644 (file)
@@ -12,11 +12,7 @@ class browserWindow:
     # column definitions are in (label, weight, specified width) triples
     columnDefs = [('something',1,None)]
     mx = my = 0
-
-
-    def clear(self):
-        self.w.erase()
-        self.w.refresh()
+    cx = cy = 0
 
     def __init__(self,window,helpbar):
         self.w = window
@@ -29,6 +25,9 @@ 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-3
         self.calcColWidths()
 
@@ -58,6 +57,15 @@ class browserWindow:
         self.w.refresh()
         self.highlight()
 
+    def clear(self):
+        self.w.erase()
+        self.w.refresh()
+
+    def centreChild(self,child):
+        (y,x)=child.getmaxyx()
+        child.mvwin(self.cy-y/2,self.cx-x/2)
+
+
     def displayHeader(self):
         cursor = 1
         for header,width in self.columns:
@@ -151,8 +159,9 @@ class bookBrowser(browserWindow):
     def updateSelection(self,book):
         bookid = book['id']
         
-        w=curses.newwin(1,1,20,20)
+        w=curses.newwin(1,1)
         bf=bookForm(w,self.hb,book)
+        self.centreChild(w)
         bf.caption='Update Book '+str(bookid)
         bf.blabel='update'
         newbook = bf.eventLoop()
@@ -164,6 +173,7 @@ class bookBrowser(browserWindow):
         bookid = book['id']
         w=curses.newwin(1,1,20,20)
         bf = bookForm(w,self.hb,book)
+        self.centreChild(w)
         bf.caption='Viewing Book '+str(bookid)
         bf.blabel='done'
         bf.eventLoop()
@@ -172,6 +182,7 @@ class bookBrowser(browserWindow):
     def categorizeSelection(self,book):
         w = curses.newwin(40,20,20,20)
         cs = categorySelector(w,self.hb)
+        self.centreChild(w)
         cs.book = book
         cs.refreshCategories()
         cs.eventLoop()
@@ -228,6 +239,7 @@ class categoryBrowser(browserWindow):
     def addCategory(self):
         w = curses.newwin(1,1,10,10)
         cf = categoryForm(w,self.hb)
+        self.centreChild(w)
         cats = cf.eventLoop()
         for c in cats:
             db.addCategory(c)
@@ -290,6 +302,7 @@ class categorySelector(browserWindow):
     def addCategory(self):
         w = curses.newwin(1,1,10,10)
         cf = categoryForm(w,self.hb)
+        self.centreChild(w)
         cats = cf.eventLoop()
         for c in cats:
             db.addCategory(c)
index 524061f..2d6b5c8 100755 (executable)
@@ -2,62 +2,14 @@
 
 import curses
 
-
-def showBold(stdscr):
-    stdscr.addstr("Type any character to see it in bold\n")
-    ch = stdscr.getch()
-
-    if (ch==curses.KEY_F1):
-        stdscr.addstr("F1 Key pressed")
-
-    else:
-        stdscr.addstr("The key pressed is ")
-        stdscr.addch(ch, curses.A_BOLD)
-
-        stdscr.refresh()
-        stdscr.getch()
-
-def simplePrintw(stdscr):
-    mesg = "Just a string"
-
-    (row,col) = stdscr.getmaxyx()
-    stdscr.addstr(row/2, (col-len(mesg))/2, mesg)
-    stdscr.addstr(row-2, 0, "This screen has " +str(row)+ " rows and " +str(col)+ " columns\n")
-
-    stdscr.addstr("Try resizing window and running it again")
-    stdscr.refresh()
-    stdscr.getch()
-
-def menutest(stdscr, l):
-    curses.curs_set(0)
-    (rows,cols)=stdscr.getmaxyx()
-    w = curses.newwin(10,40,(rows-10)/2, (cols-40)/2)
-    w.keypad(1)
-    i=0
-    for mitem in l:
-        w.addstr(i,0,mitem)
-        i+=1
-
-    highlight=0
-    w.chgat(highlight,0, curses.A_REVERSE)
+def windowLayout(stdscr):
+    w = curses.newwin(5,10,10,10)
+    w.box()
     w.refresh()
-    ch=w.getch()
-    while (ch!=113): # leave on q
-        if ch==curses.KEY_UP:
-            if highlight!=0:
-                w.chgat(highlight,0, 0)
-                highlight -= 1
-                w.chgat(highlight,0, curses.A_REVERSE)
-        if ch==curses.KEY_DOWN:
-            if highlight!=len(l)-1:
-                w.chgat(highlight,0, 0)
-                highlight += 1
-                w.chgat(highlight,0, curses.A_REVERSE)
-        w.refresh()
-        ch = w.getch()
-    
-    curses.curs_set(1)
-
+    w.getch()
+    w2 = w.derwin(2,7,2,2)
+    w2.box()
+    w2.refresh()
+    w2.getch()
 
-menu = ["item 1", "poo", "add book/article/stuff", "update", "remove"]
-curses.wrapper(menutest, menu)
+curses.wrapper(windowLayout)
index 56dcb34..8864df5 100755 (executable)
@@ -122,9 +122,9 @@ def catMenu():
 
 
 m = [("Browse Library", browseMenu),
-     ("Add Book or other item", addForm),
-     ("View the categories", catMenu),
-     ("Remove book from catalogue", deleteMenu),
+     ("Add Book", addForm),
+     ("Categories", catMenu),
+     ("View Trash", deleteMenu),
      ("",exit),
      ("Exit", exit)]
 curses.wrapper(menutest, m)