root/experimental/write_to_file/trunk/write_to_file/write_to_file.py @ 3724

Revision 3724, 8.1 KB (checked in by jgaeddert, 6 years ago)

adding installation files just to annoy Drew

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