plfdtd (0.1.0) | 2012-05-14 18:57 |
pylaf (0.5.0) | 2012-10-18 17:20 |
- # coding: utf-8
- from pylafii import *
- from scipy import *
- class FGSIN(Logic):
- class Control(ControlPanelFactory):
- SEQUENCE = ['mag','freq','phase','bias','nums','samplerate','result']
- class Plot(PlotPanel): pass
- mag = Terminal(1.)
- freq = Terminal(0.01)
- phase = Terminal(0.)
- bias = Terminal(0.)
- nums = Terminal(2000)
- samplerate = Terminal(1.)
- @rule()
- def result(self):
- print 'updated'
- t = arange(self.nums) / self.samplerate
- w = sin(2 * pi * self.freq * t + self.phase / 180. * pi)
- return self.mag * w + self.bias
- if __name__ == '__main__':
- import Tkinter
- Equipment(Tkinter.Tk(),FGSIN)
- Tkinter.mainloop()
- # coding: utf-8
- from pylafii import *
- from scipy import *
- class FGSIN(Logic):
- mag = Terminal(1.)
- freq = Terminal(0.01)
- phase = Terminal(0.)
- bias = Terminal(0.)
- nums = Terminal(2000)
- samplerate = Terminal(1.)
- @rule('mag','freq','phase','bias','nums','samplerate')
- def result(self):
- t = arange(self.nums) / self.samplerate
- w = sin(2 * pi * self.freq * t + self.phase / 180. * pi)
- return self.mag * w + self.bias
- class Plot(PlotPanel): pass
- class Control(ControlPanelFactory):
- SEQUENCE = ['mag','freq','phase','bias','nums','samplerate','result']
- if __name__ == '__main__':
- import Tkinter
- Equipment(Tkinter.Tk(),FGSIN,auto_trig=True)
- Tkinter.mainloop()
- # coding: utf-8
- from pylafii import *
- from scipy import *
- class MIXER(Parts):
- class Control(ControlPanelFactory): SEQUENCE = ['samplerate','result']
- class Plot(PlotPanel): pass
- sig_a = Terminal(array([]))
- sig_b = Terminal(array([]))
- samplerate = Terminal(1.)
- @rule('sig_a','sig_b',init=array([]))
- def result(self):
- if self.sig_a.shape == self.sig_b.shape:
- return self.sig_a * self.sig_b
- else:
- return self.result
- if __name__ == '__main__':
- import Tkinter
- from s01_fgsin_autotrig import FGSIN
- def test(master=None):
- mix = Equipment(master,MIXER,auto_trig=True)
- fga = Equipment(Tkinter.Toplevel(master),FGSIN,auto_trig=True)
- fgb = Equipment(Tkinter.Toplevel(master),FGSIN,auto_trig=True)
- connect((mix.logic,'sig_a'),(fga.logic,'result'))
- connect((mix.logic,'sig_b'),(fgb.logic,'result'))
- connect((fga.logic,'nums'),(fgb.logic,'nums'))
- connect(*[(o.logic,'samplerate') for o in [mix,fga,fgb]])
- fga.logic.freq = 0.001
- fga.logic.bias = 1.
- fga.logic.result
- fgb.logic.freq = 0.05
- fgb.logic.result
- mix.panel['plot'].children['result'].panel['plot'].ax.set_title('TITLE')
- # mix.widget('plot.result.plot').ax.set_title('TITLE')
- test(Tkinter.Tk())
- Tkinter.mainloop()
- # coding: utf-8
- if __name__ == '__main__':
- import Tkinter
- from pylafii import *
- from s01_fgsin_autotrig import FGSIN
- from s02_mixer import MIXER
- def test(master=None):
- mix = Embed(master,MIXER,LayoutV,text='RF',auto_trig=True).grid(row=0,column=2,sticky=Tkinter.N)
- fga = Embed(master,FGSIN,LayoutV,text='LO',auto_trig=True).grid(row=0,column=0)
- fgb = Embed(master,FGSIN,LayoutV,text='IF',auto_trig=True).grid(row=0,column=1)
- connect((mix.logic,'sig_a'),(fga.logic,'result'))
- connect((mix.logic,'sig_b'),(fgb.logic,'result'))
- connect((fga.logic,'nums'),(fgb.logic,'nums'))
- connect(*[(o.logic,'samplerate') for o in [mix,fga,fgb]])
- fga.logic.freq = 0.05
- fga.logic.result
- fgb.logic.freq = 0.001
- fgb.logic.bias = 1.
- fgb.logic.nums = 2001
- fgb.logic.result
- mix.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
- fga.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
- fgb.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
- test(Tkinter.Tk())
- Tkinter.mainloop()
- # coding: utf-8
- from pylafii import *
- from s01_fgsin_autotrig import FGSIN
- from s02_mixer import MIXER
- class MODAM(Logic):
- class Plot(Panel):
- def __init__(self,master=None,cnf={},**kw):
- Panel.__init__(self,master,cnf,**kw)
- mix = Embed(self,MIXER,LayoutV,name='mixer',text='RF',auto_trig=True).grid(row=0,column=2,sticky=Tkinter.N)
- fga = Embed(self,FGSIN,LayoutV,name='sga',text='LO',auto_trig=True).grid(row=0,column=0)
- fgb = Embed(self,FGSIN,LayoutV,name='sgb',text='IF',auto_trig=True).grid(row=0,column=1)
- connect((mix.logic,'sig_a'),(fga.logic,'result'))
- connect((mix.logic,'sig_b'),(fgb.logic,'result'))
- connect((fga.logic,'nums'),(fgb.logic,'nums'))
- connect(*[(o.logic,'samplerate') for o in [mix,fga,fgb]])
- fga.logic.freq = 0.05
- fga.logic.result
- fgb.logic.freq = 0.001
- fgb.logic.bias = 1.
- fgb.logic.nums = 2001
- fgb.logic.result
- if __name__ == '__main__':
- import Tkinter
- c = Equipment(Tkinter.Tk(),MODAM)
- c.panel['plot'].children['mixer'].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
- c.panel['plot'].children['sga'].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
- c.panel['plot'].children['sgb'].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
- Tkinter.mainloop()
- # coding: utf-8
- from pylafii import *
- from s01_fgsin_autotrig import FGSIN
- from s02_mixer import MIXER
- kw = lambda **kwargs: kwargs
- class MODAM(Logic):
- lof = Terminal(.05)
- iff = Terminal(.001)
- ifm = Terminal(1.)
- ifb = Terminal(1.)
- def __init__(self,master=None,name=None):
- Logic.__init__(self,master,name)
- sga = FGSIN(self,name='sga')
- sgb = FGSIN(self,name='sgb')
- mix = MIXER(self,name='mixer')
- #
- connect((self,'lof'),(sga,'freq'))
- connect((self,'iff'),(sgb,'freq'))
- connect((self,'ifm'),(sgb,'mag'))
- connect((self,'ifb'),(sgb,'bias'))
- #
- for sg,name in [(sga,'sig_a'),(sgb,'sig_b')]: connect((mix,name),(sg,'result'))
- connect(*[(sg,'nums') for sg in [sga,sgb]])
- connect(*[(o,'samplerate') for o in [mix,sga,sgb]])
- #
- class Control(Panel):
- LAYOUT = [(Tkinter.Label,kw(text='LO Frequency [MHz]')),(Entry,kw(name='lof')),
- (Tkinter.Label,kw(text='IF Frequency [MHz]')),(Entry,kw(name='iff')),
- (Tkinter.Label,kw(text='IF Magnitude [mV]')),(Entry,kw(name='ifm')),
- (Tkinter.Label,kw(text='IF Bias Voltage [mV]')),(Entry,kw(name='ifb')),]
- class Plot(Panel):
- def __init__(self,master=None,cnf={},**kw):
- Panel.__init__(self,master,cnf,**kw)
- Embed(self,MIXER,LayoutV,name='mixer',text='RF',auto_trig=True,mount=False).pack(side=Tkinter.RIGHT)
- Embed(self,FGSIN,PlotLayout,name='sgb',text='IF',mount=False).pack(side=Tkinter.RIGHT,anchor=Tkinter.N)
- Embed(self,FGSIN,PlotLayout,name='sga',text='LO',mount=False).pack(side=Tkinter.RIGHT,anchor=Tkinter.N)
- def connect(self,logic):
- Panel.connect(self,logic)
- for name in ['sga','sgb','mixer']: self.children[name].mount(logic.children[name])
- class Menu(DefaultMenu):
- ITEMS = [
- #['File', ['insert', pylaf.kw(index=0,itemType='command',label='Load')],],
- ['File', ['add_command', kw(label='Load')],],
- ['Edit',
- ['add_command', kw(label='Copy',command='_copy')],
- ['add_command', kw(label='Paset')],
- ['Test', ['add_command', kw(label='Test2')]],
- ],
- ['Stub', ],
- ]
- def _copy(self):
- print '_copy was invoked !'
- if __name__ == '__main__':
- tk = Tkinter.Tk()
- app = Equipment(tk,MODAM,LayoutV)
- # spc = Embed(Tkinter.Toplevel(tk),Spectrum); spc.assign(Spectrum()); spc.pack()
- # spc.panel('plot').resize(dpi=50,figsize=(7,5))
- # spc.panel('plot').ax.figure.subplots_adjust(
- # left = .15,
- # bottom = .15,
- # )
- # spc.panel('plot').ax.set_xlim([0.095,.105])
- # spc.panel('plot').ax.set_ylim([-140.,0.])
- app.logic.children['sga'].nums = 2001
- for name in ['sga','sgb','mixer']:
- app.panel['plot'].children[name].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
- # app.panel['plot'].children[name].panel['plot'].children['result'].panel['plot'].resize(dpi=50,figsize=(5,4))
- Tkinter.mainloop()
- }}}