Esempio n. 1
0
 def keyReleased(self, e):
     if e.name == config(MODIFY_KEY):
         self.modifierPressed = False
     if kb.matches(e, config(CANCEL_KEY)):
         self.isCancelPressed = False
     if kb.matches(e, config(RELOAD_KEY)):
         self.isReloadPressed = False
Esempio n. 2
0
    def renderImageLayer(self, overlayBase, soundList):
        imageLayer = Image.new("RGBA",
                               overlayBase.size,
                               color=(255, 255, 255, 0))

        imageEdgeLength = config(SOUND_IMAGE_EDGE_LENGTH)

        absoluteCenterX = int(self.imageXStart + imageEdgeLength * 1.5 +
                              self.imageSpacing)
        absoluteCenterY = self.height // 2

        for i in range(len(soundList)):
            if soundList[i].image is None:
                continue

            xIndex = i % 3 - 1
            yIndex = 1 - i // 3

            imageCenterX = absoluteCenterX + (imageEdgeLength +
                                              self.imageSpacing) * xIndex
            imageCenterY = absoluteCenterY + (imageEdgeLength +
                                              self.imageSpacing) * yIndex

            imageLayer.paste(
                soundList[i].image,
                (imageCenterX - imageEdgeLength // 2, imageCenterY -
                 imageEdgeLength // 2, imageCenterX + imageEdgeLength // 2,
                 imageCenterY + imageEdgeLength // 2))

        overlayBase.alpha_composite(imageLayer, (0, 0))
        return overlayBase
Esempio n. 3
0
    def tryUpdate(self):
        if config(OVERLAY_MODE) == "images":
            overlayPath = config(RESOURCE_PATH) + config(OVERLAY_IMAGES)
            renderingFunction = self.renderImageLayer
        else:
            overlayPath = config(RESOURCE_PATH) + config(OVERLAY_LABELS)
            renderingFunction = self.renderTextLayer

        soundMatrix = GLOBALS.SOUNDS_BY_STROKES
        try:
            self.updateWidget(overlayPath, soundMatrix, renderingFunction)
        except Exception as e:
            s = "Error starting Overlay:\n"
            s += str(e) + "\n\n"
            s += "Make sure '{}' points to a valid image file.\n".format(
                overlayPath)

            raise RuntimeError(s)
Esempio n. 4
0
 def runMacro(self):
     subprocess.run(config(ADDITIONAL_MACRO))
Esempio n. 5
0
 def playNotification(self, sound):
     self.playOneShotSound(config(PRIVATE_DEVICE), sound)
Esempio n. 6
0
 def playGlobal(self, sound):
     for device in [config(PRIVATE_DEVICE), config(PUBLIC_DEVICE)]:
         self.playOneShotSound(device, sound)
Esempio n. 7
0
    def keyPressed(self, e):
        # Due to the queue nature of the events, this switch can only be used from outside
        if self.acceptHotkeys:
            if kb.matches(e, config(MODIFY_KEY)):
                self.modifierPressed = True
                
            elif kb.matches(e, config(TOGGLE_ACTIVE_KEY)) and self.modifierPressed:
                self.toggleSoundboardActive()
                
            elif kb.matches(e, config(RUN_MACRO_KEY)) and self.modifierPressed:
                self.runMacro()

            elif kb.matches(e, config(CANCEL_KEY)):
                self.invalidateHotkey()
                self.stopPlayback()
                if not self.isCancelPressed:
                    self.lastCancelPress = e.time
                    self.isCancelPressed = True
                else:
                    if self.lastCancelPress + config(LONG_HOLD_TIME) < e.time:
                        self.shutDown()
                        
            elif kb.matches(e, config(RELOAD_KEY)):
                if not self.isReloadPressed:
                    self.lastReloadPress = e.time
                    self.isReloadPressed = True
                else:
                    if self.lastReloadPress + config(LONG_HOLD_TIME) < e.time:
                        self.stopPlayback()
                        self.playNotification(resolveSoundByName(RELOAD_SOUND))
                        self.reload()
                        # Reset countdown to reload
                        # Don't use event time here. Significant time has passed
                        self.lastReloadPress = time.time()

            # Handle choosing of sounds
            elif e.name in config(HOTBAR_KEYS) and self.modifierPressed and self.soundboardActive:
                if self.lastHotBarButton is not None:
                    self.playGlobal(resolveSoundByStrokes(config(HOTBAR_KEYS)[self.lastHotBarButton.name], config(HOTBAR_KEYS)[e.name]))
                    self.invalidateHotkey()
                else:
                    self.lastHotBarButton = e
                    self.overlay.drawOverlay(config(HOTBAR_KEYS)[e.name])
                    self.overlayTimer = Timer(config(OVERLAY_STAY_DURATION), self.invalidateHotkey)
                    self.overlayTimer.start()