def get_available_sizes(self, mode: ModeStr = "normal", state: StateStr = "off") -> list[core.Size]: if mode not in MODE: raise InvalidParamError(mode, MODE) if state not in STATE: raise InvalidParamError(state, STATE) return [ core.Size(i) for i in self.availableSizes(MODE[mode], STATE[state]) ]
def add_pixmap( self, pixmap: QtGui.QPixmap, mode: gui.icon.ModeStr, state: gui.icon.StateStr, ): if mode not in gui.icon.MODE: raise InvalidParamError(mode, gui.icon.MODE) if state not in gui.icon.STATE: raise InvalidParamError(state, gui.icon.STATE) self.addPixmap(pixmap, gui.icon.MODE[mode], gui.icon.STATE[state])
def get_angle_between( self, orientation_1: constants.ScreenOrientationStr, orientation_2: constants.ScreenOrientationStr, ): if orientation_1 not in constants.SCREEN_ORIENTATION: raise InvalidParamError(orientation_1, constants.SCREEN_ORIENTATION) if orientation_2 not in constants.SCREEN_ORIENTATION: raise InvalidParamError(orientation_2, constants.SCREEN_ORIENTATION) self.angleBetween( constants.SCREEN_ORIENTATION[orientation_1], constants.SCREEN_ORIENTATION[orientation_2], )
def set_feature_weight(self, feature: FeatureTypeStr, weight: FeatureWeightStr): """Set the feature weight. Args: feature: Feature type weight: Feature weight Raises: InvalidParamError: feature weight / type does not exist """ if weight not in FEATURE_WEIGHTS: raise InvalidParamError(weight, FEATURE_WEIGHTS) if feature not in FEATURE_TYPES: raise InvalidParamError(feature, FEATURE_TYPES) self.setFeatureWeight(FEATURE_TYPES[feature], FEATURE_WEIGHTS[weight])
def get_pixmap( self, size: types.SizeType | int, mode: ModeStr = "normal", state: StateStr = "off", ) -> QtGui.QPixmap: if mode not in MODE: raise InvalidParamError(mode, MODE) if state not in STATE: raise InvalidParamError(state, STATE) if isinstance(size, tuple): size = core.Size(*size) elif isinstance(size, int): size = core.Size(size, size) return self.pixmap(size, MODE[mode], STATE[state])
def set_path(cls, fmt: FormatStr, scope: ScopeStr, path: types.PathType): """Set the path to the settings file. Args: fmt: the default format to use scope: the scope to use Raises: InvalidParamError: invalid format or scope """ if fmt not in FORMAT: raise InvalidParamError(fmt, FORMAT) if scope not in SCOPE: raise InvalidParamError(scope, SCOPE) cls.setPath(FORMAT[fmt], SCOPE[scope], os.fspath(path))
def get_display_name( self, datetime: QtCore.QDateTime | TimeTypeStr, name_type: NameTypeStr = "default", locale: core.Locale | None = None, ) -> str: if isinstance(datetime, str): if datetime not in TIME_TYPE: raise InvalidParamError(datetime, TIME_TYPE) datetime = TIME_TYPE[datetime] if name_type not in NAME_TYPE: raise InvalidParamError(name_type, NAME_TYPE) if locale is None: locale = core.Locale() return self.displayName(datetime, NAME_TYPE[name_type], locale)
def get_image(self, mode: ModeStr = "clipboard") -> gui.Image | None: if mode not in MODES: raise InvalidParamError(mode, MODES) img = gui.Image(self.item.image(MODES[mode])) if img.isNull(): return None return img
def get_pixmap(self, mode: ModeStr = "clipboard") -> gui.Pixmap | None: if mode not in MODES: raise InvalidParamError(mode, MODES) pix = gui.Pixmap(self.item.pixmap(MODES[mode])) if pix.isNull(): return None return pix
def set_edit_triggers(self, *triggers: EditTriggerStr | None): items = ["none" if t is None else t for t in triggers] for item in items: if item not in EDIT_TRIGGERS: raise InvalidParamError(item, EDIT_TRIGGERS) flags = helpers.merge_flags(items, EDIT_TRIGGERS) self.setEditTriggers(flags)
def get_style_icon(cls, icon: widgets.style.StandardPixmapStr) -> gui.Icon: style = cls.style() # icon_size = style.pixelMetric(QtWidgets.QStyle.PM_MessageBoxIconSize) if icon not in widgets.style.STANDARD_PIXMAP: raise InvalidParamError(icon, widgets.style.STANDARD_PIXMAP) icon = style.standardIcon(widgets.style.STANDARD_PIXMAP[icon]) return gui.Icon(icon)
def add_resource( self, resource_type: ResourceTypeStr, name: types.PathType, resource ): if resource_type not in RESOURCE_TYPES: raise InvalidParamError(resource_type, RESOURCE_TYPES) url = core.Url(name) self.addResource(RESOURCE_TYPES[resource_type], url, resource)
def set_bar_style(self, style: BarStyleStr): if style not in BAR_STYLE: raise InvalidParamError(style, BAR_STYLE) if style != self.bar_style: self.bar_style = style self._rebuild_brush = True self.update()
def get_actual_size( self, size: types.SizeType | int, mode: gui.icon.ModeStr = "normal", state: gui.icon.StateStr = "off", ) -> core.Size: if mode not in gui.icon.MODE: raise InvalidParamError(mode, gui.icon.MODE) if state not in gui.icon.STATE: raise InvalidParamError(state, gui.icon.STATE) if isinstance(size, tuple): size = core.Size(*size) elif isinstance(size, int): size = core.Size(size, size) return core.Size( self.actualSize(size, gui.icon.MODE[mode], gui.icon.STATE[state]))
def get_pixmap(self, typ: widgets.wizard.WizardPixmapStr) -> gui.Pixmap | None: if typ not in widgets.wizard.WIZARD_PIXMAP: raise InvalidParamError(typ, widgets.wizard.WIZARD_PIXMAP) pix = gui.Pixmap(self.pixmap(widgets.wizard.WIZARD_PIXMAP[typ])) if pix.isNull(): return None return pix
def set_resize_mode(self, mode: ModeStr, col: int | None = None): if mode not in MODES: raise InvalidParamError(mode, MODES) if col is None: self.setSectionResizeMode(MODES[mode]) else: self.setSectionResizeMode(col, MODES[mode])
def scroll_to_item( self, item: QtWidgets.QListWidgetItem, mode: widgets.abstractitemview.ScrollHintStr = "ensure_visible", ): if mode not in widgets.abstractitemview.SCROLL_HINT: raise InvalidParamError(mode, widgets.abstractitemview.SCROLL_HINT) self.scrollToItem(item, widgets.abstractitemview.SCROLL_HINT[mode])
def x_to_cursor( self, x: float, cursor_pos: CursorPositionStr = "cursor_between_characters" ) -> int: if cursor_pos not in CURSOR_POSITION: raise InvalidParamError(cursor_pos, CURSOR_POSITION) return self.xToCursor(x, CURSOR_POSITION[cursor_pos])
def handle_input( self, input_type: InputStr, position: types.PointFType, timestamp: int = 0 ) -> bool: if isinstance(position, tuple): position = core.PointF(*position) if input_type not in INPUT: raise InvalidParamError(input_type, INPUT) return self.handleInput(INPUT[input_type], position, timestamp)
def set_pixmap(self, pixmap: QtGui.QPixmap | None, mode: ModeStr = "clipboard"): if mode not in MODES: raise InvalidParamError(mode, MODES) if pixmap is None: pixmap = QtGui.QPixmap() self.item.setPixmap(pixmap, MODES[mode])
def colliding_items( self, item: QtWidgets.QGraphicsItem, mode: constants.ItemSelectionModeStr = "intersects_shape", ) -> list[QtWidgets.QGraphicsItem]: if mode not in constants.ITEM_SELECTION_MODE: raise InvalidParamError(mode, constants.ITEM_SELECTION_MODE) return self.collidingItems(item, constants.ITEM_SELECTION_MODE[mode])
def set_window_flags(self, *flags: constants.WindowFlagStr, append: bool = False): for flag in flags: if flag not in constants.WINDOW_FLAGS: raise InvalidParamError(flag, constants.WINDOW_FLAGS) result = helpers.merge_flags(flags, constants.WINDOW_FLAGS) if append: result = result | self.windowFlags() self.setWindowFlags(result)
def set_cursor(self, cursor: constants.CursorShapeStr | QtGui.QCursor) -> None: if isinstance(cursor, QtGui.QCursor): curs = cursor else: if cursor not in constants.CURSOR_SHAPE: raise InvalidParamError(cursor, constants.CURSOR_SHAPE) curs = gui.Cursor(constants.CURSOR_SHAPE[cursor]) self.setCursor(curs)
def set_image(self, image: QtGui.QImage | None, mode: ModeStr = "clipboard"): if mode not in MODES: raise InvalidParamError(mode, MODES) if image is None: image = QtGui.QImage() self.item.setImage(image, MODES[mode])
def add_file( self, path: types.PathType, size: types.SizeType | int, mode: gui.icon.ModeStr, state: gui.icon.StateStr, ): if mode not in gui.icon.MODE: raise InvalidParamError(mode, gui.icon.MODE) if state not in gui.icon.STATE: raise InvalidParamError(state, gui.icon.STATE) if isinstance(size, tuple): size = core.Size(*size) elif isinstance(size, int): size = core.Size(size, size) self.addFile(os.fspath(path), size, gui.icon.MODE[mode], gui.icon.STATE[state])
def elided_text(self, text: str, mode: constants.ElideModeStr, width: int, flags=0) -> str: if mode not in constants.ELIDE_MODE: raise InvalidParamError(mode, constants.ELIDE_MODE) return self.elidedText(text, constants.ELIDE_MODE[mode], width, flags)
def set_pixmap( self, typ: widgets.wizard.WizardPixmapStr, pixmap: QtGui.QPixmap | None ): if typ not in widgets.wizard.WIZARD_PIXMAP: raise InvalidParamError(typ, widgets.wizard.WIZARD_PIXMAP) if pixmap is None: pixmap = QtGui.QPixmap() self.setPixmap(widgets.wizard.WIZARD_PIXMAP[typ], pixmap)
def set_composition_mode(self, mode: CompositionModeStr): """Set the current composition mode. Raises: InvalidParamError: composition mode does not exist """ if mode not in COMPOSITION_MODE: raise InvalidParamError(mode, COMPOSITION_MODE) self.setCompositionMode(COMPOSITION_MODE[mode])
def get_feature_weight(self, feature: FeatureTypeStr) -> FeatureWeightStr: """Return current feature weight. Returns: Feature weight """ if feature not in FEATURE_TYPES: raise InvalidParamError(feature, FEATURE_TYPES) return FEATURE_WEIGHTS.inverse[self.featureWeight(FEATURE_TYPES[feature])]
def add_pixmap( self, data: QtCore.QByteArray | QtGui.QPixmap | bytes, mode: ModeStr = "normal", state: StateStr = "off", ): if mode not in MODE: raise InvalidParamError(mode, MODE) if state not in STATE: raise InvalidParamError(state, STATE) if isinstance(data, bytes): data = QtCore.QByteArray(data) if isinstance(data, QtCore.QByteArray): pixmap = QtGui.QPixmap() pixmap.loadFromData(data) else: pixmap = data self.addPixmap(pixmap, MODE[mode], STATE[state])