def test_no_parent(): from kivy.uix.widget import Widget from kivy_garden.draggable import \ save_widget_location, restore_widget_location w = Widget() location = save_widget_location(w) assert location == { 'x': 0, 'y': 0, 'width': 100, 'height': 100, 'size_hint_x': 1, 'size_hint_y': 1, 'pos_hint': {}, 'size_hint_min_x': None, 'size_hint_min_y': None, 'size_hint_max_x': None, 'size_hint_max_y': None, } w.pos = [ 20, 20, ] w.size = [ 40, 40, ] w.size_hint = [ None, None, ] w.pos_hint = { 'x': 1, 'top': .5, } w.size_hint_min = [ 30, 30, ] w.size_hint_max = [ 70, 70, ] restore_widget_location(w, location) assert w.size == [ 100, 100, ] assert w.pos == [ 0, 0, ] assert w.size_hint == [ 1, 1, ] assert w.pos_hint == {} assert w.size_hint_min == [ None, None, ] assert w.size_hint_max == [ None, None, ]
def create_battle_btns(self): """Generates the player buttons in the battle window. They are returned as a list of widgets, which are horizontal boxes with buttons.""" group_count = 0 battle_pairs = [] #button_height = sp(200) for pair in g.pairing.pairs: innerBox = BoxLayout(orientation='horizontal', padding=4, size_hint=(1, None)) first_toggle = None if pair[0].name == 'Bye': first_toggle = Widget() first_toggle.state = 'normal' first_toggle.color = (1, 1, 1, 0.5) else: first_toggle = battleScreenToggle(group="group" + str(group_count)) first_toggle.background_color = (1, 1, 1, 0.8) first_toggle.background_color_down = (1, 1, 1, 0.2) first_toggle.color = (1, 1, 1, 1) first_toggle.halign = 'center' first_toggle.player = pair[0] first_toggle.size_hint = (1, None) first_toggle.height = self.btn_height #first_toggle.width self.button_height = self.btn_height #first_toggle.width first_icon = Image(source=self.get_icon_path(pair[0]), pos=first_toggle.pos, size=(first_toggle.size[0], self.btn_height), color=[1, 1, 1, 1]) first_name = Label(text=pair[0].name, color=(1, 1, 1, 1), font_size=sp(20)) text_label_wins = str(pair[0].victories) for enemy in pair[0].history: if enemy.name == 'Bye': text_label_wins += "*" first_wins = None if pair[0].name == 'Bye': first_wins = Label(text="", color=(1, 1, 1, 1), font_size=sp(14)) else: first_wins = Label(text=text_label_wins + " wins", color=(1, 1, 1, 1), font_size=sp(14)) first_name.pos = (first_name.pos[0], first_name.pos[1]) first_wins.pos = (first_wins.pos[0], first_wins.pos[1] - sp(20)) first_layout = RelativeLayout(size_hint=first_toggle.size_hint, size=(first_toggle.size[0], self.btn_height)) first_layout.add_widget(first_icon) first_layout.add_widget(first_toggle) first_layout.add_widget(first_name) first_layout.add_widget(first_wins) innerBox.add_widget(first_layout) g.player_buttons.append(first_toggle) second_toggle = None if pair[1].name == 'Bye': second_toggle = Widget() second_toggle.state = 'normal' second_toggle.color = (1, 1, 1, 0.5) else: second_toggle = battleScreenToggle(group="group" + str(group_count)) second_toggle.background_color = (1, 1, 1, 0.8) second_toggle.background_color_down = (1, 1, 1, 0.2) second_toggle.color = (1, 1, 1, 1) second_toggle.halign = 'center' second_toggle.player = pair[1] second_toggle.size_hint = (1, None) second_toggle.height = self.btn_height #first_toggle.width second_icon = Image(source=self.get_icon_path(pair[1]), pos=second_toggle.pos, size=(second_toggle.size[0], self.btn_height), color=[1, 1, 1, 1]) second_name = Label(text=pair[1].name, color=(1, 1, 1, 1), font_size=sp(20)) text_label_wins = str(pair[1].victories) for enemy in pair[1].history: if enemy.name == 'Bye': text_label_wins += "*" if pair[1].name == 'Bye': text_label_wins = "" second_wins = None if pair[1].name == 'Bye': second_wins = Label(text="", color=(1, 1, 1, 1), font_size=sp(14)) else: second_wins = Label(text=text_label_wins + " wins", color=(1, 1, 1, 1), font_size=sp(14)) second_name.pos = (second_name.pos[0], second_name.pos[1]) second_wins.pos = (second_wins.pos[0], second_wins.pos[1] - sp(20)) second_layout = RelativeLayout(size_hint=second_toggle.size_hint, size=(second_toggle.size[0], self.btn_height)) second_layout.add_widget(second_icon) second_layout.add_widget(second_toggle) second_layout.add_widget(second_name) second_layout.add_widget(second_wins) innerBox.add_widget(second_layout) g.player_buttons.append(second_toggle) battle_pairs.append(innerBox) group_count += 1 innerBox.size_hint = (1, None) innerBox.height = self.btn_height #innerBox.height = first_player.height #innerBox.height = first_toggle.height#width return battle_pairs