Example #1
0
 def for_color(cls, color_str: str) -> Icon:
     color = gui.Color.from_text(color_str)
     if not color.isValid():
         raise TypeError()
     bitmap = gui.Pixmap(16, 16)
     bitmap.fill(color)
     return cls(bitmap)
Example #2
0
 def __init__(self, path: types.PathType | QtGui.QPixmap, width: int | None = None):
     pix = gui.Pixmap(os.fspath(path)) if not isinstance(path, QtGui.QPixmap) else path
     if width:
         pix = pix.scaledToWidth(width)
     super().__init__(pix)
     self.set_flags(stay_on_top=True, frameless=True)
     self.setEnabled(False)
Example #3
0
 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
Example #4
0
def test_pixmap():
    pix = gui.Pixmap()
    bytes(pix)
    pix.create_dot()
    pix.get_size()
    pix.get_rect()
    pix.to_image()
Example #5
0
 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
Example #6
0
 def __init__(self, path, width=None):
     pix = gui.Pixmap(str(path))
     if width:
         pix = pix.scaledToWidth(width)
     super().__init__(pix)
     self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint
                         | QtCore.Qt.FramelessWindowHint)
     self.setEnabled(False)
Example #7
0
def for_color(color: str | QtGui.QColor) -> gui.Icon:
    if isinstance(color, str):
        color = gui.Color.from_text(color)
    if color.isValid():
        bitmap = gui.Pixmap(16, 16)
        bitmap.fill(color)
        return gui.Icon(bitmap)
    else:
        return gui.Icon(_icon("mdi.card-outline"))
Example #8
0
 def for_color(cls, color_str: str):
     color = gui.Color.from_text(color_str)
     if color.isValid():
         bitmap = gui.Pixmap(16, 16)
         bitmap.fill(color)
         icon = gui.Icon(bitmap)
     else:
         icon = qta.icon("mdi.card-outline")
     return icon
Example #9
0
def test_clipboard(qapp):
    cb = qapp.get_clipboard()
    mimedata = QtCore.QMimeData()
    pixmap = gui.Pixmap(100, 100)
    image = pixmap.toImage()
    cb.set_mimedata(mimedata)
    cb.set_image(image)
    cb.set_pixmap(pixmap)
    assert cb.get_mimedata()
    assert cb.get_image() == image
    assert cb.get_pixmap().size() == pixmap.size()
Example #10
0
def test_iconengine():
    engine = gui.IconEngine()
    engine.get_available_sizes()
    engine.get_actual_size((100, 100))
    engine.get_actual_size(100)
    with pytest.raises(InvalidParamError):
        engine.get_actual_size(100, state="test")
    with pytest.raises(InvalidParamError):
        engine.get_actual_size(100, mode="test")
    px = gui.Pixmap()
    engine.add_pixmap(px, mode="normal", state="off")
Example #11
0
 def get_pixmap(
     self,
     size: types.SizeType | int,
     mode: gui.icon.ModeStr = "normal",
     state: gui.icon.StateStr = "off",
     scale: float | None = None,
 ) -> gui.Pixmap:
     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)
     if scale is None:
         return gui.Pixmap(
             self.pixmap(size, gui.icon.MODE[mode], gui.icon.STATE[state]))
     else:
         return gui.Pixmap(
             self.scaledPixmap(size, gui.icon.MODE[mode],
                               gui.icon.STATE[state], scale))
Example #12
0
 def grab_window(
     self,
     window: int = 0,
     x: int = 0,
     y: int = 0,
     width: int | None = None,
     height: int | None = None,
 ) -> gui.Pixmap:
     if width is None:
         width = -1
     if height is None:
         height = -1
     px = self.grabWindow(window, x, y, width, height)
     return gui.Pixmap(px)
Example #13
0
 def create_checkerboard_pattern(cls, n: int, color_1: types.ColorType,
                                 color_2: types.ColorType):
     """Construct tileable checkerboard pattern for paint events."""
     # Brush will be an n×n checkerboard pattern
     pat = gui.Pixmap(2 * n, 2 * n)
     bg0 = colors.get_color(color_1)
     bg1 = colors.get_color(color_2)
     with gui.Painter(pat) as p:
         p.setPen(QtCore.Qt.PenStyle.NoPen)
         # Paint a checkerboard pattern for the color to be overlaid on
         p.fillRect(pat.rect(), bg0)
         p.fillRect(0, 0, n, n, bg1)
         p.fillRect(n, n, 2 * n, 2 * n, bg1)
     return pat
Example #14
0
 def serialize_fields(self):
     pixmap = gui.Pixmap(self.pixmap())
     return dict(
         text=self.text(),
         scaled_contents=self.hasScaledContents(),
         indent=self.indent(),
         margin=self.margin(),
         text_format=self.get_text_format(),
         pixmap=pixmap if pixmap else None,
         open_external_links=self.openExternalLinks(),
         has_selected_text=self.hasSelectedText(),
         selected_text=self.selectedText(),
         alignment=(self.get_horizontal_alignment(),
                    self.get_vertical_alignment()),
         word_wrap=self.wordWrap(),
         text_interaction_flags=self.get_text_interaction(),
     )
Example #15
0
 def get_pixmap(self) -> gui.Pixmap:
     return gui.Pixmap(self.pixmap())
Example #16
0
 def get_pixmap(self) -> gui.Pixmap | None:
     pix = self.pixmap()
     if pix.isNull():
         return None
     return gui.Pixmap(pix)
Example #17
0
def test_pixmap():
    gui.Pixmap()
Example #18
0
 def get_drag_cursor(self, action: constants.DropActionStr) -> gui.Pixmap:
     if action not in constants.DROP_ACTION:
         raise InvalidParamError(action, constants.DROP_ACTION)
     px = self.dragCursor(constants.DROP_ACTION[action])
     return gui.Pixmap(px)