Commit MetaInfo

Revisãoff965b5162d1b49329dad6b2ac38c9dd4844fa2b (tree)
Hora2012-02-25 07:09:19
Autorbijoux
Commiterbijoux

Mensagem de Log

Renewed event mechanism in term module
Restored tutorials

Mudança Sumário

Diff

diff -r 0140c466e2bf -r ff965b5162d1 src/pylafii/inst.py
--- a/src/pylafii/inst.py Wed Feb 22 08:37:11 2012 +0900
+++ b/src/pylafii/inst.py Sat Feb 25 07:09:19 2012 +0900
@@ -146,9 +146,10 @@
146146 self.config_panel_klass = {}
147147 if panel_klass is None: return
148148 #
149+ self.panel['config'] = self.config_panel
149150 for key,klass in panel_klass.iteritems():
150151 if key == 'config':
151- self.panel[key] = self.config_panel
152+ #self.panel[key] = self.config_panel
152153 for mykey,myklass in inspect.getmembers(klass,inspect.isclass):
153154 self.config_panel_klass[mykey.lower()] = myklass
154155 continue
@@ -188,6 +189,21 @@
188189 value.connect(self.logic)
189190 return self.panel['config']
190191
192+class LayoutV(Layout):
193+ def layout(self,panel):
194+ if 'toolbar' in panel:
195+ panel['toolbar'].grid(row=0,column=0,sticky=Tkinter.E+Tkinter.W+Tkinter.N+Tkinter.S)
196+ if 'plot' in panel:
197+ panel['plot'].grid(row=1,column=0,sticky=Tkinter.E+Tkinter.W+Tkinter.N+Tkinter.S)
198+ self.grid_rowconfigure(1,weight=1)
199+ if 'control' in panel:
200+ panel['control'].grid(row=2,column=0,sticky=Tkinter.E+Tkinter.W+Tkinter.N+Tkinter.S)
201+ if 'rack' in panel:
202+ panel['rack'].grid(row=3,column=0,sticky=Tkinter.E+Tkinter.W+Tkinter.N+Tkinter.S)
203+ if 'status' in panel:
204+ panel['status'].grid(row=4,column=0,sticky=Tkinter.E+Tkinter.W+Tkinter.N+Tkinter.S)
205+ self.grid_columnconfigure(0,weight=1)
206+
191207 class PlotLayout(Layout):
192208 def __init__(self,master=None,panel_klass=None,cnf={},**kw):
193209 Layout.__init__(self,master,panel_klass,cnf,**kw)
diff -r 0140c466e2bf -r ff965b5162d1 src/pylafii/term.py
--- a/src/pylafii/term.py Wed Feb 22 08:37:11 2012 +0900
+++ b/src/pylafii/term.py Sat Feb 25 07:09:19 2012 +0900
@@ -36,17 +36,33 @@
3636 ''' !!!【変更予定】Ruleを優先しないとだめ!!!'''
3737 self.observers.cleanup() # 削除したオブジェクトをコールしないよう空になった弱参照をクリア
3838 for o in self.observers.tolist():
39- if not o in ignore: o.notify(event) # オブザーバひとつひとつのupdate()をobserversの順番に起動
39+ #if TRACE:
40+ # if o in ignore:
41+ # print 'ignored %s set event' % o.term.name
42+ #if not o in ignore: o.notify(event) # オブザーバひとつひとつのupdate()をobserversの順番に起動
43+ o.notify(event)
4044 def get_observers(self):
4145 self.observers.cleanup()
4246 return self.observers.tolist()
43-
47+ @property
48+ def observers_(self):
49+ self.observers.cleanup()
50+ return self.observers.tolist()
51+ @property
52+ def rule(self):
53+ for attr in self.observers_:
54+ if attr:
55+ if isinstance(attr.term,Rule):
56+ return attr
57+ return
58+
4459 class Attribute(object):
4560 def __init__(self,owner,terminal,value):
4661 self.owner = weakref.ref(owner)
4762 self.terminal = weakref.ref(terminal)
4863 self.ignore = weakref.WeakKeyDictionary()
4964 self.node = None
65+ self.evaluating_rule = []
5066 self.register(Node(value))
5167 def register(self,node):
5268 self.unregister() # 監視を解除
@@ -58,6 +74,8 @@
5874 self.node = None # 監視対象を保持するための参照を削除
5975 def notify(self,event):
6076 self.terminal().notify(self,event)
77+ @property
78+ def term(self): return self.terminal()
6179
6280 # Generator ?
6381 class Terminal(object):
@@ -78,7 +96,7 @@
7896 except AttributeError:
7997 pass
8098 else:
81- if TRACE: print '= get = canceled notification %s.%s' % (owner.__class__.__name__,self.name)
99+ if TRACE: print '= get = %s.%s without notification' % (owner.__class__.__name__,self.name)
82100 return attr.node.value
83101 # attr.node.getlog[attr] = None # get 参照したことを対象の node.getlog へ記録
84102 if TRACE: print '= get = %s.%s' % (owner.__class__.__name__,self.name)
@@ -91,32 +109,44 @@
91109 if TRACE: print '= set = %s.%s' % (owner.__class__.__name__,self.name)
92110 node.notify('set')
93111 def notify(self, attr, event):
112+ if event == 'get':
113+ if attr.evaluating_rule: attr.node.getlog[attr.evaluating_rule[-1]] = None # getlog に実行中のルールを記録する
114+ return
94115 if not event == 'set': return
95116 setattr(attr,'__set_event',True)
96117 if TRACE: print '- set -> %s.%s' % (attr.owner().__class__.__name__,self.name)
118+ if TRACE: print 'start blocking notification for', attr.term.name
97119 owner = attr.owner()
98120 #
99121 # 依存関係のある rule を起動
100122 #
101- for name, v in terminals(owner).iteritems():
123+ for rule_name, v in terminals(owner).iteritems():
102124 if isinstance(v,Rule) and v.mode == 'interactive': # ルールが見つかったら
103- attr = v.get_attribute(owner)
104- term = attr.terminal()
125+ if TRACE: print 'Rule found: %s.%s' % (owner.__class__.__name__,rule_name)#,
126+ #if TRACE: print 'evaluating with', [o.term.name for o in attr.evaluating_rule]
127+ rule_attr = v.get_attribute(owner)
128+ if rule_attr.evaluating_rule:
129+ if rule_attr.evaluating_rule[-1] == rule_attr:
130+ if TRACE: print 'This rule is evaluating now'
131+ continue
132+ term = rule_attr.terminal()
105133 for name in term.dependency: # 未更新の Terminal がひとつもなければルールを実行する
106134 if name == self.name: # 1つでも自身に依存していたらルールを実行可能か評価する
135+ if TRACE: print '%s.%s checks' % (owner.__class__.__name__,rule_name),
107136 for myname in term.dependency: # 未更新の依存 Terminal がひとつでも見つかればルールを実行しない
108137 if TRACE: print '[%s]' % myname,
109- if attr in terminal(owner,myname).get_attribute(owner).node.getlog:
138+ if rule_attr in terminal(owner,myname).get_attribute(owner).node.getlog:
110139 if TRACE: print 'not modified'
111140 break # ログに attr が見つかれば未更新
112141 else: # break で脱出しなかった場合
113- if not len(attr.terminal().dependency) == 0:
114- if TRACE: print '\n%s.%s - get ->' % (attr.owner().__class__.__name__,self.name)
115- term.notify(attr,'get') # かつ依存関係が空()でない場合にはルールを実行する
142+ if not len(rule_attr.terminal().dependency) == 0:
143+ if TRACE: print '\n%s.%s - get -> %s.%s' % (rule_attr.owner().__class__.__name__,self.name,rule_attr.owner().__class__.__name__,rule_name)
144+ term.notify(rule_attr,'get') # かつ依存関係が空()でない場合にはルールを実行する
116145 # if TRACE: print '\n%s.%s - get ->' % (attr.owner().__class__.__name__,self.name)
117146 # term.notify(attr,'get')
118147 try: delattr(attr,'__set_event')
119148 except AttributeError: pass
149+ if TRACE: print 'end blocking notification for', attr.term.name
120150 def get_name(self, owner): # オーナーインスタンスからの参照名を取得する
121151 if self.name == None: # オーナーインスタンスが生成されてから最初に参照されたときには名称探索をする
122152 # 呼び出しのコンテキストから、オーナーインスタンスにオブジェクトが存在することが保証されているので(はずなので)チェック省略
@@ -184,6 +214,7 @@
184214 raise RulePortSetError("cannot set() a rule cell")
185215 def notify(self,attr,event):
186216 if not event == 'get': return
217+ if attr.evaluating_rule: attr.node.getlog[attr.evaluating_rule[-1]] = None # getlog に実行中のルールを記録する
187218 try: self.rule
188219 except: return # undefined rule error!!
189220 if TRACE: print '- get -> %s.%s' % (attr.owner().__class__.__name__,self.name)
@@ -205,35 +236,38 @@
205236 #
206237 # ひとつでも更新されている Terminal があればルールを実行する
207238 #
239+ #print '%s.%s' % (attr.owner().__class__.__classname__,attr.terminal())
240+ if not self.require_update(attr): return
208241 owner = attr.owner()
209- for name in self.dependency: # 依存関係のある Terminal がひとつでも更新されていれば else 節を実行してなにもせず脱出
210- myattr = terminal(owner,name).get_attribute(owner)
211- if TRACE: print '[%s]' % name,
212- if not attr in myattr.node.getlog:
213- if TRACE: print 'modified'
214- break
215- else: # 依存関係のある Terminal がひとつも更新されていなかった場合(break で脱出しなかった場合)
216- if not len(self.dependency) == 0:
217- return # 依存関係が()の場合にも else 節が実行されてしまう例外処理
218- #
219- # ルールの実行に先立って依存ターミナルへ get を通知しリンクを遡り getlog を更新する
242+# for name in self.dependency: # 依存関係のある Terminal がひとつでも更新されていれば else 節を実行してなにもせず脱出
243+# myattr = terminal(owner,name).get_attribute(owner)
244+# if TRACE: print '[%s]' % name,
245+# if not attr in myattr.node.getlog:
246+# if TRACE: print 'modified'
247+# break
248+# else: # 依存関係のある Terminal がひとつも更新されていなかった場合(break で脱出しなかった場合)
249+# if not len(self.dependency) == 0:
250+# return # 依存関係が()の場合にも else 節が実行されてしまう例外処理
220251 #
221- setattr(attr,'passed',True) # block recursive access
222- for name in self.dependency:
223- dependent = terminal(owner,name).attr(owner)
224- for o in dependent.node.get_observers():
225- if isinstance(o.terminal(),Rule):
226- o.ignore[dependent] = None
227- getattr(owner,name) # 依存ターミナルを参照してルール起動を試みる
228- for o in dependent.node.get_observers():
229- try:
230- o.detected
231- except AttributeError:
232- pass
233- else:
234- delattr(o,'detected')
235- dependent.node.getlog[attr] = None
236- delattr(attr,'passed')
252+ # ルールの実行に先立って自身に影響を与えるターミナルへ get を通知し(リンクを遡り) getlog を更新する
253+ #
254+# setattr(attr,'passed',True) # block recursive access
255+# for name in self.dependency:
256+# dependent = terminal(owner,name).attr(owner)
257+# if dependent.node.rule: dependent.node.rule.ignore[dependent] = None # 影響ターミナルに関連するルールからの逆流ブロックマーカをつける
258+ #for o in dependent.node.get_observers():
259+ # if isinstance(o.terminal(),Rule):
260+ # o.ignore[dependent] = None # 影響ターミナルに関連するルールからの逆流ブロックマーカをつける
261+ #getattr(owner,name) # 依存ターミナルを参照してルール起動を試みる
262+ #for o in dependent.node.get_observers():
263+ # try:
264+ # o.detected
265+ # except AttributeError:
266+ # pass
267+ # else:
268+ # delattr(o,'detected')
269+ #dependent.node.getlog[attr] = None
270+# delattr(attr,'passed')
237271 #
238272 # Event 内で自身を参照したときに無限循環してしまう不具合への対処
239273 #
@@ -244,10 +278,15 @@
244278 # ルールの実行
245279 #
246280 if TRACE: print 'exec %s.%s.rule' % (attr.owner().__class__.__name__,self.name)
281+ for name in self.dependency: terminal(owner,name).attr(owner).evaluating_rule.append(attr) # LILO にプッシュする
282+ attr.evaluating_rule.append(attr)
247283 attr.node.value = self.rule(owner) # rule を実行してその結果を node に保存する
284+ attr.evaluating_rule = attr.evaluating_rule[:-1]
285+ for name in self.dependency: terminal(owner,name).attr(owner).evaluating_rule = terminal(owner,name).attr(owner).evaluating_rule[:-1] # LILO からポップする
248286 if TRACE: print 'fin %s.%s.rule' % (attr.owner().__class__.__name__,self.name)
249287 attr.node.getlog.clear() # node を変更したので node.getlog を消去
250- if TRACE: print '%s.%s - set ->' % (attr.owner().__class__.__name__,self.name)
288+ if TRACE: print '%s.%s - set ->' % (attr.owner().__class__.__name__,self.name),
289+ if TRACE: print 'ignore with', [k.term.name for k,v in attr.ignore.iteritems()]
251290 attr.node.notify('set',ignore=attr.ignore)
252291 attr.ignore.clear()
253292 #
@@ -283,12 +322,35 @@
283322 #delattr(attr,'from_rule')
284323 return True
285324 return
325+ def require_update(self,attr):
326+ owner = attr.owner()
327+ if len(self.dependency) == 0: return True # 依存関係が()の場合には常に要更新
328+ for name in self.dependency:
329+ dependent = terminal(owner,name).get_attribute(owner)
330+ if TRACE: print 'checking getlog for %s =' % name,[k.term.name for k,v in dependent.node.getlog.iteritems()]
331+ rule = dependent.node.rule # このルールに影響を与えるターミナルに関連付けられたルール
332+ if rule: # ルールが存在していれば
333+ if TRACE: print '%s.%s' % (owner.__class__.__name__,name), # 影響を与えるターミナル
334+ if TRACE: print '= %s' % rule.owner().__class__.__name__ # チェックされるルール
335+ required = rule.term.require_update(rule)
336+ if required:
337+ if TRACE: print 'requires update at least'
338+ else:
339+ if TRACE: print 'skips update'
340+ if required: # 依存関係のある Rule が要更新であれば自身も要更新
341+ return True
342+ if not attr in dependent.node.getlog: # 依存関係のある Terminal がひとつでも更新されていれば要更新
343+ return True
344+ return False
286345
287346 class Event(Terminal):
288347 def __init__(self,value=None,*args,**kw):
289348 Terminal.__init__(self,value)
290349 if 'rule' in kw: self.rule = kw['rule']
291350 def notify(self, attr, event):
351+ #if event == 'get':
352+ # if attr.evaluating_rule: attr.node.getlog[attr.evaluating_rule[-1]] = None # getlog に実行中のルールを記録する
353+ # return
292354 if not event == 'set': return
293355 try: self.rule
294356 except: return # undefined rule error!!
@@ -298,7 +360,8 @@
298360 self.rule(attr.owner())
299361 if TRACE: print 'fin %s.%s.rule' % (attr.owner().__class__.__name__,self.name)
300362 try: delattr(attr,'__set_event')
301- except AttributeError: pass
363+ except AttributeError:
364+ pass
302365 Terminal.notify(self,attr,event)
303366
304367 def rule(*args,**kw):
diff -r 0140c466e2bf -r ff965b5162d1 src/pylafii/tkext.py
--- a/src/pylafii/tkext.py Wed Feb 22 08:37:11 2012 +0900
+++ b/src/pylafii/tkext.py Sat Feb 25 07:09:19 2012 +0900
@@ -6,6 +6,9 @@
66 ttk_imported = True
77 from term import event, Terminal
88
9+def node(owner,name):
10+ return getattr(owner.__class__,name).attr(owner).node
11+
912 class Entry(Tkinter.Entry,object):
1013 def __init__(self,master=None,cnf={},**kw):
1114 Tkinter.Entry.__init__(self,master,cnf,**kw)
@@ -16,7 +19,7 @@
1619 self.delete(0,len(self.get()))
1720 self.insert(0,self.value)
1821 def _backward(self,*args):
19- self.value = type(self.value)(self.get())
22+ self.value = type(node(self,'value').value)(self.get())
2023
2124 class Button(Tkinter.Button,object):
2225 value = Terminal()
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s01_fgsin.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tutorial/s01_fgsin.py Sat Feb 25 07:09:19 2012 +0900
@@ -0,0 +1,25 @@
1+# coding: utf-8
2+from pylafii import *
3+from scipy import *
4+
5+class FGSIN(Logic):
6+ class Control(ControlPanelFactory):
7+ SEQUENCE = ['mag','freq','phase','bias','nums','samplerate','result']
8+ class Plot(PlotPanel): pass
9+ mag = Terminal(1.)
10+ freq = Terminal(0.01)
11+ phase = Terminal(0.)
12+ bias = Terminal(0.)
13+ nums = Terminal(2000)
14+ samplerate = Terminal(1.)
15+ @rule()
16+ def result(self):
17+ print 'updated'
18+ t = arange(self.nums) / self.samplerate
19+ w = sin(2 * pi * self.freq * t + self.phase / 180. * pi)
20+ return self.mag * w + self.bias
21+
22+if __name__ == '__main__':
23+ import Tkinter
24+ Equipment(Tkinter.Tk(),FGSIN)
25+ Tkinter.mainloop()
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s01_fgsin_autotrig.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tutorial/s01_fgsin_autotrig.py Sat Feb 25 07:09:19 2012 +0900
@@ -0,0 +1,24 @@
1+# coding: utf-8
2+from pylafii import *
3+from scipy import *
4+
5+class FGSIN(Logic):
6+ mag = Terminal(1.)
7+ freq = Terminal(0.01)
8+ phase = Terminal(0.)
9+ bias = Terminal(0.)
10+ nums = Terminal(2000)
11+ samplerate = Terminal(1.)
12+ @rule('mag','freq','phase','bias','nums','samplerate')
13+ def result(self):
14+ t = arange(self.nums) / self.samplerate
15+ w = sin(2 * pi * self.freq * t + self.phase / 180. * pi)
16+ return self.mag * w + self.bias
17+ class Plot(PlotPanel): pass
18+ class Control(ControlPanelFactory):
19+ SEQUENCE = ['mag','freq','phase','bias','nums','samplerate','result']
20+
21+if __name__ == '__main__':
22+ import Tkinter
23+ Equipment(Tkinter.Tk(),FGSIN,auto_trig=True)
24+ Tkinter.mainloop()
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s01_figsin.py
--- a/src/tutorial/s01_figsin.py Wed Feb 22 08:37:11 2012 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
1-# coding: utf-8
2-from pylafii import *
3-from scipy import *
4-
5-class FGSIN(Logic):
6- class Control(ControlPanelFactory): SEQUENCE = ['mag','freq','phase','bias','nums','samplerate','result']
7- class Plot(PlotPanel): pass
8- mag = Terminal(1.)
9- freq = Terminal(0.01)
10- phase = Terminal(0.)
11- bias = Terminal(0.)
12- nums = Terminal(2000)
13- samplerate = Terminal(1.)
14- @rule()
15- def result(self):
16- t = arange(self.nums) / self.samplerate
17- w = sin(2 * pi * self.freq * t + self.phase / 180. * pi)
18- return self.mag * w + self.bias
19-
20-if __name__ == '__main__':
21- import Tkinter
22- Equipment(Tkinter.Tk(),FGSIN)
23- Tkinter.mainloop()
24-
\ No newline at end of file
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s01_figsin_autotrig.py
--- a/src/tutorial/s01_figsin_autotrig.py Wed Feb 22 08:37:11 2012 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
1-# coding: utf-8
2-from pylafii import *
3-from scipy import *
4-
5-class FGSIN(Logic):
6- mag = Terminal(1.)
7- freq = Terminal(0.01)
8- phase = Terminal(0.)
9- bias = Terminal(0.)
10- nums = Terminal(2000)
11- samplerate = Terminal(1.)
12- @rule('mag','freq','phase','bias','nums','samplerate')
13- def result(self):
14- t = arange(self.nums) / self.samplerate
15- w = sin(2 * pi * self.freq * t + self.phase / 180. * pi)
16- return self.mag * w + self.bias
17- class Plot(PlotPanel): pass
18- class Control(ControlPanelFactory):
19- SEQUENCE = ['mag','freq','phase','bias','nums','samplerate','result']
20-
21-if __name__ == '__main__':
22- import Tkinter
23- Equipment(Tkinter.Tk(),FGSIN,auto_trig=True) # auto_trig = True にすると常に再計算されてしまう
24- Tkinter.mainloop()
25-
\ No newline at end of file
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s02_mixer.py
--- a/src/tutorial/s02_mixer.py Wed Feb 22 08:37:11 2012 +0900
+++ b/src/tutorial/s02_mixer.py Sat Feb 25 07:09:19 2012 +0900
@@ -1,5 +1,6 @@
11 # coding: utf-8
22 from pylafii import *
3+from scipy import *
34
45 class MIXER(Parts):
56 class Control(ControlPanelFactory): SEQUENCE = ['samplerate','result']
@@ -16,7 +17,7 @@
1617
1718 if __name__ == '__main__':
1819 import Tkinter
19- from s01_figsin_autotrig import FGSIN
20+ from s01_fgsin_autotrig import FGSIN
2021 def test(master=None):
2122 mix = Equipment(master,MIXER,auto_trig=True)
2223 fga = Equipment(Tkinter.Toplevel(master),FGSIN,auto_trig=True)
@@ -27,9 +28,10 @@
2728 connect(*[(o.logic,'samplerate') for o in [mix,fga,fgb]])
2829 fga.logic.freq = 0.001
2930 fga.logic.bias = 1.
31+ fga.logic.result
3032 fgb.logic.freq = 0.05
33+ fgb.logic.result
3134 mix.panel['plot'].children['result'].panel['plot'].ax.set_title('TITLE')
32-# mix.widget('plot.result.plot').ax.set_title('TITLE')
35+ # mix.widget('plot.result.plot').ax.set_title('TITLE')
3336 test(Tkinter.Tk())
3437 Tkinter.mainloop()
35-
\ No newline at end of file
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s03_integrate.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tutorial/s03_integrate.py Sat Feb 25 07:09:19 2012 +0900
@@ -0,0 +1,25 @@
1+# coding: utf-8
2+if __name__ == '__main__':
3+ import Tkinter
4+ from pylafii import *
5+ from s01_fgsin_autotrig import FGSIN
6+ from s02_mixer import MIXER
7+ def test(master=None):
8+ mix = Embed(master,MIXER,LayoutV,text='RF',auto_trig=True).grid(row=0,column=2,sticky=Tkinter.N)
9+ fga = Embed(master,FGSIN,LayoutV,text='LO',auto_trig=True).grid(row=0,column=0)
10+ fgb = Embed(master,FGSIN,LayoutV,text='IF',auto_trig=True).grid(row=0,column=1)
11+ connect((mix.logic,'sig_a'),(fga.logic,'result'))
12+ connect((mix.logic,'sig_b'),(fgb.logic,'result'))
13+ connect((fga.logic,'nums'),(fgb.logic,'nums'))
14+ connect(*[(o.logic,'samplerate') for o in [mix,fga,fgb]])
15+ fga.logic.freq = 0.05
16+ fga.logic.result
17+ fgb.logic.freq = 0.001
18+ fgb.logic.bias = 1.
19+ fgb.logic.nums = 2001
20+ fgb.logic.result
21+ mix.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
22+ fga.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
23+ fgb.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
24+ test(Tkinter.Tk())
25+ Tkinter.mainloop()
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s03_integrate_manualmount.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tutorial/s03_integrate_manualmount.py Sat Feb 25 07:09:19 2012 +0900
@@ -0,0 +1,30 @@
1+# coding: utf-8
2+if __name__ == '__main__':
3+ import Tkinter
4+ from pylafii import *
5+ from s01_fgsin_autotrig import FGSIN
6+ from s02_mixer import MIXER
7+ def test(master=None):
8+ mix = Embed(master,MIXER,LayoutV,text='RF',auto_trig=True,mount=False).grid(row=0,column=2,sticky=Tkinter.N)
9+ fga = Embed(master,FGSIN,LayoutV,text='LO',auto_trig=True,mount=False).grid(row=0,column=0)
10+ fgb = Embed(master,FGSIN,LayoutV,text='IF',auto_trig=True,mount=False).grid(row=0,column=1)
11+ mix_logic = MIXER()
12+ fga_logic = FGSIN()
13+ fgb_logic = FGSIN()
14+ connect((mix_logic,'sig_a'),(fga_logic,'result'))
15+ connect((mix_logic,'sig_b'),(fgb_logic,'result'))
16+ connect((fga_logic,'nums'),(fgb_logic,'nums'))
17+ connect(*[(o,'samplerate') for o in [mix_logic,fga_logic,fgb_logic]])
18+ fga_logic.freq = 0.05
19+ fgb_logic.freq = 0.001
20+ fgb_logic.bias = 1.
21+ fgb_logic.nums = 2001
22+ mix.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
23+ fga.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
24+ fgb.panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
25+ mix.mount(mix_logic)
26+ fga.mount(fga_logic)
27+ fgb.mount(fgb_logic)
28+ test(Tkinter.Tk())
29+ Tkinter.mainloop()
30+
\ No newline at end of file
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s04_modam.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tutorial/s04_modam.py Sat Feb 25 07:09:19 2012 +0900
@@ -0,0 +1,30 @@
1+# coding: utf-8
2+from pylafii import *
3+from s01_fgsin_autotrig import FGSIN
4+from s02_mixer import MIXER
5+
6+class MODAM(Logic):
7+ class Plot(Panel):
8+ def __init__(self,master=None,cnf={},**kw):
9+ Panel.__init__(self,master,cnf,**kw)
10+ mix = Embed(self,MIXER,LayoutV,name='mixer',text='RF',auto_trig=True).grid(row=0,column=2,sticky=Tkinter.N)
11+ fga = Embed(self,FGSIN,LayoutV,name='sga',text='LO',auto_trig=True).grid(row=0,column=0)
12+ fgb = Embed(self,FGSIN,LayoutV,name='sgb',text='IF',auto_trig=True).grid(row=0,column=1)
13+ connect((mix.logic,'sig_a'),(fga.logic,'result'))
14+ connect((mix.logic,'sig_b'),(fgb.logic,'result'))
15+ connect((fga.logic,'nums'),(fgb.logic,'nums'))
16+ connect(*[(o.logic,'samplerate') for o in [mix,fga,fgb]])
17+ fga.logic.freq = 0.05
18+ fga.logic.result
19+ fgb.logic.freq = 0.001
20+ fgb.logic.bias = 1.
21+ fgb.logic.nums = 2001
22+ fgb.logic.result
23+
24+if __name__ == '__main__':
25+ import Tkinter
26+ c = Equipment(Tkinter.Tk(),MODAM)
27+ c.panel['plot'].children['mixer'].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
28+ c.panel['plot'].children['sga'].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
29+ c.panel['plot'].children['sgb'].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
30+ Tkinter.mainloop()
diff -r 0140c466e2bf -r ff965b5162d1 src/tutorial/s05_modam.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tutorial/s05_modam.py Sat Feb 25 07:09:19 2012 +0900
@@ -0,0 +1,71 @@
1+# coding: utf-8
2+from pylafii import *
3+from s01_fgsin_autotrig import FGSIN
4+from s02_mixer import MIXER
5+
6+kw = lambda **kwargs: kwargs
7+class MODAM(Logic):
8+ lof = Terminal(.05)
9+ iff = Terminal(.001)
10+ ifm = Terminal(1.)
11+ ifb = Terminal(1.)
12+ def __init__(self,master=None,name=None):
13+ Logic.__init__(self,master,name)
14+ sga = FGSIN(self,name='sga')
15+ sgb = FGSIN(self,name='sgb')
16+ mix = MIXER(self,name='mixer')
17+ #
18+ connect((self,'lof'),(sga,'freq'))
19+ connect((self,'iff'),(sgb,'freq'))
20+ connect((self,'ifm'),(sgb,'mag'))
21+ connect((self,'ifb'),(sgb,'bias'))
22+ #
23+ for sg,name in [(sga,'sig_a'),(sgb,'sig_b')]: connect((mix,name),(sg,'result'))
24+ connect(*[(sg,'nums') for sg in [sga,sgb]])
25+ connect(*[(o,'samplerate') for o in [mix,sga,sgb]])
26+ #
27+ class Control(Panel):
28+ LAYOUT = [(Tkinter.Label,kw(text='LO Frequency [MHz]')),(Entry,kw(name='lof')),
29+ (Tkinter.Label,kw(text='IF Frequency [MHz]')),(Entry,kw(name='iff')),
30+ (Tkinter.Label,kw(text='IF Magnitude [mV]')),(Entry,kw(name='ifm')),
31+ (Tkinter.Label,kw(text='IF Bias Voltage [mV]')),(Entry,kw(name='ifb')),]
32+ class Plot(Panel):
33+ def __init__(self,master=None,cnf={},**kw):
34+ Panel.__init__(self,master,cnf,**kw)
35+ Embed(self,MIXER,LayoutV,name='mixer',text='RF',auto_trig=True,mount=False).pack(side=Tkinter.RIGHT)
36+ Embed(self,FGSIN,PlotLayout,name='sgb',text='IF',mount=False).pack(side=Tkinter.RIGHT,anchor=Tkinter.N)
37+ Embed(self,FGSIN,PlotLayout,name='sga',text='LO',mount=False).pack(side=Tkinter.RIGHT,anchor=Tkinter.N)
38+ def connect(self,logic):
39+ Panel.connect(self,logic)
40+ for name in ['sga','sgb','mixer']: self.children[name].mount(logic.children[name])
41+ class Menu(DefaultMenu):
42+ ITEMS = [
43+ #['File', ['insert', pylaf.kw(index=0,itemType='command',label='Load')],],
44+ ['File', ['add_command', kw(label='Load')],],
45+ ['Edit',
46+ ['add_command', kw(label='Copy',command='_copy')],
47+ ['add_command', kw(label='Paset')],
48+ ['Test', ['add_command', kw(label='Test2')]],
49+ ],
50+ ['Stub', ],
51+ ]
52+ def _copy(self):
53+ print '_copy was invoked !'
54+
55+if __name__ == '__main__':
56+ tk = Tkinter.Tk()
57+ app = Equipment(tk,MODAM,LayoutV)
58+# spc = Embed(Tkinter.Toplevel(tk),Spectrum); spc.assign(Spectrum()); spc.pack()
59+# spc.panel('plot').resize(dpi=50,figsize=(7,5))
60+# spc.panel('plot').ax.figure.subplots_adjust(
61+# left = .15,
62+# bottom = .15,
63+# )
64+# spc.panel('plot').ax.set_xlim([0.095,.105])
65+# spc.panel('plot').ax.set_ylim([-140.,0.])
66+ app.logic.children['sga'].nums = 2001
67+ for name in ['sga','sgb','mixer']:
68+ app.panel['plot'].children[name].panel['plot'].children['result'].panel['plot'].ax.set_ylim([-2.,2.])
69+ # app.panel['plot'].children[name].panel['plot'].children['result'].panel['plot'].resize(dpi=50,figsize=(5,4))
70+ Tkinter.mainloop()
71+
\ No newline at end of file
Show on old repository browser