import olx
import sys
import os
sys.path.append(r".\src")
import userDictionaries
# This used to be in in init.py. Why?
from olexFunctions import OV
import htmlTools
import olexex_setup
import variableFunctions
import olex
from gui.images import GI
gui_green = OV.GetParam('gui.green')
gui_orange = OV.GetParam('gui.orange')
gui_red = OV.GetParam('gui.red')
class GeneratedGuiMaker(object):
def __init__(self):
# Define buttons, actions and hints: UP, DOWN, EDIT and DELETE
number = "%s"
onclick = "spy.move(up,SET_SNUM_METACIF_PUBL_AUTHOR_NAMES_%s)>>html.update" % number
hint = "Move author up"
self.up = GI.get_action_button_html('up', onclick, hint)
onclick = "spy.move(down,SET_SNUM_METACIF_PUBL_AUTHOR_NAMES_%s)>>html.update" % number
hint = "Move author down"
self.down = GI.get_action_button_html('down', onclick, hint)
onclick = "spy.move(del,SET_SNUM_METACIF_PUBL_AUTHOR_NAMES_%s)>>html.Update" % number
hint = "Remove author from paper"
self.delete = GI.get_action_button_html('delete', onclick, hint)
onclick = "spy.gui.report.publication.EditPersonById(SET_SNUM_METACIF_%s)"
hint = "Edit author"
self.edit_subop = GI.get_action_button_html('edit', onclick, hint)
def currentResultFilesHtmlMaker(self, type='cif'):
var = 'snum.current_result.%s' % type
val = OV.GetParam(var)
if not val:
val = os.path.normpath(olx.file.ChangeExt(OV.FileFull(), type))
list = (
{'varName': str(var),
'itemName': '%s File' % type,
'value': val,
'chooseFile': {
'caption': 'Choose %s file' % type,
'filter': '.%s files|*.%s' % (type, type),
'folder': '%s' % OV.FilePath(),
'function': 'spy.SetParam(%s,' % var
},
},
)
return htmlTools.makeHtmlTable(list)
def absorption_correctionMetadataHtmlMaker(self, ):
list = (
{'varName': '_exptl_absorpt_correction_type',
'items': "'analytical;cylinder;empirical;gaussian;integration;multi-scan;none;numerical;psi-scan;refdelf;sphere'",
'itemName': '%Abs Type%'
},
{'varName': '_exptl_absorpt_process_details',
'itemName': '%Abs Details%',
'multiline': 'multiline'
},
{'varName': '_exptl_absorpt_correction_T_max',
'itemName': '%Abs T max%',
},
{'varName': '_exptl_absorpt_correction_T_min',
'itemName': '%Abs T min%',
},
)
return htmlTools.makeHtmlTable(list)
def diffractionMetadataHtmlMaker(self, ):
list = (
{'varName': 'snum.report.diffractometer',
'itemName': '%Diffractometer%',
'items': "'%s'" % userDictionaries.localList.getListDiffractometers(),
'onchange': "spy.addToLocalList(html.GetValue(~name~),diffractometers)>>html.update",
'readonly': False,
},
)
if OV.GetParam('snum.report.diffractometer') != '?':
list += (
{'varName': 'snum.report.diffractometer_definition_file',
'itemName': '%Definition File%',
'value': userDictionaries.localList.getDiffractometerDefinitionFile(OV.GetParam('snum.report.diffractometer')),
'chooseFile': {
'caption': 'Choose definition file',
'filter': '.cif files|*.cif',
'folder': '%s/etc/site' % OV.BaseDir(),
'function': 'spy.setDiffractometerDefinitionFile(spy.GetParam(snum.report.diffractometer),'
},
},
)
list += (
{'varName': '_diffrn_ambient_temperature',
'itemName': '%Diffraction T% (K)'
},
{'varName': '_cell_measurement_temperature',
'itemName': '%Cell Measurement T% (K)'
},
{'varName': '_diffrn_special_details',
'itemName': '%Special Details%',
'multiline': 'multiline'
},
{'varName': '_refine_special_details',
'itemName': '%Refine Special Details%',
'multiline': 'multiline'
}
)
return htmlTools.makeHtmlTable(list)
def crystalMetadataHtmlMaker(self):
list = (
{'varName': '_chemical_name_systematic',
'itemName': '%Systematic Name%',
'width': '100%'
},
{'varName': '_exptl_crystal_colour',
'itemName': '%Colour%',
'box1': {'varName': '_exptl_crystal_colour_lustre',
'items': '?;.;metallic;dull;clear',
'width': '33%'
},
'box2': {'varName': '_exptl_crystal_colour_modifier',
'items': "'?;.;light;dark;whiteish;blackish;grayish;brownish;reddish;pinkish;orangish;yellowish;greenish;bluish'",
'width': '34%'
},
'box3': {'varName': '_exptl_crystal_colour_primary',
'items': "'?;colourless;white;black;gray;brown;red;pink;orange;yellow;green;blue;violet'",
'width': '33%'
},
},
{'varName': '_exptl_crystal_size',
'itemName': '%Size% & %Shape%',
'box1': {'varName': '_exptl_crystal_size_min',
'width': '20%',
},
'box2': {'varName': '_exptl_crystal_size_mid',
'width': '20%',
},
'box3': {'varName': '_exptl_crystal_size_max',
'width': '20%',
},
'box4': {'varName': '_exptl_crystal_description',
'items': "'?;block;plate;needle;prism;irregular;cube;trapezoid;rect. Prism;rhombohedral;hexagonal;octahedral;plank'",
'width': '40%'
},
},
{'varName': '_exptl_crystal_preparation',
'itemName': '%Preparation Details%',
'multiline': 'multiline',
'width': '100%'
},
{'varName': '_exptl_crystal_recrystallization_method',
'itemName': '%Crystallisation Details%',
'multiline': 'multiline',
'width': '100%',
},
{'varName': 'snum.report.crystal_mounting_method',
'itemName': '%Crystal Mounting%',
'multiline': 'multiline',
'width': '100%'
},
)
return htmlTools.makeHtmlTable(list)
def collectionMetadataHtmlMaker(self, ):
items = userDictionaries.people.getListPeople()
onchange = '''spy.gui.report.publication.OnPersonChange('~name~')>>spy.SetParam('snum.report.%s',html.GetValue('~name~'))>>spy.gui.report.publication.OnAddNameToAuthorList('~name~')'''
subop = ["SUBMITTER", "OPERATOR"]
list = []
list.append(
{
'varName': 'snum.report.submission_original_sample_id',
'itemName': '%Sample ID% ',
}
)
for tem in subop:
authorRow = {
'varName': 'snum.report.%s' % tem.lower(),
'ctrl_name': 'SET_SNUM_METACIF_%s' % tem,
'readonly': 'readonly',
'items': items,
'bgcolor': "'%s'" % OV.GetParam('gui.html.table_bg_colour'),
'onchange': onchange % tem.lower(),
'onchangealways': 'true',
}
authorRow.setdefault('itemName', '')
authorRow.setdefault('field1',
{'itemName': tem.title(),
'fieldWidth': '70%%',
'bgcolor': '#ff0000',
})
_ = "%s" % (self.edit_subop)
_ = _ % (tem)
authorRow.setdefault('field2', {'itemName': _,
'fieldWidth': '30%%',
'fieldALIGN': 'right'})
list.append(authorRow)
list.append(
{
'varName': 'snum.report.date_submitted',
'itemName': '%Date Submitted%',
'type': 'date'
}
)
list.append(
{
'varName': 'snum.report.date_collected',
'itemName': '%Date Collected%',
'type': 'date'
}
)
list.append(
{
'varName': 'snum.report.date_completed',
'itemName': '%Date Completed%',
'type': 'date'
}
)
return htmlTools.makeHtmlTable(list)
def citationsMetadataHtmlMaker(self, ):
txt = "Current Citations:
"
ref_l = OV.get_cif_item('_publ_section_references').split('\n\n')
if not ref_l:
ref = "_publ_section_references is currently missing or empty."
else:
for item in ref_l:
item = item.strip()
if item:
txt += "%s
" % item
return txt.rstrip('
')
def progressMetadataHtmlMaker(self, ):
list = (
{'varName': 'snum.dimas.progress_status',
'itemName': '%Status%',
'items': "'No Entry;Aborted;Rejected;Withdrawn;Lost;In Queue;Collecting;Reduction;Solving;Refining;Pending;Processing;Finishing;Finished;Publishing;Published;Published Duplicate;Known structure'"
},
{'varName': 'snum.dimas.progress_comment',
'itemName': '%Comment%',
'multiline': 'multiline'
},
)
return htmlTools.makeHtmlTable(list)
def referenceMetadataHtmlMaker(self, ):
list = (
{'varName': 'snum.dimas.reference_csd_refcode',
'itemName': '%CSD% %Refcode%',
},
{'varName': 'snum.dimas.reference_publ_authors',
'itemName': '%Authors%',
},
{'varName': 'snum.dimas.reference_journal_name',
'itemName': '%Journal%',
'items': "'%s'" % userDictionaries.localList.getListJournals()
},
{'varName': 'snum.dimas.reference_journal_volume',
'itemName': '%Volume%',
},
{'varName': 'snum.dimas.reference_journal_pages',
'itemName': '%Pages%',
},
{'varName': 'snum.dimas.reference_journal_year',
'itemName': '%Year%',
},
{'varName': 'snum.dimas.reference_comment',
'itemName': '%Comment%',
'multiline': 'multiline'
},
)
return htmlTools.makeHtmlTable(list)
def publicationMetadataHtmlMaker(self, ):
listAuthors = OV.GetParam('snum.metacif.publ_author_names')
list = [
{'varName': '_database_code_depnum_ccdc_archive',
'itemName': 'CCDC %Number%',
},
{'varName': '_publ_contact_author_name',
'itemName': '%Contact% %Author%',
'type': 'combo',
'items': listAuthors,
'onchange': "spy.set_cif_item('_publ_contact_author_name', html.GetValue('~name~'))",
}]
if listAuthors is None:
numberAuthors = 0
else:
numberAuthors = len(listAuthors.split(';'))
for i in range(1, numberAuthors + 1):
authorRow = {
'varName': 'snum.metacif.publ_author_names',
'ctrl_name': 'SET_SNUM_METACIF_PUBL_AUTHOR_NAMES_%s' % i,
'value': "'%s'" % listAuthors.split(';')[i - 1],
'readonly': 'true',
'bgcolor': "'%s'" % OV.GetParam('gui.html.table_bg_colour'),
'onclick': ""
}
if numberAuthors == 1:
authorRow.setdefault('itemName', '')
authorRow.setdefault('field1', {'itemName': '%Author%'})
_ = "%s" % (self.delete)
_ = _ % (i)
authorRow.setdefault('field2', {'itemName': _,
'fieldALIGN': 'right'})
elif i == 1:
box = "SET_SNUM_METACIF_PUBL_AUTHOR_NAMES_%s" % i
authorRow.setdefault('itemName', '')
authorRow.setdefault('field1', {'itemName': 'Authors