2006-06-07 11:03:58 +02:00
|
|
|
#/usr/bin/env python
|
|
|
|
__version__="0.3"
|
|
|
|
__author__="AGE"
|
|
|
|
__date__="02006-06-07"
|
|
|
|
|
|
|
|
class WknGUI:
|
|
|
|
"""
|
|
|
|
This is a GTK-Frontend for getWKNcharts.py
|
|
|
|
"""
|
2006-06-09 09:20:21 +02:00
|
|
|
import sys, time
|
2006-06-15 11:10:52 +02:00
|
|
|
from threading import Thread
|
2006-06-15 18:12:27 +02:00
|
|
|
configs = {}
|
2006-06-09 09:20:21 +02:00
|
|
|
wkns = ""
|
|
|
|
log = ""
|
2006-06-07 11:03:58 +02:00
|
|
|
|
|
|
|
def __init__(self, gtk):
|
|
|
|
self.gladefile = "wkncharts.glade"
|
|
|
|
self.gtk = gtk
|
|
|
|
self.wkngui = self.gtk.glade.XML(self.gladefile)
|
2006-06-09 09:20:21 +02:00
|
|
|
actions = { "on_read_settings_clicked": self.clicked_read_settings,
|
|
|
|
"on_cancel_settings_clicked": self.clicked_cancel_settings,
|
2006-06-07 11:03:58 +02:00
|
|
|
"on_choose_srcfile_clicked": self.clicked_choose_srcfile,
|
2006-06-15 18:12:27 +02:00
|
|
|
"on_choose_dstdir_clicked": self.clicked_choose_dstdir,
|
2006-06-09 09:20:21 +02:00
|
|
|
"on_bu_wget_charts_clicked": self.clicked_wget_charts,
|
2006-06-14 01:13:52 +02:00
|
|
|
"on_bu_pics_clicked": self.clicked_show_pics,
|
2006-06-09 09:20:21 +02:00
|
|
|
"on_bu_exit_clicked": self.exit,
|
2006-06-07 11:03:58 +02:00
|
|
|
"on_window1_destroy": self.exit
|
|
|
|
}
|
|
|
|
self.wkngui.signal_autoconnect (actions)
|
2006-06-15 11:10:52 +02:00
|
|
|
# read the config at program start
|
2006-06-09 09:20:21 +02:00
|
|
|
self.clicked_read_settings(self)
|
2006-06-07 11:03:58 +02:00
|
|
|
|
2006-06-09 09:20:21 +02:00
|
|
|
def clicked_wget_charts(self, widget):
|
|
|
|
import getWKNcharts
|
2006-06-15 18:12:27 +02:00
|
|
|
'''the real download logic is in getWKNcharts
|
2006-06-09 09:20:21 +02:00
|
|
|
that's why, we let it read in the wkn file'''
|
|
|
|
charts = getWKNcharts.WKNCharts()
|
|
|
|
charts.readwkndictfromstring(self.wkns)
|
2006-06-16 00:00:11 +02:00
|
|
|
## configure getWKNcharts
|
2006-06-15 18:12:27 +02:00
|
|
|
charts.set_times(self.configs["times"])
|
|
|
|
charts.set_dstdir(self.configs["tf_dstdir"])
|
2006-06-09 14:05:30 +02:00
|
|
|
## downlaoding in threads, so the gui won't hang
|
2006-06-10 14:18:28 +02:00
|
|
|
## giving it 'self', so that it can use the logging window
|
2006-06-15 11:10:52 +02:00
|
|
|
self.Thread(target=charts.getallcharts,args=(self,)).start()
|
2006-06-09 14:05:30 +02:00
|
|
|
## unthreaded version
|
|
|
|
#charts.getallcharts(self)
|
2006-06-07 11:03:58 +02:00
|
|
|
|
2006-06-09 09:20:21 +02:00
|
|
|
def clicked_read_settings(self, widget):
|
2006-06-15 18:12:27 +02:00
|
|
|
configs = self.configs
|
2006-06-16 00:00:11 +02:00
|
|
|
self.configs["maxloglevel"] = 3 ## 0:no logging; 1:errors; 2:status messages; 3:debug
|
2006-06-15 18:12:27 +02:00
|
|
|
## textfield values are stored in 'configs'
|
|
|
|
textfieldnames = ["tf_srcfile", "tf_dstdir"]
|
|
|
|
for name in textfieldnames:
|
|
|
|
## fill 'configs' with values from regarding textfields
|
|
|
|
self.outputfield = self.wkngui.get_widget(name)
|
|
|
|
self.textbuffer = self.outputfield.get_buffer()
|
|
|
|
configs[name] = self.textbuffer.get_text(*self.textbuffer.get_bounds ())
|
|
|
|
## checkboxes are also stored in 'configs'
|
2006-06-15 23:04:18 +02:00
|
|
|
checkboxnames = {"cb_time1":30,"cb_time2":300,"cb_time3":10000,"cb_time4":30000,"cb_time5":100000}
|
2006-06-15 18:12:27 +02:00
|
|
|
configs["times"] = []
|
|
|
|
for name in checkboxnames.keys():
|
|
|
|
if self.wkngui.get_widget(name).get_active():
|
|
|
|
configs["times"].append(checkboxnames[name])
|
|
|
|
self.add_log(("configs: %s %s" % (configs.keys(), configs.values())), 3)
|
|
|
|
self.read_wknlist()
|
|
|
|
self.check_dstdir()
|
|
|
|
|
|
|
|
def read_wknlist(self):
|
2006-06-09 09:20:21 +02:00
|
|
|
try:
|
2006-06-15 18:12:27 +02:00
|
|
|
tmpfile = open(self.configs["tf_srcfile"], "r")
|
2006-06-09 09:20:21 +02:00
|
|
|
filecontent = tmpfile.read()
|
|
|
|
tmpfile.close()
|
2006-06-15 18:12:27 +02:00
|
|
|
log = "\"%s\" erfolgreich eingelesen" % self.configs["tf_srcfile"]
|
2006-06-15 11:10:52 +02:00
|
|
|
self.add_log(log, 2)
|
2006-06-09 09:20:21 +02:00
|
|
|
except:
|
2006-06-15 18:12:27 +02:00
|
|
|
log = "Achtung: Konnte \"%s\" nicht einlesen!" % self.configs["tf_srcfile"]
|
2006-06-15 11:10:52 +02:00
|
|
|
self.add_log("verdammt: "+str(self.sys.exc_info()[0]),1)
|
|
|
|
self.add_log(log, 1)
|
2006-06-15 18:12:27 +02:00
|
|
|
raise
|
|
|
|
|
2006-06-09 09:20:21 +02:00
|
|
|
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)
|
2006-06-15 11:10:52 +02:00
|
|
|
self.add_log("neue Einstellungen gespeichert", 2)
|
2006-06-09 09:20:21 +02:00
|
|
|
|
2006-06-15 18:12:27 +02:00
|
|
|
|
2006-06-09 09:20:21 +02:00
|
|
|
def clicked_cancel_settings(self, widget):
|
2006-06-15 18:12:27 +02:00
|
|
|
'''TODO:'''
|
|
|
|
self.add_log("da war age faul B)",2)
|
2006-06-07 11:03:58 +02:00
|
|
|
|
|
|
|
def clicked_choose_srcfile(self, widget):
|
2006-06-15 18:12:27 +02:00
|
|
|
import filechooser
|
2006-06-15 11:10:52 +02:00
|
|
|
try:
|
|
|
|
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
|
2006-06-09 09:20:21 +02:00
|
|
|
self.outputfield = self.wkngui.get_widget("tf_srcfile")
|
|
|
|
self.textbuffer = self.outputfield.get_buffer()
|
2006-06-15 18:12:27 +02:00
|
|
|
|
2006-06-07 11:03:58 +02:00
|
|
|
if filename:
|
|
|
|
self.textbuffer.set_text(filename)
|
|
|
|
else:
|
|
|
|
self.textbuffer.set_text("keine Datei ausgewaehlt")
|
|
|
|
|
2006-06-15 18:12:27 +02:00
|
|
|
def clicked_choose_dstdir(self, widget):
|
|
|
|
gtk = self.gtk
|
|
|
|
try:
|
|
|
|
dialog = gtk.FileChooserDialog("Bilderverzeichnis auswaehlen..", \
|
|
|
|
None, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, \
|
|
|
|
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
|
|
|
|
dialog.set_default_response(gtk.RESPONSE_OK)
|
|
|
|
response = dialog.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
self.add_log("Verzeichnis: %s" % dialog.get_current_folder(),2)
|
|
|
|
elif response == gtk.RESPONSE_CANCEL:
|
|
|
|
self.add_log("Kein Verzeichnis ausgewaehlt",1)
|
|
|
|
self.configs["tf_dstdir"] = dialog.get_current_folder()
|
|
|
|
dialog.destroy()
|
|
|
|
self.outputfield = self.wkngui.get_widget("tf_dstdir")
|
|
|
|
self.textbuffer = self.outputfield.get_buffer()
|
|
|
|
self.textbuffer.set_text(self.configs["tf_dstdir"])
|
|
|
|
except:
|
|
|
|
self.add_log("Dateiauswahl Dialog konnte nicht gestartet werden",1)
|
|
|
|
self.add_log("verdammt: "+str(self.sys.exc_info()[0]),1)
|
|
|
|
raise
|
|
|
|
|
|
|
|
def check_dstdir(self):
|
|
|
|
from os import path
|
|
|
|
self.tf_wknlist = self.wkngui.get_widget("tf_dstdir")
|
|
|
|
if self.configs["tf_dstdir"] and path.isdir(self.configs["tf_dstdir"]):
|
|
|
|
self.outputfield = self.wkngui.get_widget("tf_dstdir")
|
|
|
|
self.textbuffer = self.outputfield.get_buffer()
|
|
|
|
self.textbuffer.set_text(self.configs["tf_dstdir"])
|
|
|
|
else:
|
|
|
|
self.add_log("Verzeichnis nicht gefunden",1)
|
|
|
|
|
2006-06-15 11:10:52 +02:00
|
|
|
def add_log(self, text, loglevel=2):
|
2006-06-16 00:00:11 +02:00
|
|
|
if int(loglevel) <= int(self.configs["maxloglevel"]):
|
2006-06-15 11:10:52 +02:00
|
|
|
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)
|
2006-06-14 01:13:52 +02:00
|
|
|
|
|
|
|
def clicked_show_pics(self, widget):
|
2006-06-15 18:12:27 +02:00
|
|
|
'''this is just for a rapid prototype'''
|
|
|
|
## set an image to display
|
2006-06-15 11:10:52 +02:00
|
|
|
#self.ci = self.wkngui.get_widget("chartimage")
|
|
|
|
#self.ci.set_from_file("foo.png")
|
|
|
|
self.add_log("Bildbetrachter gestartet", 2)
|
|
|
|
try:
|
|
|
|
import pyview
|
2006-06-15 18:21:14 +02:00
|
|
|
pv = pyview.PyView("pyview.glade","pyview",self.configs["tf_dstdir"])
|
|
|
|
#pv.show_window
|
2006-06-15 11:10:52 +02:00
|
|
|
except:
|
|
|
|
self.add_log("konnte Bildbetrachter nicht laden", 1)
|
|
|
|
self.add_log(str(self.sys.exc_info()[0]),1)
|
|
|
|
raise
|
|
|
|
|
2006-06-09 09:20:21 +02:00
|
|
|
|
2006-06-07 11:03:58 +02:00
|
|
|
def exit(self, widget):
|
|
|
|
print "ciao ciao"
|
|
|
|
self.sys.exit(1)
|
|
|
|
|
2006-06-09 09:20:21 +02:00
|
|
|
|