Exemplo n.º 1
0
def test(argv):
    # Create graph widget
    app = QtWidgets.QApplication(argv)
    graph = GraphWidget(None)
    graph.ast = ASTModel.get_ast(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../apps/simple/simple.camkes"))

    print ASTModel.find_instance(graph.ast.assembly.instances, "echo") is not None
    # find_component is not being tested because it is not used anywhere. However
    # there is no reason why find_component will fail to work, if everything else worked.

    print "visualCAmkES test passed"
    return 0
Exemplo n.º 2
0
    def open_ast(self, path_to_file, import_paths=None):
        """
        Opens the given camkes file. Deals with the drawing. Shows an error if a CAmkES Error occurs
        :param path_to_file: The path to the camkes file. A string such as "/home/bob/camkes/app/kitty/kitty.camkes
        :return
        """

        assert isinstance(path_to_file, six.string_types)

        # Checks to see if path is not empty
        if len(path_to_file) > 1:
            try:
                # Set the AST of GraphWidget
                self.root_widget.ast = ASTModel.get_ast(
                    path_to_file, import_paths)
            except CAmkESError as error:
                # If error occurred

                # For terminal users:
                print "Error occurred when opening the file... please refer to the following error"
                print error

                # Show Error as a message popup
                messageBox = QtWidgets.QMessageBox()
                messageBox.setText("Syntax Error")

                # Convert all ANSI codes to HTML
                conv = Ansi2HTMLConverter(inline=True, dark_bg=False)
                html = conv.convert(str(error), full=False)
                html = html.replace('\n', '<br/>').replace('^', '')
                messageBox.setInformativeText(
                    '<p style="font-family: monospace;"> %s </p>' % html)
                messageBox.exec_()
            else:
                # If no error, AST would have been successfully set. Change Window Title to name of file.

                # find last / (or last \ in windows)
                start_of_filename = path_to_file.rfind("/")
                if start_of_filename == -1:
                    # Might be a windows machine
                    start_of_filename = path_to_file.rfind('\\')

                if start_of_filename == -1:
                    # If still not found, assume its just the name of the file.
                    start_of_filename = 0
                else:
                    start_of_filename += 1

                self.setWindowTitle(
                    path_to_file[start_of_filename:path_to_file.rfind('.')])
Exemplo n.º 3
0
    def open_ast(self, path_to_file, import_paths=None):
        """
        Opens the given camkes file. Deals with the drawing. Shows an error if a CAmkES Error occurs
        :param path_to_file: The path to the camkes file. A string such as "/home/bob/camkes/app/kitty/kitty.camkes
        :return
        """

        assert isinstance(path_to_file, six.string_types)

        # Checks to see if path is not empty
        if len(path_to_file) > 1:
            try:
                # Set the AST of GraphWidget
                self.root_widget.ast = ASTModel.get_ast(path_to_file, import_paths)
            except CAmkESError as error:
                # If error occurred

                # For terminal users:
                print "Error occurred when opening the file... please refer to the following error"
                print error

                # Show Error as a message popup
                messageBox = QtWidgets.QMessageBox()
                messageBox.setText("Syntax Error")

                # Convert all ANSI codes to HTML
                conv = Ansi2HTMLConverter(inline=True, dark_bg=False)
                html = conv.convert(str(error), full=False)
                html = html.replace('\n', '<br/>').replace('^','')
                messageBox.setInformativeText('<p style="font-family: monospace;"> %s </p>' % html)
                messageBox.exec_()
            else:
                # If no error, AST would have been successfully set. Change Window Title to name of file.

                # find last / (or last \ in windows)
                start_of_filename = path_to_file.rfind("/")
                if start_of_filename == -1:
                    # Might be a windows machine
                    start_of_filename = path_to_file.rfind('\\')

                if start_of_filename == -1:
                    # If still not found, assume its just the name of the file.
                    start_of_filename = 0
                else:
                    start_of_filename += 1

                self.setWindowTitle(path_to_file[start_of_filename:path_to_file.rfind('.')])