diff --git a/WKNcharts/TODO b/WKNcharts/TODO
index 5008511..8de70f8 100644
--- a/WKNcharts/TODO
+++ b/WKNcharts/TODO
@@ -1,15 +1,17 @@
= TODO =
[.] bilder im programm anzeigen
- - pyview integrieren
+ [*] pyview integrieren
+ [!] pyview laesst sich nur einmal starten
[ ] download abbrechbar machen
-[ ] intervallcheckboxen auswerten
-[ ] zielverzeichnis auswerten
[ ] dateinamen fuer downloads besser vergeben, datum einbringen
[ ] libglade wrapper nutzen
[ ] einstellungen rueckgaengig machen
= DONE =
[*] loggen in threads erzeugt Speicherzugriffsfehler
+[*] wkn datei auswaehlen
+[*] zielverzeichnis auswaehlen
+[*] intervallcheckboxen auswerten
-----
diff --git a/WKNcharts/getWKNcharts.py b/WKNcharts/getWKNcharts.py
index b9e0ff6..d4e0dc3 100755
--- a/WKNcharts/getWKNcharts.py
+++ b/WKNcharts/getWKNcharts.py
@@ -27,7 +27,7 @@ class WKNCharts:
def readwkndictfromstring(self, wknstring):
'''takes the given string into a "wkn name" dictionary'''
tmp2 = wknstring.splitlines()
- print len(tmp2)
+ #print len(tmp2)
for i in tmp2:
tmp = i.split()
if tmp[0] and tmp[1]: self.wkn_dict[tmp[0]] = tmp[1]
@@ -47,12 +47,13 @@ class WKNCharts:
'seite':"kurse",
'herkunft':123
})
- print "ich hole jetzt \"%s\" %i:" % (self.wkn_dict[wkn], time)
- print host + params
+ #print "ich hole jetzt \"%s\" %i:" % (self.wkn_dict[wkn], time)
+ #print host + params
###self.gui.add_log("%s %s" % (host, params))
+
try:
f = urllib.urlopen(host + params)
- png = open("images/"+self.wkn_dict[wkn]+str(time)+".png", "w")
+ png = open(self.dstdir+"/"+self.wkn_dict[wkn]+str(time)+".png", "w")
png.write(f.read())
png.close()
import time
@@ -63,7 +64,11 @@ class WKNCharts:
def set_times(self, times):
self.times = times
+ def set_dstdir(self, dstdir):
+ self.dstdir = dstdir
+
def getallchartsnogui(self) :
+ '''TODO: this is obsolete, merge it with 'getallcharts' '''
for wkn in self.wkn_dict.keys():
for time in self.times:
self.getchart(wkn, time)
@@ -72,11 +77,17 @@ class WKNCharts:
def getallcharts(self, gui) :
self.gui = gui
+ from os import path
+ if not path.isdir(self.dstdir):
+ gui.add_log("Achtung: Zielverzeichnis %s nicht gefunden. Kein Download!" % self.dstdir, 1)
+ return
+
+ gui.add_log("Beginne Download nach: %s" % self.dstdir, 2)
for wkn in self.wkn_dict.keys():
- self.gui.add_log("hole: %s (%s)" % (self.wkn_dict[wkn], wkn))
+ self.gui.add_log(" hole gerade: %s (%s) %s" % (self.wkn_dict[wkn], wkn, str(self.times)),2)
for time in self.times:
self.getchart(wkn, time)
- print "Download fertig"
+ gui.add_log("Download Ende",2)
return
diff --git a/WKNcharts/pyview.py b/WKNcharts/pyview.py
index de10deb..71f8e5e 100644
--- a/WKNcharts/pyview.py
+++ b/WKNcharts/pyview.py
@@ -80,8 +80,9 @@ class PyView(libglade.GladeWrapper):
#self.status.push(self.status_id,size+" bytes")
self.status.push(self.status_id,os.getcwd()+"/"+filename)
- #def quit(self, *args):
+ def quit(self, *args):
#gtk.main_quit()
+ pass
def on_pyview_destroy(self, event):
self.quit()
@@ -91,6 +92,6 @@ if __name__ == "__main__":
if len(sys.argv) == 2:
start_dir=sys.argv[1]
else:
- start_dir="./images"
+ start_dir="./"
pv = PyView("./pyview.glade", "pyview", start_dir)
pv.show_window()
diff --git a/WKNcharts/wknGUI.py b/WKNcharts/wknGUI.py
index c95bc5e..97e0f2c 100644
--- a/WKNcharts/wknGUI.py
+++ b/WKNcharts/wknGUI.py
@@ -9,19 +9,20 @@ class WknGUI:
"""
import sys, time
from threading import Thread
+ configs = {}
wkns = ""
log = ""
- maxloglevel = 1
- '''0:no logging; 1:errors; 2:status messages; 3:all '''
+ maxloglevel = 3
+ '''0:no logging; 1:errors; 2:status messages; 3:debug '''
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_choose_dstdir_clicked": self.clicked_choose_dstdir,
"on_bu_wget_charts_clicked": self.clicked_wget_charts,
"on_bu_pics_clicked": self.clicked_show_pics,
"on_bu_exit_clicked": self.exit,
@@ -33,50 +34,66 @@ class WknGUI:
def clicked_wget_charts(self, widget):
import getWKNcharts
- '''the real download logic lies in getWKNcharts
+ '''the real download logic is 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)
+ charts.set_times(self.configs["times"])
+ charts.set_dstdir(self.configs["tf_dstdir"])
## 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 ())
+ configs = self.configs
+ ## 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'
+ checkboxnames = {"cb_time1":30,"cb_time2":300,"cb_time3":30000,"cb_time4":100000}
+ configs["times"] = []
+ for name in checkboxnames.keys():
+ if self.wkngui.get_widget(name).get_active():
+ configs["times"].append(checkboxnames[name])
+ print configs["times"]
+ self.add_log(("configs: %s %s" % (configs.keys(), configs.values())), 3)
+ self.read_wknlist()
+ self.check_dstdir()
+
+ def read_wknlist(self):
try:
- tmpfile = open(file, "r")
+ tmpfile = open(self.configs["tf_srcfile"], "r")
filecontent = tmpfile.read()
tmpfile.close()
- log = "\"%s\" erfolgreich eingelesen" % file
+ log = "\"%s\" erfolgreich eingelesen" % self.configs["tf_srcfile"]
self.add_log(log, 2)
except:
- log = "Achtung: Konnte \"%s\" nicht einlesen!" % file
+ log = "Achtung: Konnte \"%s\" nicht einlesen!" % self.configs["tf_srcfile"]
self.add_log("verdammt: "+str(self.sys.exc_info()[0]),1)
self.add_log(log, 1)
- return
+ raise
+
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
+ '''TODO:'''
+ self.add_log("da war age faul B)",2)
def clicked_choose_srcfile(self, widget):
+ import filechooser
try:
- import filechooser
fcd = filechooser.FileChooserDialog()
filename = fcd.getfilename()
except:
@@ -85,11 +102,44 @@ class WknGUI:
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 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)
+
def add_log(self, text, loglevel=2):
if loglevel <= self.maxloglevel:
self.logbuch = self.wkngui.get_widget("tf_logbook")
@@ -100,14 +150,14 @@ class WknGUI:
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'''
+ '''this is just for a rapid prototype'''
+ ## set an image to display
#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")
+ pyview.PyView("pyview.glade","pyview",self.configs["tf_dstdir"])
pv.show_window
except:
self.add_log("konnte Bildbetrachter nicht laden", 1)
diff --git a/WKNcharts/wknGUI.pyc b/WKNcharts/wknGUI.pyc
deleted file mode 100644
index 860fa50..0000000
Binary files a/WKNcharts/wknGUI.pyc and /dev/null differ
diff --git a/WKNcharts/wkncharts.glade b/WKNcharts/wkncharts.glade
index f81ea9e..ab90ab2 100644
--- a/WKNcharts/wkncharts.glade
+++ b/WKNcharts/wkncharts.glade
@@ -489,7 +489,7 @@
GTK_CORNER_TOP_LEFT
-
+
True
True
True
@@ -506,7 +506,7 @@
0
0
0
- TODO
+ ./images
@@ -689,78 +689,12 @@
True
1
4
- True
+ False
0
0
-
- True
- True
- 300 Tage
- True
- GTK_RELIEF_NORMAL
- True
- True
- False
- True
-
-
- 2
- 3
- 0
- 1
- fill
-
-
-
-
-
-
- True
- True
- 30 Tage
- True
- GTK_RELIEF_NORMAL
- True
- True
- False
- True
-
-
- 1
- 2
- 0
- 1
- fill
-
-
-
-
-
-
- True
- True
- 3 Jahre
- True
- GTK_RELIEF_NORMAL
- True
- True
- False
- True
-
-
- 3
- 4
- 0
- 1
- fill
-
-
-
-
-
-
+
True
True
ein Tag
@@ -776,13 +710,75 @@
1
0
1
- fill
+
+
+
+
+
+
+ True
+ True
+ 30 Tage
+ True
+ GTK_RELIEF_NORMAL
+ True
+ True
+ False
+ True
+
+
+ 1
+ 2
+ 0
+ 1
+
+
+
+
+
+
+ True
+ True
+ 300 Tage
+ True
+ GTK_RELIEF_NORMAL
+ True
+ True
+ False
+ True
+
+
+ 2
+ 3
+ 0
+ 1
+
+
+
+
+
+
+ True
+ True
+ 3 Jahre
+ True
+ GTK_RELIEF_NORMAL
+ True
+ True
+ False
+ True
+
+
+ 3
+ 4
+ 0
+ 1
- 2
+ 8
False
False
@@ -999,7 +995,7 @@
True
True
- GTK_POLICY_NEVER
+ GTK_POLICY_AUTOMATIC
GTK_POLICY_ALWAYS
GTK_SHADOW_NONE
GTK_CORNER_TOP_LEFT