Skip to content

Commit

Permalink
new dialog for adding materials. alloyAuAg can be added using GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
lavakyan committed Dec 16, 2017
1 parent 32e4193 commit 4cf3365
Showing 1 changed file with 65 additions and 9 deletions.
74 changes: 65 additions & 9 deletions mstm_studio_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from mstm_spectrum import (Material, SingleSphere, Background,
LinearBackground, LorentzBackground, SPR,
LogNormalSpheres)
from alloy_AuAg import AlloyAuAg
from fit_spheres_optic import (Fitter, FixConstraint, EqualityConstraint,
ConcentricConstraint)
#import threading
Expand Down Expand Up @@ -479,17 +480,27 @@ def btDelMatClick(master=None):
update_materials_tree()

def btAddMatClick(master=None):
global w, material
mat_str = tkSimpleDialog.askstring('Material data', 'Enter material name or refraction index')
if mat_str:
global w, root, material
dial = GenerateMaterialDialog(root)
if dial.result is None:
return
name, conc = dial.result
#~ mat_str = tkSimpleDialog.askstring('Material data', 'Enter material name or refraction index')
if name == 'alloyAuAg':
try:
mat = AlloyAuAg(conc)
except Exception as err:
tkMessageBox.showerror('Error', err)
return
else:
try: # try create material
mat = Material(mat_str)
mat = Material(name)
except Exception as err:
tkMessageBox.showerror('Error', err)
return
key = gen_mat_key(True)
add_material(key, mat)
update_materials_tree()
key = gen_mat_key(True)
add_material(key, mat)
update_materials_tree()

def btLoadMatClick(master=None):
ftypes = [('Text files', '*.txt'), ('All files', '*')]
Expand Down Expand Up @@ -786,6 +797,53 @@ def apply(self):
pass


class GenerateMaterialDialog(tkSimpleDialog.Dialog):

choises = ['4+2j', 'air', 'glass', 'water', 'alloyAuAg']

def __init__(self, master, data_name='1.0', data_conc=0):
self.data_name = data_name
self.data_conc = data_conc
tkSimpleDialog.Dialog.__init__(self, master)

def body(self, master):
Label(master, text='Material name:').grid(row=1)
Label(master, text='Concentration:').grid(row=2)

self.ename = ttk.Combobox(master, values=self.choises)
self.ename.bind('<<ComboboxSelected>>', self._cbselected)
self.ename.current(0)
self.econc = Entry(master, state='disabled')
self.econc.insert(0, self.data_conc)

self.ename.grid(row=1, column=1)
self.econc.grid(row=2, column=1)
return self.ename # initial focus

def _cbselected(self, event=None):
if self.ename.get() == 'alloyAuAg':
self.econc.configure(state='normal')
else:
self.econc.configure(state='disabled')

def validate(self):
try:
name = self.ename.get()
if not (name in self.choises):
_ = np.complex(self.ename.get())
if name == 'alloyAuAg':
self.result = name, float(self.econc.get())
else:
self.result = name, None
return True
except ValueError as err:
tkMessageBox.showerror('Error', 'Bad data entered\n%s' % err)
return False

def apply(self):
pass


class ConstraintsWindow:

constr_types = ['Fix', 'Equality', 'Concentric']
Expand All @@ -794,8 +852,6 @@ def __init__(self, master=None):
self.master = master
self.nspheres = 0
master.title('Constraints')
#~ master.geometry('600x450')
#~ self.padWE = dict(sticky=('w', 'e'), padx='0.5mm', pady='0.5mm')
self.padWE = dict(padx='0.5mm', pady='0.5mm')
self.frame = ttk.Frame(self.master)
self.create_widgets()
Expand Down

0 comments on commit 4cf3365

Please sign in to comment.