Skip to content

Commit

Permalink
Update QuykHtml.py
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
mwd1993 committed Dec 31, 2020
1 parent 54a7e9d commit 4dab427
Showing 1 changed file with 17 additions and 42 deletions.
59 changes: 17 additions & 42 deletions QuykHtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 33,18 @@ def __init__(self):
# Returns a new object of an html element
# returns: Object

def new(self, _type, _p=0):
def new(self, _type):
_split = _type.split(" ")
_obj = ""
if len(_split) > 1:
_first = _split[0]
_second = _split[1]

if "button" in _first or "input" in _first:
if _second == "br":
_container = self.new_obj("div")
_br = self.new_obj("br")
if _p != 0:
_obj = self.new_obj(_first, _p)
_container.insert([_obj, _br])
else:
_obj = self.new_obj(_first)
_container.insert([_obj, _br])

_container = self._q_element("div")
_br = self._q_element("br")
_obj = self._q_element(_first)
_container.insert([_obj, _br])
_obj.parent = self
self.last = _obj
self.all.append(_container)
Expand All @@ -62,19 56,17 @@ def new(self, _type, _p=0):
else:
return False
else:
if _p != 0:
# create special
_obj = self.new_obj(_type, _p)
else:
_obj = self.new_obj(_type)

_obj = self._q_element(_type)
_obj.parent = self
self.all.append(_obj)
self.last = _obj
return _obj

# Duplicates an element
# returns: new duped element

def dupe(self, qhtml_obj):
if isinstance(qhtml_obj, self.new_obj):
if isinstance(qhtml_obj, self._q_element):
new = copy.copy(qhtml_obj)
self.all.append(new)
return new
Expand All @@ -96,14 88,11 @@ def render(self, output_file="render.html", only_html=False, set_clip_board=Fals
_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
_preview_scripts_loaded = False
for _obj_element in self.all:
# print("ajax code for " str(_obj_element.type))

if _obj_element.has_preview() and _preview_scripts_loaded is False:
self.__get_preview_scripts()
_preview_scripts_loaded = True

if _obj_element.ajax_code != "":
# print("render ajax code detected")
self.scripts.append(_obj_element.ajax_code)

if len(_obj_element.scripts_on_page_load) > 0:
Expand All @@ -129,7 118,6 @@ def render(self, output_file="render.html", only_html=False, set_clip_board=Fals
for h in self.head:
_head_append = h "\n"

print("inserting " str(self.preview))
self.display.insert(self.preview)
_scripts_on_page_load = ' window.addEventListener("load", on_page_load_init); function on_page_load_init() {' _scripts_on_page_load '}'
html_string = "<head>" _bootstrap "<style>" _css '</style><script type="text/javascript">' _scripts '' _scripts_on_page_load '</script>' _head_append '</head>' str(
Expand All @@ -138,10 126,8 @@ def render(self, output_file="render.html", only_html=False, set_clip_board=Fals
f = open(os.getcwd() "/" output_file, "w")
f.write(html_string)
f.close()

# print(html_string)

sleep(0.2)

if not only_html:
webbrowser.get(_path).open(str(os.getcwd()) "/" output_file)

Expand All @@ -152,12 138,10 @@ def render(self, output_file="render.html", only_html=False, set_clip_board=Fals

def clip_put(self, _str):
s = self
# Check which operating system is running to get the correct copying keyword.
if platform.system() == 'Darwin':
copy_keyword = 'pbcopy'
elif platform.system() == 'Windows':
copy_keyword = 'clip'

subprocess.run(copy_keyword, universal_newlines=True, input=_str)

def file_read(self, file_name, file_path=''):
Expand All @@ -170,9 154,7 @@ def file_read(self, file_name, file_path=''):
f = open(dir_path file_name, 'r')
read = f.read()
f.close()

return read

return False

def __get_preview_scripts(self):
Expand Down Expand Up @@ -252,7 234,6 @@ def __init__(self):
# returns: class object/itself

def add(self, name: str or list, style=""):

if style == "":
if type(name) is list:
for li in name:
Expand All @@ -279,7 260,6 @@ def export(self, _file):
_b = ""
for s in self.styles:
_b = _b "" s "\n"
print("b = " _b)
f.write(_b)
f.close()

Expand Down Expand Up @@ -338,9 318,9 @@ def hextorgb(self, _hex):
_hex = _hex.lstrip('#')
return tuple(int(_hex[i:i 2], 16) for i in (0, 2, 4))

# CLASS new_obj, an element object type
# CLASS _q_element, an element object type

class new_obj:
class _q_element:

# INITIALIZE CLASS

Expand Down Expand Up @@ -470,7 450,6 @@ def get_tag_open(self):
second = ' style="' self.style.get() '">'
else:
second = ">"
# return "<" self.type " " self.get_attributes() ' style="' self.style.get() '">'
return first second

# Gets the closing tag of an object as a string
Expand All @@ -479,6 458,9 @@ def get_tag_open(self):
def get_tag_close(self):
return "</" self.type ">"

# Sets a code block to display code
# returns: self

def set_text_code_block(self, _str, text_color=False, parentheses_color=False, main_text_color=False, background_color=False):

if self.type != 'pre':
Expand Down Expand Up @@ -907,7 889,6 @@ def __init__(self, rows_or_file_path, columns_or_styling_dict=-1):
else:
_styling_value = []


for __call in _calls:
# print("call - > " str(__call))
# call method
Expand All @@ -923,7 904,6 @@ def __init__(self, rows_or_file_path, columns_or_styling_dict=-1):
_table.insert_at(_curr_row, _curr_col, _p)

_curr_col = -1
# print(_table.__dict__)
self.get = _table

else:
Expand All @@ -941,7 921,6 @@ def __init__(self, rows_or_file_path, columns_or_styling_dict=-1):

def insert_at(self, row, column, obj):
_s = self

if type(obj) is list:
for li in obj:
li.table_inserted_at = [str(row), str(column)]
Expand Down Expand Up @@ -980,8 959,6 @@ def set_td_class_at(self, row, col, _class):

def style_td_at(self, row, col, style):
_s = self
# print("\nSTYLING AT " str(row) " - " str(col) '\n')
# _s.td_styles
_s.td_styles.append({
"style": style,
"row": row,
Expand All @@ -1000,7 977,7 @@ def build(self, append_html=False):
return div

def __build_into(self, _obj: object, append_html=False):
if not isinstance(_obj, qhtml.new_obj):
if not isinstance(_obj, qhtml._q_element):
print("BUILD " str(self) " - obj = " str(_obj) " - " str(type(_obj)))
print("Error building table -> table.build(_qhtml_object_element) -> argument should be a qhtml.new(type) object.")
return False
Expand All @@ -1011,7 988,6 @@ def __build_into(self, _obj: object, append_html=False):
def __build_html(self):
row_index = -1
column_index = -1

html_table_open = '<table style="border-collapse: collapse;table-layout: fixed;width:100%;"><tbody ' \
'style="width:100%;"> '
html_table_close = "</tbody></table>"
Expand Down Expand Up @@ -1086,7 1062,6 @@ def __build_html(self):
column_index = -1

if not html_mid_build == "":
# print(html_table_open html_mid_build html_table_close)
self.time = int(round(time.time() * 1000)) - self.time_start
print("\n** Table built in " str(self.time) " MS with " str(self.columns) " columns and " str(self.rows) " rows ** \n")
return html_table_open html_mid_build html_table_close
Expand Down

0 comments on commit 4dab427

Please sign in to comment.