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 __init__(self, columns, parent=None, callback=None): super().__init__(parent) self.callback = callback self.table = QTableWidget(0, len(columns), self) self.columns = columns self.table.setMinimumSize(400, 300) self.table.setShowGrid(True) self.hh = self.table.horizontalHeader() self.hh.setStretchLastSection(False) self.vh = self.table.verticalHeader() layout = QBoxLayout( QBoxLayout.Direction(QBoxLayout.LeftToRight | QBoxLayout.TopToBottom), self) layout.addWidget(self.table) self.setLayout(layout) # self.setSizePolicy(QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum, QSizePolicy.DefaultType)) self.callback = callback if self.callback: #self.table.cellEntered.connect(self.enterProcessor) #self.vh.activated.connect(self.enterProcessor) #self.vh.selected.connect(self.enterProcessor) #self.table.clicked.connect(self.enterProcessor) self.table.itemSelectionChanged.connect(self.enterProcessor)
def __init__(self, tool): QWidget.__init__(self) self.tool = tool self.layout = QBoxLayout(QBoxLayout.TopToBottom) self.sliders = [ slider.Slider(self.tool, "Short term TDP", "Maximal TDP in the short term", 1, 1, 150, 5), slider.Slider(self.tool, "Long term TDP", "Maximal TDP in the long term", 1, 1, 150, 5) ] self.slider_grid = slider.SliderGrid(self.tool, self.sliders) self.layout.addWidget(self.slider_grid) self.duration_controls = PowerDurationControls(self.tool) duration_group = QGroupBox("Override power limit durations") duration_group.setCheckable(True) duration_group.setToolTip( """If checked, allows you to alter short term and long term package power limit durations. This is used for Turbo Boost.""") duration_group.setLayout(self.duration_controls.layout()) self.layout.addWidget(duration_group) self.setLayout(self.layout)
def init_title(self, layout: QBoxLayout): self._title.setObjectName("MainTitle") self._title.setFixedHeight(40) self._title.title_text = self.tr("DVideoEditTools") self._title.close.connect(self.close) self._title.show_minimized.connect(self.showMinimized) self._title.show_maximized.connect(self.show_max_normal) layout.addWidget(self._title)
class MainWindow(QMainWindow): """docstring for MainWindow""" def __init__(self): super().__init__() self.setWindowTitle('The Python Media Manager') self.main_widget = QWidget() self.main_grid = QGridLayout() self.over_view_widget = QWidget() self.over_view = OverView() self.over_view_widget.setLayout(self.over_view) self.scroll_area = QScrollArea() self.scroll_area.setWidget(self.over_view_widget) self.scroll_area.setWidgetResizable(True) self.search = Search() self.main_grid.addLayout(self.search, 0, 0) self.main_grid.addWidget(self.scroll_area, 1, 0) self.button_loading = QBoxLayout(QBoxLayout.LeftToRight) self.button = QPushButton("Open Collection") self.button.clicked.connect(self.open_folder) self.loader_widget = QLabel("Loading...") #self.loader_animation = QMovie("assets/loader.gif") #self.loader_widget.setMovie(self.loader_animation) self.loader_widget.setVisible(False) self.button_loading.addWidget(self.button) self.button_loading.addWidget(self.loader_widget) self.main_grid.addLayout(self.button_loading, 2, 0, 1) self.main_grid.addWidget(self.loader_widget, 2, 1, 1) self.main_widget.setLayout(self.main_grid) self.setCentralWidget(self.main_widget) self.media_manager = manager.MediaManager() self.media_manager.register_observer(self) def open_folder(self): dialog = QFileDialog(self) directory = dialog.getExistingDirectory(self) self.button.setEnabled(False) self.loader_widget.setVisible(True) self.media_manager.create_collection(directory) def recieve(self): self.over_view.update(self.media_manager.get_all_media()) self.button.setEnabled(True) self.loader_widget.setVisible(False)
def __init__(self, tool): QWidget.__init__(self) self.tool = tool self.layout = QBoxLayout(QBoxLayout.LeftToRight) self.reset_button = QPushButton() self.reset_button.setText("Defaults") self.reset_button.setIcon(QIcon.fromTheme("document-revert")) self.reset_button.clicked.connect( lambda: tool.reload_ui_from_vars(config.UVToolVars())) self.layout.addWidget(self.reset_button) self.import_button = QPushButton() self.import_button.setText("Load") self.import_button.setIcon(QIcon.fromTheme("document-open")) self.import_button.clicked.connect(self.on_import) self.layout.addWidget(self.import_button) self.export_button = QPushButton() self.export_button.setText("Save") self.export_button.setIcon(QIcon.fromTheme("document-save-as")) self.layout.addWidget(self.export_button) self.read_button = QPushButton() self.read_button.setText("Read") self.read_button.setIcon(QIcon.fromTheme("computer")) self.read_button.setToolTip("""Read values currently set on the CPU. This is useful to get accurate values after applying custom settings.""") self.read_button.clicked.connect(self.on_read) self.layout.addWidget(self.read_button) self.apply_button = QPushButton() self.apply_button.setText("Apply") self.apply_button.setToolTip( """Save the current settings to "{}" and apply. This will override the existing configuration file.""".format( config.config_path)) self.apply_button.setStyleSheet( "QPushButton:!disabled { background-color: red }") self.apply_button.clicked.connect(self.on_apply) self.layout.addWidget(self.apply_button) self.setLayout(self.layout)
def __init__(self, tool): QWidget.__init__(self) self.tool = tool self.layout = QBoxLayout(QBoxLayout.LeftToRight) self.start_toggle_button = QPushButton() self.start_toggle_button.setText("Start") self.layout.addWidget(self.start_toggle_button) self.enable_toggle_button = QPushButton() self.enable_toggle_button.setText("Enable") self.enable_toggle_button.setStyleSheet( "QPushButton:!disabled { background-color: orange }") self.layout.addWidget(self.enable_toggle_button) self.setLayout(self.layout)
def __init__(self, tool): QWidget.__init__(self) self.tool = tool self.layout = QBoxLayout(QBoxLayout.LeftToRight) self.layout.addWidget(QLabel("Update interval: ")) self.period_select = QSpinBox() self.period_select.setRange(100, 1000 * 60 * 240) # 240 seconds max self.period_select.setSingleStep(100) self.layout.addWidget(self.period_select) self.layout.addWidget(QLabel("ms")) self.layout.setStretch(1, 1) self.setLayout(self.layout)
def onclick_view_3d(self, button): self.popup_window = QWidget() self.popup_window.setMinimumWidth(450) self.popup_window.setMinimumHeight(450) self.popup_window.setLayout(QBoxLayout(QBoxLayout.TopToBottom)) self.popup_window.layout().addWidget(self.container) self.popup_window.show() self.update_scatter()
def __init__(self, tool): QWidget.__init__(self) self.tool = tool self.layout = QBoxLayout(QBoxLayout.TopToBottom) self.tjunction_offset = slider.SliderGrid(self.tool, [ slider.Slider( self.tool, "TJunction offset", "Offsets the temperature from which the CPU throttles", 1, -120, 0, 5) ]) self.layout.addWidget(self.tjunction_offset) self.power_controls = PowerControls(self.tool) power_group = QGroupBox("Override power limits") power_group.setCheckable(True) power_group.setLayout(self.power_controls.layout) self.layout.addWidget(power_group) self.setLayout(self.layout)
def __init__(self, page_view: PageView) -> None: super().__init__() self.page_view = page_view self.aspect_ratio = config_controller.paper_ratio self.setLayout(QBoxLayout(QBoxLayout.LeftToRight, self)) # add spacer, then widget, then spacer self.layout().addItem(QSpacerItem(0, 0)) self.layout().addWidget(page_view) self.layout().addItem(QSpacerItem(0, 0)) self.setAttribute(QtCore.Qt.WA_StyledBackground, True) # self.page_view.show() self.setObjectName("AspectRatio") self.setStyleSheet("#AspectRatio {background-color:grey;}")
def __init__(self, image_stream_server: ImageStreamServer) -> None: super().__init__() self._width = 196 self._height = 144 self._aspect_ratio = self._width / self._height size_policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.setSizePolicy(size_policy) layout = QBoxLayout(QBoxLayout.LeftToRight, self) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self._image_widget = ImageWidget(image_stream_server, self._width, self._height) # add spacer, then widget, then spacer self.layout().addItem(QSpacerItem(0, 0)) self.layout().addWidget(self._image_widget) self.layout().addItem(QSpacerItem(0, 0))
def __init__(self, tool): QWidget.__init__(self) self.tool = tool self.layout = QBoxLayout(QBoxLayout.TopToBottom) self.info_label = QLabel( """The system sometimes overrides the power and temperature limits. The intel-undervolt daemon can be used to enforce them periodically. Enabling the systemd service enables you to apply your settings on boot.""") self.info_label.setWordWrap(True) self.layout.addWidget(self.info_label) self.layout.addWidget(DaemonIntervalControls(self.tool)) systemd_group = QGroupBox("systemd service") self.systemd_controls = SystemdControls(self.tool) systemd_group.setLayout(self.systemd_controls.layout) systemd_group.setEnabled(self.tool.has_systemd) self.layout.addWidget(systemd_group) self.setLayout(self.layout)
def __init__(self, widget, side_widget, parent): super().__init__(parent) self.setParent(parent) self.setStyleSheet("background:#222; color:#fff; padding:0; margin:0") self.setLayout(QBoxLayout(QBoxLayout.LeftToRight, self)) self.main_widget = widget self.side_widget = side_widget self.centerWrapper = QWidget() self.centerWrapperLayout = QBoxLayout(QBoxLayout.LeftToRight) self.centerWrapperLayout.setMargin(0) self.centerWrapperLayout.setSpacing(0) self.centerWrapper.setLayout(self.centerWrapperLayout) self.centerWrapperLayout.addWidget(self.main_widget) self.centerWrapperLayout.addWidget(self.side_widget) self.layout().setMargin(0) # add spacer, then widget, then spacer self.layout().addItem(QSpacerItem(0, 0)) self.layout().addWidget(self.centerWrapper) # self.layout().addWidget(side_widget) self.layout().addItem(QSpacerItem(0, 0))
def __init__(self): super().__init__() self.setWindowTitle('The Python Media Manager') self.main_widget = QWidget() self.main_grid = QGridLayout() self.over_view_widget = QWidget() self.over_view = OverView() self.over_view_widget.setLayout(self.over_view) self.scroll_area = QScrollArea() self.scroll_area.setWidget(self.over_view_widget) self.scroll_area.setWidgetResizable(True) self.search = Search() self.main_grid.addLayout(self.search, 0, 0) self.main_grid.addWidget(self.scroll_area, 1, 0) self.button_loading = QBoxLayout(QBoxLayout.LeftToRight) self.button = QPushButton("Open Collection") self.button.clicked.connect(self.open_folder) self.loader_widget = QLabel("Loading...") #self.loader_animation = QMovie("assets/loader.gif") #self.loader_widget.setMovie(self.loader_animation) self.loader_widget.setVisible(False) self.button_loading.addWidget(self.button) self.button_loading.addWidget(self.loader_widget) self.main_grid.addLayout(self.button_loading, 2, 0, 1) self.main_grid.addWidget(self.loader_widget, 2, 1, 1) self.main_widget.setLayout(self.main_grid) self.setCentralWidget(self.main_widget) self.media_manager = manager.MediaManager() self.media_manager.register_observer(self)
def _init_ui( self, empty_widget: QWidget, ) -> None: layout = QBoxLayout( QBoxLayout.LeftToRight, self, ) self._empty_widget = empty_widget self._tab_widget = self._create_tab_widget() self._auto_show_hide_tabs() layout.addWidget(self._empty_widget, Qt.AlignCenter) layout.addWidget(self._tab_widget) layout.setMargin(0)
def setupUI(self): # WINDOW SETUP self.setWindowTitle("Keras.QuickDraw") self.setMinimumSize(QSize(800, 600)) self.setFixedSize(QSize(800, 600)) self.setWindowIcon(QIcon("favicon.ico")) # INITIALIZE: WINDOW CENTRAL self.widget_central = QWidget(self) self.widget_central.setObjectName("Window Central") self.widget_central.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.layout_central = QBoxLayout(QBoxLayout.TopToBottom, self.widget_central) self.setCentralWidget(self.widget_central) # INITIALIZE: CENTRAL HEADER self.widget_header = QWidget(self.widget_central) self.widget_header.setObjectName("Widget Header") self.widget_header.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.widget_header_indicater = QLabel(parent = self.widget_header) self.widget_header_caption = QLabel("(TARGET)", self.widget_header) self.widget_header_counter = QLabel(parent = self.widget_header) self.layout_header = QBoxLayout(QBoxLayout.LeftToRight, self.widget_header) self.layout_header.addWidget(self.widget_header_indicater, 0, Qt.AlignLeft) self.layout_header.addWidget(self.widget_header_caption , 1, Qt.AlignCenter) self.layout_header.addWidget(self.widget_header_counter , 0, Qt.AlignRight) # INITIALIZE: CENTRAL CANVAS self.widget_canvas = QCanvas(self.widget_central, self) self.widget_canvas.setObjectName("Widget Canvas") self.widget_canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # INITIALIZE: CENTRAL BUTTONS self.widget_footer = QWidget(self.widget_central) self.widget_footer.setObjectName("Widget Footer") self.widget_footer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.widget_footer_clear = QPushButton("Clear", self.widget_footer) self.widget_footer_clear.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.widget_footer_clear.clicked.connect(self.widget_canvas.resetCanvas) self.widget_footer_undo = QPushButton("Undo", self.widget_footer) self.widget_footer_undo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.widget_footer_undo.clicked.connect(self.widget_canvas.undoCanvas) self.layout_footer = QBoxLayout(QBoxLayout.LeftToRight, self.widget_footer) self.layout_footer.addWidget(self.widget_footer_undo, 0) self.layout_footer.addWidget(self.widget_footer_clear, 0) self.layout_footer.setMargin(0) # LAYOUT: HEADER + CANVAS + FOOTER -> CENTRAL WINDOW CENTRAL self.layout_central.addWidget(self.widget_header, 0) self.layout_central.addWidget(self.widget_canvas, 1, Qt.AlignCenter) self.layout_central.addWidget(self.widget_footer, 0) self.show()
def __init__(self, label_text: str, widget: Type[QWidget], layout: Optional[QLayout] = None) -> None: super().__init__() if layout is None: layout = self.Layout.HORIZONTAL label = QLabel(label_text) direction = QBoxLayout.LeftToRight if layout == self.Layout.HORIZONTAL else QBoxLayout.TopToBottom data_layout = QBoxLayout(direction) data_layout.addWidget(label) data_layout.addWidget(widget) if layout == self.Layout.HORIZONTAL: data_layout.addStretch() self.setLayout(data_layout) self.widget = widget
class AspectRatioWidget(QWidget): def __init__(self, widget, side_widget, parent): super().__init__(parent) self.setParent(parent) self.setStyleSheet("background:#222; color:#fff; padding:0; margin:0") self.setLayout(QBoxLayout(QBoxLayout.LeftToRight, self)) self.main_widget = widget self.side_widget = side_widget self.centerWrapper = QWidget() self.centerWrapperLayout = QBoxLayout(QBoxLayout.LeftToRight) self.centerWrapperLayout.setMargin(0) self.centerWrapperLayout.setSpacing(0) self.centerWrapper.setLayout(self.centerWrapperLayout) self.centerWrapperLayout.addWidget(self.main_widget) self.centerWrapperLayout.addWidget(self.side_widget) self.layout().setMargin(0) # add spacer, then widget, then spacer self.layout().addItem(QSpacerItem(0, 0)) self.layout().addWidget(self.centerWrapper) # self.layout().addWidget(side_widget) self.layout().addItem(QSpacerItem(0, 0)) def resizeEvent(self, e): w = e.size().width() h = e.size().height() side_width = self.side_widget.width() if w - 100 > h: # too wide self.layout().setDirection(QBoxLayout.LeftToRight) widget_stretch = h + side_width outer_stretch = (w - h - side_width) / 2 else: # too tall self.layout().setDirection(QBoxLayout.TopToBottom) widget_stretch = w - side_width outer_stretch = (h - w + side_width) / 2 self.layout().setStretch(0, outer_stretch) self.layout().setStretch(1, widget_stretch) self.layout().setStretch(2, outer_stretch)
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)
def __init__(self, config): assertMainThread() super().__init__(config) # state self._directory = str(Path('.').absolute()) # gui srv = Services.getService("MainWindow") config.configLoaded.connect(self._restoreState) config.configAboutToSave.connect(self._saveState) self._config = config recMenu = srv.menuBar().addMenu("&Recording") style = QApplication.style() self.actStart = QAction( QIcon.fromTheme("media-record", QIcon(":icons/media-record.svg")), "Start Recording", self) self.actStop = QAction( QIcon.fromTheme("media-playback-stop", style.standardIcon(QStyle.SP_MediaStop)), "Stop Recording", self) self.actSetDir = QAction( QIcon.fromTheme("document-open-folder", style.standardIcon(QStyle.SP_DirIcon)), "Choose directory ...", self) self.actStart.setEnabled(False) self.actStop.setEnabled(False) self.actSetDir.setEnabled(False) self.actStart.triggered.connect(self._startTriggered) self.actStop.triggered.connect(self._stopTriggered) self.actSetDir.triggered.connect(self._setDir) recMenu.addAction(self.actStart) recMenu.addAction(self.actStop) recMenu.addAction(self.actSetDir) self.dockWidget = srv.newDockWidget("RecordingControl", None, Qt.LeftDockWidgetArea, defaultLoc="PlaybackControl") 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.actStart) toolBar.addAction(self.actStop) toolBar.addAction(self.actSetDir) self._directoryLabel = ElidedLabel(self._directory, parent=self.dockWidgetContents) to = self._directoryLabel.textOption() to.setWrapMode(QTextOption.NoWrap) self._directoryLabel.setTextOption(to) self._directoryLabel.setElideMode(Qt.ElideMiddle) self._statusLabel = ElidedLabel("(disabled)", parent=self.dockWidgetContents) to = self._statusLabel.textOption() to.setWrapMode(QTextOption.NoWrap) self._statusLabel.setTextOption(to) self._statusLabel.setElideMode(Qt.ElideMiddle) toolLayout.addWidget(self._directoryLabel) toolLayout.addWidget(self._statusLabel, stretch=100) #toolLayout.addStretch(100) self.statusUpdate.connect(self._onUpdateStatus) self.notifyError.connect(self._onNotifyError)
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())
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")))
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)
class MainControls(QWidget): def on_import(self): # TODO: if changes are present, ask if it's okay to override dialog = QFileDialog(self.tool) dialog.selectFile(config.config_path) dialog.setAcceptMode(QFileDialog.AcceptOpen) dialog.setFileMode(QFileDialog.ExistingFile) path = dialog.exec() def on_read(self): pass #TODO def on_apply(self): # TODO: warning if systemd service is active... self.tool.active_service_warning() if self.tool.confirm_undervolt_apply(): info = QMessageBox(self.tool) info.setIcon(QMessageBox.Information) info.setWindowTitle("Undervolt applied") info.setText("""The undervolt appears to be successful. As a reminder, even if your system is stable now, it is not unlikely that you encounter a hang or data corruption later (even during idle). If your system hangs, you may have to power cycle it forcefully. It is recommended to run a stress test like mprime for a couple hours in order to check the system stability. Finally, you may want to press the "Read current" button in the tool in order to check the exact applied undervolt.""" ) info.exec_() def __init__(self, tool): QWidget.__init__(self) self.tool = tool self.layout = QBoxLayout(QBoxLayout.LeftToRight) self.reset_button = QPushButton() self.reset_button.setText("Defaults") self.reset_button.setIcon(QIcon.fromTheme("document-revert")) self.reset_button.clicked.connect( lambda: tool.reload_ui_from_vars(config.UVToolVars())) self.layout.addWidget(self.reset_button) self.import_button = QPushButton() self.import_button.setText("Load") self.import_button.setIcon(QIcon.fromTheme("document-open")) self.import_button.clicked.connect(self.on_import) self.layout.addWidget(self.import_button) self.export_button = QPushButton() self.export_button.setText("Save") self.export_button.setIcon(QIcon.fromTheme("document-save-as")) self.layout.addWidget(self.export_button) self.read_button = QPushButton() self.read_button.setText("Read") self.read_button.setIcon(QIcon.fromTheme("computer")) self.read_button.setToolTip("""Read values currently set on the CPU. This is useful to get accurate values after applying custom settings.""") self.read_button.clicked.connect(self.on_read) self.layout.addWidget(self.read_button) self.apply_button = QPushButton() self.apply_button.setText("Apply") self.apply_button.setToolTip( """Save the current settings to "{}" and apply. This will override the existing configuration file.""".format( config.config_path)) self.apply_button.setStyleSheet( "QPushButton:!disabled { background-color: red }") self.apply_button.clicked.connect(self.on_apply) self.layout.addWidget(self.apply_button) self.setLayout(self.layout)
class MainWindow(QMainWindow): def __init__(self): super().__init__() self.buffer = QBuffer() self.buffer.open(QBuffer.ReadWrite) self.setupUI() self.model = QModel(self) self.model.start() """ USER INTERFACE SETUP """ def setupUI(self): # WINDOW SETUP self.setWindowTitle("Keras.QuickDraw") self.setMinimumSize(QSize(800, 600)) self.setFixedSize(QSize(800, 600)) self.setWindowIcon(QIcon("favicon.ico")) # INITIALIZE: WINDOW CENTRAL self.widget_central = QWidget(self) self.widget_central.setObjectName("Window Central") self.widget_central.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.layout_central = QBoxLayout(QBoxLayout.TopToBottom, self.widget_central) self.setCentralWidget(self.widget_central) # INITIALIZE: CENTRAL HEADER self.widget_header = QWidget(self.widget_central) self.widget_header.setObjectName("Widget Header") self.widget_header.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.widget_header_indicater = QLabel(parent = self.widget_header) self.widget_header_caption = QLabel("(TARGET)", self.widget_header) self.widget_header_counter = QLabel(parent = self.widget_header) self.layout_header = QBoxLayout(QBoxLayout.LeftToRight, self.widget_header) self.layout_header.addWidget(self.widget_header_indicater, 0, Qt.AlignLeft) self.layout_header.addWidget(self.widget_header_caption , 1, Qt.AlignCenter) self.layout_header.addWidget(self.widget_header_counter , 0, Qt.AlignRight) # INITIALIZE: CENTRAL CANVAS self.widget_canvas = QCanvas(self.widget_central, self) self.widget_canvas.setObjectName("Widget Canvas") self.widget_canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # INITIALIZE: CENTRAL BUTTONS self.widget_footer = QWidget(self.widget_central) self.widget_footer.setObjectName("Widget Footer") self.widget_footer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.widget_footer_clear = QPushButton("Clear", self.widget_footer) self.widget_footer_clear.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.widget_footer_clear.clicked.connect(self.widget_canvas.resetCanvas) self.widget_footer_undo = QPushButton("Undo", self.widget_footer) self.widget_footer_undo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.widget_footer_undo.clicked.connect(self.widget_canvas.undoCanvas) self.layout_footer = QBoxLayout(QBoxLayout.LeftToRight, self.widget_footer) self.layout_footer.addWidget(self.widget_footer_undo, 0) self.layout_footer.addWidget(self.widget_footer_clear, 0) self.layout_footer.setMargin(0) # LAYOUT: HEADER + CANVAS + FOOTER -> CENTRAL WINDOW CENTRAL self.layout_central.addWidget(self.widget_header, 0) self.layout_central.addWidget(self.widget_canvas, 1, Qt.AlignCenter) self.layout_central.addWidget(self.widget_footer, 0) self.show() """ EVENT: SAVING CANVAS (QThread ALTERNATIVE) """ def paintEvent(self, event: QPaintEvent) -> None: # SCREENSHOT WIDGET OF QPaintDevice, SUCH AS QBITMAP self.widget_canvas.render(self.widget_canvas.pixmap()) if self.isVisible: self.buffer.reset() self.widget_canvas.pixmap().save(self.buffer, "BMP") return super().paintEvent(event) """ EVENT: CLOSING MAINWINDOW """ def closeEvent(self, event: QCloseEvent) -> None: self.model.terminate() self.model.wait() self.buffer.close() return super().closeEvent(event)