def change_update_check(self): """ Callback after the check for an update was finished. """ if not self._update_check_runner.check_succeed: self.update_status.setPixmap( QIcon(str(pkg_data.ERROR_SYMBOL)).pixmap( QSize(self.update_info.height() * 0.8, self.update_info.height() * 0.8))) self.update_info.setText(self._update_check_runner.err_msg) return if self._update_check_runner.update_available: self.update_status.setPixmap( QIcon(str(pkg_data.WARNING_SYMBOL)).pixmap( QSize(self.update_info.height() * 0.8, self.update_info.height() * 0.8))) self.update_info.setText("An Update is available.") # executed in a top-level script environment e.g. pythonw -m mp3monitoring --gui, ONLY then we can update, otherwise the executable is locked if Path(sys.modules['__main__'].__file__) == Path( sysconfig.get_paths() ['purelib']) / "mp3monitoring" / "__main__.py": self.update_now.show() else: self.update_status.setPixmap( QIcon(str(pkg_data.OK_SYMBOL)).pixmap( QSize(self.update_info.height() * 0.8, self.update_info.height() * 0.8))) self.update_info.setText("MP3 Monitoring is up to date.") self.update_now.hide()
def showAboutDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('About' if self else getTitleString('About')) messagebox.setText(f''' <p style="margin:0 15px 0 0;"> <b>{w3modmanager.TITLE} {w3modmanager.VERSION}</b> <small>{f'({w3modmanager.VERSION_HASH})' if w3modmanager.VERSION_HASH else ''}</small><br> {w3modmanager.SUBTITLE}<br> <br> For updates and information visit <br> <a href="{w3modmanager.URL_WEB}" style="text-decoration:none;">\ {removeUrlScheme(w3modmanager.URL_WEB)}\ </a><br> <br> Thank you for using {w3modmanager.TITLE}! </p> ''') # TODO: enhancement: check if new version is available messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setMinimumSize(QSize(500, 500)) messagebox.setStandardButtons(QMessageBox.Ok) messagebox.setAttribute(Qt.WA_DeleteOnClose) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def minimumSize(self) -> QSize: size = QSize() for item in self._items: size = size.expandedTo(item.minimumSize()) left, top, right, bottom = self.getContentsMargins() size += QSize(left + right, top + bottom) return size
def __init__(self, parent): super().__init__(parent) self.setupUi(self) self.setWindowFlags(self.windowFlags() & ~(Qt.WindowContextHelpButtonHint | Qt.MSWindowsFixedSizeDialogHint)) # set descriptions self.version.setText(static_data.VERSION) self.author.setText( f"<a href=\"{static_data.AUTHOR_GITHUB}\">{static_data.AUTHOR}</a>" ) self.license.setText( "<a href=\"https://github.com/IceflowRE/mp3monitoring/blob/main/LICENSE.md\">GPLv3</a>" ) self.website.setText( f"<a href=\"{static_data.PROJECT_URL}\">Github</a>") # set logo self.logo.setPixmap(QIcon(str(pkg_data.LOGO)).pixmap(QSize(250, 250))) self._update_app_runner = UpdateAppThread() self._update_app_runner.finished.connect(self.update_app_check) self.update_now.clicked.connect(self.update_app) self.update_now.hide() self.update_status.setPixmap( QIcon(str(pkg_data.WAIT_SYMBOL)).pixmap( QSize(self.update_info.height() * 0.8, self.update_info.height() * 0.8))) self._update_check_runner = UpdateCheckThread() self._update_check_runner.finished.connect(self.change_update_check) self._update_check_runner.start()
def find_display_size(display: GameDisplay, view: QGraphicsView, target_size: QSize) -> QSize: max_width = None max_height = None min_width = min_height = 1 display_width = display.width() display_height = display.height() while True: scene_size = view.contentsRect().size() if scene_size.width() == target_size.width(): min_width = max_width = display_width elif scene_size.width() < target_size.width(): min_width = display_width + 1 else: max_width = display_width - 1 if scene_size.height() == target_size.height(): min_height = max_height = display_height elif scene_size.height() < target_size.height(): min_height = display_height + 1 else: max_height = display_height - 1 if max_width is None: display_width *= 2 else: display_width = (min_width + max_width) // 2 if max_height is None: display_height *= 2 else: display_height = (min_height + max_height) // 2 if min_width == max_width and min_height == max_height: return QSize(display_width, display_height) display.resize(display_width, display_height) view.grab() # Force layout recalculation.
def test_hover_enter_red(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters( 240, 240, 'sandbox_hover_enter_red') as (actual, expected): expected_scene = QGraphicsScene(0, 0, 240, 240) expected_scene.addPixmap( SandboxDisplay.load_pixmap('board-1.png', QSize(240, 240))).setPos(1, 0) red_ball = SandboxDisplay.load_pixmap('ball-r-shadow-1.png', QSize(60, 60)) new_piece = expected_scene.addPixmap(red_ball) new_piece.setPos(115, 114) new_piece.setOpacity(0.5) expected_scene.render(expected) display = SandboxDisplay() display.selected_move_type = MoveType.RED height = 0 row = 1 column = 2 piece_item = display.item_levels[height][row][column] display.resize(348, 264) display.grab() # Force layout to recalculate. display.on_hover_enter(piece_item) render_display(display, actual)
def __init__(self, path: Path): self.position = QPointF() self.path = path self.size = QSize() self.InitializeSize()
def test_update(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters(240, 240, 'spargo_update') as ( actual, expected): expected_scene = QGraphicsScene(0, 0, 240, 240) expected_scene.addPixmap( SpargoDisplay.load_pixmap('board-1.png', QSize(240, 240))).setPos(1, 0) black_ball = SpargoDisplay.load_pixmap('ball-b-shadow-1.png', QSize(60, 60)) expected_scene.addPixmap(black_ball).setPos(63, 166) expected_scene.render(expected) display = SpargoDisplay() display.resize(348, 264) display.update_board(SpargoState("""\ A C E G 7 . . . . 7 5 . . . . 5 3 . . . . 3 1 . B . . 1 A C E G >W """)) render_display(display, actual) assert display.ui.black_count.text() == '1' assert display.ui.white_count.text() == '0'
def buttonsOrientationChanged(self, index): self.mainLayout.setSizeConstraint(QLayout.SetNoConstraint) self.setMinimumSize(0, 0) orientation = Qt.Orientation( int(self.buttonsOrientationComboBox.itemData(index))) if orientation == self.buttonBox.orientation(): return self.mainLayout.removeWidget(self.buttonBox) spacing = self.mainLayout.spacing() oldSizeHint = self.buttonBox.sizeHint() + QSize(spacing, spacing) self.buttonBox.setOrientation(orientation) newSizeHint = self.buttonBox.sizeHint() + QSize(spacing, spacing) if orientation == Qt.Horizontal: self.mainLayout.addWidget(self.buttonBox, 2, 0) self.resize(self.size() + QSize(-oldSizeHint.width(), newSizeHint.height())) else: self.mainLayout.addWidget(self.buttonBox, 0, 3, 2, 1) self.resize(self.size() + QSize(newSizeHint.width(), -oldSizeHint.height())) self.mainLayout.setSizeConstraint(QLayout.SetDefaultConstraint)
def test_click(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters(240, 240, 'spline_click') as (actual, expected): expected_scene = QGraphicsScene(0, 0, 240, 240) expected_scene.addPixmap( SplineDisplay.load_pixmap('board-1.png', QSize(240, 240))).setPos(1, 0) black_ball = SplineDisplay.load_pixmap('ball-b-shadow-1.png', QSize(60, 60)) expected_scene.addPixmap(black_ball).setPos(115, 114) expected_scene.render(expected) display = SplineDisplay() height = 0 row = 1 column = 2 piece_item = display.item_levels[height][row][column] display.resize(348, 264) display.grab() # Force layout to recalculate. display.on_click(piece_item) render_display(display, actual)
def mousePressEvent(self, event): self.animation = QPropertyAnimation(self.parent.menu, b"size") self.animation.setDuration(150) self.animation.setStartValue(QSize(270, self.parent.height())) self.animation.setEndValue(QSize(0, self.parent.height())) self.animation.start() self.animation.finished.connect(self.animation_end) self.hide()
def minimumSize(self) -> PySide6.QtCore.QSize: size = QSize() for item in self.items_list: size = size.expandedTo(item.minimumSize()) size += QSize(2 * self.contentsMargins().top(), 2 * self.contentsMargins().top()) return size
def closeEvent(self, event): self.layout().setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint) self.setMinimumSize(QSize(self.width(), self.minimum_height)) self.resize(QSize(self.width(), self.minimum_height)) self.persepolis_setting.setValue('LogWindow/size', self.size()) self.persepolis_setting.setValue('LogWindow/position', self.pos()) self.persepolis_setting.sync() event.accept()
def sizeHint(self, option, index): """ Returns the size needed to display the item in a QSize object. """ if index.column() == 5: size_hint = QSize(5 * self.star.width(), self.star.height()) + QSize(1, 1) return size_hint # Since we draw the grid ourselves: return QSqlRelationalDelegate.sizeHint(self, option, index) + QSize( 1, 1)
def minimumSize(self): size = QSize() for item in self._item_list: size = size.expandedTo(item.minimumSize()) size += QSize(2 * self.contentsMargins().top(), 2 * self.contentsMargins().top()) return size
def __init__(self, parent, persepolis_setting): super().__init__(parent) self.persepolis_setting = persepolis_setting # set ui direction ui_direction = self.persepolis_setting.value('ui_direction') if ui_direction == 'rtl': self.setLayoutDirection(Qt.RightToLeft) elif ui_direction in 'ltr': self.setLayoutDirection(Qt.LeftToRight) # set size self.resize(QSize(400, 80)) self.setFixedWidth(400) # show this widget as ToolTip widget self.setWindowFlags(Qt.ToolTip) # find bottom right position bottom_right_screen = QDesktopWidget().availableGeometry().bottomRight( ) bottom_right_notification = QRect(QPoint(0, 0), QSize(410, 120)) bottom_right_notification.moveBottomRight(bottom_right_screen) self.move(bottom_right_notification.topLeft()) # get persepolis icon path icons = ':/' + \ str(self.persepolis_setting.value('settings/icons')) + '/' notification_horizontalLayout = QHBoxLayout(self) # persepolis icon svgWidget = QtSvg.QSvgWidget(':/persepolis.svg') svgWidget.setFixedSize(QSize(64, 64)) notification_horizontalLayout.addWidget(svgWidget) notification_verticalLayout = QVBoxLayout() # 2 labels for notification messages self.label1 = QLabel(self) self.label1.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) self.label1.setStyleSheet("font-weight: bold") self.label1.setWordWrap(True) self.label2 = QLabel(self) self.label2.setWordWrap(True) self.label2.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) notification_verticalLayout.addWidget(self.label1) notification_verticalLayout.addWidget(self.label2) notification_horizontalLayout.addLayout(notification_verticalLayout)
def load_pixmap(name: str, size: QSize = None) -> QPixmap: file_path = ':/shibumi_images/' + name image = QImage(str(file_path)) if image.isNull(): raise ValueError(f'Unable to load image {file_path}.') pixmap = QPixmap(image) if size is not None: pixmap = ShibumiDisplay.scale_pixmap(pixmap, size.width(), size.height()) return pixmap
def __init__(self, parent: QWidget, file: str) -> None: QLabel.__init__(self, parent) self.file = file self.sizePolicy().setHorizontalStretch(1) self.setSizePolicy(EXP_FIX) self.setMinimumSize(QSize(0, 100)) self.setMaximumSize(QSize(INFINITE, 100)) self.setScaledContents(False) self.setAlignment(Qt.AlignCenter) self.app = parent
def on_bt_maximize_clicked(self): icon = QIcon() if self.isMaximized(): self.showNormal() icon.addFile(u":/window/jurassic_Window-max.svg", QSize(), QIcon.Normal, QIcon.Off) else: self.showMaximized() icon.addFile(u":/window/jurassic_Window-min.svg", QSize(), QIcon.Normal, QIcon.Off) self.bt_maximize.setIcon(icon)
def show_menu(self): self.animation = QPropertyAnimation(self.mdi.menu, b"size") self.animation.setDuration(150) self.animation.setStartValue(QSize(0, self.mdi.height())) self.animation.setEndValue(QSize(270, self.mdi.height())) self.animation.start() self.mdi.overlay.show() self.mdi.menu.show() self.mdi.setActiveSubWindow(self.mdi.overlay) self.mdi.setActiveSubWindow(self.mdi.menu)
def format_metadata(self, size: QtCore.QSize): """ Update the font size of the meta data's labels depending on the StackedWidget's size. :param size: size of the StackedWidget used in the MainPage. """ if self.metadata_formatted: # TODO: generalise 1200 and 600 if size.width() < 1200 and size.height() < 600: stylesheet = "QLabel { color : white; font-size: 10px }" else: stylesheet = "QLabel { color : white; }" self.format_metadata_labels(stylesheet)
def __init__(self, owner): super(self.__class__, self).__init__() Ui_Setting.__init__(self) self.setupUi(self) self.settings = QSettings('config.ini', QSettings.IniFormat) # self.setWindowModality(Qt.ApplicationModal) self.mainSize = QSize(1500, 1100) self.bookSize = QSize(900, 1020) self.readSize = QSize(1120, 1020) self.userId = "" self.passwd = "" self.gpuInfos = [] self.translate = QTranslator()
class Image: def __init__(self, path: Path): self.position = QPointF() self.path = path self.size = QSize() self.InitializeSize() def InitializeSize(self): image = QImage(str(self.path.absolute())) self.size.setWidth(image.width()) self.size.setHeight(image.height())
def test_hover_enter_remove(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters( 240, 240, 'spook_hover_enter_remove') as (actual, expected): expected_scene = QGraphicsScene(0, 0, 240, 240) expected_scene.addPixmap( SpookDisplay.load_pixmap('board-1.png', QSize(240, 240))).setPos(1, 0) white_ball = SpookDisplay.load_pixmap('ball-w-shadow-1.png', QSize(60, 60)) red_ball = SpookDisplay.load_pixmap('ball-r-shadow-1.png', QSize(60, 60)) black_ball = SpookDisplay.load_pixmap('ball-b-shadow-1.png', QSize(60, 60)) black_piece = expected_scene.addPixmap(black_ball) black_piece.setPos(115, 114) black_piece.setOpacity(0.5) red_piece = expected_scene.addPixmap(red_ball) red_piece.setPos(63, 62) white_piece = expected_scene.addPixmap(white_ball) white_piece.setPos(115, 62) expected_scene.render(expected) display = SpookDisplay() display.update_board( SpookState('''\ A C E G 7 . . . . 7 5 . R W . 5 3 . . B . 3 1 . . . . 1 A C E G >R(R,B) ''')) height = 0 row = 1 column = 2 piece_item = display.item_levels[height][row][column] display.resize(348, 264) display.grab() # Force layout to recalculate. display.on_hover_enter(piece_item) render_display(display, actual)
def test_double_update(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters(240, 240, 'spline_double_update') as (actual, expected): expected_scene = QGraphicsScene(0, 0, 240, 240) expected_scene.addPixmap( SplineDisplay.load_pixmap('board-1.png', QSize(240, 240))).setPos(1, 0) white_ball = SplineDisplay.load_pixmap('ball-w-shadow-1.png', QSize(60, 60)) black_ball = SplineDisplay.load_pixmap('ball-b-shadow-1.png', QSize(60, 60)) expected_scene.addPixmap(black_ball).setPos(11, 10) expected_scene.addPixmap(white_ball).setPos(63, 10) expected_scene.addPixmap(black_ball).setPos(115, 62) expected_scene.render(expected) display = SplineDisplay() trigger_resize(display, 300, 240) display.update_board( SplineState("""\ A C E G 7 W B . . 7 5 . . . W 5 3 . . . . 3 1 . . . . 1 A C E G """)) display.update_board( SplineState("""\ A C E G 7 B W . . 7 5 . . B . 5 3 . . . . 3 1 . . . . 1 A C E G """)) display.resize(348, 264) render_display(display, actual)
def __init__(self, wx: QWidget, size: tuple, parent=None): super().__init__(parent=parent) self.wx = wx self.ctag = self.wx.__class__.__name__ try: self.wx.setMinimumSize(QSize(size[0]-1, size[1]-1)) self.wx.setMaximumSize(QSize(size[0]-1, size[1]-1)) except Exception as e: print(f"debug: self.wx is {self.wx} with type of {type(self.wx)}") print("suggestion: if the type of the self.wx is some internal type, " "check nodes.py file which node is causing this") raise e self.setWidget(self.wx)
def __init__(self): super().__init__() self.setWindowTitle("La misteriosa ventana sin nombre") boton = QPushButton("Aprieta aqui!") self.setCentralWidget(boton) self.setFixedSize(QSize(640, 480))
def test_empty(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters(240, 240, 'spargo_empty') as ( actual, expected): expected_scene = QGraphicsScene(0, 0, 240, 240) expected_scene.addPixmap( SpargoDisplay.load_pixmap('board-1.png', QSize(240, 240))).setPos(1, 0) expected_scene.render(expected) display = SpargoDisplay() display.resize(348, 264) render_display(display, actual) assert display.ui.move_text.text() == 'to move' assert display.ui.black_count.text() == '0' assert display.ui.red_count.text() == '' assert display.ui.white_count.text() == '0' black_icon = display.black_pixmap.toImage() assert display.ui.black_count_pixmap.pixmap().toImage() == black_icon assert display.ui.player_pixmap.pixmap().toImage() == black_icon white_icon = display.white_pixmap.toImage() assert display.ui.white_count_pixmap.pixmap().toImage() == white_icon
def sizeHint(self, option, index): """Change the sizehint this is to prevent horizontal crop Adjust the width slightly less than the default value """ size = super().sizeHint(option, index) return QSize(size.width() - 20, size.height() + 10)
def __init__(self, parent, dict, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.dict = dict self.parent = parent # add support for other languages locale = str(self.persepolis_setting.value('settings/locale')) QLocale.setDefault(QLocale(locale)) self.translator = QTranslator() if self.translator.load(':/translations/locales/ui_' + locale, 'ts'): QCoreApplication.installTranslator(self.translator) # connecting buttons self.open_pushButtun.clicked.connect(self.openFile) self.open_folder_pushButtun.clicked.connect(self.openFolder) self.ok_pushButton.clicked.connect(self.okButtonPressed) # labels # find gid gid = self.dict['gid'] # get file_path from data base self.add_link_dict = self.parent.persepolis_db.searchGidInAddLinkTable(gid) file_path = self.add_link_dict['download_path'] # save_as self.save_as_lineEdit.setText(file_path) self.save_as_lineEdit.setToolTip(file_path) # link link = str(self.dict['link']) self.link_lineEdit.setText(link) self.link_lineEdit.setToolTip(link) # file_name window_title = str(self.dict['file_name']) file_name = QCoreApplication.translate("after_download_src_ui_tr", "<b>File name</b>: ") + \ window_title self.setWindowTitle(window_title) self.file_name_label.setText(file_name) # size size = QCoreApplication.translate("after_download_src_ui_tr", "<b>Size</b>: ") + str(self.dict['size']) self.size_label.setText(size) # disable link_lineEdit and save_as_lineEdit self.link_lineEdit.setEnabled(False) self.save_as_lineEdit.setEnabled(False) # set window size and position size = self.persepolis_setting.value( 'AfterDownloadWindow/size', QSize(570, 290)) position = self.persepolis_setting.value( 'AfterDownloadWindow/position', QPoint(300, 300)) self.resize(size) self.move(position)