def __init__(self, environment):
        super(MainWindow, self).__init__()

        self.env         = environment
        self.interpreter = Interpreter(self.env)



        # Set the ConsoleWidget parameters immediately, so even early prints are captured
        self.consoleWidget       = Console(self.env.getSetting('consoleSettings'), parent=self)
        Global.printRedirectFunc = self.consoleWidget.write
        self.consoleWidget.setExecFunction(self.interpreter.evaluateExpression)


        # Create GUI related class variables
        self.fileName        = None
        self.loadData        = []  #Set when file is loaded. Used to check if the user has changed anything when closing
        self.programTitle    = self.tr('uArm Creator Studio')
        self.scriptToggleBtn = QtWidgets.QAction(     QtGui.QIcon(Paths.run_script),     self.tr('Run'), self)
        self.devicesBtn      = QtWidgets.QAction(QtGui.QIcon(Paths.devices_neither), self.tr('Devices'), self)
        self.centralWidget   = QtWidgets.QStackedWidget()
        self.controlPanel    = ControlPanelGUI.ControlPanel(self.env, parent=self)
        self.cameraWidget    = CameraWidget(self.env.getVStream(), parent=self)
        self.floatingHint    = QtWidgets.QLabel()  # Used to display floating banners to inform the user of something
        self.resetLayoutFlag = False # If True, Program will resetore the default layout


        # Create Menu items and set up the GUI
        self.cameraWidget.play()
        self.initUI()



        # After initUI: Restore the window geometry to the state it was when the user last closed the window
        if self.env.getSetting("windowGeometry") is not None:
            state = self.env.getSetting("windowGeometry")
            state = bytearray(state, 'utf-8')
            bArr = QtCore.QByteArray.fromHex(state)
            self.restoreGeometry(bArr)


        # After initUI: Restore size and position of dockwidgets to their previous state
        if self.env.getSetting("windowState") is not None:
            state = self.env.getSetting("windowState")
            state = bytearray(state, 'utf-8')
            bArr = QtCore.QByteArray.fromHex(state)
            self.restoreState(bArr)


        # If any file is specified in "lastOpenedFile" then load it.
        if self.env.getSetting("lastOpenedFile") is not None:
            self.loadTask(filename=self.env.getSetting("lastOpenedFile"))
        else:
            self.newTask(False)


        # Create a timer that checks the connected devices and updates the icon to reflect what is connected correctly
        self.refreshTimer = QtCore.QTimer()
        self.refreshTimer.timeout.connect(self.refreshDevicesIcon)
        self.refreshTimer.start(5000)  # Once every five seconds
objectsPath = "Resources\\Objects"

print("Place this .py file in the same directory as uArmCreatorStudio.exe.")
print("Make sure the script works in GUI before trying it here")

# Create the environment. This will connect the robot and camera using Settings.txt
env = Environment(settingsPath=settingsPath,
                  objectsPath=objectsPath,
                  cascadePath=cascadePath)

# Wait for the robot and camera to connect in their seperate threads
print("Waiting 8 seconds for robot and camera to connect")
sleep(8)

# Create the interpreter
interpreter = Interpreter(env)

# Load the .task file you want to run
saveFile = json.load(open(taskPath))

# Load the task into the interpreter, and print the errors
errors = interpreter.initializeScript(saveFile)
print("The following errors occured while initializing the script:\n", errors)
if str(input(
        "Do you want to continue and start the script? (Y/N)")).lower() == "n":
    sys.exit()

# Before starting script, move the robot to a home position
robot = env.getRobot()
robot.setPos(**robot.home)