codekasten/FilmBar/filmGUI.py
2006-06-13 00:32:48 +00:00

143 lines
5.1 KiB
Python

#/usr/bin/env python
__version__="dev0.4"
__author__="AGE"
__date__="02004-08-06"
import sys
import time
import myFilms
class FilmGUI:
"""
The frontend for the FilmPseudoDB
"""
def __init__(self, gtk):
self.log = time.asctime() +" the beat starts here..\n"
# read config file
self.readConfig()
# gtk is given, it has to be known in the whole class
self.gtk = gtk
# define here, which gladefile to use for the frontend
# uncomment if you want to use the one from the configfile
self.gladefile = "fba.glade"
self.filmgui = self.gtk.glade.XML(self.gladefile)
# set button handlers, easypeasy -> buttonname:functionname
actions = { "on_bu_insertfilm_clicked": self.clicked_insertfilm,
"on_bu_apply_files_clicked": self.clicked_apply_files,
"on_bu_read_xml_clicked": self.clicked_read_xml,
"on_bu_read_joerchs_clicked": self.clicked_read_joerchs,
#"on_bu_cancel_clicked": (self.gtk.mainquit),
#"on_bu_cancel_clicked": self.exit,
"on_window1_destroy_event": self.exit
}
# connect the actions to special events
self.filmgui.signal_autoconnect (actions)
# fill some textfields with configdata
self.filmgui.get_widget("entry6").set_text(self.htmlfilmlist)
self.filmgui.get_widget("entry7").set_text(self.xmlfilmlistin)
self.filmgui.get_widget("entry8").set_text(self.xmlfilmlistout)
self.filmgui.get_widget("entry10").set_text(self.htmlfilmlist)
self.filmgui.get_widget("entry11").set_text(self.xmlfilmlistin)
# connect the logwindow
self.textview = self.filmgui.get_widget("textview1")
self.textbuffer = self.textview.get_buffer()
self.textbuffer.set_text(self.log)
self.log += "\n"+time.strftime('%H:%M:%S')
self.log += "\n\t ___program completely started___\n"
self.textbuffer.set_text(self.log)
# connect the xml_output_window
self.textview2 = self.filmgui.get_widget("textview2")
self.textbuffer2= self.textview2.get_buffer()
# finally the most important step: create a myFilms object
self.mf = myFilms.MyFilms()
return
# =======================================================
def readConfig(self):
"""
Get the Configuration from standard config file (see: Preferences)
"""
import preferences
myPrefs = preferences.Preferences()
self.gladefile = myPrefs["gladefile"]
self.htmlfilmlist = myPrefs["htmlfilmlist"]
self.xmlfilmlistin = myPrefs["xmlfilmlistin"]
self.xmlfilmlistout = myPrefs["xmlfilmlistout"]
self.log += "\n"+time.strftime('%H:%M:%S')
self.log += " read config file\n"
# =======================================================
def clicked_insertfilm(self, widget):
title = self.filmgui.get_widget("entry1").get_text()
lang = self.filmgui.get_widget("entry2").get_text()
codec = self.filmgui.get_widget("entry3").get_text()
cd = self.filmgui.get_widget("entry4").get_text()
comment = self.filmgui.get_widget("entry5").get_text()
datalist = [title,lang,codec,cd,comment]
self.mf.addFilm(datalist)
self.mf.saveToXMLFile()
self.log += "\n"+time.strftime('%H:%M:%S')
self.log += " insert film"
self.log += "\n\t\""+title+"\" to: " +self.xmlfilmlistout
self.textbuffer.set_text(self.log)
self.filmgui.get_widget("entry1").set_text("")
#self.filmgui.get_widget("entry2").set_text("")
#self.filmgui.get_widget("entry3").set_text("")
#self.filmgui.get_widget("entry4").set_text("")
#self.filmgui.get_widget("entry5").set_text("")
self.textbuffer.set_text(self.log)
# =======================================================
def clicked_apply_files(self, widget):
self.htmlfilmlist = self.filmgui.get_widget("entry6").get_text()
self.xmlfilmlistin = self.filmgui.get_widget("entry7").get_text()
self.xmlfilmlistout = self.filmgui.get_widget("entry8").get_text()
#self.mf = myFilms.MyFilms(self.xmlfilmlistin)
self.mf.setXMLFile(self.xmlfilmlistout)
self.mf.fillfromXML()
# timeformet likewise 15:47:12
self.log += "\n"+time.strftime('%H:%M:%S')
self.log += " set files"
self.log += "\n\tjoerch import:\t"+self.htmlfilmlist
self.log += "\n\txml import:\t"+self.xmlfilmlistin
self.log += "\n\txml export:\t"+self.xmlfilmlistout
self.log += "\n"
self.textbuffer.set_text(self.log)
# =======================================================
def clicked_read_xml(self, widget):
xmlstuff = self.xmlfilmlistout + " \n===============================\n"
xmlstuff += open(self.xmlfilmlistout).read()
self.textbuffer2.set_text(xmlstuff)
# =======================================================
def clicked_read_joerchs(self, widget):
# debugmode abchecken
cb2 = self.filmgui.get_widget("checkbutton2")
self.mf.setXMLFile(self.xmlfilmlistout)
debugout = self.mf.saveXMLfromJoerchs(self.htmlfilmlist, int(cb2.get_active()))
self.log += "\n"+time.strftime('%H:%M:%S')
self.log += " joerchs"
self.log += "\n\tread html: "+self.htmlfilmlist
self.log += "\n\tsaved xml: "+self.xmlfilmlistout
self.log += "\n\t"+debugout
self.textbuffer.set_text(self.log)
# =======================================================
def exit(self, widget):
print "geh kacken.."
self.gtk.mainquit
if __name__ == "__main__":
'''
xmlfilmlist = "myFilms.xml"
import myFilms
mf = myFilms.MyFilms(xmlfilmlist)
mf.addFilm()
mf.setXMLFile("fee")
mf.saveToXMLFile()
'''