root/experimental/display/trunk/display/display.py @ 3850

Revision 3850, 9.2 KB (checked in by DrewCormier, 6 years ago)

initial import

Line 
1#!/usr/bin/env python
2
3'''Write incomming packet(s) to file(s)'''
4
5import wx         #needed for display stuff
6from omniORB import CORBA      #use this for the CORBA orb stuff (pushing packets)
7import sys       #for system commands (e.g., argv and argc stuff)
8import CosNaming   #narrowing naming context stuff
9import CF, CF__POA    #core framework stuff
10import standardInterfaces__POA
11from wx.lib.anchors import LayoutAnchors  #used by splitter window
12# import wx.lib.buttons as buttons #for special wx buttons
13
14class write_to_file_short(standardInterfaces__POA.complexShort):
15    '''Writes I and Q data to 2 files'''
16
17    def __init__(self, orb, gui):       
18        self.orb = orb
19        self.gui = gui    #usually parent
20        self.delimiter = ','
21
22    def pushPacket(self, I_data, Q_data):
23        '''Store the data to be written to file when the Write Packet button is bushed'''
24        self.gui.I_data = I_data
25        self.gui.Q_data = Q_data
26 
27
28
29def create(parent,namespace, interface, ns_name, port_name):
30    #return MainFrame(parent, -1, namespace, interface, ns_name, port_name)
31    return MainFrame(parent, -1, "Don't know what this should be", namespace, interface, ns_name, port_name)
32
33#generate wx ids for my wx controls
34[wxID_MAINFRAME, wxID_SPLITTERWINDOW1, wxID_WRITEPACKETBTN, wxID_WRITEBUFFERBTN, wxID_IFILENAMEEDITOR, wxID_QFILENAMEEDITOR, wxID_IFILESTATICTEXT,wxID_QFILESTATICTEXT] = [wx.NewId() for _init_ctrls in range(8)]
35
36
37class MainFrame(wx.Frame):
38    def __init__(self, parent, id, title, namespace, interface, component_name, port_name):
39
40        self._init_ctrls(parent)
41
42        self.I_data = []
43        self.Q_data = []
44         
45        self.parent = parent
46        self.namespace = namespace
47        self.interface = interface
48        self.my_local_controls = None
49        self.component_name = component_name
50        self.port_name = port_name
51        self.setup_graphics()
52       
53        # Now Create the menu bar and items
54        self.mainmenu = wx.MenuBar()
55
56        menu = wx.Menu()
57        menu.Append(205, 'E&xit', 'Enough of this already!')
58        self.Bind(wx.EVT_MENU, self.OnFileExit, id=205)
59        self.mainmenu.Append(menu, '&File')
60       
61        menu = wx.Menu()
62        menu.Append(300, '&About', 'About this thing...')
63        self.Bind(wx.EVT_MENU, self.OnHelpAbout, id=300)
64        self.mainmenu.Append(menu, '&Help')
65
66        self.SetMenuBar(self.mainmenu)
67
68        # Bind the close event so we can disconnect the ports
69        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
70
71        self.Show(True)
72       
73        self.iFileNameEditor.write('i_out.dat')
74        self.qFileNameEditor.write('q_out.dat')
75
76
77    def _init_ctrls(self, prnt):
78        wx.Frame.__init__(self, id=wxID_MAINFRAME, name='', parent=prnt,
79              pos=wx.Point(530, 680), size=wx.Size(520, 270),
80              style=wx.DEFAULT_FRAME_STYLE, title='Write to File Tool')
81
82        self.splitterWindow1 = wx.SplitterWindow(id=wxID_SPLITTERWINDOW1,
83              name='splitterWindow1', parent=self, point=wx.Point(1, 1),
84              size=wx.Size(570, 270), style=wx.SP_3D)
85        self.splitterWindow1.SetConstraints(LayoutAnchors(self.splitterWindow1,
86              True, True, True, True))
87
88        self.WritePacketBtn = wx.Button(id=wxID_WRITEPACKETBTN, label='Write Packet',
89              name='WritePacketBtn', parent=self.splitterWindow1, pos=wx.Point(155, 150),
90              size=wx.Size(165, 50))
91        self.WritePacketBtn.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, False))
92        self.WritePacketBtn.SetBackgroundColour("green")
93        self.WritePacketBtn.Bind(wx.EVT_BUTTON, self.OnWritePacketBtnButton,
94              id=wxID_WRITEPACKETBTN)
95
96        self.WriteBufferBtn = wx.Button(id=wxID_WRITEBUFFERBTN, label='Write BUFFER',
97              name='WriteBufferBtn', parent=self.splitterWindow1, pos=wx.Point(155, 210),
98              size=wx.Size(165, 50))
99        self.WriteBufferBtn.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, False))
100        self.WriteBufferBtn.SetBackgroundColour("green")
101        self.WriteBufferBtn.Bind(wx.EVT_BUTTON, self.OnWriteBufferBtnButton,
102              id=wxID_WRITEBUFFERBTN)
103
104        #####
105        ## if you want an image on the button
106        # button_bmp = wx.Image("../AWG/my_image.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
107        # self.WritePacketBtn = buttons.GenBitmapTextButton(self.splitterWindow1,
108        #       wxID_WRITEPACKETBTN,button_bmp, 'Write Packet',
109        #       name='WritePacketBtn', pos=wx.Point(155, 250),
110        #       size=wx.Size(300, 100), style=0)
111        # self.WritePacketBtn.Bind(wx.EVT_BUTTON, self.OnWritePacketBtnButton,
112        #       id=wxID_WRITEPACKETBTN)
113        #####
114
115       
116        self.iFileNameEditor = wx.TextCtrl(id=wxID_IFILENAMEEDITOR,
117              name=u'iFileNameEditor', parent=self.splitterWindow1, pos=wx.Point(215, 50),
118              size=wx.Size(250, 30), style=0, value=u'')
119                         
120
121        self.qFileNameEditor = wx.TextCtrl(id=wxID_QFILENAMEEDITOR,
122              name=u'qFileNameEditor', parent=self.splitterWindow1, pos=wx.Point(215, 100),
123              size=wx.Size(250, 30), style=0, value=u'')
124
125
126        self.iFileStaticText = wx.StaticText(id=wxID_IFILESTATICTEXT,
127              label=u'I channel file:', name='qFileStaticText', parent=self.splitterWindow1,
128              pos=wx.Point(55, 50), size= wx.Size(100, 20), style=0)
129        self.iFileStaticText.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.BOLD,True,u'Sans'))
130
131        self.qFileStaticText = wx.StaticText(id=wxID_QFILESTATICTEXT,
132              label=u'Q channel file:', name='qFileStaticText', parent=self.splitterWindow1,
133              pos=wx.Point(55, 100), size= wx.Size(100, 20), style=0)
134        self.qFileStaticText.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.BOLD,True,u'Sans'))
135 
136 
137
138    def OnWritePacketBtnButton(self,event):
139        #get the file names from the file name editors in the GUI
140        self.i_file_name = self.iFileNameEditor.GetLineText(0)
141        self.q_file_name = self.qFileNameEditor.GetLineText(0)
142
143        #write the data out
144        open_file = open(self.i_file_name, 'w')   #open the file for writing
145        open_file.write(str(self.I_data))
146        open_file.close()
147
148        open_file = open(self.q_file_name, 'w')   #open the file for writing
149        open_file.write(str(self.Q_data))
150        open_file.close()
151
152    def OnWriteBufferBtnButton(self,event):
153        #get the file names from the file name editors in the GUI
154        self.i_file_name = self.iFileNameEditor.GetLineText(0)
155        self.q_file_name = self.qFileNameEditor.GetLineText(0)
156
157        #write the data out
158        open_file = open(self.i_file_name, 'w')   #open the file for writing
159        open_file.write(str(self.I_data))
160        open_file.close()
161
162        open_file = open(self.q_file_name, 'w')   #open the file for writing
163        open_file.write(str(self.Q_data))
164        open_file.close()
165
166    def OnFileExit(self, event):
167        '''This is what will happen when you select File -> Exit in the menu bar'''
168        self.Close()      #close the frame
169 
170    def OnHelpAbout(self, event):
171        '''Stuff that gets displayed when you select Help -> About in the menu bar'''
172        from wx.lib.dialogs import ScrolledMessageDialog
173        about = ScrolledMessageDialog(self, "Write to file tool.\nA product of Wireless@VT.", "About...")
174        about.ShowModal()
175
176    def setup_graphics(self):
177        self.CORBA_being_used = False
178
179        if True:               
180         self.CORBA_being_used = True
181         self.orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
182         obj = self.orb.resolve_initial_references("NameService")
183         rootContext = obj._narrow(CosNaming.NamingContext)
184         if rootContext is None:
185             print "Failed to narrow the root naming context"
186             sys.exit(1)
187         name = [CosNaming.NameComponent(self.component_name[0],""),
188             CosNaming.NameComponent(self.component_name[1],""),
189             CosNaming.NameComponent(self.component_name[2],"")]
190     
191         try:
192             ResourceRef = rootContext.resolve(name)
193     
194         except:
195             print "Required resource not found"
196             sys.exit(1)
197     
198         ResourceHandle = ResourceRef._narrow(CF.Resource)
199         PortReference = ResourceHandle.getPort(self.port_name)
200         if PortReference is None:
201             print "Failed to get Port reference"
202         self.PortHandle = PortReference._narrow(CF.Port)
203         
204       
205         #create the class instance of the write_to_file class
206         self.my_file_writer = write_to_file_short(self.orb, self)
207
208         obj_poa = self.orb.resolve_initial_references("RootPOA")
209         poaManager = obj_poa._get_the_POAManager()
210         poaManager.activate()
211         obj_poa.activate_object(self.my_file_writer)
212         self.PortHandle.connectPort(self.my_file_writer._this(), "thisismyconnectionid_w2file")
213         #orb.run()
214
215    def OnCloseWindow(self,event):
216        if hasattr(self.parent, 'removeToolFrame'):
217            self.parent.removeToolFrame(self)
218        self = None
219        event.Skip()
220
221    def __del__(self):
222        if self.CORBA_being_used:
223            self.PortHandle.disconnectPort("thisismyconnectionid_w2file")
224            while (_time.time() - self.my_local_plot.end_time) < 1.5:
225                #print (time.time() - self.my_local_plot.end_time)
226                pass
227                #_time.sleep(1)
228
229
230
Note: See TracBrowser for help on using the browser.