Revisão | 3cdb128e423719c742b1a1a9a61cad6bb3cd5427 (tree) |
---|---|
Hora | 2013-03-04 21:13:57 |
Autor | bijoux |
Commiter | bijoux |
restore AutoTrig
restore SelectionPanel
@@ -24,7 +24,7 @@ | ||
24 | 24 | コントロールパネルで自動生成可能なポートを返す |
25 | 25 | ''' |
26 | 26 | MYTYPES = (types.IntType,types.FloatType,types.StringType, |
27 | - numpy.float64,numpy.int64,data.SpecificTuple) | |
27 | + numpy.float64,numpy.int64,data.SpecificTuple,data.Selection) | |
28 | 28 | members = {} |
29 | 29 | for k,v in laf.getports(logic).iteritems(): |
30 | 30 | value = v.container.value |
@@ -482,6 +482,11 @@ | ||
482 | 482 | b = data.TupleBridge(w) |
483 | 483 | v.link(laf.port(b,'value')) |
484 | 484 | ControlPanel(w,logic=b).pack() |
485 | + elif isproxyaccess and isinstance(v.container.value,data.Selection): | |
486 | + # セレクションパネルの作成 | |
487 | + w = Tkinter.LabelFrame(self,text=k); w.grid(column=0,row=i,columnspan=2) | |
488 | + w = data.SelectionPanel(w); w.pack() | |
489 | + v.link(laf.port(w,'value')) | |
485 | 490 | else: |
486 | 491 | # 通常は Entry リストを作成する |
487 | 492 | if isproxyaccess: |
@@ -790,12 +795,14 @@ | ||
790 | 795 | |
791 | 796 | def extract_components(module): |
792 | 797 | result = {} |
798 | + ignore = [laf.Logic,tkext.tkWidget,vtkext.vtkLogic,vtkext.implicit.ImplicitFunction] | |
793 | 799 | for k,mdl in inspect.getmembers(module,lambda x:inspect.ismodule(x)): |
794 | 800 | klass = inspect.getmembers(mdl,lambda x:inspect.isclass(x)) |
795 | 801 | for k,cls in klass: |
796 | 802 | for c in inspect.getmro(cls): |
797 | 803 | if c is laf.Logic or c is tkext.tkWidget: |
798 | - if cls is not laf.Logic and cls is not tkext.tkWidget and cls is not vtkext.vtkLogic: | |
804 | + # if cls is not laf.Logic and cls is not tkext.tkWidget and cls is not vtkext.vtkLogic: | |
805 | + if cls not in ignore: | |
799 | 806 | result[cls] = None |
800 | 807 | return result |
801 | 808 |
@@ -1,8 +1,10 @@ | ||
1 | 1 | # coding: utf-8 |
2 | 2 | |
3 | +import Tkinter | |
3 | 4 | from ingredient import Logic,ActualEvent,event |
5 | +from tkext import tkWidget | |
4 | 6 | |
5 | -class SpecificTuple(tuple,object): | |
7 | +class SpecificTuple(tuple): | |
6 | 8 | keys = None |
7 | 9 | |
8 | 10 | class Point(SpecificTuple): |
@@ -40,3 +42,48 @@ | ||
40 | 42 | self.value = None |
41 | 43 | # keys をクリアする |
42 | 44 | self.keys = None |
45 | + | |
46 | +class Selection(int): | |
47 | + option = None | |
48 | + | |
49 | +class SelectionPanel(Tkinter.Frame,tkWidget): | |
50 | + def __init__(self,*args,**kw): | |
51 | + Tkinter.Frame.__init__(self,*args,**kw) | |
52 | + self._value = Tkinter.IntVar(self.value) | |
53 | + self._buffer = None | |
54 | + self._updated = False | |
55 | + self._event_loop() | |
56 | + def _event_loop(self): | |
57 | + self.populate_option() | |
58 | + if self._updated: | |
59 | + self._value.set(self._buffer) | |
60 | + self._updated = False | |
61 | + self.after(50,self._event_loop) | |
62 | + @event | |
63 | + def value(self): | |
64 | + self._buffer = self.value | |
65 | + self._updated = True | |
66 | + def populate_option(self): | |
67 | + # ひとつでも居住していなければラジオボタンを再生成する | |
68 | + if self.value == None: | |
69 | + return | |
70 | + option = self.value.option | |
71 | + option = [v.replace(' ','') for v in option] | |
72 | + resident = [''.join(v.config()['text'][4]) for v in self.children.itervalues()] | |
73 | + for o in option: | |
74 | + if o not in resident: | |
75 | + self.removeall() | |
76 | + self.generate() | |
77 | + break | |
78 | + def removeall(self): | |
79 | + scrap = [o for o in self.children.itervalues()] | |
80 | + for o in scrap: | |
81 | + o.destroy() | |
82 | + def generate(self): | |
83 | + option = self.value.option | |
84 | + for i,o in enumerate(option): | |
85 | + Tkinter.Radiobutton(self,text=o,variable=self._value,value=i,command=self.update).pack(anchor=Tkinter.W) | |
86 | + def update(self): | |
87 | + klass = self.value.__class__ | |
88 | + self.value = klass(self._value.get()) | |
89 | + | |
\ No newline at end of file |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | import Tkinter |
4 | 4 | import ingredient as laf |
5 | -from ingredient import event | |
5 | +from ingredient import event,Port | |
6 | 6 | |
7 | 7 | class tkWidget(object): pass |
8 | 8 |
@@ -34,3 +34,15 @@ | ||
34 | 34 | self._buffer = container.value |
35 | 35 | self._updated = True |
36 | 36 | |
37 | +class AutoTrig(Tkinter.Checkbutton,tkWidget): | |
38 | + trig = Port() | |
39 | + def __init__(self,master=None,cnf={},**kw): | |
40 | + Tkinter.Checkbutton.__init__(self,master,cnf,**kw) | |
41 | + self._status = Tkinter.IntVar() | |
42 | + self.config(text='AutoTrig',variable=self._status) | |
43 | + self._event_loop() | |
44 | + def _event_loop(self): | |
45 | + if self._status.get(): | |
46 | + self.trig | |
47 | + self.after(50,self._event_loop) | |
48 | + | |
\ No newline at end of file |
@@ -4,3 +4,4 @@ | ||
4 | 4 | from actor import * |
5 | 5 | from mapper import * |
6 | 6 | from source import * |
7 | +from implicit import * |
@@ -0,0 +1,22 @@ | ||
1 | +# coding: utf-8 | |
2 | + | |
3 | +import vtk | |
4 | +from pylafiii.ingredient import event | |
5 | +from pylafiii.data import Selection | |
6 | +from base import vtkLogic | |
7 | + | |
8 | +class ImplicitFunction(vtkLogic): pass | |
9 | + | |
10 | +class ImplicitBoolean(ImplicitFunction): | |
11 | + vtkClass = vtk.vtkImplicitBoolean | |
12 | + class OperationType(Selection): | |
13 | + option = ('Union','Intersection','Difference','Union of Magnitudes') | |
14 | + def initialize(self): | |
15 | + self.optype = self.OperationType(self.vtkobj.GetOperationType()) | |
16 | + @event | |
17 | + def optype(self): | |
18 | + dct = {0:self.vtkobj.SetOperationTypeToUnion, | |
19 | + 1:self.vtkobj.SetOperationTypeToIntersection, | |
20 | + 2:self.vtkobj.SetOperationTypeToDifference, | |
21 | + 3:self.vtkobj.SetOperationTypeToUnionOfMagnitudes} | |
22 | + dct[self.optype].__call__() |