forked from kivy-garden/garden.navigationdrawer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
703 lines (625 loc) · 28.1 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
# Copyright (c) 2013 Alexander Taylor
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
'''NavigationDrawer
================
The NavigationDrawer widget provides a hidden panel view designed to
duplicate the popular Android layout. The user views one main widget
but can slide from the left of the screen to view a second, previously
hidden widget. The transition between open/closed is smoothly
animated, with the parameters (anim time, panel width, touch
detection) all user configurable. If the panel is released without
being fully open or closed, it animates to an appropriate
configuration.
NavigationDrawer supports many different animation properties,
including moving one or both of the side/main panels, darkening
either/both widgets, changing side panel opacity, and changing which
widget is on top. The user can edit these individually to taste (this
is enough rope to hang oneself, it's easy to make a useless or silly
configuration!), or use one of a few preset animations.
The hidden panel might normally a set of navigation buttons, but the
implementation lets the user use any widget(s).
The first widget added to the NavigationDrawer is automatically used
as the side panel, and the second widget as the main panel. No further
widgets can be added, further changes are left to the user via editing
the panel widgets.
Usage summary
-------------
- The first widget added to a NavigationDrawer is used as the hidden
side panel.
- The second widget added is used as the main panel.
- Both widgets can be removed with remove_widget, or alternatively
set/removed with set_main_panel and set_side_panel.
- The hidden side panel can be revealed by dragging from the left of
the NavigationDrawer. The touch detection width is the
touch_accept_width property.
- Every animation property is user-editable, or default animations
can be chosen by setting anim_type.
See the example and docstrings for information on individual properties.
Example::
class ExampleApp(App):
def build(self):
navigationdrawer = NavigationDrawer()
side_panel = BoxLayout(orientation='vertical')
side_panel.add_widget(Label(text='Panel label'))
side_panel.add_widget(Button(text='A button'))
side_panel.add_widget(Button(text='Another button'))
navigationdrawer.add_widget(side_panel)
label_head = (
'[b]Example label filling main panel[/b]\n\n[color=ff0000](p'
'ull from left to right!)[/color]\n\nIn this example, the le'
'ft panel is a simple boxlayout menu, and this main panel is'
' a BoxLayout with a label and example image.\n\nSeveral pre'
'set layouts are available (see buttons below), but users ma'
'y edit every parameter for much more customisation.')
main_panel = BoxLayout(orientation='vertical')
label_bl = BoxLayout(orientation='horizontal')
label = Label(text=label_head, font_size='15sp',
markup=True, valign='top')
label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
label_bl.add_widget(label)
label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
main_panel.add_widget(label_bl)
main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
navigationdrawer.add_widget(main_panel)
label.bind(size=label.setter('text_size'))
def set_anim_type(name):
navigationdrawer.anim_type = name
modes_layout = BoxLayout(orientation='horizontal')
modes_layout.add_widget(Label(text='preset\nanims:'))
slide_an = Button(text='slide_\nabove_\nanim')
slide_an.bind(on_press=lambda j: set_anim_type('slide_above_anim'))
slide_sim = Button(text='slide_\nabove_\nsimple')
slide_sim.bind(on_press=lambda j: set_anim_type('slide_above_simple'))
fade_in_button = Button(text='fade_in')
fade_in_button.bind(on_press=lambda j: set_anim_type('fade_in'))
reveal_button = Button(text='reveal_\nbelow_\nanim')
reveal_button.bind(on_press=
lambda j: set_anim_type('reveal_below_anim'))
slide_button = Button(text='reveal_\nbelow_\nsimple')
slide_button.bind(on_press=
lambda j: set_anim_type('reveal_below_simple'))
modes_layout.add_widget(slide_an)
modes_layout.add_widget(slide_sim)
modes_layout.add_widget(fade_in_button)
modes_layout.add_widget(reveal_button)
modes_layout.add_widget(slide_button)
main_panel.add_widget(modes_layout)
button = Button(text='toggle NavigationDrawer state (animate)',
size_hint_y=0.2)
button.bind(on_press=lambda j: navigationdrawer.toggle_state())
button2 = Button(text='toggle NavigationDrawer state (jump)',
size_hint_y=0.2)
button2.bind(on_press=lambda j: navigationdrawer.toggle_state(False))
button3 = Button(text='toggle _main_above', size_hint_y=0.2)
button3.bind(on_press=navigationdrawer.toggle_main_above)
main_panel.add_widget(button)
main_panel.add_widget(button2)
main_panel.add_widget(button3)
return navigationdrawer
ExampleApp().run()
'''
__all__ = ('NavigationDrawer', )
from kivy.animation import Animation
from kivy.uix.widget import Widget
from kivy.uix.stencilview import StencilView
from kivy.metrics import dp
from kivy.clock import Clock
from kivy.properties import (ObjectProperty, NumericProperty, OptionProperty,
BooleanProperty, StringProperty)
from kivy.resources import resource_add_path
from kivy.lang import Builder
import os.path
resource_add_path(os.path.dirname(__file__))
Builder.load_string('''
<NavigationDrawer>:
size_hint: (1,1)
_side_panel: sidepanel
_main_panel: mainpanel
_join_image: joinimage
side_panel_width: min(dp(250), 0.5*self.width)
BoxLayout:
id: sidepanel
y: root.y
x: root.x - \
(1-root._anim_progress)* \
root.side_panel_init_offset*root.side_panel_width
height: root.side_panel_height if root.side_panel_height else root.height
width: root.side_panel_width
opacity: root.side_panel_opacity + \
(1-root.side_panel_opacity)*root._anim_progress
canvas:
Color:
rgba: (0,0,0,1)
Rectangle:
pos: self.pos
size: self.size
canvas.after:
Color:
rgba: (0,0,0,(1-root._anim_progress)*root.side_panel_darkness)
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
id: mainpanel
x: root.x + \
root._anim_progress * \
root.side_panel_width * \
root.main_panel_final_offset
y: root.y
size: root.size
canvas:
Color:
rgba: (0,0,0,1)
Rectangle:
pos: self.pos
size: self.size
canvas.after:
Color:
rgba: (0,0,0,root._anim_progress*root.main_panel_darkness)
Rectangle:
size: self.size
pos: self.pos
Image:
id: joinimage
opacity: min(sidepanel.opacity, 0 if root._anim_progress < 0.00001 \
else min(root._anim_progress*40,1))
source: root._choose_image(root._main_above, root.separator_image)
mipmap: False
width: root.separator_image_width
height: root._side_panel.height
x: (mainpanel.x - self.width + 1) if root._main_above \
else (sidepanel.x + sidepanel.width - 1)
y: root.y
allow_stretch: True
keep_ratio: False
''')
class NavigationDrawerException(Exception):
'''Raised when add_widget or remove_widget called incorrectly on a
NavigationDrawer.
'''
class NavigationDrawer(StencilView):
'''Widget taking two children, a side panel and a main panel,
displaying them in a way that replicates the popular Android
functionality. See module documentation for more info.
'''
# Internal references for side, main and image widgets
_side_panel = ObjectProperty()
_main_panel = ObjectProperty()
_join_image = ObjectProperty()
side_panel = ObjectProperty(None, allownone=True)
'''Automatically bound to whatever widget is added as the hidden panel.'''
main_panel = ObjectProperty(None, allownone=True)
'''Automatically bound to whatever widget is added as the main panel.'''
# Appearance properties
side_panel_width = NumericProperty()
'''The width of the hidden side panel. Defaults to the minimum of
250dp or half the NavigationDrawer width.'''
side_panel_height = NumericProperty(0)
'''The height of the hidden side panel. Defaults to the
NavigationDrawer height, unless explicitly set by the user.'''
separator_image = StringProperty('')
'''The path to an image that will be placed between the side and main
panels. If set to `''`, defaults to a gradient from black to
transparent in an appropriate direction (left->right if side panel
above main, right->left if main panel on top).'''
separator_image_width = NumericProperty(dp(10))
'''The width of the separator image. Defaults to 10dp'''
# Touch properties
touch_accept_width = NumericProperty('14dp')
'''Distance from the left of the NavigationDrawer in which to grab the
touch and allow revealing of the hidden panel.'''
_touch = ObjectProperty(None, allownone=True) # The currently active touch
# Animation properties
state = OptionProperty('closed', options=('open', 'closed'))
'''Specifies the state of the widget. Must be one of 'open' or
'closed'. Setting its value automatically jumps to the relevant state,
or users may use the anim_to_state() method to animate the
transition.'''
anim_time = NumericProperty(0.3)
'''The time taken for the panel to slide to the open/closed state when
released or manually animated with anim_to_state.'''
min_dist_to_open = NumericProperty(0.7)
'''Must be between 0 and 1. Specifies the fraction of the hidden panel
width beyond which the NavigationDrawer will relax to open state when
released. Defaults to 0.7.'''
_anim_progress = NumericProperty(0) # Internal state controlling
# widget positions
_anim_init_progress = NumericProperty(0)
# Animation controls
top_panel = OptionProperty('main', options=['main', 'side'])
'''Denotes which panel should be drawn on top of the other. Must be
one of 'main' or 'side'. Defaults to 'main'.'''
_main_above = BooleanProperty(True)
side_panel_init_offset = NumericProperty(0.5)
'''Intial offset (to the left of the widget) of the side panel, in
units of its total width. Opening the panel moves it smoothly to its
final position at the left of the screen.'''
side_panel_darkness = NumericProperty(0.8)
'''Controls the fade-to-black of the side panel in its hidden
state. Must be between 0 (no fading) and 1 (fades to totally
black).'''
side_panel_opacity = NumericProperty(1)
'''Controls the opacity of the side panel in its hidden state. Must be
between 0 (fade to transparent) and 1 (no transparency)'''
main_panel_final_offset = NumericProperty(1)
'''Final offset (to the right of the normal position) of the main
panel, in units of the side panel width.'''
main_panel_darkness = NumericProperty(0)
'''Controls the fade-to-black of the main panel when the side panel is
in its hidden state. Must be between 0 (no fading) and 1 (fades to
totally black).
'''
opening_transition = StringProperty('out_cubic')
'''The name of the animation transition type to use when animating to
an open state. Defaults to 'out_cubic'.'''
closing_transition = StringProperty('in_cubic')
'''The name of the animation transition type to use when animating to
a closed state. Defaults to 'out_cubic'.'''
anim_type = OptionProperty('reveal_from_below',
options=['slide_above_anim',
'slide_above_simple',
'fade_in',
'reveal_below_anim',
'reveal_below_simple',
])
'''The default animation type to use. Several options are available,
modifying all possibly animation properties including darkness,
opacity, movement and draw height. Users may also (and are
encouaged to) edit these properties individually, for a vastly
larger range of possible animations. Defaults to reveal_below_anim.
'''
def __init__(self, **kwargs):
super(NavigationDrawer, self).__init__(**kwargs)
Clock.schedule_once(self.on__main_above, 0)
def on_anim_type(self, *args):
anim_type = self.anim_type
if anim_type == 'slide_above_anim':
self.top_panel = 'side'
self.side_panel_darkness = 0
self.side_panel_opacity = 1
self.main_panel_final_offset = 0.5
self.main_panel_darkness = 0.5
self.side_panel_init_offset = 1
if anim_type == 'slide_above_simple':
self.top_panel = 'side'
self.side_panel_darkness = 0
self.side_panel_opacity = 1
self.main_panel_final_offset = 0
self.main_panel_darkness = 0
self.side_panel_init_offset = 1
elif anim_type == 'fade_in':
self.top_panel = 'side'
self.side_panel_darkness = 0
self.side_panel_opacity = 0
self.main_panel_final_offset = 0
self.main_panel_darkness = 0
self.side_panel_init_offset = 0.5
elif anim_type == 'reveal_below_anim':
self.top_panel = 'main'
self.side_panel_darkness = 0.8
self.side_panel_opacity = 1
self.main_panel_final_offset = 1
self.main_panel_darkness = 0
self.side_panel_init_offset = 0.5
elif anim_type == 'reveal_below_simple':
self.top_panel = 'main'
self.side_panel_darkness = 0
self.side_panel_opacity = 1
self.main_panel_final_offset = 1
self.main_panel_darkness = 0
self.side_panel_init_offset = 0
def on_top_panel(self, *args):
if self.top_panel == 'main':
self._main_above = True
else:
self._main_above = False
def on__main_above(self, *args):
newval = self._main_above
main_panel = self._main_panel
side_panel = self._side_panel
self.canvas.remove(main_panel.canvas)
self.canvas.remove(side_panel.canvas)
if newval:
self.canvas.insert(0, main_panel.canvas)
self.canvas.insert(0, side_panel.canvas)
else:
self.canvas.insert(0, side_panel.canvas)
self.canvas.insert(0, main_panel.canvas)
def toggle_main_above(self, *args):
if self._main_above:
self._main_above = False
else:
self._main_above = True
def add_widget(self, widget):
if len(self.children) == 0:
super(NavigationDrawer, self).add_widget(widget)
self._side_panel = widget
elif len(self.children) == 1:
super(NavigationDrawer, self).add_widget(widget)
self._main_panel = widget
elif len(self.children) == 2:
super(NavigationDrawer, self).add_widget(widget)
self._join_image = widget
elif self.side_panel is None:
self._side_panel.add_widget(widget)
self.side_panel = widget
elif self.main_panel is None:
self._main_panel.add_widget(widget)
self.main_panel = widget
else:
raise NavigationDrawerException(
'Can\'t add more than two widgets'
'directly to NavigationDrawer')
def remove_widget(self, widget):
if widget is self.side_panel:
self._side_panel.remove_widget(widget)
self.side_panel = None
elif widget is self.main_panel:
self._main_panel.remove_widget(widget)
self.main_panel = None
else:
raise NavigationDrawerException(
'Widget is neither the side or main panel, can\'t remove it.')
def set_side_panel(self, widget):
'''Removes any existing side panel widgets, and replaces them with the
argument `widget`.
'''
# Clear existing side panel entries
if len(self._side_panel.children) > 0:
for child in self._side_panel.children:
self._side_panel.remove(child)
# Set new side panel
self._side_panel.add_widget(widget)
self.side_panel = widget
def set_main_panel(self, widget):
'''Removes any existing main panel widgets, and replaces them with the
argument `widget`.
'''
# Clear existing side panel entries
if len(self._main_panel.children) > 0:
for child in self._main_panel.children:
self._main_panel.remove(child)
# Set new side panel
self._main_panel.add_widget(widget)
self.main_panel = widget
def on__anim_progress(self, *args):
if self._anim_progress > 1:
self._anim_progress = 1
elif self._anim_progress < 0:
self._anim_progress = 0
if self._anim_progress >= 1:
self.state = 'open'
elif self._anim_progress <= 0:
self.state = 'closed'
def on_state(self, *args):
Animation.cancel_all(self)
if self.state == 'open':
self._anim_progress = 1
else:
self._anim_progress = 0
def anim_to_state(self, state):
'''If not already in state `state`, animates smoothly to it, taking
the time given by self.anim_time. State may be either 'open'
or 'closed'.
'''
if state == 'open':
anim = Animation(_anim_progress=1,
duration=self.anim_time,
t=self.closing_transition)
anim.start(self)
elif state == 'closed':
anim = Animation(_anim_progress=0,
duration=self.anim_time,
t=self.opening_transition)
anim.start(self)
else:
raise NavigationDrawerException(
'Invalid state received, should be one of `open` or `closed`')
def toggle_state(self, animate=True):
'''Toggles from open to closed or vice versa, optionally animating or
simply jumping.'''
if self.state == 'open':
if animate:
self.anim_to_state('closed')
else:
self.state = 'closed'
elif self.state == 'closed':
if animate:
self.anim_to_state('open')
else:
self.state = 'open'
def on_touch_down(self, touch):
col_self = self.collide_point(*touch.pos)
col_side = self._side_panel.collide_point(*touch.pos)
col_main = self._main_panel.collide_point(*touch.pos)
if self._anim_progress < 0.001: # i.e. closed
valid_region = (self.x <=
touch.x <=
(self.x + self.touch_accept_width))
if not valid_region:
self._main_panel.on_touch_down(touch)
return False
else:
if col_side and not self._main_above:
self._side_panel.on_touch_down(touch)
return False
valid_region = (self._main_panel.x <=
touch.x <=
(self._main_panel.x + self._main_panel.width))
if not valid_region:
if self._main_above:
if col_main:
self._main_panel.on_touch_down(touch)
elif col_side:
self._side_panel.on_touch_down(touch)
else:
if col_side:
self._side_panel.on_touch_down(touch)
elif col_main:
self._main_panel.on_touch_down(touch)
return False
Animation.cancel_all(self)
self._anim_init_progress = self._anim_progress
self._touch = touch
touch.ud['type'] = self.state
touch.ud['panels_jiggled'] = False # If user moved panels back
# and forth, don't default
# to close on touch release
touch.grab(self)
return True
def on_touch_move(self, touch):
if touch is self._touch:
dx = touch.x - touch.ox
self._anim_progress = max(0, min(self._anim_init_progress +
(dx / self.side_panel_width), 1))
if self._anim_progress < 0.975:
touch.ud['panels_jiggled'] = True
else:
super(NavigationDrawer, self).on_touch_move(touch)
return
def on_touch_up(self, touch):
if touch is self._touch:
self._touch = None
init_state = touch.ud['type']
touch.ungrab(self)
jiggled = touch.ud['panels_jiggled']
if init_state == 'open' and not jiggled:
if self._anim_progress >= 0.975:
self.anim_to_state('closed')
else:
self._anim_relax()
else:
self._anim_relax()
else:
super(NavigationDrawer, self).on_touch_up(touch)
return
def _anim_relax(self):
'''Animates to the open or closed position, depending on whether the
current position is past self.min_dist_to_open.
'''
if self._anim_progress > self.min_dist_to_open:
self.anim_to_state('open')
else:
self.anim_to_state('closed')
def _choose_image(self, *args):
'''Chooses which image to display as the main/side separator, based on
_main_above.'''
if self.separator_image:
return self.separator_image
if self._main_above:
return 'navigationdrawer_gradient_rtol.png'
else:
return 'navigationdrawer_gradient_ltor.png'
if __name__ == '__main__':
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.image import Image
from kivy.core.window import Window
navigationdrawer = NavigationDrawer()
side_panel = BoxLayout(orientation='vertical')
side_panel.add_widget(Label(text='Panel label'))
popup = Popup(title='Sidebar popup',
content=Label(
text='You clicked the sidebar\npopup button'),
size_hint=(0.7, 0.7))
first_button = Button(text='Popup\nbutton')
first_button.bind(on_release=popup.open)
side_panel.add_widget(first_button)
side_panel.add_widget(Button(text='Another\nbutton'))
navigationdrawer.add_widget(side_panel)
navigationdrawer.side_panel_height = 400 # let the user choose the height of the side panel
# If he doesn't choose, it defaults to the full height
label_head = (
'[b]Example label filling main panel[/b]\n\n[color=ff0000](p'
'ull from left to right!)[/color]\n\nIn this example, the le'
'ft panel is a simple boxlayout menu, and this main panel is'
' a BoxLayout with a label and example image.\n\nSeveral pre'
'set layouts are available (see buttons below), but users ma'
'y edit every parameter for much more customisation.')
main_panel = BoxLayout(orientation='vertical')
label_bl = BoxLayout(orientation='horizontal')
label = Label(text=label_head, font_size='15sp',
markup=True, valign='top')
label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
label_bl.add_widget(label)
label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
main_panel.add_widget(label_bl)
main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
navigationdrawer.add_widget(main_panel)
label.bind(size=label.setter('text_size'))
def set_anim_type(name):
navigationdrawer.anim_type = name
def set_transition(name):
navigationdrawer.opening_transition = name
navigationdrawer.closing_transition = name
modes_layout = BoxLayout(orientation='horizontal')
modes_layout.add_widget(Label(text='preset\nanims:'))
slide_an = Button(text='slide_\nabove_\nanim')
slide_an.bind(on_press=lambda j: set_anim_type('slide_above_anim'))
slide_sim = Button(text='slide_\nabove_\nsimple')
slide_sim.bind(on_press=lambda j: set_anim_type('slide_above_simple'))
fade_in_button = Button(text='fade_in')
fade_in_button.bind(on_press=lambda j: set_anim_type('fade_in'))
reveal_button = Button(text='reveal_\nbelow_\nanim')
reveal_button.bind(on_press=
lambda j: set_anim_type('reveal_below_anim'))
slide_button = Button(text='reveal_\nbelow_\nsimple')
slide_button.bind(on_press=
lambda j: set_anim_type('reveal_below_simple'))
modes_layout.add_widget(slide_an)
modes_layout.add_widget(slide_sim)
modes_layout.add_widget(fade_in_button)
modes_layout.add_widget(reveal_button)
modes_layout.add_widget(slide_button)
main_panel.add_widget(modes_layout)
transitions_layout = BoxLayout(orientation='horizontal')
transitions_layout.add_widget(Label(text='anim\ntransitions'))
out_cubic = Button(text='out_cubic')
out_cubic.bind(on_press=
lambda j: set_transition('out_cubic'))
in_quint = Button(text='in_quint')
in_quint.bind(on_press=
lambda j: set_transition('in_quint'))
linear = Button(text='linear')
linear.bind(on_press=
lambda j: set_transition('linear'))
out_sine = Button(text='out_sine')
out_sine.bind(on_press=
lambda j: set_transition('out_sine'))
transitions_layout.add_widget(out_cubic)
transitions_layout.add_widget(in_quint)
transitions_layout.add_widget(linear)
transitions_layout.add_widget(out_sine)
main_panel.add_widget(transitions_layout)
button = Button(text='toggle NavigationDrawer state (animate)',
size_hint_y=0.2)
button.bind(on_press=lambda j: navigationdrawer.toggle_state())
button2 = Button(text='toggle NavigationDrawer state (jump)',
size_hint_y=0.2)
button2.bind(on_press=lambda j: navigationdrawer.toggle_state(False))
button3 = Button(text='toggle _main_above', size_hint_y=0.2)
button3.bind(on_press=navigationdrawer.toggle_main_above)
main_panel.add_widget(button)
main_panel.add_widget(button2)
main_panel.add_widget(button3)
Window.add_widget(navigationdrawer)
runTouchApp()