Ejemplo n.º 1
0
    def __init__(self, backlight_sysfs_path: Path) -> None:
        QMainWindow.__init__(self)

        self.backlight = Backlight(backlight_sysfs_path)

        self.screenshot = QPixmap(get_image_path("raspbian.png"))
        self.image_display_on = load_display_image(
            get_image_path("display_on.png"))
        self.image_display_off = load_display_image(
            get_image_path("display_off.png"))

        widget = QWidget()
        checkbox_layout = QBoxLayout(QBoxLayout.LeftToRight)
        main_layout = QBoxLayout(QBoxLayout.TopToBottom)
        brightness_slider_label = QLabel("Brightness", widget)
        self.live_screen_checkbox = QCheckBox("Show live screen", widget)
        self.live_screen_checkbox.stateChanged.connect(self.update_screen)
        self.power_checkbox = QCheckBox("Power", widget)
        self.power_checkbox.stateChanged.connect(self.write_power_change)
        self.brightness_slider = QSlider(Qt.Horizontal, widget)
        self.brightness_slider.valueChanged.connect(
            self.write_brightness_change)
        self.brightness_slider.setSingleStep(1)
        self.brightness_slider.setMinimum(0)
        self.brightness_slider.setMaximum(100)
        self.screen_image = QLabel()
        checkbox_layout.addWidget(self.power_checkbox)
        checkbox_layout.addWidget(self.live_screen_checkbox)
        main_layout.addLayout(checkbox_layout)
        main_layout.addWidget(brightness_slider_label)
        main_layout.addWidget(self.brightness_slider)
        main_layout.addWidget(self.screen_image)
        widget.setLayout(main_layout)

        self.thread = FileWatcherThread(self, backlight_sysfs_path)
        self.thread.file_changed.connect(self.update_widgets)
        self.thread.start()

        self.timer = QTimer(self)
        self.timer.setInterval(100)
        self.timer.timeout.connect(self.update_screen)
        self.timer.start()

        self.update_widgets("bl_power")
        self.update_widgets("brightness")

        self.setCentralWidget(widget)
        self.setWindowTitle('Raspberry Pi 7" display backlight emulator')
        self.setWindowIcon(QIcon(get_image_path("icon.png")))
Ejemplo n.º 2
0
    def __init__(self, parent):
        super(AboutDialog, self).__init__(parent, title="About SMB3Foundry")

        main_layout = QBoxLayout(QBoxLayout.LeftToRight, self)

        image = QPixmap(str(data_dir.joinpath("foundry.ico"))).scaled(200, 200)

        icon = QLabel(self)
        icon.setPixmap(image)

        main_layout.addWidget(icon)

        text_layout = QBoxLayout(QBoxLayout.TopToBottom)

        text_layout.addWidget(QLabel(f"SMB3 Foundry v{get_current_version_name()}", self))
        text_layout.addWidget(HorizontalLine())
        text_layout.addWidget(LinkLabel(self, f'By <a href="{LINK_SMB3F}">Michael</a>'))
        text_layout.addWidget((QLabel("", self)))
        text_layout.addWidget(QLabel("With thanks to:", self))
        text_layout.addWidget(
            LinkLabel(self, f'<a href="{LINK_HUKKA}">Hukka</a> for <a href="{LINK_SMB3WS}">SMB3 Workshop</a>')
        )
        text_layout.addWidget(
            LinkLabel(
                self,
                f'<a href="{LINK_SOUTHBIRD}">Captain Southbird</a> '
                f'for the <a href="{LINK_DISASM}">SMB3 Disassembly</a>',
            )
        )
        text_layout.addWidget(
            LinkLabel(self, f'<a href="{LINK_PIJOKRA}">PiJoKra</a> for helping to parse the disassembly')
        )
        text_layout.addWidget(
            LinkLabel(
                self,
                f'<a href="{LINK_BLUEFINCH}">BlueFinch</a>, ZacMario and '
                f'<a href="{LINK_SKY}">SKJyannick</a> for testing and sanity checking',
            )
        )
        text_layout.addWidget(
            QLabel(
                "Spinzig for compiling the enemy incompatibilities.",
                self
            )
        )

        main_layout.addLayout(text_layout)
Ejemplo n.º 3
0
    def __init__(self, config):
        assertMainThread()
        super().__init__(config)

        # state
        self.preventSeek = False
        self.beginTime = None
        self.timeRatio = 1.0

        # gui
        srv = Services.getService("MainWindow")
        config.configLoaded.connect(self.restoreState)
        config.configAboutToSave.connect(self.saveState)
        self.config = config
        playbackMenu = srv.menuBar().addMenu("&Playback")

        style = QApplication.style()
        self.actStart = QAction(QIcon.fromTheme("media-playback-start", style.standardIcon(QStyle.SP_MediaPlay)),
                                "Start Playback", self)
        self.actPause = QAction(QIcon.fromTheme("media-playback-pause", style.standardIcon(QStyle.SP_MediaPause)),
                                "Pause Playback", self)
        self.actPause.setEnabled(False)
        self.actStepFwd = QAction(QIcon.fromTheme("media-seek-forward",
                                                  style.standardIcon(QStyle.SP_MediaSeekForward)),
                                  "Step Forward", self)
        self.actStepBwd = QAction(QIcon.fromTheme("media-seek-backward",
                                                  style.standardIcon(QStyle.SP_MediaSeekBackward)),
                                  "Step Backward", self)
        self.actSeekEnd = QAction(QIcon.fromTheme("media-skip-forward",
                                                  style.standardIcon(QStyle.SP_MediaSkipForward)),
                                  "Seek End", self)
        self.actSeekBegin = QAction(QIcon.fromTheme("media-skip-backward",
                                                    style.standardIcon(QStyle.SP_MediaSkipBackward)),
                                    "Seek Begin", self)
        self.actSetTimeFactor = {r : QAction("x 1/%d" % (1/r), self) if r < 1 else QAction("x %d" % r, self)
                                 for r in (1/8, 1/4, 1/2, 1, 2, 4, 8)}

        # pylint: disable=unnecessary-lambda
        # let's stay on the safe side and do not use emit as a slot...
        self.actStart.triggered.connect(lambda: self._startPlayback.emit())
        self.actPause.triggered.connect(lambda: self._pausePlayback.emit())
        self.actStepFwd.triggered.connect(lambda: self._stepForward.emit(self.selectedStream()))
        self.actStepBwd.triggered.connect(lambda: self._stepBackward.emit(self.selectedStream()))
        self.actSeekEnd.triggered.connect(lambda: self._seekEnd.emit())
        self.actSeekBegin.triggered.connect(lambda: self._seekBeginning.emit())
        # pylint: enable=unnecessary-lambda

        def setTimeFactor(newFactor):
            logger.debug("new time factor %f", newFactor)
            self._setTimeFactor.emit(newFactor)

        for r in self.actSetTimeFactor:
            logger.debug("adding action for time factor %f", r)
            self.actSetTimeFactor[r].triggered.connect(functools.partial(setTimeFactor, r))

        self.dockWidget = srv.newDockWidget("PlaybackControl", None, Qt.LeftDockWidgetArea)
        self.dockWidgetContents = QWidget(self.dockWidget)
        self.dockWidget.setWidget(self.dockWidgetContents)
        toolLayout = QBoxLayout(QBoxLayout.TopToBottom, self.dockWidgetContents)
        toolLayout.setContentsMargins(0, 0, 0, 0)
        toolBar = QToolBar()
        toolLayout.addWidget(toolBar)
        toolBar.addAction(self.actSeekBegin)
        toolBar.addAction(self.actStepBwd)
        toolBar.addAction(self.actStart)
        toolBar.addAction(self.actPause)
        toolBar.addAction(self.actStepFwd)
        toolBar.addAction(self.actSeekEnd)
        playbackMenu.addAction(self.actSeekBegin)
        playbackMenu.addAction(self.actStepBwd)
        playbackMenu.addAction(self.actStart)
        playbackMenu.addAction(self.actPause)
        playbackMenu.addAction(self.actStepFwd)
        playbackMenu.addAction(self.actSeekEnd)
        playbackMenu.addSeparator()
        for r in self.actSetTimeFactor:
            playbackMenu.addAction(self.actSetTimeFactor[r])
        self.timeRatioLabel = QLabel("x 1")
        self.timeRatioLabel.addActions(list(self.actSetTimeFactor.values()))
        self.timeRatioLabel.setContextMenuPolicy(Qt.ActionsContextMenu)
        toolBar.addSeparator()
        toolBar.addWidget(self.timeRatioLabel)
        contentsLayout = QGridLayout()
        toolLayout.addLayout(contentsLayout, 10)
        # now we add a position view
        self.positionSlider = QSlider(Qt.Horizontal, self.dockWidgetContents)
        self.beginLabel = QLabel(parent=self.dockWidgetContents)
        self.beginLabel.setAlignment(Qt.AlignLeft|Qt.AlignCenter)
        self.currentLabel = QLabel(parent=self.dockWidgetContents)
        self.currentLabel.setAlignment(Qt.AlignHCenter|Qt.AlignCenter)
        self.endLabel = QLabel(parent=self.dockWidgetContents)
        self.endLabel.setAlignment(Qt.AlignRight|Qt.AlignCenter)
        contentsLayout.addWidget(self.beginLabel, 0, 0, alignment=Qt.AlignLeft)
        contentsLayout.addWidget(self.currentLabel, 0, 1, alignment=Qt.AlignHCenter)
        contentsLayout.addWidget(self.endLabel, 0, 2, alignment=Qt.AlignRight)
        contentsLayout.addWidget(self.positionSlider, 1, 0, 1, 3)
        self.positionSlider.setTracking(False)
        self.positionSlider.valueChanged.connect(self.onSliderValueChanged, Qt.DirectConnection)
        self.positionSlider.sliderMoved.connect(self.displayPosition)

        # file browser
        self.browser = BrowserWidget(self.dockWidget)
        self.nameFiltersChanged.connect(self._onNameFiltersChanged, Qt.QueuedConnection)
        contentsLayout.addWidget(self.browser, 3, 0, 1, 3)
        contentsLayout.setRowStretch(3, 100)
        self.browser.activated.connect(self.browserActivated)

        self.actShowAllFiles = QAction("Show all files")
        self.actShowAllFiles.setCheckable(True)
        self.actShowAllFiles.setChecked(False)
        self.actShowAllFiles.toggled.connect(self._onShowAllFiles)
        playbackMenu.addSeparator()
        playbackMenu.addAction(self.actShowAllFiles)

        self.actGroupStream = QActionGroup(self)
        self.actGroupStream.setExclusionPolicy(QActionGroup.ExclusionPolicy.ExclusiveOptional)
        playbackMenu.addSeparator()
        self.actGroupStreamMenu = playbackMenu.addMenu("Step Stream")
        self._selectedStream = None

        self.recentSeqs = [QAction() for i in range(10)]
        playbackMenu.addSeparator()
        recentMenu = playbackMenu.addMenu("Recent")
        for a in self.recentSeqs:
            a.setVisible(False)
            a.triggered.connect(self.openRecent)
            recentMenu.addAction(a)

        self._supportedFeaturesChanged(set(), set())
Ejemplo n.º 4
0
class GameScreen(QWidget):
    def __init__(self):
        # Call parent class's __init__()
        super().__init__()

        self.board = GameBoard()
        self.board.setFixedSize(600, 600)

        self.game_status = QLabel()
        self.game_status.setObjectName("gameStatus")
        self.game_status.setMaximumHeight(30)
        self.game_status.setAlignment(QtCore.Qt.AlignCenter)
        self.reset_button = QPushButton("Reset")
        self.reset_button.clicked.connect(self.reset_game)
        self.reset_button.setCursor(QtCore.Qt.CursorShape.PointingHandCursor)
        self.reset_button.setMinimumWidth(120)
        self.exit_button = QPushButton("Exit Game")
        self.exit_button.clicked.connect(sys.exit)
        self.exit_button.setCursor(QtCore.Qt.CursorShape.PointingHandCursor)
        self.exit_button.setMinimumWidth(120)

        self.control_panel = QVBoxLayout()
        self.control_panel.addWidget(self.game_status)
        self.control_panel.addWidget(self.reset_button)
        self.control_panel.addWidget(self.exit_button)

        self.main_layout = QBoxLayout(QBoxLayout.Direction.LeftToRight)
        self.main_layout.addWidget(self.board)
        self.main_layout.addLayout(self.control_panel)

        # Set layout
        self.setLayout(self.main_layout)

    def resizeEvent(self, event):
        offset = -self.board.main_layout.spacing() * self.board.main_layout.rowCount()
        width = self.size().width() + offset
        height = self.size().height() + offset
        excess = width - height
        if excess >= 0:
            min_cp_width = self.control_panel.minimumSize().width()
            margin = max([0, min_cp_width - excess + self.main_layout.spacing()])
            height -= margin
            self.main_layout.setDirection(QBoxLayout.Direction.LeftToRight)
            self.board.setFixedSize(height, height)
            self.board.setContentsMargins(0, 0, 0, 0)
        else:
            min_cp_height = self.control_panel.minimumSize().height()
            margin = max([0, min_cp_height + excess + self.main_layout.spacing()])
            width -= margin
            self.main_layout.setDirection(QBoxLayout.Direction.TopToBottom)
            self.board.setFixedSize(width + margin - self.main_layout.spacing(), width)
            self.board.setContentsMargins(
                (margin - self.main_layout.spacing()) / 2,
                0,
                (margin - self.main_layout.spacing()) / 2,
                0,
            )
        super().resizeEvent(event)

    def reset_game(self):
        for cell in self.board.findChildren(QPushButton):
            cell.setText(" ")
            cell.setStyleSheet("")
        self.game_status.setText("")

    def get_state(self):
        state = []
        cell_type = {"X": 1.0, "O": -1.0, " ": 0.0}
        for cell in self.board.findChildren(QPushButton):
            state.append(cell_type[cell.text()])
        # Add a batch dimension
        return torch.tensor(state).unsqueeze(0).to(self.device)

    def num_actions_available(self):
        num_actions_available = 0
        for cell in self.board.findChildren(QPushButton):
            if cell.text() == " ":
                num_actions_available += 1
        return num_actions_available

    def take_action(self, action):
        player = "X" if self.board.x_turn else "O"
        print(self.board.findChildren(QPushButton)[action.item()])
        self.board.findChildren(QPushButton)[action.item()].setText(player)
        self.board.x_turn = not self.board.x_turn
        if (game_status := self.board.check_game_status()) == 0:
            self.game_status.setText("It's a tie!")
            self.done = True
            return torch.tensor([1], device=self.device)
        elif game_status == 1:
            self.game_status.setText("X has won!")
            self.done = True
            return torch.tensor([-1 + (self.board.x_turn) * 3], device=self.device)