def add_book(self,create): # Set background color on status back to white self.set_kvattr('newbook','newbook_status_text','background_color',[1,1,1,1]) rfidcode = -99 if create: try: # Create a new book with the provided values # TODO: Need to do some value checking, eg year, copy title = self.get_kvattr('newbook','newbook_title_text','text') author = self.get_kvattr('newbook','newbook_author_text','text') year = self.get_kvattr('newbook','newbook_year_text','text') copy = self.get_kvattr('newbook','newbook_copy_text','text') except: # TODO: Log this in an error system self.set_kvattr('newbook','newbook_status_text','text','No book info!') self.set_kvattr('newbook','newbook_status_text','background_color',[1,0,0,1]) self.set_kvattr('newbook','newbook_status_text','text','Awaiting RFID Code....') self.set_kvattr('newbook','newbook_status_text','background_color',[1,0.7,0,1]) try: #TODO: get a real RFID code here rfidcode = rfid.get_rfid() print rfidcode self.set_kvattr('newbook','newbook_rfid_text','text',str(rfidcode)) while rfidcode in self.data_books: self.set_kvattr('newbook','newbook_status_text','text','RFID Code in use!') self.set_kvattr('newbook','newbook_status_text','background_color',[1,0,0,1]) rfidcode = rfid.get_rfid() self.set_kvattr('newbook','newbook_rfid_text','text',str(rfidcode)) except: # TODO: Log this in an error system self.set_kvattr('newbook','newbook_status_text','text','Bad RFID Read!') self.set_kvattr('newbook','newbook_status_text','background_color',[1,0,0,1]) try: # Now add the book to our list print title, author, year, copy, rfidcode newbook = book.Book(title, author, year, copy, rfidcode) print newbook self.data_books[rfidcode] = newbook except: print "could not add data" try: write_library_data(self.data_users, self.data_books, self.data_filenames) self.set_kvattr('newbook','newbook_status_text','text','Success!') self.set_kvattr('newbook','newbook_status_text','background_color',[0,1,0,1]) except: # TODO: Log this in an error system self.set_kvattr('newbook','newbook_status_text','text',"Can't save book data!") self.set_kvattr('newbook','newbook_status_text','background_color',[1,0,0,1]) else: # Reset text and let the user know this worked self.set_kvattr('newbook','newbook_title_text','text','') self.set_kvattr('newbook','newbook_author_text','text','') self.set_kvattr('newbook','newbook_year_text','text','') self.set_kvattr('newbook','newbook_copy_text','text','1') self.set_kvattr('newbook','newbook_rfid_text','text','') self.go_screen('librarian') return
def checkout(self): # Get the toggle state of the buton. # If we are off, then turn on and start looking for books # Also modify the checkin toggle state # Wait for a little while and then loop, this way we can catch UI updates # Unfortunately, we have to do this for user and librarian screens self.set_kvattr('user', 'user_checkin', 'state', 'normal') self.set_kvattr('user', 'user_checkout', 'state', 'down') #self.set_kvattr('librarian', 'librarian_checkout', 'state', 'down') user = self.data_users[self.current_user] while 1: # Get a book id book_id = rfid.get_rfid() # Make sure it isn't already checkedout if book_id in self.data_books: book = self.data_books[book_id] if book.status: # Check the book out to this user user.checkout(book_id) book.checkout() # Update the user screen self.set_kvattr('user','user_status_text','text','Checkout successful!') self.set_kvattr('user','user_status_text','background_color',[0,1,0,1]) # Pickle book and user data in case of a crash write_library_data(self.data_users, self.data_books, self.data_filenames) else: self.set_kvattr('user','user_status_text','text','Book already checked out.') self.set_kvattr('user','user_status_text','background_color',[1,0,0,1]) else: self.set_kvattr('user','user_status_text','text','Book not in system!') self.set_kvattr('user','user_status_text','background_color',[1,0,0,1]) pass