der erste WKNcharts Prototyp steht

This commit is contained in:
age 2006-06-15 16:12:27 +00:00
parent 10498dc99f
commit 739d448c00
6 changed files with 166 additions and 106 deletions

View file

@ -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
-----

View file

@ -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

View file

@ -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()

View file

@ -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")
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()
file = self.textbuffer.get_text(*self.textbuffer.get_bounds ())
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):
try:
import filechooser
try:
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)

Binary file not shown.

View file

@ -489,7 +489,7 @@
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="textview3">
<widget class="GtkTextView" id="tf_dstdir">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
@ -506,7 +506,7 @@
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes">TODO</property>
<property name="text" translatable="yes">./images</property>
</widget>
</child>
</widget>
@ -689,78 +689,12 @@
<property name="visible">True</property>
<property name="n_rows">1</property>
<property name="n_columns">4</property>
<property name="homogeneous">True</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>
<child>
<widget class="GtkCheckButton" id="checkbutton2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">300 Tage</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="checkbutton3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">30 Tage</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="checkbutton4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">3 Jahre</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="checkbutton1">
<widget class="GtkCheckButton" id="cb_time1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">ein Tag</property>
@ -776,13 +710,75 @@
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="cb_time2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">30 Tage</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="cb_time3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">300 Tage</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="cb_time4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">3 Jahre</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">2</property>
<property name="padding">8</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
@ -999,7 +995,7 @@
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>