Exemple #1
0
    def __init__(self):
        super(MainWindow, self).__init__()

        # Initialize the environment. Robot, camera, and objects will be loaded into the "logic" side of things
        self.env = Environment(Paths.settings_txt, Paths.objects_dir,
                               Paths.cascade_dir)
        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 = 'uArm Creator Studio'
        self.scriptToggleBtn = QtWidgets.QAction(QtGui.QIcon(Paths.run_script),
                                                 'Run', self)
        self.videoToggleBtn = QtWidgets.QAction(QtGui.QIcon(Paths.play_video),
                                                'Video', self)
        self.devicesBtn = QtWidgets.QAction(QtGui.QIcon(Paths.devices_neither),
                                            '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

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

        # 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
        errorLogger.info('---------------------------Logging Start---------------------------')
        if issubclass(exc_type, KeyboardInterrupt):
            sys.__excepthook__(exc_type, exc_value, exc_traceback)

            return

        errorLogger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
        errorLogger.info('----------------------------Logging End----------------------------')
    sys.excepthook = handle_exception


    # Set up global variables
    # Global.init()

    # Initialize the environment. Robot, camera, and objects will be loaded into the "logic" side of things
    env = Environment(Paths.settings_txt, Paths.objects_dir, Paths.cascade_dir)  # load environment
    Paths.initLogger(env.getSetting('consoleSettings'))


    # Create an exit code to track whether or not to reboot the GUI, or close it for good (for language changes)
    currentExitCode = MainWindow.EXIT_CODE_REBOOT
    while currentExitCode == MainWindow.EXIT_CODE_REBOOT:
        # Create the Application base
        app = Application(sys.argv)

        # Set Application Font
        font = QtGui.QFont()
        font.setFamily("Verdana")
        font.setPixelSize(12)
        app.setFont(font)
When you run this script, everything will start up automatically. Make sure that you have run this script with the
GUI in the same directory, so it will generate the correct settings file and objects that you might need, so when you
run this it will already know the robots COM port and the cameras ID, and all the calibration information.
"""

taskPath = "Resources\\Save Files\\test.task"
settingsPath = "Resources\\Settings.txt"
cascadePath = "Resources\\"
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)