def delete_theme(): global currentIdx, currentMenu, theme_name, menu_stack # Load custom-theme, remove .xml extension theme_name = os.path.splitext(theme.CUSTOM_THEME)[0] # Remove .xml try: os.remove(theme.theme_file) except: pass # Remove .json json_file = os.path.splitext(theme.theme_file)[0] + '.json' try: os.remove(json_file) except: pass # Remove .png png_file = os.path.splitext(theme.theme_file)[0] + '.png' try: os.remove(png_file) except: pass # Go back to main menu del menu_stack[:] menu_stack = [[menus.main, '']] currentMenu = menus.main currentIdx = 0 menus.update_naming() # redraw_board() graphics.drawCurrentMenu()
def init(): # Copy custom-theme from /usr/share if necessary if not os.path.exists(theme_file): src_file = '/usr/share/make-snake/%s' % CUSTOM_THEME if not os.path.exists(src_file): sys.exit('Error: custom-theme.xml missing from home and /usr/share/make-snake') ensure_dir(THEMES_DIR) shutil.copyfile(src_file, theme_file) load_theme() menus.update_naming()
def init(): # Copy custom-theme from /usr/share if necessary if not os.path.exists(theme_file): src_file = '/usr/share/make-snake/%s' % CUSTOM_THEME if not os.path.exists(src_file): sys.exit( 'Error: custom-theme.xml missing from home and /usr/share/make-snake' ) ensure_dir(THEMES_DIR) shutil.copyfile(src_file, theme_file) load_theme() menus.update_naming()
def update(): global tile, currentIdx, currentMenu, currentCategory, prevIndex, symbolMode, nameMode, theme_name, menu_stack key = graphics.screen.getch() if key > 0: ''' Symbol Mode ''' if symbolMode: input_string(key) if tile == '': tile = ' ' category = currentMenu[currentIdx][0] theme.set_tiles_theme(category, tile[:2]) tile = '' redraw_board() symbolMode = False return ''' Enter Name for new theme ''' if nameMode: input_string(key) theme_name = tile tile = '' # Sanitise name theme_name = theme_name.replace(" ", "-") # Replaces spaces theme_name = re.sub(r'[^a-zA-Z0-9-]', r'', theme_name) # Remove special characters theme_name = theme_name[:20] # Trim to 20 characters # Crate new theme and refresh redraw_board() menus.update_naming() # Go back to main menu del menu_stack[:] menu_stack = [[menus.main, '']] menu_stack.append([menus.editMain, theme_name]) currentMenu = menus.editMain currentIdx = 0 nameMode = False return ''' Check KEYS ''' if key == keys['DOWN']: currentIdx = (currentIdx + 1) % len(currentMenu) # Preview colors if currentMenu == menus.colors: set_color() elif currentMenu == menus.naming: # pass the saved name from the theme theme_name = currentMenu[currentIdx][0] redraw_board() return elif key == keys['UP']: currentIdx = (currentIdx - 1) % len(currentMenu) # Preview colors if currentMenu == menus.colors: set_color() elif currentMenu == menus.naming: # Pass the saved name from the theme theme_name = currentMenu[currentIdx][0] redraw_board() return elif key == keys['LEFT']: navigate_back() return elif key == keys['ENTER'] or key == keys['RIGHT']: # Back if (currentIdx == len(currentMenu) - 1): navigate_back() return # Color option elif currentMenu[currentIdx][1] is None: set_color() navigate_back() return # Tile option elif currentMenu[currentIdx][1] == "symbols": symbolMode = True return # Custom Name Mode elif currentMenu[currentIdx][1] == "name": nameMode = True return # Delete elif currentMenu[currentIdx][1] == "delete": delete_theme() return # Screenshot elif currentMenu[currentIdx][1] == "screenshot": take_screenshot() menus.editMain[3] = ["Take Screenshot [TAKEN]", "screenshot"] return # Modify existing theme elif currentMenu[currentIdx][1] == "existing": # pass the saved name from the theme theme_name = currentMenu[currentIdx][0] theme.update_name() redraw_board() graphics.update() title = currentMenu[currentIdx][0] menu_stack.append([menus.editMain, title]) currentMenu = menus.editMain currentIdx = 0 return # Submenu else: # Prevent Delete of custom-theme if currentMenu == menus.editMain and currentIdx == 2 and \ theme_name == os.path.splitext(theme.CUSTOM_THEME)[0]: return prevIndex = currentIdx title = currentMenu[currentIdx][0] menu_stack.append([currentMenu[currentIdx][1], title]) if (currentMenu == menus.board or currentMenu == menus.elements): currentCategory = title currentMenu = currentMenu[currentIdx][1] currentIdx = 0 # Preview colors if currentMenu == menus.colors: set_color() # Redraw with first theme on the list if currentMenu == menus.naming: theme_name = currentMenu[0][0] redraw_board() elif key == keys['Q']: __main__.exit() exit()
def update(): global tile, currentIdx, currentMenu, currentCategory, prevIndex, symbolMode, nameMode, theme_name, menu_stack key = graphics.screen.getch() if key > 0: ''' Symbol Mode ''' if symbolMode: input_string(key) if tile == '': tile = ' ' category = currentMenu[currentIdx][0] theme.set_tiles_theme(category, tile[:2]) tile = '' redraw_board() symbolMode = False return ''' Enter Name for new theme ''' if nameMode: input_string(key) theme_name = tile tile = '' # Sanitise name theme_name = theme_name.replace(" ", "-") # Replaces spaces theme_name = re.sub(r'[^a-zA-Z0-9-]', r'', theme_name) # Remove special characters theme_name = theme_name[:20] # Trim to 20 characters # Crate new theme and refresh redraw_board() menus.update_naming() # Go back to main menu del menu_stack[:] menu_stack = [[menus.main, '']] menu_stack.append([menus.editMain, theme_name]) currentMenu = menus.editMain currentIdx = 0 nameMode = False return ''' Check KEYS ''' if key == keys['DOWN']: currentIdx = (currentIdx + 1) % len(currentMenu) # Preview colors if currentMenu == menus.colors: set_color() elif currentMenu == menus.naming: # pass the saved name from the theme theme_name = currentMenu[currentIdx][0] redraw_board() return elif key == keys['UP']: currentIdx = (currentIdx - 1) % len(currentMenu) # Preview colors if currentMenu == menus.colors: set_color() elif currentMenu == menus.naming: # Pass the saved name from the theme theme_name = currentMenu[currentIdx][0] redraw_board() return elif key == keys['LEFT']: navigate_back() return elif key == keys['ENTER'] or key == keys['RIGHT']: # Back if (currentIdx == len(currentMenu) - 1): navigate_back() return # Color option elif currentMenu[currentIdx][1] is None: set_color() navigate_back() return # Tile option elif currentMenu[currentIdx][1] == "symbols": symbolMode = True return # Custom Name Mode elif currentMenu[currentIdx][1] == "name": nameMode = True return # Delete elif currentMenu[currentIdx][1] == "delete": delete_theme() return # Screenshot elif currentMenu[currentIdx][1] == "screenshot": take_screenshot() menus.editMain[3] = [ _("Take Screenshot [TAKEN]"), "screenshot" ] return # Modify existing theme elif currentMenu[currentIdx][1] == "existing": # pass the saved name from the theme theme_name = currentMenu[currentIdx][0] theme.update_name() redraw_board() graphics.update() title = currentMenu[currentIdx][0] menu_stack.append([menus.editMain, title]) currentMenu = menus.editMain currentIdx = 0 return # Submenu else: # Prevent Delete of custom-theme if currentMenu == menus.editMain and currentIdx == 2 and \ theme_name == os.path.splitext(theme.CUSTOM_THEME)[0]: return prevIndex = currentIdx title = currentMenu[currentIdx][0] menu_stack.append([currentMenu[currentIdx][1], title]) if (currentMenu == menus.board or currentMenu == menus.elements): currentCategory = title currentMenu = currentMenu[currentIdx][1] currentIdx = 0 # Preview colors if currentMenu == menus.colors: set_color() # Redraw with first theme on the list if currentMenu == menus.naming: theme_name = currentMenu[0][0] redraw_board() elif key == keys['Q']: __main__.exit()