本文整理汇总了Python中library.Library类的典型用法代码示例。如果您正苦于以下问题:Python Library类的具体用法?Python Library怎么用?Python Library使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Library类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_duplicate_books
def test_duplicate_books(self):
testlib = Library()
testlib.add_book(576.82, 'A New History of Life')
testlib.add_book(576.82, 'A New History of Life')
assert len(testlib.shelves[5].books) == 2
testlib.remove_book(576.82)
assert len(testlib.shelves[5].books) == 1
示例2: test_add_book
def test_add_book(self):
Library(self.store, ["Fantasy"])
Library.add_book(self.books[0])
self.assertEqual([self.books[0]], Library.books)
self.add_books([self.books[0], self.books[1]], Library)
self.assertEqual([self.books[0], self.books[1]], Library.books)
os.remove(os.path.realpath(self.store))
示例3: removeBook
def removeBook(self):
"""
Use the entered information if it is valid in order to remove the
book after the Add button is pushed.
"""
data = [self.titleEdit.text(), self.authorEdit.text(), self.yearEdit.text(), self.genre_options.currentText()]
invalid_data = Validations.check_all(*data)
if invalid_data == []:
book = Book(
self.titleEdit.text(),
self.authorEdit.text(),
self.yearEdit.text(),
self.genre_options.currentText(),
0,
0,
)
Library.remove_book(book)
self.label.setText("You removed the book successfully!")
else:
message = "Unsuccessful removal!Invalid:\n"
message += "\n".join(invalid_data)
self.label.setText(message)
for edit in (self.titleEdit, self.authorEdit, self.yearEdit):
edit.clear()
示例4: actualSetBlacklist
def actualSetBlacklist(self, comic_id, pagenum):
if comic_id is not None:
library = Library(self.dm.Session)
if pagenum == 'clear':
library.comicBlacklist(comic_id)
else:
library.comicBlacklist(comic_id, pagenum)
示例5: addBook
def addBook(self):
"""
Use the entered information if it is valid in order to add the
book after the Add button is pushed.
"""
data = [
self.titleEdit.text(),
self.authorEdit.text(),
self.yearEdit.text(),
self.genre_options.currentText(),
self.ratingEdit.text(),
self.copiesEdit.text(),
]
invalid_data = Validations.check_all(*data)
if invalid_data == []:
new_book = Book(*data)
Library.add_book(new_book)
self.label.setText("You added the book successfully!")
else:
message = "Unsuccessful addition!Invalid:\n"
message += "\n".join(invalid_data)
self.label.setText(message)
for gadget in self.gadgets:
if gadget != self.genre_options:
gadget.clear()
示例6: main
def main(args):
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
a = QtGui.QApplication(sys.argv)
library = Library(Config.library_path)
server = Server('*',
Config.req_rep_port,
Config.pub_sub_port,
library)
camera = Camera()
printer = Printer(library)
slide_show = SlideShow(library)
server.msg_recieved.connect(camera.process_cmd)
server.msg_recieved.connect(printer.process_cmd)
server.msg_recieved.connect(slide_show.process_cmd)
printer.printing_image.connect(server.printing_image)
camera.pic_taken.connect(library.add_image)
camera.count_down_changed.connect(server.count_down_changed)
camera.live_stream_activated.connect(server.live_stream_activated)
library.image_added.connect(server.image_added_to_lib)
#qrscanner = QRScanner()
#camera.new_preview_image.connect(qrscanner.new_preview_image)
server_thread = Server.startThread(server)
camera_thread = Camera.startThread(camera)
#camera_thread.started.connect(camera.start_preview)
#qrscanner_thread = QRScanner.startThread(qrscanner)
def exit_app():
print 'stopping camera'
camera.stop()
print camera_thread.wait()
print 'stopping server'
server.stop()
#print server_thread.wait()
print 'exit'
a.quit()
if not args.no_ui:
#w = Widget(camera,server,library,printer,slide_show)
w = Widget(slide_show, camera, printer)
w.grapicsView.scene().take_pic.connect(camera.take_pic)
w.grapicsView.scene().print_pic.connect(printer.print_pic)
w.grapicsView.exit_app.connect(exit_app)
w.show()
camera.count_down_started.connect(slide_show.stop)
library.image_added.connect(slide_show.start)
for image_name in library.get_all_images():
slide_show.start(image_name)
break
sys.exit(a.exec_())
示例7: test_sorting
def test_sorting(self):
testlib = Library()
testlib.add_book(100.32, 'First Book')
testlib.add_book(199.3, 'Last Book')
testlib.add_book(150, 'Middle Book')
assert testlib.shelves[1].books[0].title == 'First Book'
assert testlib.shelves[1].books[1].title == 'Middle Book'
assert testlib.shelves[1].books[2].title == 'Last Book'
示例8: test_book_information_by_title
def test_book_information_by_title(self):
Library(self.store, ["Fantasy", "Thriller"])
self.add_books([self.books[0], self.books[1], self.books[2]], Library)
book_birds = Library.book_information_by_title("Birds")
self.assertEqual([self.books[1], self.books[2]], book_birds)
book_somewhere = Library.book_information_by_title("Somewhere")
self.assertEqual([self.books[0]], book_somewhere)
self.assertEqual([], Library.book_information_by_title("Haha"))
os.remove(os.path.realpath(self.store))
示例9: post
def post(self):
params = decode(self.request.body)
if (params ["request_type"] == "lend"):
Library.lend_book(self, params["book"])
else:
if(params["request_type"] == "return"):
Library.return_book(self, params["book"])
else:
self.request.body("> Invalid operation!")
示例10: do_activate
def do_activate(self):
# Initialize snippets library
library = Library()
if platform.system() == 'Windows':
snippetsdir = os.path.expanduser('~/gedit/snippets')
else:
snippetsdir = os.path.join(GLib.get_user_config_dir(), 'gedit/snippets')
library.set_dirs(snippetsdir, self.system_dirs())
示例11: update_table
def update_table(self):
"""
Update the table after clicking the Search button.
"""
self.table.setRowCount(0)
self.table.setColumnCount(0)
search = self.searchEdit.text()
if self.author.isChecked():
results = Library.book_information_by_author(search)
elif self.title.isChecked():
results = Library.book_information_by_title(search)
else:
results = Library.book_information_by_title_author(search)
self.table = QtGui.QTableWidget(len(results), 10, self)
headers = ("Title", "Author's name", "Published in", "Genre",
"Rating", "Copies", "Get", "Return", "Like", " Dislike")
self.table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.table.setHorizontalHeaderLabels(headers)
self.table.resizeColumnsToContents()
self.table.resizeRowsToContents()
widths = [150, 150, 90, 80, 70, 60, 50, 60, 50, 70]
for col, width in zip(range(9), widths):
self.table.setColumnWidth(col, width)
self.table.horizontalHeader().setStretchLastSection(True)
for row in range(len(results)):
book = results[row]
col = 0
for column in (book.title, book.author, book.year, book.genre,
book.rating, book.number_of_copies):
item = QtGui.QTableWidgetItem(str(column))
self.table.setItem(row, col, item)
col += 1
for row in range(len(results)):
get_btn = QtGui.QPushButton("Get")
get_btn.setMinimumSize(50, 30)
get_btn.clicked.connect(partial(self.get_a_copy, row))
self.table.setCellWidget(row, 6, get_btn)
return_btn = QtGui.QPushButton("Return")
return_btn.setMinimumSize(50, 30)
return_btn.clicked.connect(partial(self.return_a_copy, row))
self.table.setCellWidget(row, 7, return_btn)
like_btn = QtGui.QPushButton("Like")
like_btn.setMinimumSize(50, 30)
like_btn.clicked.connect(partial(self.like_a_book, row))
self.table.setCellWidget(row, 8, like_btn)
dislike_btn = QtGui.QPushButton("Dislike")
dislike_btn.setMinimumSize(50, 30)
dislike_btn.clicked.connect(partial(self.dislike_a_book, row))
self.table.setCellWidget(row, 9, dislike_btn)
self.grid.addWidget(self.table, 1, 0)
示例12: test_book_information_by_author
def test_book_information_by_author(self):
Library(self.store, ["Fantasy", "Thriller"])
self.add_books(self.books, Library)
book_steven = Library.book_information_by_author("Steve Law")
self.assertEqual([self.books[0]], book_steven)
book_john = Library.book_information_by_author("John White")
self.assertEqual([self.books[1], self.books[4]], book_john)
book_steve = Library.book_information_by_author("Steve Tyler")
self.assertEqual([self.books[2], self.books[3]], book_steve)
self.assertEqual([], Library.book_information_by_author("Haha"))
os.remove(os.path.realpath(self.store))
示例13: test_create_genre_dict
def test_create_genre_dict(self):
Library(self.store, ["Fantasy", "Thriller"])
self.add_books([self.books[0], self.books[1], self.books[2]], Library)
Library.create_genre_dict()
expected_dict = {"Fantasy": [self.books[1], self.books[0]],
"Thriller": [self.books[2]]}
self.assertEqual(expected_dict, Library.genre_dict)
Library.add_book(self.books[3])
expected_dict["Thriller"].append(self.books[3])
self.assertEqual(expected_dict, Library.genre_dict)
os.remove(os.path.realpath(self.store))
示例14: generate
def generate(n):
lib = Library()
for i in range(0, n):
lib.append(Book(
"Author{0}".format(random.randint(1, n)),
"Title{0}".format(random.randint(1, n)),
random.randint(1950, 2015),
"Publ{0}".format(random.randint(1, n))))
return lib
示例15: test_remove_book
def test_remove_book(self):
testlib = Library()
testlib.add_book(576.82, 'A New History of Life')
testlib.add_book(575.01, 'An Old History of Life')
assert len(testlib.shelves[5].books) == 2
testlib.remove_book(576.82)
assert len(testlib.shelves[5].books) == 1
# remove nonexistent book
testlib.remove_book(501.2)
assert len(testlib.shelves[5].books) == 1