forked from diffpy/diffpy.pdfgui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainframe.py
More file actions
2637 lines (2318 loc) · 99.1 KB
/
mainframe.py
File metadata and controls
2637 lines (2318 loc) · 99.1 KB
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/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.4 on Thu Feb 23 15:06:06 2006
"""This module contains the main window of PDFgui."""
import os.path
import wx
import wx.aui
import wx.lib.newevent
from diffpy.pdfgui.control import structureviewer
from diffpy.pdfgui.control.controlerrors import ControlError, ControlFileError
from diffpy.pdfgui.control.pdfguicontrol import pdfguicontrol
from diffpy.pdfgui.gui import pdfguiglobals
from diffpy.pdfgui.gui.aboutdialog import DialogAbout
from diffpy.pdfgui.gui.adddatapanel import AddDataPanel
from diffpy.pdfgui.gui.addphasepanel import AddPhasePanel
from diffpy.pdfgui.gui.blankpanel import BlankPanel
from diffpy.pdfgui.gui.calculationpanel import CalculationPanel
from diffpy.pdfgui.gui.datasetpanel import DataSetPanel
from diffpy.pdfgui.gui.dopingseriespanel import DopingSeriesPanel
from diffpy.pdfgui.gui.errorreportdialog import USERSMAILINGLIST, ErrorReportDialog
from diffpy.pdfgui.gui.errorwrapper import catchObjectErrors
from diffpy.pdfgui.gui.fitnotebookpanel import FitNotebookPanel
from diffpy.pdfgui.gui.fittree import FitTree, FitTreeError
from diffpy.pdfgui.gui.journalpanel import JournalPanel
from diffpy.pdfgui.gui.outputpanel import OutputPanel
from diffpy.pdfgui.gui.pdfguiglobals import docMainFile, iconpath
from diffpy.pdfgui.gui.phasenotebookpanel import PhaseNotebookPanel
from diffpy.pdfgui.gui.plotpanel import PlotPanel
from diffpy.pdfgui.gui.preferencespanel import PreferencesPanel
from diffpy.pdfgui.gui.rseriespanel import RSeriesPanel
from diffpy.pdfgui.gui.temperatureseriespanel import TemperatureSeriesPanel
from diffpy.pdfgui.gui.welcomepanel import WelcomePanel
from diffpy.pdfgui.gui.wxextensions import wx12
from diffpy.pdfgui.utils import QuotedConfigParser
(PDFCustomEvent, EVT_PDFCUSTOM) = wx.lib.newevent.NewEvent()
# WARNING - This file cannot be maintained with wxglade any longer. Do not make
# modifications with wxglade!!!
# README - Note that wx.TreeCtrl.GetSelections works differently in MSW than it
# does in GTK. In GTK, it returns a list of nodes as they appear in the tree.
# In MSW, it returns the list of nodes in some other order. This can lead to
# trouble if the order of selected nodes is important to a method.
# wx.TreeControl does not create an event in windows. Node deselection does
# not create an event on windows. There is no workaround for this. Node
# selection vetoing does not work on windows. Finally, changing the tree
# selection sends two selection events on windows. One for an empty selection
# and one with the new selections.
class MainFrame(wx.Frame):
"""The left pane is a FitTree (from fittree.py), the right is a dynamic
panel, accessed via the data member rightPanel, which can hold one of any
number of panels. The panels that can appear in the right pane must be
derived from PDFPanel (in pdfpanel.py) and are defined in the dynamicPanels
dictionary, which is defined in __customProperties. A panel is placed in the
right pane by passing its dynamicPanels dictionary key to the
switchRightPanel method. This method takes care of displaying the panel,
giving the data it needs, and calling its refresh() method.
** NODE TYPES **
The FitTree is essential to the functionality of the Gui.
The tree contains one of five types of items:
"fit" -- This represents a fit that is to be run by pdffit.
"dataset" -- This represents a data for a fit.
"phase" -- This represents the theoretical phases needed for a
dataset or a calculation.
"calculation" -- This represents a calculation which is to be made from
using a configured fit.
Depending upon what type of item is selected in the tree, the right pane
will display the properties and configuration of that item (if in "fitting
mode", see below.) More on these item types is given in the documentation
for the FitTree in fittree.py. See r
** MODES **
The program has various modes of operation.
"fitting" -- In this mode the right pane changes depending upon what
type of item is selected in the FitTree. When the
fitting button is pressed, the program is in "fitting"
mode.
"addingdata" -- This mode is for adding data.
"addingphase" -- This mode is for adding the phase
"config" -- This mode is used for preferences and structure viewer
configuration.
"rseries" -- The mode used when configuring an r-series macro.
"tseries" -- The mode used when configuring a temperature series
macro.
"dseries" -- The mode used when configuring a doping series macro.
The mode determines how the tree and other widgets react to user
interaction. The mode of the program is changed with the method setMode.
This method outright enables or disables certain widgets that should not be
used when in certain modes.
** DATA MEMBERS **
dynamicPanels -- The dictionary of right panels. This is used to change the
right panel in the method switchRightPanel. The panels held
by the dynamicPanels dictionary are listed below by their
dictionary keys:
* Miscellaneous panels:
"blank" -- A blank panel
"rseries" -- The r-series macro panel
"tseries" -- The temperature series macro panel
"dseries" -- The doping series macro panel
"welcome" -- A welcome panel
* 'fitting' mode panels
"fit" -- The panel for 'fit' nodes
"phase" -- The panel for 'phase' nodes
"dataset" -- The panel for 'dataset' nodes
"calculation" -- The panel for 'calculation' nodes
* Panels specific to other program modes
"adddata" -- The panel used in 'addingdata' mode
"addphase" -- The panel used in 'addingphase' mode
* Panels for future implementation
"configuration" -- Another 'config' mode panel
rightPanel -- The current right panel.
fullpath -- The full path to the most recently accessed project file.
workpath -- The full path to the working directory. This is modified
whenever something is loaded or saved to file. It is
preserved in the current session and across new projects.
cP -- A python SafeConfigurationParser object. This is in charge
of storing configuration information about the most recently
used files list. It is also used by addphasepanel and
adddatapanel to store their respective fullpath variables.
The code that handles the MRU files interacts directly
with cP.
mode -- The current mode of the program. This is modified using the
setMode method. See the MODES section above.
name -- The name of the program as defined in pdfguiglobals.
control -- The pdfguicontrol object needed for interfacing with the
engine pdffit2 code.
isAltered -- A Boolean flag that indicates when the program has been
altered. This should be changed with the method needsSave so
that the save menu item and toolbar button can be updated
accordingly.
runningDict -- A dictionary of running fits and calculations indexed by
name. This dictionary is used to change the status colors of
running fits and to keep the user from editing a running
fit.
quitting -- A boolean that is set when the program is quitting. This
flag tells the error handlers to ignore any errors that take
place during shutdown.
"""
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetMinSize((700, 500))
self.auiManager = wx.aui.AuiManager(self)
self.treeCtrlMain = FitTree(
self,
-1,
style=wx.TR_HAS_BUTTONS
| wx.TR_NO_LINES
| wx.TR_EDIT_LABELS
| wx.TR_MULTIPLE
| wx.TR_HIDE_ROOT
| wx.TR_MULTIPLE
| wx.TR_DEFAULT_STYLE
| wx.SUNKEN_BORDER,
)
self.plotPanel = PlotPanel(self, -1)
self.outputPanel = OutputPanel(self, -1)
self.journalPanel = JournalPanel(self, -1)
self.panelDynamic = BlankPanel(self, -1)
self.__customProperties()
self.Bind(wx.EVT_TREE_SEL_CHANGING, self.onTreeSelChanging, self.treeCtrlMain)
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.onTreeSelChanged, self.treeCtrlMain)
self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.onEndLabelEdit, self.treeCtrlMain)
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.onBeginLabelEdit, self.treeCtrlMain)
self.__customBindings()
self.__cmdLineLoad()
self.updateTitle()
self.auiManager.Update()
self.switchRightPanel("welcome")
return
# USER CONFIGURATION CODE #################################################
def __cmdLineLoad(self):
"""Open file loaded from the command line.
This opens a file without any checking for existing projects. This
should only be called after all initializations. It will open a file
whose name is specified in pdfguiglobals.cmdargs.
"""
if pdfguiglobals.cmdargs:
filename = pdfguiglobals.cmdargs[0]
fullpath = os.path.abspath(filename)
treelist = self.control.load(fullpath)
self.treeCtrlMain.ExtendProjectTree(treelist)
self.fullpath = fullpath
self.workpath = os.path.dirname(fullpath)
self.fileHistory.AddFileToHistory(fullpath)
self.plotPanel.refresh()
return
def __defineLocalIds(self):
"""Several user functions are duplicated many times throughout the gui.
This occurrs mostly between the main menu, the right-click menu, and the
many buttons in the gui. This method defines local Ids that can be used
for all of these.
"""
# Functions that modify the tree.
# These are used in the fitting right-click menu and the main menu.
self.newFitId = wx12.NewIdRef() # New Fit
self.newCalcId = wx12.NewIdRef() # New Calculation
self.newPhaseId = wx12.NewIdRef() # New Phase
self.newDataId = wx12.NewIdRef() # New Data Set
self.deleteId = wx.ID_DELETE # Delete tree item
self.copyId = wx.ID_COPY # Copy a tree item
self.pasteId = wx.ID_PASTE # Paste a tree item into tree
self.pasteLinkId = wx12.NewIdRef() # Paste and link a fit node
# Misc. functions, these are exclusive to the main menu.
self.newId = wx.ID_NEW # Start a new Project
self.openId = wx.ID_OPEN # Open a project
self.recentId = None # Open a recent project (set later)
self.saveId = wx.ID_SAVE # Save the project
self.saveAsId = wx.ID_SAVEAS # Save the project as...
self.quitId = wx.ID_CLOSE # Quit the program
self.runFitId = wx12.NewIdRef() # Run a fit
self.stopFitId = wx12.NewIdRef() # Stop a fit
self.quickPlotId = wx12.NewIdRef() # Quick plot a fit
self.exportFitPDFId = wx12.NewIdRef() # Save a fit PDF
self.exportFitStruId = wx12.NewIdRef() # Save a fit structure
self.exportNewStruId = wx12.NewIdRef() # Export a 'new' structure
self.plotIStructId = wx12.NewIdRef() # Plot initial structure
self.plotFStructId = wx12.NewIdRef() # Plot final structure
self.printBLId = wx12.NewIdRef() # Print the bond lengths of a structure
self.printBAId = wx12.NewIdRef() # Print the bond angles of a structure
self.exportResId = wx12.NewIdRef() # Save the results file
self.runCalcId = wx12.NewIdRef() # Run a calculation
self.exportCalcPDFId = wx12.NewIdRef() # Save a calculated PDF
return
def __customProperties(self):
"""Custom Properties go here."""
# Set some visual stuff
icon = wx.Icon(iconpath("pdfgui.ico"), wx.BITMAP_TYPE_ANY)
self.SetIcon(icon)
# The panel should know its name
self.name = pdfguiglobals.name
# The fit tree needs a copy of the control, as
# most interactions with the control happen there.
self.control = pdfguicontrol(self)
self.control.startQueue()
self.treeCtrlMain.control = self.control
# Constants needed for communication with the control
self.ERROR = 1
self.UPDATE = 1 << 1
self.OUTPUT = 1 << 2
self.PLOTNOW = 1 << 3
# Needed for the error checker so it doesn't throw errors at quit time
self.quitting = False
# Wrap the events to use an event handler
self.mainFrame = self # needed by error wrapper
catchObjectErrors(self)
# Needed for loading and saving
self.fullpath = ""
self.workpath = os.path.abspath(".")
# The dictionary of running fits/calculations
self.runningDict = {}
# The configuration parser for getting configuration data.
# self.cP = QuotedConfigParser()
# Long try this to avoid DuplicateSectionError and ParsingError
self.cP = QuotedConfigParser(strict=False, allow_no_value=True)
# Set the program mode
self.mode = "fitting"
# This is the dictionary of right panels. For simplicity the five panels
# corresponding to the five tree item types are given the name of the
# data type (fit, dataset, phase, calculation). This allows for
# automatic switching of panels.
self.dynamicPanels = {
"blank": self.panelDynamic,
"welcome": WelcomePanel(self, -1),
"fit": FitNotebookPanel(self, -1),
"phase": PhaseNotebookPanel(self, -1),
"dataset": DataSetPanel(self, -1),
"calculation": CalculationPanel(self, -1),
"adddata": AddDataPanel(self, -1),
"addphase": AddPhasePanel(self, -1),
"preferences": PreferencesPanel(self, -1),
"rseries": RSeriesPanel(self, -1),
"tseries": TemperatureSeriesPanel(self, -1),
"dseries": DopingSeriesPanel(self, -1),
}
# Prepare the right pane. Display the welcome screen.
self.rightPanel = self.panelDynamic
for key in self.dynamicPanels:
self.auiManager.AddPane(
self.dynamicPanels[key],
wx.aui.AuiPaneInfo()
.Name(key)
.CenterPane()
.BestSize(wx.Size(400, 380))
.MinSize(wx.Size(190, 200))
.Hide(),
)
self.dynamicPanels[key].mainFrame = self
self.dynamicPanels[key].treeCtrlMain = self.treeCtrlMain
self.dynamicPanels[key].cP = self.cP
self.dynamicPanels[key].key = key
self.dynamicPanels[key].Enable(False)
# Do the same for the plotPanel and journalPanel
self.plotPanel.mainFrame = self
self.plotPanel.treeCtrlMain = self.treeCtrlMain
self.plotPanel.cP = self.cP
self.plotPanel.Enable(False)
self.journalPanel.mainFrame = self
self.journalPanel.treeCtrlMain = self.treeCtrlMain
self.journalPanel.cP = self.cP
# Position other panels. Note that currently MinimizeButton does not do
# anything. It is to be implemented in future versions of wx.aui
self.auiManager.AddPane(
self.outputPanel,
wx.aui.AuiPaneInfo()
.Name("outputPanel")
.Caption("PDFfit2 Output")
.Bottom()
.TopDockable()
.BottomDockable()
.LeftDockable()
.RightDockable()
.MinimizeButton()
.BestSize(wx.Size(400, 40))
.MinSize(wx.Size(200, 40)),
)
self.auiManager.AddPane(
self.treeCtrlMain,
wx.aui.AuiPaneInfo()
.Name("treeCtrlMain")
.Caption("Fit Tree")
.Left()
.TopDockable()
.BottomDockable()
.LeftDockable()
.RightDockable()
.MinimizeButton()
.BestSize(wx.Size(200, 100))
.MinSize(wx.Size(200, 40)),
)
self.auiManager.AddPane(
self.plotPanel,
wx.aui.AuiPaneInfo()
.Name("plotPanel")
.Caption("Plot Control")
.Left()
.TopDockable()
.BottomDockable()
.LeftDockable()
.RightDockable()
.MinimizeButton()
.BestSize(wx.Size(200, 250))
.MinSize(wx.Size(200, 150)),
)
self.auiManager.AddPane(
self.journalPanel,
wx.aui.AuiPaneInfo()
.Name("journalPanel")
.Caption("Project Journal")
.TopDockable()
.BottomDockable()
.LeftDockable()
.RightDockable()
.MinimizeButton()
.Hide()
.BestSize(wx.Size(450, 450))
.MinSize(wx.Size(200, 200))
.FloatingSize(wx.Size(450, 450))
.Float(),
)
# Continue with initialization
self.__defineLocalIds() # Ids for menu items
self.__setupMainMenu() # Make the main menu
self.__setupToolBar() # Make the toolbar
self.treeCtrlMain.InitializeTree() # Initialize the tree
# Load the configuration
self.loadConfiguration()
# Set the state of the program
self.needsSave(False)
return
def __setupMainMenu(self):
"""This sets up the menu in the main frame."""
self.menulength = 8
self.menuBar = wx.MenuBar()
self.SetMenuBar(self.menuBar)
# File Menu
self.fileMenu = wx12.Menu()
self.newItem = wx.MenuItem(self.fileMenu, self.newId, "&New Project\tCtrl+n", "", wx.ITEM_NORMAL)
self.fileMenu.Append(self.newItem)
self.openItem = wx.MenuItem(self.fileMenu, self.openId, "&Open Project\tCtrl+o", "", wx.ITEM_NORMAL)
self.fileMenu.Append(self.openItem)
self.recentMenu = wx12.Menu()
msub = self.fileMenu.AppendSubMenu(self.recentMenu, "&Recent Files")
self.recentId = msub.Id
self.fileMenu.AppendSeparator()
self.saveItem = wx.MenuItem(self.fileMenu, self.saveId, "&Save Project\tCtrl+s", "", wx.ITEM_NORMAL)
self.fileMenu.Append(self.saveItem)
self.saveAsItem = wx.MenuItem(
self.fileMenu,
self.saveAsId,
"Save Project &as\tCtrl+Shift+s",
"",
wx.ITEM_NORMAL,
)
self.fileMenu.Append(self.saveAsItem)
self.fileMenu.AppendSeparator()
self.quitItem = wx.MenuItem(self.fileMenu, self.quitId, "&Quit\tCtrl+q", "", wx.ITEM_NORMAL)
self.fileMenu.Append(self.quitItem)
self.menuBar.Append(self.fileMenu, "&File")
# End File Menu
# Edit Menu
self.editMenu = wx12.Menu()
self.delItem = wx.MenuItem(self.editMenu, self.deleteId, "&Delete Item(s)\tCtrl+X", "", wx.ITEM_NORMAL)
self.editMenu.Append(self.delItem)
self.copyItem = wx.MenuItem(self.editMenu, self.copyId, "&Copy Item\tCtrl+C", "", wx.ITEM_NORMAL)
self.editMenu.Append(self.copyItem)
self.pasteItem = wx.MenuItem(self.editMenu, self.pasteId, "&Paste Item\tCtrl+V", "", wx.ITEM_NORMAL)
self.editMenu.Append(self.pasteItem)
self.pasteLinkItem = wx.MenuItem(self.editMenu, self.pasteLinkId, "Paste &Linked Fit", "", wx.ITEM_NORMAL)
self.editMenu.Append(self.pasteLinkItem)
self.editMenu.AppendSeparator()
self.prefItem = wx.MenuItem(self.editMenu, wx12.NewIdRef(), "&Preferences", "", wx.ITEM_NORMAL)
self.editMenu.Append(self.prefItem)
self.menuBar.Append(self.editMenu, "&Edit")
# End Edit Menu
# View Menu
self.viewMenu = wx12.Menu()
self.defaultLayoutItem = wx.MenuItem(
self.editMenu, wx12.NewIdRef(), "Default Window Layout", "", wx.ITEM_NORMAL
)
self.viewMenu.Append(self.defaultLayoutItem)
self.viewMenu.AppendSeparator()
# These items are context sensitive.
self.showFitItem = wx.MenuItem(self.viewMenu, wx12.NewIdRef(), "Show Fit Tree", "", wx.ITEM_NORMAL)
self.viewMenu.Append(self.showFitItem)
self.showPlotItem = wx.MenuItem(self.viewMenu, wx12.NewIdRef(), "Show Plot Control", "", wx.ITEM_NORMAL)
self.viewMenu.Append(self.showPlotItem)
self.showOutputItem = wx.MenuItem(self.viewMenu, wx12.NewIdRef(), "Show Output", "", wx.ITEM_NORMAL)
self.viewMenu.Append(self.showOutputItem)
self.showJournalItem = wx.MenuItem(
self.viewMenu, wx12.NewIdRef(), "Show Journal\tCtrl+j", "", wx.ITEM_NORMAL
)
self.viewMenu.Append(self.showJournalItem)
self.menuBar.Append(self.viewMenu, "&View")
# Fits Menu
self.fitsMenu = wx12.Menu()
self.newFitItem = wx.MenuItem(self.fitsMenu, self.newFitId, "&New Fit\tCtrl+t", "", wx.ITEM_NORMAL)
self.fitsMenu.Append(self.newFitItem)
self.fitsMenu.AppendSeparator()
self.runFitItem = wx.MenuItem(self.fitsMenu, self.runFitId, "&Run Selected Fits", "", wx.ITEM_NORMAL)
self.fitsMenu.Append(self.runFitItem)
self.stopFitItem = wx.MenuItem(self.fitsMenu, self.stopFitId, "&Stop Fitting", "", wx.ITEM_NORMAL)
self.fitsMenu.Append(self.stopFitItem)
self.fitsMenu.AppendSeparator()
self.expResItem = wx.MenuItem(self.fitsMenu, self.exportResId, "Export Resu<s File", "", wx.ITEM_NORMAL)
self.fitsMenu.Append(self.expResItem)
self.fitsMenu.AppendSeparator()
# Macros sub-menu
self.macrosMenu = wx12.Menu()
self.rseriesItem = wx.MenuItem(self.macrosMenu, wx12.NewIdRef(), "r-Series", "", wx.ITEM_NORMAL)
self.macrosMenu.Append(self.rseriesItem)
self.tseriesItem = wx.MenuItem(self.macrosMenu, wx12.NewIdRef(), "Temperature Series", "", wx.ITEM_NORMAL)
self.macrosMenu.Append(self.tseriesItem)
self.dseriesItem = wx.MenuItem(self.macrosMenu, wx12.NewIdRef(), "Doping Series", "", wx.ITEM_NORMAL)
self.macrosMenu.Append(self.dseriesItem)
self.fitsMenu.AppendSubMenu(self.macrosMenu, "Macros")
self.menuBar.Append(self.fitsMenu, "Fi&ts")
# End Fits Menu
# Phases Menu
self.phasesMenu = wx12.Menu()
self.newPhaseItem = wx.MenuItem(self.phasesMenu, self.newPhaseId, "&New Phase\tCtrl+p", "", wx.ITEM_NORMAL)
self.phasesMenu.Append(self.newPhaseItem)
self.phasesMenu.AppendSeparator()
self.printBLItem = wx.MenuItem(
self.phasesMenu,
self.printBLId,
"Calculate bond lengths",
"",
wx.ITEM_NORMAL,
)
self.phasesMenu.Append(self.printBLItem)
self.printBAItem = wx.MenuItem(
self.phasesMenu, self.printBAId, "Calculate bond angles", "", wx.ITEM_NORMAL
)
self.phasesMenu.Append(self.printBAItem)
self.phasesMenu.AppendSeparator()
self.expNewPhaseItem = wx.MenuItem(
self.phasesMenu,
self.exportNewStruId,
"Export &Selected Phase",
"",
wx.ITEM_NORMAL,
)
self.phasesMenu.Append(self.expNewPhaseItem)
self.expStruItem = wx.MenuItem(
self.fitsMenu,
self.exportFitStruId,
"&Export Fit Structure",
"",
wx.ITEM_NORMAL,
)
self.phasesMenu.Append(self.expStruItem)
self.phasesMenu.AppendSeparator()
self.plotIStructItem = wx.MenuItem(
self.phasesMenu,
self.plotIStructId,
"&Plot Initial Structure",
"",
wx.ITEM_NORMAL,
)
self.phasesMenu.Append(self.plotIStructItem)
self.plotFStructItem = wx.MenuItem(
self.phasesMenu,
self.plotFStructId,
"&Plot Final Structure",
"",
wx.ITEM_NORMAL,
)
self.phasesMenu.Append(self.plotFStructItem)
self.menuBar.Append(self.phasesMenu, "&Phases")
# End Phases Menu
# Data Menu
self.dataMenu = wx12.Menu()
self.newDataItem = wx.MenuItem(self.dataMenu, self.newDataId, "&New Data Set\tCtrl+d", "", wx.ITEM_NORMAL)
self.dataMenu.Append(self.newDataItem)
self.dataMenu.AppendSeparator()
self.expFitPDFItem = wx.MenuItem(self.fitsMenu, self.exportFitPDFId, "&Export Fit PDF", "", wx.ITEM_NORMAL)
self.dataMenu.Append(self.expFitPDFItem)
self.menuBar.Append(self.dataMenu, "&Data")
# End Data Menu
# Calculations Menu
self.calcMenu = wx12.Menu()
self.newCalcItem = wx.MenuItem(
self.calcMenu,
self.newCalcId,
"&New Calculation\tCtrl+l",
"",
wx.ITEM_NORMAL,
)
self.calcMenu.Append(self.newCalcItem)
self.calcMenu.AppendSeparator()
self.runCalcItem = wx.MenuItem(
self.calcMenu,
self.runCalcId,
"&Run Selected Calculation",
"",
wx.ITEM_NORMAL,
)
self.calcMenu.Append(self.runCalcItem)
self.calcMenu.AppendSeparator()
self.expCalcPDFItem = wx.MenuItem(
self.calcMenu,
self.exportCalcPDFId,
"&Export Selected Calculation",
"",
wx.ITEM_NORMAL,
)
self.calcMenu.Append(self.expCalcPDFItem)
self.menuBar.Append(self.calcMenu, "Ca&lculations")
# End Calculations Menu
# Help Menu
self.helpMenu = wx12.Menu()
self.docItem = wx.MenuItem(self.helpMenu, wx12.NewIdRef(), "&Documentation\tF1", "", wx.ITEM_NORMAL)
self.helpMenu.Append(self.docItem)
self.requestItem = wx.MenuItem(
self.helpMenu,
wx12.NewIdRef(),
"Request a Feature / Report a Bug",
"",
wx.ITEM_NORMAL,
)
self.helpMenu.Append(self.requestItem)
self.communityItem = wx.MenuItem(self.helpMenu, wx12.NewIdRef(), "PDFgui Community", "", wx.ITEM_NORMAL)
self.helpMenu.Append(self.communityItem)
self.aboutItem = wx.MenuItem(self.helpMenu, wx12.NewIdRef(), "&About", "", wx.ITEM_NORMAL)
self.helpMenu.Append(self.aboutItem)
self.menuBar.Append(self.helpMenu, "&Help")
# End Help Menu
# For managing MRUs
self.fileHistory = wx.FileHistory(pdfguiglobals.MAXMRU)
self.fileHistory.UseMenu(self.recentMenu)
return
def __setupToolBar(self):
"""This sets up the tool bar in the parent window."""
self.toolBar = self.CreateToolBar()
wx12.patchToolBarMethods(self.toolBar)
size = (16, 16)
bitmap = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, size)
self.toolBar.AddTool(
self.newId,
"New Project",
bitmap,
wx.NullBitmap,
wx.ITEM_NORMAL,
"Start a new project",
)
bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, size)
self.toolBar.AddTool(
self.openId,
"Open Project",
bitmap,
wx.NullBitmap,
wx.ITEM_NORMAL,
"Open an existing project",
)
bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, size)
self.toolBar.AddTool(
self.saveId,
"Save Project",
bitmap,
wx.NullBitmap,
wx.ITEM_NORMAL,
"Save this project",
)
self.toolBar.AddSeparator()
# This fixes the shadowing problem on Windows.
# The bitmap has a white transparency color (mask)
maskcolor = wx.Colour(red=255, green=255, blue=255)
bitmap = wx.Bitmap(iconpath("run.png"))
bitmap.SetSize(size)
mask = wx.Mask(bitmap, maskcolor)
bitmap.SetMask(mask)
self.toolBar.AddTool(
self.runFitId,
"Start",
bitmap,
wx.NullBitmap,
wx.ITEM_NORMAL,
"Start a fit or calculation",
)
bitmap = wx.Bitmap(iconpath("stop.png"))
bitmap.SetSize(size)
mask = wx.Mask(bitmap, maskcolor)
bitmap.SetMask(mask)
self.toolBar.AddTool(
self.stopFitId,
"Stop",
bitmap,
wx.NullBitmap,
wx.ITEM_NORMAL,
"Stop running fits or calculations",
)
self.toolBar.AddSeparator()
bitmap = wx.Bitmap(iconpath("datasetitem.png"))
bitmap.SetSize(size)
self.toolBar.AddTool(
self.quickPlotId,
"Quick plot",
bitmap,
wx.NullBitmap,
wx.ITEM_NORMAL,
"Plot PDF or structure",
)
self.toolBar.Realize()
return
def __customBindings(self):
"""Custom user bindings go here.
These bindings are not present in wxglade.
"""
# Allow a general right-click to work on the tree
self.treeCtrlMain.Bind(wx.EVT_RIGHT_DOWN, self.onRightClick)
# Double-click select all type on tree
# FIXME - this doesn't work, I suspect the problem is with the tree
# selection code.
# self.treeCtrlMain.Bind(wx.EVT_LEFT_DCLICK, self.onDoubleClick2)
# self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onDoubleClick, self.treeCtrlMain)
# Middle-click quickplot
self.Bind(wx.EVT_TREE_ITEM_MIDDLE_CLICK, self.onMiddleClick, self.treeCtrlMain)
# Catch key events for the tree
self.treeCtrlMain.Bind(wx.EVT_KEY_DOWN, self.onKey)
# Catch the close event
self.Bind(wx.EVT_CLOSE, self.onQuit)
# Use the custom event to pop up error messages
self.Bind(EVT_PDFCUSTOM, self.onCustom)
# Do bindings for menu items
self.__menuBindings()
self.__fittingRightMenuBindings()
return
def __menuBindings(self):
"""Setup bindings for the main menu and toolbar.
Since all toolbar functions use the same Ids as main menu items, the
toolbar events do not need their own bindings.
"""
# File Menu
self.Bind(wx.EVT_MENU, self.onNew, id=self.newId)
self.Bind(wx.EVT_MENU, self.onOpen, id=self.openId)
self.Bind(wx.EVT_MENU, self.onSave, id=self.saveId)
self.Bind(wx.EVT_MENU, self.onSaveAs, id=self.saveAsId)
self.Bind(wx.EVT_MENU, self.onQuit, id=self.quitId)
# For recent items
self.Bind(wx.EVT_MENU_RANGE, self.onMRUFile, id=wx.ID_FILE1, id2=wx.ID_FILE5)
# Edit Menu
self.Bind(wx.EVT_MENU, self.onDelete, id=self.deleteId)
self.Bind(wx.EVT_MENU, self.onCopy, id=self.copyId)
self.Bind(wx.EVT_MENU, self.onPaste, id=self.pasteId)
self.Bind(wx.EVT_MENU, self.onPasteLink, id=self.pasteLinkId)
self.Bind(wx.EVT_MENU, self.onPreferences, self.prefItem)
# View menu
self.Bind(wx.EVT_MENU, self.onDefaultLayout, self.defaultLayoutItem)
self.Bind(wx.EVT_MENU, self.onShowFit, self.showFitItem)
self.Bind(wx.EVT_MENU, self.onShowPlot, self.showPlotItem)
self.Bind(wx.EVT_MENU, self.onShowOutput, self.showOutputItem)
self.Bind(wx.EVT_MENU, self.onShowJournal, self.showJournalItem)
# Fits Menu
self.Bind(wx.EVT_MENU, self.onNewFit, id=self.newFitId)
self.Bind(wx.EVT_MENU, self.onRun, id=self.runFitId)
self.Bind(wx.EVT_MENU, self.onStop, id=self.stopFitId)
self.Bind(wx.EVT_MENU, self.onExportRes, id=self.exportResId)
self.Bind(wx.EVT_MENU, self.onRSeries, self.rseriesItem)
self.Bind(wx.EVT_MENU, self.onTSeries, self.tseriesItem)
self.Bind(wx.EVT_MENU, self.onDSeries, self.dseriesItem)
# Macros are inserted individually
# Phases Menu
self.Bind(wx.EVT_MENU, self.onInsPhase, id=self.newPhaseId)
self.Bind(wx.EVT_MENU, self.onPrintBL, id=self.printBLId)
self.Bind(wx.EVT_MENU, self.onPrintBA, id=self.printBAId)
self.Bind(wx.EVT_MENU, self.onExportNewStruct, id=self.exportNewStruId)
self.Bind(wx.EVT_MENU, self.onExportStruct, id=self.exportFitStruId)
self.Bind(wx.EVT_MENU, self.onPlotIStruct, id=self.plotIStructId)
self.Bind(wx.EVT_MENU, self.onPlotFStruct, id=self.plotFStructId)
# Data Menu
self.Bind(wx.EVT_MENU, self.onInsData, id=self.newDataId)
self.Bind(wx.EVT_MENU, self.onExportPDF, id=self.exportFitPDFId)
# Calculations Menu
self.Bind(wx.EVT_MENU, self.onInsCalc, id=self.newCalcId)
self.Bind(wx.EVT_MENU, self.onRun, id=self.runCalcId)
self.Bind(wx.EVT_MENU, self.onSaveCalc, id=self.exportCalcPDFId)
# Help Menu
self.Bind(wx.EVT_MENU, self.onDocumentation, self.docItem)
self.Bind(wx.EVT_MENU, self.onAbout, self.aboutItem)
self.Bind(wx.EVT_MENU, self.onRequest, self.requestItem)
self.Bind(wx.EVT_MENU, self.onCommunity, self.communityItem)
# The generic menu-check.
self.Bind(wx.EVT_MENU_OPEN, self.onMainMenu)
# Toolbar events that have no menu item
self.Bind(wx.EVT_MENU, self.onQuickPlot, id=self.quickPlotId)
return
def __fittingRightMenuBindings(self):
"""Bindings for the fitting-mode right-click menu."""
self.Bind(wx.EVT_MENU, self.onNewFit, id=self.newFitId)
self.Bind(wx.EVT_MENU, self.onCopy, id=self.copyId)
self.Bind(wx.EVT_MENU, self.onPaste, id=self.pasteId)
self.Bind(wx.EVT_MENU, self.onPasteLink, id=self.pasteLinkId)
self.Bind(wx.EVT_MENU, self.onInsPhase, id=self.newPhaseId)
self.Bind(wx.EVT_MENU, self.onInsData, id=self.newDataId)
self.Bind(wx.EVT_MENU, self.onInsCalc, id=self.newCalcId)
self.Bind(wx.EVT_MENU, self.onDelete, id=self.deleteId)
return
# UTILITY FUNCTIONS ######################################################
def switchRightPanel(self, paneltype):
"""Switch the panel which is visible in the right hand side.
This sets any panel-specific data and calls the refresh() method of the
new rightPanel. All right panels must be derived from wxPanel and
PDFPanel (in pdfpanel module).
Inputs:
paneltype -- The code used in self.dynamicPanels that indicates the
panel to be displayed. If paneltype is None, the blank
panel is displayed.
"""
self.rightPanel.Enable(False)
self.plotPanel.Enable(False)
for key in self.dynamicPanels:
self.auiManager.GetPane(key).Hide()
# Why doesn't this work?
# key = self.rightPanel.key
# self.auiManager.GetPane(key).Hide()
if paneltype is None:
paneltype = "blank"
self.rightPanel = self.dynamicPanels[paneltype]
self.rightPanel.Enable(True)
self.setPanelSpecificData(paneltype)
self.rightPanel.refresh()
paneinfo = self.auiManager.GetPane(paneltype)
paneinfo.Show()
self.auiManager.Update()
selections = self.treeCtrlMain.GetSelections()
if len(selections) == 1:
self.plotPanel.Enable(True)
return
def setPanelSpecificData(self, paneltype):
"""This method sets the panel specific data for the right panel.
This method gets panel-specific data and sends it to the rightPanel. The
different types of data assignment are listed below.
"fit" type:
* Give the fit object to the panel
"phase" type:
* initialize constraints dictionary and configuration and results
* Structure objects.
"dataset" type:
* initialize configuration, constraints, and results objects
"calculation" type:
* Give the calculation object to the panel
"rseries" type:
* Give the fit object to the panel
"tseries" type:
* Give the fit object to the panel
"dseries" type:
* Give the fit object to the panel
"""
selections = self.treeCtrlMain.GetSelections()
if len(selections) == 1:
node = selections[0]
dataobject = self.treeCtrlMain.GetControlData(node)
if paneltype == "phase":
self.rightPanel.configuration = dataobject.initial
self.rightPanel.constraints = dataobject.constraints
self.rightPanel.results = dataobject.refined
elif paneltype == "dataset":
self.rightPanel.configuration = dataobject
self.rightPanel.constraints = dataobject.constraints
self.rightPanel.results = dataobject.refined
elif paneltype == "fit":
dataobject.updateParameters()
self.rightPanel.fit = dataobject
elif paneltype == "calculation":
self.rightPanel.calculation = dataobject
elif paneltype == "rseries":
self.rightPanel.fit = dataobject
elif paneltype == "tseries":
self.rightPanel.fit = dataobject
elif paneltype == "dseries":
self.rightPanel.fit = dataobject
return
def setMode(self, mode):
"""Set the mode of the program.
This method takes care of any widget properties that must change when
the mode is changed. If the mode is changing due to the change in the
right panel, always call setMode before switchRightPanel.
"fitting" mode:
* treeCtrlMain is enabled
* plotPanel panel is enabled
* toolBar is enabled
* menuBar is enabled
"addingdata" mode:
"addingphase" mode:
"config" mode:
* treeCtrlMain is disabled
* plotPanel panel is disabled
* toolBar is disabled
* menuBar is disabled
"rseries" mode:
"tseries" mode:
"dseries" mode:
* treeCtrlMain is enabled
* plotPanel panel is disabled
* toolBar is disabled
* menuBar is disabled
"""
self.mode = mode
if mode == "fitting":
self.treeCtrlMain.Enable(True)
self.plotPanel.Enable(True)
self.toolBar.Enable(True)
for i in range(self.menulength):
self.menuBar.EnableTop(i, True)
elif mode in ["addingdata", "addingphase", "config"]:
self.treeCtrlMain.Enable(False)
self.plotPanel.Enable(False)
self.toolBar.Enable(False)
for i in range(self.menulength):
self.menuBar.EnableTop(i, False)
elif mode in ["rseries", "tseries", "dseries"]:
self.treeCtrlMain.Enable(True)
self.plotPanel.Enable(False)
self.toolBar.Enable(False)
for i in range(self.menulength):
self.menuBar.EnableTop(i, False)
return
def loadConfiguration(self):
"""Load the configuration from file.
The MRU list is handled by the local member fileHistory, which is a
wxFileHistory object.
"""
# Get MRU information
localpath = os.path.expanduser(pdfguiglobals.configfilename)
if os.path.exists(localpath):
self.cP.read(localpath)
for i in range(pdfguiglobals.MAXMRU, 0, -1):
if self.cP.has_option("MRU", str(i)):
filename = self.cP.getquoted("MRU", str(i))
if filename:
self.fileHistory.AddFileToHistory(filename)
# Import perspective from last session
if self.cP.has_section("PERSPECTIVE"):
if self.cP.has_option("PERSPECTIVE", "last"):
perspective = self.cP.get("PERSPECTIVE", "last")
self.auiManager.LoadPerspective(perspective)
else:
from diffpy.pdfgui.gui.windowperspective import default
self.auiManager.LoadPerspective(default)