first full functional MAxyPlot

This commit is contained in:
2016-12-23 15:49:40 +01:00
parent 6e31c7e705
commit 36a11a5657
7 changed files with 1417 additions and 27 deletions

View File

@@ -2,30 +2,36 @@ import os,sys
import wx
import wx.py
import numpy as np
from MAxyPlot import *
from MAError import *
#from hdfTree import *
#from hdfGrid import *
#from hdfAttrib import *
#from hdfImage import *
import utilities as ut
import wxutils as ut
class MADoc():
'''
class Path():
@staticmethod
def GetImage():
path=__file__
try:symPath=os.readlink(path) #follow symbolic link
except (AttributeError,OSError) as e:pass
else:
path=symPath
path=os.path.abspath(path)
path=os.path.dirname(path)
return os.path.join(path,'images')
Implemented messages
0: The time slider has changed. usrData=index
1: The position slider has changed. usrData=index
'''
def __init__(self):
self.view=[] #list of object that have view on this document
pass
def Update(self,skipView,msg,usrData):
for v in self.view:
if v==skipView: continue
v.OnUpdate(msg,usrData)
class AboutFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,-1,'About MotionAnalyzer',size=(300,330))
imgDir=Path.GetImage()
imgDir=ut.Path.GetImage()
icon = wx.Icon(os.path.join(imgDir,'PBMA.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
self.Centre()
@@ -43,8 +49,9 @@ class AboutFrame(wx.Frame):
class MAMainFrame(wx.Frame):
def OpenFile(self,fn_npz):
doc=self.doc
try:
self.fh=fh=np.load(fn_npz)
doc.fh=fh=np.load(fn_npz)
except IOError as e:
sys.stderr.write('Unable to open File: '+fn_npz+'\n')
else:
@@ -53,7 +60,16 @@ class MAMainFrame(wx.Frame):
for k,v in fh.iteritems():
s+=' '+k+': '+str(v.dtype)+' '+str(v.shape)+'\n'
self.wxTxt.SetLabel(s)
#self.wxTree.ShowHirarchy(self.fid)
lenRec=fh['rec'].shape[0]
lenPts=fh['pts'].shape[0]
self.wxTimeCtrl.slider.SetRange(0,lenRec-1)
self.wxTimeCtrl.slider.SetPageSize(lenRec/lenPts)
self.xPosCtrl.slider.SetRange(0,lenPts-1)
#self.wxTimeCtrl.slider.SetPageSize(100)
#self.wxTree.ShowHirarchy(self.fid)
def CloseFile(self):
#http://docs.wxwidgets.org/2.8/wx_windowdeletionoverview.html#windowdeletionoverview
@@ -64,9 +80,10 @@ class MAMainFrame(wx.Frame):
except AttributeError as e:
pass
def __init__(self, parent, title):
def __init__(self, parent, title,doc):
wx.Frame.__init__(self, parent, title=title, size=wx.Size(650, 350))
imgDir=Path.GetImage()
self.doc=doc;doc.view.append(self)
imgDir=ut.Path.GetImage()
icon = wx.Icon(os.path.join(imgDir,'PBMA.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
#wxSplt = wx.SplitterWindow(self, -1)
@@ -75,16 +92,29 @@ class MAMainFrame(wx.Frame):
#wxTree.Bind(wx.EVT_TREE_ITEM_MENU, self.OnMenu, id=1)
#wx.EVT_TREE_ITEM_MENU(id, func)
#wxTxt = wx.StaticText(wxSplt, -1, '',(10,10) )#, style=wx.ALIGN_CENTRE)
self.wxTxt = wx.StaticText(self, wx.ID_ANY, "MyLabel", wx.DefaultPosition, wx.DefaultSize, 0 )
#wxSplt.SplitVertically(wxTree, wxTxt)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
wxTxt = wx.StaticText(self, wx.ID_ANY, "MyLabel", wx.DefaultPosition, wx.DefaultSize, 0 )
sizer.Add(wxTxt, 1, wx.LEFT | wx.TOP | wx.GROW)
wxTimeCtrl=ut.SliderGroup(self, label='Time', range=(0, 1000))
wxTimeCtrl.SetCallback(MAMainFrame.OnSetTime, wxTimeCtrl)
sizer.Add(wxTimeCtrl.sizer, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=5) #wxSplt.SplitVertically(wxTree, wxTxt)
wxPosCtrl=ut.SliderGroup(self, label='Position', range=(0, 1000))
wxPosCtrl.SetCallback(MAMainFrame.OnSetPosition, wxPosCtrl)
sizer.Add(wxPosCtrl.sizer, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=5) #wxSplt.SplitVertically(wxTree, wxTxt)
#wxSplt.SetMinimumPaneSize(320)
#wxLstCtrl=HdfAttrListCtrl(wxSplt)
#wxSplt.SplitVertically(wxTree, wxLstCtrl)
self.BuildMenu()
self.Centre()
self.wxTimeCtrl=wxTimeCtrl
self.xPosCtrl=wxPosCtrl
self.wxTxt=wxTxt
#self.wxTree=wxTree
#self.display=wxTxt
def __del__(self):
@@ -146,11 +176,16 @@ class MAMainFrame(wx.Frame):
#mn.AppendItem(mnItem)
self.SetMenuBar(mnBar)
self.CreateStatusBar()
self.SetStatusText("This is the status message")
def OnShowXYPath(self, event):
pass
frame=MAxyPlotFrame(self,self.doc)
frame.Show(True)
def OnShowError(self, event):
pass
frame=MAErrorFrame(self,self.doc)
frame.Show(True)
def OnShowVelocity(self, event):
pass
@@ -192,7 +227,43 @@ rec
# 'hid=wxTree.GetPyData(wxNode)']:
# shell.run(cmd, prompt=False)
def OnUpdate(self,msg,usrData):
#this is the model-view-control update function
print self,msg,usrData
@staticmethod
def OnSetTime(usrData, value, msg):
'called when the time slider has been changed'
print 'OnSetTime', usrData, value, msg
view=usrData.slider.Parent
doc=view.doc
doc.Update(view,0,value)
# imgFrm=usrData.slider.Parent
# imgFrm.img.set_array(imgFrm.data[usrData.value,...])
# data=imgFrm.data
# sl=ut.GetSlice(imgFrm.idxXY,data.shape,imgFrm.wxAxCtrlLst)
# try:
# tomoNorm=imgFrm.tomoNorm
# except AttributeError:
# imgFrm.canvas.img.set_array(data[sl])
# else:
# data=data[sl]*tomoNorm
# imgFrm.canvas.img.set_array(data)
# if imgFrm.mnItemShowMoment.IsChecked():
# imgFrm.PlotMoments()
# imgFrm.canvas.draw()
pass
@staticmethod
def OnSetPosition(usrData, value, msg):
'called when the time slider has been changed'
print 'OnSetPosition', usrData, value, msg
view = usrData.slider.Parent
doc = view.doc
doc.Update(view, 1, value)
if __name__ == '__main__':
def GetArgs():
@@ -211,7 +282,8 @@ if __name__ == '__main__':
def OnInit(self):
args=GetArgs()
frame = MAMainFrame(None, 'PBMotionAnalyzer')
doc=MADoc()
frame = MAMainFrame(None,'PBMotionAnalyzer',doc)
if args.npzFile:
frame.OpenFile(args.npzFile)
frame.Show(True)