コード例 #1
0
def StartOnePlayer():
    global onePlayerWindow
    global drawButtonOnePlayer
    global cardImagesOnePlayer
    global guessContainerOnePlayer
    global guessCheckButtonOnePlayer
    global guessTextBoxOnePlayer
    global correctOnePlayer
    global errorTextOnePlayer

    onePlayerWindow = Window(app, title="One Player Game", layout="grid")
    onePlayerWindow.width = 320; onePlayerWindow.height = 560; onePlayerWindow.bg = "Lime"

    drawButtonOnePlayer = PushButton(onePlayerWindow, text="Draw!", grid=[0, 0], align="top", command=ButtonSwapOnePlayer)
    drawButtonOnePlayer.width = 20; drawButtonOnePlayer.height = 5; drawButtonOnePlayer.bg = "White"
    cardImagesOnePlayer = Box(onePlayerWindow, layout="grid", grid=[0, 1], align="top", border=True)
    cardImagesOnePlayer.set_border(10, "Lime")

    guessContainerOnePlayer = Box(onePlayerWindow, layout="grid", grid=[0, 2], align="top", border=True)
    guessContainerOnePlayer.set_border(10, "Lime")
    guessTextBoxOnePlayer = TextBox(guessContainerOnePlayer, grid=[0, 0], align="top")
    guessTextBoxOnePlayer.text_size = 20; guessTextBoxOnePlayer.bg = "White"; guessTextBoxOnePlayer.disable();
    guessCheckButtonOnePlayer = PushButton(guessContainerOnePlayer, text="Check!", grid=[0, 1], align="top", command=CheckValuesOnePlayer)
    guessCheckButtonOnePlayer.width = 20; guessCheckButtonOnePlayer.height = 5; guessCheckButtonOnePlayer.bg = "White"; guessCheckButtonOnePlayer.disable();
    pointsTextOnePlayer = Text(guessContainerOnePlayer, text="Score: ", grid=[0, 2], align="top")

    correctOnePlayer = Text(onePlayerWindow, text="", grid=[0, 3])
    errorTextOnePlayer = Text(onePlayerWindow, text="Please enter a number!", grid=[0, 4])
    errorTextOnePlayer.hide()
コード例 #2
0
def Run():
    global startWindow
    global finalCheck
    global startButtons

    startWindow = Window(app, title="Starting Screen", layout="grid")
    startWindow.width = 360; startWindow.height = 630; startWindow.bg = "Lime"

    playersQuestionText = Text(startWindow, text="How Many Players?", grid=[0, 0], align="top")
    playersQuestionText.text_size = 25
    playerButtonContainer = Box(startWindow, layout="grid", grid=[0, 1], align="top", border=True)
    playerButtonContainer.set_border(10, "Lime")
    buttonOnePlayer = PushButton(playerButtonContainer, text="1 Player", grid=[1, 0], command=lambda: SetPlayerNumber(True, "1 Player"))
    buttonOnePlayer.width = 20; buttonOnePlayer.height = 10; buttonOnePlayer.bg = "White"
    buttonTwoPlayer = PushButton(playerButtonContainer, text="2 Player", grid=[2, 0], command=lambda: SetPlayerNumber(False, "2 Player"))
    buttonTwoPlayer.width = 20; buttonTwoPlayer.height = 10; buttonTwoPlayer.bg = "White"

    gameModeQuestionText = Text(startWindow, text="What Game Mode?", grid=[0, 2], align="top")
    gameModeQuestionText.text_size = 25
    gameModeButtonContainer = Box(startWindow, layout="grid", grid=[0, 3], align="top", border=True)
    gameModeButtonContainer.set_border(10, "Lime")
    buttonAddition = PushButton(gameModeButtonContainer, text="Addition", grid=[1, 0], command=lambda: SetGameMode(True, "Addition"))
    buttonAddition.width = 20; buttonAddition.height = 10; buttonAddition.bg = "White"
    buttonSubtraction = PushButton(gameModeButtonContainer, text="Subtraction", grid=[2, 0], command=lambda: SetGameMode(False, "Subtraction"))
    buttonSubtraction.width = 20; buttonSubtraction.height = 10; buttonSubtraction.bg = "White"

    finalCheck = Box(startWindow, layout="grid", grid=[0, 4], align="top", border=True)
    finalCheck.set_border(10, "Lime")
    startButton = PushButton(finalCheck, text="Start!", grid=[0, 2], align="top", command=StartGame)
    startButton.width = 20; startButton.height = 5; startButton.bg = "White"; startButton.disable()
コード例 #3
0
def test_border():
    a = App()
    b = Box(a)
    assert not b.border
    assert b.border == 0

    b.border = True
    assert b.border
    assert b.border == 1
    assert b._get_tk_config("highlightbackground") == "black"

    b.border = False
    assert not b.border

    b.border = 10
    assert b.border
    assert b.border == 10

    b.set_border(11, "red")
    assert b.border
    assert b.border == 11
    assert b._get_tk_config("highlightbackground") == "red"
    a.destroy()
コード例 #4
0
def StartTwoPlayer():
    global twoPlayerWindow
    global drawButtonTwoPlayer
    global cardImagesTwoPlayer1
    global cardImagesTwoPlayer2
    global guessContainerTwoPlayer1
    global guessContainerTwoPlayer2
    global guessTextBoxTwoPlayer1
    global guessTextBoxTwoPlayer2
    global guessCheckButtonTwoPlayer
    global correctTwoPlayer1
    global correctTwoPlayer2
    global errorTextTwoPlayer

    twoPlayerWindow = Window(app, title="Two Player Game", layout="grid")
    twoPlayerWindow.width = 660; twoPlayerWindow.height = 570; twoPlayerWindow.bg = "Lime"

    drawButtonTwoPlayer = PushButton(twoPlayerWindow, text="Draw!", grid=[0, 0], align="top", padx=20, command=ButtonSwapTwoPlayer)
    drawButtonTwoPlayer.width = 20; drawButtonTwoPlayer.height = 5; drawButtonTwoPlayer.bg = "White"
    cardImagesTwoPlayer1 = Box(twoPlayerWindow, layout="grid", grid=[0, 1], align="top", border=True)
    cardImagesTwoPlayer1.set_border(5, "Lime")
    cardImagesTwoPlayer2 = Box(twoPlayerWindow, layout="grid", grid=[1, 1], align="top", border=True)
    cardImagesTwoPlayer2.set_border(5, "Lime")

    guessContainerTwoPlayer1 = Box(twoPlayerWindow, layout="grid", grid=[0, 2], align="top", border=True)
    guessContainerTwoPlayer1.set_border(10, "Lime")
    guessTextBoxTwoPlayer1 = TextBox(guessContainerTwoPlayer1, grid=[0, 0], align="top")
    guessTextBoxTwoPlayer1.text_size = 20; guessTextBoxTwoPlayer1.bg = "White"; guessTextBoxTwoPlayer1.disable()
    guessContainerTwoPlayer2 = Box(twoPlayerWindow, layout="grid", grid=[1, 2], align="top", border=True)
    guessContainerTwoPlayer2.set_border(10, "Lime")
    guessTextBoxTwoPlayer2 = TextBox(guessContainerTwoPlayer2, grid=[0, 0], align="top")
    guessTextBoxTwoPlayer2.text_size = 20; guessTextBoxTwoPlayer2.bg = "White"; guessTextBoxTwoPlayer2.disable()

    pointsTextTwoPlayer1 = Text(guessContainerTwoPlayer1, text="Player One Score: ", grid=[0, 2], align="top")
    pointsTextTwoPlayer2 = Text(guessContainerTwoPlayer2, text="Player Two Score: ", grid=[0, 2], align="top")

    guessCheckButtonTwoPlayer = PushButton(twoPlayerWindow, text="Check!", grid=[0, 3], align="top", command=CheckValuesTwoPlayer)
    guessCheckButtonTwoPlayer.width = 20; guessCheckButtonTwoPlayer.height = 5; guessCheckButtonTwoPlayer.bg = "White"; guessCheckButtonTwoPlayer.disable()

    correctTwoPlayer1 = Text(guessContainerTwoPlayer1, text="", grid=[0, 3])
    correctTwoPlayer2 = Text(guessContainerTwoPlayer2, text="", grid=[0, 3])
    errorTextTwoPlayer = Text(twoPlayerWindow, text="Please Enter a Number!", grid=[0, 4])
    errorTextTwoPlayer.hide()
コード例 #5
0
    def __init__(self, app, port, locx, locy):
        self.screen_width = app.tk.winfo_screenwidth()
        self.screen_height = app.tk.winfo_screenheight()
        #print( "Width {}, Height {}".format( self.screen_width, self.screen_height ) )

        self.locx = locx
        self.locy = locy
        self.strobe_cam = PiStrobeCam(port, 0.1)

        valid = self.strobe_cam.strobe.set_enable(False)
        self.enabled = valid

        box = Box(app, layout="grid", grid=[locx, locy])
        box.set_border(1, "black")
        box.bg = picommon.col_lightgray1 if ((locx + locy) % 2
                                             == 0) else picommon.col_lightgray2

        Text(box, grid=[0, 0], text="Strobe", align="left")
        Box(box, grid=[1, 0], width=130, height=1)
        Box(box, grid=[2, 0], width=80, height=1)
        Box(box, grid=[3, 0], width=80, height=1)

        Text(box, grid=[0, 1], text="Status:", align="left")
        self.strobe_status_text = Text(box, grid=[1, 1], align="left")

        Text(box, grid=[0, 2], text="Period:", align="left")
        self.strobe_time_text = Text(box, grid=[1, 2], align="left")
        self.strobe_time_text.value = "N/A"
        self.strobe_time_box = TextBox(box,
                                       grid=[2, 2],
                                       align="left",
                                       width=6,
                                       enabled=self.enabled)
        self.strobe_time_box.value = "1000"
        self.set_timing_btn = PushButton(box,
                                         command=self.set_timing,
                                         text="Set",
                                         grid=[3, 2],
                                         width=12,
                                         align="left",
                                         pady=1,
                                         enabled=self.enabled)

        Text(box, grid=[0, 3], text="Framerate:", align="left")
        self.strobe_framerate_text = Text(box, grid=[1, 3], align="left")
        self.optimize_fps_btn = PushButton(box,
                                           command=self.optimize_fps,
                                           text="Optimize",
                                           grid=[3, 3],
                                           width=12,
                                           align="left",
                                           pady=1,
                                           enabled=False)

        self.snapshot_btn = PushButton(box,
                                       command=self.save_snapshot,
                                       text="Snapshot",
                                       grid=[3, 4],
                                       width=12,
                                       align="left",
                                       pady=1,
                                       enabled=self.enabled)

        Box(box, grid=[4, 5], width=10, height=10)
        Box(box, grid=[0, 5], width=80, height=1)

        self.strobe_cam.camera.start_preview(
            fullscreen=False,
            window=(self.screen_width - PREVIEW_X + 1,
                    self.screen_height - PREVIEW_Y, PREVIEW_X, PREVIEW_Y))
コード例 #6
0
    def __init__(self, app, heater_num, port, locx, locy):
        self.locx = locx
        self.locy = locy
        self.holder = piholder.PiHolder(port, 0.05)
        self.autotuning = False
        self.pid_enabled = False
        self.stir_enabled = False

        valid, id, id_valid = self.holder.get_id()
        #    print( "ID OK:{}".format( valid ) )
        self.enabled = valid and id_valid

        box = Box(app, layout="grid", grid=[locx, locy])
        box.set_border(1, "black")
        box.bg = picommon.col_lightgray1 if ((locx + locy) % 2
                                             == 0) else picommon.col_lightgray2

        Text(box,
             grid=[0, 0],
             text="Heater {}".format(heater_num),
             align="left")
        Box(box, grid=[1, 0], width=130, height=1)
        Box(box, grid=[2, 0], width=80, height=1)
        Box(box, grid=[3, 0], width=80, height=1)

        Text(box, grid=[0, 1], text="Status:", align="left")
        self.holder_status_text = Text(box, grid=[1, 1], align="left")

        Text(box, grid=[0, 2], text="Temp:", align="left")
        self.holder_temp = Text(box, grid=[1, 2], align="left")

        Text(box, grid=[0, 3], text="Autotune:", align="left")
        self.autotune_status_text = Text(box, grid=[1, 3], align="left")

        Text(box, grid=[0, 4], text="Stir:", align="left")
        self.stir_speed = Text(box, grid=[1, 4], align="left")

        self.temp_target_box = TextBox(box,
                                       grid=[2, 2],
                                       align="left",
                                       width=6,
                                       enabled=self.enabled)
        self.set_temp_btn = PushButton(box,
                                       command=self.set_temp,
                                       text="Set Temp",
                                       grid=[3, 2],
                                       width=12,
                                       align="left",
                                       pady=1,
                                       enabled=self.enabled)
        self.set_pid_enable_btn = PushButton(box,
                                             command=self.set_pid_running,
                                             text="",
                                             grid=[3, 1],
                                             width=12,
                                             align="left",
                                             pady=1,
                                             enabled=self.enabled)

        self.autotune_target_box = TextBox(box,
                                           grid=[2, 3],
                                           align="left",
                                           width=6,
                                           enabled=self.enabled)
        self.autotune_target_box.value = "50.00"
        self.autotune_btn = PushButton(box,
                                       command=self.set_autotune,
                                       text="",
                                       grid=[3, 3],
                                       width=12,
                                       align="left",
                                       pady=1,
                                       enabled=self.enabled)

        self.stir_target_box = TextBox(box,
                                       grid=[2, 4],
                                       align="left",
                                       width=6,
                                       enabled=self.enabled)
        self.stir_target_box.value = "20"
        self.stir_btn = PushButton(box,
                                   command=self.set_stir_running,
                                   text="",
                                   grid=[3, 4],
                                   width=12,
                                   align="left",
                                   pady=1,
                                   enabled=self.enabled)

        #    spacer=Box( box, grid=[0, 4], width=100, height=10 )
        #    spacer.bg="black"
        Box(box, grid=[4, 5], width=10, height=10)
        Box(box, grid=[0, 5], width=80, height=1)

        self.temp_c_target = self.get_temp()
コード例 #7
0
def SQLQuerySelection():
    queryWindow = Window(app, title="SQL Query Selection", layout="grid")
    queryWindow.width = 800
    queryWindow.bg = "Grey"

    dataButtonContainer = Box(queryWindow,
                              layout="grid",
                              grid=[0, 0],
                              align="top",
                              border=True)
    dataButtonContainer.set_border(10, "Grey")

    allDataButton = PushButton(
        dataButtonContainer,
        text="Show All Data",
        grid=[0, 0],
        align="top",
        command=lambda: SQLQueriesExecution(
            "SELECT Date, Time, Temp, Humid, Press FROM WeatherData",
            "Date, Time, Temperature, Humidity, Pressure"))
    allDataButton.width = 10
    allDataButton.height = 5
    allDataButton.bg = "White"
    '''
    Request all the fields from the database and orders then ascending by a specifc field
    Doesn't get any return variables
    '''
    sortingText = Text(dataButtonContainer,
                       text="Sort By:",
                       grid=[0, 1],
                       align="top")
    tempSortButton = PushButton(
        dataButtonContainer,
        text="Temperature (min - max)",
        grid=[0, 2],
        align="top",
        command=lambda: SQLQueriesExecution(
            "SELECT Date, Time, Temp, Humid, Press FROM WeatherData ORDER BY Temp ASC",
            "Date, Time, Temperature, Humidity, Pressure"))
    tempSortButton.width = 20
    tempSortButton.height = 5
    tempSortButton.bg = "White"
    humidSortButton = PushButton(
        dataButtonContainer,
        text="Humidity (min - max)",
        grid=[1, 2],
        align="top",
        command=lambda: SQLQueriesExecution(
            "SELECT Date, Time, Temp, Humid, Press FROM WeatherData ORDER BY Humid ASC",
            "Date, Time, Temperature, Humidity, Pressure"))
    humidSortButton.width = 20
    humidSortButton.height = 5
    humidSortButton.bg = "White"
    pressSortButton = PushButton(
        dataButtonContainer,
        text="Pressure (min - max)",
        grid=[2, 2],
        align="top",
        command=lambda: SQLQueriesExecution(
            "SELECT Date, Time, Temp, Humid, Press FROM WeatherData ORDER BY Press ASC",
            "Date, Time, Temperature, Humidity, Pressure"))
    pressSortButton.width = 20
    pressSortButton.height = 5
    pressSortButton.bg = "White"
コード例 #8
0
def MainPage():
    global mainWindow

    mainWindow = Window(app, title="S.W.I.G.G.S", layout="grid")
    mainWindow.width = 900
    mainWindow.height = 850
    mainWindow.bg = "Grey"

    titleText = Text(
        mainWindow,
        text="Sheldon Weather Information & Graph Generating Software",
        grid=[0, 0],
        align="top")
    titleText.text_size = 25
    abbreviationText = Text(mainWindow,
                            text="---S.W.I.G.G.S---",
                            grid=[0, 1],
                            align="top")
    abbreviationText.text_size = 20

    spacerText = Text(mainWindow, text="", grid=[0, 2], align="top")
    spacerText.text_size = 20

    savedText = Text(mainWindow,
                     text="---Display Stored Data---",
                     grid=[0, 3],
                     align="top")
    savedText.text_size = 25

    standardButtonContainer = Box(mainWindow,
                                  layout="grid",
                                  grid=[0, 4],
                                  align="top",
                                  border=True)
    standardButtonContainer.set_border(10, "Grey")
    dataButton = PushButton(standardButtonContainer,
                            text="Display Data",
                            grid=[0, 0],
                            align="top",
                            command=SQLQuerySelection)
    dataButton.width = 20
    dataButton.height = 5
    dataButton.bg = "White"
    graphButtonContainer = Box(standardButtonContainer,
                               layout="grid",
                               grid=[0, 1],
                               align="top",
                               border=True)
    graphButtonContainer.set_border(10, "Grey")
    tempGraphButton = PushButton(graphButtonContainer,
                                 text="Temperature Graph",
                                 grid=[0, 1],
                                 align="top",
                                 command=CreateTempGraph)
    tempGraphButton.width = 20
    tempGraphButton.height = 5
    tempGraphButton.bg = "White"
    humidGraphButton = PushButton(graphButtonContainer,
                                  text="Humidity Graph",
                                  grid=[1, 1],
                                  align="top",
                                  command=CreateHumidGraph)
    humidGraphButton.width = 20
    humidGraphButton.height = 5
    humidGraphButton.bg = "White"
    pressGraphButton = PushButton(graphButtonContainer,
                                  text="Pressure Graph",
                                  grid=[2, 1],
                                  align="top",
                                  command=CreatePressGraph)
    pressGraphButton.width = 20
    pressGraphButton.height = 5
    pressGraphButton.bg = "White"

    liveText = Text(mainWindow,
                    text="---Live Data Collection---",
                    grid=[0, 5],
                    align="top")
    liveText.text_size = 25
    informationText = Text(mainWindow,
                           text="Collect Data for...",
                           grid=[0, 6],
                           align="top")
    informationText.text_size = 15
    liveContainer = Box(mainWindow,
                        layout="grid",
                        grid=[0, 7],
                        align="top",
                        border=True)
    liveContainer.set_border(10, "Grey")
    '''
    Runs LiveCollection function passing through the number of cycles to complete the displayed time on the button
    Doesn't get any return variables
    '''
    hrs48Button = PushButton(liveContainer,
                             text="48 Hours...",
                             grid=[0, 0],
                             align="top",
                             command=lambda: LiveCollection(17280))
    hrs48Button.width = 10
    hrs48Button.height = 5
    hrs48Button.bg = "White"
    hrs24Button = PushButton(liveContainer,
                             text="24 Hours...",
                             grid=[1, 0],
                             align="top",
                             command=lambda: LiveCollection(8640))
    hrs24Button.width = 10
    hrs24Button.height = 5
    hrs24Button.bg = "White"
    hrs12Button = PushButton(liveContainer,
                             text="12 Hours...",
                             grid=[3, 0],
                             align="top",
                             command=lambda: LiveCollection(4320))
    hrs12Button.width = 10
    hrs12Button.height = 5
    hrs12Button.bg = "White"
    hrs1Button = PushButton(liveContainer,
                            text="1 Hours...",
                            grid=[4, 0],
                            align="top",
                            command=lambda: LiveCollection(360))
    hrs1Button.width = 10
    hrs1Button.height = 5
    hrs1Button.bg = "White"
    customButton = PushButton(mainWindow,
                              text="Custom Time...",
                              grid=[0, 8],
                              align="top",
                              command=CustomLiveCollection)
    customButton.width = 15
    customButton.height = 5
    customButton.bg = "White"

    warningContainer = Box(mainWindow,
                           layout="grid",
                           grid=[0, 9],
                           align="top",
                           border=True)
    warningContainer.set_border(30, "Grey")
    databaseButton = PushButton(warningContainer,
                                text="!Create New Database!",
                                grid=[0, 0],
                                align="top",
                                command=CreateNewDatabase)
    databaseButton.width = 20
    databaseButton.height = 2
    databaseButton.bg = "Red"
コード例 #9
0
ファイル: m8tricks.py プロジェクト: topshed/m8tricks
def startup():

    HOME = str(Path.home())
    HERE = os.path.dirname(os.path.realpath(__file__))
    global NOHAT
    global ONEMU
    global tstamp
    tstamp = ""
    NOHAT = False
    ONEMU = False
    global framerate
    framerate = 1

    def no_hat_check():
        global NOHAT
        global ONEMU
        NOHAT = yesno(
            "No SenseHAT detected",
            "No SenseHat detected - Do you want to carry on anyway?")
        if NOHAT:
            if "arm" in os.uname().machine:
                ONEMU = yesno(
                    "Looks like a Pi",
                    "Do you want to try to run in the SenseHat emulator?")
                if ONEMU:
                    if not os.path.isfile("/usr/bin/sense_emu_gui"):
                        warn(
                            "Sorry",
                            "It doesn't look like the SenseHAT emulator is installed"
                        )
                        sys.exit()
            else:
                warn(
                    "No pi!",
                    "It doesn't look like the you're on a Raspberry Pi. You can still save animations and images."
                )

        else:
            sys.exit()

    global col
    col = (255, 255, 255)
    global blank_frame
    blank_frame = [(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)]

    global frames
    frames = {1: blank_frame.copy()}
    global current_frame_number
    current_frame_number = 1
    framerate = 1  # frames per second
    global looping

    looping = False

    def illum_pixel(x, y):
        global col
        #global NOHAT
        matrix.set_pixel(x, y, col)
        if not NOHAT:
            sh.set_pixel(x, y, col)

    def col_select(x, y):
        global col
        if y == 0:
            col = (255, 0, 0)
            button_clear.text_color = "black"
        elif y == 1:
            col = (0, 255, 0)
            button_clear.text_color = "black"
        elif y == 2:
            col = (0, 0, 255)
            button_clear.text_color = "white"
        elif y == 3:
            col = (255, 255, 0)
            button_clear.text_color = "black"
        elif y == 4:
            col = (80, 80, 80)
            button_clear.text_color = "white"
        elif y == 5:
            col = (255, 255, 255)
            button_clear.text_color = "black"

        elif y == 6:
            col = (255, 0, 255)
            button_clear.text_color = "black"
        elif y == 7:
            col = (255, 150, 0)
            button_clear.text_color = "black"
            button_clear.text_color = "black"
        elif y == 8:
            col = (0, 0, 0)
            button_clear.text_color = "white"
        elif y == 9:
            col = (66, 220, 240)
            button_clear.text_color = "black"
        box.bg = col
        button_clear.bg = col

    def hex_to_rgb(hex):
        return (tuple(int(hex[i:i + 2], 16) for i in (0, 2, 4)))

    def p_clicked(x, y):
        if (x <= 7) and (y <= 7):

            if matrix.get_pixel(x, y) == "black":
                illum_pixel(x, y)
                frames[current_frame_number][(y * 8) + x] = col
            elif hex_to_rgb(str(matrix.get_pixel(x, y).strip('#'))) == col:
                matrix.set_pixel(x, y, "black")
                sh.set_pixel(x, y, (0, 0, 0))
                frames[current_frame_number][(y * 8) + x] = (0, 0, 0)
            else:
                illum_pixel(x, y)
                frames[current_frame_number][(y * 8) + x] = col

    def clear_matrix():
        global NOHAT
        if not NOHAT:
            sh.clear(col)
        for x in range(8):
            for y in range(8):
                matrix.set_pixel(x, y, col)
                frames[current_frame_number][(y * 8) + x] = col

    def new_frame():
        global current_frame_number
        global frames
        global blank_frame
        if current_frame_number != len(frames):  # not last frame
            for f in range(len(frames), current_frame_number, -1):
                frames[f + 1] = frames[f].copy()

        frames[current_frame_number + 1] = blank_frame.copy()
        current_frame_number += 1

        load_frame()

    def copy_frame():
        global current_frame_number
        global frames
        if current_frame_number != len(frames):  # not last frame
            for f in range(len(frames), current_frame_number, -1):
                frames[f + 1] = frames[f].copy()
        frames[current_frame_number + 1] = frames[current_frame_number].copy()
        current_frame_number += 1

        load_frame()

    def delete_frame():
        global current_frame_number
        global frames
        global blank_frame
        if current_frame_number != 1:
            if current_frame_number != len(frames):  # not last frame
                for f in range(current_frame_number, len(frames)):
                    frames[f] = frames[f + 1].copy()
            current_frame_number -= 1
            del frames[len(frames)]

            load_frame()
        else:
            warn("Heads up", "Only one frame exits - you can't delete it")

    def load_frame():
        global NOHAT
        frame_status_text.value = ("Frame " +
                                   str(current_frame_number).zfill(3) +
                                   " of " + str(len(frames)).zfill(3))
        if not NOHAT:
            sh.set_pixels(frames[current_frame_number])
        for x in range(8):
            for y in range(8):
                matrix.set_pixel(x, y,
                                 frames[current_frame_number][(y * 8) + x])
        load_other_frames()

    def load_other_frames():
        prev_matrix.color = "black"
        next_matrix.color = "black"
        if len(frames) == 2:
            if current_frame_number == 1:
                for x in range(8):
                    for y in range(8):
                        next_matrix.set_pixel(
                            x, y,
                            frames[current_frame_number + 1][(y * 8) + x])
                for x in range(8):
                    for y in range(8):
                        prev_matrix.set_pixel(x, y, "grey")
            else:
                for x in range(8):
                    for y in range(8):
                        prev_matrix.set_pixel(
                            x, y,
                            frames[current_frame_number - 1][(y * 8) + x])
                for x in range(8):
                    for y in range(8):
                        next_matrix.set_pixel(x, y, "grey")

        if len(frames) >= 3:
            if current_frame_number == 1:

                for x in range(8):
                    for y in range(8):
                        next_matrix.set_pixel(
                            x, y,
                            frames[current_frame_number + 1][(y * 8) + x])
                for x in range(8):
                    for y in range(8):
                        prev_matrix.set_pixel(x, y, "grey")
            elif current_frame_number == len(frames):
                for x in range(8):
                    for y in range(8):
                        prev_matrix.set_pixel(
                            x, y,
                            frames[current_frame_number - 1][(y * 8) + x])
                for x in range(8):
                    for y in range(8):
                        next_matrix.set_pixel(x, y, "grey")
            else:
                for x in range(8):
                    for y in range(8):
                        next_matrix.set_pixel(
                            x, y,
                            frames[current_frame_number + 1][(y * 8) + x])
                for x in range(8):
                    for y in range(8):
                        prev_matrix.set_pixel(
                            x, y,
                            frames[current_frame_number - 1][(y * 8) + x])

    def left():
        global current_frame_number
        if current_frame_number > 1:
            current_frame_number -= 1
            load_frame()

    def right():
        global current_frame_number
        if current_frame_number < len(frames):
            current_frame_number += 1
            load_frame()

    def right_play(tin):
        global tstamp
        global current_frame_number
        global stopped
        global looping
        if tstamp == tin:
            if (current_frame_number < len(frames)) and not stopped:
                current_frame_number += 1
                load_frame()
            if (current_frame_number == len(frames)) and not stopped:

                button_play.enable()
                button_stop.disable()
                slider_framerate.enable()
                button_go_end.enable()
                button_go_start.enable()
                button_left.enable()
                button_right.enable()
                if checkbox_repeat.value == 1:
                    looping = True
                    current_frame_number = 0
                    play()

                else:
                    stopped = True

    def go_end():
        global current_frame_number
        global frames
        current_frame_number = len(frames)
        load_frame()

    def go_start():
        global current_frame_number
        current_frame_number = 1
        load_frame()

    def play():
        global framerate
        global stopped
        global current_frame_number
        global looping
        global tstamp
        if len(frames) > 1:
            button_play.disable()
            button_stop.enable()
            button_go_end.disable()
            button_go_start.disable()
            button_go_end.disable()
            button_left.disable()
            button_right.disable()
            slider_framerate.disable()
            stopped = False
            tstamp = str(time.time())
            t = int(1000 / framerate)
            if looping:
                for i in range(
                        1,
                        len(frames) + 1
                ):  # because we set current_frame_number = 0 when looping we need an extra iteration
                    frame_status_text.after(t * i, right_play, args=[tstamp])

            else:
                for i in range(1, len(frames)):
                    frame_status_text.after(t * i, right_play, args=[tstamp])

    def stop():
        global stopped
        stopped = True
        button_play.enable()
        button_stop.disable()
        slider_framerate.enable()
        button_go_end.enable()
        button_go_start.enable()
        button_left.enable()
        button_right.enable()
        #for i in range(len(frames)):
        #   frame_status_text.cancel(right_play)

    def export_as_python():
        global framerate
        filename = filedialog.asksaveasfilename(
            initialdir=HOME,
            title="Export file",
            filetypes=(("python files", "*.py"), ("all files", "*.*")))
        if len(filename) != 0:
            with open(filename, "w") as export_file:
                export_file.write("# m8tricks output file \n")
                export_file.write("from sense_hat import SenseHat\n")
                export_file.write("from time import sleep\n")
                export_file.write("sh = SenseHat()\n")
                export_file.write("sh.clear(0,0,0)\n")
                for e in range(1, len(frames) + 1):
                    export_file.write("sh.set_pixels(" + str(frames[e]) +
                                      ")\n")
                    export_file.write("sleep(1/" + str(framerate) + ")\n")

    def import_python():
        global framerate
        global current_frame_number
        current_frame_number = 1
        filename = filedialog.askopenfilename(initialdir=HOME,
                                              title="Select file",
                                              filetypes=(("python files",
                                                          "*.py"),
                                                         ("all files", "*.*")))
        if len(filename) != 0:
            with open(filename, "r") as import_file:
                line1 = import_file.readline()
                if line1 == "# m8tricks output file \n":
                    #print("This looks like an 8x8 Grid Editor file")
                    try:
                        for line in import_file:
                            if line.startswith("sh.set_pixels"):
                                grid = line[14:-2]
                                frames[
                                    current_frame_number] = ast.literal_eval(
                                        grid)
                                current_frame_number += 1
                        current_frame_number -= 1
                        load_frame()
                    except:
                        error("Import failed",
                              "Sorry, that file could not be imported")
                else:
                    not_our_file = yesno(
                        "Uh-oh",
                        "This doesn't look like a m8tricks file. Carry on trying to import it?"
                    )
                    if not_our_file == True:
                        try:
                            for line in import_file:
                                if line.startswith("sh.set_pixels"):
                                    grid = line[14:-2]
                                    frames[
                                        current_frame_number] = ast.literal_eval(
                                            grid)
                                    current_frame_number += 1
                            current_frame_number -= 1
                            load_frame()
                        except:
                            error("Import failed",
                                  "Sorry, that file could not be imported")

    def set_framerate():
        global framerate
        framerate = slider_framerate.value

    def sh_rotation():
        sh.set_rotation(int(combo_rotation.value))

    app = App(title="m8tricks", layout="grid", height=540, width=500)
    box_top = Box(app, layout="grid", grid=[0, 0, 5, 1])
    button_go_start = PushButton(box_top,
                                 command=go_start,
                                 grid=[0, 0, 2, 1],
                                 text="<<",
                                 image=HERE + "/images/endl.png")
    button_left = PushButton(box_top,
                             command=left,
                             grid=[2, 0, 2, 1],
                             text="<",
                             image=HERE + "/images/left.png")
    button_play = PushButton(box_top,
                             command=play,
                             grid=[4, 0, 2, 1],
                             text="PLAY",
                             image=HERE + "/images/play.png")
    button_stop = PushButton(box_top,
                             command=stop,
                             grid=[6, 0, 2, 1],
                             text="STOP",
                             enabled=False,
                             image=HERE + "/images/stop.png")
    button_right = PushButton(box_top,
                              command=right,
                              grid=[8, 0, 2, 1],
                              text=">",
                              image=HERE + "/images/right.png")
    button_go_end = PushButton(box_top,
                               command=go_end,
                               grid=[10, 0, 2, 1],
                               text=">>",
                               image=HERE + "/images/endr.png")
    checkbox_repeat = CheckBox(app, text=" Repeat", grid=[6, 0, 1, 1])
    box_framerate = Box(app, layout="grid", grid=[7, 0, 2, 1])
    box_framerate.set_border(0, "#ff0000")
    slider_framerate = Slider(box_framerate,
                              command=set_framerate,
                              grid=[0, 0],
                              start=1,
                              end=25)
    text_slider = Text(box_framerate,
                       text="Framerate (fps)",
                       grid=[0, 1],
                       size=10)

    matrix = Waffle(app,
                    height=8,
                    width=8,
                    dim=30,
                    command=p_clicked,
                    color="black",
                    grid=[0, 1, 7, 7])
    palette = Waffle(app,
                     height=10,
                     width=1,
                     dim=20,
                     command=col_select,
                     grid=[7, 1, 1, 7])
    palette.set_pixel(0, 0, "red")
    palette.set_pixel(0, 1, (0, 255, 0))
    palette.set_pixel(0, 2, "blue")
    palette.set_pixel(0, 3, "yellow")
    palette.set_pixel(0, 4, (100, 100, 100))
    palette.set_pixel(0, 5, "white")
    palette.set_pixel(0, 6, (255, 0, 255))
    palette.set_pixel(0, 7, "orange")
    palette.set_pixel(0, 8, "black")
    palette.set_pixel(0, 9, (66, 220, 240))
    box = Box(app, width=30, height=30, grid=[2, 10, 2, 1])
    box.bg = col
    text_current_col = Text(app, text="Selected Colour:", grid=[0, 10, 3, 1])
    text_rotation = Text(app, text="LED Rotation:", grid=[5, 10, 3, 1])
    combo_rotation = Combo(app,
                           options=["0", "90", "180", "270"],
                           grid=[8, 10, 2, 1],
                           command=sh_rotation)

    button_clear = PushButton(app,
                              command=clear_matrix,
                              grid=[8, 1],
                              text="Clear")
    button_clear.bg = col

    frame_status_text = Text(app,
                             text="Frame " +
                             str(current_frame_number).zfill(3) + " of " +
                             str(len(frames)).zfill(3),
                             grid=[0, 11, 3, 1])
    button_new_frame = PushButton(app,
                                  command=new_frame,
                                  grid=[3, 11, 2, 1],
                                  text="New",
                                  padx=28)
    button_new_frame = PushButton(app,
                                  command=copy_frame,
                                  grid=[5, 11, 2, 1],
                                  text="Duplicate")
    button_new_frame = PushButton(app,
                                  command=delete_frame,
                                  grid=[7, 11, 2, 1],
                                  text="Delete",
                                  padx=20)

    prev_matrix = Waffle(app,
                         height=8,
                         width=8,
                         dim=8,
                         color="grey",
                         grid=[0, 13, 3, 3])
    next_matrix = Waffle(app,
                         height=8,
                         width=8,
                         dim=8,
                         color="grey",
                         grid=[7, 13, 3, 3])

    menubar = MenuBar(app,
                      toplevel=["File"],
                      options=[[["Import file", import_python],
                                ["Export as", export_as_python]]])

    if os.path.isfile("/proc/device-tree/hat/product"):
        file = open("/proc/device-tree/hat/product", "r")
        hat = file.readline()
        if hat == "Sense HAT\x00":
            #print('Sense HAT detected')
            file.close()
        else:
            #print("No SenseHAT detected")
            no_hat_check()
    else:
        #print("No SenseHAT detected")
        no_hat_check()

    if not NOHAT:  # SenseHat detected to run normally
        from sense_hat import SenseHat
        sh = SenseHat()
        sh.clear(0, 0, 0)
    else:
        if ONEMU:  # No SenseHat - and we're on a Pi so try the emulator
            from sense_emu import SenseHat
            sh = SenseHat()
            sh.clear(0, 0, 0)
            NOHAT = False
        else:  #Disable SenseHat functions
            text_rotation.disable()
            combo_rotation.disable()

    app.display()