Advertisement
soulseb

12345

Jun 11th, 2025 (edited)
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.43 KB | None | 0 0
  1. from kivy.config import Config
  2. Config.set('graphics', 'width', '360')
  3. Config.set('graphics', 'height', '640')
  4. Config.set('graphics', 'resizable', '0')
  5.  
  6. from kivy.app import App
  7. from kivy.lang import Builder
  8. from kivy.animation import Animation
  9. from kivy.core.window import Window
  10. from kivy.metrics import dp
  11. from kivy.uix.boxlayout import BoxLayout
  12. from kivy.uix.button import Button
  13. from kivy.uix.widget import Widget
  14. from kivy.uix.behaviors import ButtonBehavior
  15. from kivy.uix.label import Label
  16. from kivy.uix.modalview import ModalView
  17. from kivy.properties import StringProperty, NumericProperty
  18. from kivy.utils import platform
  19. from kivy.clock import Clock
  20.  
  21. Builder.load_string('''
  22. <ClickableOverlay>:
  23.    canvas:
  24.        Color:
  25.            rgba: 0, 0, 0, 0.3 if self.active else 0
  26.        Rectangle:
  27.            pos: self.pos
  28.            size: self.size
  29.  
  30. <ContentItem>:
  31.    orientation: 'horizontal'
  32.    size_hint_y: None
  33.    height: dp(50)
  34.    spacing: dp(5)
  35.    padding: dp(5)
  36.    canvas.before:
  37.        Color:
  38.            rgba: 0.4, 0.4, 0.6, 1
  39.        Rectangle:
  40.            pos: self.pos
  41.            size: self.size
  42.    
  43.    Label:
  44.        id: title_label
  45.        text: root.item_title
  46.        size_hint_x: 0.8
  47.        halign: 'left'
  48.        valign: 'middle'
  49.        text_size: self.width, None
  50.        color: 1, 1, 1, 1
  51.        font_size: dp(16)
  52.        bold: True
  53.    
  54.    Button:
  55.        id: info_button
  56.        text: 'i'
  57.        size_hint_x: 0.2
  58.        size_hint_y: 1
  59.        background_normal: ''
  60.        background_color: 0.8, 0.8, 0.2, 1
  61.        font_size: dp(14)
  62.        bold: True
  63.        on_press: root.show_info()
  64.  
  65. <InfoDialog>:
  66.    size_hint: (0.8, 0.5)
  67.    auto_dismiss: True
  68.    BoxLayout:
  69.        orientation: 'vertical'
  70.        padding: dp(20)
  71.        spacing: dp(10)
  72.        canvas.before:
  73.            Color:
  74.                rgba: 0.3, 0.3, 0.5, 1
  75.            Rectangle:
  76.                pos: self.pos
  77.                size: self.size
  78.        
  79.        Label:
  80.            text: root.title
  81.            font_size: dp(20)
  82.            bold: True
  83.            color: 1, 1, 1, 1
  84.            size_hint_y: 0.3
  85.        
  86.        Label:
  87.            text: root.description
  88.            font_size: dp(16)
  89.            color: 1, 1, 1, 1
  90.            text_size: self.width, None
  91.            valign: 'top'
  92.            halign: 'left'
  93.            size_hint_y: 0.7
  94.        
  95.        Button:
  96.            text: 'Close'
  97.            size_hint_y: 0.2
  98.            background_normal: ''
  99.            background_color: 0.8, 0.3, 0.3, 1
  100.            on_press: root.dismiss()
  101.  
  102. <SearchApplicationUI>:
  103.    orientation: 'vertical'
  104.    spacing: dp(5)
  105.    
  106.    # Notification panel (top)
  107.    BoxLayout:
  108.        id: notification_panel
  109.        size_hint_y: None
  110.        height: 0
  111.        opacity: 0
  112.        canvas.before:
  113.            Color:
  114.                rgba: 0.2, 0.8, 0.4, 0.9
  115.            Rectangle:
  116.                pos: self.pos
  117.                size: self.size
  118.        Label:
  119.            id: notification_label
  120.            text: ''
  121.            color: 1, 1, 1, 1
  122.            font_size: dp(18)
  123.            bold: True
  124.            halign: 'center'
  125.            padding: [dp(10), dp(5)]
  126.    
  127.    # Main content (takes all available space)
  128.    ScrollView:
  129.        id: content_scroll
  130.        size_hint_y: 1  # Critical - makes it expand
  131.        do_scroll_y: True
  132.        
  133.        BoxLayout:
  134.            id: items_container
  135.            orientation: 'vertical'
  136.            size_hint_y: None
  137.            height: self.minimum_height
  138.            spacing: dp(5)
  139.            padding: [dp(10), dp(0)]
  140.    
  141.    # Search panel (fixed at bottom)
  142.    BoxLayout:
  143.        id: search_controls
  144.        size_hint_y: None
  145.        height: dp(60)
  146.        padding: dp(10)
  147.        spacing: dp(5)
  148.        
  149.        TextInput:
  150.            id: search_field
  151.            hint_text: 'Enter search query...'
  152.            multiline: False
  153.            size_hint_x: 0.8
  154.            padding: [dp(10), (self.height - self.line_height)/2]
  155.            font_size: dp(16)
  156.            on_focus: root.on_search_focus_changed(*args)
  157.            on_text_validate: root.perform_search()
  158.        
  159.        Button:
  160.            id: action_btn
  161.            text: 'Add'
  162.            size_hint_x: 0.2
  163.            font_size: dp(13)
  164.            bold: True
  165.            background_normal: ''
  166.            background_color: (0.4, 0.6, 0.4, 1)
  167.            on_press: root.toggle_notification_panel()
  168.    
  169.    # Keyboard overlay (invisible when not needed)
  170.    ClickableOverlay:
  171.        id: keyboard_dismiss_area
  172.        size_hint_y: None
  173.        height: 0
  174.        on_press: root.hide_virtual_keyboard()
  175. ''')
  176.  
  177. class ClickableOverlay(ButtonBehavior, Widget):
  178.     active = False
  179.  
  180. class InfoDialog(ModalView):
  181.     title = StringProperty('')
  182.     description = StringProperty('')
  183.  
  184. class ContentItem(ButtonBehavior, BoxLayout):
  185.     item_title = StringProperty('')
  186.     item_description = StringProperty('')
  187.    
  188.     def __init__(self, item_title="", item_description="", **kwargs):
  189.         super().__init__(**kwargs)
  190.         self.item_title = item_title
  191.         self.item_description = item_description
  192.    
  193.     def on_press(self):
  194.         app = App.get_running_app()
  195.         app.root.ids.notification_label.text = f"Selected: {self.item_title}"
  196.         if app.root.ids.notification_panel.height == 0:
  197.             app.root.show_notification_panel()
  198.    
  199.     def show_info(self):
  200.         dialog = InfoDialog(title=self.item_title,
  201.                           description=self.item_description)
  202.         dialog.open()
  203.  
  204. class SearchApplicationUI(BoxLayout):
  205.     keyboard_height = NumericProperty(0)
  206.    
  207.     def __init__(self, **kwargs):
  208.         super().__init__(**kwargs)
  209.         Window.clearcolor = (0.4, 0.4, 0.4, 1)
  210.         Window.bind(on_keyboard=self.handle_keyboard_event)
  211.         self.initialize_content()
  212.    
  213.     def handle_keyboard_event(self, window, key, *args):
  214.         """Handle hardware back button press"""
  215.         if key == 27:  # ESC key
  216.             if self.ids.search_field.focus:
  217.                 self.hide_virtual_keyboard()
  218.                 return True
  219.             return False
  220.    
  221.     def initialize_content(self):
  222.         """Populate the content area with sample items"""
  223.         for i in range(1, 21):
  224.             item = ContentItem(
  225.                 item_title=f'Item {i}',
  226.                 item_description=f'Detailed description for item {i}. '
  227.                                f'This contains all relevant information about the item.'
  228.             )
  229.             self.ids.items_container.add_widget(item)
  230.    
  231.     def on_search_focus_changed(self, instance, has_focus):
  232.         """Handle search field focus changes"""
  233.         self.ids.keyboard_dismiss_area.height = self.keyboard_height if has_focus else 0
  234.    
  235.     def hide_virtual_keyboard(self):
  236.         """Dismiss the virtual keyboard"""
  237.         self.ids.search_field.focus = False
  238.    
  239.     def toggle_notification_panel(self):
  240.         """Toggle the notification panel visibility"""
  241.         if self.ids.notification_panel.height == 0:
  242.             query = self.ids.search_field.text.strip()
  243.             if query:
  244.                 self.ids.notification_label.text = f"Added: {query}"
  245.                 self.show_notification_panel()
  246.         else:
  247.             self.hide_notification_panel()
  248.    
  249.     def show_notification_panel(self):
  250.         """Animate notification panel appearance"""
  251.         Animation(height=dp(50), opacity=1, duration=0.3).start(self.ids.notification_panel)
  252.         self.ids.action_btn.text = "Remove"
  253.         self.ids.action_btn.background_color = (0.8, 0.3, 0.3, 1)
  254.    
  255.     def hide_notification_panel(self):
  256.         """Animate notification panel disappearance"""
  257.         Animation(height=0, opacity=0, duration=0.3).start(self.ids.notification_panel)
  258.         self.ids.action_btn.text = "Add"
  259.         self.ids.action_btn.background_color = (0.4, 0.6, 0.4, 1)
  260.    
  261.     def perform_search(self):
  262.         """Execute search operation"""
  263.         query = self.ids.search_field.text.strip()
  264.         if query:
  265.             self.ids.notification_label.text = f"Found: {query}"
  266.             if self.ids.notification_panel.height == 0:
  267.                 self.show_notification_panel()
  268.  
  269. class SearchApplication(App):
  270.     """Main application class"""
  271.    
  272.     def build(self):
  273.         return SearchApplicationUI()
  274.  
  275. if __name__ == '__main__':
  276.     SearchApplication().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement