<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> from kivy . compat import string_types <EOL> from kivy . factory import Factory <EOL> from kivy . uix . button import Button <EOL> from kivy . properties import ( OptionProperty , NumericProperty , ObjectProperty , <EOL> ListProperty , BooleanProperty ) <EOL> from kivy . uix . boxlayout import BoxLayout <EOL> class SplitterStrip ( Button ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> class Splitter ( BoxLayout ) : <EOL> '''<STR_LIT>''' <EOL> border = ListProperty ( [ <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> ] ) <EOL> '''<STR_LIT>''' <EOL> strip_cls = ObjectProperty ( SplitterStrip ) <EOL> '''<STR_LIT>''' <EOL> sizable_from = OptionProperty ( '<STR_LIT:left>' , options = ( <EOL> '<STR_LIT:left>' , '<STR_LIT:right>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> '''<STR_LIT>''' <EOL> strip_size = NumericProperty ( '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> min_size = NumericProperty ( '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> max_size = NumericProperty ( '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> _parent_proportion = NumericProperty ( <NUM_LIT:0.> ) <EOL> '''<STR_LIT>''' <EOL> _bound_parent = ObjectProperty ( None , allownone = True ) <EOL> '''<STR_LIT>''' <EOL> keep_within_parent = BooleanProperty ( False ) <EOL> '''<STR_LIT>''' <EOL> rescale_with_parent = BooleanProperty ( False ) <EOL> '''<STR_LIT>''' <EOL> __events__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . _container = None <EOL> self . _strip = None <EOL> super ( Splitter , self ) . __init__ ( ** kwargs ) <EOL> do_size = self . _do_size <EOL> fbind = self . fbind <EOL> fbind ( '<STR_LIT>' , do_size ) <EOL> fbind ( '<STR_LIT>' , do_size ) <EOL> fbind ( '<STR_LIT>' , self . _rebind_parent ) <EOL> def on_sizable_from ( self , instance , sizable_from ) : <EOL> if not instance . _container : <EOL> return <EOL> sup = super ( Splitter , instance ) <EOL> _strp = instance . _strip <EOL> if _strp : <EOL> _strp . unbind ( on_touch_down = instance . strip_down ) <EOL> _strp . unbind ( on_touch_move = instance . strip_move ) <EOL> _strp . unbind ( on_touch_up = instance . strip_up ) <EOL> self . unbind ( disabled = _strp . setter ( '<STR_LIT>' ) ) <EOL> sup . remove_widget ( instance . _strip ) <EOL> else : <EOL> cls = instance . strip_cls <EOL> if isinstance ( cls , string_types ) : <EOL> cls = Factory . get ( cls ) <EOL> instance . _strip = _strp = cls ( ) <EOL> sz_frm = instance . sizable_from [ <NUM_LIT:0> ] <EOL> if sz_frm in ( '<STR_LIT:l>' , '<STR_LIT:r>' ) : <EOL> _strp . size_hint = None , <NUM_LIT:1> <EOL> _strp . width = instance . strip_size <EOL> instance . orientation = '<STR_LIT>' <EOL> instance . unbind ( strip_size = _strp . setter ( '<STR_LIT:width>' ) ) <EOL> instance . bind ( strip_size = _strp . setter ( '<STR_LIT:width>' ) ) <EOL> else : <EOL> _strp . size_hint = <NUM_LIT:1> , None <EOL> _strp . height = instance . strip_size <EOL> instance . orientation = '<STR_LIT>' <EOL> instance . unbind ( strip_size = _strp . setter ( '<STR_LIT>' ) ) <EOL> instance . bind ( strip_size = _strp . setter ( '<STR_LIT>' ) ) <EOL> index = <NUM_LIT:1> <EOL> if sz_frm in ( '<STR_LIT:r>' , '<STR_LIT:b>' ) : <EOL> index = <NUM_LIT:0> <EOL> sup . add_widget ( _strp , index ) <EOL> _strp . bind ( on_touch_down = instance . strip_down ) <EOL> _strp . bind ( on_touch_move = instance . strip_move ) <EOL> _strp . bind ( on_touch_up = instance . strip_up ) <EOL> _strp . disabled = self . disabled <EOL> self . bind ( disabled = _strp . setter ( '<STR_LIT>' ) ) <EOL> def add_widget ( self , widget , index = <NUM_LIT:0> ) : <EOL> if self . _container or not widget : <EOL> return Exception ( '<STR_LIT>' ) <EOL> self . _container = widget <EOL> sz_frm = self . sizable_from [ <NUM_LIT:0> ] <EOL> if sz_frm in ( '<STR_LIT:l>' , '<STR_LIT:r>' ) : <EOL> widget . size_hint_x = <NUM_LIT:1> <EOL> else : <EOL> widget . size_hint_y = <NUM_LIT:1> <EOL> index = <NUM_LIT:0> <EOL> if sz_frm in ( '<STR_LIT:r>' , '<STR_LIT:b>' ) : <EOL> index = <NUM_LIT:1> <EOL> super ( Splitter , self ) . add_widget ( widget , index ) <EOL> self . on_sizable_from ( self , self . sizable_from ) <EOL> def remove_widget ( self , widget , * largs ) : <EOL> super ( Splitter , self ) . remove_widget ( widget ) <EOL> if widget == self . _container : <EOL> self . _container = None <EOL> def clear_widgets ( self ) : <EOL> self . remove_widget ( self . _container ) <EOL> def strip_down ( self , instance , touch ) : <EOL> if not instance . collide_point ( * touch . pos ) : <EOL> return False <EOL> touch . grab ( self ) <EOL> self . dispatch ( '<STR_LIT>' ) <EOL> def on_press ( self ) : <EOL> pass <EOL> def _rebind_parent ( self , instance , new_parent ) : <EOL> if self . _bound_parent is not None : <EOL> self . _bound_parent . unbind ( size = self . rescale_parent_proportion ) <EOL> if self . parent is not None : <EOL> new_parent . bind ( size = self . rescale_parent_proportion ) <EOL> self . _bound_parent = new_parent <EOL> self . rescale_parent_proportion ( ) <EOL> def rescale_parent_proportion ( self , * args ) : <EOL> if not self . parent : <EOL> return <EOL> if self . rescale_with_parent : <EOL> parent_proportion = self . _parent_proportion <EOL> if self . sizable_from in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> new_height = parent_proportion * self . parent . height <EOL> self . height = max ( self . min_size , min ( new_height , self . max_size ) ) <EOL> else : <EOL> new_width = parent_proportion * self . parent . width <EOL> self . width = max ( self . min_size , min ( new_width , self . max_size ) ) <EOL> def _do_size ( self , instance , value ) : <EOL> if self . sizable_from [ <NUM_LIT:0> ] in ( '<STR_LIT:l>' , '<STR_LIT:r>' ) : <EOL> self . width = max ( self . min_size , min ( self . width , self . max_size ) ) <EOL> else : <EOL> self . height = max ( self . min_size , min ( self . height , self . max_size ) ) <EOL> def strip_move ( self , instance , touch ) : <EOL> if touch . grab_current is not instance : <EOL> return False <EOL> max_size = self . max_size <EOL> min_size = self . min_size <EOL> sz_frm = self . sizable_from [ <NUM_LIT:0> ] <EOL> if sz_frm in ( '<STR_LIT:t>' , '<STR_LIT:b>' ) : <EOL> diff_y = ( touch . dy ) <EOL> if self . keep_within_parent : <EOL> if sz_frm == '<STR_LIT:t>' and ( self . top + diff_y ) > self . parent . top : <EOL> diff_y = self . parent . top - self . top <EOL> elif sz_frm == '<STR_LIT:b>' and ( self . y + diff_y ) < self . parent . y : <EOL> diff_y = self . parent . y - self . y <EOL> if sz_frm == '<STR_LIT:b>' : <EOL> diff_y *= - <NUM_LIT:1> <EOL> if self . size_hint_y : <EOL> self . size_hint_y = None <EOL> if self . height > <NUM_LIT:0> : <EOL> self . height += diff_y <EOL> else : <EOL> self . height = <NUM_LIT:1> <EOL> height = self . height <EOL> self . height = max ( min_size , min ( height , max_size ) ) <EOL> self . _parent_proportion = self . height / self . parent . height <EOL> else : <EOL> diff_x = ( touch . dx ) <EOL> if self . keep_within_parent : <EOL> if sz_frm == '<STR_LIT:l>' and ( self . x + diff_x ) < self . parent . x : <EOL> diff_x = self . parent . x - self . x <EOL> elif ( sz_frm == '<STR_LIT:r>' and <EOL> ( self . right + diff_x ) > self . parent . right ) : <EOL> diff_x = self . parent . right - self . right <EOL> if sz_frm == '<STR_LIT:l>' : <EOL> diff_x *= - <NUM_LIT:1> <EOL> if self . size_hint_x : <EOL> self . size_hint_x = None <EOL> if self . width > <NUM_LIT:0> : <EOL> self . width += diff_x <EOL> else : <EOL> self . width = <NUM_LIT:1> <EOL> width = self . width <EOL> self . width = max ( min_size , min ( width , max_size ) ) <EOL> self . _parent_proportion = self . width / self . parent . width <EOL> def strip_up ( self , instance , touch ) : <EOL> if touch . grab_current is not instance : <EOL> return <EOL> if touch . is_double_tap : <EOL> max_size = self . max_size <EOL> min_size = self . min_size <EOL> sz_frm = self . sizable_from [ <NUM_LIT:0> ] <EOL> s = self . size <EOL> if sz_frm in ( '<STR_LIT:t>' , '<STR_LIT:b>' ) : <EOL> if self . size_hint_y : <EOL> self . size_hint_y = None <EOL> if s [ <NUM_LIT:1> ] - min_size <= max_size - s [ <NUM_LIT:1> ] : <EOL> self . height = max_size <EOL> else : <EOL> self . height = min_size <EOL> else : <EOL> if self . size_hint_x : <EOL> self . size_hint_x = None <EOL> if s [ <NUM_LIT:0> ] - min_size <= max_size - s [ <NUM_LIT:0> ] : <EOL> self . width = max_size <EOL> else : <EOL> self . width = min_size <EOL> touch . ungrab ( instance ) <EOL> self . dispatch ( '<STR_LIT>' ) <EOL> def on_release ( self ) : <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from kivy . app import App <EOL> from kivy . uix . button import Button <EOL> from kivy . uix . floatlayout import FloatLayout <EOL> class SplitterApp ( App ) : <EOL> def build ( self ) : <EOL> root = FloatLayout ( ) <EOL> bx = BoxLayout ( ) <EOL> bx . add_widget ( Button ( ) ) <EOL> bx . add_widget ( Button ( ) ) <EOL> bx2 = BoxLayout ( ) <EOL> bx2 . add_widget ( Button ( ) ) <EOL> bx2 . add_widget ( Button ( ) ) <EOL> bx2 . add_widget ( Button ( ) ) <EOL> spl = Splitter ( <EOL> size_hint = ( <NUM_LIT:1> , <NUM_LIT> ) , <EOL> pos_hint = { '<STR_LIT>' : <NUM_LIT:1> } , <EOL> sizable_from = '<STR_LIT>' ) <EOL> spl1 = Splitter ( <EOL> sizable_from = '<STR_LIT:left>' , <EOL> size_hint = ( None , <NUM_LIT:1> ) , width = <NUM_LIT> ) <EOL> spl1 . add_widget ( Button ( ) ) <EOL> bx . add_widget ( spl1 ) <EOL> spl . add_widget ( bx ) <EOL> spl2 = Splitter ( size_hint = ( <NUM_LIT> , <NUM_LIT:1> ) ) <EOL> spl2 . add_widget ( bx2 ) <EOL> spl2 . sizable_from = '<STR_LIT:right>' <EOL> root . add_widget ( spl ) <EOL> root . add_widget ( spl2 ) <EOL> return root <EOL> SplitterApp ( ) . run ( ) </s>
