MCPcopy Create free account
hub / github.com/Proxlight/Proxlight-Designer / generate_code

Function generate_code

backend.py:5–295  ·  view source on GitHub ↗
(token, link, output_path)

Source from the content-addressed store, hash-verified

3from tkinter import messagebox
4
5def generate_code(token, link, output_path):
6
7 def get_color(element):
8 # Returns HEX form of element RGB color (str)
9 el_r = element["fills"][0]["color"]['r'] * 255
10 el_g = element["fills"][0]["color"]['g'] * 255
11 el_b = element["fills"][0]["color"]['b'] * 255
12
13 hex_code = ('#%02x%02x%02x' % (round(el_r), round(el_g), round(el_b)))
14
15 return hex_code
16
17
18 def get_coordinates(element):
19 # Returns element coordinates as x (int) and y (int)
20 x = int(element["absoluteBoundingBox"]["x"])
21 y = int(element["absoluteBoundingBox"]["y"])
22
23 return x, y
24
25
26 def get_dimensions(element):
27 # Return element dimensions as width (int) and height (int)
28 height = int(element["absoluteBoundingBox"]["height"])
29 width = int(element["absoluteBoundingBox"]["width"])
30
31 return width, height
32
33
34 def get_text_properties(element):
35 # Return element font and fontSize (str)
36 font = element["style"]["fontPostScriptName"]
37 fontSize = element["style"]["fontSize"]
38
39 return font, fontSize
40
41
42 global fig_window, response
43
44 generated_dir = output_path + "/generated_code/"
45
46 lines = []
47 lines.extend(['from tkinter import *\n\n',
48 'def btn_clicked():',
49 ' print("Button Clicked")\n\n\n'
50 'window = Tk()'])
51
52
53 # Getting File Data
54
55 def find_between(s, first, last):
56 try:
57 start = s.index(first) + len(first)
58 end = s.index(last, start)
59
60 return s[start:end]
61
62 except ValueError:

Callers

nothing calls this directly

Calls 5

find_betweenFunction · 0.85
get_dimensionsFunction · 0.85
get_colorFunction · 0.85
get_coordinatesFunction · 0.85
get_text_propertiesFunction · 0.85

Tested by

no test coverage detected