Пример #1
0
class Ui_info_box(object):
    def setupUi(self, info_box):
        info_box.setObjectName(_fromUtf8("info_box"))
        info_box.resize(317, 174)
        info_box.setFlat(False)
        info_box.setCheckable(False)
        info_box.setChecked(False)
        self.weather_icon = QSvgWidget(info_box)
        self.weather_icon.setGeometry(QtCore.QRect(30, 50, 50, 50))
        self.weather_icon.setObjectName(_fromUtf8("weather_icon"))
        self.temp_high = QtGui.QLabel(info_box)
        self.temp_high.setGeometry(QtCore.QRect(110, 50, 181, 17))
        self.temp_high.setObjectName(_fromUtf8("temp_high"))
        self.condition = QtGui.QLabel(info_box)
        self.condition.setGeometry(QtCore.QRect(20, 110, 251, 17))
        self.condition.setObjectName(_fromUtf8("condition"))
        self.temp_low = QtGui.QLabel(info_box)
        self.temp_low.setGeometry(QtCore.QRect(110, 80, 171, 17))
        self.temp_low.setObjectName(_fromUtf8("temp_low"))
        self.weather_setter = QtGui.QPushButton(info_box)
        self.weather_setter.setGeometry(QtCore.QRect(170, 140, 114, 27))
        self.weather_setter.setObjectName(_fromUtf8("weather_setter"))
        self.quitter = QtGui.QPushButton(info_box)
        self.quitter.setGeometry(QtCore.QRect(50, 140, 84, 22))
        self.quitter.setObjectName(_fromUtf8("quitter"))

        self.retranslateUi(info_box)
        QtCore.QMetaObject.connectSlotsByName(info_box)

    def retranslateUi(self, info_box):
        info_box.setWindowTitle(QtGui.QApplication.translate("info_box", "fail", None, QtGui.QApplication.UnicodeUTF8))
        info_box.setTitle(QtGui.QApplication.translate("info_box", "forecast_date", None, QtGui.QApplication.UnicodeUTF8))
        self.temp_high.setText(QtGui.QApplication.translate("info_box", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
        self.condition.setText(QtGui.QApplication.translate("info_box", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
        self.temp_low.setText(QtGui.QApplication.translate("info_box", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
        self.weather_setter.setText(QtGui.QApplication.translate("info_box", "Set Weather", None, QtGui.QApplication.UnicodeUTF8))
        self.quitter.setText(QtGui.QApplication.translate("info_box", "Quit", None, QtGui.QApplication.UnicodeUTF8))
Пример #2
0
class RadioWidget(QtGui.QWidget):

    currentFrequency = 88.1
    scanInterval = 0.5
    scanDirection = "none"
    scanTimer = None
    playing = False
    radioManager = None

    buttonDefaultStyle = "border: 2px solid #000;"
    buttonPressedStyle = "border: 2px solid #fff;"

    presetFrameStyle = "border: 2px solid #7f7f7f; border-radius: 10px; margin:10px; "
    presetFrameSelectedStyle = "border: none; background-color: #fff200; border-radius: 10px; margin:10px; "

    presetContentsStyle = "border: none; color:#fff"
    presetContentsSelectedStyle = "border: none; color:#000"

    settingPreset = False

    def __init__(self, parent):
        super(RadioWidget, self).__init__(parent)
        self.resize(320, 240)

        freqFont = QtGui.QFont()
        freqFont.setPointSize(35)

        self.frequencyDisplay = QtGui.QLCDNumber(self)
        self.frequencyDisplay.setGeometry(QtCore.QRect(90, 15, 131, 51))
        self.frequencyDisplay.setFont(freqFont)
        self.frequencyDisplay.setStyleSheet('color: white')
        self.frequencyDisplay.setFrameShape(QtGui.QFrame.NoFrame)
        self.updateRadioFrequency()

        self.slideUpFrame = QFrame(self)
        self.slideUpFrame.setGeometry(QtCore.QRect(230, 15, 50, 50))
        self.slideUpFrame.setFrameShape(QtGui.QFrame.Box)
        self.slideUpFrame.setFrameShadow(QtGui.QFrame.Plain)
        self.slideUpFrame.setStyleSheet(self.buttonDefaultStyle)

        self.slideUpButton = QSvgWidget("icons/forward3.svg",
                                        self.slideUpFrame)
        self.slideUpButton.setGeometry(QtCore.QRect(5, 5, 40, 40))

        pressable(self.slideUpButton).connect(self.doFreqUpPressed)

        self.slideDownFrame = QFrame(self)
        self.slideDownFrame.setGeometry(QtCore.QRect(50, 15, 50, 50))
        self.slideDownFrame.setFrameShape(QtGui.QFrame.Box)
        self.slideDownFrame.setFrameShadow(QtGui.QFrame.Plain)
        self.slideDownFrame.setStyleSheet(self.buttonDefaultStyle)

        self.slideDownButton = QSvgWidget("icons/backward2.svg",
                                          self.slideDownFrame)
        self.slideDownButton.setGeometry(QtCore.QRect(0, 5, 40, 40))

        pressable(self.slideDownButton).connect(self.doFreqDownPressed)

        self.horizontalLayoutWidget = QtGui.QWidget(self)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 100, 300, 80))
        self.horizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setAlignment(self.horizontalLayoutWidget,
                                           QtCore.Qt.AlignCenter)
        self.horizontalLayout.setMargin(0)

        QtCore.QMetaObject.connectSlotsByName(self)

    def fillPresets(self, presets, selected=False):
        self.settingPreset = selected
        print("Filling Radio presets")
        self.clearPresets()
        font = QtGui.QFont()
        font.setPointSize(18)
        self.changingPreset = None
        for x in range(0, len(presets)):
            pre = presets[x]
            presetButton = QFrame()
            presetButton.setFrameShape(QtGui.QFrame.Box)

            if (selected == True):
                presetButton.setStyleSheet(self.presetFrameSelectedStyle)
            else:
                presetButton.setStyleSheet(self.presetFrameStyle)
            presetButton.freq = pre.frequency
            presetButton.preID = pre.id
            releaseableSender(presetButton).connect(self.presetSelected)

            presetDisplay = QtGui.QLabel(presetButton)
            presetDisplay.setGeometry(QtCore.QRect(5, 0, 90, 80))
            presetDisplay.setAlignment(QtCore.Qt.AlignCenter)
            if (selected == True):
                presetDisplay.setStyleSheet(self.presetContentsSelectedStyle)
            else:
                presetDisplay.setStyleSheet(self.presetContentsStyle)
            presetDisplay.setFont(font)
            presetDisplay.setText(str(pre.frequency))

            self.horizontalLayout.addWidget(presetButton)

    def presetSelected(self, obj):
        if (self.settingPreset):
            self.emit(QtCore.SIGNAL('presetChanged'),
                      [obj.preID, self.currentFrequency])
        else:
            print("preset selected: " + str(obj.freq))
            self.currentFrequency = float(obj.freq)
            self.updateRadioFrequency()
            self.emit(QtCore.SIGNAL('frequencyChanged'), self.currentFrequency)

    def clearPresets(self):
        for i in reversed(range(self.horizontalLayout.count())):
            self.horizontalLayout.itemAt(i).widget().deleteLater()

    def updateRadioFrequency(self):
        self.frequencyDisplay.display("{0:.1f}".format(self.currentFrequency))
        newFreq = str(self.frequencyDisplay.value())

    def isFreqValid(self, freq):
        if (freq >= 88.1 and freq <= 108.1):
            return True
        else:
            return False

    def doFreqDownPressed(self):
        self.scanDirection = "down"
        self.doChangeFrequency()

    def doFreqUpPressed(self):
        self.scanDirection = "up"
        self.doChangeFrequency()

    def doChangeFrequency(self):
        t = Thread(target=self.changeFrequency, args=(self, ))
        t.start()

    def changeFrequency(self, parent):

        freq = parent.currentFrequency
        if (self.scanDirection == "down"):
            freq = freq - 0.2
        elif (self.scanDirection == "up"):
            freq = freq + 0.2
        if (self.isFreqValid(freq)):
            parent.currentFrequency = freq
            parent.updateRadioFrequency()
Пример #3
0
class BedbotWidget(QtGui.QWidget):

    loadedModules = None

    currentWidget = None
    currentWidgetIndex = 2

    listenToButtons = True

    hasIOLibraries = False

    autoCloseTimer = None

    currentAudioModule = None
    pinConfig = {}

    pinCallbacks = []
    disabledPins = []
    currentButtonIndicators = []

    pinStatusTimer = None

    def __init__(self, parent, modules):
        super(BedbotWidget, self).__init__(parent)

        self.resize(320, 240)

        self.loadPinConfig()

        self.loadedModules = modules

        self.connect(self, QtCore.SIGNAL('processPigpioEvent'),
                     self.pinEventCallback)

        self.initializeMenu()

        menuWidgets = []
        for m in self.loadedModules:
            self.connect(m, QtCore.SIGNAL('logEvent'), self.logEvent)
            """For a module to be used in the app, it must be located in the Modules folder and have 
            an 'Enabled' attribute set to True.  If it's not there, or it's false, the module is ignored
            """
            if (hasattr(m, "Enabled") == True and m.Enabled == True):
                """Scans all active modules to see if they should be added to the menu.  Module must have 'addMenuWidget' function """
                if (self.moduleHasFunction(m, "addMenuWidget")):
                    if (hasattr(m, "menuOrder") == True):
                        menuWidgets.insert(m.menuOrder, m)
                    else:
                        menuWidgets.insert(len(menuWidgets), m)
                """Scans all active modules to see if they require the pin configuration."""
                if (self.moduleHasFunction(m, "setPin")):
                    m.setPin(self.pinConfig)
                """Allows a module to tell other modules to send output on a specific pin (for the audio relay)"""
                self.connect(m, QtCore.SIGNAL('pinRequested'),
                             self.pinRequestedCallback)
                """Tells BedbotWidget to show a popup according to specifications provided"""
                self.connect(m, QtCore.SIGNAL('showPopup'),
                             self.showPopupCallback)
                """Tells BedbotWidget which colored circle indicators to display"""
                self.connect(m, QtCore.SIGNAL('requestButtonPrompt'),
                             self.buttonPromptRequestCallback)
                """Event that modules can call to invoke methods on other modules without knowing about them beforehand """
                self.connect(m, QtCore.SIGNAL('broadcastModuleRequest'),
                             self.broadcastModuleRequestCallback)
                """Allows active modules to send signals to all other modules to stop audio playback"""
                self.connect(m, QtCore.SIGNAL('stopAllAudio'),
                             self.stopAllAudioCallback)
                """If a modules uses the audio output, it must have the attribute 'UsesAudio' and have it set to True
                If it does, than it can use the audio status display in BedbotWidget to display it's current status
                """
                if (hasattr(m, "UsesAudio") == True and m.UsesAudio == True):
                    self.connect(m, QtCore.SIGNAL('audioStarted'),
                                 self.audioStartedCallback)
                    self.connect(m, QtCore.SIGNAL('audioStopped'),
                                 self.audioStoppedCallback)
        """ After all modules are loaded, use the attribute 'menuOrder' on active modules to organize the menu icons"""
        for i in range(0, len(menuWidgets)):
            menuWidgets[i].menuOrder = i
            self.addMainWidget(menuWidgets[i])

        self.menu_widget.configureMenu()
        self.toggleMainMenu(True)
        QtCore.QMetaObject.connectSlotsByName(self)

    def broadcastModuleRequestCallback(self,
                                       caller,
                                       methodToCall,
                                       methodArgs=None,
                                       callbackMethod=None,
                                       targetModuleName=None):
        """Callback for the 'broadcastModuleRequest' event that modules can call to invoke methods on other modules
        without knowing about them beforehand
        """
        results = []
        for m in self.loadedModules:
            if (targetModuleName != None
                    and type(m).__name__ != targetModuleName):
                continue
            if (hasattr(m, "Enabled") == True and m.Enabled == True):
                if (self.moduleHasFunction(m, methodToCall)):
                    if (callbackMethod != None):
                        if (methodArgs != None):
                            results.append(
                                getattr(m, methodToCall)(methodArgs))
                        else:
                            results.append(getattr(m, methodToCall)())
                    else:
                        getattr(m, methodToCall)(methodArgs)

        if (callbackMethod != None and hasattr(caller, "Enabled") == True
                and caller.Enabled == True):
            if (self.moduleHasFunction(caller, callbackMethod)):
                getattr(caller, callbackMethod)(results)

    def stopAllAudioCallback(self):
        self.stopAllAudio()

    def buttonPromptRequestCallback(self, buttonsToPrompt):
        self.clearButtonPrompts()
        for x in buttonsToPrompt:
            if (x == "ON"):
                self.onButtonIndicator.setVisible(True)
            elif (x == "CONTEXT"):
                self.contextButtonIndicator.setVisible(True)
            elif (x == "OFF"):
                self.offButtonIndicator.setVisible(True)

    def clearButtonPrompts(self):
        self.onButtonIndicator.setVisible(False)
        self.contextButtonIndicator.setVisible(False)
        self.offButtonIndicator.setVisible(False)

    def showPopupCallback(self,
                          caller,
                          msg=None,
                          popupType=None,
                          popupArgs=None):

        self.customPopup = Popup(self)
        self.connect(self.customPopup, QtCore.SIGNAL('popupResult'),
                     self.popupCallback)
        if (popupType == None):
            self.customPopup.doWait(msg)
        else:
            if (popupType == "optionSelect" and popupArgs != None):
                self.customPopup.optionSelect(msg, popupArgs)
            elif (popupType == "numberSelect"):
                self.customPopup.numberSelect(msg, popupArgs)
            elif (popupType == "alarm"):
                self.customPopup.alarm(popupArgs)
            elif (popupType == "snooze"):
                self.customPopup.snooze(popupArgs)

    def popupCallback(self, result):
        for m in self.loadedModules:
            if (self.moduleHasFunction(m, "popupResult")):
                m.popupResult(result)

    def pinRequestedCallback(self, pin):
        self.pinEventCallback(pin)

    def audioStoppedCallback(self, sourceModule):
        self.currentAudioModule = None
        self.stopAllAudio(self.currentAudioModule)
        self.statusDisplay.setText("")

    def audioStartedCallback(self, sourceModule):
        self.currentAudioModule = sourceModule
        self.stopAllAudio(self.currentAudioModule)
        self.statusDisplay.setText("")
        if (self.moduleHasFunction(self.currentAudioModule,
                                   "getAudioStatusDisplay")):
            self.statusDisplay.setText(
                self.currentAudioModule.getAudioStatusDisplay())

    def stopAllAudio(self, ignoredModule=None):
        for m in self.loadedModules:
            if (hasattr(m, "UsesAudio") == True and m.UsesAudio == True
                    and (ignoredModule == None or
                         (ignoredModule != None and m != ignoredModule))):
                if (self.moduleHasFunction(m, "stop")):
                    m.stop()

    def logEvent(self, evtStr):
        print(evtStr)
        logging.info(str(evtStr))

    def initializeMenu(self):
        self.menu_widget = DynamicMenu(self)
        self.menu_widget.setGeometry(QtCore.QRect(10, 10, 320, 190))
        self.menu_widget.setVisible(True)
        self.connect(self.menu_widget, QtCore.SIGNAL('showWidget'),
                     self.showWidgetCallback)

        self.menuButton = QSvgWidget("icons/three-bars.svg", self)
        self.menuButton.setGeometry(QtCore.QRect(10, 200, 30, 35))
        pressableSender(self.menuButton).connect(self.menuButtonPressed)
        self.menuButton.setVisible(False)

        self.onButtonIndicator = ButtonIndicator(self, 30, "green")
        self.onButtonIndicator.setGeometry(QtCore.QRect(50, 202, 30, 30))
        self.onButtonIndicator.setVisible(False)

        self.contextButtonIndicator = ButtonIndicator(self, 30, "blue")
        self.contextButtonIndicator.setGeometry(QtCore.QRect(80, 202, 30, 30))
        self.contextButtonIndicator.setVisible(False)

        self.offButtonIndicator = ButtonIndicator(self, 30, "red")
        self.offButtonIndicator.setGeometry(QtCore.QRect(110, 202, 30, 30))
        self.offButtonIndicator.setVisible(False)

        font = QtGui.QFont()
        font.setPointSize(15)

        self.statusDisplay = QtGui.QLabel(self)
        self.statusDisplay.setGeometry(QtCore.QRect(150, 200, 140, 35))
        self.statusDisplay.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignVCenter)
        self.statusDisplay.setStyleSheet('color: #eaf736')
        self.statusDisplay.setFont(font)
        pressableSender(self.statusDisplay).connect(self.audioStatusPressed)

    def audioStatusPressed(self, obj):
        if (self.currentAudioModule != None):
            self.menu_widget.setMenuItemSelected(self.currentAudioModule)
            self.showWidgetCallback(self.currentAudioModule)

    def toggleMainMenu(self, showMenu):
        if (showMenu):
            self.hideMainWidgets()
            self.autoCloseTimer = QTimer()
            self.autoCloseTimer.timeout.connect(self.autoCloseMainMenu)
            self.autoCloseTimer.start(5000)
        self.menuButton.setVisible(not showMenu)
        self.menu_widget.setVisible(showMenu)

    def autoCloseMainMenu(self):
        self.autoCloseTimer.stop()
        self.autoCloseTimer = None
        if (self.currentWidget != None):
            self.showWidgetCallback(self.currentWidget)

    def triggerMenuButton(self):
        self.menuButtonTimer.stop()
        self.menuButton.load("icons/three-bars.svg")
        self.toggleMainMenu(True)

    def menuButtonPressed(self, obj):
        self.menuButton.load("icons/three-barsSelected.svg")
        self.menuButtonTimer = QTimer()
        self.menuButtonTimer.timeout.connect(self.triggerMenuButton)
        self.menuButtonTimer.start(500)

    def showWidgetCallback(self, w):
        if (self.autoCloseTimer != None):
            self.autoCloseTimer.stop()
            self.autoCloseTimer = None
        self.hideMainWidgets()
        w.showWidget()
        self.currentWidget = w
        self.toggleMainMenu(False)

    def hideMainWidgets(self):
        self.clearButtonPrompts()
        for m in self.loadedModules:
            if (hasattr(m, "Enabled") == True and m.Enabled == True):
                if (self.moduleHasFunction(m, "hideWidget")):
                    m.hideWidget()
        self.menu_widget.setVisible(False)

    def moduleHasFunction(self, m, functionName):
        """Helper to determine if a module has a specific function available"""
        funct = getattr(m, functionName, None)
        if (callable(funct)):
            return True
        return False

    def addMainWidget(self, w):
        """Adds a widget that has Enabled set to true, has a method called 'addMenuWidget' and has an optional menuOrder parameter"""
        w.addMenuWidget(self)
        self.menu_widget.addMenuItem(w)

    def simulateButton(self, buttonDesc):
        """Simulates a button call, usually for debug purposes"""
        self.pinEventCallback(self.pinConfig[buttonDesc])

    def pinEventCallback(self, channel):
        self.logEvent("pin callback for channel: " + str(channel))
        if (hasattr(self, "customPopup") == True):
            self.customPopup.processPin(self.pinConfig, channel)
        #else:
        for m in self.loadedModules:
            if (hasattr(m, "ListenForPinEvent") == True
                    and m.ListenForPinEvent == True
                    and self.moduleHasFunction(m, "processPinEvent")):
                m.processPinEvent(channel)

    def pigpioCallback(self, gpio, level, tick):
        currentlyDisabled = gpio in self.disabledPins
        if (currentlyDisabled == False):
            self.disabledPins.append(gpio)
            self.emit(QtCore.SIGNAL('processPigpioEvent'), gpio)
            t = Thread(target=self.reenablePin, args=(
                self,
                gpio,
            ))
            t.start()

    def reenablePin(self, parent, pin):
        """Renables a pin after it fires to prevent extra event from firing"""
        time.sleep(1)
        print("reenable pin: " + str(pin))
        parent.disabledPins.remove(pin)

    def loadPinConfig(self):
        """Loads the pinConfig.json file that specifies the pins used and a name"""
        with open("pinConfig.json") as data_file:
            data = json.load(data_file)
        self.pinConfig = {}

        if (hasIOLibraries):
            self.pi = pigpio.pi()

        for x in range(0, len(data["pins"])):
            p = data["pins"][x]
            self.pinConfig[p["type"]] = p["pin"]
            if (hasIOLibraries and self.listenToButtons == True
                    and p["listenForPress"] == True):
                self.logEvent("adding event to pin: " + str(p["pin"]))
                self.pi.set_pull_up_down(p["pin"], pigpio.PUD_DOWN)
                cb1 = self.pi.callback(p["pin"], pigpio.RISING_EDGE,
                                       self.pigpioCallback)

    def doClose(self):

        try:
            self.customPopup.closePopup()
        except Exception:
            print("problem disposing of popup")

        for m in self.loadedModules:
            try:
                m.dispose()
            except BaseException:
                print("problem disposing")
                print(m)
        try:
            self.pi.stop()
        except BaseException:
            print("problem cleaning up IO")
Пример #4
0
class MainWindow(QWidget):
    """
    Create a surface for the chessboard.
    """
    def __init__(self, board_configuration=None):
        """
        Initialize the chessboard.
        """
        super().__init__()

        self.setWindowTitle("Chess GUI")
        self.setGeometry(300, 300, 800, 800)

        self.widgetSvg = QSvgWidget(parent=self)
        self.widgetSvg.setGeometry(10, 10, 600, 600)

        self.boardSize = min(self.widgetSvg.width(),
                             self.widgetSvg.height())
        self.coordinates = True
        self.margin = 0.05 * self.boardSize if self.coordinates else 0
        self.squareSize = (self.boardSize - 2 * self.margin) / 8.0
        self.pieceToMove = [None, None]
        self.pieceToInsert = [None, None]
        self.board = chess.Board()
        if(board_configuration):
            self.board.set_piece_map(board_configuration)
        self.drawBoard()


    @pyqtSlot(QWidget)
    def mousePressEvent(self, event):
        """
        Handle left mouse clicks and enable moving chess pieces by
        clicking on a chess piece and then the target square.

        Moves must be made according to the rules of chess because
        illegal moves are suppressed.
        """
        if event.x() <= self.boardSize and event.y() <= self.boardSize:
            # if event.buttons() == Qt.RightButton:
            if self.margin < event.x() < self.boardSize - self.margin and self.margin < event.y() < self.boardSize - self.margin:
                file = int((event.x() - self.margin) / self.squareSize)
                rank = 7 - int((event.y() - self.margin) / self.squareSize)
                square = chess.square(file, rank)
                piece = self.board.piece_at(square)
                coordinates = "{}{}".format(chr(file + 97), str(rank + 1))
                if self.pieceToInsert[0] is not None and self.pieceToInsert[1] is not None:
                    print("INSERTING.....")
                    self.board.set_piece_at(square, chess.Piece(self.pieceToInsert[0], self.pieceToInsert[1]))
                    self.pieceToInsert = [None, None]
                elif self.pieceToMove[0] is not None:
                    #move = chess.Move.from_uci("{}{}".format(self.pieceToMove[1], coordinates))
                    # if move in self.board.legal_moves:
                    self.board.set_piece_at(square, self.pieceToMove[0])
                    self.board.set_piece_at(self.pieceToMove[1], None)
                    # self.board.push(move)
                    piece = None
                    coordinates = None
                
                self.pieceToMove = [piece, square]
                self.drawBoard()

    @pyqtSlot(QWidget)
    def keyPressEvent(self, event):
        """
        Handle left mouse clicks and enable moving chess pieces by
        clicking on a chess piece and then the target square.

        Moves must be made according to the rules of chess because
        illegal moves are suppressed.
        """
        pressed = event.key()
        print(pressed)
        if(pressed == 81):
            print("You want to insert a queen -- press q")
            self.pieceToInsert[0] = piece_name_index['queen']
        elif(pressed == 75):
            print("You want to insert a king -- press k")
            self.pieceToInsert[0] = piece_name_index['king']
        elif(pressed == 78):
            print("You want to insert a knight -- press n")
            self.pieceToInsert[0] = piece_name_index['knight']
        elif(pressed == 80):
            print("You want to insert a pawn -- press p")
            self.pieceToInsert[0] = piece_name_index['pawn']
        elif(pressed == 66):
            print("You want to insert a bishop -- press b")
            self.pieceToInsert[0] = piece_name_index['bishop']
        elif(pressed == 82):
            print("You want to insert a rook -- press r")
            self.pieceToInsert[0] = piece_name_index['rook']
        elif(pressed == 49):
            print("You want white")
            if(self.pieceToInsert[0]):
                self.pieceToInsert[1] = True
        elif(pressed == 48):
            print("You want black")
            if(self.pieceToInsert[0]):
                self.pieceToInsert[1] = False
        elif(pressed == 16777220):
            print("You are finished with the GUI")
            self.close()

    def drawBoard(self):
        global analyzed_board
        """
        Draw a chessboard with the starting position and then redraw
        it for every new move.
        """
        self.boardSvg = self.board._repr_svg_().encode("UTF-8")
        self.drawBoardSvg = self.widgetSvg.load(self.boardSvg)
        analyzed_board = self.board.copy()
        return self.drawBoardSvg

    def show(self):
        super().show()
        return self.board