当前位置: 首页>>代码示例>>Python>>正文


Python AnchorLayout.collide_point方法代码示例

本文整理汇总了Python中kivy.uix.anchorlayout.AnchorLayout.collide_point方法的典型用法代码示例。如果您正苦于以下问题:Python AnchorLayout.collide_point方法的具体用法?Python AnchorLayout.collide_point怎么用?Python AnchorLayout.collide_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy.uix.anchorlayout.AnchorLayout的用法示例。


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

示例1: AppLauncherIconWidget

# 需要导入模块: from kivy.uix.anchorlayout import AnchorLayout [as 别名]
# 或者: from kivy.uix.anchorlayout.AnchorLayout import collide_point [as 别名]
class AppLauncherIconWidget(GridLayout):
    """
        Displays icon and name of a single application
        Also handles input on the app icon
    """

    __imageParent = None  # type: AnchorLayout
    __imageWidget = None  # type: ImageWidget
    __nameWidget = None  # type: Label

    __starter = None  # type: AppStarter

    __paddingTmp = -1  # type: int
    __touched = False  # type: int

    def __init__(self, image: Image, name: str, starter: AppStarter, height: int, **kwargs):
        super(AppLauncherIconWidget, self).__init__(**kwargs)

        self.__starter = starter

        self.cols = 1
        self.rows = 2

        self.rows_minimum[0] = height * 0.8
        self.rows_minimum[1] = height - self.rows_minimum[0]

        self.row_force_default = True

        self.__imageParent = AnchorLayout()
        self.__imageParent.anchor_x = 'center'
        self.__imageParent.anchor_y = 'center'

        self.__imageWidget = ImageWidget()
        self.__imageWidget.allow_stretch = True
        self.__imageWidget.keep_ratio = True
        self.__imageWidget.texture = image.texture

        self.__nameWidget = Label()
        self.__nameWidget.text = name
        self.__nameWidget.color = [0, 0, 0, 1]

        self.__imageParent.add_widget(self.__imageWidget)
        self.add_widget(self.__imageParent)
        self.add_widget(self.__nameWidget)

    def set_image_size(self, size: int, percentage: float):
        if self.__paddingTmp is -1:
            self.__imageParent.padding = [(size - (size * percentage)) / 2, (size - (size * percentage)) / 2, (size - (size * percentage)) / 2, (size - (size * percentage)) / 2]
        else:
            self.__paddingTmp = (size - (size * percentage)) / 2

    def on_touch_down(self, touch):
        if self.__imageWidget.collide_point(*touch.pos):
            self.__touched = True
            self.__paddingTmp = self.__imageParent.padding[0]
            self.__imageParent.padding = [self.__paddingTmp * 1 / 0.8, self.__paddingTmp * 1 / 0.8, self.__paddingTmp * 1 / 0.8, self.__paddingTmp * 1 / 0.8]
        else:
            self.__touched = False

    def on_touch_up(self, touch):
        if self.__imageParent.collide_point(*touch.pos):
            self.__starter.start_app()

        self.__imageParent.padding = [self.__paddingTmp, self.__paddingTmp, self.__paddingTmp, self.__paddingTmp]
        self.__paddingTmp = -1
        self.__touched = False
开发者ID:Silveryard,项目名称:SmartHome,代码行数:68,代码来源:AppLauncherIconWidget.py


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