[adf44c2] | 1 | |
---|
| 2 | ################################################################################ |
---|
| 3 | #This software was developed by the University of Tennessee as part of the |
---|
| 4 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 5 | #project funded by the US National Science Foundation. |
---|
| 6 | # |
---|
| 7 | #See the license text in license.txt |
---|
| 8 | # |
---|
| 9 | #copyright 2009, University of Tennessee |
---|
| 10 | ################################################################################ |
---|
| 11 | import wx |
---|
| 12 | import os |
---|
| 13 | import sys |
---|
| 14 | import copy |
---|
| 15 | #import sans.guiframe.gui_manager as gui |
---|
| 16 | from sans.guiframe.events import StatusEvent |
---|
| 17 | from sans.guiframe.gui_style import GUIFRAME |
---|
[026041c] | 18 | from sans.guiframe import gui_manager as CURRENT |
---|
[493c90c] | 19 | from sans.guiframe.customdir import SetupCustom |
---|
[adf44c2] | 20 | # default configuration |
---|
[bf0acea] | 21 | DEFAULT_STRINGS = {'GUIFRAME_WIDTH':-1, |
---|
| 22 | 'GUIFRAME_HEIGHT':-1, |
---|
| 23 | 'PLOPANEL_WIDTH':-1, |
---|
| 24 | 'DATAPANEL_WIDTH':-1, |
---|
[adf44c2] | 25 | 'DATALOADER_SHOW':True, |
---|
| 26 | 'TOOLBAR_SHOW':True, |
---|
| 27 | 'FIXED_PANEL':True, |
---|
| 28 | 'WELCOME_PANEL_SHOW':False, |
---|
[f2d9e76] | 29 | 'CLEANUP_PLOT':False, |
---|
[c994f8f] | 30 | 'DEFAULT_PERSPECTIVE':'Fitting', |
---|
| 31 | 'DEFAULT_OPEN_FOLDER': None} |
---|
[026041c] | 32 | try: |
---|
| 33 | CURRENT_STRINGS = {'GUIFRAME_WIDTH':CURRENT.GUIFRAME_WIDTH, |
---|
| 34 | 'GUIFRAME_HEIGHT':CURRENT.GUIFRAME_HEIGHT, |
---|
| 35 | 'PLOPANEL_WIDTH':CURRENT.PLOPANEL_WIDTH, |
---|
| 36 | 'DATAPANEL_WIDTH':CURRENT.DATAPANEL_WIDTH, |
---|
| 37 | 'DATALOADER_SHOW':CURRENT.DATALOADER_SHOW, |
---|
| 38 | 'TOOLBAR_SHOW':CURRENT.TOOLBAR_SHOW, |
---|
| 39 | 'FIXED_PANEL':CURRENT.FIXED_PANEL, |
---|
| 40 | 'WELCOME_PANEL_SHOW':CURRENT.WELCOME_PANEL_SHOW, |
---|
| 41 | 'CLEANUP_PLOT':CURRENT.CLEANUP_PLOT, |
---|
[c994f8f] | 42 | 'DEFAULT_PERSPECTIVE':CURRENT.DEFAULT_PERSPECTIVE, |
---|
| 43 | 'DEFAULT_OPEN_FOLDER':CURRENT.DEFAULT_OPEN_FOLDER} |
---|
[026041c] | 44 | except: |
---|
| 45 | CURRENT_STRINGS = DEFAULT_STRINGS |
---|
| 46 | |
---|
[adf44c2] | 47 | if sys.platform.count("win32") > 0: |
---|
| 48 | PANEL_WIDTH = 265 |
---|
| 49 | PANEL_HEIGHT = 235 |
---|
| 50 | FONT_VARIANT = 0 |
---|
| 51 | else: |
---|
| 52 | PANEL_WIDTH = 285 |
---|
| 53 | PANEL_HEIGHT = 255 |
---|
| 54 | FONT_VARIANT = 1 |
---|
| 55 | |
---|
| 56 | """ |
---|
| 57 | Dialog to set Appication startup configuration |
---|
| 58 | """ |
---|
| 59 | class StartupConfiguration(wx.Dialog): |
---|
| 60 | """ |
---|
| 61 | Dialog for Startup Configuration |
---|
| 62 | """ |
---|
| 63 | def __init__(self, parent, gui, id=-1, title="Startup Setting"): |
---|
| 64 | wx.Dialog.__init__(self, parent, id, title, |
---|
| 65 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
| 66 | # parent |
---|
| 67 | self.parent = parent |
---|
[493c90c] | 68 | self.path = SetupCustom().find_dir() |
---|
[adf44c2] | 69 | self._gui = gui |
---|
| 70 | # font size |
---|
| 71 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
[026041c] | 72 | self.current_string = copy.deepcopy(CURRENT_STRINGS) |
---|
[c994f8f] | 73 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
[adf44c2] | 74 | # build layout |
---|
| 75 | panel = wx.Panel(self, -1) |
---|
| 76 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[9d8f193] | 77 | wx.StaticBox(panel, -1, 'Set View-Configuration', (5, 5), |
---|
[adf44c2] | 78 | (PANEL_WIDTH*0.94, PANEL_HEIGHT*0.7)) |
---|
| 79 | default_bt = wx.RadioButton(panel, -1, 'Default View', (15, 30), |
---|
| 80 | style=wx.RB_GROUP) |
---|
| 81 | default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnDefault) |
---|
| 82 | default_bt.SetValue(True) |
---|
| 83 | current_bt = wx.RadioButton(panel, -1, 'Current View', (15, 55)) |
---|
| 84 | current_bt.SetValue(False) |
---|
| 85 | current_bt.Bind(wx.EVT_RADIOBUTTON, self.OnCurrent) |
---|
[657e52c] | 86 | msg = "\nThis new configuration will take effect when\n" |
---|
| 87 | msg += "running this application next time." |
---|
[adf44c2] | 88 | note_txt = wx.StaticText(panel, -1, msg, (15, 75)) |
---|
[b3de12a4] | 89 | note_txt.SetForegroundColour("black") |
---|
[adf44c2] | 90 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 91 | cancelButton = wx.Button(self, -1, 'Cancel', size=(70, 25)) |
---|
| 92 | hbox.Add(cancelButton, 1, wx.RIGHT, 5) |
---|
| 93 | cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel) |
---|
| 94 | okButton = wx.Button(self, -1, 'OK', size=(70, 25)) |
---|
| 95 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
| 96 | okButton.Bind(wx.EVT_BUTTON, self.OnClose) |
---|
| 97 | vbox.Add(panel) |
---|
| 98 | |
---|
| 99 | vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.RIGHT | wx.BOTTOM, 5) |
---|
| 100 | # set sizer |
---|
| 101 | self.SetSizer(vbox) |
---|
| 102 | #pos = self.parent.GetPosition() |
---|
| 103 | #self.SetPosition(pos) |
---|
| 104 | |
---|
| 105 | def OnDefault(self, event=None): |
---|
| 106 | """ |
---|
| 107 | Set to default |
---|
| 108 | """ |
---|
| 109 | event.Skip() |
---|
| 110 | # event object and selection |
---|
[026041c] | 111 | self.return_string = copy.deepcopy(DEFAULT_STRINGS) |
---|
| 112 | return self.return_string |
---|
[adf44c2] | 113 | |
---|
| 114 | def OnCurrent(self, event=None): |
---|
| 115 | """ |
---|
| 116 | Set to curent setup |
---|
| 117 | """ |
---|
| 118 | event.Skip() |
---|
[2ad3601] | 119 | if self.parent.IsMaximized(): |
---|
| 120 | gui_pw, gui_ph = (0, 0) |
---|
| 121 | else: |
---|
[6306f2f] | 122 | gui_pw, gui_ph = self.parent.get_window_size() |
---|
[adf44c2] | 123 | self.current_string['GUIFRAME_WIDTH'] = gui_pw |
---|
| 124 | self.current_string['GUIFRAME_HEIGHT'] = gui_ph |
---|
| 125 | try: |
---|
| 126 | p_size = None |
---|
| 127 | for panel in self.parent.plot_panels.values(): |
---|
[f2d9e76] | 128 | p_panel = self.parent._mgr.GetPane(panel.window_name) |
---|
| 129 | if p_panel.IsShown(): |
---|
| 130 | if p_size == None or panel.size > p_size: |
---|
| 131 | p_size = panel.size |
---|
[adf44c2] | 132 | if p_size == None: |
---|
[026041c] | 133 | p_size = CURRENT_STRINGS['PLOPANEL_WIDTH'] |
---|
[adf44c2] | 134 | self.current_string['PLOPANEL_WIDTH'] = p_size |
---|
| 135 | |
---|
| 136 | data_pw, _ = self.parent.panels["data_panel"].GetSizeTuple() |
---|
| 137 | if data_pw == None: |
---|
[026041c] | 138 | data_pw = CURRENT_STRINGS['DATAPANEL_WIDTH'] |
---|
[adf44c2] | 139 | self.current_string['DATAPANEL_WIDTH'] = data_pw |
---|
| 140 | |
---|
[6eea960] | 141 | #label = self.parent._data_panel_menu.GetText() |
---|
| 142 | label = self.parent._mgr.GetPane(\ |
---|
| 143 | self.parent.panels['data_panel'].window_name).IsShown() |
---|
| 144 | if label:# == 'Hide Data Explorer': |
---|
[adf44c2] | 145 | self.current_string['DATALOADER_SHOW'] = True |
---|
| 146 | else: |
---|
| 147 | self.current_string['DATALOADER_SHOW'] = False |
---|
| 148 | |
---|
| 149 | if self.parent._toolbar.IsShown(): |
---|
| 150 | self.current_string['TOOLBAR_SHOW'] = True |
---|
| 151 | else: |
---|
| 152 | self.current_string['TOOLBAR_SHOW'] = False |
---|
| 153 | |
---|
| 154 | style = self._gui & GUIFRAME.FLOATING_PANEL |
---|
| 155 | if style == GUIFRAME.FLOATING_PANEL: |
---|
| 156 | self.current_string['FIXED_PANEL'] = False |
---|
| 157 | else: |
---|
| 158 | self.current_string['FIXED_PANEL'] = True |
---|
| 159 | |
---|
| 160 | if self.parent._mgr.GetPane(self.parent.panels['default'].window_name).IsShown(): |
---|
| 161 | self.current_string['WELCOME_PANEL_SHOW'] = True |
---|
| 162 | else: |
---|
| 163 | self.current_string['WELCOME_PANEL_SHOW'] = False |
---|
[f2d9e76] | 164 | self.current_string['CLEANUP_PLOT'] = \ |
---|
| 165 | self.parent.cleanup_plots |
---|
[adf44c2] | 166 | perspective = self.parent.get_current_perspective() |
---|
[c994f8f] | 167 | self.current_string['DEFAULT_PERSPECTIVE'] =\ |
---|
| 168 | str(perspective.sub_menu) |
---|
| 169 | location = '' |
---|
| 170 | temp = self.parent._default_save_location.split("\\") |
---|
| 171 | for strings in temp: |
---|
| 172 | location += (strings + "/") |
---|
| 173 | self.current_string['DEFAULT_OPEN_FOLDER'] = location |
---|
| 174 | #self.parent._default_save_location.ascii_letters |
---|
[adf44c2] | 175 | |
---|
| 176 | except: |
---|
| 177 | raise |
---|
| 178 | # event object and selection |
---|
[026041c] | 179 | self.return_string = self.current_string |
---|
| 180 | return self.return_string |
---|
[adf44c2] | 181 | |
---|
| 182 | def OnCancel(self, event): |
---|
| 183 | """ |
---|
| 184 | Close event |
---|
| 185 | """ |
---|
| 186 | # clear event |
---|
| 187 | event.Skip() |
---|
[026041c] | 188 | self.return_string = {} |
---|
[adf44c2] | 189 | self.Destroy() |
---|
| 190 | |
---|
| 191 | def OnClose(self, event): |
---|
| 192 | """ |
---|
| 193 | Close event |
---|
| 194 | """ |
---|
| 195 | # clear event |
---|
| 196 | event.Skip() |
---|
| 197 | fname = os.path.join(self.path, 'custom_config.py') |
---|
[026041c] | 198 | self.write_string(fname, self.return_string) |
---|
[adf44c2] | 199 | |
---|
| 200 | self.Destroy() |
---|
| 201 | |
---|
| 202 | def write_string(self, fname, strings): |
---|
| 203 | """ |
---|
| 204 | Write and Save file |
---|
| 205 | """ |
---|
| 206 | |
---|
| 207 | try: |
---|
| 208 | out_f = open(fname,'w') |
---|
| 209 | except : |
---|
| 210 | raise #RuntimeError, "Error: Can not change the configuration..." |
---|
| 211 | out_f.write("#Application appearance custom configuration\n" ) |
---|
| 212 | for key, item in strings.iteritems(): |
---|
[c994f8f] | 213 | if (key == 'DEFAULT_PERSPECTIVE') or \ |
---|
| 214 | (key == 'DEFAULT_OPEN_FOLDER' and item != None): |
---|
| 215 | out_f.write("%s = \"%s\"\n" % (key,str(item))) |
---|
[adf44c2] | 216 | else: |
---|
| 217 | out_f.write("%s = %s\n" % (key,str(item))) |
---|
| 218 | |
---|
[026041c] | 219 | out_f.close() |
---|
| 220 | |
---|