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