-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxmtusaxs_root_josh.py
1051 lines (951 loc) · 46 KB
/
wxmtusaxs_root_josh.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
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
#Boa:Frame:root
#*************************************************************************
# Copyright (c) 2009-2010 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2009-2010 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# This file is distributed subject to a Software License Agreement found
# in the file LICENSE that is included with this distribution.
#*************************************************************************
'''wxmtusaxs_root: Define the GUI elements and interface (this is the main code)
########### SVN repository information ###################
# $Date: 2015-03-16 15:02:28 -0500 (Mon, 16 Mar 2015) $
# $Author: ilavsky $
# $Revision: 1235 $
# $URL: https://subversion.xray.aps.anl.gov/small_angle/USAXS/wxmtusaxs/trunk/wxmtusaxs_root_josh.py $
# $Id: wxmtusaxs_root_josh.py 1235 2015-03-16 20:02:28Z ilavsky $
########### SVN repository information ###################
@note: for an undo example, see: http://wiki.wxpython.org/AnotherTutorial
'''
import os, datetime, copy, inspect, wx
from wx.lib.wordwrap import wordwrap
import wxmtusaxs_pair
import wxmtusaxs_tab
import wxmtusaxs_row
import wxmtusaxs_xml
import wxmtusaxs_pvsetup
import wxmtusaxs_version
import wxmtusaxs_htmlview
from wxmtusaxs_strings import USAXSStrings, SAXSStrings
def create(parent):
'''created by Boa-constructor'''
return root(parent)
#################################
### added methods ###
#################################
[wxID_ROOT, wxID_ROOTPAGEBOOK, wxID_ROOTSTATUSBAR1,
] = [wx.NewId() for _init_ctrls in range(3)]
[wxID_ROOTMENUFILECLOSE, wxID_ROOTMENUFILEEXIT, wxID_ROOTMENUFILEEXPORT,
wxID_ROOTMENUFILEIMPORT, wxID_ROOTMENUFILENEW, wxID_ROOTMENUFILEOPEN,
wxID_ROOTMENUFILEPREFERENCES, wxID_ROOTMENUFILESAVE, wxID_ROOTMENUFILESAVEAS,
wxID_ROOTMENUFILEEXPORTUSAXS, wxID_ROOTMENUFILEEXPORTSAXS,
] = [wx.NewId() for _init_coll_menuFile_Items in range(11)]
[wxID_ROOTMENUABOUTABOUT, wxID_ROOTMENUABOUTHELP,
] = [wx.NewId() for _init_coll_menuAbout_Items in range(2)]
[wxID_ROOTMENUPAGECHOICECHANGETABTITLE,
wxID_ROOTMENUPAGECHOICEDELETETAB, wxID_ROOTMENUPAGECHOICENEWROW,
wxID_ROOTMENUPAGECHOICENEWTAB,
] = [wx.NewId() for _init_coll_menuPage_Items in range(4)]
[wxID_ROOTMENUPAGECHOICECHANGEPAIRTITLE,
wxID_ROOTMENUPAGECHOICEDELETEPAIR,
wxID_ROOTMENUPAGECHOICEEPICSCONFIG,
wxID_ROOTMENUPAGECHOICENEWPAIR,
] = [wx.NewId() for _init_coll_menuStaff_Items in range(4)]
[wxID_TOOLBARNEWTAB,
wxID_TOOLBARCHANGETABTITLE,
wxID_TOOLBARDELETETAB,
wxID_TOOLBARSAVE,
wxID_TOOLBAREXPORTUSAXS,
wxID_TOOLBAREXPORTSAXS,
wxID_TOOLBARNEWROW,
] = [wx.NewId() for _init_coll_toolbar_Items in range(7)]
class root(wx.Frame):
'''wxmtusaxs: Define the GUI elements and interface'''
# see: http://wiki.wxpython.org/BoaFAQ
_custom_classes = {'wx.Panel': ['XYpair']}
def _init_coll_menuBar1_Menus(self, parent):
# generated method, don't edit
parent.Append(menu=self.menuFile, title=u'File')
parent.Append(menu=self.menuEdit, title=u'Edit')
parent.Append(menu=self.menuPage, title=u'Page')
parent.Append(menu=self.menuAbout, title=u'About')
parent.Append(menu=self.menuStaff, title=u'Staff')
def _init_coll_menuStaff_Items(self, parent):
parent.Append(help='Create settings for a new X,Y pair of EPICS motors',
id=wxID_ROOTMENUPAGECHOICENEWPAIR, kind=wx.ITEM_NORMAL,
text='Create New X,Y pair\tCtrl+p')
parent.Append(help=u'Delete settings for a new X,Y pair of EPICS motors',
id=wxID_ROOTMENUPAGECHOICEDELETEPAIR, kind=wx.ITEM_NORMAL,
text='Delete this X,Y pair\tCtrl+Shift+p')
parent.Append(help=u'Change the title for this X,Y pair',
id=wxID_ROOTMENUPAGECHOICECHANGEPAIRTITLE, kind=wx.ITEM_NORMAL,
text='Change X,Y pair title\tCtrl+Shift+m')
parent.AppendSeparator()
parent.Append(help='Configure the EPICS PVs for this X,Y pair',
id=wxID_ROOTMENUPAGECHOICEEPICSCONFIG, kind=wx.ITEM_NORMAL,
text=u'EPICS configuration')
parent.AppendSeparator()
parent.Append(help=u'Import Row data (label, x, y) from a tab-separated file',
id=wxID_ROOTMENUFILEIMPORT, kind=wx.ITEM_NORMAL,
text=u'Import Rows ...\tCtrl+i')
parent.Append(help=u'Export Row data (label, x, y) to a tab-separated file',
id=wxID_ROOTMENUFILEEXPORT, kind=wx.ITEM_NORMAL,
text=u'Export Rows ...\tCtrl+e')
parent.Append(help='Manage the program defaults',
id=wxID_ROOTMENUFILEPREFERENCES, kind=wx.ITEM_NORMAL,
text='Preferences ...\tAlt+p')
parent.AppendSeparator()
self.Bind(wx.EVT_MENU, self.OnMenuPageChoicenewpairMenu,
id=wxID_ROOTMENUPAGECHOICENEWPAIR)
self.Bind(wx.EVT_MENU, self.OnMenuPageChoicedeletepairMenu,
id=wxID_ROOTMENUPAGECHOICEDELETEPAIR)
self.Bind(wx.EVT_MENU, self.OnMenuPageChoicechangetitleMenu,
id=wxID_ROOTMENUPAGECHOICECHANGEPAIRTITLE)
self.Bind(wx.EVT_MENU, self.OnMenuPageChoiceepicsconfigMenu,
id=wxID_ROOTMENUPAGECHOICEEPICSCONFIG)
self.Bind(wx.EVT_MENU, self.OnMenuFilePreferencesMenu,
id=wxID_ROOTMENUFILEPREFERENCES)
self.Bind(wx.EVT_MENU, self.OnMenuFileExportMenu,
id=wxID_ROOTMENUFILEEXPORT)
self.Bind(wx.EVT_MENU, self.OnMenuFileImportMenu,
id=wxID_ROOTMENUFILEIMPORT)
def _init_coll_menuPage_Items(self, parent):
# generated method, don't edit
parent.Append(help='Create a new tab of settings for this X,Y pair of EPICS motors',
id=wxID_ROOTMENUPAGECHOICENEWTAB, kind=wx.ITEM_NORMAL,
text='Create new tab\tCtrl+t')
parent.Append(help='Delete this tab of settings for this X,Y pair of EPICS motors',
id=wxID_ROOTMENUPAGECHOICEDELETETAB, kind=wx.ITEM_NORMAL,
text='Delete tab\tCtrl+Shift+t')
parent.Append(help='', id=wxID_ROOTMENUPAGECHOICECHANGETABTITLE,
kind=wx.ITEM_NORMAL, text='Change tab title\tCtrl+m')
parent.AppendSeparator()
parent.Append(help='Create a new row for settings for this X,Y pair of EPICS motors',
id=wxID_ROOTMENUPAGECHOICENEWROW, kind=wx.ITEM_NORMAL,
text='Create new row\tCtrl+r')
self.Bind(wx.EVT_MENU, self.OnMenuPageChoicenewrowMenu,
id=wxID_ROOTMENUPAGECHOICENEWROW)
self.Bind(wx.EVT_MENU, self.OnMenuPageChoicenewtabMenu,
id=wxID_ROOTMENUPAGECHOICENEWTAB)
self.Bind(wx.EVT_MENU, self.OnMenuPageChoicedeletetabMenu,
id=wxID_ROOTMENUPAGECHOICEDELETETAB)
self.Bind(wx.EVT_MENU, self.OnMenuPageChoicechangetabtitleMenu,
id=wxID_ROOTMENUPAGECHOICECHANGETABTITLE)
def _init_coll_menuFile_Items(self, parent):
# generated method, don't edit
parent.Append(help=u'Create a new set', id=wxID_ROOTMENUFILENEW,
kind=wx.ITEM_NORMAL, text=u'New\tCtrl+n')
parent.Append(help=u'Open a configuration file',
id=wxID_ROOTMENUFILEOPEN, kind=wx.ITEM_NORMAL,
text=u'Open ...\tCtrl+o')
parent.Append(help=u'Close the current file', id=wxID_ROOTMENUFILECLOSE,
kind=wx.ITEM_NORMAL, text=u'Close\tCtrl+w')
parent.AppendSeparator()
parent.Append(help=u'Record the settings to the current file',
id=wxID_ROOTMENUFILESAVE, kind=wx.ITEM_NORMAL,
text=u'Save\tCtrl+s')
parent.Append(help=u'Choose a file to record the settings',
id=wxID_ROOTMENUFILESAVEAS, kind=wx.ITEM_NORMAL,
text=u'Save As ...\tCtrl+Shift+s')
parent.AppendSeparator()
parent.Append(help=u'Export usaxs.mac file',
id=wxID_ROOTMENUFILEEXPORTUSAXS, kind=wx.ITEM_NORMAL,
text=u'Export usaxs macro ...\tCtrl+Shift+e')
parent.Append(help=u'Export saxs.py file',
id=wxID_ROOTMENUFILEEXPORTSAXS, kind=wx.ITEM_NORMAL,
text=u'Export saxs Python ...\tCtrl+Alt+Shift+e')
parent.AppendSeparator()
parent.Append(help=u'Quit the wxmtusaxs application',
id=wxID_ROOTMENUFILEEXIT, kind=wx.ITEM_NORMAL, text=u'Exit')
self.Bind(wx.EVT_MENU, self.OnMenuFileExitMenu,
id=wxID_ROOTMENUFILEEXIT)
self.Bind(wx.EVT_MENU, self.OnMenuFileCloseMenu,
id=wxID_ROOTMENUFILECLOSE)
self.Bind(wx.EVT_MENU, self.OnMenuFileNewMenu, id=wxID_ROOTMENUFILENEW)
self.Bind(wx.EVT_MENU, self.OnMenuFileOpenMenu,
id=wxID_ROOTMENUFILEOPEN)
self.Bind(wx.EVT_MENU, self.OnMenuFileSaveMenu,
id=wxID_ROOTMENUFILESAVE)
self.Bind(wx.EVT_MENU, self.OnMenuFileSaveasMenu,
id=wxID_ROOTMENUFILESAVEAS)
self.Bind(wx.EVT_MENU, self.OnMenuFileExportUsaxsMenu,
id=wxID_ROOTMENUFILEEXPORTUSAXS)
self.Bind(wx.EVT_MENU, self.OnMenuFileExportSaxsMenu,
id=wxID_ROOTMENUFILEEXPORTSAXS)
def _init_coll_menuAbout_Items(self, parent):
# generated method, don't edit
parent.Append(help=u'Not ready yet', id=wxID_ROOTMENUABOUTHELP,
kind=wx.ITEM_NORMAL, text=u'Help')
parent.Append(help=u'General information about wxmtusaxs',
id=wxID_ROOTMENUABOUTABOUT, kind=wx.ITEM_NORMAL,
text=u'About ...')
self.Bind(wx.EVT_MENU, self.ShowAbout, id=wxID_ROOTMENUABOUTABOUT)
self.Bind(wx.EVT_MENU, self.OnMenuAboutHelpMenu,
id=wxID_ROOTMENUABOUTHELP)
def _init_coll_statusBar1_Fields(self, parent):
# generated method, don't edit
parent.SetFieldsCount(1)
parent.SetStatusText(number=0, text=u'status')
parent.SetStatusWidths([-1])
def _init_coll_toolbar_Items(self, parent):
parent.AddLabelTool(wxID_TOOLBARNEWTAB, 'New Tab',wx.ArtProvider.GetBitmap(wx.ART_NEW),wx.NullBitmap,0,'New Tab')
parent.AddLabelTool(wxID_TOOLBARCHANGETABTITLE, 'Change Tab Title',wx.Bitmap('graphics/rename.png'),wx.NullBitmap,0,'Change Current Tab Title')
parent.AddLabelTool(wxID_TOOLBARDELETETAB, 'Delete Current Tab',wx.ArtProvider.GetBitmap(wx.ART_DELETE),wx.NullBitmap,0,'Delete Current Tab')
parent.AddSeparator();
parent.AddLabelTool(wxID_TOOLBARSAVE, 'Save',wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE),wx.NullBitmap,0,'Save Settings')
parent.AddLabelTool(wxID_TOOLBAREXPORTUSAXS, 'Export usaxs.mac',wx.Bitmap('graphics/export.png'),wx.NullBitmap,0,'Export Current Tab as usaxs.mac')
#parent.AddLabelTool(wxID_TOOLBAREXPORTSAXS, 'Export saxs.py',wx.Bitmap('graphics/export.png'),wx.NullBitmap,0,'Export Current Tab as saxs.py')
parent.AddSeparator();
parent.AddLabelTool(wxID_TOOLBARNEWROW, 'New Row', wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW),wx.NullBitmap,0,'Create new sample row')
self.Bind(wx.EVT_TOOL, self.OnMenuPageChoicenewtabMenu,
id=wxID_TOOLBARNEWTAB)
self.Bind(wx.EVT_TOOL, self.OnMenuPageChoicedeletetabMenu,
id=wxID_TOOLBARDELETETAB)
self.Bind(wx.EVT_TOOL, self.OnMenuPageChoicechangetabtitleMenu,
id=wxID_TOOLBARCHANGETABTITLE)
self.Bind(wx.EVT_TOOL, self.OnMenuFileSaveMenu,
id=wxID_TOOLBARSAVE)
self.Bind(wx.EVT_TOOL, self.OnMenuFileExportUsaxsMenu,
id=wxID_TOOLBAREXPORTUSAXS)
self.Bind(wx.EVT_TOOL, self.OnMenuFileExportSaxsMenu,
id=wxID_TOOLBAREXPORTSAXS)
self.Bind(wx.EVT_TOOL, self.OnMenuPageChoicenewrowMenu,
id=wxID_TOOLBARNEWROW)
#self.Create(self,parent,1)
def _init_utils(self):
# generated method, don't edit
self.menuFile = wx.Menu(title='')
self.menuEdit = wx.Menu(title='')
self.menuPage = wx.Menu(title='')
self.menuStaff = wx.Menu(title='')
self.menuAbout = wx.Menu(title='')
self.menuBar1 = wx.MenuBar()
toolbar = self.CreateToolBar()
self._init_coll_menuFile_Items(self.menuFile)
self._init_coll_menuStaff_Items(self.menuStaff)
self._init_coll_menuPage_Items(self.menuPage)
self._init_coll_menuAbout_Items(self.menuAbout)
self._init_coll_menuBar1_Menus(self.menuBar1)
self._init_coll_toolbar_Items(toolbar)
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_ROOT, name=u'root', parent=prnt,
pos=wx.Point(312, 25), size=wx.Size(500, 504),
style=wx.DEFAULT_FRAME_STYLE, title=u'wxmtusaxs')
self._init_utils()
self.SetClientSize(wx.Size(568, 470))
self.SetMinSize(wx.Size(568, 550))
self.SetMenuBar(self.menuBar1)
self.statusBar1 = wx.StatusBar(id=wxID_ROOTSTATUSBAR1,
name='statusBar1', parent=self, style=0)
self._init_coll_statusBar1_Fields(self.statusBar1)
self.SetStatusBar(self.statusBar1)
self.pagebook = wx.Notebook(id=wxID_ROOTPAGEBOOK, name=u'pagebook',
parent=self, pos=wx.Point(80, 0), size=wx.Size(488, 427), style=0)
self.pagebook.SetToolTipString(u'Each "page" describes a different X,Y pair of EPICS motors')
def __init__(self, parent, settingsFile = None):
'''This is the main application window and class.
@param parent: object that owns this window
@param settingsFile: [string] name of the XML file'''
self.paircounter = 0 # incrementing index to create page names
self._init_ctrls(parent)
self.title = self.GetTitle()
self._dirty(False) # settings need to be saved to a file if True
self.pwd = os.getcwd()
self.settingsFile = settingsFile
if self.settingsFile == None:
self.NewPair() # by default, make a starting space
else:
self.SetStatusText('opening: %s' % self.settingsFile)
self.OpenSettingsFile(self.settingsFile)
# disable these menu items until they are implemented
#self.menuAbout.FindItemById(wxID_ROOTMENUABOUTHELP).Enable(False)
self.menuStaff.FindItemById(wxID_ROOTMENUFILEEXPORT).Enable(False)
self.menuStaff.FindItemById(wxID_ROOTMENUFILEPREFERENCES).Enable(False)
# ################################
# ## added methods ###
# ################################
def PairHandler(self, thePair, theTab, theRow, command):
'''Callback function to handle a command from a pair
@param thePair: wxmtusaxs_pair.XYpair object
@param theTab: wxmtusaxs_tab.Tab object
@param theRow: wxmtusaxs_row.Row object
@param command: [string] action from Row button'''
commandSet = ['delete', 'set', 'go', 'stop']
if command not in commandSet:
self.SetStatusText('Unknown command: %s' % command)
return
if command == 'delete':
self.DeleteRow(thePair, theTab, theRow)
if command == 'set':
self.SetRow(thePair, theTab, theRow)
if command == 'go':
self.GoRow(thePair, theTab, theRow)
if command == 'stop':
self.StopPair(thePair)
def _dirty(self, state=True):
'''Declare the settings dirty (means that changes are unsaved)
@param state: [Boolean] True means there are unsaved changes'''
self.dirty = state
title = self.title
if state == True:
title = '* ' + title + ' *'
self.SetTitle(title)
def NewPair(self, newtab=True):
'''Create a page for a new X,Y pair
@param newtab: [Boolean] option to create a first tab'''
self.paircounter += 1 # unique for each new page
name = 'panel' + repr(self.paircounter)
text = 'pair ' + repr(self.paircounter)
panel = wxmtusaxs_pair.XYpair(name=name, parent=self.pagebook,
root=self, rootCallback=self.PairHandler, newtab=newtab)
self.pagebook.AddPage(imageId=-1, page=panel, select=True, text=text)
panel.SetPageTitle(text)
self.SetStatusText('Created page titled: %s' % text)
self.Layout()
self._dirty()
return panel
def GetPairText(self, pairnum):
'''@param pairnum: [int] index number of the XY_pair
@return: text of the pair numbered pairnum'''
return self.pagebook.GetPageText(pairnum)
def SetPairText(self, pairnum, text):
'''set the text of the pair numbered pairnum
@param pairnum: [int] index number of the XY_pair
@param text: [string] name of the XYpair'''
self.pagebook.SetPageText(pairnum, text)
panel = self.pagebook.GetPage(pairnum)
panel.SetPageTitle(text)
def DeletePairnum(self, pairnum):
'''Delete the selected X,Y pair and settings
@param pairnum: [int] index number of the XY_pair'''
try:
self.pagebook.DeletePage(pairnum)
except:
self.SetStatusText('Could not delete that pair')
def GetEpicsConfig(self, pairnum):
'''Return the EPICS PV configuration for the indexed X,Y pair
@param pairnum: [int] index number of the XY_pair'''
panel = self.pagebook.GetPage(pairnum)
config = panel.GetEpicsConfig()
return config
def SetEpicsConfig(self, pairnum, config):
'''Define the EPICS PVs for the indexed X,Y pair
@param pairnum: [int] index number of the XY_pair
@param config: Python dictionary of EPICS PV configuration'''
panel = self.pagebook.GetPage(pairnum)
panel.SetEpicsConfig(config)
panel.ConnectEpics()
def RequestConfirmation(self, command, text):
'''Present a dialog asking user to confirm step
@param command: [string] action to be confirmed
@param text: [string] message to user'''
# confirm this step
self.SetStatusText('Request Confirmation')
dlg = wx.MessageDialog(self, text,
'Confirm %s' % command,
wx.YES|wx.NO)
result = dlg.ShowModal()
dlg.Destroy() # destroy first
if result == wx.ID_YES:
self.SetStatusText('accepted request: %s' % command)
else:
self.SetStatusText('canceled request: %s' % command)
return result
def DeleteRow(self, thePair, theTab, theRow):
'''Process a 'delete' command from a row button
@param thePair: wxmtusaxs_pair.XYpair object
@param theTab: wxmtusaxs_tab.Tab object
@param theRow: wxmtusaxs_row.Row object'''
text = 'Delete row labeled: %s' % theRow.GetLabel()
# confirm this step
result = self.RequestConfirmation('Delete Row', text + '?')
if result != wx.ID_YES:
return
self.SetStatusText(text)
theTab.DeleteRow(theRow)
self._dirty()
def SetRow(self, thePair, theTab, theRow):
'''Process a 'set' command from a row button
@param thePair: wxmtusaxs_pair.XYpair object
@param theTab: wxmtusaxs_tab.Tab object
@param theRow: wxmtusaxs_row.Row object'''
text = theRow.GetLabel()
self.SetStatusText('Set X, Y on row labeled: %s' % text)
x, y = thePair.GetRbvXY()
theRow.SetXY(x, y)
if len(theRow.GetLabel().strip()) == 0:
t = datetime.datetime.now()
yyyymmdd = t.strftime("%Y-%m-%d")
hhmmss = t.strftime("%H:%M:%S")
theRow.SetLabel(yyyymmdd + ',' + hhmmss)
self._dirty()
def GoRow(self, thePair, theTab, theRow):
'''Process a 'go' command from a row button
@param thePair: wxmtusaxs_pair.XYpair object
@param theTab: wxmtusaxs_tab.Tab object
@param theRow: wxmtusaxs_row.Row object'''
text = theRow.GetLabel()
self.SetStatusText('Move EPICS motors on row labeled: %s' % text)
x_txt, y_txt = theRow.GetXY()
try:
x = float(x_txt)
y = float(y_txt)
except:
self.SetStatusText('X or Y not a number, will not move')
return
# identify EPICS motors and send them the move commands
thePair.MoveAxes(x, y)
title = thePair.GetPageTitle()
self.SetStatusText('Move %s to (%s, %s)' % (title, x_txt, y_txt))
def StopPair(self, thePair):
'''Process a 'stop' command from a stop button.
Need to stop the two associated positioners.
@param thePair: wxmtusaxs_pair.XYpair object'''
thePair.StopAxes()
title = thePair.GetPageTitle()
self.SetStatusText('Stop ' + title)
def ImportRows(self, rowfile):
'''Import a row file into the current tab (make a tab if none exists)
@param rowfile: [string] name of the 3-column tab-separated file'''
self.SetStatusText('file: %s' % rowfile)
try:
fp = open(rowfile, 'r')
buf = fp.read()
fp.close()
except:
self.SetStatusText('Could not read file: %s' % rowfile)
return
#
if self.pagebook.GetSelection() < 0:
self.NewPair(newtab=False) # need to make a new page
pagenum = self.pagebook.GetSelection()
pair = self.pagebook.GetPage(pagenum)
if pair.GetSelection() < 0:
pair.NewTab(newrow=False)
tabnum = pair.GetSelection()
tab = pair.table.GetPage(tabnum)
linenum = 0
for line in buf.strip().split('\n'):
linenum += 1
try:
label, x, y = line.strip().split('\t')
row = tab.NewRow()
row.SetLabel(label)
row.SetXY(x, y)
except:
self.SetStatusText('Problem with row: %d' % linenum)
tab.Remap() # adjust for changes
def OpenSettingsFile(self, settingsFile):
'''Open the named settings file and replace all the current settings
@param settingsFile: [string] name of the XML file'''
try:
rc = wxmtusaxs_xml.Settings(settingsFile)
result = rc.ReadXmlFile()
if result != None:
return result
except:
self.SetStatusText('Could not open: %s' % settingsFile)
return
# safe to proceed now
self.SetStatusText('Opened: %s' % settingsFile)
self.pagebook.DeleteAllPages()
self.settingsFile = settingsFile
selectedpairnum = rc.GetSelectedPair()
for pairnum in range(rc.CountPairs()):
pairnode = self.NewPair(newtab=False)
self.SetPairText(pairnum, rc.GetPairTitle(pairnum))
self.SetEpicsConfig(pairnum, rc.GetEpicsConfig(pairnum))
selectedtabnum = rc.GetSelectedTab(pairnum)
for tabnum in range(rc.CountTabs(pairnum)):
tabnode = pairnode.NewTab(newrow=False)
pairnode.SetTabText(tabnum, rc.GetTabTitle(pairnum, tabnum))
selectedrownum = rc.GetSelectedRow(pairnum, tabnum)
for rownum in range(rc.CountRows(pairnum, tabnum)):
label = rc.GetRowTitle(pairnum, tabnum, rownum)
x, y = rc.GetRowXY(pairnum, tabnum, rownum)
thickness = rc.GetRowThickness(pairnum,tabnum,rownum)
usaxsModeString = rc.GetRowUSAXSMode(pairnum, tabnum, rownum)
rownode = tabnode.NewRow()
rownode.SetLabel(label)
rownode.SetXY(x, y)
rownode.SetThickness(thickness)
rownode.SetUSAXSMode(usaxsModeString)
tabnode.Remap()
if selectedrownum >= 0:
# none of these work correctly in ScrolledPanel
#tabnode.ChangeSelection(selectedrownum)
#tabnode.Scroll(1, 1+selectedrownum*25)
#row = tabnode.sizer.GetItem(rownum).GetWindow()
#tabnode.ScrollChildIntoView(row)
pass
if selectedtabnum >= 0:
pairnode.table.ChangeSelection(selectedtabnum)
if selectedpairnum >= 0:
self.pagebook.ChangeSelection(selectedpairnum)
self._dirty(False)
def SaveSettingsFile(self, settingsFile):
'''Save the current settings to the named settings file
@param settingsFile: [string] name of the XML file'''
rc = wxmtusaxs_xml.Settings(settingsFile)
selectedpair = self.pagebook.GetSelection()
for pairnum in range(self.pagebook.GetPageCount()):
rc.NewPair(self.GetPairText(pairnum))
if selectedpair == pairnum:
rc.SelectPair(pairnum)
pair = self.pagebook.GetPage(pairnum)
config = self.GetEpicsConfig(pairnum)
rc.SetEpicsConfig(pairnum, config)
selectedtab = pair.GetSelection()
for tabnum in range(pair.table.GetPageCount()):
rc.NewTab(pairnum, pair.GetTabText(tabnum))
if selectedtab == tabnum:
rc.SelectTab(pairnum, tabnum)
tab = pair.table.GetPage(tabnum)
#selectedrow = tab.GetSelection()
for rownum in range(len(tab.GetChildren())):
rc.NewRow(pairnum, tabnum, tab.GetRowLabel(rownum))
x, y = tab.GetRowXY(rownum)
rc.SetRowXY(pairnum, tabnum, rownum, x, y)
thickness = tab.GetRowThickness(rownum)
rc.SetRowThickness(pairnum, tabnum, rownum, thickness)
usaxsModeString = tab.GetRowUSAXSMode(rownum)
rc.SetRowUSAXSMode(pairnum, tabnum, rownum, usaxsModeString)
rc.SetSettingsFile(settingsFile)
rc.SaveXmlFile()
self.settingsFile = settingsFile
self._dirty(False)
def is_number(self,s):
try:
float(s)
return True
except ValueError:
return False
def SaveUsaxsMacro(self, settingsFile):
'''Save the current tab to a USAXS spec macro
@param settingsFile: [string] name of the file'''
selectedpair = self.pagebook.GetSelection()
pair = self.pagebook.GetPage(selectedpair)
selectedtab = pair.GetSelection()
tab = pair.table.GetPage(selectedtab)
tabTitle = pair.GetTabText(selectedtab);
stringSet = USAXSStrings()
usaxsScanMacroHeader = stringSet.GetMacroHeaderPart1()
usaxsScanMacroHeader = usaxsScanMacroHeader + 'EXPERIMENT = "' + tabTitle + '"'
usaxsScanMacroHeader = usaxsScanMacroHeader + stringSet.GetMacroHeaderPart2()
usaxsSwitchover = stringSet.GetMacroUSAXSPinSwitch()
usaxsScanMacroFooter = stringSet.GetMacroFooter()
""" PAB -- fix requested by JIL to make generated macro human readable.
stores last parameters and does not repeat them if not needed.....
"""
lastExpTime = 0
lastNumExp = 0
lastUsaxsTime = 0
lastNumPnts = 0
lastFinish = 0
macroFile = open(settingsFile,'w')
macroFile.write(usaxsScanMacroHeader);
for rownum in range(len(tab.GetChildren())):
x, y = tab.GetRowXY(rownum);
name = tab.GetRowLabel(rownum);
thickness = tab.GetRowThickness(rownum);
if thickness == "":
thickness = "1"
if tab.GetRowDoPinhole(rownum):
if self.is_number(x) and self.is_number(y) and name != "":
if tab.GetRowExpTime(rownum) and tab.GetRowExpTime(rownum) != lastExpTime:
macroFile.write("\n set_PIN_EXP_TIME " + tab.GetRowExpTime(rownum) + "\n")
lastExpTime = tab.GetRowExpTime(rownum)
if tab.GetRowNoExp(rownum) and tab.GetRowNoExp(rownum) != lastNumExp:
macroFile.write("\n set_PIN_NUMEXP " + tab.GetRowNoExp(rownum) + "\n")
lastNumExp = tab.GetRowNoExp(rownum)
macroFile.write("\n pinholeExp " + x + " " + y + " " + thickness + " \"" + name + "\"\n");
#macroFile.write(usaxsSwitchover)
macroFile.write("\n #End of pinSAXS, next is WAXS \n")
for rownum in range(len(tab.GetChildren())):
x, y = tab.GetRowXY(rownum);
name = tab.GetRowLabel(rownum);
thickness = tab.GetRowThickness(rownum);
if thickness == "":
thickness = "1"
if tab.GetRowDoWAXS(rownum):
if self.is_number(x) and self.is_number(y) and name != "":
if tab.GetRowWExpTime(rownum) and tab.GetRowWExpTime(rownum) != lastExpTime:
macroFile.write("\n set_WAXS_EXP_TIME " + tab.GetRowWExpTime(rownum) + "\n")
lastExpTime = tab.GetRowWExpTime(rownum)
if tab.GetRowWNoExp(rownum) and tab.GetRowWNoExp(rownum) != lastNumExp:
macroFile.write("\n set_WAXS_NUMEXP " + tab.GetRowWNoExp(rownum) + "\n")
lastNumExp = tab.GetRowWNoExp(rownum)
macroFile.write("\n waxsExp " + x + " " + y + " " + thickness + " \"" + name + "\"\n");
#macroFile.write(usaxsSwitchover)
macroFile.write("\n #End of WAXS, next is USAXS \n")
for rownum in range(len(tab.GetChildren())):
x, y = tab.GetRowXY(rownum);
name = tab.GetRowLabel(rownum);
thickness = tab.GetRowThickness(rownum);
if thickness == "":
thickness = "1"
if tab.GetRowDoUSAXS(rownum):
if tab.GetRowDoFUSAXS(rownum)==True:
#macroFile.write("\n preUSAXStune; Flyscan " + x + " " + y + " " + thickness + " \"" + name + "\"\n");
elif tab.GetRowDoFUSAXS(rownum)==False:
if self.is_number(x) and self.is_number(y) and name != "":
if tab.GetRowCountTime(rownum) and tab.GetRowCountTime(rownum)!= lastUsaxsTime:
macroFile.write("\n set_USAXS_TIME " + tab.GetRowCountTime(rownum) + "\n")
lastUsaxsTime = tab.GetRowCountTime(rownum)
if tab.GetRowNumPts(rownum) and tab.GetRowNumPts(rownum) != lastNumPnts:
macroFile.write("\n set_NUMPNTS " + tab.GetRowNumPts(rownum) + "\n")
lastNumPnts = tab.GetRowNumPts(rownum)
if tab.GetRowMaxQ(rownum) and tab.GetRowMaxQ(rownum) != lastFinish:
macroFile.write("\n set_FINISH " + tab.GetRowNumPts(rownum) + "\n")
lastFinish = tab.GetRowMaxQ(rownum)
macroFile.write("\n preUSAXStune; USAXSscan " + x + " " + y + " " + thickness + " \"" + name + "\"\n");
#josh add flyscanwriting
#macroFile.write(usaxsScanMacroFooter);
#macroFile.close();
#def SaveSaxsMacro(self, settingsFile):
# '''Save the current tab to a SAXS python script
# @param settingsFile: [string] name of the file'''
# selectedpair = self.pagebook.GetSelection()
# pair = self.pagebook.GetPage(selectedpair)
# selectedtab = pair.GetSelection()
# tab = pair.table.GetPage(selectedtab)
# tabTitle = pair.GetTabText(selectedtab);
# stringSet = SAXSStrings()
# saxsScanMacroHeader = stringSet.GetMacroHeaderPart1()
# saxsScanMacroHeader = saxsScanMacroHeader + 'EXPERIMENT = "' + tabTitle + '"'
# saxsScanMacroHeader = saxsScanMacroHeader + stringSet.GetMacroHeaderPart2()
# saxsScanMacroFooter = stringSet.GetMacroFooter()
# macroFile = open(settingsFile,'w')
# macroFile.write(saxsScanMacroHeader);
# for rownum in range(len(tab.GetChildren())):
# x, y = tab.GetRowXY(rownum);
# name = tab.GetRowLabel(rownum);
# thickness = tab.GetRowThickness(rownum);
# if thickness == "":
# thickness = "_thickness_"
# if tab.GetRowDoPinhole(rownum):
# if tab.GetRowExpTime(rownum):
# exptime = tab.GetRowExpTime(rownum)
# else:
# exptime = "__time__"
# macroFile.write("\n pinhole.PinholeExp(" + x + "," + y + "," + exptime + " , \"" + name + "\" ," + thickness + ")\n");
# macroFile.write(saxsScanMacroFooter);
# macroFile.close();
def PostNotice(self, title, message, flags):
'''post a message dialog box
@param title: [string] window title bar
@param message: [string] message message text
@param flags: dialog box flags (such as wx.OK | wx.ICON_INFORMATION)'''
dlg = wx.MessageDialog(None, message, title, flags)
dlg.ShowModal()
dlg.Destroy()
# ################################
# ## event handling routines ###
# ################################
def ShowAbout(self, event):
'''describe this application
@param event: wxPython event object'''
# derived from http://wiki.wxpython.org/Using%20wxPython%20Demo%20Code
# First we create and fill the info object
info = wx.AboutDialogInfo()
info.Name = wxmtusaxs_version.__summary__
info.Version = wxmtusaxs_version.__version__
info.Copyright = wxmtusaxs_version.__copyright__
description = ''
for line in wxmtusaxs_version.__documentation__.strip().splitlines():
item = line.strip()
if len(item) > 0:
description += ' ' + line.strip()
else:
description += '\n\n'
info.Description = wordwrap(description, 400, wx.ClientDC(self))
URL = wxmtusaxs_version.__url__
info.WebSite = (URL, wxmtusaxs_version.__svndesc__)
author = wxmtusaxs_version.__author__
author += ", " + wxmtusaxs_version.__author_email__
others = [ "author: ", author ]
others.extend(wxmtusaxs_version.__contributor_credits__)
info.Developers = others
info.License = wxmtusaxs_version.__license__
# Then we call wx.AboutBox giving it the info object
wx.AboutBox(info)
def OnMenuFileNewMenu(self, event):
'''Requested new settings
@param event: wxPython event object'''
self.SetStatusText('Requested new settings')
if self.dirty:
# confirm this step
result = self.RequestConfirmation('New',
'There are unsaved changes. Create new settings anyway?')
if result != wx.ID_YES:
return
self.pagebook.DeleteAllPages()
self.NewPair()
self._dirty(False)
self.settingsFile = None
def OnMenuFileOpenMenu(self, event):
'''Requested to open XML settings file
@param event: wxPython event object'''
if self.dirty:
# confirm this step
result = self.RequestConfirmation('Open ...',
'There are unsaved changes. Open anyway?')
if result != wx.ID_YES:
return
#---
self.SetStatusText('Requested to open XML settings file')
wildcard = "XML files (*.xml)|*.xml|" \
"All files (*)|*"
instruction = "Choose an XML file with full settings." \
" (The selected file will be verified before it is loaded.)"
dlg = wx.FileDialog(None, instruction,
self.pwd, "", wildcard, wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.pwd = os.path.dirname(dlg.GetPath())
self.OpenSettingsFile(dlg.GetPath())
dlg.Destroy()
def OnMenuFileSaveMenu(self, event):
'''Requested to save settings to XML file
@param event: wxPython event object'''
if self.settingsFile == None:
self.OnMenuFileSaveasMenu(event)
else:
self.SaveSettingsFile(self.settingsFile)
def OnMenuFileSaveasMenu(self, event):
'''Requested to save settings to new XML file
@param event: wxPython event object'''
self.SetStatusText('Save current settings to XML file')
wildcard = "XML files (*.xml)|*.xml|" \
"All files (*)|*"
instruction = "Save current settings to XML file" \
" (either existing or new)"
dlg = wx.FileDialog(None, instruction,
self.pwd, "", wildcard, wx.SAVE|wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
self.pwd = os.path.dirname(filename)
self.SaveSettingsFile(filename)
dlg.Destroy()
self._dirty(False)
def OnMenuFileExportUsaxsMenu(self,event):
'''Requested to save current tab to a usaxs.mac file
@param event: wxPython event object'''
self.SetStatusText('Export current tab to spec macro')
wildcard = "spec macros (*.mac)|*.mac|" \
"All files (*) |*"
instruction = "Export current tab as USAXS spec macro"
now = datetime.datetime.now()
dlg=wx.FileDialog(None,instruction,"/data/USAXS_data/"+str(now.year)+"-"+str(now.month).zfill(2)+"/","usaxs.mac",wildcard,wx.SAVE|wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
self.pwd = os.path.dirname(filename)
self.SaveUsaxsMacro(filename)
dlg.Destroy()
def OnMenuFileExportSaxsMenu(self,event):
'''Requested to save current tab to a saxs.py file
@param event: wxPython event object'''
self.SetStatusText('Export current tab to spec macro')
wildcard = "python files (*.py)|*.py|" \
"All files (*) |*"
instruction = "Export current tab as SAXS python script"
now = datetime.datetime.now()
dlg=wx.FileDialog(None,instruction,"/data/SAXS/"+str(now.year)+"-"+str(now.month).zfill(2)+"/","saxs.py",wildcard,wx.SAVE|wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
self.pwd = os.path.dirname(filename)
self.SaveSaxsMacro(filename)
dlg.Destroy()
def OnMenuFileCloseMenu(self, event):
'''User requested to close the settings file
@param event: wxPython event object'''
if self.pagebook.GetPageCount() > 0:
if self.dirty:
# confirm this step
result = self.RequestConfirmation('Close All',
'There are unsaved changes. Close All anyway?')
if result != wx.ID_YES:
return
self.SetStatusText('Close All requested')
self.pagebook.DeleteAllPages()
else:
self.SetStatusText('Nothing to close')
self._dirty(False)
def OnMenuFileImportMenu(self, event):
'''user requested to import a table of settings from a file
@param event: wxPython event object'''
wildcard = "text files (*.txt)|*.txt|" \
"All fifles (*)|*"
instruction = "Choose a file with row settings"
dlg = wx.FileDialog(None, instruction,
self.pwd, "", wildcard, wx.OPEN)
# what about changing self.pwd here?
if dlg.ShowModal() == wx.ID_OK:
self.pwd = os.path.dirname(dlg.GetPath())
self.ImportRows(dlg.GetPath())
dlg.Destroy()
def OnMenuFileExportMenu(self, event):
'''user requested to export a Tab
@param event: wxPython event object
@note: Not implemented yet'''
event.Skip()
def OnMenuFilePreferencesMenu(self, event):
'''user requested to view/edit preferences
@param event: wxPython event object
@note: Not implemented yet'''
self.SetStatusText('Requested to edit Preferences')
self.PostNotice("Construction Zone!",
"'Preferences ...' menu item not implemented yet.",
wx.OK | wx.ICON_INFORMATION)
def OnMenuFileExitMenu(self, event):
'''User requested to quit the application
@param event: wxPython event object'''
if self.dirty:
# confirm this step
result = self.RequestConfirmation('Exit (Quit)',
'There are unsaved changes. Exit (Quit) anyway?')
if result != wx.ID_YES:
return
self.Close()
def OnMenuPageChoicenewpairMenu(self, event):
'''User requested a new X,Y pair
@param event: wxPython event object'''
self.NewPair()
self._dirty()
def OnMenuPageChoicedeletepairMenu(self, event):
'''User requested to delete the X,Y pair
@param event: wxPython event object'''
pagenum = self.pagebook.GetSelection()
if pagenum < 0:
self.SetStatusText('no page to delete')
return
text = self.pagebook.GetPageText(pagenum)
# confirm this step
requestText = 'Delete X,Y page [%s]?' % text
result = self.RequestConfirmation('Delete X,Y page?',
requestText)
if result == wx.ID_YES:
self.DeletePairnum(pagenum)
self.SetStatusText('page was deleted')
self._dirty()
def OnMenuPageChoicechangetitleMenu(self, event):
'''User requested to change the page title
@param event: wxPython event object'''
pagenum = self.pagebook.GetSelection()
if pagenum >= 0:
self.SetStatusText('requested X,Y page name change')
response = wx.GetTextFromUser(parent=self,
message='Rename this page of settings:',
caption='Rename this page',
default_value=self.pagebook.GetPageText(pagenum))
if len(response) > 0:
self.SetStatusText('New page title: %s' % response)
self.SetPairText(pagenum, response)
self._dirty()
else:
self.SetStatusText('Rename was canceled')
else:
self.SetStatusText('no page to rename')
def OnMenuPageChoicenewtabMenu(self, event):
'''user requested a new tab
@param event: wxPython event object'''
pagenum = self.pagebook.GetSelection()
if pagenum < 0:
self.SetStatusText('No pages now! Cannot create a tab.')
return # early
pair = self.pagebook.GetPage(pagenum)
pair.NewTab()
self.SetStatusText('Created new tab.')
self._dirty()
def OnMenuPageChoicedeletetabMenu(self, event):
'''user requested to delete a tab
@param event: wxPython event object'''
pagenum = self.pagebook.GetSelection()
if pagenum < 0:
self.SetStatusText('No pages now! Cannot delete a tab.')
return # early
pair = self.pagebook.GetPage(pagenum)
tabnum = pair.GetSelection()
if tabnum < 0:
self.SetStatusText('No tab to delete.')
return
text = pair.GetTabText(tabnum)
# confirm this step
requestText = 'Delete tab [%s]?' % text
result = self.RequestConfirmation('Delete tab?',
requestText)
if result == wx.ID_YES:
self.SetStatusText(pair.DeleteTab())
self._dirty()
def OnMenuPageChoicechangetabtitleMenu(self, event):
'''user requested to rename tab
@param event: wxPython event object'''
pagenum = self.pagebook.GetSelection()
if pagenum < 0:
self.SetStatusText('No pages now! Cannot rename a tab.')
return # early
pair = self.pagebook.GetPage(pagenum)
tabnum = pair.GetSelection()
if tabnum < 0:
self.SetStatusText('No tab to rename.')
return
text = pair.GetTabText(tabnum)
self.SetStatusText('requested tab name change')
response = wx.GetTextFromUser(parent=self,
message='Rename this tab:',
caption='Rename this tab',
default_value=text)
if len(response) > 0:
self.SetStatusText('New tab name: %s' % response)
pair.SetTabText(tabnum, response)
self._dirty()
else: