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


Python Screen.btn_functions方法代码示例

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


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

示例1: build

# 需要导入模块: from kivy.uix.screenmanager import Screen [as 别名]
# 或者: from kivy.uix.screenmanager.Screen import btn_functions [as 别名]
    def build(self):
        root = FloatLayout()

        ## Screen Manager
        self.screen_manager = ScreenManager(transition=SlideTransition(),size_hint=[None,None], pos_hint={'left': 1})
        root.bind(size=self.update_size)
        root.add_widget(self.screen_manager)

        ## "Navbar" Buttons
        ## These are meant to work like the Android navbar would, and I have named them as such.
        # These two functions are used for a indicator for the button being pressed.
        def rend_circle(btn):
            with btn.canvas:
                Color(1,1,1,0.25)
                size = (btn.size[0], btn.size[1]*1.5)
                btn.hl = Ellipse(pos=( btn.pos[0]+((btn.size[0]/2)-(size[0]/2)), btn.pos[1]+((btn.size[1]/2)-(size[1]/2)) ), size=size)
                Color(1,1,1,1) # Reset the color, otherwise the background goes dark
        def derend_circle(btn):
            btn.canvas.remove(btn.hl)
        self.win_btn = Button(text='', size_hint=[None,None],size=[192,192],height=192,pos_hint={'right': 1, 'center_y': 0.8})
        self.win_btn.bind(on_press=rend_circle)
        self.win_btn.bind(on_release=derend_circle)
        self.win_btn.bind(on_release=self.pressed_win)

        self.home_btn = Button(text='', size_hint=[None,None],size=[192,192],pos_hint={'right': 1, 'center_y': 0.5})
        self.home_btn.bind(on_press=rend_circle)
        self.home_btn.bind(on_release=derend_circle)
        self.home_btn.bind(on_release=self.pressed_home)

        self.back_btn = Button(text='', size_hint=[None,None],size=[192,192],pos_hint={'right': 1, 'center_y': 0.2})
        self.back_btn.bind(on_press=rend_circle)
        self.back_btn.bind(on_release=derend_circle)
        self.back_btn.bind(on_release=self.pressed_back)

        root.add_widget(self.win_btn)
        root.add_widget(self.home_btn)
        root.add_widget(self.back_btn)

        # Render the background
        def update_rect(instance, value):
            instance.bg.pos = instance.pos
            instance.bg.size = instance.size
        self.screen_manager.bind(size=update_rect,pos=update_rect)
        with self.screen_manager.canvas.before:
            self.screen_manager.bg = Rectangle(source='background.png')

        Loader.loading_image = 'loading.png'
        ## FileChooser
        chooser_screen = Screen(name='chooser')
        chooser = FileChooserGalleryView(rootpath=PHOTOS_PATH)
        chooser.file_system = filesystem
        def select_folder(chooser, photostrip):
            photostrip.set_path(chooser.current_entry.path)
            self.goto_screen('photostrip', 'left')
        chooser.bind(on_select_folder=lambda args:select_folder(chooser, photostrip))
        chooser_screen.add_widget(chooser)

        ## Painter
        self.paint_screen = PaintScreen(name='painter')
        self.paint_screen.bind(on_leave=lambda src: self.paint_screen.painter.clear())

        ## ImageViewer
        viewer_screen = ViewerScreen(name='viewer')
        viewer_screen.bind(on_enter=lambda src:setattr(self.paint_screen.image,'source',viewer_screen.image.source))

        ## Photo strip
        def foo(a):
            print type(a), a
        photostrip_screen = Screen(name='photostrip')
        photostrip = PhotoStrip()
        photostrip_screen.add_widget(photostrip)
        photostrip.bind(
                on_press=lambda src,fn:viewer_screen.set_image(fn),
                on_release=lambda src,fn: self.goto_screen('painter', 'left'),
        )

        # Set up the icons and functions for the navbar buttons
        chooser_screen.btns             = [None,                                       'ic_action_refresh.png',      None]
        chooser_screen.btn_functions    = [None,                                       chooser._trigger_update,      None]

        photostrip_screen.btns          = [None,                                       None,                         'ic_sysbar_back.png']
        photostrip_screen.btn_functions = [None,                                       None,                         lambda:self.goto_screen('chooser', 'right')]

        viewer_screen.btns              = ['ic_action_edit.png',                       None,                         'ic_sysbar_back.png']
        viewer_screen.btn_functions     = [lambda:self.goto_screen('painter', 'left'), viewer_screen.drawing_toggle, lambda:self.goto_screen('photostrip', 'right')]

        self.paint_screen.btns          = ['ic_action_save.png',                       None,                         'ic_action_discard.png']
        self.paint_screen.btn_functions = [self.save_painter,                          None,                         lambda:self.goto_screen('photostrip', 'right')]

        # Finally, add the screens to the manager
        self.screen_manager.add_widget(chooser_screen)
        self.screen_manager.add_widget(photostrip_screen)
        self.screen_manager.add_widget(viewer_screen)
        self.screen_manager.add_widget(self.paint_screen)

        # Set the navbar buttons from the variables set above
        self.screen_manager.transition.bind(on_complete=self.update_buttons)
        self.update_buttons()

        return root
开发者ID:mijofa,项目名称:photo-guestbook,代码行数:102,代码来源:main.py


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