codekasten/WKNcharts/wknGUI.py
2006-06-10 12:18:28 +00:00

93 lines
2.9 KiB
Python

#/usr/bin/env python
__version__="0.3"
__author__="AGE"
__date__="02006-06-07"
class WknGUI:
"""
This is a GTK-Frontend for getWKNcharts.py
"""
import sys, time
wkns = ""
log = ""
def __init__(self, gtk):
self.gladefile = "wkncharts.glade"
self.gtk = gtk
self.gladefile = "wkncharts.glade"
self.wkngui = self.gtk.glade.XML(self.gladefile)
actions = { "on_read_settings_clicked": self.clicked_read_settings,
"on_cancel_settings_clicked": self.clicked_cancel_settings,
"on_choose_srcfile_clicked": self.clicked_choose_srcfile,
"on_bu_wget_charts_clicked": self.clicked_wget_charts,
"on_bu_exit_clicked": self.exit,
"on_window1_destroy": self.exit
}
self.wkngui.signal_autoconnect (actions)
self.log += "\n"+self.time.strftime('%H:%M:%S')+" "
self.log += "Programm gestartet "
self.clicked_read_settings(self)
def clicked_wget_charts(self, widget):
import getWKNcharts
from threading import Thread
'''the real download logic lies in getWKNcharts
that's why, we let it read in the wkn file'''
charts = getWKNcharts.WKNCharts()
charts.readwkndictfromstring(self.wkns)
charts.set_times([30, 300])
self.add_log("beginne Download der WKNS")
## downlaoding in threads, so the gui won't hang
## giving it 'self', so that it can use the logging window
Thread(target=charts.getallcharts,args=(self,)).start()
## unthreaded version
#charts.getallcharts(self)
self.add_log("Download abgeschlossen")
def clicked_read_settings(self, widget):
self.outputfield = self.wkngui.get_widget("tf_srcfile")
self.textbuffer = self.outputfield.get_buffer()
file = self.textbuffer.get_text(*self.textbuffer.get_bounds ())
try:
tmpfile = open(file, "r")
filecontent = tmpfile.read()
tmpfile.close()
self.add_log("%s erfolgreich eingelesen" % file)
except:
self.buffer.set_text(filecontent)
self.log = "Achtung: Konnte %s nicht einlesen" % file
self.wkns = (filecontent)
self.tf_wknlist = self.wkngui.get_widget("tf_wknlist")
self.wknlistbuffer = self.tf_wknlist.get_buffer()
self.wknlistbuffer.set_text(self.wkns)
self.add_log("neue Einstellungen gespeichert")
def clicked_cancel_settings(self, widget):
'''TODO:
self.add_log("alte Einstellungen wieder hergestellt")
'''
pass
def clicked_choose_srcfile(self, widget):
import filechooser
fcd = filechooser.FileChooserDialog()
filename = fcd.getfilename()
self.outputfield = self.wkngui.get_widget("tf_srcfile")
self.textbuffer = self.outputfield.get_buffer()
if filename:
self.textbuffer.set_text(filename)
else:
self.textbuffer.set_text("keine Datei ausgewaehlt")
def add_log(self, text):
self.logbuch = self.wkngui.get_widget("tf_logbook")
self.buffer = self.logbuch.get_buffer()
self.log += "\n"+self.time.strftime('%H:%M:%S')+" "
self.log += text
self.buffer.set_text(self.log)
def exit(self, widget):
print "ciao ciao"
self.sys.exit(1)