Exemplo n.º 1
0
 def refreshMode(self):
     self.modeSwitch["menu"].delete(0, 'end')
     modeOptions = getModeOptions()
     for option in modeOptions:
         self.modeSwitch["menu"].add_command(
             label=option, command=lambda o=option: self.modeVar.set(o))
     updateLabel(self.tlabel, self.label_text, "Refreshed available modes",
                 0)
     self.modeVar.set(modeOptions[0])
Exemplo n.º 2
0
    def delKey(self):
        hotkeys = getHotkeys()
        # Check if there are hotkeys to delete
        if not hotkeys:
            updateLabel(self.tlabel, self.label_text, "No hotkey to delete")
            return

        # Try to delete the hotkey if it exists, remove the file if there are no more hotkeys
        try:
            mode = self.modeVar.get()  # Get the current mode
            # Attempt to delete the hotkey
            hotkeys[mode][str(self.mob.eType)].pop(str(self.mob.ID))
            # Format the hotkey dict accordingly
            if not bool(hotkeys[mode][str(self.mob.eType)]):
                hotkeys[mode].pop(str(self.mob.eType))
                if not bool(hotkeys[mode]):
                    hotkeys.pop(mode)
                    if not bool(hotkeys):
                        remove("Data/hotkeys.json")

            # If there are still hotkeys to save, save them
            if bool(hotkeys):
                saveHotkeys(hotkeys)
            updateLabel(self.tlabel, self.label_text,
                        "Deleted last Midi input hotkey", 0)
        except KeyError:
            updateLabel(self.tlabel, self.label_text, "No hotkey to delete")
Exemplo n.º 3
0
    def delete(self):
        hotkeys = getHotkeys()      # Get the current list of hotkeys
        # Get the current mode and midi object
        mode, self.mob = parseDropdown(self.modeVar.get(), self.hotkeyVar.get())
        # Delete the hotkey
        hotkeys[mode][str(self.mob.eType)].pop(str(self.mob.ID))
        # Format the hotkey dict accordingly
        if not bool(hotkeys[mode][str(self.mob.eType)]):
            hotkeys[mode].pop(str(self.mob.eType))
            if not bool(hotkeys[mode]):
                hotkeys.pop(mode)
                if not bool(hotkeys):
                    remove("Data/hotkeys.json")

        # If there are still hotkeys to save, save them
        if bool(hotkeys):
            saveHotkeys(hotkeys)
        # Update the mode dropdown
        self.updateMode()
        updateLabel(self.tlabel, self.label_text, "Deleted selected hotkey")
        # Update the main label after a couple seconds
        self.master.after(2000, lambda: updateLabel(self.tlabel, self.label_text, "Make a selection below"))
Exemplo n.º 4
0
 def updateMode(self):
     updateLabel(self.mlabel, self.mode_text, self.modeVar.get(),
                 "Mode switch: " + self.modeVar.get())
Exemplo n.º 5
0
 def editHotkeys(self):
     updateLabel(self.tlabel, self.label_text,
                 "Make a selection in the popup")
     editGUI(self.taskQueueOut)
Exemplo n.º 6
0
    def workerTaskThread(self):
        while self.running:
            try:
                # Get task ID and GUI class that called the task
                ID, gMaster = self.taskQueueIn.get()

                # Handle different tasks by the parsed ID
                if ID == 1:     # Get midi input
                    updateLabel(gMaster.tlabel, gMaster.label_text, "Awaiting Midi input...")

                    # Get midi input and store in GUI class
                    checkMob = self.getMidi()
                    if type(checkMob) is mObject:
                        gMaster.mob = checkMob
                    else:
                        return

                    # Parse type of midi event for display
                    if gMaster.mob.eType == 11:
                        mEvent = "Encoder"
                    elif gMaster.mob.eType == 9:
                        mEvent = "Note ON"
                    elif gMaster.mob.eType == 8:
                        mEvent = "Note OFF"
                    else:
                        mEvent = "Unknown"

                    # Build label message
                    msg = mEvent + " | ID: " + str(gMaster.mob.ID) + " | Value: " + str(gMaster.mob.val)
                    updateLabel(gMaster.tlabel,
                                gMaster.label_text,
                                msg,
                                "Captured: " + msg)
                    gMaster.toggleButtons(tk.NORMAL)

                elif ID == 2:       # Get single hotkey
                    # Update label and get hotkey input from user
                    updateLabel(gMaster.tlabel, gMaster.label_text, "Enter hotkey")
                    hotkey = capHotkey()

                    # If we're in the edit window, get the correct mode, save the hotkey, update the label
                    if gMaster.master.title() == "Edit Hotkeys":
                        mode = parseDropdown(gMaster.modeVar.get(), gMaster.hotkeyVar.get())[0]
                        saveHotkey(hotkey, mode, gMaster.mob)
                        updateLabel(gMaster.tlabel, gMaster.label_text, "Mapped Midi input to: " + hotkey)
                        gMaster.updateMode()

                    # We're in the main window, get the correct mode, save the hotkey, update the label
                    else:
                        mode = gMaster.modeVar.get()
                        saveHotkey(hotkey, mode, gMaster.mob)
                        updateLabel(gMaster.tlabel, gMaster.label_text, "Mapped last Midi input to: " + hotkey, 0)

                    gMaster.toggleButtons(tk.NORMAL)
                    # Update main label after a couple seconds
                    gMaster.master.after(2000, lambda: updateLabel(gMaster.tlabel, gMaster.label_text,
                                                                   "Make a selection below"))

                elif ID == 3:       # Get two hotkeys
                    # Update label and get first hotkey input from user
                    updateLabel(gMaster.tlabel, gMaster.label_text, "Enter hotkey for decrease")
                    dHotkey = capHotkey()
                    # Sleep to allow time for key ups
                    sleep(0.25)

                    # Update label and get second hotkey input from user
                    updateLabel(gMaster.tlabel, gMaster.label_text, "Enter hotkey for increase")
                    iHotkey = capHotkey()

                    # If we're in the edit window, get the correct mode, save the hotkeys, update the label
                    if gMaster.master.title() == "Edit Hotkeys":
                        mode = parseDropdown(gMaster.modeVar.get(), gMaster.hotkeyVar.get())[0]
                        saveHotkey((dHotkey, iHotkey), mode, gMaster.mob)
                        updateLabel(gMaster.tlabel,
                                    gMaster.label_text,
                                    "Mapped Midi input to decrease: " + dHotkey + " and increase: " + iHotkey)
                        gMaster.updateMode()

                    # We're in the main window, get the correct mode, save the hotkey, update the label
                    else:
                        mode = gMaster.modeVar.get()
                        saveHotkey((dHotkey, iHotkey), mode, gMaster.mob)
                        updateLabel(gMaster.tlabel,
                                    gMaster.label_text,
                                    "Mapped last Midi input to decrease: " + dHotkey + " and increase: " + iHotkey,
                                    0)
                    gMaster.toggleButtons(tk.NORMAL)
                    # Update main label after a copule seconds
                    gMaster.master.after(2000, lambda: updateLabel(gMaster.tlabel, gMaster.label_text,
                                                                   "Make a selection below"))

            except Queue.Empty:
                # If queue is empty we wait 100 ms before trying to process again
                sleep(0.1)
        return