我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用kivy.uix.gridlayout.GridLayout()。
def build(self): root_widget = BoxLayout(orientation='vertical') output_label = Label(size_hint_y=1) button_symbols = ('1', '2', '3', '+', '4', '5', '6', '-', '7', '8', '9', '.', '0', '*', '/', '=') button_grid = GridLayout(cols=4, size_hint_y=2) for symbol in button_symbols: button_grid.add_widget(Button(text=symbol)) clear_button = Button(text='clear', size_hint_y=None, height=100) root_widget.add_widget(output_label) root_widget.add_widget(button_grid) root_widget.add_widget(clear_button) return root_widget
def __init__(self, **kvargs): super(KDialog, self).__init__(**kvargs) self.orientation = "vertical" self.param = None # ???? ??? ?????? ?????? "??-???-??????". self.box_buttons_select = BoxLayout(orientation="horizontal", size_hint_y=None, height=40) self.scroll = ScrollView() self.box_content = GridLayout(cols=2, size_hint_y=None) self.box_content.bind(minimum_height=self.box_content.setter("height")) self.body = Popup(title_align=self.title_align, background=self.background_image, on_dismiss=self.dismiss_callback) # ??? ???? ?????????. with self.box_content.canvas: Color(0.16, 0.16, 0.16) self.canvas_for_box_content = \ Rectangle(pos=(5, 5), size=(self.box_content.width, self.box_content.height)) self.box_content.bind(size=self._update_canvas_size, pos=self._update_canvas_size) self.scroll.add_widget(self.box_content)
def _update_canvas_size(self, instance, value): """?????????? ??? ????????? ??????? ?????? ??????????. type instance: instance <kivy.uix.gridlayout.GridLayout object'>; type value: list; param value: ??????? ?????? instance; """ self.canvas_for_box_content.pos = instance.pos self.canvas_for_box_content.size = instance.size # ????????? ?????? ???? Popup - ???? ?????????. self.body_message.height = self.canvas_for_box_content.size[1] + 150 if self.body_message.height > Window.size[1]: self.body_message.height = Window.size[1] - 10
def __init__(self, **kwargs): # inicializace super(PartylineScreen, self).__init__(**kwargs) self.root.insertStrings.append((self, "STR_PARTYLINE")) self.input = TextInput(size_hint=(.8, .07), pos_hint={'x':.08, 'y':.024}) self.output = Label(markup=True, font_name='font/Roboto-Regular.ttf', font_size='16dp', size_hint_y = None) self.SLayout = GridLayout(size_hint_y = None, cols=1, spacing=0) self.SLayout.bind(minimum_height=self.SLayout.setter('height')) self.scroll = ScrollView(size_hint=(1,.9), pos_hint={'center_x': .58, 'y': .125}, scroll_timeout=10000) self.scroll.do_scroll_x = False self.scroll.add_widget(self.SLayout) self.SLayout.add_widget(self.output) self.layout = RelativeLayout(size_hint=(.75, .83), pos_hint={'center_x': .437, 'y': .02}) self.send = DelButton(color=(1,1,1,0), text='SEND', size_hint=(None, .1), pos_hint={'x':.88, 'y':.022}, background_normal='crop/icons/send.png', background_down='crop/icons/send.png') self.send.bind(on_press=self.sendMsg) self.input.bind(focus=self.on_focus) self.layout.content.add_widget(self.scroll) self.layout.content.add_widget(self.input) self.layout.content.add_widget(self.send) self.add_widget(self.layout) if self.root.onAndroid(): self.LayouFocusOn = Animation(size_hint_y=.5, pos_hint={'center_x': .437, 'y': .38}, duration=.2) self.LayouFocusOut = Animation(size_hint_y=.83, pos_hint={'center_x': .437, 'y': .02}, duration=.2)
def _update_canvas_size(self, instance, value): '''?????????? ??? ????????? ??????? ?????? ??????????. type instance: instance <kivy.uix.gridlayout.GridLayout object'>; type value: list; param value: ??????? ?????? instance; ''' self.canvas_for_box_content.pos = instance.pos self.canvas_for_box_content.size = instance.size # ????????? ?????? ???? Popup. self.height = self.dp(self.canvas_for_box_content.size[1] + 70) self.width = self.dp(int(Window.size[0] // self.hint_x)) if self.height > Window.size[1]: self.height = self.dp(Window.size[1] - 10)
def generate_wifi_list_screen(self): self.wifi_grid = GridLayout(cols=1, padding=0, spacing=0) self.placeholder = WifiLoadingList() self.wifi_grid.add_widget(self.placeholder) self.rsm._generate_backbutton_screen( name=self.name, title=roboprinter.lang.pack['WiFi']['Select_Network'], back_destination=self.back_destination, content=self.wifi_grid, cta=self._refresh_wifi_list, icon='Icons/Manual_Control/refresh_icon.png') thread.start_new_thread(self._append_wifi_list, ()) Clock.schedule_interval(self._wifi_callback, 1 / 30.) return
def __init__(self, client): # TODO handle connection errors properly self.client = client self.layout = GridLayout(cols = 2, pos_hint={'x': 0, 'y': 0}, size_hint=(1, 0.1)) self.client.layout.add_widget(self.layout, index = 1000) self.client.bind('connected', self.connected) self.client.bind('loaded', self.loaded) self.client.bind('registered', self.registered) if self.client.config.get('connection', 'autoconnect') == 'yes': self.auto = True self.client.connect(self.client.config.get('connection', 'server')) else: self.auto = False self.server_input = TextInput(text = self.client.config.get('connection', 'server')) self.server_button = Button(text = 'Connect', size_hint = (0.25, 1)) self.server_button.bind(on_press = self.do_connect) self.layout.add_widget(self.server_input) self.layout.add_widget(self.server_button)
def update_dialog(self, cur_build, upd_build): popup = Popup(title='Update', content=ScrollView(), size_hint=(0.8,None), height=cm(5)) grid = GridLayout(cols=1, spacing=0, size_hint_y=None) grid.bind(minimum_height= grid.setter('height')) con = StackLayout() grid.add_widget(con) popup.content.add_widget(grid) lbl1 = Label(text='Current build is %s' % (cur_build), size_hint_y=None, height=cm(1)) lbl2 = Label(text='Build %s available' % (upd_build), size_hint_y=None, height=cm(1)) btn1 = Button(text='Cancel', size_hint=(0.5, None), height=cm(1)) btn2 = Button(text='Update', size_hint=(0.5, None), height=cm(1)) btn1.bind(on_release=popup.dismiss) btn2.bind(on_release=lambda x: {self.update(), popup.dismiss()}) for x in (lbl1, lbl2, btn1, btn2): con.add_widget(x) popup.open()
def __init__(self, target, **kwargs): super(BattleMenuState, self).__init__(target, **kwargs) print('battle menu state here, how ya doin', self, target) overlay = App.get_running_app().overlay self.move_button = Button(text='Move', on_release=lambda dt: self.change(SelectMoveState)) self.attack_button = Button(text='Attack', on_release=lambda dt: self.change(SelectAttackState)) self.wait_button = Button(text='Wait', on_release=lambda dt: self.change(TurnEnd)) menu = GridLayout(cols=1, size_hint=(None, None), row_force_default=True, row_default_height=40) menu.width = dp(100) menu.height = menu.minimum_height buttons = [self.move_button, self.attack_button, self.wait_button] for button in buttons: menu.add_widget(button) menu.y = dp((Window.height / 2) + (menu.height / 2)) menu.x = dp(40) self.menu = menu overlay.add_widget(self.menu) self.target.game.set_focus_target(self.target)
def _update_canvas_size(self, instance, value): """?????????? ??? ????????? ??????? ?????? ??????????. type instance: instance <kivy.uix.gridlayout.GridLayout object'>; type value: list; param value: ??????? ?????? instance; """ self.canvas_for_box_content.pos = instance.pos self.canvas_for_box_content.size = instance.size # ????????? ??????? ???? Popup - ???? ?????????. if self.param in ["text", "tel", "address", "mail", "password", "datetime", "number"]: plus_height = 170 elif self.param == "logpass": plus_height = 200 else: plus_height = 120 self.body.height = self.canvas_for_box_content.size[1] + plus_height self.body.width = int(Window.size[0] / self.size_hint_x) if self.body.height > Window.size[1]: self.body.height = Window.size[1] - 10 if self.rst: self.message.height = self.body.height / 1.33
def __init__(self, **kwargs): super(LoginScreen, self).__init__(**kwargs) '''self.orientation = 'vertical' ### self.grid = GridLayout() self.grid.cols = 2 self.grid.add_widget(Label(text='User Name')) self.grid.username = TextInput(multiline=False) self.grid.add_widget(self.grid.username) self.grid.add_widget(Label(text='password')) self.grid.password = TextInput(multiline=False) self.grid.add_widget(self.grid.password) ### self.options = BoxLayout() self.options.size_hint_y = 0.5 self.options.bt_cancel = Button(text='Cancel') self.options.add_widget(self.options.bt_cancel) self.options.bt_login = Button(text='Login') self.options.bt_login.bind(on_press=self.bt_login_clicked) self.options.add_widget(self.options.bt_login) ### self.add_widget(self.grid) self.add_widget(self.options)''' ###
def __init__(self, **kwargs): super(LoginScreen, self).__init__(**kwargs) self.username_w = TextInput(multiline=False) self.password_w = TextInput(password=True, multiline=False) self.login_btn = Button(text='Login') self.login_btn.bind(on_press=self.login) layout = GridLayout() layout.cols = 2 layout.add_widget(Label(text='Username')) layout.add_widget(self.username_w) layout.add_widget(Label(text='Password')) layout.add_widget(self.password_w) layout.add_widget(self.login_btn) self.add_widget(layout)
def on_enter(self, onsuccess=False): container = self.ids.container if self.from_back: return if len(container.children) > 2: container.remove_widget(container.children[0]) from network import get_data talks = get_data('tracks', onsuccess=onsuccess) gl = None if not talks: return talk_info = talks['0.0.1'][0][self.talkid] self.ids.talk_title.text = talk_info['title'] self.ids.talk_desc.text = talk_info['description'] if 'speaker' in talk_info.keys(): speaker=talk_info['speaker'] if speaker['name']: speaker_details = SpeakerDetails(speaker=speaker) if 'social' in speaker: speaker_social = speaker['social'][0] social_len = len(speaker_social) gl = GridLayout(cols=social_len, size_hint_y=None, padding='2dp', spacing='2dp') import webbrowser for social_acc, social_link in speaker_social.items(): imbt = Factory.ImBut() imbt.source = 'atlas://data/default/' + social_acc.lower() imbt.on_released = partial(webbrowser.open,social_link) gl.add_widget(imbt) speaker_details.add_widget(gl) self.ids.container.add_widget(speaker_details) Factory.Animation(opacity=1, d=.3).start(container) self.ids.scroll.scroll_y = 1
def __init__(self, **kwargs): # inicializace self.root = kwargs['root'] self.root.insertStrings.append((self, )) super(BookmarksScreen, self).__init__(**kwargs) self.layout = GridLayout(cols=1, size_hint_y=None, size_hint_x = 1, spacing=10) self.layout.bind(minimum_height=self.layout.setter('height')) self.scrollview.add_widget(self.layout)
def _key_handler(self, instance, KEY, *args): # Reakce na stisk systémové klávesy OS Android print "Key: {0}".format(KEY) if KEY == 1001: if self.sm.current not in ('MainMenuScreen', 'GameScreen'): if self.sm.current == "SettingsScreen": self.sm.get_screen("SettingsScreen").dropdown.dismiss() self.sm.current_screen.prev() else: if self.sm.current == 'MainMenuScreen': text = self.L.STR_POPUP_EXIT title = self.L.STR_POPUP_EXIT_TITLE yes_callback = self.popupStop else: text = self.L.STR_POPUP_DISCONNECT title = self.L.STR_POPUP_DISCONNECT_TITLE yes_callback = self.popupDisconnect content = BoxLayout(orientation='vertical') content.add_widget(Label(text=text, font_name='font/Roboto-Regular.ttf', font_size='14dp')) buttons = GridLayout(cols=2, rows=1, spacing=10, size_hint=(1, .3)) yes = Button(text=self.L.STR_YES) yes.bind(on_press=yes_callback) no = Button(text=self.L.STR_NO) buttons.add_widget(yes) buttons.add_widget(no) content.add_widget(buttons) self.popupExit = Popup(title=title, size_hint=(.7,.3), content=content, auto_dismiss=False) no.bind(on_press=self.popupExit.dismiss) self.popupExit.open() elif KEY == 1002: self.dispatch('on_pause') elif KEY == 1004: self.dispatch('on_pause')
def build(self): app = GridLayout(rows=2) debugger= ExdDebugger(app=self, size_hint_y= 0.3) app.add_widget(self.STACK) app.add_widget(debugger) return app
def show_locations(self, *args): screen = self.Screen(name='locations') # self.screen.ids.action_previous.previous_image = \ # 'atlas://data/images/defaulttheme/previous_normal' # self.screen.ids.action_previous.app_icon = \ # 'Data/Images/shops/{}.png'.format(self.shop) # scroll_icons.add_widget(box_locations) box_menu = GridLayout(cols=2) for i, location in enumerate(self.locations): box_menu.add_widget( self.CustomMenuItem( background_item=self.core.background_locations[i], icon_item='Data/Images/locations/{}.png'.format(location), text_item=self.core.dict_locations[location], id_item=location, text_color=self.get_color_from_hex( self.core.theme_text_color), events_callback=self.events_program ) ) screen.add_widget(box_menu) self.screen.ids.screen_manager.add_widget(screen) effect = self.choice(self.effects_transition) self.screen.ids.screen_manager.transition = effect() self.screen.ids.screen_manager.current = 'locations' # self.screen.ids.action_previous.title = \ # self.core.string_name_shop.format(self.shop.capitalize()) self.set_current_item_tabbed_panel( self.get_hex_from_color(self.core.color_action_bar), self.core.theme_text_color )
def _create_up_down_button(self): gridlayout = GridLayout(rows=2, size_hint_x=0.2, spacing=20, padding=(10,10,10,10)) button_up = Button( background_normal="Icons/Up-arrow-grey.png", background_down="Icons/Up-arrow-blue.png", ) button_up.bind(on_press=self.up_action_file) button_down = Button( background_normal="Icons/Down-arrow-grey.png", background_down="Icons/Down-arrow-blue.png", ) button_down.bind(on_press=self.down_action_file) gridlayout.add_widget(button_up) gridlayout.add_widget(button_down) return gridlayout
def update_done_dialog(self, cur_build, upd_build): popup = Popup(title='Update done', content=ScrollView(), size_hint=(0.8,None), height=cm(5)) grid = GridLayout(cols=1, spacing=0, size_hint_y=None) grid.bind(minimum_height= grid.setter('height')) con = StackLayout() grid.add_widget(con) popup.content.add_widget(grid) lbl1 = Label(text='Done updating from %s to %s' % (cur_build, upd_build), size_hint_y=None, height=cm(1)) btn1 = Button(text='Close', size_hint=(1, None), height=cm(1)) btn1.bind(on_release=popup.dismiss) for x in (lbl1, btn1): con.add_widget(x) popup.open()
def __init__(self): super().__init__() self.images = dict() self.root = FloatLayout(size=(Window.width, Window.height)) self.grid = GridLayout(cols=8) self.add_widget(self.root) self.root.add_widget(self.grid) for i, bucket in enumerate(config["visual_debugger"]["available_buckets"]): layout = BoxLayout(orientation="vertical") image = VisualDebuggerImage( allow_stretch=True ) image.bind(texture=image.update_texture_filters) self.images[bucket] = image layout.add_widget(image) label = Label( text=bucket, color=(1, 1, 1, 1), size_hint=(1, 0.1) ) layout.add_widget(label) self.grid.add_widget(layout) Window.bind(on_resize=self.on_window_resize) Window.clearcolor = (0.136, 0.191, 0.25, 1)
def setup_contents(self, msg): content = GridLayout(cols=1, rows=2) self.exit = Button(text='OK') self.exit.bind(on_press=self.dismiss) self.cancel = Button(text='Cancel') text = Label(text=msg, id='popup_content') content.add_widget(text) return content
def __init__(self, **kvargs): super(ThemesForum, self).__init__(**kvargs) self.size_hint = (1, 1) box_scroll = ScrollView() box_scroll_and_paginator = BoxLayout(orientation="vertical", spacing=5) box_for_paginator = BoxLayout(size_hint_y=None, height=40) layout = GridLayout(cols=1, spacing=17, size_hint=(1, None)) layout.bind(minimum_height=layout.setter('height')) layout.add_widget(Widget(size_hint=(1, .5))) layout.add_widget(Label(text=self.title, font_size=self.font_size + 4, markup=True)) layout.add_widget(Widget(size_hint=(1, .5))) layout.add_widget(SettingSpacer()) # ????????? ???????. if self.flag != "forumcat": number_page = Label(text=self.number_page, markup=True) number_page.bind(on_ref_press=self.refs_callback) box_for_paginator.add_widget(number_page) for data in self.data: for key in ["theme", "total_topics", "last_theme", "sep", "last_answer"]: try: if data[key] == "": continue except KeyError: pass font_size = self.font_size + 4 if key == "theme" \ else self.font_size if key == "sep": layout.add_widget(Widget(size_hint=(1, .5))) else: name_item = data[key] info = Label(text=name_item, font_size=font_size, id=name_item, markup=True) info.bind( size=lambda *args: self._update_window_size(args), on_ref_press=self.refs_callback) layout.add_widget(info) if key == "theme": layout.add_widget(SettingSpacer()) layout.add_widget(SettingSpacer()) box_scroll.add_widget(layout) box_scroll_and_paginator.add_widget(box_scroll) if self.flag != "forumcat": box_scroll_and_paginator.add_widget(box_for_paginator) self.add_widget(box_scroll_and_paginator)
def __init__(self, **kvargs): super(ScrollButton, self).__init__(**kvargs) self.layout = GridLayout(cols=1, padding=5, spacing=5, size_hint_y=None) self.layout.bind(minimum_height=self.layout.setter('height')) self.body = Popup(content=self, size_hint_y=None, size_hint_x=None, pos_hint={"center_x": .5, "center_y": .5}, width=int(Window.size[0] / self.size_hint_x), background=self.background_image) # ??? ??? ?????? ????????? - (canvas GridLayout). with self.layout.canvas: Color(0.0, 0.0, 0.0) self.canvas_for_box_content = \ Rectangle(pos=(5, 5), size=(self.layout.width, self.layout.height)) self.layout.bind(size=self._update_canvas_size, pos=self._update_canvas_size) for list_button in self.button_list: if not list_button[2]: image = "atlas://data/images/defaulttheme/button" else: image = list_button[2] button = Button(text=list_button[0], size_hint_y=None, height=self.height_button, background_normal=image, id=list_button[0]) if callable(self.events_callback): button.bind(on_press=self.events_callback, on_release=self._close_popup) self.layout.add_widget(button) text = list_button[1] if text: self.layout.add_widget( RstDocument(text=text, size_hint_y=None, background_color=self.background_text_color, underline_color="#2fbfe0", height=self.height_text)) self.add_widget(self.layout)
def build(self): root_widget = BoxLayout(orientation='vertical') output_label = Label(size_hint_y=1) button_symbols = ('1', '2', '3', '+', '4', '5', '6', '-', '7', '8', '9', '.', '0', '*', '/', '=') button_grid = GridLayout(cols=4, size_hint_y=2) for symbol in button_symbols: button_grid.add_widget(Button(text=symbol)) clear_button = Button(text='clear', size_hint_y=None, height=100) def print_button_text(instance): output_label.text += instance.text for button in button_grid.children[1:]: # note use of the # `children` property button.bind(on_press=print_button_text) def resize_label_text(label, new_height): label.font_size = 0.5*label.height output_label.bind(height=resize_label_text) def evaluate_result(instance): try: output_label.text = str(eval(output_label.text)) except SyntaxError: output_label.text = 'Python syntax error!' button_grid.children[0].bind(on_press=evaluate_result) def clear_label(instance): output_label.text = '' clear_button.bind(on_press=clear_label) root_widget.add_widget(output_label) root_widget.add_widget(button_grid) root_widget.add_widget(clear_button) return root_widget
def onFilter(self): popup = BoxLayout(orientation='vertical', size=self.size, pos=self.pos) self.filter_popup = Popup( title='Filter', content=popup, size_hint=( 0.9, 0.9), auto_dismiss=False) scroll = ScrollView() checkbox = GridLayout( cols=2, row_force_default=True, row_default_height=self.height / 20, size_hint_y=None) checkbox.bind(minimum_height=checkbox.setter('height')) select_all = GridLayout( cols=2, row_force_default=True, row_default_height=self.height / 20, size_hint_y=0.08) self.select_all_checkbox = CheckBox(size_hint_x=0.2) select_all_label = Label( text='Select All', text_size=( self.width * 0.7, None), halign='left') select_all.add_widget(self.select_all_checkbox) select_all.add_widget(select_all_label) cancel = Button(text='Cancel', on_release=self.dismiss_filter_popup) ok = Button(text='Ok', on_release=self.filter_ok) buttons = BoxLayout(size_hint_y=None, height=self.height / 20) buttons.add_widget(cancel) buttons.add_widget(ok) scroll.add_widget(checkbox) popup.add_widget(scroll) popup.add_widget(select_all) popup.add_widget(buttons) self.filter_rows = {} for i in range(len(self._log_analyzer.supported_types)): self.filter_rows[i] = CheckBox(size_hint_x=0.2) checkbox.add_widget(self.filter_rows[i]) checkbox.add_widget( Label( text=str( list( self._log_analyzer.supported_types)[i]))) self.select_all_checkbox.bind(active=self.filter_select_all) self.filter_popup.open()
def __init__(self, **kvargs): super(BDialog, self).__init__( size_hint_x=None, size_hint_y=None, **kvargs ) box_buttons = GridLayout( cols=1, padding=5, spacing=5, size_hint_y=None ) box_buttons.bind(minimum_height=box_buttons.setter('height')) scroll = ScrollView() # ??? ??? ?????? ????????? - (canvas GridLayout). with box_buttons.canvas: Color(0.0, 0.0, 0.0) self.canvas_for_box_content = \ Rectangle( pos=(5, 5), size=(box_buttons.width, box_buttons.height) ) box_buttons.bind( size=self._update_canvas_size, pos=self._update_canvas_size ) for list_button in self.button_list: if not list_button[1]: image = 'atlas://data/images/defaulttheme/button' else: image = list_button[1] button = Button( text=list_button[0], size_hint_y=None, height=self.dp(self.height_button), background_normal=image, id=list_button[0], background_down=self.background_image_shadows[0] ) if callable(self.events_callback): button.bind( on_press=self.events_callback, on_release=self.dismiss ) box_buttons.add_widget(button) scroll.add_widget(box_buttons) self.content = scroll self.width = self.dp(int(Window.size[0] // self.hint_x))
def __init__(self, **kvargs): super(BDialog, self).__init__( size_hint_x=None, size_hint_y=None, **kvargs ) box_buttons = GridLayout( cols=1, padding=5, spacing=5, size_hint_y=None ) box_buttons.bind(minimum_height=box_buttons.setter('height')) scroll = ScrollView() # ??? ??? ?????? ????????? - (canvas GridLayout). with box_buttons.canvas: Color(rgba=self.background_grid) self.canvas_for_box_content = \ Rectangle( pos=(5, 5), size=(box_buttons.width, box_buttons.height) ) box_buttons.bind( size=self._update_canvas_size, pos=self._update_canvas_size ) for list_button in self.button_list: if not list_button[1]: image = 'atlas://data/images/defaulttheme/button' else: image = list_button[1] button = Button( text=list_button[0], size_hint_y=None, height=self.dp(self.height_button), background_normal=image, id=list_button[0], background_down=self.background_image_shadows[0], background_color=choice(self.background_color_buttons) ) if callable(self.events_callback): button.bind( on_press=self.events_callback, on_release=self.dismiss ) box_buttons.add_widget(button) scroll.add_widget(box_buttons) self.content = scroll self.width = self.dp(int(Window.size[0] // self.hint_x))