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


Python Image.to_widget方法代码示例

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


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

示例1: SettingPos

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import to_widget [as 别名]
class SettingPos(SettingString):
    '''Implementation of a string setting on top of a :class:`SettingItem`.
    It is visualized with a :class:`~kivy.uix.label.Label` widget that, when
    clicked, will open a :class:`~kivy.uix.popup.Popup` with a
    :class:`~kivy.uix.textinput.Textinput` so the user can enter a custom
    value.
    '''

    popup = ObjectProperty(None, allownone=True)
    '''(internal) Used to store the current popup when it's shown.

    :attr:`popup` is an :class:`~kivy.properties.ObjectProperty` and defaults
    to None.
    '''

#     position = ObjectProperty(None)
    '''(internal) Used to store the current textinput from the popup and
    to listen for changes.

    :attr:`textinput` is an :class:`~kivy.properties.ObjectProperty` and
    defaults to None.
    '''
    pic = StringProperty()
    position = StringProperty('50*50')

    def __init__(self, **kwargs):
        super(SettingPos, self).__init__(**kwargs)
        self.img = Image(source=self.pic)

    def on_panel(self, instance, value):
        if value is None:
            return
        self.bind(on_release=self._create_popup)

    def _dismiss(self, *largs):
        if self.popup:
            self.popup.dismiss()
        self.popup = None

    def _register(self, instance, touch):
        if self.img.collide_point(*touch.pos):
            #             self.position = '*'.join([str(p) for p in touch.pos])
            #             print(touch)
            #             print(self.img.pos)
            #             print(self.img.size)
            #             print(Window.size)
            x, y = self.img.to_widget(touch.pos[0], touch.pos[1], True)
            x = x - self.img.pos[0] - 20.0
            y = y + 68.0
#             print('%s * %s' % (x, y))
            self.position = str(x) + '*' + str(y)

    def _validate(self, instance):
        value = self.position
        self.value = value
#         print(self.value)
        self._dismiss()

    def _create_popup(self, instance):
        # create popup layout
        content = BoxLayout(orientation='vertical', spacing='5dp')
#         popup_width = min(0.95 * Window.width, dp(500))
        self.popup = popup = Popup(
            title=self.title, content=content)
        pos = [float(c) for c in self.value.split('*')]
        scat = ScatterCross(size=(20, 20), size_hint=(None, None), pos=pos)
        scat.bind(on_touch_up=self._register)
        self.img.add_widget(scat)
        content.add_widget(self.img)
        content.add_widget(SettingSpacer())

        # 2 buttons are created for accept or cancel the current value
        btnlayout = BoxLayout(size_hint_y=None, height='50dp', spacing='5dp')
        btn = Button(text='Ok')
        btn.bind(on_release=self._validate)
        btnlayout.add_widget(btn)
        btn = Button(text='Cancel')
        btn.bind(on_release=self._dismiss)
        btnlayout.add_widget(btn)
        content.add_widget(btnlayout)

        # all done, open the popup !
        popup.open()
开发者ID:bverdu,项目名称:onDemand,代码行数:85,代码来源:widgets.py


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