2021-12-25 02:15:42 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2021-12-25 09:02:09 +01:00
|
|
|
MAX_ROWS = 9
|
|
|
|
MAX_COLS = 9
|
2021-12-25 02:15:42 +01:00
|
|
|
ICON_NAME_PREFIX = "workspace"
|
|
|
|
|
|
|
|
WORKSPACE_WIDTH = 50
|
|
|
|
WORKSPACE_HEIGHT = 50
|
|
|
|
STROKE_COLOR = "#bebebe"
|
|
|
|
STROKE_WIDTH = 5
|
|
|
|
BORDER_RADIUS = 10
|
|
|
|
|
|
|
|
with open("workspace_icon_template.data") as f:
|
|
|
|
TEMPLATE = f.read()
|
|
|
|
|
2021-12-25 02:20:55 +01:00
|
|
|
def define_globals(data, width, height):
|
|
|
|
data = data.replace("{{WIDTH}}", str(width))
|
|
|
|
data = data.replace("{{HEIGHT}}", str(height))
|
|
|
|
data = data.replace("{{STROKE_COLOR}}", STROKE_COLOR)
|
|
|
|
data = data.replace("{{STROKE_WIDTH}}", str(STROKE_WIDTH))
|
|
|
|
return data
|
|
|
|
|
|
|
|
def draw_outer_rectangle(data, width, height):
|
|
|
|
data = data.replace("{{BORDER_RADIUS}}", str(BORDER_RADIUS))
|
|
|
|
data = data.replace("{{RECTANGLE_X}}", str(STROKE_WIDTH / 2))
|
|
|
|
data = data.replace("{{RECTANGLE_Y}}", str(STROKE_WIDTH / 2))
|
|
|
|
data = data.replace("{{RECTANGLE_WIDTH}}", str(width - STROKE_WIDTH))
|
|
|
|
data = data.replace("{{RECTANGLE_HEIGHT}}", str(height - STROKE_WIDTH))
|
|
|
|
return data
|
|
|
|
|
2021-12-25 07:11:27 +01:00
|
|
|
def draw_line(is_horizontal, start_x, start_y, length):
|
|
|
|
data = ""
|
|
|
|
direction = "H" if is_horizontal else "V"
|
|
|
|
data += f'<path style="fill:none;stroke:{STROKE_COLOR};'
|
|
|
|
data += f'stroke-width:{STROKE_WIDTH}" '
|
|
|
|
data += f'd="M {start_x},{start_y} {direction} {length}" />'
|
|
|
|
return data
|
|
|
|
|
2021-12-25 07:53:24 +01:00
|
|
|
def draw_full_rect(x, y, width, height):
|
|
|
|
data = ""
|
|
|
|
data += f'<rect style="fill:{STROKE_COLOR}" '
|
|
|
|
data += f'width="{width}" height="{height}" x="{x}" y="{y}" '
|
|
|
|
data += '/>'
|
|
|
|
return data
|
|
|
|
|
2021-12-25 07:11:27 +01:00
|
|
|
def draw_horizontal_lines(data, n_rows, width):
|
|
|
|
row = 1
|
|
|
|
while row < n_rows:
|
|
|
|
data += draw_line(True, 0, row * WORKSPACE_HEIGHT, width)
|
|
|
|
row += 1
|
|
|
|
return data
|
|
|
|
|
|
|
|
def draw_vertical_lines(data, n_cols, height):
|
|
|
|
col = 1
|
|
|
|
while col < n_cols:
|
|
|
|
data += draw_line(False, col * WORKSPACE_WIDTH, 0, height)
|
|
|
|
col += 1
|
|
|
|
return data
|
|
|
|
|
2021-12-25 07:54:04 +01:00
|
|
|
def draw_active_space(data, n_cols, index):
|
2021-12-25 07:53:24 +01:00
|
|
|
active_row = index // n_cols
|
|
|
|
active_col = index % n_cols
|
|
|
|
x = active_col * WORKSPACE_WIDTH + STROKE_WIDTH / 2
|
|
|
|
y = active_row * WORKSPACE_HEIGHT + STROKE_WIDTH / 2
|
|
|
|
width = WORKSPACE_WIDTH - STROKE_WIDTH
|
|
|
|
height = WORKSPACE_HEIGHT - STROKE_WIDTH
|
|
|
|
data += draw_full_rect(x, y, width, height)
|
|
|
|
return data
|
|
|
|
|
2021-12-25 02:15:42 +01:00
|
|
|
def generate_icons(n_rows, n_cols):
|
2021-12-25 07:53:24 +01:00
|
|
|
for i in range(n_rows * n_cols):
|
|
|
|
filename = f"{ICON_NAME_PREFIX}_{n_rows}x{n_cols}_{i + 1}.svg"
|
2021-12-25 02:15:42 +01:00
|
|
|
width = n_cols * WORKSPACE_WIDTH
|
|
|
|
height = n_rows * WORKSPACE_HEIGHT
|
|
|
|
data = TEMPLATE
|
2021-12-25 02:20:55 +01:00
|
|
|
data = define_globals(data, width, height)
|
|
|
|
data = draw_outer_rectangle(data, width, height)
|
2021-12-25 07:11:27 +01:00
|
|
|
data = draw_horizontal_lines(data, n_rows, width)
|
|
|
|
data = draw_vertical_lines(data, n_cols, height)
|
2021-12-25 07:54:04 +01:00
|
|
|
data = draw_active_space(data, n_cols, i)
|
2021-12-25 02:15:42 +01:00
|
|
|
data += "</svg>"
|
|
|
|
with open(filename, "w") as f:
|
|
|
|
f.write(data)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
for N_ROWS in range(MAX_ROWS + 1):
|
|
|
|
for N_COLS in range(MAX_COLS + 1):
|
|
|
|
generate_icons(N_ROWS, N_COLS)
|