Load matplotlib only when needed, this speeds up a little pyfa startup

This commit is contained in:
HomeWorld
2010-12-05 17:47:49 +02:00
parent cba719f324
commit 7d0f5cf910
3 changed files with 27 additions and 11 deletions

View File

@@ -22,22 +22,35 @@ import bitmapLoader
import gui.display
import gui.globalEvents as GE
try:
import matplotlib as mpl
mpl.use('wxagg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.figure import Figure
enabled = True
except:
print "Problems importing matplotlib; continuing without graphs"
enabled = False
from gui.graph import Graph
import service
import gui.mainFrame
enabled = True
mplImported = False
class GraphFrame(wx.Frame):
def __init__(self, parent, style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE | wx.FRAME_FLOAT_ON_PARENT):
global enabled
global mplImported
if not enabled:
return
try:
import matplotlib as mpl
if not mplImported:
mpl.use('wxagg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.figure import Figure
enabled = True
except:
print "Problems importing matplotlib; continuing without graphs"
enabled = False
return
mplImported = True
wx.Frame.__init__(self, parent, title=u"pyfa: Graph Generator", style=style, size=(520, 390))
i = wx.IconFromBitmap(bitmapLoader.getBitmap("graphs_small", "icons"))

View File

@@ -394,6 +394,9 @@ class MainFrame(wx.Frame):
self.waitDialog.Destroy()
def openGraphFrame(self, event):
if not gui.graphFrame.enabled:
return
if not self.graphFrame:
self.graphFrame = GraphFrame(self)
self.graphFrame.Show()

View File

@@ -78,7 +78,7 @@ class MainMenuBar(wx.MenuBar):
graphFrameItem = wx.MenuItem(windowMenu, self.graphFrameId, "Graphs\tCTRL+G")
graphFrameItem.SetBitmap(bitmapLoader.getBitmap("graphs_small", "icons"))
graphFrameItem.Enable(gui.graphFrame.enabled)
# graphFrameItem.Enable(gui.graphFrame.enabled)
windowMenu.AppendItem(graphFrameItem)
#windowMenu.Append(wx.ID_PREFERENCES)