", string)
## find all occurances of '->' and replace this with an arrow.
regex = re.compile(r"->", re.X)
string = regex.sub(r"→", string)
## find all occurances of strings between t^..^t. These are the headers for tip of the day.
regex = re.compile(r"t \^ (.*?) \^ t", re.X)
string = regex.sub(r"\1 ", string)
## find all occurances of strings between <<..>>. These are keys to pressthe headers for tip of the day.
regex = re.compile(r"<< (.*?) >>", re.X)
string = regex.sub(r"\1", string)
## find all occurances of strings between n^..^n. These are the notes.
regex = re.compile(r"n \^ (.*?) \^ n", re.X)
string = regex.sub(r"", string)
## find all occurances of strings between l[]. These are links to help or tutorial popup boxes.
regex = re.compile(r"l\[\s*(?P.*?)\s*,\s*(?P.*?)\s*\,\s*(?P.*?)\s*\]", re.X)
string = regex.sub(r"»\g", string)
## find all occurances of strings between gui[]. These are links make something happen on the GUI.
regex = re.compile(r"gui\[\s*(?P.*?)\s*,\s*(?P.*?)\s*\,\s*(?P.*?)\s*\]", re.X)
string = regex.sub(r"»\g", string)
## find all occurances of strings between XX. These are command line entities.
width = int(OV.GetHtmlPanelwidth()) - 10
regex = re.compile(r" XX (.*?)( [^\XX\XX]* ) XX ", re.X)
m = regex.findall(string)
code_bg_colour = OV.GetParam('gui.html.code.bg_colour').hexadecimal
code_fg_colour = OV.GetParam('gui.html.code.fg_colour').hexadecimal
html_tag = OV.GetParam('gui.html.code.html_tag')
if m:
s = regex.sub(r"" %(width,code_bg_colour, code_fg_colour, html_tag, html_tag), string)
else:
s = string
string = s
## find all occurances of strings between ~. These are the entries for the table.
regex = re.compile(r" ~ (.*?)( [^\~\~]* ) ~ ", re.X)
m = regex.findall(string)
colour = OV.FindValue('gui_html_highlight_colour')
if m:
s = regex.sub(r"| \2 " %colour, string)
else:
s = string
## find all occurances of strings between@. These are the table headers.
string = s
regex = re.compile(r" @ (.*?)( [^\@\@]* ) @ ", re.X)
m = regex.findall(string)
colour = "#232323"
if m:
s = regex.sub(r" | | \2 | ", string)
else:
s = string
## find all occurances of strings between &. These are the tables.
string = s
#regex = re.compile(r" (&&) (.*?)( [^\&\&]* ) (&&) ", re.X)
regex = re.compile(r" (&&) (.*?) (&&) ", re.X)
#regex = re.compile(r" & (.*?)( [^\&\&]* ) & ", re.X)
m = regex.findall(string)
if m:
s = regex.sub(r"", string)
else:
s = string
return s, d
def reg_command(self, string):
regex = re.compile(r" ~ (.*?)( [^\~\~]* ) ~ ", re.X)
m = regex.findall(string)
colour = OV.FindValue('gui_html_highlight_colour')
if m:
s = regex.sub(r'''
\2
''' %colour, string)
else:
s = string
return s
def changeBoxColour(ctrl_name,colour):
if olx.GetValue(ctrl_name) in ('?',''):
olx.html_SetBG(ctrl_name,colour)
else:
olx.html_SetBG(ctrl_name,OV.FindValue('gui_html_input_bg_colour'))
return ''
OV.registerFunction(changeBoxColour)
def switchButton(name,state):
if state == 'off':
copy_from = "%soff.png" %name
copy_to = "%s.png" %name
OV.CopyVFSFile(copy_from, copy_to)
else:
copy_from = "%son.png" %name
copy_to = "%s.png" %name
OV.CopyVFSFile(copy_from, copy_to)
OV.htmlReload()
return ""
OV.registerFunction(switchButton)
def bgcolor(ctrl_name):
value = olx.GetValue(ctrl_name)
if value in ('?',''):
colour = 'rgb(255,220,220)'
else:
colour = OV.FindValue('gui_html_input_bg_colour')
return colour
OV.registerFunction(bgcolor)
def getStyles(fileName):
cssPath = '%s/etc/CIF/styles/%s.css' %(OV.BaseDir(),fileName)
if not os.path.exists(cssPath): return ''
css = open(cssPath,'r').read()
styleHTML = """
""" %css
return styleHTML
OV.registerFunction(getStyles)
def getStylesList():
styles = os.listdir("%s/etc/CIF/styles" %OV.BaseDir())
exclude = ("rsc.css", "thesis.css", "custom.css")
stylesList = ";".join(style[:-4] for style in styles
if style not in exclude and style.endswith('.css'))
return 'default;' + stylesList
OV.registerFunction(getStylesList)
def getTemplatesList():
templates = os.listdir("%s/etc/CIF/styles" %OV.BaseDir())
exclude = ("footer.htm")
templatesList = ";".join(template[:-4] for template in templates
if template not in exclude and template.endswith('.htm'))
return templatesList
OV.registerFunction(getTemplatesList)
def getPopBoxPosition():
ws = olx.GetWindowSize('html')
ws = ws.split(",")
WS = olx.GetWindowSize('main-cs', ws[0], int(ws[3]))
WS = WS.split(",")
sX = int(WS[0])
sY = int(WS[1]) -2
sTop = int(ws[1])
return (sX, sY, sTop)
def get_template(name):
template = r"%s/etc/gui/blocks/templates/%s.htm" %(olx.BaseDir(),name)
if os.path.exists(template):
rFile = open(template, 'r')
str = rFile.read()
return str
else:
return None
def makeHtmlBottomPop(args, pb_height = 50, y = 0, panel_diff = 22):
txt = args.get('txt',None)
name = args.get('name',"test")
replace_str = args.get('replace',None)
import OlexVFS
from ImageTools import ImageTools
IM = ImageTools()
metric = getPopBoxPosition()
if not txt:
txt = get_template(name)
txt = txt.replace(r"",replace_str.upper())
pop_html = name
pop_name = name
htm_location = "%s.htm" %pop_html
OlexVFS.write_to_olex(htm_location,txt)
width = int(IM.gui_htmlpanelwidth) - panel_diff
x = metric[0] + 10
if not y:
y = metric[1] - pb_height - 8
pstr = "popup %s '%s' -t='%s' -w=%s -h=%s -x=%s -y=%s" %(pop_name, htm_location, pop_name, width, pb_height, x, y)
OV.cmd(pstr)
olx.html_SetBorders(pop_name,0)
OV.cmd(pstr)
olx.html_SetBorders(pop_name,0)
olx.html_Reload(pop_name)
OV.registerMacro(makeHtmlBottomPop, 'txt-Text to display&;name-Name of the Bottom html popupbox')
def OnModeChange(*args):
global active_mode
global last_mode
debug = OV.GetParam("olex2.debug")
d = {
'move sel':'button-move_near',
'move sel -c=':'button-copy_near',
'grow':'button-grow_mode',
'split -r=EADP':'button_full-move_atoms_or_model_disorder',
'split':'button_full-move_atoms_or_model_disorder',
'name':'button_small-name',
'fixu':'button-fix_u',
'fixxyz':'button-fix_xyz',
'occu':'button-set_occu',
'off':None
}
name = 'mode'
mode = ""
i = 0
mode_disp = ""
args = args[0].split()
modes_with_other_stuff_l = ["grow", "name"]
for item in args:
for m in modes_with_other_stuff_l:
if m in item:
item = m
i += 1
mode = mode + " " + item
if i < 2:
mode_disp += " " + item
mode = mode.strip()
mode_disp = mode_disp.strip()
if 'name' in mode:
active_mode = 'button_small-name'
elif 'grow' in mode:
active_mode = 'button-grow_mode'
else:
active_mode = d.get(mode, None)
# mode_disp = "%s" %mode
if last_mode == active_mode:
return
if not active_mode:
active_mode = d.get(mode_disp, None)
if mode == 'off':
OV.SetParam('olex2.in_mode',None)
OV.cmd("html.hide pop_%s" %name)
if not last_mode: return
use_image = "%soff.png" %last_mode
control = "IMG_%s" %last_mode.upper()
if OV.IsControl(control):
OV.SetImage(control,use_image)
copy_to = "%s.png" %last_mode
OV.CopyVFSFile(use_image, copy_to,2)
OV.cmd("html.hide pop_%s" %name)
last_mode = None
OV.SetParam('olex2.in_mode',None)
OV.SetParam('olex2.short_mode',None)
else:
OV.SetParam('olex2.in_mode',mode.split("=")[0])
makeHtmlBottomPop({'replace':mode_disp, 'name':'pop_mode'}, pb_height=50)
if active_mode:
use_image= "%son.png" %active_mode
control = "IMG_%s" %active_mode.upper()
if OV.IsControl(control):
OV.SetImage(control,use_image)
copy_to = "%s.png" %active_mode
OV.CopyVFSFile(use_image, copy_to,1)
if last_mode:
use_image = "%soff.png" %last_mode
control = "IMG_%s" %last_mode.upper()
if OV.IsControl(control):
OV.SetImage(control,use_image)
copy_to = "%s.png" %last_mode
OV.CopyVFSFile(use_image, copy_to,2)
last_mode = active_mode
OV.SetParam('olex2.in_mode',mode.split("=")[0])
OV.SetParam('olex2.short_mode',mode_disp)
last_mode = active_mode
## if active_mode == last_mode:
## active_mode = None
## Deal with button images
#if not active_mode:
#if not last_mode: return
#use_image = "%soff.png" %last_mode
#OV.SetImage("IMG_%s" %last_mode.upper(),use_image)
#copy_to = "%s.png" %last_mode
#OV.CopyVFSFile(use_image, copy_to,2)
#OV.cmd("html.hide pop_%s" %name)
#last_mode = None
#else:
#if last_mode:
#use_image = "%soff.png" %last_mode
#OV.SetImage("IMG_%s" %last_mode.upper(),use_image)
#copy_to = "%s.png" %last_mode
#OV.CopyVFSFile(use_image, copy_to,2)
#if active_mode == last_mode:
#last_mode = None
#active_mode = None
#OV.SetVar('olex2_in_mode','False')
#OV.cmd("html.hide pop_%s" %name)
#if active_mode:
#use_image= "%son.png" %active_mode
#OV.SetImage("IMG_%s" %active_mode.upper(),use_image)
#copy_to = "%s.png" %active_mode
#OV.CopyVFSFile(use_image, copy_to,1)
#last_mode = active_mode
#OV.SetVar('olex2_in_mode',mode.split("=")[0])
OV.registerCallback('modechange',OnModeChange)
def OnStateChange(*args):
name = args[0]
state = args[1]
d = {
'basisvis':'button-show_basis',
'cellvis':'button-show_cell',
'htmlttvis':'button-tooltips',
'helpvis':'button-help',
}
img_base = d.get(name)
if not img_base:
return False
state = olx.CheckState(name)
if state == "true":
use_image= "%son.png" %img_base
else:
use_image = "%soff.png" %img_base
OV.SetImage("IMG_%s" %img_base.upper(),use_image)
copy_to = "%s.png" %img_base
OV.CopyVFSFile(use_image, copy_to,2)
return True
OV.registerCallback('statechange',OnStateChange)
def MakeActiveGuiButton(name,cmds,toolname=""):
n = name.split("-")
d = {}
d.setdefault('bt', n[0])
d.setdefault('bn', n[1])
d.setdefault('BT', n[0].upper())
d.setdefault('BN', n[1].upper())
d.setdefault('cmds', cmds.replace("\(","("))
d.setdefault('target', OV.TranslatePhrase("%s-target" %n[1]))
d.setdefault('toolname', toolname)
txt = '''
'''%d
return txt
OV.registerFunction(MakeActiveGuiButton)
def InActionButton(name,state,toolname=""):
if state == "on":
use_image= "%son.png" %name
OV.SetImage("IMG_%s%s" %(name.upper().lstrip(".PNG"),toolname),use_image)
if state == "off":
use_image= "%soff.png" %name
OV.SetImage("IMG_%s%s" %(name.upper().lstrip(".PNG"),toolname), use_image)
return True
OV.registerFunction(InActionButton)
def PopProgram(txt="Fred"):
name = "pop_prg_analysis"
makeHtmlBottomPop({'txt':txt, 'name':name}, pb_height=225)
def PopBanner(txt=''):
name = "pop_banner"
makeHtmlBottomPop({'txt':txt, 'name':name}, pb_height=65, y = 130,panel_diff=22)
OV.registerFunction(PopBanner)
def doBanner(i):
i = int(i)
#olx.html_SetImage("BANNER_IMAGE","banner_%i.png" %i)
OV.CopyVFSFile("banner_%i.png" %i, "banner.png")
OV.CopyVFSFile("banner_%i.htm" %i, "banner.htm")
offset = 10
target = 2
ist = ""
cmds = []
ist += "aio-* 0 "
d = olx.banner_slide.get(i,0)
if not d:
i = i + 1
d = olx.banner_slide.get(i,0)
if not d:
i = i -2
d = olx.banner_slide.get(i,0)
if not d:
# print i, "Nothing"
return
# print i, d.get('name')
OV.SetParam('snum.refinement.banner_slide', i)
ist += d.get('itemstate',0)
cmds += d.get('cmd',"").split(">>")
OV.setItemstate(ist)
for cmd in cmds:
OV.cmd(cmd)
OV.registerFunction(doBanner)
def getTip(number=0): ##if number = 0: get random tip, if number = "+1" get next tip, otherwise get the named tip
from random import randint
global current_tooltip_number
max_i = 20
if number == '0':
txt = "tip-0"
j = 0
while "tip-" in txt:
j += 1
i = randint (1,max_i)
if i == current_tooltip_number: continue
txt = OV.TranslatePhrase("tip-%i" %i)
if j > max_i * 2: break
txt += '''
|
%s''' %make_edit_link("tip", "%i" %i)
elif number == "+1":
i = current_tooltip_number + 1
txt = OV.TranslatePhrase("tip-%i" %i)
if "tip-" in txt:
i = 1
txt = OV.TranslatePhrase("tip-%i" %i)
txt += '''
|
%s''' %make_edit_link("tip", "%i" %i)
elif number == "list":
txt = ""
for i in xrange(max_i):
if i == 0: continue
t = OV.TranslatePhrase("tip-%i" %i)
if "tip-" in t:
break
t = t.split("^t")[0]
t += "^t"
t = t.strip()
txt += '''