Ejemplo n.º 1
0
def test_qt_rect_to_rect_with_q_rect_f():
    rect = qt_rect_to_rect(QRectF(1.5, 2.5, 3.5, 4.5))
    assert isinstance(rect, Rect)
    assert rect.x == GraphicUnit(1.5)
    assert rect.y == GraphicUnit(2.5)
    assert rect.width == GraphicUnit(3.5)
    assert rect.height == GraphicUnit(4.5)
Ejemplo n.º 2
0
    def test_modified(self):
        test_font = Font("Bravura", 12, 2, False)
        modifying_family_name = test_font.modified(size=14,
                                                   weight=1,
                                                   italic=True)
        assert modifying_family_name.family_name == "Bravura"
        assert modifying_family_name.size == GraphicUnit(14)
        assert modifying_family_name.weight == 1
        assert modifying_family_name.italic is True

        modifying_size = test_font.modified(family_name="Cormorant Garamond",
                                            weight=1,
                                            italic=True)
        assert modifying_size.family_name == "Cormorant Garamond"
        assert modifying_size.size == GraphicUnit(12)
        assert modifying_size.weight == 1
        assert modifying_size.italic is True

        modifying_weight = test_font.modified(family_name="Cormorant Garamond",
                                              size=14,
                                              italic=True)
        assert modifying_weight.family_name == "Cormorant Garamond"
        assert modifying_weight.size == GraphicUnit(14)
        assert modifying_weight.weight == 2
        assert modifying_weight.italic is True

        modifying_italic = test_font.modified(family_name="Cormorant Garamond",
                                              size=14,
                                              weight=2)
        assert modifying_italic.family_name == "Cormorant Garamond"
        assert modifying_italic.size == GraphicUnit(14)
        assert modifying_italic.weight == 2
        assert modifying_italic.italic is False
Ejemplo n.º 3
0
def test_qt_rect_to_rect_with_q_rect():
    rect = qt_rect_to_rect(QRect(1, 2, 3, 4))
    assert isinstance(rect, Rect)
    assert rect.x == GraphicUnit(1)
    assert rect.y == GraphicUnit(2)
    assert rect.width == GraphicUnit(3)
    assert rect.height == GraphicUnit(4)
Ejemplo n.º 4
0
    def __post_init__(self):
        super().__setattr__(
            "qt_object",
            QtGui.QFont(
                self.family_name,
                # Float font sizes can't be set in QFont's constructor,
                # so set it to -1 (system default) here and set actual
                # size below with setPointSizeF
                -1,
                self.weight if self.weight is not None else -1,
                self.italic,
            ),
        )
        self.qt_object.setPointSizeF(self.size.base_value)
        super().__setattr__("_qt_font_info_object",
                            QtGui.QFontInfo(self.qt_object))
        super().__setattr__(
            "_qt_font_metrics_object",
            QtGui.QFontMetricsF(self.qt_object, neoscore._app_interface.view),
        )
        super().__setattr__("ascent",
                            GraphicUnit(self._qt_font_metrics_object.ascent()))
        super().__setattr__(
            "descent", GraphicUnit(self._qt_font_metrics_object.descent()))

        super().__setattr__(
            "x_height", GraphicUnit(self._qt_font_metrics_object.xHeight()))
Ejemplo n.º 5
0
    def __init__(
        self,
        start: PointDef,
        start_parent: GraphicObject,
        end: PointDef,
        end_parent: Optional[GraphicObject] = None,
    ):
        """
        Args:
            start: The position of the start-pedal mark relative to `start_parent`.
            start_parent: Anchor for the start-pedal mark, which must be in a staff
                or a staff itself.
            end: The position of the release-pedal mark relative to `end_parent`.
            end_parent: An optional anchor for the release-pedal mark. If provided,
                this must be in the same staff as `start_parent`. Otherwise, this
                defaults to `self`.
        """
        ObjectGroup.__init__(self, start, start_parent)
        Spanner2D.__init__(
            self,
            end if isinstance(end, Point) else Point(*end),
            cast(Positioned, end_parent) if end_parent else self,
        )
        StaffObject.__init__(self, self.parent)

        # Add opening pedal mark
        # (GraphicObject init handles registration with ObjectGroup)
        self.depress_mark = MusicText((GraphicUnit(0), GraphicUnit(0)),
                                      "keyboardPedalPed",
                                      parent=self)
        self.lift_mark = MusicText(self.end_pos,
                                   "keyboardPedalUp",
                                   parent=self.end_parent)
Ejemplo n.º 6
0
 def test_init(self):
     mock_parent = InvisibleObject((Unit(10), Unit(11)), parent=self.staff)
     test_object = MusicText((Unit(5), Unit(6)), "accidentalFlat",
                             mock_parent, self.font)
     assert test_object.x == GraphicUnit(5)
     assert test_object.y == GraphicUnit(6)
     assert test_object.text == "\ue260"
     assert test_object.font == self.font
     assert test_object.parent == mock_parent
Ejemplo n.º 7
0
def test_rect_to_qt_rect_f():
    qrect = rect_to_qt_rect_f(
        Rect(GraphicUnit(1.2), GraphicUnit(2.2), GraphicUnit(3.2),
             GraphicUnit(4.2)))
    assert isinstance(qrect, QRectF)
    assert qrect.x() == 1.2
    assert qrect.y() == 2.2
    assert qrect.width() == 3.2
    assert qrect.height() == 4.2
Ejemplo n.º 8
0
 def test_init(self):
     mock_parent = InvisibleObject((Unit(10), Unit(11)), parent=None)
     test_object = Text((Unit(5), Unit(6)), "testing", self.font,
                        mock_parent)
     assert test_object.x == GraphicUnit(5)
     assert test_object.y == GraphicUnit(6)
     assert test_object.text == "testing"
     assert test_object.font == self.font
     assert test_object.parent == mock_parent
Ejemplo n.º 9
0
def qt_point_to_point(qt_point: Union[QPoint, QPointF]) -> Point:
    """Create a Point from a QPoint or QPointF

    Args:
        qt_point: The source point

    Returns: Point
    """
    return Point(GraphicUnit(qt_point.x()), GraphicUnit(qt_point.y()))
Ejemplo n.º 10
0
 def test_init(self):
     test_font = Font("Bravura", 12, 2, False)
     assert test_font.family_name == "Bravura"
     assert test_font.size == GraphicUnit(12)
     assert test_font.weight == 2
     assert test_font.italic is False
     assert test_font._interface.family_name == "Bravura"
     assert test_font._interface.size == GraphicUnit(12)
     assert test_font._interface.weight == 2
     assert test_font._interface.italic is False
Ejemplo n.º 11
0
def qt_rect_to_rect(qt_rect: Union[QRect, QRectF]) -> Rect:
    """Create a Rect from a QRect or QRectF

    Args:
        qt_rect (QRect or QRectF): The source rect

    Returns: Rect
    """
    return Rect(
        GraphicUnit(qt_rect.x()),
        GraphicUnit(qt_rect.y()),
        GraphicUnit(qt_rect.width()),
        GraphicUnit(qt_rect.height()),
    )
Ejemplo n.º 12
0
 def test_bounding_rect_of(self):
     font = Font("Bravura", 12, 1, False)
     rect = font.bounding_rect_of("")
     assert rect == Rect(GraphicUnit(0), GraphicUnit(0), GraphicUnit(0),
                         GraphicUnit(0))
     rect = font.bounding_rect_of("abc")
     assert rect == Rect(GraphicUnit(1), GraphicUnit(-14), GraphicUnit(29),
                         GraphicUnit(14))
Ejemplo n.º 13
0
    def __init__(
        self,
        color: ColorDef = Color("#000000"),
        thickness: Optional[Unit] = None,
        pattern: PenPattern = PenPattern.SOLID,
        join_style: PenJoinStyle = PenJoinStyle.BEVEL,
        cap_style: PenCapStyle = PenCapStyle.SQUARE,
    ):
        """
        Args:
            color (Color or init tuple): The stroke color
            thickness (Unit): The stroke thickness.
                A value of `0` indicates Args cosmetic pixel width.
                Defaults to `constants.DEFAULT_PEN_THICKNESS`.
            pattern (PenPattern): The stroke pattern.
                Defaults to a solid line.
            join_style (PenJoinStyle): Defaults to a bevel join
            cap_style (PenCapStyle): Defaults to a square cap

        """
        self._color = color_from_def(color)
        self._thickness = (
            thickness
            if thickness is not None
            else GraphicUnit(constants.DEFAULT_PEN_THICKNESS)
        )
        self._pattern = pattern
        self._join_style = join_style
        self._cap_style = cap_style
        self._regenerate_interface()
Ejemplo n.º 14
0
 def setUp(self):
     neoscore.setup()
     self.pen = PenInterface(
         Color("#000000"),
         GraphicUnit(0),
         PenPattern.SOLID,
         PenJoinStyle.BEVEL,
         PenCapStyle.SQUARE,
     )
     self.brush = BrushInterface(Color("#000000"), BrushPattern.SOLID)
Ejemplo n.º 15
0
 def __init__(self, pos, pen=None, brush=None):
     super().__init__()
     self._pos = pos
     if pen:
         self._pen = pen
     else:
         self._pen = PenInterface(
             Color("#000000"),
             GraphicUnit(0),
             PenPattern.SOLID,
             PenJoinStyle.BEVEL,
             PenCapStyle.SQUARE,
         )
     if brush:
         self._brush = brush
     else:
         self._brush = BrushInterface(Color("#000000"), BrushPattern.SOLID)
Ejemplo n.º 16
0
 def __init__(
     self,
     family_name: str,
     size: Union[Unit, float],
     weight: Optional[int] = None,
     italic: bool = False,
 ):
     """
     Args:
         family_name: The font family name
         size: The size (height) of the font
         weight: The font weight on a 0-100 scale, where 50 is normal,
             lower numbers are lighter, and higher are darker.
             If `None` (the default), a normal weight will be used.
         italic: Whether or not the font is italicized
     """
     self._family_name = family_name
     self._size = size if isinstance(size, Unit) else GraphicUnit(size)
     self._weight = weight
     self._italic = italic
     self._interface = FontInterface(
         self.family_name, self.size, self.weight, self.italic
     )
Ejemplo n.º 17
0
def test_qt_point_to_point_with_q_point():
    point = qt_point_to_point(QPoint(1, 2))
    assert isinstance(point, Point)
    assert point.x == GraphicUnit(1)
    assert point.y == GraphicUnit(2)
Ejemplo n.º 18
0
def test_convert_all_to_unit_handles_strings_correctly():
    iterable = {"a": 5, "b": ["abcd", 2]}
    convert_all_to_unit(iterable, GraphicUnit)
    assert isinstance(iterable["b"][1], GraphicUnit)
    assert iterable["b"][1] == GraphicUnit(2)
    assert iterable["b"][0] == "abcd"
Ejemplo n.º 19
0
def test_convert_all_to_unit_dict_in_dict():
    iterable = {"a": 5, "b": {6: 7}}
    convert_all_to_unit(iterable, GraphicUnit)
    assert isinstance(iterable["b"], dict)
    assert isinstance(iterable["b"][6], GraphicUnit)
    assert iterable["b"][6] == GraphicUnit(7)
Ejemplo n.º 20
0
def test_convert_all_to_unit_simple_dict():
    iterable = {"a": 1, "b": GraphicUnit(2), "c": "h"}
    convert_all_to_unit(iterable, GraphicUnit)
    assert iterable["a"] == GraphicUnit(1)
Ejemplo n.º 21
0
def test_qt_point_to_point_with_q_point_f():
    point = qt_point_to_point(QPointF(1.5, 2.5))
    assert isinstance(point, Point)
    assert point.x == GraphicUnit(1.5)
    assert point.y == GraphicUnit(2.5)
Ejemplo n.º 22
0
 def test_init(self):
     mock_parent = InvisibleObject((Unit(10), Unit(11)), parent=None)
     test_object = InvisibleObject((Unit(5), Unit(6)), parent=mock_parent)
     assert test_object.x == GraphicUnit(5)
     assert test_object.y == GraphicUnit(6)
     assert test_object.parent == mock_parent
Ejemplo n.º 23
0
def test_convert_all_to_unit_list_in_list():
    iterable = [5, 6, [7, 8]]
    convert_all_to_unit(iterable, GraphicUnit)
    assert isinstance(iterable[2], list)
    assert isinstance(iterable[2][0], GraphicUnit)
    assert iterable[2][0] == GraphicUnit(7)
Ejemplo n.º 24
0
def test_convert_all_to_unit_simple_list():
    iterable = [1, GraphicUnit(2), "b"]
    convert_all_to_unit(iterable, GraphicUnit)
    assert iterable[0] == GraphicUnit(1)
Ejemplo n.º 25
0
def test_convert_all_to_unit_list_in_dict():
    iterable = {"a": 5, "b": [6, 7]}
    convert_all_to_unit(iterable, GraphicUnit)
    assert isinstance(iterable["b"], list)
    assert isinstance(iterable["b"][0], GraphicUnit)
    assert iterable["b"][0] == GraphicUnit(6)
Ejemplo n.º 26
0
def test_convert_all_to_unit_tuple_in_dict():
    iterable = {"a": 5, "b": (6, 7)}
    convert_all_to_unit(iterable, GraphicUnit)
    assert isinstance(iterable["b"], tuple)
    assert isinstance(iterable["b"][0], GraphicUnit)
    assert iterable["b"][0] == GraphicUnit(6)
Ejemplo n.º 27
0
def test_convert_all_to_unit_tuple_in_list():
    iterable = [(5, 6), 2, 3]
    convert_all_to_unit(iterable, GraphicUnit)
    assert isinstance(iterable[0][0], GraphicUnit)
    assert isinstance(iterable[0], tuple)
    assert iterable[0][0] == GraphicUnit(5)
Ejemplo n.º 28
0
def test_point_to_qt_point_f():
    qpoint = point_to_qt_point_f(Point(GraphicUnit(1.2), GraphicUnit(2.2)))
    assert isinstance(qpoint, QPointF)
    assert qpoint.x() == 1.2
    assert qpoint.y() == 2.2
Ejemplo n.º 29
0
def test_convert_all_to_unit_dict_in_list():
    iterable = [5, 6, 2, {"b": 3}]
    convert_all_to_unit(iterable, GraphicUnit)
    assert isinstance(iterable[3], dict)
    assert isinstance(iterable[3]["b"], GraphicUnit)
    assert iterable[3]["b"] == GraphicUnit(3)
Ejemplo n.º 30
0
 def test_graphic_unit_unit_conversion(self):
     assert_almost_equal(GraphicUnit(1), Unit(1))
     assert_almost_equal(GraphicUnit(2), Unit(2))