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