-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex_processing.py
479 lines (389 loc) · 20.8 KB
/
ex_processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# -*- coding: utf-8 -*-
# for smart_terminal ( see mode Example )
# This is an object that extends the function of the smart terminal to
# do some special processing.
# This one is just an example of how to code them if you want to make one of your own.
# You should also look at other examples typically named xxx_processing.py
# It extends the gui, the automatic tasks, and the data processing ( including db access )
# Of the smart terminal.
#
# Will try to give lots of comments in this file
#.
#
import logging
#from Tkinter import * # is added everywhere since a gui assume tkinter namespace
import sys
import Tkinter as Tk
import abc
import abc_def
# from abc_base import PluginBase
# ---------------------------
import smart_terminal
sys.path.append( r"../rshlib" )
sys.path.append( r"../irtools" )
sys.path.append( r"../ir_test_data" )
sys.path.append( r"../irtools/sony" )
def test_func( a_string ):
print( a_string )
class ButtonAction( object ):
"""
this may become an asbstract class for plug in button actions in the smart terminal, a bit like processing add to the array
need ref to my processing object probably
hold info to implement a button in the gui
looks like a struct so far
"""
def __init__( self, a_processor, a_name, a_function ):
self.processor = a_processor # why this it is a mini controller where used?
self.name = a_name
self.function = a_function # where are the arguments elswhere in the thing in function_args with set_args
self.function_args = [ self.name, "I am an argument", "and another " ]
self.button = None
def set_button( self, a_button ):
"""
use when button actually created ( or move a factory in here??)
"""
self.button = a_button
def set_args( self, a_args ):
self.function_args = a_args
class ExampleProcessing( abc_def.ABCProcessing ):
"""
add on for smart_termial
implements abstract class
"""
def __init__( self, controller ): #iranalyzers ):
self.controller = controller
self.parameters = controller.parameters
self.logger = logging.getLogger( self.controller.logger_id + ".example" ) # assign to logger or get all the time does logger have aname or does this assign
self.logger.info( "in class ExamplerProcessing init for the smart_terminal" )
self.task_list = None
self.make_task_list()
# ------------------------- this is a data driven way to do this but may not be a great method move to add_gui
self.button_actions = [] # list of ButtonAction s define buttons both for gui and their actions
# most of this could be down in the add_gui
# use this to create buttons and define their actions, functions should take what for args, lists???
self.button_var = None # needs to be created after root
# self.controller.gui.root.button_var = Tk.StringVar()
# self.button_var.set( self.controller.parameters.rb_num_on )
#------ constants for controlling layout ------
#Button names
# for the ir analizer pretty much dead
self.BN_PRINT_SAMPLES = "Send Array a"
self.BN_PRINT_MAJORITY = "MPMotor Print Majority"
self.BN_PRINT_AVE = "Print Average"
self.BN_PRINT_FREQ = "Print Freq"
self.BN_COPY_SAMPLES = "Copy Samples"
self.BN_COPY_MAJORITY = "Copy Majority"
self.BN_COPY_AVE = "Copy Average"
self.BN_COPY_FREQ = "Copy Freq"
self.BN_CMP_MA = "Cmp M<>A"
self.BN_DN_MA = "DnLd Majority"
self.BN_DN_AV = "DnLd Average"
self.current_action = None
# -------------------------------------------------
def do_send_list( self, a_list ): #
"""
test for now to make the terminal send a list -- may be called an array elsewhere
"""
self.controller.do_send_list( a_list )
# -------------------------------------------------
def add_gui( self, parent, ): # if this were a class then could access its variables later
"""
make frame for motor control and return it
add buttons for different stepping now for unipolar in 3 modes, expand
"""
self.button_var = Tk.IntVar() # must be done after root is created
ret_frame = Tk.Frame( parent, width = 300, height=200, bg = "gray", relief = Tk.RAISED, borderwidth=1 )
button_actions = []
# ------------------------------------------
the_steping = [ "z", # coils go down phase across
"a1 0 0 0",
"a0 1 0 0",
"a0 0 1 0",
"a0 0 0 1",
"c4",
]
a_button_action = ButtonAction( self, "Simple\nSteping", self.do_send_list )
a_button_action.set_args( the_steping )
button_actions.append( a_button_action )
# ------------------------------------------
half_steping = [ "z", "a1 1 0 0 0 0 0 1",
"a0 1 1 1 0 0 0 0",
"a0 0 0 1 1 1 0 0",
"a0 0 0 0 0 1 1 1",
"c4"
]
a_button_action = ButtonAction( self, "Half\nSteping", self.do_send_list )
a_button_action.set_args( half_steping )
button_actions.append( a_button_action )
# ------------------------------------------
the_steping = [ "z", # coils go down phase across
"a1 0 0 1",
"a1 1 0 0",
"a0 1 1 0",
"a0 0 1 1",
"c4",
]
a_button_action = ButtonAction( self, "Full\nSteping", self.do_send_list )
a_button_action.set_args( the_steping )
button_actions.append( a_button_action )
# self.iranalyzers = button_actions # phase out iraanalyzers
self.button_actions = button_actions # controls creation and actions of additional buttons
color = "blue"
a_frame = Tk.Frame( ret_frame, width = 300, height=200, bg = "gray", relief = Tk.RAISED, borderwidth=1 )
a_frame.pack( side=Tk.TOP, expand = Tk.YES, ) #fill=Tk.Y ))
for ix, i_button_action in enumerate( self.button_actions ):
a_button = Tk.Button( a_frame, width=10, height=2, text = i_button_action.name, wraplength = 60 )
a_button.bind( "<Button-1>", self.do_button_action )
a_button.grid( row = ( ix / 4 ) + 1, column = ix%4, sticky ='E' + "W" )
a_frame.grid_columnconfigure( ix, weight=1 )
i_button_action.set_button( a_button )
# self.actButtons.append( a_button )
#print buttonX.cget('bg') # "SystemButtonFace"
b_frame = Tk.Frame( ret_frame, width = 300, height=200, bg = "blue", relief = Tk.RAISED, borderwidth=1 )
b_frame.pack( side=Tk.TOP, expand = Tk.YES, ) #fill=Tk.Y ))
ix_value = 0
rb0 = Tk.Radiobutton( b_frame, text="off", variable = self.button_var, value = ix_value )
rb0.grid( row=0, column = ix_value )
ix_value += 1
rb1 = Tk.Radiobutton( b_frame, text="unformmated", variable = self.button_var, value = ix_value )
rb1.grid( row=0, column = ix_value )
ix_value += 1
rb2 = Tk.Radiobutton( b_frame, text="CAP", variable = self.button_var, value = ix_value )
rb2.grid( row=0, column = ix_value )
ix_value += 1
self.lower_rb = ix_value # used in controller
rbx = Tk.Radiobutton( b_frame, text="lower", variable = self.button_var, value = ix_value )
rbx.grid( row=0, column=ix_value )
ix_value += 1
self.no_ws_rb = ix_value
rbx = Tk.Radiobutton( b_frame, text="No WS", variable = self.button_var, value=ix_value )
rbx.grid( row=0, column = ix_value )
ix_value += 1
self.url_to_wiki = ix_value # used in controller
rbx = Tk.Radiobutton( b_frame, text="url to wiki", variable = self.button_var, value = ix_value )
rbx.grid( row=0, column=ix_value )
ix_value += 1
self.comma_sep_rb = ix_value # used in controller
rbx = Tk.Radiobutton( b_frame, text="comma sep", variable = self.button_var, value = ix_value )
rbx.grid( row=0, column=ix_value )
ix_value += 1
self.undent_rb = ix_value
rbx = Tk.Radiobutton( b_frame, text="undent", variable = self.button_var, value = ix_value )
rbx.grid( row=0, column=ix_value )
ix_value += 1
rbx = Tk.Radiobutton( b_frame, text="test", variable = self.button_var, value=ix_value )
rbx.grid( row=0, column=ix_value )
return ret_frame
#----------------------------------------
def make_task_list( self ):
"""
for now use old stuff
"""
self.make_tasks_for_green_house( )
# ----------------------------------------
def make_tasks_for_green_house( self, ):
"""
!! have tasks ready for test
make tasks for green house, uses some stuff in
parameters
status, under development
"""
print( "just a test make tasks for green house " )
self.logger.debug( "motor_processing: make_tasks_for_green_house" )
self.task_list = smart_terminal.TaskList( self.controller )
self.task_list.reset_tasks()
# open port,
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_open_trans,
task_rec = self.task_list.task_open_rec,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1,
time_start = 2, time_delta = 5, time_error = 100 )
# check version
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_version_trans,
task_rec = self.task_list.task_version_rec,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1,
time_start = 5, time_delta = 5, time_error = 10 )
# print message
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_print_trans,
task_rec = self.task_list.task_print_rec,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1,
time_start = 5, time_delta = 5, time_error = 10 )
need_me.set_msg( "this is message 1" )
# print message
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_print_trans,
task_rec = self.task_list.task_print_rec,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1,
time_start = 1, time_delta = 5, time_error = 10 )
need_me.set_msg( "this is message 2" )
# print message
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_print_trans,
task_rec = self.task_list.task_print_rec,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1,
time_start = 1, time_delta = 5, time_error = 10 )
need_me.set_msg( "this is message 3" )
# aquire data -- but wait after version
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_gh_trans_aquire,
task_rec = self.task_list.task_gh_rec_aquire,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1, # = 0 infinite loop
time_start = 5, time_delta = .1, time_error = 10 )
# get temperature
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_gh_trans_temp,
task_rec = self.task_list.task_gh_rec_temp,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1, # = 0 infinite loop
time_start = .1, time_delta = .1, time_error = 10 )
# get temperature
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_gh_trans_humid,
task_rec = self.task_list.task_gh_rec_humid,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 1, # = 0 infinite loop
time_start = .1, time_delta = .1, time_error = 10 )
# go back !!!!!!!!
need_me = smart_terminal.ATask( task_list = self.task_list,
task_trans = self.task_list.task_go_back_n,
task_rec = self.task_list.task_go_back_n,
task_special = self.task_list.task_special_exception,
task_time_error = self.task_list.task_special_exception,
repeats = 0, # = 0 infinite loop -- but not for go back
time_start = .1, time_delta = 5, time_error = 10 )
need_me.set_msg( "task_go_back_n " )
need_me.set_TVO( 3 )
# ====================== end of loop ========================
#
# # close port, this is normally the never occuring end
# need_me = smart_terminal.ATask( self, task_trans = self.task_close_trans, task_rec = self.task_close_rec,
# task_special = self.task_special_exception, task_time_error = self.task_special_exception,
# repeats = 1, # = 0 infinite loop
# time_start = .1, time_delta = 5, time_error = 10 )
#
# # print message
# need_me = smart_terminal.ATask( self, task_trans = self.task_print_trans, task_rec = self.task_print_rec,
# task_special = self.task_special_exception, task_time_error = self.task_special_exception,
# repeats = 1,
# time_start = 5, time_delta = 5, time_error = 10 )
#
# need_me.set_msg( "this is message 999" )
#
return self.task_list
# #----------------------------------------
# # both the next 2 functions finall call doCurrent, they just set up the context
# def doButtonIra( self, event):
# """
# easy to add functions that look at the button text
# """
# for ix, anal in enumerate( self.iranalyzers ) :
# text = anal.name
# btext = event.widget["text"]
# if text == btext:
# self.current_iranalyzer = anal
# use_anal = anal
# break
#
# for b in ( self.gui_buttons ):
# b.config( bg= "white" )
# event.widget.config( bg="gray" )
#
# anal.copy_average()
# #print "broke with ", btext
# self.doCurrent( )
#----------------------------------------------
def do_button_action( self, event ):
"""
think this works but is odd we can actually do function based on the widget, and this does not
do a good job if invalid button is called
easy to add functions that look at the button text but could actually use the button instance self.button_actions.
"""
for ix, i_button_action in enumerate( self.button_actions ):
text = i_button_action.name # or i_button_action.button == event.widget !! probably better
btext = event.widget[ "text" ]
if event.widget == i_button_action.button:
#event.widget.config( bg="gray" ) # this may blink the button when the action happens look into this
i_button_action.function( i_button_action.function_args )
# self.current_action = act # not sure what did look in old cod
break
#----------------------------------------
# does the current action set up by the prior 2 functins
# left over from IR Terminal, might be of use when reimplemented.
def doCurrent( self ):
"""
do current action on current data set
with redirected output to my gui
"""
# the download buttons
if self.current_iranalyzer == None:
return
if self.current_action == self.BN_DN_AV:
self.controller.sendArray( self.current_iranalyzer.get_majority() )
return
elif self.current_action == self.BN_DN_MA:
self.controller.sendArray( self.current_iranalyzer.get_average() )
return
# these buttons redirect sys out
try:
#sys.stdout.flush()
#sys.stdout = self.save_redir
if self.current_action == self.BN_PRINT_SAMPLES:
self.current_iranalyzer.print_samples()
#sys.stdout.flush()
elif self.current_action == self.BN_PRINT_MAJORITY :
self.current_iranalyzer.print_majority()
#sys.stdout = self.save_sys_stdout
elif self.current_action == self.BN_PRINT_AVE:
self.current_iranalyzer.print_average()
elif self.current_action == self.BN_PRINT_FREQ:
self.current_iranalyzer.print_freq()
elif self.current_action == self.BN_COPY_SAMPLES:
self.current_iranalyzer.copy_samples()
sys.stdout.flush()
elif self.current_action == self.BN_COPY_MAJORITY :
self.current_iranalyzer.copy_majority()
sys.stdout.flush()
elif self.current_action == self.BN_COPY_AVE:
self.current_iranalyzer.copy_average()
elif self.current_action == self.BN_COPY_FREQ:
self.current_iranalyzer.copy_freq()
elif self.current_action == self.BN_CMP_MA:
self.current_iranalyzer.compare_majority_to_average()
else:
self.logger.error( "doCurrent() error, undefined action" )
except Exception as ex:
# perhaps really in finally, need to learn
#print "putting back sys.out"
#sys.stdout = self.save_sys_stdout
raise
finally:
sys.stdout.flush()
#print "putting back sys.out"
#sys.stdout = self.save_sys_stdout
#print "putting back sys.out done"
# ==============================================
if __name__ == '__main__':
"""
run the app here for convenience of launching
"""
print( "" )
print( " ========== starting SmartTerminal from example_processing.py ==============" )
import smart_terminal
a_app = smart_terminal.SmartTerminal( )
# ======================= eof ===========================