diff --git a/WKNcharts/WknCharts.py b/WKNcharts/WknCharts.py index 054749e..c691811 100755 --- a/WKNcharts/WknCharts.py +++ b/WKNcharts/WknCharts.py @@ -18,7 +18,7 @@ class WknCharts: import wknGUI wg = wknGUI.WknGUI(gtk) - # this is necessary for using threads later + # this is necessary for using threads in "wg" gtk.gdk.threads_init() gtk.gdk.threads_enter() gtk.main() diff --git a/WKNcharts/guiShowPics.py b/WKNcharts/guiShowPics.py new file mode 100644 index 0000000..cbefaab --- /dev/null +++ b/WKNcharts/guiShowPics.py @@ -0,0 +1,11 @@ +#!/bin/env/python + +class GuiShowPics: + '''this class will soon substitute pyview.py''' + import sys,os,stat,re,locale + match_pics=re.compile(r".*\.(png|tiff|jpg|jpeg|xpm)$") + + def __init__(self, gui): + self.gui = gui + + diff --git a/WKNcharts/pyview/pyview.glade b/WKNcharts/pyview.glade similarity index 92% rename from WKNcharts/pyview/pyview.glade rename to WKNcharts/pyview.glade index 2654676..1b29d8e 100644 --- a/WKNcharts/pyview/pyview.glade +++ b/WKNcharts/pyview.glade @@ -2,7 +2,6 @@ - True @@ -12,6 +11,11 @@ False True False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST @@ -35,14 +39,17 @@ True + True + 240 True True + 60 True True GTK_POLICY_AUTOMATIC @@ -107,6 +114,8 @@ + 440 + 280 True True GTK_POLICY_AUTOMATIC diff --git a/WKNcharts/pyview/pyview b/WKNcharts/pyview.py similarity index 85% rename from WKNcharts/pyview/pyview rename to WKNcharts/pyview.py index ac4057a..de10deb 100644 --- a/WKNcharts/pyview/pyview +++ b/WKNcharts/pyview.py @@ -13,12 +13,7 @@ match_pics=re.compile(r".*\.(png|tiff|jpg|jpeg|xpm)$") import sys -if len(sys.argv) == 2: - start_dir=sys.argv[1] -else: - start_dir="." - -class pyview(libglade.GladeWrapper): +class PyView(libglade.GladeWrapper): def __init__(self, Filename, WindowName, start_dir="."): libglade.GladeWrapper.__init__(self, Filename, WindowName) @@ -44,6 +39,9 @@ class pyview(libglade.GladeWrapper): self._chdir(start_dir) + def show_window(self): + gtk.main() + def _chdir(self,newdir): try: os.chdir(newdir) @@ -79,15 +77,20 @@ class pyview(libglade.GladeWrapper): filename=model.get_value(iter,0) self.image.set_from_file(filename) size=locale.format("%d",os.stat(filename).st_size,1) - self.status.push(self.status_id,size+" bytes") + #self.status.push(self.status_id,size+" bytes") + self.status.push(self.status_id,os.getcwd()+"/"+filename) - def quit(self, *args): - gtk.main_quit() + #def quit(self, *args): + #gtk.main_quit() def on_pyview_destroy(self, event): self.quit() -PYVIEW = pyview("./pyview.glade", "pyview", start_dir) - -gtk.main() +if __name__ == "__main__": + if len(sys.argv) == 2: + start_dir=sys.argv[1] + else: + start_dir="./images" + pv = PyView("./pyview.glade", "pyview", start_dir) + pv.show_window() diff --git a/WKNcharts/pyview/libglade.py b/WKNcharts/pyview/libglade.py deleted file mode 100644 index 2effff3..0000000 --- a/WKNcharts/pyview/libglade.py +++ /dev/null @@ -1,33 +0,0 @@ -#This requires pygtk2 - -import gettext -import gtk -import gtk.glade - -class GladeWrapper: - """ - Superclass for glade based applications. Just derive from this - and your subclass should create methods whose names correspond to - the signal handlers defined in the glade file. Any other attributes - in your class will be safely ignored. - - This class will give you the ability to do: - subclass_instance.GtkWindow.method(...) - subclass_instance.widget_name... - """ - def __init__(self, Filename, WindowName): - #load glade file. - self.widgets = gtk.glade.XML(Filename, WindowName, gettext.textdomain()) - self.GtkWindow = getattr(self, WindowName) - - instance_attributes = {} - for attribute in dir(self.__class__): - instance_attributes[attribute] = getattr(self, attribute) - self.widgets.signal_autoconnect(instance_attributes) - - def __getattr__(self, attribute): #Called when no attribute in __dict__ - widget = self.widgets.get_widget(attribute) - if widget is None: - raise AttributeError("Widget [" + attribute + "] not found") - self.__dict__[attribute] = widget #add reference to cache - return widget diff --git a/WKNcharts/wknGUI.py b/WKNcharts/wknGUI.py index 3152a69..c95bc5e 100644 --- a/WKNcharts/wknGUI.py +++ b/WKNcharts/wknGUI.py @@ -8,8 +8,11 @@ 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" @@ -25,26 +28,24 @@ class WknGUI: "on_window1_destroy": self.exit } self.wkngui.signal_autoconnect (actions) - self.log += "\n"+self.time.strftime('%H:%M:%S')+" " - self.log += "Programm gestartet " + # read the config at program start 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]) charts.set_times([30]) - self.add_log("beginne Download der WKNS") + 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 - Thread(target=charts.getallcharts,args=(self,)).start() + self.Thread(target=charts.getallcharts,args=(self,)).start() ## unthreaded version #charts.getallcharts(self) - self.add_log("Download abgeschlossen") + self.add_log("Download abgeschlossen",2) def clicked_read_settings(self, widget): self.outputfield = self.wkngui.get_widget("tf_srcfile") @@ -54,15 +55,18 @@ class WknGUI: tmpfile = open(file, "r") filecontent = tmpfile.read() tmpfile.close() - self.add_log("%s erfolgreich eingelesen" % file) + log = "\"%s\" erfolgreich eingelesen" % file + self.add_log(log, 2) except: - self.buffer.set_text(filecontent) - self.log = "Achtung: Konnte %s nicht einlesen" % file + 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") + self.add_log("neue Einstellungen gespeichert", 2) def clicked_cancel_settings(self, widget): '''TODO: @@ -71,9 +75,14 @@ class WknGUI: pass def clicked_choose_srcfile(self, widget): - import filechooser - fcd = filechooser.FileChooserDialog() - filename = fcd.getfilename() + 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: @@ -81,18 +90,30 @@ class WknGUI: 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 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 - atm''' - self.ci = self.wkngui.get_widget("chartimage") - self.ci.set_from_file("foo.png") + 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" diff --git a/WKNcharts/wknGUI.pyc b/WKNcharts/wknGUI.pyc index 42c55e4..860fa50 100644 Binary files a/WKNcharts/wknGUI.pyc and b/WKNcharts/wknGUI.pyc differ diff --git a/WKNcharts/wkncharts.glade b/WKNcharts/wkncharts.glade index 7df5048..f81ea9e 100644 --- a/WKNcharts/wkncharts.glade +++ b/WKNcharts/wkncharts.glade @@ -113,13 +113,14 @@ True - True + False 0 True True + True GTK_RELIEF_NORMAL True @@ -186,7 +187,7 @@ 0 - False + True False @@ -220,7 +221,7 @@ True - gtk-zoom-in + gtk-zoom-fit 4 0.5 0.5 @@ -261,7 +262,7 @@ 0 - False + True False @@ -336,7 +337,7 @@ 0 - False + True False @@ -374,87 +375,6 @@ - - - True - False - 0 - - - - True - gtk-zoom-fit - 4 - 0.5 - 0.5 - 0 - 0 - - - 7 - False - True - - - - - - True - True - GTK_POLICY_ALWAYS - GTK_POLICY_ALWAYS - GTK_SHADOW_NONE - GTK_CORNER_TOP_LEFT - - - - True - GTK_SHADOW_IN - - - - True - 0.5 - 0.5 - 0 - 0 - - - - - - - 0 - True - True - - - - - False - True - - - - - - True - Bilder - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - tab - - - True @@ -531,13 +451,12 @@ True - True True True GDK_EXTENSION_EVENTS_ALL True False - True + False GTK_JUSTIFY_LEFT GTK_WRAP_NONE True @@ -577,7 +496,7 @@ True True False - True + False GTK_JUSTIFY_LEFT GTK_WRAP_NONE True @@ -890,13 +809,14 @@ True + True True GTK_RELIEF_NORMAL True - + True 0.5 0.5 @@ -908,15 +828,15 @@ 0 - + True False 2 - + True - gtk-undo + gtk-cancel 4 0.5 0.5 @@ -931,7 +851,7 @@ - + True Rückgängig True