• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vecrec.Rect类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vecrec.Rect的典型用法代码示例。如果您正苦于以下问题:Python Rect类的具体用法?Python Rect怎么用?Python Rect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Rect类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_bounding_rect_too_small

def test_bounding_rect_too_small():
    # Just big enough, should not raise.
    drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=1,
            default_row_height=10,
            default_col_width=10,
    )
    # Too narrow.
    with pytest.raises(UsageError):
        drawing.make_grid(
                Rect.from_size(9, 10),
                num_rows=1,
                num_cols=1,
                default_row_height=10,
                default_col_width=10,
        )
    # Too short.
    with pytest.raises(UsageError):
        drawing.make_grid(
                Rect.from_size(10, 9),
                num_rows=1,
                num_cols=1,
                default_row_height=10,
                default_col_width=10,
        )
开发者ID:kxgames,项目名称:glooey,代码行数:27,代码来源:test_grid.py


示例2: test_padding

def test_padding():
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=1,
            padding=1,
    )
    assert cells == {
            (0,0): Rect(1, 1, 8, 8),
    }

    cells = drawing.make_grid(
            Rect.from_size(10, 11),
            num_rows=2,
            num_cols=1,
            padding=1,
    )
    assert cells == {
            (0,0): Rect(1, 6, 8, 4),
            (1,0): Rect(1, 1, 8, 4),
    }

    cells = drawing.make_grid(
            Rect.from_size(11, 10),
            num_rows=1,
            num_cols=2,
            padding=1
    )
    assert cells == {
            (0,0): Rect(1, 1, 4, 8),
            (0,1): Rect(6, 1, 4, 8),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:32,代码来源:test_grid.py


示例3: test_inner_padding

def test_inner_padding():
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=1,
            inner_padding=1,
    )
    assert cells == {
            (0,0): Rect(0, 0, 10, 10),
    }

    cells = drawing.make_grid(
            Rect.from_size(10, 11),
            num_rows=2,
            num_cols=1,
            inner_padding=1,
    )
    assert cells == {
            (0,0): Rect(0, 6, 10, 5),
            (1,0): Rect(0, 0, 10, 5),
    }

    cells = drawing.make_grid(
            Rect.from_size(11, 10),
            num_rows=1,
            num_cols=2,
            inner_padding=1
    )
    assert cells == {
            (0,0): Rect(0, 0, 5, 10),
            (0,1): Rect(6, 0, 5, 10),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:32,代码来源:test_grid.py


示例4: test_no_shared_state

def test_no_shared_state():
    """
    See issue #11.
    """
    grid_1 = drawing.Grid()
    grid_2 = drawing.Grid()
    i, j = 0, 0

    grid_1.set_row_height(i, 1)
    grid_2.set_row_height(i, 2)

    assert grid_1.get_requested_row_height(i) == 1
    assert grid_2.get_requested_row_height(i) == 2

    grid_1.set_col_width(j, 1)
    grid_2.set_col_width(j, 2)

    assert grid_1.get_requested_col_width(j) == 1
    assert grid_2.get_requested_col_width(j) == 2

    rect_1, rect_2 = Rect.from_size(1, 1), Rect.from_size(2, 2)
    assert rect_1 is not rect_2

    grid_1.set_min_cell_rect(i, j, rect_1)
    grid_2.set_min_cell_rect(i, j, rect_2)

    assert grid_1.get_min_cell_rect(i, j) is rect_1
    assert grid_2.get_min_cell_rect(i, j) is rect_2
开发者ID:kxgames,项目名称:glooey,代码行数:28,代码来源:test_grid.py


示例5: do_draw_hands

    def do_draw_hands(self):
        # We're hard-coding the radii of the hands here.  Probably it would be 
        # better to make separate attributes for these, but I think that would 
        # start to detract from the clarity of the example.

        rects = {
            'hour': Rect.from_size(self.custom_hour_hand_width, self.radius/2),
            'min': Rect.from_size(self.custom_minute_hand_width, self.radius),
            'sec': Rect.from_size(self.custom_second_hand_width, self.radius),
        }

        # The clock hands all start pointing towards 12:00, and the rotations 
        # are clockwise, so 90° is 3:00, 180° is 6:00, 270° is 9:00, etc.

        now = datetime.datetime.now()
        angles = {
            'hour': 360 * now.hour / 12,
            'min': 360 * now.minute / 60,
            'sec': 360 * now.second / 60,
        }

        for k in self._hands:
            rects[k].bottom = 0
            rects[k].center_x = 0

            self._hands[k].rect = rects[k]
            self._hands[k].group.angle = angles[k]
            self._hands[k].color = self._color
            self._hands[k].show()
开发者ID:kxgames,项目名称:glooey,代码行数:29,代码来源:line_clock.py


示例6: test_parent_changed

def test_parent_changed():
    child, parent = Rect.null(), Rect.null()

    def change_parent(child_rect, parent_rect):
        parent_rect.left += 1

    with pytest.raises(RuntimeError, match='change_parent'):
        glooey.drawing.align(change_parent, child, parent)
开发者ID:kxgames,项目名称:glooey,代码行数:8,代码来源:test_alignment.py


示例7: test_not_enough_cols

def test_not_enough_cols():
    with pytest.raises(UsageError):
        drawing.make_grid(
                Rect.null(),
                cells={
                    (0,1): Rect.null(),
                },
                num_rows=1,
                num_cols=1,
        )
开发者ID:kxgames,项目名称:glooey,代码行数:10,代码来源:test_grid.py


示例8: test_negative_sizes

def test_negative_sizes():
    # Initially I thought this should be an error, but then I decided that it 
    # probably just works as you'd expect it to, and it might be a useful way 
    # to create an overlapping effect or to get rid of padding in certain 
    # places.

    # row_heights can be negative.
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=2,
            num_cols=1,
            row_heights={0: -2},
    )
    assert cells == {
            (0,0): Rect(0, 12, 10, -2),
            (1,0): Rect(0,  0, 10, 12),
    }

    # default_row_height can be negative.
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=2,
            num_cols=1,
            row_heights={1: 'expand'},
            default_row_height=-2,
    )
    assert cells == {
            (0,0): Rect(0, 12, 10, -2),
            (1,0): Rect(0,  0, 10, 12),
    }

    # col_widths can be negative.
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=2,
            col_widths={0: -2},
    )
    assert cells == {
            (0,0): Rect(0, 0, -2, 10),
            (0,1): Rect(-2, 0, 12, 10),
    }

    # default_col_width can be negative.
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=2,
            col_widths={1: 'expand'},
            default_col_width=-2,
    )
    assert cells == {
            (0,0): Rect(0, 0, -2, 10),
            (0,1): Rect(-2, 0, 12, 10),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:55,代码来源:test_grid.py


示例9: test_child_outside_parent

def test_child_outside_parent():
    child = Rect.from_square(5)
    parent = Rect.from_square(6)

    def move_1px_right(child_rect, parent_rect):
        child_rect.left += 1

    # This should be fine the first time...
    glooey.drawing.align(move_1px_right, child, parent)

    # ...but out-of-bounds the second time.
    with pytest.raises(RuntimeError, match='move_1px_right'):
        glooey.drawing.align(move_1px_right, child, parent)
开发者ID:kxgames,项目名称:glooey,代码行数:13,代码来源:test_alignment.py


示例10: set_images

    def set_images(self, *, color=None, center=None, top=None, bottom=None, 
            left=None, right=None, top_left=None, top_right=None, 
            bottom_left=None, bottom_right=None, vtile=None, htile=None):

        self._color = color
        self._tile_images = {
                ij: img for ij, img in {
                    (0,0): top_left,
                    (0,1): top,
                    (0,2): top_right,
                    (1,0): left,
                    (1,1): center,
                    (1,2): right,
                    (2,0): bottom_left,
                    (2,1): bottom,
                    (2,2): bottom_right,
                }.items()
                if img is not None}

        self._grid.min_cell_rects={
            ij: Rect.from_size(img.width, img.height)
            for ij, img in self._tile_images.items()}

        if vtile is not None: self._vtile = vtile
        if htile is not None: self._htile = htile

        self._update_tiles()
开发者ID:,项目名称:,代码行数:27,代码来源:


示例11: __init__

    def __init__(self, rect=None, color='green', *,
            batch=None, group=None, usage='static', hidden=False):

        self._rect = rect or Rect.null()
        self._color = Color.from_anything(color)

        data = 'v2f/' + usage, 'c4B/' + usage
        super().__init__(batch, group, 4, GL_QUADS, data, hidden)
开发者ID:kxgames,项目名称:glooey,代码行数:8,代码来源:artists.py


示例12: test_one_cell

def test_one_cell():
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=1,
    )
    assert cells == {
            (0,0): Rect(0, 0, 10, 10),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:9,代码来源:test_grid.py


示例13: test_setters

def test_setters():
    grid = drawing.Grid()
    assert grid.make_claim() == (0, 0)

    grid.num_rows = 1
    grid.default_row_height = 10
    assert grid.make_claim() == (0, 10)

    grid.num_cols = 1
    grid.default_col_width = 10
    assert grid.make_claim() == (10, 10)

    grid.padding = 1
    assert grid.make_claim() == (12, 12)

    grid.num_rows = 2
    grid.num_cols = 2
    assert grid.make_claim() == (23, 23)

    grid.set_min_cell_rects({(0,0): Rect.from_size(20, 20)})
    assert grid.make_claim() == (33, 33)

    grid.del_min_cell_rects()
    assert grid.make_claim() == (23, 23)

    grid.set_min_cell_rect(0, 0, Rect.from_size(20, 20))
    assert grid.make_claim() == (33, 33)

    grid.del_min_cell_rect(0, 0)
    assert grid.make_claim() == (23, 23)

    grid.set_row_height(0, 20)
    assert grid.make_claim() == (23, 33)

    grid.del_row_height(0)
    assert grid.make_claim() == (23, 23)

    grid.set_col_width(0, 20)
    assert grid.make_claim() == (33, 23)

    grid.del_col_width(0)
    assert grid.make_claim() == (23, 23)
开发者ID:kxgames,项目名称:glooey,代码行数:42,代码来源:test_grid.py


示例14: test_no_expandable_cells

def test_no_expandable_cells():
    # If the grid can't fill all the space made available to it, it will pack 
    # against the top-left corner.  I chose this corner arbitrarily (although 
    # other corners would've been slightly harder to implement).  I decided 
    # against adding the ability to control how the grid fits in its bounding 
    # box for two reasons.  First, you can get the same effect by simply adding 
    # expandable rows or columns.  Second, you can just change the bounding 
    # box.  Still, it's possible I'll change my mind about this behavior.

    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=1,
            row_heights={0: 2},
            col_widths={0: 2},
    )
    assert cells == {
            (0,0): Rect(0, 8, 2, 2),
    }

    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=1,
            default_row_height=2,
            default_col_width=2,
    )
    assert cells == {
            (0,0): Rect(0, 8, 2, 2),
    }

    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            cells={
                (0,0): Rect.from_size(2, 2),
            },
            default_row_height=0,
            default_col_width=0,
    )
    assert cells == {
            (0,0): Rect(0, 8, 2, 2),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:42,代码来源:test_grid.py


示例15: test_make_claim

def test_make_claim():
    grid = drawing.Grid()
    cells = {
        (0,0): Rect.from_size(1, 2),
        (1,1): Rect.from_size(3, 4),
    }
    assert grid.make_claim(cells) == (6, 8)
    assert grid.make_claim() == (6, 8)
    assert grid.min_width == 6
    assert grid.min_height == 8
    assert grid.min_bounding_rect == Rect(0, 0, 6, 8)

    grid.default_row_height = 0
    grid.default_col_width = 0

    assert grid.make_claim(cells) == (4, 6)
    assert grid.make_claim() == (4, 6)
    assert grid.min_width == 4
    assert grid.min_height == 6
    assert grid.min_bounding_rect == Rect(0, 0, 4, 6)
开发者ID:kxgames,项目名称:glooey,代码行数:20,代码来源:test_grid.py


示例16: test_two_cells

def test_two_cells():
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=2,
            num_cols=1,
    )
    assert cells == {
            (0,0): Rect(0, 5, 10, 5),
            (1,0): Rect(0, 0, 10, 5),
    }

    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=2,
    )
    assert cells == {
            (0,0): Rect(0, 0, 5, 10),
            (0,1): Rect(5, 0, 5, 10),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:20,代码来源:test_grid.py


示例17: set_appearance

    def set_appearance(self, *, color=None, outline=None, image=None, 
            center=None, top=None, bottom=None, left=None, right=None, 
            top_left=None, top_right=None, bottom_left=None, bottom_right=None, 
            vtile='auto', htile='auto'):

        if image and center:
            raise UsageError("""\
specifying both 'image' and 'center' is ambiguous.

Both of these options specify an image that should go in the middle of the 
frame.  The only difference is that, if 'htile' or 'vtile' are set to 'auto' 
(the default value), 'center' enables tiling and 'image' doesn't.""")

        # Decide whether the background should tile in either dimension.

        auto_vtile = False
        auto_htile = False

        if top or bottom:
            auto_vtile = True
        if left or right:
            auto_htile = True
        if center and not (top or left or bottom or right):
            auto_vtile = True
            auto_htile = True

        self._vtile = auto_vtile if vtile == 'auto' else vtile
        self._htile = auto_htile if htile == 'auto' else htile

        # Store the images in a grid-like data structure.

        self._color = color
        self._outline = outline
        self._tile_images = {
                ij: img for ij, img in {
                    (0,0): top_left,
                    (0,1): top,
                    (0,2): top_right,
                    (1,0): left,
                    (1,1): center or image,
                    (1,2): right,
                    (2,0): bottom_left,
                    (2,1): bottom,
                    (2,2): bottom_right,
                }.items()
                if img is not None}

        self._grid.min_cell_rects = {
            ij: Rect.from_size(img.width, img.height)
            for ij, img in self._tile_images.items()}

        self._update_tiles()
开发者ID:kxgames,项目名称:glooey,代码行数:52,代码来源:artists.py


示例18: test_request_row_height

def test_request_row_height():
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=2,
            num_cols=1,
            row_heights={0: 2},
    )
    assert cells == {
            (0,0): Rect(0, 8, 10, 2),
            (1,0): Rect(0, 0, 10, 8),
    }

    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=2,
            num_cols=1,
            row_heights={1: 2},
    )
    assert cells == {
            (0,0): Rect(0, 2, 10, 8),
            (1,0): Rect(0, 0, 10, 2),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:22,代码来源:test_grid.py


示例19: test_request_col_width

def test_request_col_width():
    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=2,
            col_widths={0: 2},
    )
    assert cells == {
            (0,0): Rect(0, 0, 2, 10),
            (0,1): Rect(2, 0, 8, 10),
    }

    cells = drawing.make_grid(
            Rect.from_size(10, 10),
            num_rows=1,
            num_cols=2,
            col_widths={1: 2},
    )
    assert cells == {
            (0,0): Rect(0, 0, 8, 10),
            (0,1): Rect(8, 0, 2, 10),
    }
开发者ID:kxgames,项目名称:glooey,代码行数:22,代码来源:test_grid.py


示例20: do_resize_children

        def do_resize_children(self):
            grip_width, grip_height = self.grip.claimed_size

            if self.bar.scale_grip:
                scaled_width, scaled_height = self.bar._get_scaled_grip_size()
                grip_width = clamp(scaled_width, grip_width, self.width)
                grip_height = clamp(scaled_height, grip_height, self.height)

            # Copied from `Mover.do_resize_children()`; refer there for 
            # details.  Maybe should be more DRY...
            child_rect = Rect.from_size(grip_width, grip_height)
            self.child._resize(child_rect)
            self._keep_child_in_rect()
开发者ID:kxgames,项目名称:glooey,代码行数:13,代码来源:scrolling.py



注:本文中的vecrec.Rect类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vector.make_vector函数代码示例发布时间:2022-05-26
下一篇:
Python vec3._vec3函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap