def build(self): # Create a box layout boxLayout = BoxLayout() # Anchor Layout1 anchorLayout1 = AnchorLayout(anchor_x='left', anchor_y='bottom') button1 = Button(text='Bottom-Left', size_hint=(0.6, 0.3)) anchorLayout1.add_widget(button1) # Anchor Layout2 anchorLayout2 = AnchorLayout() anchorLayout2.anchor_x = 'right' anchorLayout2.anchor_y = 'top' # Anchor Layout3 anchorLayout3 = AnchorLayout() anchorLayout3.anchor_x = 'left' anchorLayout3.anchor_y = 'top' # Add the anchor layouts to a box layout button2 = Button(text='Top-Right', size_hint=(0.6, 0.3)) anchorLayout2.add_widget(button2) # Add the anchor layouts to a box layout button3 = Button(text='Top-Left', size_hint=(0.6, 0.3)) anchorLayout3.add_widget(button3) # Add both the anchor layouts to the box layout boxLayout.add_widget(anchorLayout1) boxLayout.add_widget(anchorLayout2) boxLayout.add_widget(anchorLayout3) # Return the boxlayout widget return boxLayout
def build(self): layout = AnchorLayout(anchor_x='right', anchor_y='center') btn1 = Button(text="Button 1") btn2 = Button(text="Button 2") btn3 = Button(text="Button 3") btn4 = Button(text="Button 4") btn5 = Button(text="Button 5") layout.add_widget(btn1) layout.anchor_x = 'center' layout.anchor_y = 'center' layout.add_widget(btn2) layout.anchor_x = 'left' layout.anchor_y = 'center' layout.add_widget(btn3) layout.anchor_x = 'right' layout.anchor_y = 'bottom' layout.add_widget(btn4) layout.anchor_x = 'center' layout.anchor_y = 'bottom' layout.add_widget(btn5) return layout
def setLayout(self): self.size = (1500, 1000) with self.canvas: Color(.532345, 1.0, .742, 1.0) Rectangle(size=self.size) sound_board_layout = AnchorLayout() sound_board_layout.anchor_x = "center" sound_board_layout.anchor_y = "top" sound_board_layout.size = self.size sound_board_layout.pos = self.pos sound_board_layout.size_hint = (1.0, 1.0) sound_board_layout.spacing = 50 self.title_layout.orientation = "vertical" self.title_layout.size_hint = (1.0, 1.0) self.title_layout.spacing = 10 title_label = Label() title_label.text = "Soundboard" title_label.color = [.6, .2, 1, .5] title_label.font_size = 50 title_label.font_name = "C:\\Windows\\Fonts\\Arial" title_label.size_hint = (1, 1) self.title_layout.add_widget(title_label) self.set_settings_layout() self.set_sounds() self.title_layout.add_widget(self.grid_layout) sound_board_layout.add_widget(self.title_layout) self.add_widget(sound_board_layout)
def __init__(self, app, **kwargs): super().__init__(**kwargs) self.app = app self.orientation = "horizontal" self.padding = (5, 0) self.adaptive_height = True self.label = MDLabel() self.label.halign = "center" self.add_widget(self.label) self.check1 = Check(self.update_value1) self.add_widget(self.check1) self.check2 = Check(self.update_value2) self.check2.size = ("36dp", "36dp") checkAnchor = AnchorLayout() checkAnchor.add_widget(self.check2) checkAnchor.anchor_x = "center" self.add_widget(checkAnchor) checkAnchor.size_hint_x = 0.2 self.check3 = Check(self.update_value3) self.add_widget(self.check3) self.bind(text=self.update_text)
def build(self): # Anchor Layout1 anchorLayout1 = AnchorLayout(anchor_x='left', anchor_y='bottom') button1 = Button(text='test', size_hint=(0.3, 0.3)) def callback(instance): print('The button <%s> is being pressed' % instance.text) publish.single("test", hostname="192.168.1.11") button1.bind(on_press=callback) anchorLayout1.add_widget(button1) # Anchor Layout2 anchorLayout2 = AnchorLayout() anchorLayout2.anchor_x = 'right' anchorLayout2.anchor_y = 'top' # Add the anchor layouts to a box layout vid = Video(source="http://192.168.1.11:8081/", play=True) anchorLayout2.add_widget(vid) # Create a box layout boxLayout = BoxLayout() # Add both the anchor layouts to the box layout boxLayout.add_widget(anchorLayout1) boxLayout.add_widget(anchorLayout2) # Return the boxlayout widget return boxLayout
def set_content(self, instance_content_dialog): def _events_callback(result_press): self.dismiss() if result_press: self.events_callback(result_press, self) if self.device_ios: # create buttons for iOS self.background = self._background if instance_content_dialog.__class__ is ContentInputDialog: self.text_field = MDTextFieldRect( pos_hint={'center_x': .5}, size_hint=(1, None), multiline=False, height=dp(33), cursor_color=self.theme_cls.primary_color, hint_text=instance_content_dialog.hint_text) instance_content_dialog.ids.box_input.height = dp(33) instance_content_dialog.ids.box_input.add_widget( self.text_field) if self.text_button_cancel != '': anchor = 'left' else: anchor = 'center' box_button_ok = AnchorLayout(anchor_x=anchor) box_button_ok.add_widget( MDTextButton(text=self.text_button_ok, font_size='18sp', on_release=lambda x: _events_callback( self.text_button_ok))) instance_content_dialog.ids.box_buttons.add_widget(box_button_ok) if self.text_button_cancel != '': box_button_ok.anchor_x = 'left' box_button_cancel = AnchorLayout(anchor_x='right') box_button_cancel.add_widget( MDTextButton(text=self.text_button_cancel, font_size='18sp', on_release=lambda x: _events_callback( self.text_button_cancel))) instance_content_dialog.ids.box_buttons.add_widget( box_button_cancel) else: # create buttons for Android if instance_content_dialog.__class__ is ContentInputDialog: self.text_field = MDTextField( size_hint=(1, None), height=dp(48), hint_text=instance_content_dialog.hint_text) instance_content_dialog.ids.box_input.height = dp(48) instance_content_dialog.ids.box_input.add_widget( self.text_field) instance_content_dialog.ids.box_buttons.remove_widget( instance_content_dialog.ids.sep) box_buttons = AnchorLayout(anchor_x='right', size_hint_y=None, height=dp(30)) box = BoxLayout(size_hint_x=None, spacing=dp(5)) box.bind(minimum_width=box.setter('width')) button_ok = MDRaisedButton( text=self.text_button_ok, on_release=lambda x: _events_callback(self.text_button_ok)) box.add_widget(button_ok) if self.text_button_cancel != '': button_cancel = MDFlatButton( text=self.text_button_cancel, theme_text_color='Custom', text_color=self.theme_cls.primary_color, on_release=lambda x: _events_callback(self. text_button_cancel)) box.add_widget(button_cancel) box_buttons.add_widget(box) instance_content_dialog.ids.box_buttons.add_widget(box_buttons) instance_content_dialog.ids.box_buttons.height = button_ok.height instance_content_dialog.remove_widget( instance_content_dialog.ids.sep)
def set_content(self, instance_content_dialog): def _events_callback(result_press): self.dismiss() if result_press and self.events_callback: self.events_callback(result_press, self) if self.device_ios: # create buttons for iOS self.background = self._background if isinstance(instance_content_dialog, ContentInputDialog): self.text_field = MDTextFieldRect( pos_hint={"center_x": 0.5}, size_hint=(1, None), multiline=False, height=dp(33), cursor_color=self.theme_cls.primary_color, hint_text=instance_content_dialog.hint_text, ) instance_content_dialog.ids.box_input.height = dp(33) instance_content_dialog.ids.box_input.add_widget( self.text_field ) if self.text_button_cancel != "": anchor = "left" else: anchor = "center" box_button_ok = AnchorLayout(anchor_x=anchor) box_button_ok.add_widget( MDTextButton( text=self.text_button_ok, font_size="18sp", on_release=lambda x: _events_callback(self.text_button_ok), ) ) instance_content_dialog.ids.box_buttons.add_widget(box_button_ok) if self.text_button_cancel != "": box_button_ok.anchor_x = "left" box_button_cancel = AnchorLayout(anchor_x="right") box_button_cancel.add_widget( MDTextButton( text=self.text_button_cancel, font_size="18sp", on_release=lambda x: _events_callback( self.text_button_cancel ), ) ) instance_content_dialog.ids.box_buttons.add_widget( box_button_cancel ) else: # create buttons for Android if isinstance(instance_content_dialog, ContentInputDialog): self.text_field = MDTextField( size_hint=(1, None), height=dp(48), hint_text=instance_content_dialog.hint_text, ) instance_content_dialog.ids.box_input.height = dp(48) instance_content_dialog.ids.box_input.add_widget( self.text_field ) instance_content_dialog.ids.box_buttons.remove_widget( instance_content_dialog.ids.sep ) box_buttons = AnchorLayout( anchor_x="right", size_hint_y=None, height=dp(30) ) box = BoxLayout(size_hint_x=None, spacing=dp(5)) box.bind(minimum_width=box.setter("width")) button_ok = MDRaisedButton( text=self.text_button_ok, on_release=lambda x: _events_callback(self.text_button_ok), ) box.add_widget(button_ok) if self.text_button_cancel != "": button_cancel = MDFlatButton( text=self.text_button_cancel, theme_text_color="Custom", text_color=self.theme_cls.primary_color, on_release=lambda x: _events_callback( self.text_button_cancel ), ) box.add_widget(button_cancel) box_buttons.add_widget(box) instance_content_dialog.ids.box_buttons.add_widget(box_buttons) instance_content_dialog.ids.box_buttons.height = button_ok.height instance_content_dialog.remove_widget( instance_content_dialog.ids.sep )