def detach_tab(self, index: int, point: types.PointType): """Detach tab by removing its contents and placing them in a DetachedTab window. Args: index (int): index location of the tab to be detached point (QtCore.QPoint): screen pos for creating the new DetachedTab window Returns: None: Description """ # Get the tab content if isinstance(point, tuple): point = QtCore.QPoint(*point) name = self.tabText(index) icon = self.tab_icon(index) if icon is None: icon = self.window().windowIcon() widget = self.widget(index) try: widget_rect = widget.frameGeometry() except AttributeError: return # Create a new detached tab window detached_tab = DetachedTab(name, widget) detached_tab.set_modality("none") detached_tab.set_icon(icon) detached_tab.setGeometry(widget_rect) detached_tab.on_close.connect(self.attach_tab) detached_tab.move(point) detached_tab.show() # Create a reference to maintain access to the detached tab self.detached_tabs[name] = detached_tab
def pixmap(self, size: QtCore.QSize, mode: QtGui.QIcon.Mode, state: QtGui.QIcon.State) -> QtGui.QPixmap: """Return the icon as a pixmap with requested size, mode, and state.""" img = gui.Image(size, QtGui.QImage.Format.Format_ARGB32) img.fill(QtCore.Qt.GlobalColor.transparent) pixmap = QtGui.QPixmap.fromImage( img, QtCore.Qt.ImageConversionFlag.NoFormatConversion) rect = QtCore.QRect(QtCore.QPoint(0, 0), size) self.paint(QtGui.QPainter(pixmap), rect, mode, state) return pixmap
def window_frame_section_at( self, point: types.PointType) -> constants.WindowFrameSectionStr: """Return the window frame section at given position. Returns: str: Window frame section """ if isinstance(point, tuple): point = QtCore.QPoint(*point) return constants.WINDOW_FRAME_SECTION.inverse[ self.windowFrameSectionAt(point)]
def show_text( cls, position: types.PointType | None = None, text: str = "", linebreak_px: int = 400, ): if position is None: position = QtGui.QCursor.pos() elif isinstance(position, tuple): position = QtCore.QPoint(*position) cls.showText(position, f'<div style="max-width: {linebreak_px}px">{text}</div>')
return constants.CAP_STYLE.inverse[self.capStyle()] def set_join_style(self, style: constants.JoinStyleStr): """Set join style to use. Args: style: join style to use Raises: InvalidParamError: join style does not exist """ if style not in constants.JOIN_STYLE: raise InvalidParamError(style, constants.JOIN_STYLE) self.setJoinStyle(constants.JOIN_STYLE[style]) def get_join_style(self) -> constants.JoinStyleStr: """Return current join style. Returns: join style """ return constants.JOIN_STYLE.inverse[self.joinStyle()] def create_stroke(self, path: QtGui.QPainterPath) -> gui.PainterPath: return gui.PainterPath(self.createStroke(path)) if __name__ == "__main__": p = PainterPathStroker(QtCore.QPoint(1, 1)) print(list(p))
def get_screen_at(self, point: types.PointType) -> gui.Screen: if isinstance(point, tuple): point = QtCore.QPoint(*point) return gui.Screen(self.screenAt(point))
self.addRect(rect) def set_fill_rule(self, rule: constants.FillRuleStr): """Set fill rule. Args: rule: fill rule to use Raises: InvalidParamError: fill rule does not exist """ if rule not in constants.FILL_RULE: raise InvalidParamError(rule, constants.FILL_RULE) self.setFillRule(constants.FILL_RULE[rule]) def get_fill_rule(self) -> constants.FillRuleStr: """Return current fill rule. Returns: fill rule """ return constants.FILL_RULE.inverse[self.fillRule()] def get_bounding_rect(self) -> core.RectF: return core.RectF(self.boundingRect()) if __name__ == "__main__": p = PainterPath(QtCore.QPoint(1, 1)) print(type(p[0]))