Browse Source

fix graph export to png. More focus fixes

master
steve 14 years ago
parent
commit
cd3ed9a937
  1. 5
      pyfpdb/GuiAutoImport.py
  2. 50
      pyfpdb/GuiGraphViewer.py
  3. 4
      pyfpdb/fpdb.pyw

5
pyfpdb/GuiAutoImport.py

@ -32,11 +32,12 @@ import Configuration
import string
class GuiAutoImport (threading.Thread):
def __init__(self, settings, config, sql):
def __init__(self, settings, config, sql, parent):
self.importtimer = 0
self.settings = settings
self.config = config
self.sql = sql
self.parent = parent
imp = self.config.get_import_parameters()
@ -138,6 +139,8 @@ class GuiAutoImport (threading.Thread):
#dia_chooser.set_current_folder(pathname)
dia_chooser.set_filename(current_path)
#dia_chooser.set_select_multiple(select_multiple) #not in tv, but want this in bulk import
dia_chooser.set_destroy_with_parent(True)
dia_chooser.set_transient_for(self.parent)
response = dia_chooser.run()
if response == gtk.RESPONSE_OK:

50
pyfpdb/GuiGraphViewer.py

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

4
pyfpdb/fpdb.pyw

@ -867,7 +867,7 @@ class fpdb:
def tab_auto_import(self, widget, data=None):
"""opens the auto import tab"""
new_aimp_thread = GuiAutoImport.GuiAutoImport(self.settings, self.config, self.sql)
new_aimp_thread = GuiAutoImport.GuiAutoImport(self.settings, self.config, self.sql, self.window)
self.threads.append(new_aimp_thread)
aimp_tab=new_aimp_thread.get_vbox()
self.add_and_display_tab(aimp_tab, "Auto Import")
@ -918,7 +918,7 @@ This program is licensed under the AGPL3, see agpl-3.0.txt in the fpdb installat
def tabGraphViewer(self, widget, data=None):
"""opens a graph viewer tab"""
new_gv_thread = GuiGraphViewer.GuiGraphViewer(self.sql, self.config)
new_gv_thread = GuiGraphViewer.GuiGraphViewer(self.sql, self.config, self.window)
self.threads.append(new_gv_thread)
gv_tab = new_gv_thread.get_vbox()
self.add_and_display_tab(gv_tab, "Graphs")

Loading…
Cancel
Save