Commit 6c25bda2 by Alexander Kryklia

added style and removed width

parent dc42f181
...@@ -69,9 +69,19 @@ class GraphicalSliderToolModule(XModule): ...@@ -69,9 +69,19 @@ class GraphicalSliderToolModule(XModule):
Simple variant: slider and plot controls are not inside any tag. Simple variant: slider and plot controls are not inside any tag.
""" """
#substitute plot #substitute plot
plot_div = '<div class="' + self.html_class + '_plot" id="' + self.html_id + '_plot"></div>' plot_div = '<div class="{element_class}__plot" id="{element_id}_plot \
html_string = re.sub(r'\$[^\$]*plot[^\$]*\$', style="{style}"></div>'
plot_div, html_string, flags=re.IGNORECASE | re.UNICODE) # extract css style from plot
plot_def = re.findall(r'\$\s+plot[^\$]*\$', html_string)
style = re.search(r'(?=.*width\=[\"\'](.*)[\"\'])', plot_def)
if style:
style = style.groups()[0]
else: # no style parameter
style = ''
replacement = plot_div.format(element_class=self.html_class,
style=style)
html_string = re.sub(r'\$\s+plot[^\$]*\$', replacement, html_string,
flags=re.IGNORECASE | re.UNICODE)
# get variables # get variables
if json.loads(self.configuration_json)['root'].get('parameters'): if json.loads(self.configuration_json)['root'].get('parameters'):
...@@ -85,62 +95,70 @@ class GraphicalSliderToolModule(XModule): ...@@ -85,62 +95,70 @@ class GraphicalSliderToolModule(XModule):
#substitute sliders #substitute sliders
slider_div = '<div class="{element_class}_slider" \ slider_div = '<div class="{element_class}_slider" \
id="{element_id}_slider_{var}" \ id="{element_id}_slider_{var}" \
data-var="{var}" data-el_width="{width}">\ data-var="{var}" data-el_style="{style}">\
</div>' </div>'
for var in variables: for var in variables:
# find $slider var='var' ... $ # find $slider var='var' ... $
instances = re.findall(r'\$slider\s+(?=.*var\=[\"\']' + var + '[\"\'])' \ instances = re.findall(r'\$\s+slider\s+(?=.*var\=[\"\']' + var + '[\"\'])' \
+ r'[^\$]*\$', html_string) + r'[^\$]*\$', html_string)
if instances: # if presented if instances: # if presented, only one slider per var
slider_def = instances[0] # get $slider var='var' ... $ string slider_def = instances[0] # get $slider var='var' ... $ string
# get width # extract var for proper style extraction further
width = re.search(r'(?=.*width\=[\"\'](\d+)[\"\'])', slider_def) var_substring = re.search(r'(var\=[\"\']' + var + r'[\"\'])',
if width: slider_def)
width = width.groups()[0] slider_def = slider_def.replace(var_substring, '')
else: # no width parameter # get style
width = '' style = re.search(r'(?=.*style\=[\"\'](.*)[\"\'])', slider_def)
# substitue parameters to slider div if style:
style = style.groups()[0]
else: # no style parameter
style = ''
# substitute parameters to slider div
replacement = slider_div.format(element_class=self.html_class, replacement = slider_div.format(element_class=self.html_class,
element_id=self.html_id, element_id=self.html_id,
var=var, var=var, style=style)
width=width)
# subsitute $slider var='var' ... $ in html_srting to proper # subsitute $slider var='var' ... $ in html_srting to proper
# html div element # html div element
html_string = re.sub(r'\$slider\s+(?=.*var\=[\"\'](' + \ html_string = re.sub(r'\$\s+slider\s+(?=.*var\=[\"\'](' + \
var + ')[\"\'])' + r'[^\$]*\$', var + ')[\"\'])' + r'[^\$]*\$',
replacement, html_string, flags=re.IGNORECASE | re.UNICODE) replacement, html_string, flags=re.IGNORECASE | re.UNICODE)
# substitute inputs if we have them # substitute inputs if we have them
input_el = '<input class="{element_class}_input" \ input_el = '<input class="{element_class}_input" \
id="{element_id}_input_{var}" \ id="{element_id}_input_{var}" \
data-var="{var}" data-el_width="{width}" \ data-var="{var}" data-el_style="{style}" \
data-el_readonly="{readonly}"> \ data-el_readonly="{readonly}"> \
</input>' </input>'
input_index = 0 # make multiple inputs for same variable have input_index = 0 # make multiple inputs for same variable have
# different id # different id
for var in variables: # multiple inputs test for var in variables:
input_index = +1 input_index = +1
instances = re.findall(r'\$input\s+(?=.*var\=[\"\']' + var + '[\"\'])' \ instances = re.findall(r'\$\s+input\s+(?=.*var\=[\"\']' + var + '[\"\'])' \
+ r'[^\$]*\$', html_string) + r'[^\$]*\$', html_string)
# import ipdb; ipdb.set_trace() # import ipdb; ipdb.set_trace()
for input_def in instances: for input_def in instances: # for multiple inputs per var
width = re.search(r'(?=.*width\=[\"\'](\d+)[\"\'])', input_def) # extract var and readonly before style!
if width: var_substring = re.search(r'(var\=[\"\']' + var + r'[\"\'])',
width = width.groups()[0] input_def)
else: input_def = input_def.replace(var_substring, '')
width = '' readonly = re.search(r'(?=.*(readonly\=[\"\'](\w+)[\"\']))', input_def)
readonly = re.search(r'(?=.*readonly\=[\"\'](\w+)[\"\'])', input_def)
if readonly: if readonly:
readonly = readonly.groups()[0] readonly = readonly.groups()[1]
input_def = input_def.replace(readonly.groups()[0], '')
else: else:
readonly = '' readonly = ''
style = re.search(r'(?=.*style\=[\"\'](.*)[\"\'])', input_def)
if style:
style = style.groups()[0]
else:
style = ''
replacement = input_el.format(element_class=self.html_class, replacement = input_el.format(element_class=self.html_class,
element_id=self.html_id + '_' + str(input_index), element_id=self.html_id + '_' + str(input_index),
var=var, width=width, readonly=readonly) var=var, readonly=readonly, style=style)
html_string = re.sub(r'\$input\s+(?=.*var\=[\"\'](' + \ html_string = re.sub(r'\$\s+input\s+(?=.*var\=[\"\'](' + \
var + ')[\"\'])' + r'[^\$]*\$', var + ')[\"\'])' + r'[^\$]*\$',
replacement, html_string, flags=re.IGNORECASE | re.UNICODE) replacement, html_string, flags=re.IGNORECASE | re.UNICODE)
return html_string return html_string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment