codekasten/WKNcharts/wknGUI.py
age 2a2986996a * bildbetrachter eingebaut
* loglevel eingefuehrt
 * bildtab aus notepad entfernt
2006-06-15 09:10:52 +00:00

122 lines
3.8 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
from threading import Thread
wkns = ""
log = ""
maxloglevel = 1
'''0:no logging; 1:errors; 2:status messages; 3:all '''
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_pics_clicked": self.clicked_show_pics,
"on_bu_exit_clicked": self.exit,
"on_window1_destroy": self.exit
}
self.wkngui.signal_autoconnect (actions)
# read the config at program start
self.clicked_read_settings(self)
def clicked_wget_charts(self, widget):
import getWKNcharts
'''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])
charts.set_times([30])
self.add_log("beginne Download der WKNS",2)
## downlaoding in threads, so the gui won't hang
## giving it 'self', so that it can use the logging window
self.Thread(target=charts.getallcharts,args=(self,)).start()
## unthreaded version
#charts.getallcharts(self)
self.add_log("Download abgeschlossen",2)
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()
log = "\"%s\" erfolgreich eingelesen" % file
self.add_log(log, 2)
except:
log = "Achtung: Konnte \"%s\" nicht einlesen!" % file
self.add_log("verdammt: "+str(self.sys.exc_info()[0]),1)
self.add_log(log, 1)
return
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", 2)
def clicked_cancel_settings(self, widget):
'''TODO:
self.add_log("alte Einstellungen wieder hergestellt")
'''
pass
def clicked_choose_srcfile(self, widget):
try:
import filechooser
fcd = filechooser.FileChooserDialog()
filename = fcd.getfilename()
except:
self.add_log("Dateiauswahl Dialog konnte nicht gestartet werden",1)
self.add_log("verdammt: "+str(self.sys.exc_info()[0]),1)
raise
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, loglevel=2):
if loglevel <= self.maxloglevel:
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 += " (L" + str(loglevel) + ") "
self.log += text
self.buffer.set_text(self.log)
def clicked_show_pics(self, widget):
'''this is for now 'cause i'm to lazy to implement the viewer
in a better way'''
#self.ci = self.wkngui.get_widget("chartimage")
#self.ci.set_from_file("foo.png")
self.add_log("Bildbetrachter gestartet", 2)
try:
import pyview
pv = pyview.PyView("pyview.glad","pyview","./images")
pv.show_window
except:
self.add_log("konnte Bildbetrachter nicht laden", 1)
self.add_log(str(self.sys.exc_info()[0]),1)
raise
def exit(self, widget):
print "ciao ciao"
self.sys.exit(1)