Created
January 19, 2024 23:41
-
-
Save Sultan-papagani/c317d5188f4239c278b807efd076cf95 to your computer and use it in GitHub Desktop.
Visualize SDR++ Themes with Python Pygame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this script on the same folder as .json theme files. | |
# for example: sdrpp_windows_x64\res\colormaps | |
# run .py and change themes with arrow keys -> <- | |
# Dependencies: | |
# pip install pillow | |
# pip install pygame | |
import json, pygame, os | |
from PIL import ImageColor | |
current_index = 0; | |
json_files = [f for f in os.listdir(os.getcwd()) if f.endswith('.json')] | |
total = len(json_files) | |
def loadnew(t): | |
global current_index | |
current_index += t | |
if current_index < 0: | |
current_index = total -1 | |
if current_index > total - 1: | |
current_index = 0 | |
f = open(json_files[current_index]) | |
data = json.load(f)["map"] | |
f.close() | |
wx = 300 # width of the display | |
window = pygame.display.set_mode((wx, max_y)) | |
pygame.display.set_caption(f"{current_index}:{json_files[current_index]}") | |
print(f"colors: {len(data)}") | |
index = 0 | |
drawline = len(data) < 30 | |
for color in data: | |
rgb = ImageColor.getrgb(color) | |
pygame.draw.rect(window, rgb, [0, max_y - index, wx, max_y // len(data)+1]) | |
if drawline: | |
pygame.draw.line(window, (0,0,0), (0, max_y-index),(wx, max_y-index)) | |
index += max_y // len(data)+1 | |
running = True | |
pygame.init() | |
max_y = pygame.display.Info().current_h - 80 # 80: title bar + bottom bar so window can fit the monitor | |
loadnew(0) | |
while running: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
running = False | |
pygame.quit() #yes exiting gives error lmao | |
if event.type == pygame.KEYDOWN: | |
if event.key == pygame.K_LEFT: | |
loadnew(-1) | |
if event.key == pygame.K_RIGHT: | |
loadnew(1) | |
pygame.display.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment