import json __author__ = 'frank' class Conversion: def __init__(self): pass def resolve_refs(self, job): initNode = job.get('initNode') job.pop('initNode', None) config = job.pop('config', None) atoms_data = job.pop('atoms', None) atoms_dict = {} for k in atoms_data.keys(): #print k, atoms_data[k] #print atoms_data[k]['atom_reference_pointer'] atoms_data[k]['key'] = k atoms_dict[atoms_data[k]['atom_reference_pointer']] = atoms_data[k] for k in sorted(job.keys()): if job[k].get('atom'): #print k, job[k]['atom']['atom_reference_pointer'] if job[k]['atom']['atom_reference_pointer']: job[k]['atom']['data'] = atoms_dict[job[k]['atom']['atom_reference_pointer']] return atoms_data, config, initNode class MasterJobSelectionStep: def __init__(self, active_col): self.data = {'Column': 0, 'Name': 'Operation Mode', 'Row': 0, 'Type': 7, 'children': [{'children': [{'invisible': False, 'leaf': True, 'myText': 'Select active column', 'myValue': active_col, 'readonly': False, 'type': 'COMBOBOX'}], 'expanded': True, 'myText': 'Options'} ], 'execPy': '', 'expanded': False, 'id': 0, 'leaf': False} class MasterJobStartStep: def __init__(self, trigger_src, id=1, row=2, column=0, idcodesrc="0", delIdcode="false", display_time="1", op_mode="", prg_sel= "false", job_sel= "false"): if delIdcode == 0: delIdcode = "false" else: delIdcode = "true" self.data = {'Column': column, 'Name': 'Start', 'Row': row, 'Type': 0, 'children': [{'children': [{'invisible': False, 'leaf': True, "min": 0.1, "max": 10, "step": 0.1, "default": 1, 'myText': 'Job step info display time', 'myValue': str(display_time), 'readonly': False, 'type': 'NUMBERFIELD_U'}], 'expanded': True, 'myText': 'Options'}, {'children': [{'choice': [[0, 'no id code'], [1, 'Cycle Counter'], [2, 'Open Protocol'], [3, 'Scanner'], [4, 'Multiple ID Inputs'], [5, 'VW XML']], 'invisible': False, 'leaf': True, 'myText': 'Source Selection Start', 'myValue': str(idcodesrc), 'readonly': False, 'StepType': 0, 'type': 'COMBOBOX'}, {'invisible': False, 'leaf': True, 'myText': 'Delete ID code after start', 'myValue': str(delIdcode), 'readonly': False, 'type': 'CHECKBOX'} ], 'expanded': True, 'myText': 'ID Code Source'}, {'children': [{'choice': [[0, 'auto'], [1, 'select'], [2, 'manual']], 'invisible': False, 'leaf': True, 'myText': 'Operation Mode', 'myValue': str(op_mode), 'readonly': column == 0, 'StepType': 0, 'type': 'COMBOBOX' }, { 'invisible': False, 'leaf': False, 'myText': 'Trigger', 'expanded': column > 0, 'readonly': column == 0, 'children': [ {'invisible': False, 'leaf': True, 'myText': 'HMI', 'myValue': trigger_src.get('HMI'), 'readonly': False, 'type': 'CHECKBOX'}, #{'invisible': False, # 'leaf': True, # 'myText': 'Pin for HMI (optional)', # 'myValue': "",#str(prg_sel), # 'readonly': False, # 'type': 'EDITBOX'}, {'invisible': False, 'leaf': True, 'myText': 'Open Protocol', 'myValue': trigger_src.get('Open Protocol'), 'readonly': False, 'type': 'CHECKBOX'}, {'invisible': False, 'leaf': True, 'myText': 'BMS Signal ManOp', 'myValue': trigger_src.get('BMS Signal ManOp'), 'readonly': False, 'type': 'CHECKBOX'} ] }, { 'invisible': False, 'leaf': True, 'myText': 'Allow Prg selection', 'myValue': str(prg_sel), 'readonly': False, 'type': 'CHECKBOX' }, { 'invisible': False, 'leaf': True, 'myText': 'Allow Job selection', 'myValue': str(job_sel), 'readonly': False, 'type': 'CHECKBOX' }], 'expanded': True, 'myText': 'Operation Mode Settings'}], 'execPy': '', 'expanded': False, 'id': id, 'leaf': False} class MasterJobScanStep: def __init__(self, id, row, column, text, name, comment, scanCodes, timeout=600, range="{\"1-256\"}", source=0, target=0, trigger=2, play_sound=False, attempts=2, display_text="", id_range="{\"1-256\"}", extjobctrl=False, laserOnTime=3): self.data = {'Column': column, 'Name': 'ID Input', 'Row': row, 'Type': 5, 'children': [ {"myText": "General", "expanded": True, "children": [ {"myText": "Name", "myValue": name, "type": "EDITBOX", "maxLength": 40, "leaf": True, "execPy": "step['name'] = firstLevel.get('myValue')"}, {"myText": "Comment", "myValue": comment, "type": "EDITBOX", "maxLength": 100, "leaf": True, "execPy": "step['comment'] = firstLevel.get('myValue')" } ] }, {'children': [{'choice': [[0, 'no id code'], [1, 'Cycle Counter'], [2, 'Open Protocol'], [3, 'Scanner'], [4, 'Multiple ID Inputs'], [5, 'VW XML']], 'invisible': False, 'leaf': True, 'myText': 'Source Selection Start', 'myValue': "0", 'readonly': True, 'StepType': 0, 'type': 'COMBOBOX'}, {'invisible': False, 'leaf': True, 'myText': 'Delete ID code after start', 'myValue': "false", 'readonly': True, 'type': 'CHECKBOX'} ], 'expanded': True, 'readonly': True, 'myText': 'ID Code Source'}, {'children': [ { 'leaf': True, 'myText': 'Source Selection', 'myValue': str(source), 'StepType': 5, 'choice': [ [0, 'Scanner'], [1, 'Open Protocol'] ], 'type': "COMBOBOX", 'readonly': False }, {'choice': [[1, 'ID Code'], [4, 'ID Input Assignment'], [5, 'ID Code / ID Input Assignment']], 'leaf': True, 'myText': 'Choose target for ID Input', 'myValue': str(target), 'type': 'COMBOBOX' }, {'invisible': False, 'leaf': True, 'myText': 'Masking ID Code', 'myValue': str(id_range), #'1-64' 'readonly': False, 'type': 'EDITBOX' }, {'invisible': False, 'leaf': True, 'myText': 'Masking', 'myValue': str(range), #'1-64' 'readonly': False, 'type': 'EDITBOX' }, #{"myText": "Attempts", # "myValue": str(attempts), # "invisible": False, # "validation": "ATTEMPTNUMBER", # "readonly": False, # "type": "EDITBOX", # "leaf": True, #}, {'myText': "Display Text", "myValue": str(display_text), "type": "EDITBOX", "invisible": False, "readonly": False, "maxLength": 80, "leaf": True }, { 'leaf': True, 'myText': 'External job control', 'myValue': str(extjobctrl).lower(), 'type': 'CHECKBOX' }, { 'children': [ { 'default': 600, 'leaf': True, 'max': 1000, 'min': 1, 'myText': 'Timeout', 'myValue': str(timeout), 'step': 1, 'type': 'NUMBERFIELD_U'}, { 'leaf': True, 'myText': 'Error Message after Timeout', 'myValue': str(text), 'maxLength': 80, 'type': 'EDITBOX' } ], 'myText': 'Timeout Options', 'expanded': True }, {'children': [ { 'leaf': True, 'myText': 'Triggermode for scanner', 'myValue': str(trigger), 'choice': [[5, 'Play Startbutton'], [1, 'Menubutton'], [2, 'Button Left'], [3, 'Button Right'], [4, 'BMS'] ], 'type': "COMBOBOX", 'readonly': False }, { 'leaf': True, 'max': 25, 'min': 1, 'step': 0.5, 'myText': 'Laser on time', 'myValue': str(laserOnTime), 'type': 'NUMBERFIELD_U' }, { 'leaf': True, 'myText': 'Play decode signal tone', 'myValue': str(play_sound).lower(), 'type': 'CHECKBOX' }, {'children': [ { 'leaf': True, 'myText': 'Code 128', 'myValue': str(scanCodes.get('Code128', True)).lower(), 'type': 'CHECKBOX' }, { 'leaf': True, 'myText': 'UCC/EAN-128', 'myValue': str(scanCodes.get('UccEan128', True)).lower(), 'type': 'CHECKBOX' }, { 'leaf': True, 'myText': 'Code 39', 'myValue': str(scanCodes.get('Code39', True)).lower(), 'type': 'CHECKBOX' }, { 'leaf': True, 'myText': 'Code 93', 'myValue': str(scanCodes.get('Code93', True)).lower(), 'type': 'CHECKBOX' }, { 'leaf': True, 'myText': 'Code 11', 'myValue': str(scanCodes.get('Code11', True)).lower(), 'type': 'CHECKBOX' }, { 'leaf': True, 'myText': 'Interleaved 2 of 5', 'myValue': str(scanCodes.get('Interleaved2of5', True)).lower(), 'type': 'CHECKBOX' }, { 'leaf': True, 'myText': 'Codabar', 'myValue': str(scanCodes.get('Codabar', True)).lower(), 'type': 'CHECKBOX' }, { 'leaf': True, 'myText': 'MSI', 'myValue': str(scanCodes.get('Msi', True)).lower(), 'type': 'CHECKBOX' } ], 'expanded': True, 'myText': 'Barcodes' } ], 'expanded': True, 'myText': 'Scan Options' } ], 'expanded': True, 'leaf': False, 'myText': 'ID Input Options', 'myValue': '' } ], 'expanded': False, 'id': id, 'leaf': False} class MasterJobEndStep: def __init__(self, id, row, column=0): self.data = {'Column': column, 'Name': 'End', 'Row': row, 'Type': 2, 'children': [{'children': [{'execPy': '', 'invisible': True, 'leaf': True, 'myText': 'Enable tool', 'myValue': 'false', 'readonly': True, 'type': 'CHECKBOX'}], 'expanded': True, 'myText': 'Options'}], 'execPy': '', 'expanded': False, 'id': id, 'leaf': False} class MasterJob: def __init__(self, initNode): self.data = [{ 'Comment': initNode.get('jobComment'), 'Date': initNode.get('jobDate'), 'Name': 'MASTER', 'Slot': 0, 'User': initNode.get('jobUser'), 'Version': '', 'id': 1, 'steps': []}] def appendStep(self, step): self.data[0]['steps'].append(step.data) ''' if __name__ == '__main__': master = MasterJob() master.appendStep(MasterJobStartStep(1)) master.appendStep(MasterJobScanStep()) master.appendStep(MasterJobEndStep()) data = json.dumps(master.data, indent=2, sort_keys=True) print "JSON", data '''