def _ui_layer_paintEvent(self, _): """Draw screenshot and selection rectangle on window.""" painter = QtGui.QPainter(self.ui_layer) if logger.getEffectiveLevel() == logging.DEBUG: # Draw debug information on screen screen = self.tray.screens[self.screen_idx] x = y = 25 painter.setPen(QtGui.QPen(self.color)) painter.drawText(x, y * 1, f"QScreen: {screen.geometry}") painter.drawText(x, y * 2, f"Image: {screen.screenshot.size().toTuple()}") painter.drawText(x, y * 3, f"Pos QScreen: {self.selection.rect}") painter.drawText(x, y * 4, f"Pos Image: {self.selection.scaled_rect}") painter.drawText(x, y * 5, f"Scale factor: {self.selection.scale_factor}") painter.drawText(x, y * 6, f"DPR: {screen.device_pixel_ratio}") if not self.is_selecting: return # Draw selection rectangle rect = self.selection.rect painter.setPen(QtGui.QPen(self.color, self.pen_width, QtCore.Qt.DashLine)) painter.drawRect(*rect.geometry) # Draw Mode indicator if CaptureMode[self.tray.settings.value("mode").upper()] is CaptureMode.PARSE: mode_indicator = get_icon("parse.svg") else: mode_indicator = get_icon("raw.svg") mode_indicator.paint(painter, rect.right - 24, rect.top - 30, 24, 24) painter.end()
def __init__(self, screen_idx: int, color: str, parent=None): """Initialize window.""" super().__init__() self.screen_idx: int = screen_idx self.color: QtGui.QColor = QtGui.QColor(color) self.tray: QtWidgets.QMainWindow = parent or self self.ui_layer_css = f"#ui_layer {{border: 3px solid {self.color.name()};}}" self.is_positioned: bool = False # Window properties self.setObjectName(f"window-{self.screen_idx}") self.setWindowTitle("NormCap") self.setWindowIcon(get_icon("normcap.png")) self.setAnimated(False) self.setEnabled(True) # Prepare selection rectangle self.selection: Selection = Selection() self.is_selecting: bool = False self.mode_indicator: QtGui.QIcon = QtGui.QIcon() self.pen_width: int = 2 # Setup widgets and show logger.debug("Create window for screen %s", self.screen_idx) self._add_image_layer() self._add_ui_layer()
def _create_message_box(): message_box = QtWidgets.QMessageBox() # Necessary on wayland for main window to regain focus: message_box.setWindowFlags(QtCore.Qt.Popup) message_box.setIconPixmap(get_icon("normcap.png").pixmap(48, 48)) message_box.setStandardButtons( QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel ) message_box.setDefaultButton(QtWidgets.QMessageBox.Ok) return message_box
def __init__(self, parent: QtWidgets.QMainWindow, settings: QtCore.QSettings): super().__init__(parent) self.setObjectName("settings_icon") self.settings = settings self.setCursor(QtCore.Qt.ArrowCursor) self.setFixedSize(38, 38) self.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) self.setIcon(get_icon("settings.svg")) self.setIconSize(QtCore.QSize(26, 26)) self.setPopupMode(QtWidgets.QToolButton.InstantPopup) self.setAutoRaise(True) self.message_box = QtWidgets.QMessageBox() self.message_box.setIconPixmap(get_icon("normcap.png").pixmap(48, 48)) # Necessary on wayland for main window to regain focus: self.message_box.setWindowFlags(QtCore.Qt.Popup) self._add_menu() self.setStyleSheet(_BUTTON_STYLE) self.com = Communicate()
def __init__(self, parent, args): logger.debug("Set up tray icon") super().__init__(parent) self.com = Communicate() self.settings = Settings("normcap", "settings", init_settings=args) if args.get("reset", False): self.settings.reset() self.capture.mode = ( CaptureMode.PARSE if self.settings.value("mode") == "parse" else CaptureMode.RAW ) self.clipboard = QtWidgets.QApplication.clipboard() self.screens: dict[int, Screen] = system_info.screens() self.setIcon(utils.get_icon("tray.png", "tool-magic-symbolic")) self._add_tray_menu() self._add_update_checker() self._add_notifier() self._set_signals() self._update_screenshots()
def test_get_icon_sytem_use_fallback(qtbot): icon = utils.get_icon("normcap.png", "not-existing-icon") assert icon.name() == "" assert len(icon.availableSizes()) == 1
def test_get_icon_sytem(qtbot): icon = utils.get_icon("normcap.png", "edit-undo") assert icon.name() == "edit-undo" assert len(icon.availableSizes()) >= 1
def test_get_icon_custom(qtbot): icon = utils.get_icon("normcap.png") assert icon.name() == "" assert len(icon.availableSizes()) == 1