# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'slate_configurator.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

MEDIA = 1
KEY = 2
STRING = 3
KEY_PRESS = 4
KEY_RELEASE = 5
CHANGE_LAYER = 6
MOUSE_CLICK = 7
MOUSE_MOVE = 8

LEFT_BUTTON = 1
MIDDLE_BUTTON = 4
RIGHT_BUTTON = 2

COMBOBOX_MEDIA = [
    "Volume Up",
    "Volume Down",
    "Mute",
    "Play/Pause",
    "Stop",
    "Rewind",
    "Fast Forward",
    "Record",
    "Next Track",
    "Previous Track",
    "Eject",
    "Brightness Increase",
    "Brightness Decrease"
]

COMBOBOX_MOUSE = [
    "Mouse Up",
    "Mouse Down",
    "Mouse Left",
    "Mouse Right",
    "Left Button",
    "Right Button",
    "Middle Button"
]

BLANK_LAYER = {
            "name": "Blank",
            "touch_shortcuts": [
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
               {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
               {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
               {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
                {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
               {
                    "label": "Label",
                    "icon": "icons/pr_blank.bmp",
                    "actions": (None, None),
                },
            ],
            "key_shortcuts": [
                {
                    "assigned_key": 0,
                    "actions": (None, None),
                },
                {
                    "assigned_key": 1,
                    "actions": (None, None),
                },
                {
                    "assigned_key": 2,
                    "actions": [None, None],
                },
                {
                    "assigned_key": 3,
                    "actions": (None, None),
                },
                {
                    "assigned_key": 4,
                    "actions": (None, None),
                },
                {
                    "assigned_key": 5,
                    "actions": (None, None),
                },
                {
                    "assigned_key": 6,
                    "actions": (None, None),
                },
                {
                    "assigned_key": 7,
                    "actions": (None, None),
                },
            ],
            "encoder": {
                "increment": (None, None),
                "decrement": (None, None),
                "button": (None, None),
            },
            "joystick": {
                "x+": (None, None),
                "x-": (None, None),
                "y+": (None, None),
                "y-": (None, None),
                "button": (None, None),
            }
        }


from PyQt5 import QtCore, QtGui, QtWidgets, Qt
from layers_config import slate_config
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control_code import ConsumerControlCode
import dialogs.screenkey as screenkey
import dialogs.new_layer as new_layer
import dialogs.delete_layer as delete_layer
import winsound
import copy
import wmi

def convertQttoHID(qt_code):
    if qt_code == QtCore.Qt.Key.Key_A: return Keycode.A
    if qt_code == QtCore.Qt.Key.Key_B: return Keycode.B
    if qt_code == QtCore.Qt.Key.Key_C: return Keycode.C
    if qt_code == QtCore.Qt.Key.Key_D: return Keycode.D
    if qt_code == QtCore.Qt.Key.Key_E: return Keycode.E
    if qt_code == QtCore.Qt.Key.Key_F: return Keycode.F
    if qt_code == QtCore.Qt.Key.Key_G: return Keycode.G
    if qt_code == QtCore.Qt.Key.Key_H: return Keycode.H
    if qt_code == QtCore.Qt.Key.Key_I: return Keycode.I
    if qt_code == QtCore.Qt.Key.Key_J: return Keycode.J
    if qt_code == QtCore.Qt.Key.Key_K: return Keycode.K
    if qt_code == QtCore.Qt.Key.Key_L: return Keycode.L
    if qt_code == QtCore.Qt.Key.Key_M: return Keycode.M
    if qt_code == QtCore.Qt.Key.Key_N: return Keycode.N
    if qt_code == QtCore.Qt.Key.Key_O: return Keycode.O
    if qt_code == QtCore.Qt.Key.Key_P: return Keycode.P
    if qt_code == QtCore.Qt.Key.Key_Q: return Keycode.Q
    if qt_code == QtCore.Qt.Key.Key_R: return Keycode.R
    if qt_code == QtCore.Qt.Key.Key_S: return Keycode.S
    if qt_code == QtCore.Qt.Key.Key_T: return Keycode.T
    if qt_code == QtCore.Qt.Key.Key_U: return Keycode.U
    if qt_code == QtCore.Qt.Key.Key_V: return Keycode.V
    if qt_code == QtCore.Qt.Key.Key_W: return Keycode.W
    if qt_code == QtCore.Qt.Key.Key_X: return Keycode.X
    if qt_code == QtCore.Qt.Key.Key_Y: return Keycode.Y
    if qt_code == QtCore.Qt.Key.Key_Z: return Keycode.Z
    if qt_code == QtCore.Qt.Key.Key_1: return Keycode.ONE
    if qt_code == QtCore.Qt.Key.Key_2: return Keycode.TWO
    if qt_code == QtCore.Qt.Key.Key_3: return Keycode.THREE
    if qt_code == QtCore.Qt.Key.Key_4: return Keycode.FOUR
    if qt_code == QtCore.Qt.Key.Key_5: return Keycode.FIVE
    if qt_code == QtCore.Qt.Key.Key_6: return Keycode.SIX
    if qt_code == QtCore.Qt.Key.Key_7: return Keycode.SEVEN
    if qt_code == QtCore.Qt.Key.Key_8: return Keycode.EIGHT
    if qt_code == QtCore.Qt.Key.Key_9: return Keycode.NINE
    if qt_code == QtCore.Qt.Key.Key_0: return Keycode.ZERO
    if qt_code == QtCore.Qt.Key.Key_Enter: return Keycode.ENTER
    if qt_code == QtCore.Qt.Key.Key_Escape: return Keycode.ESCAPE
    if qt_code == QtCore.Qt.Key.Key_Backspace: return Keycode.BACKSPACE
    if qt_code == QtCore.Qt.Key.Key_Tab: return Keycode.TAB
    if qt_code == QtCore.Qt.Key.Key_Space: return Keycode.SPACEBAR
    if qt_code == QtCore.Qt.Key.Key_Minus: return Keycode.MINUS
    if qt_code == QtCore.Qt.Key.Key_Equal: return Keycode.EQUALS
    if qt_code == QtCore.Qt.Key.Key_BracketLeft: return Keycode.LEFT_BRACKET
    if qt_code == QtCore.Qt.Key.Key_BracketRight: return Keycode.RIGHT_BRACKET
    if qt_code == QtCore.Qt.Key.Key_Backslash: return Keycode.BACKSLASH
    if qt_code == QtCore.Qt.Key.Key_NumberSign: return Keycode.POUND
    if qt_code == QtCore.Qt.Key.Key_Semicolon: return Keycode.SEMICOLON
    if qt_code == QtCore.Qt.Key.Key_QuoteDbl: return Keycode.QUOTE
    if qt_code == QtCore.Qt.Key.Key_Backslash: return Keycode.GRAVE_ACCENT
    if qt_code == QtCore.Qt.Key.Key_Comma: return Keycode.COMMA
    if qt_code == QtCore.Qt.Key.Key_Period: return Keycode.PERIOD
    if qt_code == QtCore.Qt.Key.Key_Slash: return Keycode.FORWARD_SLASH
    if qt_code == QtCore.Qt.Key.Key_CapsLock: return Keycode.CAPS_LOCK
    if qt_code == QtCore.Qt.Key.Key_F1: return Keycode.F1
    if qt_code == QtCore.Qt.Key.Key_F2: return Keycode.F2
    if qt_code == QtCore.Qt.Key.Key_F3: return Keycode.F3
    if qt_code == QtCore.Qt.Key.Key_F4: return Keycode.F4
    if qt_code == QtCore.Qt.Key.Key_F5: return Keycode.F5
    if qt_code == QtCore.Qt.Key.Key_F6: return Keycode.F6
    if qt_code == QtCore.Qt.Key.Key_F7: return Keycode.F7
    if qt_code == QtCore.Qt.Key.Key_F8: return Keycode.F8
    if qt_code == QtCore.Qt.Key.Key_F9: return Keycode.F9
    if qt_code == QtCore.Qt.Key.Key_F10: return Keycode.F10
    if qt_code == QtCore.Qt.Key.Key_F11: return Keycode.F11
    if qt_code == QtCore.Qt.Key.Key_F12: return Keycode.F12
    if qt_code == QtCore.Qt.Key.Key_Print: return Keycode.PRINT_SCREEN
    if qt_code == QtCore.Qt.Key.Key_ScrollLock: return Keycode.SCROLL_LOCK
    if qt_code == QtCore.Qt.Key.Key_Pause: return Keycode.PAUSE
    if qt_code == QtCore.Qt.Key.Key_Insert: return Keycode.INSERT
    if qt_code == QtCore.Qt.Key.Key_Home: return Keycode.HOME
    if qt_code == QtCore.Qt.Key.Key_PageUp: return Keycode.PAGE_UP
    if qt_code == QtCore.Qt.Key.Key_Delete: return Keycode.DELETE
    if qt_code == QtCore.Qt.Key.Key_End: return Keycode.END
    if qt_code == QtCore.Qt.Key.Key_PageDown: return Keycode.PAGE_DOWN
    if qt_code == QtCore.Qt.Key.Key_Right: return Keycode.RIGHT_ARROW
    if qt_code == QtCore.Qt.Key.Key_Left: return Keycode.LEFT_ARROW
    if qt_code == QtCore.Qt.Key.Key_Down: return Keycode.DOWN_ARROW
    if qt_code == QtCore.Qt.Key.Key_Up: return Keycode.UP_ARROW
    if qt_code == QtCore.Qt.Key.Key_NumLock: return Keycode.KEYPAD_NUMLOCK
    if qt_code == QtCore.Qt.Key.Key_Asterisk: return Keycode.KEYPAD_ASTERISK
    if qt_code == QtCore.Qt.Key.Key_ApplicationLeft: return Keycode.APPLICATION
    if qt_code == QtCore.Qt.Key.Key_F20: return Keycode.F20
    if qt_code == QtCore.Qt.Key.Key_F21: return Keycode.F21
    if qt_code == QtCore.Qt.Key.Key_F22: return Keycode.F22
    if qt_code == QtCore.Qt.Key.Key_F23: return Keycode.F23
    if qt_code == QtCore.Qt.Key.Key_F24: return Keycode.F24
    if qt_code == QtCore.Qt.Key.Key_Control: return Keycode.CONTROL
    if qt_code == QtCore.Qt.Key.Key_Shift: return Keycode.SHIFT
    if qt_code == QtCore.Qt.Key.Key_Alt: return Keycode.ALT

def convertHIDtoQt(hid_code):
    if hid_code == Keycode.A: return QtCore.Qt.Key.Key_A
    if hid_code == Keycode.B: return QtCore.Qt.Key.Key_B
    if hid_code == Keycode.C: return QtCore.Qt.Key.Key_C
    if hid_code == Keycode.D: return QtCore.Qt.Key.Key_D
    if hid_code == Keycode.E: return QtCore.Qt.Key.Key_E
    if hid_code == Keycode.F: return QtCore.Qt.Key.Key_F
    if hid_code == Keycode.G: return QtCore.Qt.Key.Key_G
    if hid_code == Keycode.H: return QtCore.Qt.Key.Key_H
    if hid_code == Keycode.I: return QtCore.Qt.Key.Key_I
    if hid_code == Keycode.J: return QtCore.Qt.Key.Key_J
    if hid_code == Keycode.K: return QtCore.Qt.Key.Key_K
    if hid_code == Keycode.L: return QtCore.Qt.Key.Key_L
    if hid_code == Keycode.M: return QtCore.Qt.Key.Key_M
    if hid_code == Keycode.N: return QtCore.Qt.Key.Key_N
    if hid_code == Keycode.O: return QtCore.Qt.Key.Key_O
    if hid_code == Keycode.P: return QtCore.Qt.Key.Key_P
    if hid_code == Keycode.Q: return QtCore.Qt.Key.Key_Q
    if hid_code == Keycode.R: return QtCore.Qt.Key.Key_R
    if hid_code == Keycode.S: return QtCore.Qt.Key.Key_S
    if hid_code == Keycode.T: return QtCore.Qt.Key.Key_T
    if hid_code == Keycode.U: return QtCore.Qt.Key.Key_U
    if hid_code == Keycode.V: return QtCore.Qt.Key.Key_V
    if hid_code == Keycode.W: return QtCore.Qt.Key.Key_W
    if hid_code == Keycode.X: return QtCore.Qt.Key.Key_X
    if hid_code == Keycode.Y: return QtCore.Qt.Key.Key_Y
    if hid_code == Keycode.Z: return QtCore.Qt.Key.Key_Z
    if hid_code == Keycode.ONE: return QtCore.Qt.Key.Key_1 
    if hid_code == Keycode.TWO: return QtCore.Qt.Key.Key_2
    if hid_code == Keycode.THREE: return QtCore.Qt.Key.Key_3
    if hid_code == Keycode.FOUR: return QtCore.Qt.Key.Key_4
    if hid_code == Keycode.FIVE: return QtCore.Qt.Key.Key_5
    if hid_code == Keycode.SIX: return QtCore.Qt.Key.Key_6
    if hid_code == Keycode.SEVEN: return QtCore.Qt.Key.Key_7 
    if hid_code == Keycode.EIGHT: return QtCore.Qt.Key.Key_8 
    if hid_code == Keycode.NINE: return QtCore.Qt.Key.Key_9
    if hid_code == Keycode.ZERO: return QtCore.Qt.Key.Key_0
    if hid_code == Keycode.ENTER: return QtCore.Qt.Key.Key_Enter
    if hid_code == Keycode.ESCAPE: return QtCore.Qt.Key.Key_Escape
    if hid_code == Keycode.BACKSPACE: return QtCore.Qt.Key.Key_Backspace
    if hid_code == Keycode.TAB: return QtCore.Qt.Key.Key_Tab
    if hid_code == Keycode.SPACEBAR: return QtCore.Qt.Key.Key_Space
    if hid_code == Keycode.MINUS: return QtCore.Qt.Key.Key_Minus
    if hid_code == Keycode.EQUALS: return QtCore.Qt.Key.Key_Equal
    if hid_code == Keycode.LEFT_BRACKET: return QtCore.Qt.Key.Key_BracketLeft
    if hid_code == Keycode.RIGHT_BRACKET: return QtCore.Qt.Key.Key_BracketRight
    if hid_code == Keycode.BACKSLASH: return QtCore.Qt.Key.Key_Backslash
    if hid_code == Keycode.POUND: return QtCore.Qt.Key.Key_NumberSign
    if hid_code == Keycode.SEMICOLON: return QtCore.Qt.Key.Key_Semicolon
    if hid_code == Keycode.QUOTE: return QtCore.Qt.Key.Key_QuoteDbl
    if hid_code == Keycode.GRAVE_ACCENT: return QtCore.Qt.Key.Key_Backslash
    if hid_code == Keycode.COMMA: return QtCore.Qt.Key.Key_Comma
    if hid_code == Keycode.PERIOD: return QtCore.Qt.Key.Key_Period
    if hid_code == Keycode.FORWARD_SLASH: return QtCore.Qt.Key.Key_Slash
    if hid_code == Keycode.CAPS_LOCK: return QtCore.Qt.Key.Key_CapsLock
    if hid_code == Keycode.F1: return QtCore.Qt.Key.Key_F1
    if hid_code == Keycode.F2: return QtCore.Qt.Key.Key_F2
    if hid_code == Keycode.F3: return QtCore.Qt.Key.Key_F3
    if hid_code == Keycode.F4: return QtCore.Qt.Key.Key_F4
    if hid_code == Keycode.F5: return QtCore.Qt.Key.Key_F5
    if hid_code == Keycode.F6: return QtCore.Qt.Key.Key_F6
    if hid_code == Keycode.F7: return QtCore.Qt.Key.Key_F7
    if hid_code == Keycode.F8: return QtCore.Qt.Key.Key_F8
    if hid_code == Keycode.F9: return QtCore.Qt.Key.Key_F9
    if hid_code == Keycode.F10: return QtCore.Qt.Key.Key_F10
    if hid_code == Keycode.F11: return QtCore.Qt.Key.Key_F11
    if hid_code == Keycode.F12: return QtCore.Qt.Key.Key_F12
    if hid_code == Keycode.PRINT_SCREEN: return QtCore.Qt.Key.Key_Print
    if hid_code == Keycode.SCROLL_LOCK: return QtCore.Qt.Key.Key_ScrollLock
    if hid_code == Keycode.PAUSE: return QtCore.Qt.Key.Key_Pause
    if hid_code == Keycode.INSERT: return QtCore.Qt.Key.Key_Insert
    if hid_code == Keycode.HOME: return QtCore.Qt.Key.Key_Home
    if hid_code == Keycode.PAGE_UP: return QtCore.Qt.Key.Key_PageUp
    if hid_code == Keycode.DELETE: return QtCore.Qt.Key.Key_Delete
    if hid_code == Keycode.END: return QtCore.Qt.Key.Key_End
    if hid_code == Keycode.PAGE_DOWN: return QtCore.Qt.Key.Key_PageDown
    if hid_code == Keycode.RIGHT_ARROW: return QtCore.Qt.Key.Key_Right
    if hid_code == Keycode.LEFT_ARROW: return QtCore.Qt.Key.Key_Left
    if hid_code == Keycode.DOWN_ARROW: return QtCore.Qt.Key.Key_Down
    if hid_code == Keycode.UP_ARROW: return QtCore.Qt.Key.Key_Up
    if hid_code == Keycode.KEYPAD_NUMLOCK: return QtCore.Qt.Key.Key_NumLock
    if hid_code == Keycode.KEYPAD_ASTERISK: return QtCore.Qt.Key.Key_Asterisk
    if hid_code == Keycode.APPLICATION: return QtCore.Qt.Key.Key_ApplicationLeft
    if hid_code == Keycode.F20: return QtCore.Qt.Key.Key_F20
    if hid_code == Keycode.F21: return QtCore.Qt.Key.Key_F21
    if hid_code == Keycode.F22: return QtCore.Qt.Key.Key_F22
    if hid_code == Keycode.F23: return QtCore.Qt.Key.Key_F23
    if hid_code == Keycode.F24: return QtCore.Qt.Key.Key_F24
    if hid_code == Keycode.CONTROL: return QtCore.Qt.KeyboardModifier.ControlModifier
    if hid_code == Keycode.SHIFT: return QtCore.Qt.KeyboardModifier.ShiftModifier
    if hid_code == Keycode.RIGHT_SHIFT: return QtCore.Qt.KeyboardModifier.ShiftModifier
    if hid_code == Keycode.ALT: return QtCore.Qt.KeyboardModifier.AltModifier

def fillInputForm(self, layer, prefix, macro_type_index):
    # Get actions for input
    if prefix == "screenkey":
        actions = slate_config["layers"][ui.layer_select.currentIndex()]["touch_shortcuts"][layer]["actions"]
    elif prefix == "key_0":
        actions = layer["key_shortcuts"][0]["actions"]
    elif prefix == "key_1":
        actions = layer["key_shortcuts"][1]["actions"]
    elif prefix == "key_2":
        actions = layer["key_shortcuts"][2]["actions"]
    elif prefix == "key_3":
        actions = layer["key_shortcuts"][3]["actions"]
    elif prefix == "key_4":
        actions = layer["key_shortcuts"][4]["actions"]
    elif prefix == "key_5":
        actions = layer["key_shortcuts"][5]["actions"]
    elif prefix == "key_6":
        actions = layer["key_shortcuts"][6]["actions"]
    elif prefix == "key_7":
        actions = layer["key_shortcuts"][7]["actions"]
    elif prefix == "xAxis_pos":
        actions = layer["joystick"]["x+"]
    elif prefix == "xAxis_neg":
        actions = layer["joystick"]["x-"]
    elif prefix == "yAxis_pos":
        actions = layer["joystick"]["y+"]
    elif prefix == "yAxis_neg":
        actions = layer["joystick"]["y-"]
    elif prefix == "joystick_button":
        actions = layer["joystick"]["button"]
    elif prefix == "encoder_increment":
        actions = layer["encoder"]["increment"]
    elif prefix == "encoder_decrement":
        actions = layer["encoder"]["decrement"]
    elif prefix == "encoder_button":
        actions = layer["encoder"]["button"]
    # Fill input form
    if macro_type_index == 0:
        pass
    if macro_type_index == 1:
        getattr(self, "%s_hotkey" % prefix).setKeySequence(ui.constructKeySequence(actions[1]))
    if macro_type_index == 2:
        getattr(self, "%s_string" % prefix).setText(actions[1])
    if macro_type_index == 3:
        if actions[1] == ConsumerControlCode.VOLUME_INCREMENT:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(0)
        if actions[1] == ConsumerControlCode.VOLUME_DECREMENT:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(1)
        if actions[1] == ConsumerControlCode.MUTE:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(2)
        if actions[1] == ConsumerControlCode.PLAY_PAUSE:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(3)
        if actions[1] == ConsumerControlCode.STOP:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(4)
        if actions[1] == ConsumerControlCode.REWIND:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(5)
        if actions[1] == ConsumerControlCode.FAST_FORWARD:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(6)
        if actions[1] == ConsumerControlCode.RECORD:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(7)
        if actions[1] == ConsumerControlCode.SCAN_NEXT_TRACK:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(8)
        if actions[1] == ConsumerControlCode.SCAN_PREVIOUS_TRACK:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(9)
        if actions[1] == ConsumerControlCode.EJECT:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(10)
        if actions[1] == ConsumerControlCode.BRIGHTNESS_INCREMENT:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(11)
        if actions[1] == ConsumerControlCode.BRIGHTNESS_DECREMENT:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(12)
    if macro_type_index == 4:
        pass
    if macro_type_index == 5:
        if actions[1] == [0, 100, 0]:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(0)
        if actions[1] == [0, -100, 0]:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(1)
        if actions[1] == [-100, 0, 0]:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(2)
        if actions[1] == [100, 0, 0]:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(3)
        if actions[1] == LEFT_BUTTON:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(4)
        if actions[1] == RIGHT_BUTTON:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(5)
        if actions[1] == MIDDLE_BUTTON:
            getattr(self, "%s_combobox" % prefix).setCurrentIndex(6)

class Ui_MainWindow(object):
    icon0 = QtGui.QIcon()
    icon1 = QtGui.QIcon()
    icon2 = QtGui.QIcon()
    icon3 = QtGui.QIcon()
    icon4 = QtGui.QIcon()
    icon5 = QtGui.QIcon()
    icon6 = QtGui.QIcon()
    icon7 = QtGui.QIcon()
    icon8 = QtGui.QIcon()
    icon9 = QtGui.QIcon()
    icon10 = QtGui.QIcon()
    icon11 = QtGui.QIcon()

    prevLayerIndex = -1

    changesMade = False

    def generateScreenKeyIcon(self, layer, number):
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("../slate-software/" + layer["touch_shortcuts"][number]["icon"]), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        return icon

    def closeEvent(self):
        print("user has clicked on red x")
        import sys
        sys.exit(0)

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(850, 610)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(850, 610))
        MainWindow.setMaximumSize(QtCore.QSize(850, 610))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("images/slate_windowicon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 841, 571))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.widget = QtWidgets.QWidget(self.verticalLayoutWidget)
        self.widget.setObjectName("widget")
        self.button_separator = QtWidgets.QFrame(self.widget)
        self.button_separator.setGeometry(QtCore.QRect(220, 539, 31, 31))
        self.button_separator.setFrameShape(QtWidgets.QFrame.VLine)
        self.button_separator.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.button_separator.setObjectName("button_separator")
        self.exit_button = QtWidgets.QPushButton(self.widget)
        self.exit_button.setGeometry(QtCore.QRect(110, 540, 111, 29))
        self.exit_button.setObjectName("exit_button")
        self.exit_button.clicked.connect(lambda: self.closeEvent(QtGui.QCloseEvent()))
        self.save_config_button = QtWidgets.QPushButton(self.widget)
        self.save_config_button.setGeometry(QtCore.QRect(250, 540, 141, 29))
        self.save_config_button.setObjectName("save_config_button")
        self.layerGroupBox = QtWidgets.QGroupBox(self.widget)
        self.layerGroupBox.setGeometry(QtCore.QRect(0, 0, 521, 61))
        self.layerGroupBox.setObjectName("layerGroupBox")
        self.layer_select = QtWidgets.QComboBox(self.layerGroupBox)
        self.layer_select.setGeometry(QtCore.QRect(60, 20, 141, 29))
        self.layer_select.setObjectName("layer_select")
        self.delete_layer_button = QtWidgets.QPushButton(self.layerGroupBox)
        self.delete_layer_button.setGeometry(QtCore.QRect(440, 20, 71, 29))
        self.delete_layer_button.setObjectName("delete_layer_button")
        self.create_layer_button = QtWidgets.QPushButton(self.layerGroupBox)
        self.create_layer_button.setGeometry(QtCore.QRect(300, 20, 121, 29))
        self.create_layer_button.setObjectName("create_layer_button")
        self.layer_select_label = QtWidgets.QLabel(self.layerGroupBox)
        self.layer_select_label.setGeometry(QtCore.QRect(10, 20, 51, 29))
        self.layer_select_label.setObjectName("layer_select_label")
        self.layer_separator_2 = QtWidgets.QFrame(self.layerGroupBox)
        self.layer_separator_2.setGeometry(QtCore.QRect(420, 20, 21, 29))
        self.layer_separator_2.setFrameShape(QtWidgets.QFrame.VLine)
        self.layer_separator_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.layer_separator_2.setObjectName("layer_separator_2")
        self.rename_layer_button = QtWidgets.QPushButton(self.layerGroupBox)
        self.rename_layer_button.setGeometry(QtCore.QRect(220, 20, 61, 29))
        self.rename_layer_button.setObjectName("rename_layer_button")
        self.layer_separator_3 = QtWidgets.QFrame(self.layerGroupBox)
        self.layer_separator_3.setGeometry(QtCore.QRect(280, 20, 21, 29))
        self.layer_separator_3.setFrameShape(QtWidgets.QFrame.VLine)
        self.layer_separator_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.layer_separator_3.setObjectName("layer_separator_3")
        self.layer_separator_4 = QtWidgets.QFrame(self.layerGroupBox)
        self.layer_separator_4.setGeometry(QtCore.QRect(200, 20, 21, 29))
        self.layer_separator_4.setFrameShape(QtWidgets.QFrame.VLine)
        self.layer_separator_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.layer_separator_4.setObjectName("layer_separator_4")
        self.macroGroupBox = QtWidgets.QGroupBox(self.widget)
        self.macroGroupBox.setGeometry(QtCore.QRect(0, 60, 521, 471))
        self.macroGroupBox.setObjectName("macroGroupBox")
        self.macroTabs = QtWidgets.QTabWidget(self.macroGroupBox)
        self.macroTabs.setGeometry(QtCore.QRect(10, 20, 501, 441))
        self.macroTabs.setObjectName("macroTabs")
        #self.macroTabs.currentChanged.connect(self.changePreviewImage)
        self.macroTab_screenkeys = QtWidgets.QWidget()
        self.macroTab_screenkeys.setObjectName("macroTab_screenkeys")
        self.row_select_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.row_select_label.setGeometry(QtCore.QRect(20, 20, 31, 21))
        self.row_select_label.setObjectName("row_select_label")
        self.column_select_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.column_select_label.setGeometry(QtCore.QRect(170, 20, 51, 21))
        self.column_select_label.setObjectName("column_select_label")
        self.row_select = QtWidgets.QSpinBox(self.macroTab_screenkeys)
        self.row_select.setEnabled(False)
        self.row_select.setGeometry(QtCore.QRect(60, 20, 42, 22))
        self.row_select.setStatusTip("")
        self.row_select.setMaximum(3)
        self.row_select.setProperty("value", 3)
        self.row_select.setObjectName("row_select")
        self.column_select = QtWidgets.QSpinBox(self.macroTab_screenkeys)
        self.column_select.setEnabled(False)
        self.column_select.setGeometry(QtCore.QRect(230, 20, 42, 22))
        self.column_select.setMaximum(4)
        self.column_select.setProperty("value", 4)
        self.column_select.setObjectName("column_select")
        self.divider_screenkey = QtWidgets.QFrame(self.macroTab_screenkeys)
        self.divider_screenkey.setGeometry(QtCore.QRect(10, 50, 421, 16))
        self.divider_screenkey.setFrameShape(QtWidgets.QFrame.HLine)
        self.divider_screenkey.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.divider_screenkey.setObjectName("divider_screenkey")
        self.max_row_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.max_row_label.setEnabled(True)
        self.max_row_label.setGeometry(QtCore.QRect(110, 20, 51, 21))
        self.max_row_label.setObjectName("max_row_label")
        self.max_column_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.max_column_label.setGeometry(QtCore.QRect(280, 20, 51, 21))
        self.max_column_label.setObjectName("max_column_label")
        self.screenkey_0_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_0_label.setGeometry(QtCore.QRect(30, 160, 81, 21))
        self.screenkey_0_label.setObjectName("screenkey_0_label")
        self.screenkey_0_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_1_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_1_label.setGeometry(QtCore.QRect(130, 160, 81, 21))
        self.screenkey_1_label.setObjectName("screenkey_1_label")
        self.screenkey_1_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_2_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_2_label.setGeometry(QtCore.QRect(230, 160, 81, 21))
        self.screenkey_2_label.setObjectName("screenkey_2_label")
        self.screenkey_2_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_3_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_3_label.setGeometry(QtCore.QRect(330, 160, 81, 21))
        self.screenkey_3_label.setObjectName("screenkey_3_label")
        self.screenkey_3_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_4_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_4_label.setGeometry(QtCore.QRect(30, 270, 81, 21))
        self.screenkey_4_label.setObjectName("screenkey_4_label")
        self.screenkey_4_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_5_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_5_label.setGeometry(QtCore.QRect(130, 270, 81, 21))
        self.screenkey_5_label.setObjectName("screenkey_5_label")
        self.screenkey_5_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_6_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_6_label.setGeometry(QtCore.QRect(230, 270, 81, 21))
        self.screenkey_6_label.setObjectName("screenkey_6_label")
        self.screenkey_6_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_7_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_7_label.setGeometry(QtCore.QRect(330, 270, 81, 21))
        self.screenkey_7_label.setObjectName("screenkey_7_label")
        self.screenkey_7_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_8_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_8_label.setGeometry(QtCore.QRect(30, 380, 81, 21))
        self.screenkey_8_label.setObjectName("screenkey_8_label")
        self.screenkey_8_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_9_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_9_label.setGeometry(QtCore.QRect(130, 380, 81, 21))
        self.screenkey_9_label.setObjectName("screenkey_9_label")
        self.screenkey_9_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_10_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_10_label.setGeometry(QtCore.QRect(230, 380, 81, 21))
        self.screenkey_10_label.setObjectName("screenkey_10_label")
        self.screenkey_10_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_11_label = QtWidgets.QLabel(self.macroTab_screenkeys)
        self.screenkey_11_label.setGeometry(QtCore.QRect(330, 380, 81, 21))
        self.screenkey_11_label.setObjectName("screenkey_11_label")
        self.screenkey_11_label.setAlignment(QtCore.Qt.AlignCenter)
        self.screenkey_0 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_0.setGeometry(QtCore.QRect(30, 80, 81, 81))
        self.screenkey_0.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_0.setText("")
        
        self.icon0 = self.generateScreenKeyIcon(slate_config["layers"][0], 0)
        self.icon1 = self.generateScreenKeyIcon(slate_config["layers"][0], 1)
        self.icon2 = self.generateScreenKeyIcon(slate_config["layers"][0], 2)
        self.icon3 = self.generateScreenKeyIcon(slate_config["layers"][0], 3)
        self.icon4 = self.generateScreenKeyIcon(slate_config["layers"][0], 4)
        self.icon5 = self.generateScreenKeyIcon(slate_config["layers"][0], 5)
        self.icon6 = self.generateScreenKeyIcon(slate_config["layers"][0], 6)
        self.icon7 = self.generateScreenKeyIcon(slate_config["layers"][0], 7)
        self.icon8 = self.generateScreenKeyIcon(slate_config["layers"][0], 8)
        self.icon9 = self.generateScreenKeyIcon(slate_config["layers"][0], 9)
        self.icon10 = self.generateScreenKeyIcon(slate_config["layers"][0], 10)
        self.icon11 = self.generateScreenKeyIcon(slate_config["layers"][0], 11)
 
        self.screenkey_0.setIcon(self.icon0)
        self.screenkey_0.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_0.setObjectName("screenkey_0")
        self.screenkey_1 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_1.setGeometry(QtCore.QRect(130, 80, 81, 81))
        self.screenkey_1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_1.setText("")
        self.screenkey_1.setIcon(self.icon1)
        self.screenkey_1.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_1.setObjectName("screenkey_1")
        self.screenkey_2 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_2.setGeometry(QtCore.QRect(230, 80, 81, 81))
        self.screenkey_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_2.setText("")
        self.screenkey_2.setIcon(self.icon2)
        self.screenkey_2.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_2.setObjectName("screenkey_2")
        self.screenkey_3 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_3.setGeometry(QtCore.QRect(330, 80, 81, 81))
        self.screenkey_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_3.setText("")
        self.screenkey_3.setIcon(self.icon3)
        self.screenkey_3.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_3.setObjectName("screenkey_3")
        self.screenkey_4 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_4.setGeometry(QtCore.QRect(30, 190, 81, 81))
        self.screenkey_4.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_4.setText("")
        self.screenkey_4.setIcon(self.icon4)
        self.screenkey_4.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_4.setObjectName("screenkey_4")
        self.screenkey_5 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_5.setGeometry(QtCore.QRect(130, 190, 81, 81))
        self.screenkey_5.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_5.setText("")
        self.screenkey_5.setIcon(self.icon5)
        self.screenkey_5.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_5.setObjectName("screenkey_5")
        self.screenkey_6 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_6.setGeometry(QtCore.QRect(230, 190, 81, 81))
        self.screenkey_6.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_6.setText("")
        self.screenkey_6.setIcon(self.icon6)
        self.screenkey_6.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_6.setObjectName("screenkey_6")
        self.screenkey_7 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_7.setGeometry(QtCore.QRect(330, 190, 81, 81))
        self.screenkey_7.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_7.setText("")
        self.screenkey_7.setIcon(self.icon7)
        self.screenkey_7.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_7.setObjectName("screenkey_7")
        self.screenkey_10 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_10.setGeometry(QtCore.QRect(230, 300, 81, 81))
        self.screenkey_10.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_10.setText("")
        self.screenkey_10.setIcon(self.icon8)
        self.screenkey_10.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_10.setObjectName("screenkey_10")
        self.screenkey_8 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_8.setGeometry(QtCore.QRect(30, 300, 81, 81))
        self.screenkey_8.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_8.setText("")
        self.screenkey_8.setIcon(self.icon9)
        self.screenkey_8.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_8.setObjectName("screenkey_8")
        self.screenkey_11 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_11.setGeometry(QtCore.QRect(330, 300, 81, 81))
        self.screenkey_11.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_11.setText("")
        self.screenkey_11.setIcon(self.icon10)
        self.screenkey_11.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_11.setObjectName("screenkey_11")
        self.screenkey_9 = QtWidgets.QPushButton(self.macroTab_screenkeys)
        self.screenkey_9.setGeometry(QtCore.QRect(130, 300, 81, 81))
        self.screenkey_9.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.screenkey_9.setText("")
        self.screenkey_9.setIcon(self.icon11)
        self.screenkey_9.setIconSize(QtCore.QSize(80, 80))
        self.screenkey_9.setObjectName("screenkey_9")
        self.macroTabs.addTab(self.macroTab_screenkeys, "")
        self.macroTab_physicalkeys = QtWidgets.QWidget()
        self.macroTab_physicalkeys.setObjectName("macroTab_physicalkeys")
        self.key_0_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_0_label.setGeometry(QtCore.QRect(20, 20, 41, 21))
        self.key_0_label.setObjectName("key_0_label")
        self.key_0 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_0.setGeometry(QtCore.QRect(60, 20, 121, 21))
        self.key_0.setObjectName("key_0")
        self.key_0.addItem("")
        self.key_0.addItem("")
        self.key_0.addItem("")
        self.key_0.addItem("")
        self.key_0.addItem("")
        self.key_0.addItem("")
        self.key_1_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_1_label.setGeometry(QtCore.QRect(20, 50, 41, 21))
        self.key_1_label.setObjectName("key_1_label")
        self.key_2_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_2_label.setGeometry(QtCore.QRect(20, 80, 41, 21))
        self.key_2_label.setObjectName("key_2_label")
        self.key_3_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_3_label.setGeometry(QtCore.QRect(20, 110, 41, 21))
        self.key_3_label.setObjectName("key_3_label")
        self.key_4_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_4_label.setGeometry(QtCore.QRect(20, 140, 41, 21))
        self.key_4_label.setObjectName("key_4_label")
        self.key_5_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_5_label.setGeometry(QtCore.QRect(20, 170, 41, 21))
        self.key_5_label.setObjectName("key_5_label")
        self.key_6_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_6_label.setGeometry(QtCore.QRect(20, 200, 41, 21))
        self.key_6_label.setObjectName("key_6_label")
        self.key_7_label = QtWidgets.QLabel(self.macroTab_physicalkeys)
        self.key_7_label.setGeometry(QtCore.QRect(20, 230, 41, 21))
        self.key_7_label.setObjectName("key_7_label")
        self.key_1 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_1.setGeometry(QtCore.QRect(60, 50, 121, 21))
        self.key_1.setObjectName("key_1")
        self.key_1.addItem("")
        self.key_1.addItem("")
        self.key_1.addItem("")
        self.key_1.addItem("")
        self.key_1.addItem("")
        self.key_1.addItem("")
        self.key_3 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_3.setGeometry(QtCore.QRect(60, 110, 121, 21))
        self.key_3.setObjectName("key_3")
        self.key_3.addItem("")
        self.key_3.addItem("")
        self.key_3.addItem("")
        self.key_3.addItem("")
        self.key_3.addItem("")
        self.key_3.addItem("")
        self.key_2 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_2.setGeometry(QtCore.QRect(60, 80, 121, 21))
        self.key_2.setObjectName("key_2")
        self.key_2.addItem("")
        self.key_2.addItem("")
        self.key_2.addItem("")
        self.key_2.addItem("")
        self.key_2.addItem("")
        self.key_2.addItem("")
        self.key_5 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_5.setGeometry(QtCore.QRect(60, 170, 121, 21))
        self.key_5.setObjectName("key_5")
        self.key_5.addItem("")
        self.key_5.addItem("")
        self.key_5.addItem("")
        self.key_5.addItem("")
        self.key_5.addItem("")
        self.key_5.addItem("")
        self.key_4 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_4.setGeometry(QtCore.QRect(60, 140, 121, 21))
        self.key_4.setObjectName("key_4")
        self.key_4.addItem("")
        self.key_4.addItem("")
        self.key_4.addItem("")
        self.key_4.addItem("")
        self.key_4.addItem("")
        self.key_4.addItem("")
        self.key_7 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_7.setGeometry(QtCore.QRect(60, 230, 121, 21))
        self.key_7.setObjectName("key_7")
        self.key_7.addItem("")
        self.key_7.addItem("")
        self.key_7.addItem("")
        self.key_7.addItem("")
        self.key_7.addItem("")
        self.key_7.addItem("")
        self.key_6 = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_6.setGeometry(QtCore.QRect(60, 200, 121, 21))
        self.key_6.setObjectName("key_6")
        self.key_6.addItem("")
        self.key_6.addItem("")
        self.key_6.addItem("")
        self.key_6.addItem("")
        self.key_6.addItem("")
        self.key_6.addItem("")
        self.key_0_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_0_hotkey.setEnabled(True)
        self.key_0_hotkey.setGeometry(QtCore.QRect(190, 20, 161, 21))
        self.key_0_hotkey.setObjectName("key_0_hotkey")
        self.key_0_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_0_string.setEnabled(True)
        self.key_0_string.setGeometry(QtCore.QRect(190, 20, 291, 21))
        self.key_0_string.setObjectName("key_0_string")
        self.key_0_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_0_combobox.setGeometry(QtCore.QRect(190, 20, 161, 21))
        self.key_0_combobox.setObjectName("key_0_combobox")
        self.key_1_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_1_hotkey.setEnabled(True)
        self.key_1_hotkey.setGeometry(QtCore.QRect(190, 50, 161, 21))
        self.key_1_hotkey.setObjectName("key_1_hotkey")
        self.key_1_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_1_combobox.setGeometry(QtCore.QRect(190, 50, 161, 21))
        self.key_1_combobox.setObjectName("key_1_combobox")
        self.key_1_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_1_string.setEnabled(True)
        self.key_1_string.setGeometry(QtCore.QRect(190, 50, 291, 21))
        self.key_1_string.setObjectName("key_1_string")
        self.key_2_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_2_hotkey.setEnabled(True)
        self.key_2_hotkey.setGeometry(QtCore.QRect(190, 80, 161, 21))
        self.key_2_hotkey.setObjectName("key_2_hotkey")
        self.key_2_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_2_combobox.setGeometry(QtCore.QRect(190, 80, 161, 21))
        self.key_2_combobox.setObjectName("key_2_combobox")
        self.key_2_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_2_string.setEnabled(True)
        self.key_2_string.setGeometry(QtCore.QRect(190, 80, 291, 21))
        self.key_2_string.setObjectName("key_2_string")
        self.key_3_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_3_hotkey.setEnabled(True)
        self.key_3_hotkey.setGeometry(QtCore.QRect(190, 110, 161, 21))
        self.key_3_hotkey.setObjectName("key_3_hotkey")
        self.key_3_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_3_combobox.setGeometry(QtCore.QRect(190, 110, 161, 21))
        self.key_3_combobox.setObjectName("key_3_combobox")
        self.key_3_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_3_string.setEnabled(True)
        self.key_3_string.setGeometry(QtCore.QRect(190, 110, 291, 21))
        self.key_3_string.setObjectName("key_3_string")
        self.key_4_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_4_hotkey.setEnabled(True)
        self.key_4_hotkey.setGeometry(QtCore.QRect(190, 140, 151, 21))
        self.key_4_hotkey.setObjectName("key_4_hotkey")
        self.key_4_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_4_combobox.setGeometry(QtCore.QRect(190, 140, 161, 21))
        self.key_4_combobox.setObjectName("key_4_combobox")
        self.key_4_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_4_string.setEnabled(True)
        self.key_4_string.setGeometry(QtCore.QRect(190, 140, 291, 21))
        self.key_4_string.setObjectName("key_4_string")
        self.key_5_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_5_hotkey.setEnabled(True)
        self.key_5_hotkey.setGeometry(QtCore.QRect(190, 170, 161, 21))
        self.key_5_hotkey.setObjectName("key_5_hotkey")
        self.key_5_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_5_combobox.setGeometry(QtCore.QRect(190, 170, 161, 21))
        self.key_5_combobox.setObjectName("key_5_combobox")
        self.key_5_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_5_string.setEnabled(True)
        self.key_5_string.setGeometry(QtCore.QRect(190, 170, 291, 21))
        self.key_5_string.setObjectName("key_5_string")
        self.key_6_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_6_hotkey.setEnabled(True)
        self.key_6_hotkey.setGeometry(QtCore.QRect(190, 200, 161, 21))
        self.key_6_hotkey.setObjectName("key_6_hotkey")
        self.key_6_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_6_combobox.setGeometry(QtCore.QRect(190, 200, 161, 21))
        self.key_6_combobox.setObjectName("key_6_combobox")
        self.key_6_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_6_string.setEnabled(True)
        self.key_6_string.setGeometry(QtCore.QRect(190, 200, 291, 21))
        self.key_6_string.setObjectName("key_6_string")
        self.key_7_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_physicalkeys)
        self.key_7_hotkey.setEnabled(True)
        self.key_7_hotkey.setGeometry(QtCore.QRect(190, 230, 161, 21))
        self.key_7_hotkey.setObjectName("key_7_hotkey")
        self.key_7_combobox = QtWidgets.QComboBox(self.macroTab_physicalkeys)
        self.key_7_combobox.setGeometry(QtCore.QRect(190, 230, 161, 21))
        self.key_7_combobox.setObjectName("key_7_combobox")
        self.key_7_string = QtWidgets.QLineEdit(self.macroTab_physicalkeys)
        self.key_7_string.setEnabled(True)
        self.key_7_string.setGeometry(QtCore.QRect(190, 230, 291, 21))
        self.key_7_string.setObjectName("key_7_string")
        self.macroTabs.addTab(self.macroTab_physicalkeys, "")
        self.macroTab_joystick = QtWidgets.QWidget()
        self.macroTab_joystick.setObjectName("macroTab_joystick")
        self.xAxis_neg_label = QtWidgets.QLabel(self.macroTab_joystick)
        self.xAxis_neg_label.setGeometry(QtCore.QRect(20, 50, 71, 21))
        self.xAxis_neg_label.setObjectName("xAxis_neg_label")
        self.xAxis_pos_label = QtWidgets.QLabel(self.macroTab_joystick)
        self.xAxis_pos_label.setGeometry(QtCore.QRect(20, 20, 71, 21))
        self.xAxis_pos_label.setObjectName("xAxis_pos_label")
        self.xAxis_neg = QtWidgets.QComboBox(self.macroTab_joystick)
        self.xAxis_neg.setGeometry(QtCore.QRect(100, 50, 121, 22))
        self.xAxis_neg.setObjectName("xAxis_neg")
        self.xAxis_neg.addItem("")
        self.xAxis_neg.addItem("")
        self.xAxis_neg.addItem("")
        self.xAxis_neg.addItem("")
        self.xAxis_neg.addItem("")
        self.xAxis_neg.addItem("")
        self.xAxis_pos = QtWidgets.QComboBox(self.macroTab_joystick)
        self.xAxis_pos.setGeometry(QtCore.QRect(100, 20, 121, 22))
        self.xAxis_pos.setObjectName("xAxis_pos")
        self.xAxis_pos.addItem("")
        self.xAxis_pos.addItem("")
        self.xAxis_pos.addItem("")
        self.xAxis_pos.addItem("")
        self.xAxis_pos.addItem("")
        self.xAxis_pos.addItem("")
        self.yAxis_pos = QtWidgets.QComboBox(self.macroTab_joystick)
        self.yAxis_pos.setGeometry(QtCore.QRect(100, 80, 121, 22))
        self.yAxis_pos.setObjectName("yAxis_pos")
        self.yAxis_pos.addItem("")
        self.yAxis_pos.addItem("")
        self.yAxis_pos.addItem("")
        self.yAxis_pos.addItem("")
        self.yAxis_pos.addItem("")
        self.yAxis_pos.addItem("")
        self.yAxis_pos_label = QtWidgets.QLabel(self.macroTab_joystick)
        self.yAxis_pos_label.setGeometry(QtCore.QRect(20, 80, 71, 21))
        self.yAxis_pos_label.setObjectName("yAxis_pos_label")
        self.yAxis_neg = QtWidgets.QComboBox(self.macroTab_joystick)
        self.yAxis_neg.setGeometry(QtCore.QRect(100, 110, 121, 22))
        self.yAxis_neg.setObjectName("yAxis_neg")
        self.yAxis_neg.addItem("")
        self.yAxis_neg.addItem("")
        self.yAxis_neg.addItem("")
        self.yAxis_neg.addItem("")
        self.yAxis_neg.addItem("")
        self.yAxis_neg.addItem("")
        self.yAxis_neg_label = QtWidgets.QLabel(self.macroTab_joystick)
        self.yAxis_neg_label.setGeometry(QtCore.QRect(20, 110, 71, 21))
        self.yAxis_neg_label.setObjectName("yAxis_neg_label")
        self.joystick_button = QtWidgets.QComboBox(self.macroTab_joystick)
        self.joystick_button.setGeometry(QtCore.QRect(100, 140, 121, 22))
        self.joystick_button.setObjectName("joystick_button")
        self.joystick_button.addItem("")
        self.joystick_button.addItem("")
        self.joystick_button.addItem("")
        self.joystick_button.addItem("")
        self.joystick_button.addItem("")
        self.joystick_button.addItem("")
        self.joystick_button_label = QtWidgets.QLabel(self.macroTab_joystick)
        self.joystick_button_label.setGeometry(QtCore.QRect(20, 140, 71, 21))
        self.joystick_button_label.setObjectName("joystick_button_label")
        self.xAxis_pos_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_joystick)
        self.xAxis_pos_hotkey.setEnabled(True)
        self.xAxis_pos_hotkey.setGeometry(QtCore.QRect(230, 20, 161, 21))
        self.xAxis_pos_hotkey.setObjectName("xAxis_pos_hotkey")
        self.xAxis_pos_combobox = QtWidgets.QComboBox(self.macroTab_joystick)
        self.xAxis_pos_combobox.setGeometry(QtCore.QRect(230, 20, 161, 21))
        self.xAxis_pos_combobox.setObjectName("xAxis_pos_combobox")
        self.xAxis_pos_string = QtWidgets.QLineEdit(self.macroTab_joystick)
        self.xAxis_pos_string.setEnabled(True)
        self.xAxis_pos_string.setGeometry(QtCore.QRect(230, 20, 251, 21))
        self.xAxis_pos_string.setObjectName("xAxis_pos_string")
        self.xAxis_neg_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_joystick)
        self.xAxis_neg_hotkey.setEnabled(True)
        self.xAxis_neg_hotkey.setGeometry(QtCore.QRect(230, 50, 161, 21))
        self.xAxis_neg_hotkey.setObjectName("xAxis_neg_hotkey")
        self.xAxis_neg_combobox = QtWidgets.QComboBox(self.macroTab_joystick)
        self.xAxis_neg_combobox.setGeometry(QtCore.QRect(230, 50, 161, 21))
        self.xAxis_neg_combobox.setObjectName("xAxis_neg_combobox")
        self.xAxis_neg_string = QtWidgets.QLineEdit(self.macroTab_joystick)
        self.xAxis_neg_string.setEnabled(True)
        self.xAxis_neg_string.setGeometry(QtCore.QRect(230, 50, 251, 21))
        self.xAxis_neg_string.setObjectName("xAxis_neg_string")
        self.yAxis_pos_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_joystick)
        self.yAxis_pos_hotkey.setEnabled(True)
        self.yAxis_pos_hotkey.setGeometry(QtCore.QRect(230, 80, 161, 21))
        self.yAxis_pos_hotkey.setObjectName("yAxis_pos_hotkey")
        self.yAxis_pos_combobox = QtWidgets.QComboBox(self.macroTab_joystick)
        self.yAxis_pos_combobox.setGeometry(QtCore.QRect(230, 80, 161, 21))
        self.yAxis_pos_combobox.setObjectName("yAxis_pos_combobox")
        self.yAxis_pos_string = QtWidgets.QLineEdit(self.macroTab_joystick)
        self.yAxis_pos_string.setEnabled(True)
        self.yAxis_pos_string.setGeometry(QtCore.QRect(230, 80, 251, 21))
        self.yAxis_pos_string.setObjectName("yAxis_pos_string")
        self.yAxis_neg_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_joystick)
        self.yAxis_neg_hotkey.setEnabled(True)
        self.yAxis_neg_hotkey.setGeometry(QtCore.QRect(230, 110, 161, 21))
        self.yAxis_neg_hotkey.setObjectName("yAxis_neg_hotkey")
        self.yAxis_neg_combobox = QtWidgets.QComboBox(self.macroTab_joystick)
        self.yAxis_neg_combobox.setGeometry(QtCore.QRect(230, 110, 161, 21))
        self.yAxis_neg_combobox.setObjectName("yAxis_neg_combobox")
        self.yAxis_neg_string = QtWidgets.QLineEdit(self.macroTab_joystick)
        self.yAxis_neg_string.setEnabled(True)
        self.yAxis_neg_string.setGeometry(QtCore.QRect(230, 110, 251, 21))
        self.yAxis_neg_string.setObjectName("yAxis_neg_string")
        self.joystick_button_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_joystick)
        self.joystick_button_hotkey.setEnabled(True)
        self.joystick_button_hotkey.setGeometry(QtCore.QRect(230, 140, 161, 21))
        self.joystick_button_hotkey.setObjectName("joystick_button_hotkey")
        self.joystick_button_combobox = QtWidgets.QComboBox(self.macroTab_joystick)
        self.joystick_button_combobox.setGeometry(QtCore.QRect(230, 140, 161, 21))
        self.joystick_button_combobox.setObjectName("joystick_button_combobox")
        self.joystick_button_string = QtWidgets.QLineEdit(self.macroTab_joystick)
        self.joystick_button_string.setEnabled(True)
        self.joystick_button_string.setGeometry(QtCore.QRect(230, 140, 251, 21))
        self.joystick_button_string.setObjectName("joystick_button_string")
        self.macroTabs.addTab(self.macroTab_joystick, "")
        self.macroTab_encoder = QtWidgets.QWidget()
        self.macroTab_encoder.setObjectName("macroTab_encoder")
        self.encoder_increment_label = QtWidgets.QLabel(self.macroTab_encoder)
        self.encoder_increment_label.setGeometry(QtCore.QRect(20, 20, 151, 21))
        self.encoder_increment_label.setObjectName("encoder_increment_label")
        self.encoder_decrement_label = QtWidgets.QLabel(self.macroTab_encoder)
        self.encoder_decrement_label.setGeometry(QtCore.QRect(20, 90, 211, 21))
        self.encoder_decrement_label.setObjectName("encoder_decrement_label")
        self.encoder_increment = QtWidgets.QComboBox(self.macroTab_encoder)
        self.encoder_increment.setGeometry(QtCore.QRect(20, 50, 121, 22))
        self.encoder_increment.setObjectName("encoder_increment")
        self.encoder_increment.addItem("")
        self.encoder_increment.addItem("")
        self.encoder_increment.addItem("")
        self.encoder_increment.addItem("")
        self.encoder_increment.addItem("")
        self.encoder_increment.addItem("")
        self.encoder_decrement = QtWidgets.QComboBox(self.macroTab_encoder)
        self.encoder_decrement.setGeometry(QtCore.QRect(20, 120, 121, 22))
        self.encoder_decrement.setObjectName("encoder_decrement")
        self.encoder_decrement.addItem("")
        self.encoder_decrement.addItem("")
        self.encoder_decrement.addItem("")
        self.encoder_decrement.addItem("")
        self.encoder_decrement.addItem("")
        self.encoder_decrement.addItem("")
        self.encoder_button_label = QtWidgets.QLabel(self.macroTab_encoder)
        self.encoder_button_label.setGeometry(QtCore.QRect(20, 160, 41, 21))
        self.encoder_button_label.setObjectName("encoder_button_label")
        self.encoder_button = QtWidgets.QComboBox(self.macroTab_encoder)
        self.encoder_button.setGeometry(QtCore.QRect(20, 190, 121, 22))
        self.encoder_button.setObjectName("encoder_button")
        self.encoder_button.addItem("")
        self.encoder_button.addItem("")
        self.encoder_button.addItem("")
        self.encoder_button.addItem("")
        self.encoder_button.addItem("")
        self.encoder_button.addItem("")
        self.encoder_increment_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_encoder)
        self.encoder_increment_hotkey.setEnabled(True)
        self.encoder_increment_hotkey.setGeometry(QtCore.QRect(150, 50, 161, 21))
        self.encoder_increment_hotkey.setObjectName("encoder_increment_hotkey")
        self.encoder_increment_combobox = QtWidgets.QComboBox(self.macroTab_encoder)
        self.encoder_increment_combobox.setGeometry(QtCore.QRect(150, 50, 161, 21))
        self.encoder_increment_combobox.setObjectName("encoder_increment_combobox")
        self.encoder_increment_string = QtWidgets.QLineEdit(self.macroTab_encoder)
        self.encoder_increment_string.setEnabled(True)
        self.encoder_increment_string.setGeometry(QtCore.QRect(150, 50, 291, 21))
        self.encoder_increment_string.setObjectName("encoder_increment_string")
        self.encoder_decrement_string = QtWidgets.QLineEdit(self.macroTab_encoder)
        self.encoder_decrement_string.setEnabled(True)
        self.encoder_decrement_string.setGeometry(QtCore.QRect(150, 120, 291, 21))
        self.encoder_decrement_string.setObjectName("encoder_decrement_string")
        self.encoder_decrement_combobox = QtWidgets.QComboBox(self.macroTab_encoder)
        self.encoder_decrement_combobox.setGeometry(QtCore.QRect(150, 120, 161, 21))
        self.encoder_decrement_combobox.setObjectName("encoder_decrement_combobox")
        self.encoder_decrement_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_encoder)
        self.encoder_decrement_hotkey.setEnabled(True)
        self.encoder_decrement_hotkey.setGeometry(QtCore.QRect(150, 120, 161, 21))
        self.encoder_decrement_hotkey.setObjectName("encoder_decrement_hotkey")
        self.encoder_button_hotkey = QtWidgets.QKeySequenceEdit(self.macroTab_encoder)
        self.encoder_button_hotkey.setEnabled(True)
        self.encoder_button_hotkey.setGeometry(QtCore.QRect(150, 190, 161, 21))
        self.encoder_button_hotkey.setObjectName("encoder_button_hotkey")
        self.encoder_button_combobox = QtWidgets.QComboBox(self.macroTab_encoder)
        self.encoder_button_combobox.setGeometry(QtCore.QRect(150, 190, 161, 21))
        self.encoder_button_combobox.setObjectName("encoder_button_combobox")
        self.encoder_button_string = QtWidgets.QLineEdit(self.macroTab_encoder)
        self.encoder_button_string.setEnabled(True)
        self.encoder_button_string.setGeometry(QtCore.QRect(150, 190, 291, 21))
        self.encoder_button_string.setObjectName("encoder_button_string")
        self.macroTabs.addTab(self.macroTab_encoder, "")
        self.referenceGroupBox = QtWidgets.QGroupBox(self.widget)
        self.referenceGroupBox.setGeometry(QtCore.QRect(530, 0, 301, 531))
        self.referenceGroupBox.setObjectName("referenceGroupBox")
        self.reference_image_pixmap = QtGui.QPixmap("images/slate_config_ref_screenkeys.png")
        self.reference_image = QtWidgets.QLabel(self.referenceGroupBox)
        self.reference_image.setObjectName("reference_image")
        self.reference_image.setPixmap(self.reference_image_pixmap)
        self.reference_image.resize(301,531)
        self.reference_image.setAlignment(QtCore.Qt.AlignCenter)
        self.apply_config_button = QtWidgets.QPushButton(self.widget)
        self.apply_config_button.setGeometry(QtCore.QRect(580, 540, 201, 29))
        self.apply_config_button.setObjectName("apply_config_button")
        self.apply_config_button.clicked.connect(self.applyToSlate)
        self.verticalLayout.addWidget(self.widget)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.layer_select_label.setBuddy(self.layer_select)
        self.row_select_label.setBuddy(self.row_select)
        self.column_select_label.setBuddy(self.column_select)
        self.key_0_label.setBuddy(self.key_0)
        self.key_1_label.setBuddy(self.key_1)
        self.key_2_label.setBuddy(self.key_2)
        self.key_3_label.setBuddy(self.key_3)
        self.key_4_label.setBuddy(self.key_4)
        self.key_5_label.setBuddy(self.key_5)
        self.key_6_label.setBuddy(self.key_6)
        self.key_7_label.setBuddy(self.key_7)
        self.encoder_increment_label.setBuddy(self.encoder_increment)
        self.encoder_decrement_label.setBuddy(self.encoder_decrement)
        self.encoder_button_label.setBuddy(self.encoder_button)

        self.retranslateUi(MainWindow)
        self.macroTabs.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.create_layer_button, self.key_7_hotkey)
        MainWindow.setTabOrder(self.key_7_hotkey, self.delete_layer_button)
        MainWindow.setTabOrder(self.delete_layer_button, self.macroTabs)
        MainWindow.setTabOrder(self.macroTabs, self.row_select)
        MainWindow.setTabOrder(self.row_select, self.column_select)
        MainWindow.setTabOrder(self.column_select, self.screenkey_0)
        MainWindow.setTabOrder(self.screenkey_0, self.screenkey_1)
        MainWindow.setTabOrder(self.screenkey_1, self.screenkey_2)
        MainWindow.setTabOrder(self.screenkey_2, self.screenkey_3)
        MainWindow.setTabOrder(self.screenkey_3, self.screenkey_4)
        MainWindow.setTabOrder(self.screenkey_4, self.screenkey_5)
        MainWindow.setTabOrder(self.screenkey_5, self.screenkey_6)
        MainWindow.setTabOrder(self.screenkey_6, self.screenkey_7)
        MainWindow.setTabOrder(self.screenkey_7, self.screenkey_8)
        MainWindow.setTabOrder(self.screenkey_8, self.screenkey_9)
        MainWindow.setTabOrder(self.screenkey_9, self.screenkey_10)
        MainWindow.setTabOrder(self.screenkey_10, self.screenkey_11)
        MainWindow.setTabOrder(self.screenkey_11, self.key_0)
        MainWindow.setTabOrder(self.key_0, self.key_1)
        MainWindow.setTabOrder(self.key_1, self.key_2)
        MainWindow.setTabOrder(self.key_2, self.key_3)
        MainWindow.setTabOrder(self.key_3, self.key_4)
        MainWindow.setTabOrder(self.key_4, self.key_5)
        MainWindow.setTabOrder(self.key_5, self.key_6)
        MainWindow.setTabOrder(self.key_6, self.key_7)
        MainWindow.setTabOrder(self.key_7, self.save_config_button)
        MainWindow.setTabOrder(self.save_config_button, self.key_0_hotkey)
        MainWindow.setTabOrder(self.key_0_hotkey, self.key_0_string)
        MainWindow.setTabOrder(self.key_0_string, self.key_1_hotkey)
        MainWindow.setTabOrder(self.key_1_hotkey, self.exit_button)
        MainWindow.setTabOrder(self.exit_button, self.key_2_hotkey)
        MainWindow.setTabOrder(self.key_2_hotkey, self.key_1_string)
        MainWindow.setTabOrder(self.key_1_string, self.key_3_hotkey)
        MainWindow.setTabOrder(self.key_3_hotkey, self.key_2_combobox)
        MainWindow.setTabOrder(self.key_2_combobox, self.key_4_hotkey)
        MainWindow.setTabOrder(self.key_4_hotkey, self.key_1_combobox)
        MainWindow.setTabOrder(self.key_1_combobox, self.key_5_hotkey)
        MainWindow.setTabOrder(self.key_5_hotkey, self.key_3_string)
        MainWindow.setTabOrder(self.key_3_string, self.key_6_hotkey)
        MainWindow.setTabOrder(self.key_6_hotkey, self.key_4_combobox)
        MainWindow.setTabOrder(self.key_4_combobox, self.key_4_string)
        MainWindow.setTabOrder(self.key_4_string, self.key_2_string)
        MainWindow.setTabOrder(self.key_2_string, self.key_5_combobox)
        MainWindow.setTabOrder(self.key_5_combobox, self.layer_select)
        MainWindow.setTabOrder(self.layer_select, self.key_5_string)
        MainWindow.setTabOrder(self.key_5_string, self.key_3_combobox)
        MainWindow.setTabOrder(self.key_3_combobox, self.key_6_combobox)
        MainWindow.setTabOrder(self.key_6_combobox, self.key_6_string)
        MainWindow.setTabOrder(self.key_6_string, self.key_0_combobox)
        MainWindow.setTabOrder(self.key_0_combobox, self.key_7_combobox)
        MainWindow.setTabOrder(self.key_7_combobox, self.key_7_string)
        MainWindow.setTabOrder(self.key_7_string, self.xAxis_neg)
        MainWindow.setTabOrder(self.xAxis_neg, self.xAxis_pos)
        MainWindow.setTabOrder(self.xAxis_pos, self.yAxis_pos)
        MainWindow.setTabOrder(self.yAxis_pos, self.yAxis_neg)
        MainWindow.setTabOrder(self.yAxis_neg, self.joystick_button)
        MainWindow.setTabOrder(self.joystick_button, self.xAxis_pos_hotkey)
        MainWindow.setTabOrder(self.xAxis_pos_hotkey, self.xAxis_pos_combobox)
        MainWindow.setTabOrder(self.xAxis_pos_combobox, self.xAxis_pos_string)
        MainWindow.setTabOrder(self.xAxis_pos_string, self.xAxis_neg_hotkey)
        MainWindow.setTabOrder(self.xAxis_neg_hotkey, self.xAxis_neg_combobox)
        MainWindow.setTabOrder(self.xAxis_neg_combobox, self.xAxis_neg_string)
        MainWindow.setTabOrder(self.xAxis_neg_string, self.yAxis_pos_hotkey)
        MainWindow.setTabOrder(self.yAxis_pos_hotkey, self.yAxis_pos_combobox)
        MainWindow.setTabOrder(self.yAxis_pos_combobox, self.yAxis_pos_string)
        MainWindow.setTabOrder(self.yAxis_pos_string, self.yAxis_neg_hotkey)
        MainWindow.setTabOrder(self.yAxis_neg_hotkey, self.yAxis_neg_combobox)
        MainWindow.setTabOrder(self.yAxis_neg_combobox, self.yAxis_neg_string)
        MainWindow.setTabOrder(self.yAxis_neg_string, self.joystick_button_hotkey)
        MainWindow.setTabOrder(self.joystick_button_hotkey, self.joystick_button_combobox)
        MainWindow.setTabOrder(self.joystick_button_combobox, self.joystick_button_string)
        MainWindow.setTabOrder(self.joystick_button_string, self.encoder_increment)
        MainWindow.setTabOrder(self.encoder_increment, self.encoder_decrement)
        MainWindow.setTabOrder(self.encoder_decrement, self.encoder_button)
        MainWindow.setTabOrder(self.encoder_button, self.encoder_increment_hotkey)
        MainWindow.setTabOrder(self.encoder_increment_hotkey, self.encoder_increment_combobox)
        MainWindow.setTabOrder(self.encoder_increment_combobox, self.encoder_increment_string)
        MainWindow.setTabOrder(self.encoder_increment_string, self.encoder_decrement_string)
        MainWindow.setTabOrder(self.encoder_decrement_string, self.encoder_decrement_combobox)
        MainWindow.setTabOrder(self.encoder_decrement_combobox, self.encoder_decrement_hotkey)
        MainWindow.setTabOrder(self.encoder_decrement_hotkey, self.encoder_button_hotkey)
        MainWindow.setTabOrder(self.encoder_button_hotkey, self.encoder_button_combobox)
        MainWindow.setTabOrder(self.encoder_button_combobox, self.encoder_button_string)
        MainWindow.setTabOrder(self.encoder_button_string, self.apply_config_button)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Slate Configurator"))
        self.exit_button.setText(_translate("MainWindow", "Exit"))
        self.save_config_button.setText(_translate("MainWindow", "Save Config as File"))
        self.layerGroupBox.setTitle(_translate("MainWindow", "Layer"))
        self.delete_layer_button.setText(_translate("MainWindow", "Delete"))
        self.create_layer_button.setText(_translate("MainWindow", "+ Create layer"))
        self.layer_select_label.setText(_translate("MainWindow", "Select:"))
        self.rename_layer_button.setText(_translate("MainWindow", "Rename"))
        self.macroGroupBox.setTitle(_translate("MainWindow", "Macros"))
        self.row_select_label.setText(_translate("MainWindow", "Rows"))
        self.column_select_label.setText(_translate("MainWindow", "Columns"))
        self.row_select.setToolTip(_translate("MainWindow", "Currently only supports 3 rows"))
        self.column_select.setToolTip(_translate("MainWindow", "Currently only supports 4 columns"))
        self.max_row_label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" color:#7f7f7f;\">(max 3)</span></p></body></html>"))
        self.max_column_label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" color:#7f7f7f;\">(max 4)</span></p></body></html>"))
        self.screenkey_0_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_1_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_2_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_3_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_4_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_5_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_6_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_7_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_8_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_9_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_10_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.screenkey_11_label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\">Label</p></body></html>"))
        self.macroTabs.setTabText(self.macroTabs.indexOf(self.macroTab_screenkeys), _translate("MainWindow", "On-Screen Keys"))
        self.key_0_label.setText(_translate("MainWindow", "Key 1"))
        self.key_0.setItemText(0, _translate("MainWindow", "None"))
        self.key_0.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_0.setItemText(2, _translate("MainWindow", "String"))
        self.key_0.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_0.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_0.setItemText(5, _translate("MainWindow", "Mouse"))
        self.key_1_label.setText(_translate("MainWindow", "Key 2"))
        self.key_2_label.setText(_translate("MainWindow", "Key 3"))
        self.key_3_label.setText(_translate("MainWindow", "Key 4"))
        self.key_4_label.setText(_translate("MainWindow", "Key 5"))
        self.key_5_label.setText(_translate("MainWindow", "Key 6"))
        self.key_6_label.setText(_translate("MainWindow", "Key 7"))
        self.key_7_label.setText(_translate("MainWindow", "Key 8"))
        self.key_1.setItemText(0, _translate("MainWindow", "None"))
        self.key_1.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_1.setItemText(2, _translate("MainWindow", "String"))
        self.key_1.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_1.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_1.setItemText(5, _translate("MainWindow", "Mouse"))
        self.key_3.setItemText(0, _translate("MainWindow", "None"))
        self.key_3.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_3.setItemText(2, _translate("MainWindow", "String"))
        self.key_3.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_3.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_3.setItemText(5, _translate("MainWindow", "Mouse"))
        self.key_2.setItemText(0, _translate("MainWindow", "None"))
        self.key_2.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_2.setItemText(2, _translate("MainWindow", "String"))
        self.key_2.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_2.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_2.setItemText(5, _translate("MainWindow", "Mouse"))
        self.key_5.setItemText(0, _translate("MainWindow", "None"))
        self.key_5.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_5.setItemText(2, _translate("MainWindow", "String"))
        self.key_5.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_5.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_5.setItemText(5, _translate("MainWindow", "Mouse"))
        self.key_4.setItemText(0, _translate("MainWindow", "None"))
        self.key_4.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_4.setItemText(2, _translate("MainWindow", "String"))
        self.key_4.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_4.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_4.setItemText(5, _translate("MainWindow", "Mouse"))
        self.key_7.setItemText(0, _translate("MainWindow", "None"))
        self.key_7.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_7.setItemText(2, _translate("MainWindow", "String"))
        self.key_7.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_7.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_7.setItemText(5, _translate("MainWindow", "Mouse"))
        self.key_6.setItemText(0, _translate("MainWindow", "None"))
        self.key_6.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.key_6.setItemText(2, _translate("MainWindow", "String"))
        self.key_6.setItemText(3, _translate("MainWindow", "Media Control"))
        self.key_6.setItemText(4, _translate("MainWindow", "Windows"))
        self.key_6.setItemText(5, _translate("MainWindow", "Mouse"))
        self.macroTabs.setTabText(self.macroTabs.indexOf(self.macroTab_physicalkeys), _translate("MainWindow", "Physical Keys"))
        self.xAxis_neg_label.setText(_translate("MainWindow", "X-Axis (-)"))
        self.xAxis_pos_label.setText(_translate("MainWindow", "X-Axis (+)"))
        self.xAxis_neg.setItemText(0, _translate("MainWindow", "None"))
        self.xAxis_neg.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.xAxis_neg.setItemText(2, _translate("MainWindow", "String"))
        self.xAxis_neg.setItemText(3, _translate("MainWindow", "Media Control"))
        self.xAxis_neg.setItemText(4, _translate("MainWindow", "Windows"))
        self.xAxis_neg.setItemText(5, _translate("MainWindow", "Mouse"))
        self.xAxis_pos.setItemText(0, _translate("MainWindow", "None"))
        self.xAxis_pos.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.xAxis_pos.setItemText(2, _translate("MainWindow", "String"))
        self.xAxis_pos.setItemText(3, _translate("MainWindow", "Media Control"))
        self.xAxis_pos.setItemText(4, _translate("MainWindow", "Windows"))
        self.xAxis_pos.setItemText(5, _translate("MainWindow", "Mouse"))
        self.yAxis_pos.setItemText(0, _translate("MainWindow", "None"))
        self.yAxis_pos.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.yAxis_pos.setItemText(2, _translate("MainWindow", "String"))
        self.yAxis_pos.setItemText(3, _translate("MainWindow", "Media Control"))
        self.yAxis_pos.setItemText(4, _translate("MainWindow", "Windows"))
        self.yAxis_pos.setItemText(5, _translate("MainWindow", "Mouse"))
        self.yAxis_pos_label.setText(_translate("MainWindow", "Y-Axis (+)"))
        self.yAxis_neg.setItemText(0, _translate("MainWindow", "None"))
        self.yAxis_neg.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.yAxis_neg.setItemText(2, _translate("MainWindow", "String"))
        self.yAxis_neg.setItemText(3, _translate("MainWindow", "Media Control"))
        self.yAxis_neg.setItemText(4, _translate("MainWindow", "Windows"))
        self.yAxis_neg.setItemText(5, _translate("MainWindow", "Mouse"))
        self.yAxis_neg_label.setText(_translate("MainWindow", "Y-Axis (-)"))
        self.joystick_button.setItemText(0, _translate("MainWindow", "None"))
        self.joystick_button.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.joystick_button.setItemText(2, _translate("MainWindow", "String"))
        self.joystick_button.setItemText(3, _translate("MainWindow", "Media Control"))
        self.joystick_button.setItemText(4, _translate("MainWindow", "Windows"))
        self.joystick_button.setItemText(5, _translate("MainWindow", "Mouse"))
        self.joystick_button_label.setText(_translate("MainWindow", "Button"))
        self.macroTabs.setTabText(self.macroTabs.indexOf(self.macroTab_joystick), _translate("MainWindow", "Joystick"))
        self.encoder_increment_label.setText(_translate("MainWindow", "Clockwise (Increment, +)"))
        self.encoder_decrement_label.setText(_translate("MainWindow", "Counter-Clockwise (Decrement, -)"))
        self.encoder_increment.setItemText(0, _translate("MainWindow", "None"))
        self.encoder_increment.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.encoder_increment.setItemText(2, _translate("MainWindow", "String"))
        self.encoder_increment.setItemText(3, _translate("MainWindow", "Media Control"))
        self.encoder_increment.setItemText(4, _translate("MainWindow", "Windows"))
        self.encoder_increment.setItemText(5, _translate("MainWindow", "Mouse"))
        self.encoder_decrement.setItemText(0, _translate("MainWindow", "None"))
        self.encoder_decrement.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.encoder_decrement.setItemText(2, _translate("MainWindow", "String"))
        self.encoder_decrement.setItemText(3, _translate("MainWindow", "Media Control"))
        self.encoder_decrement.setItemText(4, _translate("MainWindow", "Windows"))
        self.encoder_decrement.setItemText(5, _translate("MainWindow", "Mouse"))
        self.encoder_button_label.setText(_translate("MainWindow", "Button"))
        self.encoder_button.setItemText(0, _translate("MainWindow", "None"))
        self.encoder_button.setItemText(1, _translate("MainWindow", "Hotkey"))
        self.encoder_button.setItemText(2, _translate("MainWindow", "String"))
        self.encoder_button.setItemText(3, _translate("MainWindow", "Media Control"))
        self.encoder_button.setItemText(4, _translate("MainWindow", "Windows"))
        self.encoder_button.setItemText(5, _translate("MainWindow", "Mouse"))
        self.macroTabs.setTabText(self.macroTabs.indexOf(self.macroTab_encoder), _translate("MainWindow", "Rotary Encoder"))
        self.referenceGroupBox.setTitle(_translate("MainWindow", "Reference"))
        self.reference_image.setText(_translate("MainWindow", ""))
        self.apply_config_button.setText(_translate("MainWindow", "Apply to Slate"))

    def hide_inputs(self, MainWindow):
        # By default macros are set to None, so hide inputs for them
        self.key_0_hotkey.setVisible(False)
        self.key_0_string.setVisible(False)
        self.key_0_combobox.setVisible(False)
        self.key_1_hotkey.setVisible(False)
        self.key_1_string.setVisible(False)
        self.key_1_combobox.setVisible(False)
        self.key_2_hotkey.setVisible(False)
        self.key_2_string.setVisible(False)
        self.key_2_combobox.setVisible(False)
        self.key_3_hotkey.setVisible(False)
        self.key_3_string.setVisible(False)
        self.key_3_combobox.setVisible(False)
        self.key_4_hotkey.setVisible(False)
        self.key_4_string.setVisible(False)
        self.key_4_combobox.setVisible(False)
        self.key_5_hotkey.setVisible(False)
        self.key_5_string.setVisible(False)
        self.key_5_combobox.setVisible(False)
        self.key_6_hotkey.setVisible(False)
        self.key_6_string.setVisible(False)
        self.key_6_combobox.setVisible(False)
        self.key_7_hotkey.setVisible(False)
        self.key_7_string.setVisible(False)
        self.key_7_combobox.setVisible(False)
        self.xAxis_pos_hotkey.setVisible(False)
        self.xAxis_pos_string.setVisible(False)
        self.xAxis_pos_combobox.setVisible(False)
        self.xAxis_neg_hotkey.setVisible(False)
        self.xAxis_neg_string.setVisible(False)
        self.xAxis_neg_combobox.setVisible(False)
        self.yAxis_pos_hotkey.setVisible(False)
        self.yAxis_pos_string.setVisible(False)
        self.yAxis_pos_combobox.setVisible(False)
        self.yAxis_neg_hotkey.setVisible(False)
        self.yAxis_neg_string.setVisible(False)
        self.yAxis_neg_combobox.setVisible(False)
        self.joystick_button_hotkey.setVisible(False)
        self.joystick_button_string.setVisible(False)
        self.joystick_button_combobox.setVisible(False)
        self.encoder_increment_hotkey.setVisible(False)
        self.encoder_increment_string.setVisible(False)
        self.encoder_increment_combobox.setVisible(False)
        self.encoder_decrement_hotkey.setVisible(False)
        self.encoder_decrement_string.setVisible(False)
        self.encoder_decrement_combobox.setVisible(False)
        self.encoder_button_hotkey.setVisible(False)
        self.encoder_button_string.setVisible(False)
        self.encoder_button_combobox.setVisible(False)
        ui_screenkey.screenkey_hotkey.setVisible(False)
        ui_screenkey.screenkey_string.setVisible(False)
        ui_screenkey.screenkey_combobox.setVisible(False)

    def getInputMacroTypeIndex(self, layer, input_type, number):
        if input_type == "touch_shortcuts":
            macroType = layer[input_type][number]["actions"][0]
        if input_type == "key_shortcuts":
            macroType = layer[input_type][number]["actions"][0]
        if input_type == "encoder":
            if number == 0:
                macroType = layer[input_type]["increment"][0]
            if number == 1:
                macroType = layer[input_type]["decrement"][0]
            if number == 2:
                macroType = layer[input_type]["button"][0]
        if input_type == "joystick":
            if number == 0:
                macroType = layer[input_type]["x+"][0]
            if number == 1:
                macroType = layer[input_type]["x-"][0]
            if number == 2:
                macroType = layer[input_type]["y+"][0]
            if number == 3:
                macroType = layer[input_type]["y-"][0]
            if number == 4:
                macroType = layer[input_type]["button"][0]
        if macroType == None:
            return 0
        if macroType == KEY:
            return 1
        if macroType == STRING:
            return 2
        if macroType == MEDIA:
            return 3
        if macroType == MOUSE_CLICK or MOUSE_MOVE:
            return 5
                
    def getScreenKeyLabel(self, layer, number):
        return layer["touch_shortcuts"][number]["label"]

    def changePreviewImage(self, index):
        if index == 0:
            new_image = QtGui.QPixmap("images/slate_config_ref_screenkeys.png")
            self.reference_image.setPixmap(new_image)
        if index == 1:
            new_image = QtGui.QPixmap("images/slate_config_ref_keys.png")
            self.reference_image.setPixmap(new_image)
        if index == 2:
            new_image = QtGui.QPixmap("images/slate_config_ref_joystick.png")
            self.reference_image.setPixmap(new_image)
        if index == 3:
            new_image = QtGui.QPixmap("images/slate_config_ref_encoder.png")
            self.reference_image.setPixmap(new_image)

    def showInputForm(self, prefix, macro_type_index):
        if macro_type_index == 0:
            getattr(self, '%s_hotkey' % prefix).setVisible(False)
            getattr(self, '%s_hotkey' % prefix).clear()
            getattr(self, '%s_string' % prefix).setVisible(False)
            getattr(self, '%s_string' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).setVisible(False)
            getattr(self, '%s_combobox' % prefix).clear()
        if macro_type_index == 1:
            getattr(self, '%s_hotkey' % prefix).setVisible(True)
            getattr(self, '%s_hotkey' % prefix).clear()
            getattr(self, '%s_string' % prefix).setVisible(False)
            getattr(self, '%s_string' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).setVisible(False)
            getattr(self, '%s_combobox' % prefix).clear()
        if macro_type_index == 2:
            getattr(self, '%s_hotkey' % prefix).setVisible(False)
            getattr(self, '%s_hotkey' % prefix).clear()
            getattr(self, '%s_string' % prefix).setVisible(True)
            getattr(self, '%s_string' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).setVisible(False)
            getattr(self, '%s_combobox' % prefix).clear()
        if macro_type_index == 3:
            getattr(self, '%s_hotkey' % prefix).setVisible(False)
            getattr(self, '%s_hotkey' % prefix).clear()
            getattr(self, '%s_string' % prefix).setVisible(False)
            getattr(self, '%s_string' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).setVisible(True)
            getattr(self, '%s_combobox' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).addItems(COMBOBOX_MEDIA)
        if macro_type_index == 4:
            getattr(self, '%s_hotkey' % prefix).setVisible(False)
            getattr(self, '%s_hotkey' % prefix).clear()
            getattr(self, '%s_string' % prefix).setVisible(False)
            getattr(self, '%s_string' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).setVisible(True)
            getattr(self, '%s_combobox' % prefix).clear()
        if macro_type_index == 5:
            getattr(self, '%s_hotkey' % prefix).setVisible(False)
            getattr(self, '%s_hotkey' % prefix).clear()
            getattr(self, '%s_string' % prefix).setVisible(False)
            getattr(self, '%s_string' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).setVisible(True)
            getattr(self, '%s_combobox' % prefix).clear()
            getattr(self, '%s_combobox' % prefix).addItems(COMBOBOX_MOUSE)
        
    def fillInputForm(self, layer, prefix, macro_type_index):
        # Get actions for input
        if prefix == "screenkey":
            actions = slate_config["layers"][ui.layer_select.currentIndex()]["touch_shortcuts"][layer]["actions"]
        elif prefix == "key_0":
            actions = layer["key_shortcuts"][0]["actions"]
        elif prefix == "key_1":
            actions = layer["key_shortcuts"][1]["actions"]
        elif prefix == "key_2":
            actions = layer["key_shortcuts"][2]["actions"]
        elif prefix == "key_3":
            actions = layer["key_shortcuts"][3]["actions"]
        elif prefix == "key_4":
            actions = layer["key_shortcuts"][4]["actions"]
        elif prefix == "key_5":
            actions = layer["key_shortcuts"][5]["actions"]
        elif prefix == "key_6":
            actions = layer["key_shortcuts"][6]["actions"]
        elif prefix == "key_7":
            actions = layer["key_shortcuts"][7]["actions"]
        elif prefix == "xAxis_pos":
            actions = layer["joystick"]["x+"]
        elif prefix == "xAxis_neg":
            actions = layer["joystick"]["x-"]
        elif prefix == "yAxis_pos":
            actions = layer["joystick"]["y+"]
        elif prefix == "yAxis_neg":
            actions = layer["joystick"]["y-"]
        elif prefix == "joystick_button":
            actions = layer["joystick"]["button"]
        elif prefix == "encoder_increment":
            actions = layer["encoder"]["increment"]
        elif prefix == "encoder_decrement":
            actions = layer["encoder"]["decrement"]
        elif prefix == "encoder_button":
            actions = layer["encoder"]["button"]

        # Fill input form
        if macro_type_index == 0:
            pass
        if macro_type_index == 1:
            getattr(self, "%s_hotkey" % prefix).setKeySequence(self.constructKeySequence(actions[1]))
        if macro_type_index == 2:
            getattr(self, "%s_string" % prefix).setText(actions[1])
        if macro_type_index == 3:
            if actions[1] == ConsumerControlCode.VOLUME_INCREMENT:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(0)
            if actions[1] == ConsumerControlCode.VOLUME_DECREMENT:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(1)
            if actions[1] == ConsumerControlCode.MUTE:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(2)
            if actions[1] == ConsumerControlCode.PLAY_PAUSE:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(3)
            if actions[1] == ConsumerControlCode.STOP:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(4)
            if actions[1] == ConsumerControlCode.REWIND:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(5)
            if actions[1] == ConsumerControlCode.FAST_FORWARD:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(6)
            if actions[1] == ConsumerControlCode.RECORD:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(7)
            if actions[1] == ConsumerControlCode.SCAN_NEXT_TRACK:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(8)
            if actions[1] == ConsumerControlCode.SCAN_PREVIOUS_TRACK:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(9)
            if actions[1] == ConsumerControlCode.EJECT:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(10)
            if actions[1] == ConsumerControlCode.BRIGHTNESS_INCREMENT:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(11)
            if actions[1] == ConsumerControlCode.BRIGHTNESS_DECREMENT:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(12)
        if macro_type_index == 4:
            pass
        if macro_type_index == 5:
            if actions[1] == [0, 100, 0]:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(0)
            if actions[1] == [0, -100, 0]:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(1)
            if actions[1] == [-100, 0, 0]:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(2)
            if actions[1] == [100, 0, 0]:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(3)
            if actions[1] == LEFT_BUTTON:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(4)
            if actions[1] == RIGHT_BUTTON:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(5)
            if actions[1] == MIDDLE_BUTTON:
                getattr(self, "%s_combobox" % prefix).setCurrentIndex(6)

            
            

    def fillFromLayer(self, index):
        # Cache existing input data for previous layer first
        # (except screenkeys which are already dynamically cached)
        if self.prevLayerIndex != -1:
            print("Saving cached data from layer " + str(self.prevLayerIndex) + "...")
            # Save cached data for physical keys
            layer = slate_config["layers"][self.prevLayerIndex]
            layer["key_shortcuts"][0]["actions"] = self.writeActions("key_0", self.key_0.currentIndex())
            layer["key_shortcuts"][1]["actions"] = self.writeActions("key_1", self.key_1.currentIndex())
            layer["key_shortcuts"][2]["actions"] = self.writeActions("key_2", self.key_2.currentIndex())
            layer["key_shortcuts"][3]["actions"] = self.writeActions("key_3", self.key_3.currentIndex())
            layer["key_shortcuts"][4]["actions"] = self.writeActions("key_4", self.key_4.currentIndex())
            layer["key_shortcuts"][5]["actions"] = self.writeActions("key_5", self.key_5.currentIndex())
            layer["key_shortcuts"][6]["actions"] = self.writeActions("key_6", self.key_6.currentIndex())
            layer["key_shortcuts"][7]["actions"] = self.writeActions("key_7", self.key_7.currentIndex())
            # Save cached data for joystick
            layer["joystick"]["x+"] = self.writeActions("xAxis_pos", self.xAxis_pos.currentIndex())
            layer["joystick"]["x-"] = self.writeActions("xAxis_neg", self.xAxis_neg.currentIndex())
            layer["joystick"]["y+"] = self.writeActions("yAxis_pos", self.yAxis_pos.currentIndex())
            layer["joystick"]["y-"] = self.writeActions("yAxis_neg", self.yAxis_neg.currentIndex())
            layer["joystick"]["button"] = self.writeActions("joystick_button", self.joystick_button.currentIndex())
            # Save cached data for encoder
            layer["encoder"]["increment"] = self.writeActions("encoder_increment", self.encoder_increment.currentIndex())
            layer["encoder"]["decrement"] = self.writeActions("encoder_decrement", self.encoder_decrement.currentIndex())
            layer["encoder"]["button"] = self.writeActions("encoder_button", self.encoder_button.currentIndex())

        # Get layer from index
        print("Number of layers: " + str(len(slate_config["layers"])))
        layer = slate_config["layers"][index]
        # TODO: Fill screen keys
        self.screenkey_0.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 0))
        self.screenkey_0_label.setText(self.getScreenKeyLabel(layer, 0))
        self.screenkey_1.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 1))
        self.screenkey_1_label.setText(self.getScreenKeyLabel(layer, 1))
        self.screenkey_2.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 2))
        self.screenkey_2_label.setText(self.getScreenKeyLabel(layer, 2))
        self.screenkey_3.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 3))
        self.screenkey_3_label.setText(self.getScreenKeyLabel(layer, 3))
        self.screenkey_4.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 4))
        self.screenkey_4_label.setText(self.getScreenKeyLabel(layer, 4))
        self.screenkey_5.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 5))
        self.screenkey_5_label.setText(self.getScreenKeyLabel(layer, 5))
        self.screenkey_6.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 6))
        self.screenkey_6_label.setText(self.getScreenKeyLabel(layer, 6))
        self.screenkey_7.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 7))
        self.screenkey_7_label.setText(self.getScreenKeyLabel(layer, 7))
        self.screenkey_8.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 8))
        self.screenkey_8_label.setText(self.getScreenKeyLabel(layer, 8))
        self.screenkey_9.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 9))
        self.screenkey_9_label.setText(self.getScreenKeyLabel(layer, 9))
        self.screenkey_10.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 10))
        self.screenkey_10_label.setText(self.getScreenKeyLabel(layer, 10))
        self.screenkey_11.setIcon(self.generateScreenKeyIcon(slate_config["layers"][self.layer_select.currentIndex()], 11))
        self.screenkey_11_label.setText(self.getScreenKeyLabel(layer, 11))
        # TODO: Fill physical keys
        self.key_0.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 0))
        self.showInputForm("key_0", self.key_0.currentIndex())
        self.fillInputForm(layer, "key_0", self.key_0.currentIndex())
        self.key_1.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 1))
        self.showInputForm("key_1", self.key_1.currentIndex())
        self.fillInputForm(layer, "key_1", self.key_1.currentIndex())
        self.key_2.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 2))
        self.showInputForm("key_2", self.key_2.currentIndex())
        self.fillInputForm(layer, "key_2", self.key_2.currentIndex())
        self.key_3.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 3))
        self.showInputForm("key_3", self.key_3.currentIndex())
        self.fillInputForm(layer, "key_3", self.key_3.currentIndex())
        self.key_4.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 4))
        self.showInputForm("key_4", self.key_4.currentIndex())
        self.fillInputForm(layer, "key_4", self.key_4.currentIndex())
        self.key_5.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 5))
        self.showInputForm("key_5", self.key_5.currentIndex())
        self.fillInputForm(layer, "key_5", self.key_5.currentIndex())
        self.key_6.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 6))
        self.showInputForm("key_6", self.key_6.currentIndex())
        self.fillInputForm(layer, "key_6", self.key_6.currentIndex())
        self.key_7.setCurrentIndex(self.getInputMacroTypeIndex(layer, "key_shortcuts", 7))
        self.showInputForm("key_7", self.key_7.currentIndex())
        self.fillInputForm(layer, "key_7", self.key_7.currentIndex())
        # TODO: Fill joystick
        self.xAxis_pos.setCurrentIndex(self.getInputMacroTypeIndex(layer, "joystick", 0))
        self.showInputForm("xAxis_pos", self.xAxis_pos.currentIndex())
        self.fillInputForm(layer, "xAxis_pos", self.xAxis_pos.currentIndex())
        self.xAxis_neg.setCurrentIndex(self.getInputMacroTypeIndex(layer, "joystick", 1))
        self.showInputForm("xAxis_neg", self.xAxis_neg.currentIndex())
        self.fillInputForm(layer, "xAxis_neg", self.xAxis_neg.currentIndex())
        self.yAxis_pos.setCurrentIndex(self.getInputMacroTypeIndex(layer, "joystick", 2))
        self.showInputForm("yAxis_pos", self.yAxis_pos.currentIndex())
        self.fillInputForm(layer, "yAxis_pos", self.yAxis_pos.currentIndex())
        self.yAxis_neg.setCurrentIndex(self.getInputMacroTypeIndex(layer, "joystick", 3))
        self.showInputForm("yAxis_neg", self.yAxis_neg.currentIndex())
        self.fillInputForm(layer, "yAxis_neg", self.yAxis_neg.currentIndex())
        self.joystick_button.setCurrentIndex(self.getInputMacroTypeIndex(layer, "joystick", 4))
        self.showInputForm("joystick_button", self.joystick_button.currentIndex())
        self.fillInputForm(layer, "joystick_button", self.joystick_button.currentIndex())
        # TODO: Fill encoder
        self.encoder_increment.setCurrentIndex(self.getInputMacroTypeIndex(layer, "encoder", 0))
        self.showInputForm("encoder_increment", self.encoder_increment.currentIndex())
        self.fillInputForm(layer, "encoder_increment", self.encoder_increment.currentIndex())
        self.encoder_decrement.setCurrentIndex(self.getInputMacroTypeIndex(layer, "encoder", 1))
        self.showInputForm("encoder_decrement", self.encoder_decrement.currentIndex())
        self.fillInputForm(layer, "encoder_decrement", self.encoder_decrement.currentIndex())
        self.encoder_button.setCurrentIndex(self.getInputMacroTypeIndex(layer, "encoder", 2))
        self.showInputForm("encoder_button", self.encoder_button.currentIndex())
        self.fillInputForm(layer, "encoder_button", self.encoder_button.currentIndex())

        self.prevLayerIndex = index
        
        # Any time a change is made beyond a blank layer, allow deletion of layer
        self.delete_layer_button.setEnabled(True)

        self.changesMade = True

    def initFromConfig(self, MainWindow):
        # Fill combobox with layer names
        for layer in slate_config["layers"]:
            self.layer_select.addItem(layer["name"])
        # Set combobox to have first layer selected
        #self.layer_select.setCurrentIndex(0)
        # Fill from first layer
        self.fillFromLayer(0)
        self.changesMade = False

    def mediaControlObject(self, media_combobox_index):
        if media_combobox_index == 0:   # Volume Up
            return ConsumerControlCode.VOLUME_INCREMENT
        if media_combobox_index == 1:   # Volume Down
            return ConsumerControlCode.VOLUME_DECREMENT
        if media_combobox_index == 2:   # Mute
            return ConsumerControlCode.MUTE
        if media_combobox_index == 3:   # Play / Pause
            return ConsumerControlCode.PLAY_PAUSE
        if media_combobox_index == 4:   # Stop
            return ConsumerControlCode.STOP
        if media_combobox_index == 5:   # Rewind
            return ConsumerControlCode.REWIND
        if media_combobox_index == 6:   # Fast Forward
            return ConsumerControlCode.FAST_FORWARD
        if media_combobox_index == 7:   # Record
            return ConsumerControlCode.RECORD
        if media_combobox_index == 8:   # Next Track
            return ConsumerControlCode.SCAN_NEXT_TRACK
        if media_combobox_index == 9:   # Previous Track
            return ConsumerControlCode.SCAN_PREVIOUS_TRACK
        if media_combobox_index == 10:   # Eject
            return ConsumerControlCode.EJECT
        if media_combobox_index == 11:   # Brightness Increase
            return ConsumerControlCode.BRIGHTNESS_INCREMENT
        if media_combobox_index == 12:   # Brightness Decrease
            return ConsumerControlCode.BRIGHTNESS_DECREMENT

    def mouseObject(self, mouse_combobox_index):
        if mouse_combobox_index == 0: # Mouse Up
            return (MOUSE_MOVE, [0, 100, 0])
        if mouse_combobox_index == 1: # Mouse Down
            return (MOUSE_MOVE, [0, -100, 0])
        if mouse_combobox_index == 2: # Mouse Left
            return (MOUSE_MOVE, [-100, 0, 0])
        if mouse_combobox_index == 3: # Mouse Right
            return (MOUSE_MOVE, [100, 0, 0])
        if mouse_combobox_index == 4: # Left Button
            return (MOUSE_CLICK, LEFT_BUTTON)
        if mouse_combobox_index == 5: # Right Button
            return (MOUSE_CLICK, RIGHT_BUTTON)
        if mouse_combobox_index == 6: # Middle Button
            return (MOUSE_CLICK, MIDDLE_BUTTON)

    def constructHIDList(self, keySequence):
        total_keys = keySequence.count()
        hid_list = []
        for key in range(total_keys):
            if "Shift+" in QtGui.QKeySequence(keySequence[key]).toString():
                hid_list.append(Keycode.SHIFT)
                hid_list.append(convertQttoHID(keySequence[key] - QtCore.Qt.KeyboardModifier.ShiftModifier))
            elif "Ctrl+" in QtGui.QKeySequence(keySequence[key]).toString():
                hid_list.append(Keycode.CONTROL)
                hid_list.append(convertQttoHID(keySequence[key] - QtCore.Qt.KeyboardModifier.ControlModifier))
            elif "Alt+" in QtGui.QKeySequence(keySequence[key]).toString():
                hid_list.append(Keycode.ALT)
                hid_list.append(convertQttoHID(keySequence[key] - QtCore.Qt.KeyboardModifier.AltModifier))
            else:
                hid_list.append(convertQttoHID(keySequence[key]))
        return hid_list

    def constructKeySequence(self, hid_list):
        total_keys = len(hid_list)
        keySequence = []
        for key in range(total_keys):
            print("adding to keySequence: " + str(convertHIDtoQt(hid_list[key])))
            keySequence.append(convertHIDtoQt(hid_list[key]))
        if total_keys == 0:
            return QtGui.QKeySequence(0)
        if total_keys == 1:
            k1 = keySequence[0]
            if k1 == QtCore.Qt.Key.Key_Shift:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.ShiftModifier)
            else:
                return QtGui.QKeySequence(k1)
        if total_keys == 2:
            k1 = keySequence[0]
            k2 = keySequence[1]
            if k1 == QtCore.Qt.KeyboardModifier.ShiftModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.ShiftModifier + k2)
            elif k1 == QtCore.Qt.KeyboardModifier.ControlModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.ControlModifier + k2)
            elif k1 == QtCore.Qt.KeyboardModifier.AltModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.AltModifier + k2)
            else:
                return QtGui.QKeySequence(k1, k2)
        if total_keys == 3:
            k1 = keySequence[0]
            k2 = keySequence[1]
            k3 = keySequence[2]
            if k1 == QtCore.Qt.KeyboardModifier.ShiftModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.ShiftModifier + k2, k3)
            elif k1 == QtCore.Qt.KeyboardModifier.ControlModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.ControlModifier + k2, k3)
            elif k1 == QtCore.Qt.KeyboardModifier.AltModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.AltModifier + k2, k3)
            if k2 == QtCore.Qt.KeyboardModifier.ShiftModifier:
                return QtGui.QKeySequence(k1, QtCore.Qt.KeyboardModifier.ShiftModifier + k3)
            elif k2 == QtCore.Qt.KeyboardModifier.ControlModifier:
                return QtGui.QKeySequence(k1, QtCore.Qt.KeyboardModifier.ControlModifier + k3)
            elif k2 == QtCore.Qt.KeyboardModifier.AltModifier:
                return QtGui.QKeySequence(k1, QtCore.Qt.KeyboardModifier.AltModifier + k3)
            else:
                return QtGui.QKeySequence(k1, k2, k3)
        if total_keys == 4:
            k1 = keySequence[0]
            k2 = keySequence[1]
            k3 = keySequence[2]
            k4 = keySequence[3]
            if k1 == QtCore.Qt.KeyboardModifier.ShiftModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.ShiftModifier + k2, k3, k4)
            elif k1 == QtCore.Qt.KeyboardModifier.ControlModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.ControlModifier + k2, k3, k4)
            elif k1 == QtCore.Qt.KeyboardModifier.AltModifier:
                return QtGui.QKeySequence(QtCore.Qt.KeyboardModifier.AltModifier + k2, k3, k4)
            if k2 == QtCore.Qt.KeyboardModifier.ShiftModifier:
                return QtGui.QKeySequence(k1, QtCore.Qt.KeyboardModifier.ShiftModifier + k3, k4)
            elif k2 == QtCore.Qt.KeyboardModifier.ControlModifier:
                return QtGui.QKeySequence(k1, QtCore.Qt.KeyboardModifier.ControlModifier + k3, k4)
            elif k2 == QtCore.Qt.KeyboardModifier.AltModifier:
                return QtGui.QKeySequence(k1, QtCore.Qt.KeyboardModifier.AltModifier + k3, k4)
            if k3 == QtCore.Qt.KeyboardModifier.ShiftModifier:
                return QtGui.QKeySequence(k1, k2, QtCore.Qt.KeyboardModifier.ShiftModifier + k4)
            elif k3 == QtCore.Qt.KeyboardModifier.ControlModifier:
                return QtGui.QKeySequence(k1, k2, QtCore.Qt.KeyboardModifier.ControlModifier + k4)
            elif k3 == QtCore.Qt.KeyboardModifier.AltModifier:
                return QtGui.QKeySequence(k1, k2, QtCore.Qt.KeyboardModifier.AltModifier + k4)
            else:
                return QtGui.QKeySequence(k1, k2, k3, k4)

    def writeScreenKeyActions(self, macro_type):
        if macro_type == 0:
            return (None, None)
        if macro_type == 1: # Hotkey
            return (KEY, self.constructHIDList(ui_screenkey.screenkey_hotkey.keySequence()))
        if macro_type == 2: # String
            return (STRING, ui_screenkey.screenkey_string.text())
        if macro_type == 3: # Media Control
            return (MEDIA, self.mediaControlObject(ui_screenkey.screenkey_combobox.currentIndex()))
        if macro_type == 4: # Windows
            return (None, None)
        if macro_type == 5: # Mouse Control
            return self.mouseObject(ui_screenkey.screenkey_combobox.currentIndex())

    def writeActions(self, prefix, macro_type):
        if macro_type == 0:
            return (None, None)
        if macro_type == 1: # Hotkey
            return (KEY, self.constructHIDList(getattr(self, "%s_hotkey" % prefix).keySequence()))
        if macro_type == 2: # String
            return (STRING, getattr(self, "%s_string" % prefix).text())
        if macro_type == 3: # Media Control
            return (MEDIA, self.mediaControlObject(getattr(self, "%s_combobox" % prefix).currentIndex()))
        if macro_type == 4: # Windows
            return (None, None)
        if macro_type == 5: # Mouse Control
            return self.mouseObject(getattr(self, "%s_combobox" % prefix).currentIndex())
            
    def openScreenKeyDialog(self, key_number):
        layer = slate_config["layers"][self.layer_select.currentIndex()]
        current_label = layer["touch_shortcuts"][key_number]["label"]
        current_image_path = layer["touch_shortcuts"][key_number]["icon"]
        ui_screenkey.screenkey_macro.setCurrentIndex(self.getInputMacroTypeIndex(layer, "touch_shortcuts", key_number))
        ui_screenkey.screenkey_name.setText(current_label)
        ui_screenkey.screenkey_image_path.setText(current_image_path)
        ui_screenkey.showInputForm("screenkey", ui_screenkey.screenkey_macro.currentIndex())
        fillInputForm(ui_screenkey, key_number, "screenkey", ui_screenkey.screenkey_macro.currentIndex())
        if EditScreenKey.exec() == 1:
            # User pressed ok on dialog --> save contents to cached config
            layer["touch_shortcuts"][key_number]["label"] = ui_screenkey.screenkey_name.text()
            layer["touch_shortcuts"][key_number]["icon"] = ui_screenkey.screenkey_image_path.text()
            action = self.writeScreenKeyActions(ui_screenkey.screenkey_macro.currentIndex())
            print("Wrote action to cached config: " + str(action))
            layer["touch_shortcuts"][key_number]["actions"] = action
            self.prevLayerIndex = -1
            self.fillFromLayer(self.layer_select.currentIndex())

    def openNewLayerDialog(self):
        LayerDialog.setWindowTitle("Create New Layer")
        ui_layerdialog.label.setText("New layer name:")
        ui_layerdialog.newlayer_name.clear()
        if LayerDialog.exec() == 1:
            # User pressed ok on dialog --> generate new layer
            new_name = ui_layerdialog.newlayer_name.text()
            slate_config["layers"].append(copy.deepcopy(BLANK_LAYER))
            self.layer_select.addItem(new_name)
            new_layer_index = len(slate_config["layers"]) - 1
            slate_config["layers"][new_layer_index]["name"] = new_name
            self.layer_select.setCurrentIndex(new_layer_index)

    def openRenameLayerDialog(self):
        LayerDialog.setWindowTitle("Rename Layer")
        ui_layerdialog.label.setText("Layer name:")
        ui_layerdialog.newlayer_name.setText(self.layer_select.currentText())
        if LayerDialog.exec() == 1:
            # User pressed ok on dialog --> rename layer
            new_name = ui_layerdialog.newlayer_name.text()
            renamed_layer_index = self.layer_select.currentIndex()
            slate_config["layers"][renamed_layer_index]["name"] = new_name
            self.layer_select.setItemText(renamed_layer_index, new_name)
            # If the blank layer gets renamed, allow deletion
            self.delete_layer_button.setEnabled(True)
            # Renaming a layer counts as a change
            self.changesMade = True

    def openDeleteLayerDialog(self):
        # Play sound to indicate user is making a change that needs confirmation
        winsound.MessageBeep()
        if DeleteLayerDialog.exec() == 1:
            # User pressed ok on dialog --> delete current layer
            self.prevLayerIndex = -1
            if len(slate_config["layers"]) == 1:
                slate_config["layers"][0] = copy.deepcopy(BLANK_LAYER)
                self.layer_select.setItemText(0, "Blank")
                self.fillFromLayer(0)
                # When all layers deleted and the blank layer is generated, disable delete button
                self.delete_layer_button.setEnabled(False)
            else:
                current_index = self.layer_select.currentIndex()
                slate_config["layers"].pop(current_index)
                self.layer_select.removeItem(current_index)

    def writeToFile(self):
        from pprint import pprint
        new_config = slate_config
        with open('layers_config.py', 'w') as out:
            out.write('slate_config =')
            pprint(new_config, stream=out)

    def applyToSlate(self):
        from shutil import copy2
        layers_path = ""
        self.writeToFile()

        c = wmi.WMI()
        for drive in c.Win32_LogicalDisk():
            if drive.VolumeName == "CIRCUITPY":
                layers_path = drive.Caption + "/layers.py"

        if layers_path == "":
            print("CIRCUITPY not found")
            return

        try:
            # Copy file used by configurator to Slate's internal memory
            copy2('layers_config.py', layers_path)
            print("Layers config applied successfully.")
            # Show a message box after successfully applying config
            winsound.MessageBeep()
            msgBox = QtWidgets.QMessageBox()
            msgBox.setWindowTitle("Success")
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap("images/slate_windowicon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            msgBox.setWindowIcon(icon)
            msgBox.setIcon(QtWidgets.QMessageBox.Information)
            msgBox.setText("Config applied successfully!\nSlate is rebooting...")
            msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
            msgBox.setDefaultButton(QtWidgets.QMessageBox.Ok)
            msgBox.exec()
        except IOError as er:
            print(er)

    def saveConfigFile(self):
        #TODO: allow user to save config with custom name/location
        # For now, just write current edits to file
        # Caches current layer data
        self.fillFromLayer(self.layer_select.currentIndex())
        # Writes cached object to file
        self.writeToFile()
        # Allows user to exit without prompt
        self.changesMade = False
        # Print what happened
        print("Config saved manually to layers_config.py")

    
    def closeEvent(self, event):
        if self.changesMade:
            msgBox = QtWidgets.QMessageBox()
            msgBox.setWindowTitle("Exit")
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap("images/slate_windowicon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            msgBox.setWindowIcon(icon)
            msgBox.setText("<b align='center'>The config has been modified.</b>")
            msgBox.setInformativeText("Do you want to save your changes?")
            msgBox.setStandardButtons(QtWidgets.QMessageBox.Save | QtWidgets.QMessageBox.Discard | QtWidgets.QMessageBox.Cancel)
            msgBox.setDefaultButton(QtWidgets.QMessageBox.Save)
            ret = msgBox.exec()
            if ret == QtWidgets.QMessageBox.Save:
                self.writeToFile()
                exit()
            elif ret == QtWidgets.QMessageBox.Discard:
                event.accept()
                exit()
            if ret == QtWidgets.QMessageBox.Cancel:
                event.ignore()
        else:
            event.accept()
            exit()

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    EditScreenKey = QtWidgets.QDialog()
    LayerDialog = QtWidgets.QDialog()
    DeleteLayerDialog = QtWidgets.QDialog()
    ui = Ui_MainWindow()
    ui_screenkey = screenkey.Ui_screenKeyDialog()
    ui_screenkey.setupUi(EditScreenKey)
    ui_layerdialog = new_layer.Ui_newLayerDialog()
    ui_layerdialog.setupUi(LayerDialog)
    ui_deletelayerdialog = delete_layer.Ui_deleteLayerDialog()
    ui_deletelayerdialog.setupUi(DeleteLayerDialog)
    ui.setupUi(MainWindow)
    ui.hide_inputs(MainWindow)
    ui.initFromConfig(MainWindow)
    ui.macroTabs.currentChanged.connect(ui.changePreviewImage)
    ui.layer_select.currentIndexChanged.connect(ui.fillFromLayer)
    ui.screenkey_0.clicked.connect(lambda: ui.openScreenKeyDialog(0))
    ui.screenkey_1.clicked.connect(lambda: ui.openScreenKeyDialog(1))
    ui.screenkey_2.clicked.connect(lambda: ui.openScreenKeyDialog(2))
    ui.screenkey_3.clicked.connect(lambda: ui.openScreenKeyDialog(3))
    ui.screenkey_4.clicked.connect(lambda: ui.openScreenKeyDialog(4))
    ui.screenkey_5.clicked.connect(lambda: ui.openScreenKeyDialog(5))
    ui.screenkey_6.clicked.connect(lambda: ui.openScreenKeyDialog(6))
    ui.screenkey_7.clicked.connect(lambda: ui.openScreenKeyDialog(7))
    ui.screenkey_8.clicked.connect(lambda: ui.openScreenKeyDialog(8))
    ui.screenkey_9.clicked.connect(lambda: ui.openScreenKeyDialog(9))
    ui.screenkey_10.clicked.connect(lambda: ui.openScreenKeyDialog(10))
    ui.screenkey_11.clicked.connect(lambda: ui.openScreenKeyDialog(11))
    ui.key_0.currentIndexChanged.connect(lambda: ui.showInputForm("key_0", ui.key_0.currentIndex()))
    ui.key_1.currentIndexChanged.connect(lambda: ui.showInputForm("key_1", ui.key_1.currentIndex()))
    ui.key_2.currentIndexChanged.connect(lambda: ui.showInputForm("key_2", ui.key_2.currentIndex()))
    ui.key_3.currentIndexChanged.connect(lambda: ui.showInputForm("key_3", ui.key_3.currentIndex()))
    ui.key_4.currentIndexChanged.connect(lambda: ui.showInputForm("key_4", ui.key_4.currentIndex()))
    ui.key_5.currentIndexChanged.connect(lambda: ui.showInputForm("key_5", ui.key_5.currentIndex()))
    ui.key_6.currentIndexChanged.connect(lambda: ui.showInputForm("key_6", ui.key_6.currentIndex()))
    ui.key_7.currentIndexChanged.connect(lambda: ui.showInputForm("key_7", ui.key_7.currentIndex()))
    ui.xAxis_pos.currentIndexChanged.connect(lambda: ui.showInputForm("xAxis_pos", ui.xAxis_pos.currentIndex()))
    ui.xAxis_neg.currentIndexChanged.connect(lambda: ui.showInputForm("xAxis_neg", ui.xAxis_neg.currentIndex()))
    ui.yAxis_pos.currentIndexChanged.connect(lambda: ui.showInputForm("yAxis_pos", ui.yAxis_pos.currentIndex()))
    ui.yAxis_neg.currentIndexChanged.connect(lambda: ui.showInputForm("yAxis_neg", ui.yAxis_neg.currentIndex()))
    ui.joystick_button.currentIndexChanged.connect(lambda: ui.showInputForm("joystick_button", ui.joystick_button.currentIndex()))
    ui.encoder_increment.currentIndexChanged.connect(lambda: ui.showInputForm("encoder_increment", ui.encoder_increment.currentIndex()))
    ui.encoder_decrement.currentIndexChanged.connect(lambda: ui.showInputForm("encoder_decrement", ui.encoder_decrement.currentIndex()))
    ui.encoder_button.currentIndexChanged.connect(lambda: ui.showInputForm("encoder_button", ui.encoder_button.currentIndex()))
    ui.create_layer_button.clicked.connect(ui.openNewLayerDialog)
    ui.rename_layer_button.clicked.connect(ui.openRenameLayerDialog)
    ui.delete_layer_button.clicked.connect(ui.openDeleteLayerDialog)
    # ui.apply_config_button.clicked.connect(ui.applyToSlate)
    ui.save_config_button.clicked.connect(ui.saveConfigFile)

    MainWindow.closeEvent = ui.closeEvent
    MainWindow.show()

    sys.exit(app.exec_())
