Beispiel #1
0
class AddAreaDlg(QDialog):
		
	def __init__(self, parent=None):
		super(AddAreaDlg, self).__init__(parent)
		self.setWindowTitle("New Relief Device Area")
		
		name_label = QLabel("&Name:")
		self.name_lineedit = QLineEdit()
		self.name_lineedit.setMaxLength(200)
		name_label.setBuddy(self.name_lineedit)
		location_label = QLabel("&Location:")
		self.location_combobox = QComboBox()
		self.location_combobox.setEditable(True)
		location_label.setBuddy(self.location_combobox)
		self.browse_button = QPushButton("&Browse...")
		button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
		
		layout = QGridLayout()
		layout.addWidget(name_label, 0, 0)
		layout.addWidget(self.name_lineedit, 0, 1)
		layout.addWidget(location_label, 1, 0)
		layout.addWidget(self.location_combobox, 1, 1)
		layout.addWidget(self.browse_button, 1, 2)
		#layout.addWidget(QFrame.HLine, 2, 0)
		layout.addWidget(button_box, 2, 1)
		self.setLayout(layout)
		
		self.browse_button.clicked.connect(self.browseFiles)
		button_box.accepted.connect(self.accept)
		button_box.rejected.connect(self.reject)
		
	def browseFiles(self):
		self.dirname = QFileDialog.getExistingDirectory(self, "Select file location", options=QFileDialog.ShowDirsOnly)
		self.location_combobox.insertItem(0, self.dirname)
		self.location_combobox.setCurrentIndex(0)
		
	def accept(self):
		if len(self.name_lineedit.text().strip()) == 0:
			QMessageBox.warning(self, "Error: Relief Device Area Name Blank", "The relief device area must be given a name.", QMessageBox.Ok)
			self.name_lineedit.setFocus()
			return
		if len(self.location_combobox.currentText().strip()) == 0:
			QMessageBox.warning(self, "Error: Location Blank", "You must save the relief device area file to a valid directory.", QMessageBox.Ok)
			self.location_combobox.setFocus()
			return
		if not os.path.exists(self.location_combobox.currentText().replace("\\", "/")):
			QMessageBox.warning(self, "Error: Directory Does Not Exist", "The specified directory does not exist.", QMessageBox.Ok)
			self.location_combobox.setFocus()
			return
		if os.path.isfile(self.location_combobox.currentText().replace("\\", "/") + "/" + self.name_lineedit.text() + ".rda"):
			if QMessageBox.question(self, "File Already Exists", 
			"The file {0} already exists at {1}. Are you sure you want to proceed and overwrite this file?".format(self.name_lineedit.text() + ".rda", 
			self.location_combobox.currentText().replace("\\", "/")), QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
				self.name_lineedit.setFocus()
				return
		QDialog.accept(self)

	def returnVals(self):
		return self.name_lineedit.text(), self.location_combobox.currentText().replace("\\", "/") + "/"
Beispiel #2
0
class AddDeviceDlg(QDialog):

	def __init__(self, root_node, parent=None):
		super(AddDeviceDlg, self).__init__(parent)
		self.setWindowTitle("Add Relief Device")

		id_label = QLabel("&Relief Device ID:")
		self.id_lineedit = QLineEdit()
		self.id_lineedit.setMaxLength(200)
		id_label.setBuddy(self.id_lineedit)
		area_label = QLabel("Associated Relief Device &Area:")
		self.area_combobox = QComboBox()
		for area in root_node.children:
			self.area_combobox.addItem(area.name, area)
		area_label.setBuddy(self.area_combobox)
		color_label = QLabel("&Text Color:")
		self.color_combobox = QComboBox()
		for key in sorted(COLORS.keys()):
			pixmap = QPixmap(26, 26)
			pixmap.fill(COLORS[key])
			self.color_combobox.addItem(QIcon(pixmap), key)
		color_label.setBuddy(self.color_combobox)
		button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
			
		layout = QGridLayout()
		layout.addWidget(id_label, 0, 0)
		layout.addWidget(self.id_lineedit, 0, 1)
		layout.addWidget(area_label, 1, 0)
		layout.addWidget(self.area_combobox, 1, 1)
		layout.addWidget(color_label, 2, 0)
		layout.addWidget(self.color_combobox, 2, 1)
		layout.addWidget(button_box, 3, 1)
		self.setLayout(layout)
		
		button_box.accepted.connect(self.accept)
		button_box.rejected.connect(self.reject)
		
	def accept(self):
		if len(self.id_lineedit.text().strip()) == 0:
			QMessageBox.warning(self, "Error: Relief Device ID Blank", "The relief device must be given an ID.", QMessageBox.Ok)
			self.id_lineedit.setFocus()
			return
		selected_area = self.area_combobox.itemData(self.area_combobox.currentIndex())
		for device in selected_area.children:
			if device.name == self.id_lineedit.text():
				QMessageBox.warning(self, "Error: Relief Device ID Already Exists", 
				"Cannot add relief device because that relief device ID already exists. Please create a new relief device ID.", QMessageBox.Ok)
				self.id_lineedit.setFocus()
				self.id_lineedit.setSelection(0, self.id_lineedit.maxLength())
				return
		QDialog.accept(self)
		
	def returnVals(self):
		return (self.id_lineedit.text(), self.area_combobox.itemData(self.area_combobox.currentIndex()),
		COLORS[self.color_combobox.currentText()])
Beispiel #3
0
class Layer(object):

    def __init__(self):
        super(Layer, self).__init__()
        self.orientation = Quaternion()
        self.picked = None
        self.show = QCheckBox()
        self.show.setChecked(True)
        self.alpha_slider = QSlider(QtCore.Qt.Orientation.Horizontal)
        self.alpha_slider.setRange(0, 1024)
        self.alpha_slider.setValue(1024)
        self.alpha_number = QDoubleSpinBox()
        self.alpha_number.setDecimals(3)
        self.alpha_number.setSingleStep(0.01)
        self.alpha_number.setRange(0, 1)
        self.alpha_number.setValue(1)
        self.alpha_slider.valueChanged.connect(self._alphaSliderChanged)
        self.alpha_number.valueChanged.connect(self._alphaNumberChanged)
        self.move = QCheckBox()
        self.move.setChecked(True)
        self.quat = QLineEdit()
        font = QFont('monospace')
        font.setStyleHint(QFont.TypeWriter)
        self.quat.setFont(font)
        default_quat = '+0.000, +1.000, +0.000, +0.000'
        margins = self.quat.textMargins()
        self.quat.setFixedWidth(
            # HACK -------------------------------------------v
            QFontMetrics(self.quat.font()).width(default_quat + '  ') +
            margins.left() + margins.right()
        )
        self.quat.setInputMask('#0.000, #0.000, #0.000, #0.000')
        self.quat.setMaxLength(30)
        self.quat.setText(default_quat)
        self.quat.editingFinished.connect(self._orientationChanged)
        self.nbytes = QLabel()
        self.nbytes.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.nbytes.setText('0')
        self.label = QLabel()
        self.label.setText('<empty>')

    def multiplyOrientation(self, quat):
        self.setOrientation(quat * self.orientation)

    def setOrientation(self, quat):
        self.orientation = quat
        self.quat.setText(
            '%+1.3f, %+1.3f, %+1.3f, %+1.3f' % (
                self.orientation.w,
                self.orientation.x,
                self.orientation.y,
                self.orientation.z,
            )
        )

    def _orientationChanged(self):
        text = self.quat.text()

    def alpha(self):
        return self.alpha_number.value() if self.show.isChecked() else 0.0

    def _alphaSliderChanged(self):
        self.alpha_number.setValue(self.alpha_slider.value() / 1024.0)

    def _alphaNumberChanged(self):
        self.alpha_slider.setValue(1024 * self.alpha_number.value())

    def setup_ui(self, table, row):
        widgets = [
            None,
            CenterH(self.show),
            self.alpha_slider,
            self.alpha_number,
            CenterH(self.move),
            self.quat,
            self.nbytes,
            self.label,
        ]
        for (column, widget) in enumerate(widgets):
            if widget is not None:
                table.setCellWidget(row, column, widget)

    def load_file(self, file_name, in_format):
        self.sphere = proj.load_sphere(file_name, projection=in_format)
        in_format = self.sphere.__class__
        print('Loaded input %s from %s.' % (in_format.__name__, file_name))
        self.texture_id = glGenTextures(1)
        self.sphere.to_gl(self.texture_id)
        self.shader = Shader(
            vert=VERTEX_SHADER,
            frag=FRAGMENT_SHADER + self.sphere.get_glsl_sampler(),
        )
        self.label.setText(file_name)
        self.nbytes.setText(read_bsize(self.sphere.array.nbytes))
Beispiel #4
0
class EegCarDashboardWindow(QWidget):

    def setSliderMaxThrottle(self, x):
        self.setMaxThrottle(x)
        # self.dashboard.set_throttle(x)
        # self.dashboard.wheel.forward(x)

    def setSteeringValue(self, x):
        # x range is 1-9 need to scale (10-90)
        x = x*10
        self.dashboard.set_steering(x)
        # self.dashboard.steering.turn_by_position(x)
        pot = 1.5
        self.dashboard.steering.turn_by_position(x, pot)

    def setSteeringTurnRangeValue(self, x):
        ticks = int(100000 * (x/10.0)) # max is 100000
        # print "STEERING TURN TICKS %d" % ticks
        self.dashboard.set_steering_eeg_turn_ticks(ticks)

    def steering_update_current_pos(self):
        # x = int(self.steering_current_pos.text()) + delta_x
        # while check busy
        ## read position
        ## print 'current pos %d' % x

        ticks = int(self.steering_move_ticks.text())
        seconds = int(ticks/(DEFAULT_STEERING_SPEED*7))
        seconds = seconds + 1 # at least one second
        ending_time = time.time() + seconds
        while time.time() < ending_time:
            # print "ENDNIG: %d" % ending_time
            # print "CURRENT: %d" % time.time()
            self.steering_set_current_pos(self.dashboard.steering.get_current_location())

    def steering_set_current_pos(self, x):
        self.steering_current_pos.setText(str(x))    

    def steering_move_left(self):
        ticks = int(self.steering_move_ticks.text())
        # Stepping Motor MOVE!
        self.dashboard.steering.stepping_driver.forward(ticks)
        self.setMessage('Steering left')
        self.steering_update_current_pos()

    def steering_move_right(self):
        ticks = int(self.steering_move_ticks.text())
        # Stepping Motor MOVE!
        self.dashboard.steering.stepping_driver.backward(ticks)
        self.setMessage('Steering right')
        self.steering_update_current_pos()

    def set_steering_move_ticks_value(self):
        self.steering_move_ticks.blockSignals(True) # update line edit
        ticks = int(self.steering_move_ticks.text())
        self.steering_move_ticks.setText(str(ticks)) 
        self.steering_move_ticks.blockSignals(False)
        self.steering_move_ticks.setModified(True)

        if self.steering_move_ticks.isModified():
            self.steering_move_ticks.clearFocus()
        self.maxThrottle.setModified(False)

    def steering_reset_position(self):
        # RESET
        self.setMessage('Steering Controller Reset')
        self.dashboard.steering.stepping_driver.reset() # reset
        self.dashboard.steering.stepping_driver.set_speed(DEFAULT_STEERING_SPEED) # set speed
        self.steering_update_current_pos()

    def setMessage(self, msg):
        self.statusBar.showMessage(msg, 2000)

    def remote_control(self, state):
        if state == QtCore.Qt.Checked:
            self.dashboard.set_rc_mode(True)
            self.setMessage('SET RC MODE')
        else:
            self.dashboard.set_rc_mode(False)
            self.setMessage('CLEAR RC MODE')

    def keep_mode_control(self, state):
        if state == QtCore.Qt.Checked:
            self.keep_mode = True
            self.setMessage('Keep Mode (EEG)')
        else:
            self.keep_mode = False
            self.setMessage('Keyboard Mode')

    def power_handle_mode_control(self, state):
        if state == QtCore.Qt.Checked:
            self.dashboard.set_power_handle_mode(True)
            self.setMessage('Power Handle (Auto Steering Middle)')
        else:
            self.dashboard.set_power_handle_mode(False)
            self.setMessage('Turn Off Power Handle')

    def ignore_eeg_input_control(self, state):
        if state == QtCore.Qt.Checked:
            self.dashboard.set_ignore_eeg_input(True)
            self.setMessage('Ignore EEG Input')
        else:
            self.dashboard.set_ignore_eeg_input(False)
            self.setMessage('Access EEG Input')

    def stright_control(self, state):
        if state == QtCore.Qt.Checked:
            self.dashboard.set_rc_stright_mode(True)
            self.setMessage('RC STRIGHT Mode')
        else:
            self.dashboard.set_rc_stright_mode(False)
            self.setMessage('RC FREE L/R Mode')

    def __init__(self):
        QWidget.__init__(self)
        self.setWindowTitle("EEG Pilot Dashboard")
        self.setGeometry(0, 0, 750, 800)
        # self.setGeometry(300, 300, 750, 800)
        self.dashboard = EegCarDashboard()
        self.dashboard.set_max_throttle(DEFAULT_MAX_THROTTLE)
        self.dashboard.set_backward_max_throttle(DEFAULT_MAX_BACK_THROTTLE)

        self.layout = QVBoxLayout(self)

        # Drive Setting
        self.rc_mode = QCheckBox('Remote Control', self)
        self.rc_mode.stateChanged.connect(self.remote_control)

        self.rc_stright_mode = QCheckBox('RC Stright', self)
        self.rc_stright_mode.stateChanged.connect(self.stright_control)

        self.keep_mode_checkbox = QCheckBox('Keep Mode', self)
        self.keep_mode_checkbox.stateChanged.connect(self.keep_mode_control)

        self.power_handle_mode_checkbox = QCheckBox('Power Handle', self)
        self.power_handle_mode_checkbox.stateChanged.connect(self.power_handle_mode_control)

        self.ignore_eeg_input = QCheckBox('Ignore Eeg Input', self)
        self.ignore_eeg_input.stateChanged.connect(self.ignore_eeg_input_control)

        drive_layout = QHBoxLayout(self)
        drive_layout.addWidget(self.rc_mode)
        drive_layout.addWidget(self.rc_stright_mode)
        drive_layout.addWidget(self.keep_mode_checkbox)
        drive_layout.addWidget(self.power_handle_mode_checkbox)
        drive_layout.addWidget(self.ignore_eeg_input)

        drive_groupbox = QtGui.QGroupBox("Drive Status & Setting")
        drive_groupbox.setLayout(drive_layout)

        # Throttle Setting
        self.throttle_slider = QSlider(Qt.Horizontal)
        self.throttle_slider.setFocusPolicy(Qt.StrongFocus)
        self.throttle_slider.setTickPosition(QSlider.TicksBothSides)
        self.throttle_slider.setTickInterval(10)
        self.throttle_slider.setSingleStep(10)
        self.throttle_slider.setValue(DEFAULT_MAX_THROTTLE)

        self.throttle_slider.valueChanged.connect(self.throttle_slider.setValue)
        self.connect(self.throttle_slider, SIGNAL("valueChanged(int)"), self.setSliderMaxThrottle)
        self.throttle_label = QLabel('Max Throttle (%): ', self)


        self.maxThrottle = QLineEdit(str(DEFAULT_MAX_THROTTLE))
        # self.maxThrottle.textChanged[str].connect(self.setMaxThrottle)
        self.maxThrottle.editingFinished.connect(self.setMaxThrottle)
        self.maxThrottle.setMaxLength(2)
        self.maxThrottle.setMaximumWidth(40)

        self.backwardMaxThrottle = QLineEdit(str(DEFAULT_MAX_BACK_THROTTLE))
        # self.maxThrottle.textChanged[str].connect(self.setMaxThrottle)
        self.backwardMaxThrottle.editingFinished.connect(self.setBackwardMaxThrottle)
        self.backwardMaxThrottle.setMaxLength(2)
        self.backwardMaxThrottle.setMaximumWidth(40)

        throttle_layout = QHBoxLayout(self)
        throttle_layout.addWidget(self.throttle_label)
        throttle_layout.addWidget(self.throttle_slider)
        throttle_layout.addWidget(QLabel("Forward Max:"))
        throttle_layout.addWidget(self.maxThrottle)

        throttle_layout.addWidget(QLabel("Backward Max:"))
        throttle_layout.addWidget(self.backwardMaxThrottle)

        throttle_groupbox = QtGui.QGroupBox("Max Throttle Setting (30-99)")
        throttle_groupbox.setLayout(throttle_layout)

        # Steering
        self.steering_label = QLabel('Turn Range', self)
        self.steering_turn_range_slider = QSlider(Qt.Horizontal)
        self.steering_turn_range_slider.setFocusPolicy(Qt.StrongFocus)
        self.steering_turn_range_slider.setTickPosition(QSlider.TicksBothSides)
        self.steering_turn_range_slider.setRange(1, 9)
        # self.steering_slider.setMinimum(2)
        # self.steering_slider.setMaximum(8)
        self.steering_turn_range_slider.setMinimum(4)
        self.steering_turn_range_slider.setMaximum(8)
        self.steering_turn_range_slider.setTickInterval(1)
        self.steering_turn_range_slider.setSingleStep(1)
        self.steering_turn_range_slider.setValue(6)
        self.steering_turn_range_slider.valueChanged.connect(self.steering_turn_range_slider.setValue)
        self.connect(self.steering_turn_range_slider, SIGNAL("valueChanged(int)"), self.setSteeringTurnRangeValue)

        self.steering_adjust_label = QLabel(' Home Adjust ', self)
        self.steering_move_left_button = QPushButton('<Left+', self)
        self.steering_current_pos = QLabel('0', self)
        self.steering_move_right_button = QPushButton('-Right>', self)

        self.steering_move_ticks = QLineEdit(str(5000))
        self.steering_move_ticks.editingFinished.connect(self.set_steering_move_ticks_value)
        self.steering_move_ticks.setMaxLength(5)
        self.steering_move_ticks.setMaximumWidth(50)

        self.steering_reset = QPushButton('Reset', self)

        self.steering_move_left_button.clicked.connect(self.steering_move_left)
        self.steering_move_right_button.clicked.connect(self.steering_move_right)
        self.steering_reset.clicked.connect(self.steering_reset_position)

        steering_layout = QHBoxLayout(self)
        steering_layout.addWidget(self.steering_label)
        # steering_layout.addWidget(self.steering_slider)
        steering_layout.addWidget(self.steering_turn_range_slider)
        steering_layout.addWidget(self.steering_adjust_label)
        steering_layout.addWidget(self.steering_move_left_button)


        steering_layout.addWidget(self.steering_current_pos)
        steering_layout.addWidget(self.steering_move_right_button)
        steering_layout.addWidget(self.steering_move_ticks)
        steering_layout.addWidget(self.steering_reset)

        steering_groupbox = QtGui.QGroupBox("Steering Setting")
        steering_groupbox.setLayout(steering_layout)

        self.layout.addWidget(self.dashboard, 2)
        self.layout.addWidget(drive_groupbox)
        self.layout.addWidget(throttle_groupbox)
        self.layout.addWidget(steering_groupbox)

        self.statusBar = QStatusBar()
        self.statusBar.showMessage('Ready', 2000)
        self.layout.addWidget(self.statusBar)

        self.setIcon()
        self.show()

        # save the state
        self.default_backgroundcolor = self.palette().color(QtGui.QPalette.Background)
        self.previos_steering = 50
        self.init_keep_mode()
        self.init_power_handle_mode()

        # Timer For reading current steering position
        # self.timer = QtCore.QTimer()
        # self.timer.timeout.connect(self.readSteeringPos)
        # # check every second
        # self.timer.start(1000)  

        # Timer For Powerhandle
        # self.power_handle_timer = QtCore.QTimer()
        # self.power_handle_timer.timeout.connect(self.update_power_handle)
        # # check every half second
        # self.power_handle_timer.start(500)

        # # Timer For Start Accel
        # self.start_accel_timer = QtCore.QTimer()
        # # self.start_accel_timer.singleShot(5000, self.end_start_accel_handle)
        # self.can_start_accel = True

    # def set_start_accel(self, value):
    #     self.can_start_accel = value

    # def get_start_accel(self):
    #     return self.can_start_accel

    # def end_start_accel_handle(self):
    #     self.dashboard.end_start_accel()

    # def update_power_handle(self):
    #     if self.power_handle_mode:
    #         self.dashboard.update_power_handle()

    def readSteeringPos(self):
        # self.setMessage(str(self.dashboard.steering.get_current_steering()))
        # TODO: is it thread safe?
        # self.steering_set_current_pos(self.dashboard.steering.get_current_location())
        return

    def getMaxThrottle(self):
        return int(self.maxThrottle.text())

    def getBackwardMaxThrottle(self):
        return int(self.backwardMaxThrottle.text())

    def setMaxThrottle(self, _throttle=None):
        if _throttle is None: # from line textbox
            throttle = self.getMaxThrottle()
            self.throttle_slider.blockSignals(True); # update slider
            self.throttle_slider.setValue(throttle);
            self.throttle_slider.blockSignals(False);
        else: # from slider 
            throttle = _throttle
            self.maxThrottle.blockSignals(True); # update line edit
            self.maxThrottle.setText(str(throttle)) 
            self.maxThrottle.blockSignals(False);
            self.maxThrottle.setModified(True)

        if self.maxThrottle.isModified():
            if throttle >= FORWARD_THROTTLE_THRESHOLD: # forward throttle threshold is 20
                self.dashboard.set_max_throttle(throttle)
                self.setMessage("Forward Max Throttle: %d" % throttle)
                self.maxThrottle.clearFocus()
        self.maxThrottle.setModified(False)

    def setBackwardMaxThrottle(self):
        throttle = self.getBackwardMaxThrottle()
        if self.backwardMaxThrottle.isModified():
            if throttle >= BACKWARD_THROTTLE_THRESHOLD: # backward throttle threshold is 20
                self.dashboard.set_backward_max_throttle(throttle)
                self.backwardMaxThrottle.clearFocus()
        self.backwardMaxThrottle.setModified(False)

    def setIcon(self):
        self.appIcon = QIcon('logo.png')
        self.setWindowIcon(self.appIcon)

    def init_keep_mode(self):
        self.w_keep_countdown = 0
        self.x_keep_countdown = 0
        self.a_keep_countdown = 0
        self.d_keep_countdown = 0
        self.default_keep_countdown = DEFAULT_KEEP_COUNT
        # self.default_keep_countdown = 28
        # self.default_keep_countdown = 38
        self.keep_mode = False

    def init_power_handle_mode(self):
        self.power_handle_mode = False

    def is_keep_mode(self, ignore_key):
        # if key is 'w' -> w_keep_countdown
        # if key is 'x' -> x_keep_countdown
        # ignore several 's' key while chountdown number to zero

        if self.keep_mode:
            if ignore_key == Qt.Key_S: 
                if self.dashboard.power_handle_mode == True:
                    self.dashboard.update_power_handle()
                if self.w_keep_countdown > 0:
                    self.w_keep_countdown = self.w_keep_countdown - 1
                    # print "w keep countdown %d" % self.w_keep_countdown
                    self.setMessage("w keep countdown %d" % self.w_keep_countdown)
                    self.x_keep_countdown = 0
                    return True
                if self.x_keep_countdown > 0:
                    self.x_keep_countdown = self.x_keep_countdown - 1
                    # print "x keep countdown %d" % self.x_keep_countdown
                    self.setMessage("x keep countdown %d" % self.x_keep_countdown)
                    self.w_keep_countdown = 0
                    return True
 
            if ignore_key == Qt.Key_X: 
                if self.w_keep_countdown > 0:
                    self.w_keep_countdown = self.w_keep_countdown - 1
                    self.setMessage("w keep countdown %d" % self.w_keep_countdown)
                    if self.w_keep_countdown < DEFAULT_KEEP_COUNT - 10:
                      # self.stop()
                      self.dashboard.set_key_input('s')
                      self.dashboard.stop()
                      self.dashboard.set_start_accel(True)
                    return True

            if ignore_key == Qt.Key_W: 
                if self.x_keep_countdown > 0:
                    self.x_keep_countdown = self.x_keep_countdown - 1
                    self.setMessage("x keep countdown %d" % self.x_keep_countdown)
                    if self.x_keep_countdown < DEFAULT_KEEP_COUNT - 10:
                      # self.stop()
                      self.dashboard.set_key_input('s')
                      self.dashboard.stop()
                      self.dashboard.set_start_accel(True)
                    return True
 
        return False

    def go_to_keep_mode(self, key):
        if key == Qt.Key_W:
            self.w_keep_countdown = self.default_keep_countdown

        if key == Qt.Key_X:
            self.x_keep_countdown = self.default_keep_countdown

        # A, D make a w_keep_countdown FOR powerhandle
        if key == Qt.Key_A:
            self.w_keep_countdown = self.default_keep_countdown

        if key == Qt.Key_D:
            self.w_keep_countdown = self.default_keep_countdown
                
    def keyPressEvent(self, event):
        if self.dashboard.rc_mode == True :
            if self.dashboard.ignore_eeg_input == True:
                self.ignore_eeg_input.setChecked(True)
                if event.key():
                    self.dashboard.set_key_input('Ignore')
                return
            else: 
                self.ignore_eeg_input.setChecked(False)

        # self.update_power_handle(event.key())

        if self.is_keep_mode(event.key()):
            return

        if event.key() == Qt.Key_S:
            self.dashboard.set_key_input('s')
            self.dashboard.stop()
            self.dashboard.set_start_accel(True)

        if event.key() == Qt.Key_W:
            self.dashboard.set_key_input('w')
            if self.dashboard.get_start_accel() == True:
                self.dashboard.start_accel_forward()
            else:
                self.dashboard.forward()

        if event.key() == Qt.Key_A:
            self.dashboard.set_key_input('a')
            if self.dashboard.get_start_accel() == True:
                self.dashboard.start_accel_turn_left()
            else:
                self.dashboard.turn_left()

        if event.key() == Qt.Key_X:
            self.dashboard.set_key_input('x')

            if self.dashboard.get_start_accel() == True:
                self.dashboard.start_accel_backward()
            else:
                self.dashboard.backward()

        if event.key() == Qt.Key_D:
            self.dashboard.set_key_input('d')
            if self.dashboard.get_start_accel() == True:
                self.dashboard.start_accel_turn_right()
            else:
                self.dashboard.turn_right()

        if event.key() == Qt.Key_B:
            self.dashboard.set_key_input('b')
            self.dashboard.brake()

        if event.key() == Qt.Key_R:
            self.dashboard.set_key_input('r')
            # TODO: Make Inspection Mode
            # self.dashboard.steering.position_clear()
            #pot = self.dashboard.wheel.get_steering_pot()
            #self.dashboard.steering.middle_position(pot)

        if event.key() == Qt.Key_F:
            if self.dashboard.isFullScreen():
                for i in range(self.layout.count()):
                    w = self.layout.itemAt(i).widget()
                    w.show()
                self.dashboard.showNormal()
                self.change_backgroundcolor(self.default_backgroundcolor);
                self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.WindowTitleHint)
                self.showNormal()
            else:
                for i in range(self.layout.count()):
                    w = self.layout.itemAt(i).widget()
                    if w == self.dashboard:
                        continue
                    w.hide()
                self.change_backgroundcolor(Qt.black);
                self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint)
                self.showMaximized()
                self.dashboard.showFullScreen()

            self.dashboard.reset_label_position()

        if event.key() == Qt.Key_Escape:
            self.dashboard.close()
            self.close()

        self.go_to_keep_mode(event.key())

    def change_backgroundcolor(self, color):
        p = self.palette()
        p.setColor(self.backgroundRole(), color)
        self.setPalette(p)