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