1010
1111
1212# Recognition Config
13- # This tell Ink Recognizer Service that the sample is in en-US.
13+ # This tell Ink Recognizer Service that the sample is in en-US.
1414# Default value is "en-US".
1515# If "language" in a stroke is specified, this will be overlaped in that stroke.
1616LANGUAGE_RECOGNITION_LOCALE = "en-US"
17- # This tell Ink Recognizer Service that domain of the application is writing, i.e. all strokes are writing.
18- # Default value is ApplicationKind.MIXED, which means let Ink Recognizer Service detect kind of strokes.
17+ # This tell Ink Recognizer Service that domain of the application is writing,
18+ # i.e. all strokes are writing.
19+ # Default value is ApplicationKind.MIXED, which means let Ink Recognizer
20+ # Service detect kind of strokes.
1921# If "kind" in a stroke is specified, this will be overlaped in that stroke.
2022APPLICATION_KIND = ApplicationKind .WRITING
2123
2224
23- # This ratio map the number of pixel for x and y axis coordinates on canvas into number of mm
24- # In InK Recognizer Server, every coordinate in InkPoint will multiply this number
25- # You may also want to mutliply /divide this value before sending request and after receiving response
25+ # This ratio map the number of pixel for x and y axis coordinates on canvas
26+ # into number of mm.
27+ # In InK Recognizer Server, every coordinate in InkPoint will multiply this number.
28+ # You may also want to mutliply /divide this value before sending request and
29+ # after receiving response.
2630app = wx .App (False )
27- mm_on_canvas = float (wx .GetDisplaySizeMM ()[1 ])
31+ mm_on_canvas = float (wx .GetDisplaySizeMM ()[1 ])
2832pixel_on_canvas = float (wx .GetDisplaySize ()[1 ])
29- UNIT_MULTIPLE = mm_on_canvas / pixel_on_canvas
33+ UNIT_MULTIPLE = mm_on_canvas / pixel_on_canvas
3034
3135
3236# UI config
@@ -60,18 +64,21 @@ def __init__(self,
6064class RecognitionManager :
6165 def __init__ (self ):
6266 self ._client = InkRecognizerClient (
63- URL , CREDENTIAL ,
64- ink_point_unit = InkPointUnit .MM ,
67+ URL ,
68+ CREDENTIAL ,
69+ ink_point_unit = InkPointUnit .MM ,
6570 # Convert stroke unit from pixel to mm by specify unit_multiple
6671 # You can also multiply the number when creating InkPoints
6772 unit_multiple = UNIT_MULTIPLE ,
6873 # Set language recognition locale
6974 language = LANGUAGE_RECOGNITION_LOCALE ,
7075 # Pre-set recognition type
7176 application_kind = APPLICATION_KIND
72- )
77+ )
78+ # Aruments in constructor becomes default arguments for each request
79+ # You can also specify these arguments in recognize_ink() requests.
7380 self ._reset_ink ()
74-
81+
7582 def _reset_ink (self ):
7683 self ._stroke_list = []
7784 self ._reset_stroke ()
@@ -88,11 +95,12 @@ def stroke_start(self):
8895 return
8996
9097 def stroke_end (self ):
91- stroke = InkStroke (len (self ._stroke_list ),
92- self ._curr_stroke_points )
98+ stroke = InkStroke (
99+ len (self ._stroke_list ),
100+ self ._curr_stroke_points )
93101 self ._stroke_list .append (stroke )
94102 self ._reset_stroke ()
95-
103+
96104 def get_stroke_list (self ):
97105 return self ._stroke_list
98106
@@ -150,12 +158,12 @@ def on_paint(self, event):
150158
151159 def on_click (self , event ):
152160 self ._recognition_manager .stroke_start ()
153-
161+
154162 def on_drag (self , event ):
155163 if event .Dragging ():
156164 self ._recognition_manager .add_point (event .X , event .y )
157165 self .Refresh ()
158-
166+
159167 def on_release (self , event ):
160168 self ._recognition_manager .stroke_end ()
161169 self .Refresh ()
@@ -171,7 +179,7 @@ def search(self, event, word, call_back):
171179 self ._recognition_manager .search (word , call_back )
172180
173181
174- # Sample wxpython app
182+ # Sample wxpython app
175183class InkRecognizerDemo (wx .Frame ):
176184 def __init__ (self ):
177185 super (InkRecognizerDemo , self ).__init__ (None )
@@ -184,18 +192,24 @@ def __init__(self):
184192 self .clear_button = wx .Button (self .view , wx .ID_ANY , 'Clear' , (0 , canvas_height - 30 ))
185193
186194 self .search_text = wx .TextCtrl (self .view , wx .ID_ANY , "" , (0 , canvas_height - 120 ))
187- func_search = lambda event : self .view .search (event , self .search_text .GetLineText (0 ), call_back = self .show_search_result )
188- self .search_button .Bind (wx .EVT_BUTTON , func_search )
189- func_recognize = lambda event : self .view .recognize (event , call_back = self .show_result )
190- self .recognize_button .Bind (wx .EVT_BUTTON , func_recognize )
195+ self .search_button .Bind (wx .EVT_BUTTON , self ._search_function )
196+ self .recognize_button .Bind (wx .EVT_BUTTON , self ._recognize_function )
191197 self .clear_button .Bind (wx .EVT_BUTTON , self .view .clear )
192-
193198
194- def show_result (self , result ):
199+ def _search_function (self , event ):
200+ return self .view .search (
201+ event ,
202+ self .search_text .GetLineText (0 ),
203+ call_back = self ._show_search_result )
204+
205+ def _recognize_function (self , event ):
206+ return self .view .recognize (event , call_back = self ._show_result )
207+
208+ def _show_result (self , result ):
195209 dlg = wx .MessageDialog (self , result , "Recognition Result" )
196210 dlg .ShowModal ()
197-
198- def show_search_result (self , num_words ):
211+
212+ def _show_search_result (self , num_words ):
199213 dlg = wx .MessageDialog (self , "Find %s words" % num_words , "Recognition Result" )
200214 dlg .ShowModal ()
201215
0 commit comments