|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +__all__ = ( |
| 4 | + "MDSearchView", |
| 5 | + "MDSearchBar", |
| 6 | + "MDSearchTrailingIcon", |
| 7 | + "MDSearchTrailingAvatar", |
| 8 | +) |
| 9 | + |
| 10 | +import os |
| 11 | + |
| 12 | +from kivy.lang import Builder |
| 13 | +from kivy.metrics import dp |
| 14 | +from kivy.properties import StringProperty, ListProperty |
| 15 | +from kivy.uix.behaviors import ButtonBehavior |
| 16 | +from kivy.uix.image import Image |
| 17 | +from kivy.uix.modalview import ModalView |
| 18 | + |
| 19 | +from kivymd import uix_path |
| 20 | +from kivymd.uix.behaviors import RectangularRippleBehavior |
| 21 | +from kivymd.uix.boxlayout import MDBoxLayout |
| 22 | +from kivymd.uix.button import MDIconButton |
| 23 | + |
| 24 | +with open( |
| 25 | + os.path.join(uix_path, "search", "search.kv"), encoding="utf-8" |
| 26 | +) as kv_file: |
| 27 | + Builder.load_string(kv_file.read()) |
| 28 | + |
| 29 | + |
| 30 | +class MDSearchTrailingAvatar(ButtonBehavior, Image): |
| 31 | + pass |
| 32 | + |
| 33 | + |
| 34 | +class MDSearchTrailingIcon(MDIconButton): |
| 35 | + pass |
| 36 | + |
| 37 | +class MDSearchView(ModalView): |
| 38 | + |
| 39 | + _header_height = dp(70) |
| 40 | + def __init__(self, search_bar, *args, **kwargs): |
| 41 | + super().__init__(*args, **kwargs) |
| 42 | + self.search_bar = search_bar |
| 43 | + |
| 44 | + def open_view(self): |
| 45 | + self.ids.root_container.width = self.search_bar.width |
| 46 | + self.ids.root_container.pos = [ |
| 47 | + self.search_bar.pos[0], |
| 48 | + self.search_bar.pos[1] - self.ids.root_container.height + self.search_bar.height |
| 49 | + ] |
| 50 | + # TODO: make it like animating from that view |
| 51 | + self.open() |
| 52 | + |
| 53 | + def close_view(self): |
| 54 | + self.dismiss() |
| 55 | + |
| 56 | + |
| 57 | +class MDSearchBar(ButtonBehavior, MDBoxLayout): |
| 58 | + |
| 59 | + leading_icon = StringProperty("magnify") |
| 60 | + supporting_text = StringProperty("Hinted search text") |
| 61 | + |
| 62 | + # internal |
| 63 | + _supporting_text_padding = ListProperty([0, 0, dp(30), 0]) |
| 64 | + _search_view = None |
| 65 | + def __init__(self, *args, **kwargs): |
| 66 | + super().__init__(*args, **kwargs) |
| 67 | + self.register_event_type("on_leading_icon_release") |
| 68 | + self.register_event_type("on_leading_icon_press") |
| 69 | + self._search_view = MDSearchView(self) |
| 70 | + |
| 71 | + def on_leading_icon_release(self): |
| 72 | + pass |
| 73 | + |
| 74 | + def on_leading_icon_press(self): |
| 75 | + pass |
| 76 | + |
| 77 | + def on_release(self): |
| 78 | + pass |
0 commit comments