forked from diffpy/diffpy.pdfgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrseriespanel.py
187 lines (166 loc) · 7.36 KB
/
rseriespanel.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
#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-
##############################################################################
#
# PDFgui by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2006 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:05:55 2019
import wx
from diffpy.pdfgui.control.pdfguimacros import makeRSeries
from diffpy.pdfgui.gui.pdfpanel import PDFPanel
from diffpy.pdfgui.gui.wxextensions.validators import FLOAT_ONLY, TextValidator
class RSeriesPanel(wx.Panel, PDFPanel):
def __init__(self, *args, **kwds):
PDFPanel.__init__(self)
# begin wxGlade: RSeriesPanel.__init__
kwds["style"] = kwds.get("style", 0) | wx.TAB_TRAVERSAL
wx.Panel.__init__(self, *args, **kwds)
self.instructionsLabel = wx.StaticText(
self,
wx.ID_ANY,
"Select a fit from the tree on the left and set the first value, last value, \nand the step size of the maximum and/or minimum of the fit range\nbelow. If you have not set up a fit to be the template for the series, hit\ncancel and rerun this macro once a fit has been created.", # noqa: E501
)
self.maxFirstLabel = wx.StaticText(self, wx.ID_ANY, "first")
self.maxFirstTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.maxLastLabel = wx.StaticText(self, wx.ID_ANY, "last")
self.maxLastTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.maxStepLabel = wx.StaticText(self, wx.ID_ANY, "step")
self.maxStepTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.minFirstLabel = wx.StaticText(self, wx.ID_ANY, "first")
self.minFirstTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.minLastLabel = wx.StaticText(self, wx.ID_ANY, "last")
self.minLastTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.minStepLabel = wx.StaticText(self, wx.ID_ANY, "step")
self.minStepTextCtrl = wx.TextCtrl(self, wx.ID_ANY, "")
self.goButton = wx.Button(self, wx.ID_OK, "OK")
self.cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel")
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.onOK, self.goButton)
self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelButton)
# end wxGlade
self.__customProperties()
def __set_properties(self):
# begin wxGlade: RSeriesPanel.__set_properties
self.instructionsLabel.SetFont(
wx.Font(
10,
wx.FONTFAMILY_DEFAULT,
wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL,
0,
"Sans",
)
)
# end wxGlade
def __do_layout(self):
# begin wxGlade: RSeriesPanel.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4_copy = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "fit minimum"), wx.HORIZONTAL)
sizer_4 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "fit maximum"), wx.HORIZONTAL)
sizer_1.Add(self.instructionsLabel, 0, wx.ALL | wx.EXPAND, 5)
sizer_4.Add(self.maxFirstLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
sizer_4.Add(self.maxFirstTextCtrl, 0, wx.ALL, 5)
sizer_4.Add(self.maxLastLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
sizer_4.Add(self.maxLastTextCtrl, 0, wx.ALL, 5)
sizer_4.Add(self.maxStepLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
sizer_4.Add(self.maxStepTextCtrl, 0, wx.ALL, 5)
sizer_1.Add(sizer_4, 0, wx.ALL | wx.EXPAND, 5)
sizer_4_copy.Add(self.minFirstLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
sizer_4_copy.Add(self.minFirstTextCtrl, 0, wx.ALL, 5)
sizer_4_copy.Add(self.minLastLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
sizer_4_copy.Add(self.minLastTextCtrl, 0, wx.ALL, 5)
sizer_4_copy.Add(self.minStepLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
sizer_4_copy.Add(self.minStepTextCtrl, 0, wx.ALL, 5)
sizer_1.Add(sizer_4_copy, 0, wx.ALL | wx.EXPAND, 5)
sizer_3.Add((20, 20), 1, wx.EXPAND, 0)
sizer_3.Add(self.goButton, 0, wx.ALL, 5)
sizer_3.Add(self.cancelButton, 0, wx.ALL, 5)
sizer_1.Add(sizer_3, 0, wx.EXPAND, 0)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
# end wxGlade
# ################################################
def __customProperties(self):
"""Set the custom properties of this panel."""
self.fit = None
self.ctrlMap = {
"maxfirst": "maxFirstTextCtrl",
"maxlast": "maxLastTextCtrl",
"maxstep": "maxStepTextCtrl",
"minfirst": "minFirstTextCtrl",
"minlast": "minLastTextCtrl",
"minstep": "minStepTextCtrl",
}
for var in self.ctrlMap:
setattr(self, var, None)
for ctrlname in self.ctrlMap.values():
textCtrl = getattr(self, ctrlname)
textCtrl.SetValidator(TextValidator(FLOAT_ONLY))
return
def onOK(self, event): # wxGlade: RSeriesPanel.<event_handler>
"""Add make a temperature series and add it to the project."""
for varname, ctrlname in self.ctrlMap.items():
textCtrl = getattr(self, ctrlname)
value = textCtrl.GetValue()
if value == "":
value = None
else:
value = float(value)
setattr(self, varname, value)
org = makeRSeries(
self.mainFrame.control,
self.fit,
self.maxfirst,
self.maxlast,
self.maxstep,
self.minfirst,
self.minlast,
self.minstep,
)
self.treeCtrlMain.ExtendProjectTree(org, clear=False)
self.mainFrame.needsSave()
self.onCancel(event)
return
def onCancel(self, event): # wxGlade: RSeriesPanel.<event_handler>
"""Return to the main panel."""
self.mainFrame.setMode("fitting")
self.treeCtrlMain.UnselectAll()
self.mainFrame.switchRightPanel("blank")
return
def treeSelectionUpdate(self, node):
"""Set the current fit when the tree selection changes."""
nodetype = self.treeCtrlMain.GetNodeType(node)
if nodetype == "fit":
self.fit = self.treeCtrlMain.GetControlData(node)
self.refresh()
return
def refresh(self):
"""Block out OK button if there is no fit.
This also blocks OK if the fit has no datasets or phases.
"""
# We can't rely on Veto to block unwanted tree selections on windows.
# So, we have to check for errors here.
node = None
nodetype = None
selections = self.treeCtrlMain.GetSelections()
if selections:
node = selections[0]
nodetype = self.treeCtrlMain.GetNodeType(node)
if node and nodetype == "fit" and self.fit and self.fit.hasDataSets() and self.fit.hasStructures():
self.goButton.Enable()
else:
self.goButton.Enable(False)
return
# end of class RSeriesPanel