def if_elif_func(node, label): logs = {} # "if" line if_widget, if_layout = simpleWidgets.simpleWidget() # if if_layout.addWidget(simpleWidgets.simpleLabel(label)) # condition sub_widget = terminalWidgets.LE_terminal() sub_widget.setup(node.test) if_layout.addWidget(sub_widget) logs.update({id(sub_widget): sub_widget}) # : if_layout.addWidget(simpleWidgets.simpleLabel(':')) # Draw up a new ASTWidget to handle the branch space_widget, space_layout = simpleWidgets.simpleWidget() space_layout.addSpacing(50) ASTWidget_widget = ASTWidget(node) space_layout.addWidget(ASTWidget_widget) for branch in node: t = ASTWidget_widget.branchID_2_terminals[id(branch)] logs.update(t) return if_widget, space_widget, logs
def rb_dotted_as_name(node): # Make the main widget container widget, layout = simpleWidgets.simpleWidget() logs = {} # Check the value n = len(node) for i in range(n): if i != 0: layout.addWidget(simpleWidgets.simpleLabel('.')) child, log = fetch(node[i]) layout.addWidget(child) logs.update(log) if node.target: layout.addWidget(simpleWidgets.simpleLabel(' as ')) # Check the target targetWidget = terminalWidgets.LE_terminal() targetWidget.setup(node, target=True) log = {id(targetWidget): targetWidget} layout.addWidget(targetWidget) logs.update(log) return widget, logs
def nH_widgetBuilder(cls, node, astTools): widget, layout = simpleWidgets.simpleWidget(vertical=True) logs = {} ## First if statement ========================================================================================== ifnode = node.value[0] if_widget, space_widget, new_logs = cls.if_elif_func(ifnode, 'if') layout.addWidget(if_widget) layout.addWidget(space_widget) ## ============================================================================================================= if len(node.value) > 0: for i in range(len(node.value)): if i == 0: pass elif node.value[i].type == 'elif': elifnode = node.value[i] if_widget, space_widget, new_logs = cls.if_elif_func( elifnode, 'elif') layout.addWidget(if_widget) layout.addWidget(space_widget) else: elsenode = node.value[i] if_widget, space_widget, new_logs = cls.if_elif_func( elsenode) layout.addWidget(if_widget) layout.addWidget(space_widget) return widget, logs
def rb_dict(node): # Make the main widget container widget, layout = simpleWidgets.simpleWidget() logs = {} # Drop left bracket layout.addWidget(simpleWidgets.simpleLabel('{')) n = len(node) for i in range(n): if i != 0: layout.addWidget(simpleWidgets.simpleLabel(',')) child, log = fetch(node[i].key) layout.addWidget(child) logs.update(log) # Drop right colon layout.addWidget(simpleWidgets.simpleLabel(':')) child, log = fetch(node[i].value) layout.addWidget(child) logs.update(log) # Drop right bracket layout.addWidget(simpleWidgets.simpleLabel('}')) return widget, logs
def rb_tupList(node, bracketingSymbols): # Make the main widget container widget, layout = simpleWidgets.simpleWidget() logs = {} # Drop left bracket lbWidget = QLabel() lbWidget.setText(bracketingSymbols[0]) layout.addWidget(lbWidget) n = len(node) for i in range(n): if i != 0: layout.addWidget(simpleWidgets.simpleLabel(',')) child, log = fetch(node[i]) logs.update(log) layout.addWidget(child) # Drop right bracket rbWidget = QLabel() rbWidget.setText(bracketingSymbols[1]) layout.addWidget(rbWidget) return widget, logs
def rb_for(node): widget, layout = simpleWidgets.simpleWidget(vertical=True) logs = {} # "For" line For_widget, For_layout = simpleWidgets.simpleWidget() # for For_layout.addWidget(simpleWidgets.simpleLabel('for')) # iterator # iterator , iterator_log = fetch(node.iterator) iterator, iterator_log = LE_handle(node.iterator) For_layout.addWidget(iterator) logs.update(iterator_log) # in For_layout.addWidget(simpleWidgets.simpleLabel('in')) # target # target , target_log = fetch(node.target) target, target_log = LE_handle(node.target) For_layout.addWidget(target) logs.update(target_log) # : For_layout.addWidget(simpleWidgets.simpleLabel(':')) layout.addWidget(For_widget) # Call back to the editAST class of astElements space_widget, space_layout = simpleWidgets.simpleWidget() space_layout.addSpacing(50) astElements_widget = standardWidgets.ASTWidget(node) space_layout.addWidget(astElements_widget) layout.addWidget(space_widget) # TODO: EditAST needs a way to pass the terminals in a way that makes sense terminals = [] for branch in node: t = astElements_widget.branchID_2_terminals[id(branch)] logs.update(t) return widget, logs
def nH_widgetBuilder(cls, node, astTools): widget, layout = simpleWidgets.simpleWidget(vertical=True) logs = {} # "For" line For_widget, For_layout = simpleWidgets.simpleWidget() # for For_layout.addWidget(simpleWidgets.simpleLabel('for')) # Get the appropriate widget and add it to the layout sub_widget = terminalWidgets.LE_terminal() sub_widget.setup(node.iterator) For_layout.addWidget(sub_widget) logs.update({id(sub_widget): sub_widget}) # in For_layout.addWidget(simpleWidgets.simpleLabel('in')) # Get the appropriate widget and add it to the layout sub_widget = terminalWidgets.LE_terminal() sub_widget.setup(node.target) For_layout.addWidget(sub_widget) logs.update({id(sub_widget): sub_widget}) # : For_layout.addWidget(simpleWidgets.simpleLabel(':')) layout.addWidget(For_widget) # Draw up a new ASTWidget to handle the branch space_widget, space_layout = simpleWidgets.simpleWidget() space_layout.addSpacing(50) ASTWidget_widget = ASTWidget(node) space_layout.addWidget(ASTWidget_widget) layout.addWidget(space_widget) # TODO: EditAST needs a way to pass the terminals in a way that makes sense for branch in node: t = ASTWidget_widget.branchID_2_terminals[id(branch)] logs.update(t) return widget, logs
def rb_ifelseblock(node): widget, layout = simpleWidgets.simpleWidget(vertical=True) logs = {} for branch in node.value: subWidget, log = fetch(branch) logs.update(log) layout.addWidget(subWidget) return widget, logs
def rb_if(node, prepend=''): widget, layout = simpleWidgets.simpleWidget(vertical=True) logs = {} if prepend != 'else': testWidget, testLayout = simpleWidgets.simpleWidget() # Add the if label testLayout.addWidget(simpleWidgets.simpleLabel(prepend + 'if ')) # Add the test node subTestWidget, log = fetch(node.test) logs.update(log) testLayout.addWidget(subTestWidget) # Add the trailing colon: testLayout.addWidget(simpleWidgets.simpleLabel(':')) layout.addWidget(testWidget) else: testWidget, testLayout = simpleWidgets.simpleWidget() testLayout.addWidget(simpleWidgets.simpleLabel('else:')) layout.addWidget(testWidget) # Add the rest of the widgets that follow in the value section # Call back to the editAST class of astElements space_widget, space_layout = simpleWidgets.simpleWidget() space_layout.addSpacing(50) astElements_widget = standardWidgets.ASTWidget(node) space_layout.addWidget(astElements_widget) layout.addWidget(space_widget) # for branch in node.value: # subWidget , log = fetch( branch ) # logs.update( log ) # layout.addWidget(subWidget) # print('Function Call') # print(logs) return widget, logs
def nH_widgetBuilder(cls, node, astTools): # Make the frame widget = QFrame() layout = QVBoxLayout() widget.setLayout(layout) terminalsDict = {} # Build the widget from the assignment node # Set up the title titleString = '' if len(node.value) == 1: titleString = node.value.value else: for i in range(len(node.value) - 1): if i == 0: pass else: titleString += '.' titleString += node.value[i].value titleLabel = simpleWidgets.simpleLabel(titleString) titleLabel.setAlignment(Qt.AlignHCenter) titleLabel.setToolTip(node.dumps()) layout.addWidget(titleLabel) # Add the inputs inputs = node.value[-1] if len(inputs) == 0: pass else: inputTitleLabel = simpleWidgets.simpleLabel('Inputs') inputTitleLabel.setAlignment(Qt.AlignHCenter) layout.addWidget(inputTitleLabel) for i, eachInput in enumerate(inputs): eachWidget, eachLayout = simpleWidgets.simpleWidget() if eachInput.target: # Check for keyword arguments input_label = '{} : '.format(eachInput.target) else: input_label = 'Argument {} : '.format(i + 1) # No kwargs eachLabel = simpleWidgets.simpleLabel(input_label) eachLE = terminalWidgets.LE_terminal() # eachLE = terminalWidgets.COMBO_terminal() eachLE.setup(eachInput.value) eachLayout.addWidget(eachLabel) eachLayout.addWidget(eachLE, 1) # eachLayout.addStretch(1) layout.addWidget(eachWidget, 1) terminalsDict.update({id(eachLE): eachLE}) return widget, terminalsDict
def else_func(node): logs = {} # "if" line else_widget, else_layout = simpleWidgets.simpleWidget() # if else_layout.addWidget(simpleWidgets.simpleLabel('else')) # : else_layout.addWidget(simpleWidgets.simpleLabel(':')) # Draw up a new ASTWidget to handle the branch space_widget, space_layout = simpleWidgets.simpleWidget() space_layout.addSpacing(50) ASTWidget_widget = ASTWidget(node) space_layout.addWidget(ASTWidget_widget) for branch in node: t = ASTWidget_widget.branchID_2_terminals[id(branch)] logs.update(t) return else_widget, space_widget, logs
def rb_getitem(node): # Make the main widget container widget, layout = simpleWidgets.simpleWidget() logs = {} # Put parenthesis around this layout.addWidget(simpleWidgets.simpleLabel('[')) n = len(node) # Loop through the number of arguments child, log = fetch(node.value) layout.addWidget(child) logs.update(log) # Put parenthesis around this layout.addWidget(simpleWidgets.simpleLabel(']')) return widget, logs
def rb_atomtrailers(node): # Make the main widget container widget, layout = simpleWidgets.simpleWidget() logs = {} # Get the length of the tuple n = len(node) # Make a gui element for each entry, and add it to the main gui widget for i in range(n): child, log = fetch(node[i]) layout.addWidget(child) logs.update(log) if (i < n - 1): if (node[i + 1].type == 'name'): layout.addWidget(simpleWidgets.simpleLabel('.')) return widget, logs
def rb_call_argument(node): # Make the main widget container widget, layout = simpleWidgets.simpleWidget() logs = {} if node.target: # Left and right side of an equals sign # Check the target targetWidget, log = fetch(node.target) layout.addWidget(targetWidget) logs.update(log) # Place the equals sign layout.addWidget(simpleWidgets.simpleLabel(' = ')) # Check the value valueWidget, log = fetch(node.value) layout.addWidget(valueWidget) logs.update(log) return widget, logs
def rb_call(node): # Make the main widget container widget, layout = simpleWidgets.simpleWidget() logs = {} # Put parenthesis around this layout.addWidget(simpleWidgets.simpleLabel('(')) # Loop through the number of arguments n = len(node) for i in range(n): child, log = fetch(node[i]) layout.addWidget(child) logs.update(log) if i != (n - 1): layout.addWidget(simpleWidgets.simpleLabel(',')) # Put parenthesis around this layout.addWidget(simpleWidgets.simpleLabel(')')) return widget, logs
def rb_pass(node): widget, layout = simpleWidgets.simpleWidget() layout.addWidget(simpleWidgets.simpleLabel('pass')) # Set the status of the pass statement to be 1, a success widget.status = 1 return widget, {id(widget): widget}
def nH_widgetBuilder(node, astTools): """ nH_widgetBuilder is defined in nodeHander class but it MUST be overwritten. This is where the widget and its functionality is defined. The only purpose of the method defined in nodeHandler is to alert the program that the method hasn't been overwritten and can't be used. """ # Make the frame widget = QFrame() layout = QVBoxLayout() widget.setLayout(layout) terminalsDict = {} # Add the title titleLabel = simpleWidgets.simpleLabel('Create From Mold') titleLabel.setToolTip(node.dumps()) titleLabel.setAlignment(Qt.AlignHCenter) layout.addWidget(titleLabel) ## Check for each positional argument labels_tooltips_nodes = [] DM_label = 'DM Object : ' DM_tooltip = 'Name of the de-la-mo model object' DM_node = node.value.value[2].value[0] labels_tooltips_nodes.append([DM_label, DM_tooltip, DM_node]) mold_label = 'Mold : ' mold_tooltip = 'Mold' mold_node = node.value.value[2].value[1] labels_tooltips_nodes.append([mold_label, mold_tooltip, mold_node]) direction_label = 'Direction : ' direction_tooltip = '\'OFFSET\' or \'ORIG\' ' direction_node = node.value.value[2].value[2] labels_tooltips_nodes.append( [direction_label, direction_tooltip, direction_node]) thickness_label = 'Layer thickness : ' thickness_tooltip = 'Layer thickness' thickness_node = node.value.value[2].value[3] labels_tooltips_nodes.append( [thickness_label, thickness_tooltip, thickness_node]) name_label = 'Unique layer name : ' name_tooltip = 'Unique layer name' name_node = node.value.value[2].value[4] labels_tooltips_nodes.append([name_label, name_tooltip, name_node]) section_label = 'Section : ' section_tooltip = 'ABAQUS section of the layer' section_node = node.value.value[2].value[5] labels_tooltips_nodes.append( [section_label, section_tooltip, section_node]) layup_label = 'Ply orientation : ' layup_tooltip = 'Ply orientation in degrees' layup_node = node.value.value[2].value[6] labels_tooltips_nodes.append([layup_label, layup_tooltip, layup_node]) # Add a horizontal widget to put the input and output widgets into # Output vertical layout input_output_widget = QWidget() input_output_layout = QHBoxLayout() input_output_widget.setLayout(input_output_layout) # input vertical layout input_widget = QWidget() input_layout = QVBoxLayout() input_widget.setLayout(input_layout) input_Label = simpleWidgets.simpleLabel('Inputs') input_Label.setAlignment(Qt.AlignHCenter) input_layout.addWidget(input_Label) # Build the GUI for label, tooltip, astNode in labels_tooltips_nodes: eachWidget, eachLayout = simpleWidgets.simpleWidget() eachLabel = simpleWidgets.simpleLabel(label) eachLabel.setToolTip(tooltip) eachLE = terminalWidgets.LE_terminal() # eachLE = terminalWidgets.COMBO_terminal() eachLE.setup(astNode) eachLayout.addWidget(eachLabel) eachLayout.addWidget(eachLE, 1) # eachLayout.addStretch(1) input_layout.addWidget(eachWidget, 1) terminalsDict.update({id(eachLE): eachLE}) ## Check for keyword arguments if node.value.value[2].value[7].target.value == 'coordsys': coordsys_tooltip = 'Reference coordinate system for layup' coordsys_node = node.value.value[2].value[7].value anotherWidget, anotherLayout = simpleWidgets.simpleWidget() anotherLabel = simpleWidgets.simpleLabel('coordsys : ') anotherLabel.setToolTip(tooltip) anotherLE = terminalWidgets.LE_terminal() # eachLE = terminalWidgets.COMBO_terminal() anotherLE.setup(coordsys_node) anotherLayout.addWidget(anotherLabel) anotherLayout.addWidget(anotherLE, 1) # eachLayout.addStretch(1) input_layout.addWidget(anotherWidget, 1) terminalsDict.update({id(anotherLE): anotherLE}) # Outputs # Output vertical layout output_widget = QWidget() output_layout = QVBoxLayout() output_widget.setLayout(output_layout) output_Label = simpleWidgets.simpleLabel('Outputs') output_Label.setAlignment(Qt.AlignHCenter) output_layout.addWidget(output_Label) label = 'New Layer : ' tooltip = 'Create a new layer from a mold' astNode = node.target eachWidget, eachLayout = simpleWidgets.simpleWidget() eachLabel = simpleWidgets.simpleLabel(label) eachLabel.setToolTip(tooltip) eachLE = terminalWidgets.LE_terminal() # eachLE = terminalWidget.COMBO_terminal() eachLE.setup(astNode) eachLayout.addWidget(eachLabel) eachLayout.addWidget(eachLE, 1) # eachLayout.addStretch(1) output_layout.addWidget(eachWidget, 1) terminalsDict.update({id(eachLE): eachLE}) # Add output and input widgets to the main input_output_layout input_output_layout.addWidget(output_widget) input_output_layout.addWidget(input_widget) # Add input_output_widget to the main layout layout.addWidget(input_output_widget) return widget, terminalsDict
def nH_widgetBuilder(cls, node, astTools): # Make the frame widget = QFrame() layout = QVBoxLayout() widget.setLayout(layout) terminalsDict = {} # Build the widget from the assignment node # Set up the title titleString = '' if len(node.value) == 1: titleString = node.value.value else: for i in range(len(node.value) - 1): if i == 0: pass else: titleString += '.' titleString += node.value[i].value titleLabel = simpleWidgets.simpleLabel(titleString) titleLabel.setAlignment(Qt.AlignHCenter) titleLabel.setToolTip(node.dumps()) layout.addWidget(titleLabel) # Add a horizontal widget to put the input and output widgets into # Output vertical layout input_output_widget = QWidget() input_output_layout = QHBoxLayout() input_output_widget.setLayout(input_output_layout) # Add the outputs # If there is just one target, put it in a list n = len(node.target) if n == 1: outputs = [node.target] else: outputs = node.target # Output vertical layout output_widget = QWidget() output_layout = QVBoxLayout() output_widget.setLayout(output_layout) outputTitleLabel = simpleWidgets.simpleLabel('Outputs') outputTitleLabel.setAlignment(Qt.AlignHCenter) output_layout.addWidget(outputTitleLabel) for i in range(len(outputs)): eachWidget, eachLayout = simpleWidgets.simpleWidget() eachLabel = simpleWidgets.simpleLabel('Output {} :'.format(i + 1)) eachLE = terminalWidgets.LE_terminal() # eachLE = terminalWidgets.COMBO_terminal() eachLE.setup(outputs[i]) eachLayout.addWidget(eachLabel) eachLayout.addWidget(eachLE, 1) # eachLayout.addStretch(1) output_layout.addWidget(eachWidget, 1) terminalsDict.update({id(eachLE): eachLE}) input_output_layout.addWidget(output_widget, 1) # Add the inputs inputs = node.value[-1] # input vertical layout input_widget = QWidget() input_layout = QVBoxLayout() input_widget.setLayout(input_layout) inputTitleLabel = simpleWidgets.simpleLabel('Inputs') inputTitleLabel.setAlignment(Qt.AlignHCenter) input_layout.addWidget(inputTitleLabel) for i, eachInput in enumerate(inputs): eachWidget, eachLayout = simpleWidgets.simpleWidget() if eachInput.target: # Check for keyword arguments input_label = '{} : '.format(eachInput.target) else: input_label = 'Argument {} : '.format(i + 1) # No kwargs eachLabel = simpleWidgets.simpleLabel(input_label) eachLE = terminalWidgets.LE_terminal() # eachLE = terminalWidgets.COMBO_terminal() eachLE.setup(eachInput.value) eachLayout.addWidget(eachLabel) eachLayout.addWidget(eachLE, 1) # eachLayout.addStretch(1) input_layout.addWidget(eachWidget, 1) terminalsDict.update({id(eachLE): eachLE}) input_output_layout.addWidget(input_widget, 1) layout.addWidget(input_output_widget, 1) return widget, terminalsDict
def nH_widgetBuilder(cls, ast, astTools): # Make the frame widget = QFrame() layout = QVBoxLayout() widget.setLayout(layout) terminalsDict = {} # Save the last_intro_node widget.last_intro_node = 66 # Set up the title titleString = 'De-La-Mo Initialization' titleLabel = simpleWidgets.simpleLabel(titleString) titleLabel.setAlignment(Qt.AlignHCenter) intro_dump = '' for i in range(widget.last_intro_node): intro_dump += ast[i].dumps() intro_dump += '\n' titleLabel.setToolTip(intro_dump) layout.addWidget(titleLabel) descriptionText = \ 'This block hides a significant amount of the initialization of the script. It holds \n \ the code that imports de-la-mo modules, loads parameters, and instantiates tools used \n \ in the rest of the script. It is not important to the end user, but if the user is \n \ interested they may right click on the block and select \'Split\' from the menu, or \n \ the user may look at the raw code in a text editor.' description = simpleWidgets.simpleLabel(descriptionText) description.setAlignment(Qt.AlignHCenter) layout.addWidget(description) # input and output lists input_labels_tooltips_nodes = [] output_labels_tooltips_nodes = [] # Example # DM_label = 'DM Object : ' # DM_tooltip = 'Name of the de-la-mo model object' # DM_node = node.value.value[2].value[0] # input_labels_tooltips_nodes.append([DM_label,DM_tooltip,DM_node]) # Node 16 DM_label = 'DM Object : ' DM_tooltip = 'Name of the de-la-mo model object' DM_node = ast[16].target output_labels_tooltips_nodes.append([DM_label, DM_tooltip, DM_node]) # Node 34 ScriptName_label = 'Script Name : ' ScriptName_tooltip = 'Should match the name of the python script open here, with quotes.' ScriptName_node = ast[34].value.value[2][0].value input_labels_tooltips_nodes.append( [ScriptName_label, ScriptName_tooltip, ScriptName_node]) # Node 41 parameter_label = 'Abaqus Parameter File : ' parameter_tooltip = '' parameter_node = ast[41].value[2][0].value input_labels_tooltips_nodes.append( [parameter_label, parameter_tooltip, parameter_node]) # Add a horizontal widget to put the input and output widgets into # Output vertical layout input_output_widget = QWidget() input_output_layout = QHBoxLayout() input_output_widget.setLayout(input_output_layout) # input vertical layout input_widget = QWidget() input_layout = QVBoxLayout() input_widget.setLayout(input_layout) input_Label = simpleWidgets.simpleLabel('Inputs') input_Label.setAlignment(Qt.AlignHCenter) input_layout.addWidget(input_Label) # Build the GUI for label, tooltip, astNode in input_labels_tooltips_nodes: eachWidget, eachLayout = simpleWidgets.simpleWidget() eachLabel = simpleWidgets.simpleLabel(label) eachLabel.setToolTip(tooltip) eachLE = terminalWidgets.LE_terminal() # eachLE = terminalWidgets.COMBO_terminal() eachLE.setup(astNode) eachLayout.addWidget(eachLabel) eachLayout.addWidget(eachLE, 1) # eachLayout.addStretch(1) input_layout.addWidget(eachWidget, 1) terminalsDict.update({id(eachLE): eachLE}) # Outputs # Output vertical layout output_widget = QWidget() output_layout = QVBoxLayout() output_widget.setLayout(output_layout) output_Label = simpleWidgets.simpleLabel('Outputs') output_Label.setAlignment(Qt.AlignHCenter) output_layout.addWidget(output_Label) # Build the GUI for label, tooltip, astNode in output_labels_tooltips_nodes: eachWidget, eachLayout = simpleWidgets.simpleWidget() eachLabel = simpleWidgets.simpleLabel(label) eachLabel.setToolTip(tooltip) eachLE = terminalWidgets.LE_terminal() # eachLE = terminalWidgets.COMBO_terminal() eachLE.setup(astNode) eachLayout.addWidget(eachLabel) eachLayout.addWidget(eachLE, 1) # eachLayout.addStretch(1) output_layout.addWidget(eachWidget, 1) terminalsDict.update({id(eachLE): eachLE}) # Add output and input widgets to the main input_output_layout input_output_layout.addWidget(output_widget) input_output_layout.addWidget(input_widget) # Add input_output_widget to the main layout layout.addWidget(input_output_widget) return widget, terminalsDict