예제 #1
0
 def execute(self, data={}):
     try:
         from idlelib.EditorWindow import EditorWindow
     except Exception:
         print_err("This lesson requires IDLE. To proceed idlelib and its dependencies, tkinter and _tkinter, must be installed. Sorry for the inconvenience.")
         input("<enter> to leave swirlypy")
         sys.exit()
예제 #2
0
    def execute(self, data={}):
        """Execute the question in the default way, by first printing
        itself, then asking for a response and testing it in a loop
        until it is correct."""
        # XXX: Collect statistics here so that it can be used for
        # grading.

        # print("I am running")
        # Print the output.
        self.print()

        # Loop until correct.
        while True:
            # Get the user's response.
            #data.update(globals())
            # print(data)
            resp = self.get_response(data=data)

            # Test it. If correct (True), then break from this loop. If
            # not, print the hint, if it's present.
            testresult = self.test_response(resp, data=data)
            if testresult == True:
                break
            elif testresult == False:
                try:
                    colors.print_err(self.hint)
                except AttributeError:
                    pass
            else:
                # If the test is not a boolean, (i.e. None), then it was
                # not testable or relevant, for some reason.
                continue
예제 #3
0
def menu():
    print("\n")
    print("Welcome to the course menu! If you like to exit to the main menu at any point, press Ctrl+D or enter '0'. \n")
    print("You have the following courses to choose from: \n")

    path = str(import_course_path.get_path())


    # # print(filter(os.path.isdir, os.listdir(path)))
    courses = next(os.walk( os.path.join(path,'.')))[1]
    courses.remove("__pycache__")

    for index, course in enumerate(courses):
        colors.print_option("%d: %s" % (index + 1, course))

    print("\n")

    try:
        course_select = input("| --  Select a course: ")
        print("\n")
    except EOFError:
        print("Returning to the main menu.. \n")
        return


    try:
        course_select = int(course_select)
    except ValueError or ModuleNotFoundError:
        colors.print_err("No course. Returning to Course menu.. \n")
        menu()
  

    if type(course_select) == int:
        if course_select == 0:
            print("Returning to the main menu.. \n")
            return
        try:
            course_select = courses[course_select - 1]
        except IndexError or ModuleNotFoundError:
            colors.print_err("No course. Returning to Course menu.. \n")
            menu()
    
    moduleNames = 'courses.'+ str(course_select)
    pkg  = '.initialize_lesson'

    m = importlib.import_module(moduleNames+pkg)
    # print(m)

    #print(globals())

    data = m.get_data()
    # print(m.pd.DataFrame())
    # print("| Choose from the following commands: ('run', 'info', 'create', 'test') \n")

    # command = input("| Enter a command for the course: ")

    main(m, data, parse(["run", os.path.join(path,course_select)]))
예제 #4
0
def load_course(path):
    """Helper function for subcommands which need to load courses
    predictably."""
    # Try to load the course.
    try:
        return swirlypy.course.Course.load(path)
    except FileNotFoundError as e:
        colors.print_err("Couldn't load course: %s" % e)
        print("Does it have course.yaml?")
        return None
예제 #5
0
def load_course(path):
    """Helper function for subcommands which need to load courses
    predictably."""
    # Try to load the course.
    try:
        return swirlypy.course.Course.load(path)
    except FileNotFoundError as e:
        colors.print_err("Couldn't load course: %s" % e)
        print("Does it have course.yaml?")
        return None
예제 #6
0
파일: course.py 프로젝트: ZTK13/swirlypy
    def execute(self):
        """Repeatedly prompts the user for lessons to run until
        explictly exited."""

        # Loop until user EOF.
        while True:
            # Present the menu.
            self.menu()
            try:
                colors.print_inst("Selection: ", end="")
                identifier = input().strip()
                self.execute_lesson(identifier)
            except NoSuchLessonException:
                colors.print_err("No lesson: %s" % identifier)
            except EOFError:
                # If the user hits CTRL-D, exit.
                # XXX: Tell the user this.
                print()
                print("Bye!")
                break
예제 #7
0
    def execute(self):
        """Repeatedly prompts the user for lessons to run until
        explictly exited."""

        # Loop until user EOF.
        while True:
            # Present the menu.
            self.menu()
            try:
                colors.print_inst("Selection: ", end="")
                identifier = input().strip()
                self.execute_lesson(identifier)
            except NoSuchLessonException:
                colors.print_err("No lesson: %s" % identifier)
            except EOFError:
                # If the user hits CTRL-D, exit.
                # XXX: Tell the user this.
                print()
                print("Bye!")
                break
예제 #8
0
파일: course.py 프로젝트: ZTK13/swirlypy
 def print_err(string):
     errs = True
     colors.print_err(string)
예제 #9
0
 def print_err(string):
     errs = True
     colors.print_err(string)
예제 #10
0
# swirlytool is the primary Swirlypy user interface tool, which is
# responsible for the running, creation, and inspection of Swirlypy
# courses.

import sys, argparse
import os
import tarfile

import swirlypy.colors as colors

try:
    # XXX: We should be able to just import swirlypy here. We need to
    # set __all__ in the __init__.py of the main module.
    import swirlypy.course
except ImportError as e:
    colors.print_err("Can't import a needed module: %s" % e)
    print("Is it installed or in your PYTHONPATH?")
    sys.exit(1)


def load_course(path):
    """Helper function for subcommands which need to load courses
    predictably."""
    # Try to load the course.
    try:
        return swirlypy.course.Course.load(path)
    except FileNotFoundError as e:
        colors.print_err("Couldn't load course: %s" % e)
        print("Does it have course.yaml?")
        return None
예제 #11
0
# swirlytool is the primary Swirlypy user interface tool, which is
# responsible for the running, creation, and inspection of Swirlypy
# courses.

import sys, argparse
import os
import tarfile

import swirlypy.colors as colors

try:
    # XXX: We should be able to just import swirlypy here. We need to
    # set __all__ in the __init__.py of the main module.
    import swirlypy.course
except ImportError as e:
    colors.print_err("Can't import a needed module: %s" % e)
    print("Is it installed or in your PYTHONPATH?")
    sys.exit(1)

def load_course(path):
    """Helper function for subcommands which need to load courses
    predictably."""
    # Try to load the course.
    try:
        return swirlypy.course.Course.load(path)
    except FileNotFoundError as e:
        colors.print_err("Couldn't load course: %s" % e)
        print("Does it have course.yaml?")
        return None

def run(args):