def _addButton(self, parent, name, source, size, pos, action_func, on_top=False): button = Image(source=source) button.size = size button.on_top = on_top button.pos = pos button.scale = 1. button.rotation = 0. button.action = action_func button.name = name self.objects.update({name: {'obj': button}}) parent.add_widget(button) return button
def AddImageAndCategories(self, imageDict, clb=None): self.clear_widgets() l = len(imageDict.keys()) if l % 2: self.rows = l / 2 + 1 else: self.rows = l / 2 categories = imageDict.keys() if len(categories) > 1: random.shuffle(categories) for category in categories: img = Image(source=imageDict[category]['image']) img.name = category if clb: img.bind(on_touch_down=clb) img = self.add_widget(img)
def build(self): self.from_move = None self.to_move = None self.chessboard = ChessBoard() self.analysis_board = ChessBoard() self.squares = [] self.use_engine = False self.last_touch_down_move = None self.last_touch_up_move = None parent = BoxLayout(size_hint=(1,1)) grid = GridLayout(cols = 8, rows = 8, spacing = 0, size_hint=(1, 1)) for i, name in enumerate(SQUARES): bt = Image(allow_stretch=True) bt.sq = i bt.name = name # bt.border = [0,0,0,0] if i in light_squares: bt.sq_color = "l" bt.background_down = "img/empty-l.png" # bt.background_color=[1,1,1,1] else: bt.sq_color = "d" bt.background_down = "img/empty-d.png" # bt.background_color=[0,0,0,0] # print i # bt.bind(on_press=self.callback) bt.bind(on_touch_down=self.touch_down_move) bt.bind(on_touch_up=self.touch_up_move) # bt.bind(on_touch_up=self.touch_move) grid.add_widget(bt) self.squares.append(bt) b = BoxLayout(size_hint=(0.15,0.15)) ## Spacers # b.add_widget(Button(spacing=1)) # b.add_widget(Button(spacing=1)) # b.add_widget(Button(spacing=1)) # Move control buttons # back_bt = Button(markup=True) # # back_bt.background_normal="img/empty-l.png" # back_bt.text="[color=ff3333]Back[/color]" # back_bt.bind(on_press=self.back) # b.add_widget(back_bt) # save_bt = Button(markup=True) #fwd_bt.background_normal="img/empty-d.png" save_bt.text="[color=3333ff]Save[/color]" # save_bt.text="Save" save_bt.bind(on_press=self.save) b.add_widget(save_bt) # b.add_widget(Button(spacing=10)) # b.add_widget(Button(spacing=10)) # b.add_widget(Button(spacing=10)) # grid.add_widget(b) # board_box.add_widget(grid) # board_box.add_widget(b) # fen_input = TextInput(text="FEN", focus=True, multiline=False) # def on_fen_input(instance): # self.chessboard.setFEN(instance.text) # self.refresh_board() ## print 'The widget', instance.text # # fen_input.bind(on_text_validate=on_fen_input) ## self._keyboard.bind(on_key_down=self._on_keyboard_down) # # # b.add_widget(fen_input) settings_bt = Button(markup=True, text='Setup') settings_bt.bind(on_press=self.go_to_settings) b.add_widget(settings_bt) # self.root.current='settings' parent.add_widget(grid) info_grid = GridLayout(cols = 1, rows = 4, spacing = 1, size_hint=(0.3, 1), orientation='vertical') info_grid.add_widget(b) self.game_score = ScrollableLabel('New Game', ref_callback=self.go_to_move) info_grid.add_widget(self.game_score) self.engine_score = ScrollableLabel('[ref=engine_toggle]Analysis[/ref]', ref_callback=self.add_eng_moves) info_grid.add_widget(self.engine_score) info_grid.add_widget(Button(text="Text")) parent.add_widget(info_grid) self.refresh_board() platform = kivy.utils.platform() self.uci_engine = None if self.is_desktop(): self._keyboard = Window.request_keyboard( self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.start_engine_thread() sm = ScreenManager(transition=SlideTransition()) board_screen = Screen(name='main') board_screen.add_widget(parent) sm.add_widget(board_screen) settings_screen = SettingsScreen(name='settings') settings_screen.add_widget(self.generate_settings()) sm.add_widget(settings_screen) return sm
def build(self): self.from_move = None self.to_move = None self.chessboard = ChessBoard() self.analysis_board = ChessBoard() self.squares = [] self.use_engine = False self.last_touch_down_move = None self.last_touch_up_move = None parent = BoxLayout(size_hint=(1, 1)) grid = GridLayout(cols=8, rows=8, spacing=0, size_hint=(1, 1)) for i, name in enumerate(SQUARES): bt = Image(allow_stretch=True) bt.sq = i bt.name = name # bt.border = [0,0,0,0] if i in light_squares: bt.sq_color = "l" bt.background_down = "img/empty-l.png" # bt.background_color=[1,1,1,1] else: bt.sq_color = "d" bt.background_down = "img/empty-d.png" # bt.background_color=[0,0,0,0] # print i # bt.bind(on_press=self.callback) bt.bind(on_touch_down=self.touch_down_move) bt.bind(on_touch_up=self.touch_up_move) # bt.bind(on_touch_up=self.touch_move) grid.add_widget(bt) self.squares.append(bt) b = BoxLayout(size_hint=(0.15, 0.15)) ## Spacers # b.add_widget(Button(spacing=1)) # b.add_widget(Button(spacing=1)) # b.add_widget(Button(spacing=1)) # Move control buttons # back_bt = Button(markup=True) # # back_bt.background_normal="img/empty-l.png" # back_bt.text="[color=ff3333]Back[/color]" # back_bt.bind(on_press=self.back) # b.add_widget(back_bt) # save_bt = Button(markup=True) #fwd_bt.background_normal="img/empty-d.png" save_bt.text = "[color=3333ff]Save[/color]" # save_bt.text="Save" save_bt.bind(on_press=self.save) b.add_widget(save_bt) # b.add_widget(Button(spacing=10)) # b.add_widget(Button(spacing=10)) # b.add_widget(Button(spacing=10)) # grid.add_widget(b) # board_box.add_widget(grid) # board_box.add_widget(b) # fen_input = TextInput(text="FEN", focus=True, multiline=False) # def on_fen_input(instance): # self.chessboard.setFEN(instance.text) # self.refresh_board() ## print 'The widget', instance.text # # fen_input.bind(on_text_validate=on_fen_input) ## self._keyboard.bind(on_key_down=self._on_keyboard_down) # # # b.add_widget(fen_input) settings_bt = Button(markup=True, text='Setup') settings_bt.bind(on_press=self.go_to_settings) b.add_widget(settings_bt) # self.root.current='settings' parent.add_widget(grid) info_grid = GridLayout(cols=1, rows=4, spacing=1, size_hint=(0.3, 1), orientation='vertical') info_grid.add_widget(b) self.game_score = ScrollableLabel('New Game', ref_callback=self.go_to_move) info_grid.add_widget(self.game_score) self.engine_score = ScrollableLabel( '[ref=engine_toggle]Analysis[/ref]', ref_callback=self.add_eng_moves) info_grid.add_widget(self.engine_score) info_grid.add_widget(Button(text="Text")) parent.add_widget(info_grid) self.refresh_board() platform = kivy.utils.platform() self.uci_engine = None if self.is_desktop(): self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.start_engine_thread() sm = ScreenManager(transition=SlideTransition()) board_screen = Screen(name='main') board_screen.add_widget(parent) sm.add_widget(board_screen) settings_screen = SettingsScreen(name='settings') settings_screen.add_widget(self.generate_settings()) sm.add_widget(settings_screen) return sm