forked from diffpy/diffpy.pdfgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbondlengthdialog.py
256 lines (199 loc) · 8.49 KB
/
bondlengthdialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-
##############################################################################
#
# PDFgui by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2007 trustees of the Michigan State University.
# All rights reserved.
#
# File coded by: Chris Farrow
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE.txt for license information.
#
##############################################################################
# generated by wxGlade 0.9.3 on Fri Jul 19 16:00:05 2019
import wx
from diffpy.pdfgui.gui.wxextensions.validators import FLOAT_ONLY, TextValidator
# begin wxGlade: extracode
# end wxGlade
class BondLengthDialog(wx.Dialog):
def __init__(self, *args, **kwds):
# begin wxGlade: BondLengthDialog.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
wx.Dialog.__init__(self, *args, **kwds)
self.SetTitle("Calculate Bond Lengths")
sizer_2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, ""), wx.VERTICAL)
self.instructionsLabel = wx.StaticText(self, wx.ID_ANY, "Enter the indices of two atoms.")
sizer_2.Add(self.instructionsLabel, 0, wx.ALL, 5)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2.Add(sizer_3, 0, wx.EXPAND, 0)
self.indicesLabel = wx.StaticText(self, wx.ID_ANY, "Atom Indices")
sizer_3.Add(self.indicesLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.aSpinCtrl = wx.SpinCtrl(self, wx.ID_ANY, "", min=0, max=100, style=0)
self.aSpinCtrl.SetMinSize((80, 27))
sizer_3.Add(self.aSpinCtrl, 0, wx.ALL, 5)
self.bSpinCtrl = wx.SpinCtrl(self, wx.ID_ANY, "", min=0, max=100, style=0)
self.bSpinCtrl.SetMinSize((80, 27))
sizer_3.Add(self.bSpinCtrl, 0, wx.ALL, 5)
self.static_line_2 = wx.StaticLine(self, wx.ID_ANY)
sizer_2.Add(self.static_line_2, 0, wx.BOTTOM | wx.EXPAND, 5)
self.instructionsLabel2 = wx.StaticText(
self,
wx.ID_ANY,
"Or enter the elemental symbols of two atoms and\nthe range over which to calculate the bond lengths.",
)
sizer_2.Add(self.instructionsLabel2, 0, wx.ALL, 5)
sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2.Add(sizer_4, 0, wx.EXPAND, 0)
self.elementLabel = wx.StaticText(self, wx.ID_ANY, "Elements")
sizer_4.Add(self.elementLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.aComboBox = wx.ComboBox(self, wx.ID_ANY, choices=[], style=0)
self.aComboBox.SetMinSize((80, 27))
sizer_4.Add(self.aComboBox, 0, wx.ALL, 5)
self.bComboBox = wx.ComboBox(self, wx.ID_ANY, choices=[], style=0)
self.bComboBox.SetMinSize((80, 27))
sizer_4.Add(self.bComboBox, 0, wx.ALL, 5)
sizer_4_copy_1 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2.Add(sizer_4_copy_1, 0, wx.EXPAND, 0)
self.rangeLabel = wx.StaticText(self, wx.ID_ANY, "Range")
sizer_4_copy_1.Add(self.rangeLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.lbTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.lbTextCtrl.SetMinSize((80, 27))
sizer_4_copy_1.Add(self.lbTextCtrl, 0, wx.ALL, 5)
self.toLabel = wx.StaticText(self, wx.ID_ANY, "to")
sizer_4_copy_1.Add(self.toLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.ubTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.ubTextCtrl.SetMinSize((80, 27))
sizer_4_copy_1.Add(self.ubTextCtrl, 0, wx.ALL, 5)
self.static_line_1 = wx.StaticLine(self, wx.ID_ANY)
sizer_2.Add(self.static_line_1, 0, wx.EXPAND, 0)
sizer_4_copy = wx.BoxSizer(wx.HORIZONTAL)
sizer_2.Add(sizer_4_copy, 0, wx.EXPAND, 0)
sizer_4_copy.Add((0, 0), 1, wx.EXPAND, 0)
self.cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel")
sizer_4_copy.Add(self.cancelButton, 0, wx.ALL, 5)
self.okButton = wx.Button(self, wx.ID_OK, "OK")
sizer_4_copy.Add(self.okButton, 0, wx.ALL, 5)
self.SetSizer(sizer_2)
sizer_2.Fit(self)
self.Layout()
self.Bind(wx.EVT_SPINCTRL, self.onSpin, self.aSpinCtrl)
self.Bind(wx.EVT_SPINCTRL, self.onSpin, self.bSpinCtrl)
self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelButton)
self.Bind(wx.EVT_BUTTON, self.onOk, self.okButton)
# end wxGlade
self.__customProperties()
def __customProperties(self):
"""Set the custom properties."""
self.a = 1
self.b = 2
self.ea = "ALL"
self.eb = "ALL"
self.lb = 0
self.ub = 0
# Set the textCtrl validators and focus events
textCtrls = [self.lbTextCtrl, self.ubTextCtrl]
for ctrl in textCtrls:
ctrl.SetValidator(TextValidator(FLOAT_ONLY))
ctrl.Bind(wx.EVT_KILL_FOCUS, self.onTextKillFocus)
self.comboBoxes = [self.aComboBox, self.bComboBox]
for cbox in self.comboBoxes:
cbox.Bind(wx.EVT_KILL_FOCUS, self.onComboKillFocus)
cbox.Bind(wx.EVT_COMBOBOX, self.onComboKillFocus)
return
def setStructure(self, structure):
"""Set the structure and update the widgets.
This must be called before the spin control boxes will be settable to
anything other than 1.
"""
self.okButton.Enable(True)
natoms = len(structure)
if natoms < 2:
self.okButton.Enable(False)
return
# Fill the spin controls
self.aSpinCtrl.SetRange(1, natoms)
self.bSpinCtrl.SetRange(1, natoms)
self.aSpinCtrl.SetValue(min(1, natoms))
self.bSpinCtrl.SetValue(min(2, natoms))
# Fill the combo boxes
self.eList = sorted(set(a.element for a in structure))
self.eList.insert(0, "All")
self.aComboBox.Clear()
self.bComboBox.Clear()
for el in self.eList:
self.aComboBox.Append(el)
self.bComboBox.Append(el)
self.aComboBox.SetValue("All")
self.bComboBox.SetValue("All")
self.lbTextCtrl.SetValue("0.0")
self.ubTextCtrl.SetValue("0.0")
return
def onTextKillFocus(self, event):
self.lb = float(self.lbTextCtrl.GetValue())
self.ub = float(self.ubTextCtrl.GetValue())
event.Skip()
return
def onComboKillFocus(self, event):
# Verify that the combo boxes are valid
for cbox in self.comboBoxes:
val = cbox.GetValue()
if val not in self.eList:
val = "All"
cbox.SetValue(val)
self.ea = self.aComboBox.GetValue()
self.eb = self.bComboBox.GetValue()
event.Skip()
return
def getCtrlLetter(self, ctrl):
"""Get the letter associated with the control."""
if ctrl is self.aSpinCtrl:
return "a"
return "b"
def onSpin(self, event): # wxGlade: BondLengthDialog.<event_handler>
letters = ["a", "b"]
ctrl = event.GetEventObject()
val = event.GetSelection()
atomLetter = self.getCtrlLetter(ctrl)
# Check to see if the value is increasing or decreasing
increasing = True
oldval = getattr(self, atomLetter)
if val < oldval:
increasing = False
# Check to see if the value is equal to another. If so, move it along in
# the direction it was going.
letters.remove(atomLetter)
newval = val
loop = True
while loop:
loop = False
for letter in letters:
if newval == getattr(self, letter):
loop = True
if increasing:
newval += 1
else:
newval -= 1
# Set the new value, depending on what it is.
if newval > 0 and newval <= ctrl.GetMax():
setattr(self, atomLetter, newval)
wx.CallAfter(ctrl.SetValue, newval)
else:
setattr(self, atomLetter, oldval)
wx.CallAfter(ctrl.SetValue, oldval)
return
def onCancel(self, event): # wxGlade: BondLengthDialog.<event_handler>
event.Skip()
def onOk(self, event): # wxGlade: BondLengthDialog.<event_handler>
self.onTextKillFocus(event)
self.onComboKillFocus(event)
event.Skip()
# end of class BondLengthDialog
if __name__ == "__main__":
app = wx.PySimpleApp(0)
blenDialog = BondLengthDialog(None, -1, "")
app.SetTopWindow(blenDialog)
blenDialog.Show()
app.MainLoop()