|
|
|
@ -23,6 +23,7 @@ import os
|
|
|
|
|
import sys |
|
|
|
|
import traceback |
|
|
|
|
from time import * |
|
|
|
|
from datetime import datetime |
|
|
|
|
#import pokereval |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
@ -48,11 +49,12 @@ import Charset
|
|
|
|
|
|
|
|
|
|
class GuiGraphViewer (threading.Thread): |
|
|
|
|
|
|
|
|
|
def __init__(self, querylist, config, debug=True): |
|
|
|
|
def __init__(self, querylist, config, parent, debug=True): |
|
|
|
|
"""Constructor for GraphViewer""" |
|
|
|
|
self.sql = querylist |
|
|
|
|
self.conf = config |
|
|
|
|
self.debug = debug |
|
|
|
|
self.parent = parent |
|
|
|
|
#print "start of GraphViewer constructor" |
|
|
|
|
self.db = Database.Database(self.conf, sql=self.sql) |
|
|
|
|
|
|
|
|
@ -334,21 +336,41 @@ class GuiGraphViewer (threading.Thread):
|
|
|
|
|
def exportGraph (self, widget, data): |
|
|
|
|
if self.fig is None: |
|
|
|
|
return # Might want to disable export button until something has been generated. |
|
|
|
|
|
|
|
|
|
dia_chooser = gtk.FileChooserDialog(title="Please choose the directory you wish to export to:", |
|
|
|
|
action=gtk.FILE_CHOOSER_ACTION_OPEN, |
|
|
|
|
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) |
|
|
|
|
#TODO: Suggest path and filename to start with |
|
|
|
|
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, |
|
|
|
|
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OK,gtk.RESPONSE_OK)) |
|
|
|
|
dia_chooser.set_destroy_with_parent(True) |
|
|
|
|
dia_chooser.set_transient_for(self.parent) |
|
|
|
|
try: |
|
|
|
|
dia_chooser.set_filename(self.exportFile) # use previously chosen export path as default |
|
|
|
|
except: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
response = dia_chooser.run() |
|
|
|
|
if response == gtk.RESPONSE_OK: |
|
|
|
|
self.exportDir = dia_chooser.get_filename() |
|
|
|
|
print "DEBUG: self.exportDir = %s" %(self.exportDir) |
|
|
|
|
elif response == gtk.RESPONSE_CANCEL: |
|
|
|
|
|
|
|
|
|
if response == gtk.RESPONSE_CANCEL: |
|
|
|
|
print 'Closed, no graph exported' |
|
|
|
|
dia_chooser.destroy() |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
# generate a unique filename for export |
|
|
|
|
now = datetime.now() |
|
|
|
|
now_formatted = now.strftime("%Y%m%d%H%M%S") |
|
|
|
|
self.exportFile = dia_chooser.get_filename() + "/fpdb" + now_formatted + ".png" |
|
|
|
|
dia_chooser.destroy() |
|
|
|
|
#TODO: Check to see if file exists |
|
|
|
|
#NOTE: Dangerous - will happily overwrite any file we have write access too |
|
|
|
|
#TODO: This asks for a directory but will take a filename and overwrite it. |
|
|
|
|
self.fig.savefig(self.exportDir, format="png") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#print "DEBUG: self.exportFile = %s" %(self.exportFile) |
|
|
|
|
self.fig.savefig(self.exportFile, format="png") |
|
|
|
|
|
|
|
|
|
#display info box to confirm graph created |
|
|
|
|
diainfo = gtk.MessageDialog(parent=self.parent, |
|
|
|
|
flags=gtk.DIALOG_DESTROY_WITH_PARENT, |
|
|
|
|
type=gtk.MESSAGE_INFO, |
|
|
|
|
buttons=gtk.BUTTONS_OK, |
|
|
|
|
message_format="Graph created") |
|
|
|
|
diainfo.format_secondary_text(self.exportFile) |
|
|
|
|
diainfo.run() |
|
|
|
|
diainfo.destroy() |
|
|
|
|
|
|
|
|
|
#end of def exportGraph |
|
|
|
|