Example #1
0
File: book.py Project: koe-/ebola
	def to_xml(self, library=None):
		d = self.to_dict()
		
		res = "<book>\n"
		for x in d:
			if x == "authors":
				if len(d["authors"]) > 0:
					res = res + "  <authors>\n"+ \
								"    <name>" + ("</name>\n    <name>".join([Utilities.escape_xml(y) for y in d["authors"]])) + "</name>\n"+ \
								"  </authors>\n"
			elif x == "categories" and library != None:
				if len(d["categories"]) > 0:
					res = res + "  <categories>\n"
					col = library.categories.collection
					for i in d["categories"]:
						res = res + \
								"    <item>\n" + \
								"      " + "".join(["<n color='" + col[y].color + "'>" + Utilities.escape_xml(col[y].name) + "</n>" for y in library.categories.get_full_category_ids(i)]) + "\n" +\
								"    </item>\n"
					res = res + "  </categories>\n"
			elif x == "isbn10":
				res = res + "  <isbn10>" + ISBN.to_string(d["isbn10"], set_hyphen=False) + "</isbn10>\n"
			elif x == "isbn13":
				res = res + "  <isbn13>" + ISBN.to_string(d["isbn13"], set_hyphen=False) + "</isbn13>\n"
			elif d[x] != None:
				res = res + "  <" + x + ">" + Utilities.escape_xml(str(d[x])) + "</" + x + ">\n"
		return res + "</book>\n"
Example #2
0
	def add_book_item(self, book, library = None):
		row = Gtk.ListBoxRow()
		row.ebola_labels = {}
		
		self.connect("row-selected", self.on_row_selected)
		#row.connect("focus-in-event", self.on_focus_in)
		
		hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
		vimgbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
		vimgbox.pack_start(Gtk.Alignment(), False, False, 0)
		if book.cover == None:
			pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("unknown_cover.svg", 105, 74)
			missingImg = Gtk.Image.new_from_pixbuf(pixbuf)
			vimgbox.pack_start(missingImg, False, False, 0)
		else:
			if book.cover[:7] == "file://":
				pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(book.cover[7:], 105, 74)
				missingImg = Gtk.Image.new_from_pixbuf(pixbuf)
				vimgbox.pack_start(missingImg, False, False, 0)
		hbox.pack_start(vimgbox, False, False, 0)
		
		vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
		
		lbl = Gtk.Label(xalign=0)
		lbl.set_markup("<big><b>" + Utilities.escape_xml(str(book.title)) + "</b></big>")
		lbl.set_justify(Gtk.Justification.LEFT)
		lbl.set_margin_right(5)
		row.ebola_labels["title"] = lbl
		
		hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
		hbox2.pack_start(lbl, True, True, 0)
		
		vbox.pack_start(hbox2, True, True, 0)
		
		lbl = Gtk.Label(xalign=0)
		lbl.set_markup("<b><i>" + Utilities.escape_xml(", ".join(book.authors)) + "</i></b>")
		lbl.set_justify(Gtk.Justification.LEFT)
		vbox.pack_start(lbl, True, True, 0)
		row.ebola_labels["authors"] = lbl
		
		cats = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
		for cid in book.categories:
			cats.pack_start(self.category_selector_widget(cid, library), False, False, 0)
		vbox.pack_start(cats, False, True, 0)
		
		lbl = Gtk.Label(xalign=0)
		
		edition = ""
		if book.edition != None:
			edition = str(book.edition) + ". Edition, "
		
		lbl.set_markup("<b>Publisher:</b> " + Utilities.escape_xml(str(book.publisher)) + ", " + Utilities.escape_xml(edition + str(book.publication_date)))
		lbl.set_justify(Gtk.Justification.LEFT)
		vbox.pack_start(lbl, True, True, 0)
		row.ebola_labels["pubInfo"] = lbl
		
		lbl = Gtk.Label(xalign=0)
		lbl.set_markup("<i>ISBN " + ISBN.to_string(book.isbn13) + "</i>")
		lbl.set_justify(Gtk.Justification.LEFT)
		vbox.pack_start(lbl, True, True, 0)
		row.ebola_labels["isbn"] = lbl
		
		hbox.pack_start(vbox, True, True, 0)
		row.add(hbox)
		self.add(row)
		row.show_all()
		
		row.ebola_button_show_in_folder = Gtk.LinkButton(book.uri, "Show in folder")
		row.ebola_button_show_in_folder.set_margin_top(5)
		row.ebola_button_show_in_folder.set_margin_bottom(5)
		row.ebola_button_show_in_folder.set_margin_right(5)
		row.ebola_button_show_in_folder.connect("activate-link", self.on_show_in_folder)
		hbox2.pack_end(row.ebola_button_show_in_folder, False, True, 0)
		
		row.ebola_button_open = Gtk.LinkButton(book.uri, "Open")
		row.ebola_button_open.set_margin_top(5)
		row.ebola_button_open.set_margin_bottom(5)
		row.ebola_button_open.set_margin_right(5)
		hbox2.pack_end(row.ebola_button_open, False, True, 0)
		
		row.ebola_book_description = None
		if book.description != None and book.description != "":
			lbl = Gtk.Label(xalign=0)
			lbl.set_markup("\n<b>Description:</b> " + Utilities.escape_xml(str(book.description)))
			lbl.set_justify(Gtk.Justification.LEFT)
			lbl.set_line_wrap(True)
			lbl.set_selectable(True)
			lbl.set_lines(3)
			
			revealer = Gtk.Revealer()
			revealer.set_reveal_child(False)
			revealer.add(lbl)
			
			lbl = Gtk.Label()
			lbl.set_markup("<a href='#'>Show Description</a>")
			lbl.ebola_revealer = revealer
			lbl.connect("activate-link", self.toggle_description)
			
			row.ebola_book_description = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
			row.ebola_book_description.pack_end(lbl, True, True, 0)
			row.ebola_book_description.pack_end(revealer, True, True, 0)
			
			vbox.pack_start(row.ebola_book_description, True, True, 0)
		
		self.rows.append(row)