def createSidebar(self, num_of_buttons): sidebar = Element("sidebar", "") for _ in range(num_of_buttons): sidebar.addChildren( Element("sidebar-element", self.createRandomMenuItemText())) return sidebar
def createMenu(self, logo_left, num_of_buttons): menu = Element("header", "") logo = None if logo_left: logo = Element("logo-left", "") else: logo = Element("logo-right", "") menu.addChildren(logo) for _ in range(num_of_buttons): menu.addChildren( Element("btn-inactive-white", self.createRandomMenuItemText())) return menu
def createRow(self, row_type): if not row_type in [0, 1, 2, 3, 4, 5]: print("wrong row type given", row_type) raise types = { 0: ["single"], 1: ["double", "double"], 2: ["double", "quadruple", "quadruple"], 3: ["quadruple", "double", "quadruple"], 4: ["quadruple", "quadruple", "double"], 5: ["quadruple", "quadruple", "quadruple", "quadruple"] } row = Element("row", "") for element in types[row_type]: row.addChildren(self.createRowElement(element)) return row
def createRandomFile(): with open("assets/dsl-mapping.json") as data_file: dsl_mapping = json.load(data_file) root = Element("body", "") menue_or_sidebar = random.choice([True, False]) if menue_or_sidebar: logo_left = random.choice([True, False]) num_of_menue_buttons = random.randint(1, 4) menu = tokenBuilder.createMenu(logo_left, num_of_menue_buttons) root.addChildren(menu) else: sidebar = tokenBuilder.createSidebar(4) root.addChildren(sidebar) num_of_rows = random.randint(1, 3) for i in range(num_of_rows): row_type = random.randint(0, 4) row = tokenBuilder.createRow(row_type) print("adding row", i, "of total", num_of_rows) root.addChildren(row) filename = "random_generation" + "_" + time.strftime("%d.%m.%Y-%H:%M:%S") file_html = open("markup/" + filename + ".html", "w+") file_token = open("token/" + filename + ".gui", "w+") token_sequence = root.toString2() file_token.write(token_sequence) html = root.render(dsl_mapping) file_html.write(html) return filename
def createAllPossibilities(): menu_or_sidebar = [True, False] logo_left_or_right = [True, False] possible_num_of_menu_button = [1, 2, 3, 4] possible_num_of_rows = [1, 2, 3] possible_row_type = [0, 1, 2, 3, 4, 5] row_count_layout_combinations = [] for i in possible_num_of_rows: row_count_layout_combinations.extend( list(itertools.product(possible_row_type, repeat=i))) for i in range(len(row_count_layout_combinations)): row_count_layout_combinations[i] = list( row_count_layout_combinations[i]) complete_layouts = [] for menu_flag in menu_or_sidebar: for logo_flag in logo_left_or_right: for num_of_menue_button in possible_num_of_menu_button: for row_count_layout in row_count_layout_combinations: if not menu_flag and not logo_flag: pass else: root = Element("body", "") if menu_flag: menu = tokenBuilder.createMenu( logo_flag, num_of_menue_button) root.addChildren(menu) else: sidebar = tokenBuilder.createSidebar( num_of_menue_button) root.addChildren(sidebar) for i in range(len(row_count_layout)): row = tokenBuilder.createRow(row_count_layout[i]) root.addChildren(row) complete_layouts.append(root) print("Created", len(complete_layouts), "different layouts.") return complete_layouts
def createNewContentElement(tag_name): content = "" if tag_name in ["single", "double", "quadruple"]: content = "" elif tag_name in ["text"]: content = tokenBuilder.createRandomShortParagraphText() elif tag_name in [ "sidebar-element", "btn-inactive-blue", "btn-inactive-black", "btn-inactive-grey", "btn-inactive-white" ]: content = tokenBuilder.createRandomMenuItemText() elif tag_name in ["small-title"]: content = tokenBuilder.createRandomHeadlineText() return Element(tag_name, content)
def createElementsFromTokenList(token_list): token_list.reverse() root = Element(token_list.pop(), "") parentStack = [] lastElement = root while len(token_list) > 0: if token_list[-1] == "{": parentStack.append(lastElement) token_list.pop() elif token_list[-1] == "}": parentStack.pop() token_list.pop() else: new_element = createNewContentElement(token_list.pop()) parentStack[-1].addChildren(new_element) lastElement = new_element return root
def createRowElement(self, width): if not width in ["single", "double", "quadruple"]: print("wrong width given", width) raise grid_element = Element(width, "") headline = Element("small-title", self.createRandomHeadlineText()) if width == "quadruple": text = Element("text", self.createRandomShortParagraphText()) else: text = Element("text", self.createRandomParagraphText()) button_type = random.choice( ["btn-inactive-blue", "btn-inactive-black", "btn-inactive-grey"]) button = Element(button_type, self.createRandomMenuItemText()) grid_element.addChildren(headline) grid_element.addChildren(text) grid_element.addChildren(button) return grid_element