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

Revision 3695, 7.4 KB (checked in by DrewCormier, 6 years ago)

changed about message and removed some more unneeded code

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:
15    #TODO:add comment explainging this class
16
17    def __init__(self, parent):       
18        self.parent = parent
19
20    def write(self, data, file_name):
21        #TODO: test this method
22        open_file = open(file_name, 'w')   #open the file for writing
23        open_file.write(data)
24        open_file.close()
25       
26   
27
28def create(parent,namespace, interface, ns_name, port_name):
29    #return MainFrame(parent, -1, namespace, interface, ns_name, port_name)
30    return MainFrame(parent, -1, "Don't know what this should be", namespace, interface, ns_name, port_name)
31
32#generate wx ids for my wx controls
33[wxID_MAINFRAME, wxID_SPLITTERWINDOW1, wxID_PUSHPACKETBTN, wxID_IFILENAMEEDITOR, wxID_QFILENAMEEDITOR, wxID_IFILESTATICTEXT,wxID_QFILESTATICTEXT] = [wx.NewId() for _init_ctrls in range(11)]
34
35
36class MainFrame(wx.Frame):
37    def __init__(self, parent, id, title, namespace, interface, component_name, port_name):
38
39        #TODO: get this from the sources class
40        tmp_sources_instance = sources.sources()
41        self.available_sources = tmp_sources_instance.get_sources_list()
42
43        self._init_ctrls(parent)
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.dat')
74        self.qFileNameEditor.write('q.dat')
75
76        #set the default source
77        #this way if the user presses the "PushPacket" button before selecting
78        #a source, the source that is being displayed will be used
79        self.iSourceChoice.SetSelection(0)
80        self.qSourceChoice.SetSelection(0)
81
82    def _init_ctrls(self, prnt):
83        wx.Frame.__init__(self, id=wxID_MAINFRAME, name='', parent=prnt,
84              pos=wx.Point(374, 370), size=wx.Size(520, 370),
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, 370), 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='Push Packet',
94              name='PushPacketBtn', parent=self.splitterWindow1, pos=wx.Point(155, 250),
95              size=wx.Size(145, 50))
96        self.PushPacketBtn.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, False))
97        self.PushPacketBtn.SetBackgroundColour("green")
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, 150),
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, 200),
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, 150), 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, 200), 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         #connect to an existing port
176         ResourceHandle = ResourceRef._narrow(CF.Resource)
177         PortReference = ResourceHandle.getPort(self.port_name)
178         if PortReference is None:
179             print "Failed to get Port reference"
180         self.PortHandle = PortReference._narrow(standardInterfaces__POA.complexShort)
181         
182    def OnCloseWindow(self,event):
183        if hasattr(self.parent, 'removeToolFrame'):
184            self.parent.removeToolFrame(self)
185        self = None
186        event.Skip()
187
188
189
190
Note: See TracBrowser for help on using the browser.