#! /usr/bin/env mpscript # import wx import MpWx #-------------------------------------------------------------------------- class MpWxTestFrame(wx.Frame): def __init__( self ): wx.Frame.__init__( self, None, title="MpWx Monitor Test" ) # Create a panel to contain the widgets. self.panel = wx.Panel( self ) # Create a Box sizer to contain the controls. self.panel.box = wx.BoxSizer( wx.HORIZONTAL ) # Attach the sizer to the panel. self.panel.SetSizer( self.panel.box ) # Construct a label describing the field. hostname = _test.server.get_field("hostname") port = int( _test.server.get_field("port") ) if ( port != 9727 ): field_label = "%s@%s:%s" \ % ( hostname, port, _test.field_name ) else: if ( hostname != "localhost" ): field_label = "%s:%s" \ % ( hostname, _test.field_name ) else: field_label = _test.field_name # Display the label. self.panel.label = wx.StaticText( self.panel, -1, field_label ) self.panel.box.Add( self.panel.label, \ 0, wx.ALIGN_LEFT | wx.ALL, 2 ) # Display the value to be monitored. self.panel.monitor = MpWx.ValueEntry( self.panel, \ _test.server, _test.field_name ) self.panel.box.Add( self.panel.monitor, \ 0, wx.ALIGN_LEFT | wx.ALL, 2 ) # Exit when the top level window is closed. self.Bind( wx.EVT_CLOSE, self.OnCloseWindow) # Expand the size of the top level window to make sure # that all windows are visible. self.panel.Fit() self.Fit() def OnCloseWindow( self, event ): self.Destroy() #-------------------------------------------------------------------------- class MpWxTestTimer(wx.Timer): def __init__( self, record_list ): wx.Timer.__init__( self ) self.record_list = record_list self.Bind( wx.EVT_TIMER, self.OnTimerEvent ) def OnTimerEvent( self, event ): try: self.record_list.wait_for_messages( 0.001 ) except Mp.Timed_Out_Error: pass #-------------------------------------------------------------------------- class MpWxTestApp(wx.App): def OnInit( self ): self.frame = MpWxTestFrame() self.frame.Show() self.SetTopWindow( self.frame ) return True #-------------------------------------------------------------------------- # Create an object to hold attributes used by the test. class _Test: pass _test = _Test() #-------------------------------------------------------------------------- def main( record_list, argv ): field_id = Mp.parse_network_field_id( argv[0] ); server_host = field_id[0] server_port = int( field_id[1] ) _test.server = record_list.connect_to_mx_server( \ server_host, server_port, 0 ) _test.field_name = "%s.%s" % ( field_id[2], field_id[3] ) app = MpWxTestApp() _test.timer = MpWxTestTimer( record_list ) _test.timer.Start( 100, False ) app.MainLoop()