#!/usr/bin/python

# pybook
# written by Thesandlord and posted onto internettablettalk forum
# this is a mini front end for testing liqbase book reading functionality on your own books
# this may be removed in  future revisions and was just a way to test liqreader component.
# http://www.internettablettalk.com/forums/showthread.php?t=21259&page=2


import gtk
import pygtk
import os
import hildon

class Namespace: pass
def main(x):
	ns = Namespace()
	ns.pixelDouble = False
	ns.fullscreen = False
	window = hildon.Window()
	def quiter(x):
		gtk.main_quit()

	window.connect("destroy", quiter)

	tab = gtk.Table(2, 5)
	tab.show()

	def filesel(x):

		def ok(x):
			filename = game.get_filename()
			game.destroy()
			global snesg
			snesg = filename
			return filename

		game = gtk.FileSelection(title="Pick a Book")
		game.cancel_button.connect("clicked", lambda w: game.destroy())
		game.ok_button.connect("clicked", ok)
		game.set_filename("/media/")
		a = game.run()
		return a

	def startit(snesg):
		os.popen("/media/mmc1/liqbase/liqbase " + snesg)
	
	fullscreenButton = gtk.CheckButton("Fullscreen");
	def toggleFullscreen(x):
		if fullscreenButton.get_active():
			ns.fullscreen = True
		else:
			ns.fullscreen = False

	fileb1 = gtk.Button("Select Book")
	fileb1.connect('clicked', filesel)
	fileb1.show()

	tab.attach(fileb1, 0, 2, 0, 1)

	def changed_cb(combobox):
		model = combobox.get_model()
		active = combobox.get_active()
		if active < 0:
			return None
		global multi
		multi = model[active][0]
		return model[active][0]

       
	
	notesString = "Controls: Select Read a Book to read. Use fingers to scroll, etc... 4 MB maximum filesize, only .txt files"
	notes = gtk.Label(notesString)
	notes.set_line_wrap(True)
	notes.show()
	tab.attach(notes, 0, 2, 3, 4)

	def e(x):
		startit(snesg)

	start = gtk.Button("Start Reading!")
	start.connect("clicked", e)
	start.show()

	tab.attach(start, 0, 2, 4, 5)

	window.add(tab)
	window.show()
	gtk.main()

x = "0"
main(x)







