# AArView Copyright 2006 Paul Milenkovic import sys import wx from wx import py from wx.lib.activexwrapper import MakeActiveXClass from UBAfxP import * import win32com.client # Python command interpreter window class EmbedShell(py.shell.Shell): def __init__(self, frame): # Frame object is a wx main window that contains # this command-shell object as a child window py.shell.Shell.__init__(self, parent=frame, id=-1) # Save frame object in the interpreter dictionary self.interp.locals['frame'] = frame self.interp.locals['display'] = frame.display def Show(self, vis): # Override of Show() maintains a Visible property self.Visible = vis py.shell.Shell.Show(self, vis) # AArView main window class AArFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "AArView", size=(800,600)) # Menu layout mMain = wx.MenuBar() mFiles = wx.Menu() mFiles.Append(101, "&Open") mFiles.AppendSeparator() mFiles.Append(103, "E&xit") mMain.Append(mFiles, "&Files") mEdit = wx.Menu() mEdit.Append(201, "&Copy image to clipboard") mMain.Append(mEdit, "&Edit") mView = wx.Menu() mView.Append(309, "&Shell", "", wx.ITEM_CHECK) mMain.Append(mView, "&View") self.SetMenuBar(mMain) self.Bind(wx.EVT_MENU, self.OnFilesOpen, id=101) self.Bind(wx.EVT_MENU, self.OnFilesExit, id=103) self.Bind(wx.EVT_MENU, self.OnEditCopy, id=201) self.Bind(wx.EVT_MENU, self.OnViewShell, id=309) # Control creation # MakeActiveXClass() returns a function, which in turn is called # to create an instance of the ActiveX control. self.display = MakeActiveXClass(UBeamAfx, eventObj=self)(self, -1) self.display.ShowOK = True self.voice = win32com.client.Dispatch("TF32Voice.JitterShimmerSNR") self.py_shell = EmbedShell(self) self.py_shell.Show(False) # Control layout mnwSizer = wx.BoxSizer(wx.VERTICAL) self.AddtoSizer(mnwSizer, self.display, 4) self.AddtoSizer(mnwSizer, self.py_shell, 1) mView.Check(309, self.py_shell.Visible) self.SetSizer(mnwSizer) self.SetAutoLayout(True) self.SetBackgroundColour(wx.NamedColor("LIGHTGREY")) self.Show(True) self.display.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) # Functions to show/hide main window elements def AddtoSizer(self, sizer, ctl, pval): sizer.Add(ctl, proportion=pval, flag=wx.EXPAND) sizer.Show(ctl, ctl.Visible) def ShowMain(self, ctl, visible): ctl.Visible = visible self.GetSizer().Show(ctl, visible); self.GetSizer().Layout() def DSPLayout(self): self.display.F0_visible = False self.display.RMS_visible = False self.display.TF_visible = False self.display.Spec_visible = True def ComputeJitter(self, tokens): return self.voice.ComputeNewJit(self.display._oleobj_,0,tokens) # Menu callbacks def OnFilesOpen(self, event): self.display.OpenWaveDlg() def OnFilesExit(self, event): self.Close() def OnEditCopy(self, event): self.display.CopytoClipboard() def OnViewShell(self, event): self.ShowMain(self.py_shell, not self.py_shell.Visible) if self.py_shell.Visible: self.py_shell.SetFocus(); def OnSetFocus(self, event): if self.py_shell.Visible: self.py_shell.SetFocus(); # wxPython application object: creates, displays, and runs program main window. # Required if this module is started as a main program from command line. # Not required if an AArFrame object is created from a wxPython pyshell, # which already contains a wx application object running an event loop. class AArViewApp(wx.App): def OnInit(self): self.frame = AArFrame() for pstr in sys.argv[1:]: if pstr == "-DSP": self.frame.DSPLayout() else: self.frame.display.FileName = pstr return True # Starts main program -- inactive if this module is loaded as a library if __name__ == '__main__': myApp = AArViewApp(0) myApp.MainLoop()