[24adb89] | 1 | """ |
---|
| 2 | Implement grid used to store data |
---|
| 3 | """ |
---|
| 4 | import wx |
---|
| 5 | import numpy |
---|
[904830e] | 6 | import math |
---|
| 7 | import re |
---|
[850525c] | 8 | import os |
---|
[24adb89] | 9 | import sys |
---|
[7ad194fa] | 10 | import copy |
---|
[24adb89] | 11 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
| 12 | import wx.grid as Grid |
---|
| 13 | import wx.aui |
---|
| 14 | from wx.aui import AuiNotebook as nb |
---|
| 15 | import wx.lib.sheet as sheet |
---|
[1c86a37] | 16 | from sans.guiframe.panel_base import PanelBase |
---|
| 17 | from sans.guiframe.utils import format_number |
---|
[24adb89] | 18 | from sans.guiframe.events import NewPlotEvent |
---|
| 19 | from sans.guiframe.events import StatusEvent |
---|
[fe98127] | 20 | from danse.common.plottools import plottables |
---|
[24adb89] | 21 | from sans.guiframe.dataFitting import Data1D |
---|
| 22 | |
---|
[904830e] | 23 | FUNC_DICT = {"sqrt": "math.sqrt", |
---|
| 24 | "pow": "math.sqrt"} |
---|
[73197d0] | 25 | |
---|
[5425990] | 26 | class BatchCell: |
---|
| 27 | """ |
---|
| 28 | Object describing a cell in the grid. |
---|
| 29 | |
---|
| 30 | """ |
---|
| 31 | def __init__(self): |
---|
| 32 | self.label = "" |
---|
| 33 | self.value = None |
---|
| 34 | self.col = -1 |
---|
| 35 | self.row = -1 |
---|
[75790dc] | 36 | self.object = [] |
---|
[5425990] | 37 | |
---|
[73197d0] | 38 | |
---|
[904830e] | 39 | def parse_string(sentence, list): |
---|
| 40 | """ |
---|
| 41 | Return a dictionary of column label and index or row selected |
---|
| 42 | :param sentence: String to parse |
---|
| 43 | :param list: list of columns label |
---|
| 44 | """ |
---|
| 45 | toks = [] |
---|
| 46 | p2 = re.compile(r'\d+') |
---|
| 47 | p = re.compile(r'[\+\-\*\%\/]') |
---|
| 48 | labels = p.split(sentence) |
---|
| 49 | col_dict = {} |
---|
| 50 | for elt in labels: |
---|
| 51 | rang = None |
---|
| 52 | temp_arr = [] |
---|
| 53 | for label in list: |
---|
| 54 | label_pos = elt.find(label) |
---|
| 55 | if label_pos != -1: |
---|
| 56 | if elt.count(',') > 0: |
---|
| 57 | new_temp = [] |
---|
| 58 | temp = elt.split(label) |
---|
| 59 | for item in temp: |
---|
| 60 | range_pos = item.find(":") |
---|
| 61 | if range_pos != -1: |
---|
| 62 | rang = p2.findall(item) |
---|
| 63 | for i in xrange(int(rang[0]), int(rang[1])+1 ): |
---|
| 64 | new_temp.append(i) |
---|
| 65 | temp_arr += new_temp |
---|
| 66 | else: |
---|
| 67 | temp = elt.split(label) |
---|
| 68 | for item in temp: |
---|
| 69 | range_pos = item.find(":") |
---|
| 70 | if range_pos != -1: |
---|
| 71 | rang = p2.findall(item) |
---|
| 72 | for i in xrange(int(rang[0]), int(rang[1])+1 ): |
---|
| 73 | temp_arr.append(i) |
---|
| 74 | col_dict[elt] = (label, temp_arr) |
---|
| 75 | return col_dict |
---|
[24adb89] | 76 | |
---|
[f4b37d1] | 77 | |
---|
| 78 | |
---|
| 79 | class SPanel(ScrolledPanel): |
---|
| 80 | def __init__(self, parent, *args, **kwds): |
---|
| 81 | ScrolledPanel.__init__(self, parent , *args, **kwds) |
---|
| 82 | self.SetupScrolling() |
---|
| 83 | |
---|
[24adb89] | 84 | class GridPage(sheet.CSheet): |
---|
[9c8f3ad] | 85 | """ |
---|
| 86 | """ |
---|
[24adb89] | 87 | def __init__(self, parent, panel=None): |
---|
| 88 | """ |
---|
| 89 | """ |
---|
| 90 | sheet.CSheet.__init__(self, parent) |
---|
[f4b37d1] | 91 | |
---|
| 92 | self.AdjustScrollbars() |
---|
| 93 | #self.SetLabelBackgroundColour('#DBD4D4') |
---|
[fd51a7c] | 94 | self.uid = wx.NewId() |
---|
[f4b37d1] | 95 | self.parent = parent |
---|
[24adb89] | 96 | self.panel = panel |
---|
| 97 | self.col_names = [] |
---|
[8523a1f2] | 98 | self.data_inputs = {} |
---|
| 99 | self.data_outputs = {} |
---|
[d03a356] | 100 | self.data = None |
---|
[71fa9028] | 101 | self.details = "" |
---|
| 102 | self.file_name = None |
---|
[9c8f3ad] | 103 | self._cols = 50 |
---|
| 104 | self._rows = 51 |
---|
[63dc6e5] | 105 | self.last_selected_row = -1 |
---|
| 106 | self.last_selected_col = -1 |
---|
[1c86a37] | 107 | self.col_width = 30 |
---|
| 108 | self.row_height = 20 |
---|
[656d65d] | 109 | self.max_row_touse = 0 |
---|
[49ad00b] | 110 | self.axis_value = [] |
---|
| 111 | self.axis_label = "" |
---|
| 112 | self.selected_cells = [] |
---|
| 113 | self.selected_cols = [] |
---|
[75790dc] | 114 | self.selected_rows = [] |
---|
| 115 | self.plottable_cells = [] |
---|
[63dc6e5] | 116 | self.plottable_flag = False |
---|
[1c86a37] | 117 | self.SetColMinimalAcceptableWidth(self.col_width) |
---|
| 118 | self.SetRowMinimalAcceptableHeight(self.row_height) |
---|
[24adb89] | 119 | self.SetNumberRows(self._cols) |
---|
| 120 | self.SetNumberCols(self._rows) |
---|
[f4b37d1] | 121 | self.AutoSize() |
---|
[1c86a37] | 122 | self.default_col_width = 75 |
---|
| 123 | if self.GetNumberCols() > 0: |
---|
| 124 | self.default_col_width = self.GetColSize(0) |
---|
[49ad00b] | 125 | self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.on_left_click) |
---|
[24adb89] | 126 | self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_right_click) |
---|
[49ad00b] | 127 | self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.on_selected_cell) |
---|
[656d65d] | 128 | self.Bind(wx.grid.EVT_GRID_CMD_CELL_CHANGE, self.on_edit_cell) |
---|
[1c86a37] | 129 | |
---|
| 130 | |
---|
[656d65d] | 131 | def on_edit_cell(self, event): |
---|
| 132 | """ |
---|
| 133 | """ |
---|
| 134 | row, col = event.GetRow(), event.GetCol() |
---|
| 135 | if row > self.max_row_touse: |
---|
| 136 | self.max_row_touse = row |
---|
| 137 | event.Skip() |
---|
[49ad00b] | 138 | |
---|
| 139 | def on_selected_cell(self, event): |
---|
| 140 | """ |
---|
| 141 | Handler catching cell selection |
---|
| 142 | """ |
---|
| 143 | flag = event.CmdDown() or event.ControlDown() |
---|
[904830e] | 144 | row, col = event.GetRow(), event.GetCol() |
---|
| 145 | cell = (row, col) |
---|
[63dc6e5] | 146 | event.Skip() |
---|
[49ad00b] | 147 | if not flag: |
---|
| 148 | self.selected_cells = [] |
---|
[904830e] | 149 | self.axis_value = [] |
---|
| 150 | self.axis_label = "" |
---|
[63dc6e5] | 151 | if col >= 0: |
---|
| 152 | self.axis_label = self.GetCellValue(0, col) |
---|
[dadf255] | 153 | if cell not in self.selected_cells: |
---|
| 154 | if row > 0: |
---|
| 155 | self.selected_cells.append(cell) |
---|
[49ad00b] | 156 | else: |
---|
[dadf255] | 157 | if flag: |
---|
| 158 | self.selected_cells.remove(cell) |
---|
| 159 | self.axis_value = [] |
---|
| 160 | for cell_row, cell_col in self.selected_cells: |
---|
| 161 | if cell_row > 0 and cell_row < self.max_row_touse: |
---|
| 162 | self.axis_value.append(self.GetCellValue(cell_row, cell_col)) |
---|
[63dc6e5] | 163 | |
---|
[75790dc] | 164 | |
---|
[63dc6e5] | 165 | |
---|
[49ad00b] | 166 | def on_left_click(self, event): |
---|
| 167 | """ |
---|
| 168 | Catch the left click on label mouse event |
---|
| 169 | """ |
---|
[647df0d1] | 170 | event.Skip() |
---|
[49ad00b] | 171 | flag = event.CmdDown() or event.ControlDown() |
---|
| 172 | col = event.GetCol() |
---|
[63dc6e5] | 173 | row = event.GetRow() |
---|
[dadf255] | 174 | if not flag: |
---|
| 175 | self.selected_cols = [] |
---|
[75790dc] | 176 | self.selected_rows = [] |
---|
[dadf255] | 177 | self.selected_cells = [] |
---|
| 178 | self.axis_label = "" |
---|
[63dc6e5] | 179 | self.plottable_list = [] |
---|
[75790dc] | 180 | self.plottable_cells = [] |
---|
[63dc6e5] | 181 | self.plottable_flag = False |
---|
[75790dc] | 182 | |
---|
[63dc6e5] | 183 | self.last_selected_col = col |
---|
| 184 | self.last_selected_row = row |
---|
[75790dc] | 185 | if row != -1 and row not in self.selected_rows: |
---|
| 186 | self.selected_rows.append(row) |
---|
| 187 | |
---|
[647df0d1] | 188 | if col != -1: |
---|
| 189 | for row in range(1, self.GetNumberRows()+ 1): |
---|
| 190 | cell = (row, col) |
---|
| 191 | if row > 0 and row < self.max_row_touse: |
---|
| 192 | if cell not in self.selected_cells: |
---|
| 193 | self.selected_cells.append(cell) |
---|
| 194 | self.selected_cols.append(col) |
---|
| 195 | self.axis_value = [] |
---|
| 196 | for cell_row, cell_col in self.selected_cells: |
---|
| 197 | self.axis_value.append(self.GetCellValue(cell_row, cell_col)) |
---|
| 198 | self.axis_label = self.GetCellValue(0, col) |
---|
[75790dc] | 199 | |
---|
[24adb89] | 200 | def on_right_click(self, event): |
---|
[9c8f3ad] | 201 | """ |
---|
| 202 | Catch the right click mouse |
---|
| 203 | """ |
---|
[656d65d] | 204 | |
---|
[24adb89] | 205 | col = event.GetCol() |
---|
[656d65d] | 206 | self.selected_cols = [] |
---|
| 207 | self.selected_cols.append(col) |
---|
[24adb89] | 208 | # Slicer plot popup menu |
---|
| 209 | slicerpop = wx.Menu() |
---|
[656d65d] | 210 | col_label_menu = wx.Menu() |
---|
[1c86a37] | 211 | c_name = self.GetCellValue(0, col) |
---|
| 212 | label = "Insert column before %s " % str(c_name) |
---|
[656d65d] | 213 | slicerpop.AppendSubMenu(col_label_menu , |
---|
[1c86a37] | 214 | '&%s' % str(label), str(label)) |
---|
[71fa9028] | 215 | col_name = [self.GetCellValue(0, c) |
---|
| 216 | for c in range(self.GetNumberCols())] |
---|
| 217 | row = 0 |
---|
| 218 | label = self.GetCellValue(row, col) |
---|
| 219 | self.insert_col_menu(col_label_menu, label, self) |
---|
[b18cf3d] | 220 | |
---|
| 221 | |
---|
| 222 | col_after_menu = wx.Menu() |
---|
| 223 | label = "Insert column after %s " % str(c_name) |
---|
| 224 | slicerpop.AppendSubMenu(col_after_menu , |
---|
| 225 | '&%s' % str(label), str(label)) |
---|
| 226 | col_name = [self.GetCellValue(0, c) |
---|
| 227 | for c in range(self.GetNumberCols())] |
---|
| 228 | self.insert_after_col_menu(col_after_menu, label, self) |
---|
| 229 | |
---|
| 230 | |
---|
[656d65d] | 231 | id = wx.NewId() |
---|
| 232 | hint = 'Remove selected column %s' |
---|
[71fa9028] | 233 | slicerpop.Append(id, '&Remove Column', hint) |
---|
[656d65d] | 234 | wx.EVT_MENU(self, id, self.on_remove_column) |
---|
[24adb89] | 235 | |
---|
[656d65d] | 236 | pos = wx.GetMousePosition() |
---|
[24adb89] | 237 | pos = self.ScreenToClient(pos) |
---|
| 238 | self.PopupMenu(slicerpop, pos) |
---|
[647df0d1] | 239 | event.Skip() |
---|
[24adb89] | 240 | |
---|
[71fa9028] | 241 | def insert_col_menu(self, menu, label, window): |
---|
| 242 | """ |
---|
| 243 | """ |
---|
| 244 | id = wx.NewId() |
---|
| 245 | title = "Empty" |
---|
| 246 | hint = 'Insert empty column before %s' % str(label) |
---|
| 247 | menu.Append(id, title, hint) |
---|
| 248 | wx.EVT_MENU(window, id, self.on_insert_column) |
---|
[fb0de166] | 249 | row = 0 |
---|
| 250 | col_name = [self.GetCellValue(row, col) |
---|
[71fa9028] | 251 | for col in range(self.GetNumberCols())] |
---|
| 252 | for c_name in self.data.keys(): |
---|
| 253 | if c_name not in col_name: |
---|
| 254 | id = wx.NewId() |
---|
| 255 | hint = "Insert %s column before the " % str(c_name) |
---|
| 256 | hint += " %s column" % str(label) |
---|
| 257 | menu.Append(id, '&%s' % str(c_name), hint) |
---|
| 258 | wx.EVT_MENU(window, id, self.on_insert_column) |
---|
| 259 | |
---|
[b18cf3d] | 260 | def insert_after_col_menu(self, menu, label, window): |
---|
| 261 | """ |
---|
| 262 | """ |
---|
| 263 | id = wx.NewId() |
---|
| 264 | title = "Empty" |
---|
| 265 | hint = 'Insert empty column after %s' % str(label) |
---|
| 266 | menu.Append(id, title, hint) |
---|
| 267 | wx.EVT_MENU(window, id, self.on_insert_after_column) |
---|
| 268 | row = 0 |
---|
| 269 | col_name = [self.GetCellValue(row, col) |
---|
| 270 | for col in range(self.GetNumberCols())] |
---|
| 271 | for c_name in self.data.keys(): |
---|
| 272 | if c_name not in col_name: |
---|
| 273 | id = wx.NewId() |
---|
| 274 | hint = "Insert %s column after the " % str(c_name) |
---|
| 275 | hint += " %s column" % str(label) |
---|
| 276 | menu.Append(id, '&%s' % str(c_name), hint) |
---|
| 277 | wx.EVT_MENU(window, id, self.on_insert_after_column) |
---|
| 278 | |
---|
[71fa9028] | 279 | def on_remove_column(self, event=None): |
---|
[656d65d] | 280 | """ |
---|
| 281 | """ |
---|
| 282 | if self.selected_cols is not None or len(self.selected_cols) > 0: |
---|
| 283 | col = self.selected_cols[0] |
---|
[71fa9028] | 284 | self.remove_column(col=col, numCols=1) |
---|
| 285 | |
---|
| 286 | def remove_column(self, col, numCols=1): |
---|
| 287 | """ |
---|
| 288 | Remove column to the current grid |
---|
| 289 | """ |
---|
| 290 | # add data to the grid |
---|
| 291 | row = 0 |
---|
| 292 | col_name = self.GetCellValue(row, col) |
---|
| 293 | self.data[col_name] = [] |
---|
| 294 | for row in range(1, self.GetNumberRows() + 1): |
---|
| 295 | if row < self.max_row_touse: |
---|
| 296 | value = self.GetCellValue(row, col) |
---|
| 297 | self.data[col_name].append(value) |
---|
| 298 | for k , value_list in self.data.iteritems(): |
---|
| 299 | if k != col_name: |
---|
| 300 | length = len(value_list) |
---|
| 301 | if length < self.max_row_touse: |
---|
| 302 | diff = self.max_row_touse - length |
---|
| 303 | for i in range(diff): |
---|
| 304 | self.data[k].append("") |
---|
| 305 | self.DeleteCols(pos=col, numCols=numCols, updateLabels=True) |
---|
[656d65d] | 306 | |
---|
| 307 | def on_insert_column(self, event): |
---|
| 308 | """ |
---|
| 309 | """ |
---|
| 310 | if self.selected_cols is not None or len(self.selected_cols) > 0: |
---|
| 311 | col = self.selected_cols[0] |
---|
| 312 | # add data to the grid |
---|
| 313 | row = 0 |
---|
| 314 | id = event.GetId() |
---|
| 315 | col_name = event.GetEventObject().GetLabelText(id) |
---|
[71fa9028] | 316 | self.insert_column(col=col, col_name=col_name) |
---|
| 317 | if not issubclass(event.GetEventObject().__class__ , wx.Menu): |
---|
| 318 | col += 1 |
---|
| 319 | self.selected_cols[0] += 1 |
---|
[b18cf3d] | 320 | |
---|
| 321 | def on_insert_after_column(self, event): |
---|
| 322 | """ |
---|
| 323 | Insert the given column after the highlighted column |
---|
| 324 | """ |
---|
| 325 | if self.selected_cols is not None or len(self.selected_cols) > 0: |
---|
| 326 | col = self.selected_cols[0] + 1 |
---|
| 327 | # add data to the grid |
---|
| 328 | row = 0 |
---|
| 329 | id = event.GetId() |
---|
| 330 | col_name = event.GetEventObject().GetLabelText(id) |
---|
| 331 | self.insert_column(col=col, col_name=col_name) |
---|
| 332 | if not issubclass(event.GetEventObject().__class__ , wx.Menu): |
---|
| 333 | self.selected_cols[0] += 1 |
---|
[71fa9028] | 334 | |
---|
| 335 | def insert_column(self, col, col_name): |
---|
| 336 | """ |
---|
| 337 | """ |
---|
| 338 | |
---|
| 339 | row = 0 |
---|
| 340 | self.InsertCols(pos=col, numCols=1, updateLabels=True) |
---|
| 341 | if col_name.strip() != "Empty": |
---|
| 342 | self.SetCellValue(row, col, str(col_name.strip())) |
---|
| 343 | if col_name in self.data.keys(): |
---|
| 344 | value_list = self.data[col_name] |
---|
| 345 | cell_row = 1 |
---|
| 346 | for value in value_list: |
---|
[b18cf3d] | 347 | label = format_number(value, high=True) |
---|
| 348 | self.SetCellValue(cell_row, col, str(label)) |
---|
[71fa9028] | 349 | cell_row += 1 |
---|
[b18cf3d] | 350 | self.AutoSizeColumn(col, True) |
---|
| 351 | width = self.GetColSize(col) |
---|
| 352 | if width < self.default_col_width: |
---|
| 353 | self.SetColSize(col, self.default_col_width) |
---|
| 354 | self.ForceRefresh() |
---|
[656d65d] | 355 | |
---|
[24adb89] | 356 | def on_set_x_axis(self, event): |
---|
[9c8f3ad] | 357 | """ |
---|
| 358 | """ |
---|
[24adb89] | 359 | self.panel.set_xaxis(x=self.axis_value, label=self.axis_label) |
---|
| 360 | |
---|
| 361 | def on_set_y_axis(self, event): |
---|
[9c8f3ad] | 362 | """ |
---|
| 363 | """ |
---|
[24adb89] | 364 | self.panel.set_yaxis(y=self.axis_value, label=self.axis_label) |
---|
| 365 | |
---|
[71fa9028] | 366 | def set_data(self, data_inputs, data_outputs, details, file_name): |
---|
[24adb89] | 367 | """ |
---|
[9c8f3ad] | 368 | Add data to the grid |
---|
[dadf255] | 369 | :param data_inputs: data to use from the context menu of the grid |
---|
| 370 | :param data_ouputs: default columns deplayed |
---|
[24adb89] | 371 | """ |
---|
[71fa9028] | 372 | self.file_name = file_name |
---|
| 373 | self.details = details |
---|
| 374 | |
---|
[8523a1f2] | 375 | if data_outputs is None: |
---|
| 376 | data_outputs = {} |
---|
| 377 | self.data_outputs = data_outputs |
---|
[71fa9028] | 378 | if data_inputs is None: |
---|
[8523a1f2] | 379 | data_inputs = {} |
---|
| 380 | self.data_inputs = data_inputs |
---|
[656d65d] | 381 | self.data = {} |
---|
| 382 | for item in (self.data_outputs, self.data_inputs): |
---|
| 383 | self.data.update(item) |
---|
[8523a1f2] | 384 | if len(self.data_outputs) > 0: |
---|
[9c8f3ad] | 385 | self._cols = self.GetNumberCols() |
---|
| 386 | self._rows = self.GetNumberRows() |
---|
[8523a1f2] | 387 | self.col_names = self.data_outputs.keys() |
---|
[24adb89] | 388 | self.col_names.sort() |
---|
[9c8f3ad] | 389 | nbr_user_cols = len(self.col_names) |
---|
| 390 | #Add more columns to the grid if necessary |
---|
| 391 | if nbr_user_cols > self._cols: |
---|
| 392 | new_col_nbr = nbr_user_cols - self._cols |
---|
| 393 | self.AppendCols(new_col_nbr, True) |
---|
| 394 | #Add more rows to the grid if necessary |
---|
[8523a1f2] | 395 | nbr_user_row = len(self.data_outputs.values()) |
---|
[9c8f3ad] | 396 | if nbr_user_row > self._rows + 1: |
---|
| 397 | new_row_nbr = nbr_user_row - self._rows |
---|
| 398 | self.AppendRows(new_row_nbr, True) |
---|
| 399 | # add data to the grid |
---|
[10675c3] | 400 | row = 0 |
---|
[24adb89] | 401 | col = 0 |
---|
[8523a1f2] | 402 | cell_col = 0 |
---|
| 403 | for col_name in self.col_names: |
---|
| 404 | # use the first row of the grid to add user defined labels |
---|
| 405 | self.SetCellValue(row, col, str(col_name)) |
---|
[24adb89] | 406 | col += 1 |
---|
[8523a1f2] | 407 | cell_row = 1 |
---|
| 408 | value_list = self.data_outputs[col_name] |
---|
| 409 | |
---|
| 410 | for value in value_list: |
---|
[5425990] | 411 | label = value |
---|
| 412 | if issubclass(value.__class__, BatchCell): |
---|
| 413 | label = value.label |
---|
[1c86a37] | 414 | try: |
---|
| 415 | float(label) |
---|
[4c712ea4] | 416 | label = format_number(label, high=True) |
---|
[1c86a37] | 417 | except: |
---|
| 418 | label = str(label) |
---|
| 419 | self.SetCellValue(cell_row, cell_col, label) |
---|
| 420 | self.AutoSizeColumn(cell_col, True) |
---|
| 421 | width = self.GetColSize(cell_col) |
---|
| 422 | if width < self.default_col_width: |
---|
| 423 | self.SetColSize(cell_col, self.default_col_width) |
---|
| 424 | |
---|
[8523a1f2] | 425 | cell_row += 1 |
---|
| 426 | cell_col += 1 |
---|
[656d65d] | 427 | if cell_row > self.max_row_touse: |
---|
| 428 | self.max_row_touse = cell_row |
---|
[1c86a37] | 429 | self.ForceRefresh() |
---|
| 430 | |
---|
[71fa9028] | 431 | def get_grid_view(self): |
---|
| 432 | """ |
---|
| 433 | Return value contained in the grid |
---|
| 434 | """ |
---|
| 435 | grid_view = {} |
---|
| 436 | for col in xrange(self.GetNumberCols()): |
---|
| 437 | label = self.GetCellValue(row=0, col=col) |
---|
| 438 | label = label.strip() |
---|
| 439 | if label != "": |
---|
| 440 | grid_view[label] = [] |
---|
| 441 | for row in range(1, self.max_row_touse+1): |
---|
| 442 | value = self.GetCellValue(row=row, col=col) |
---|
| 443 | if value != "": |
---|
| 444 | grid_view[label].append(value) |
---|
| 445 | else: |
---|
| 446 | grid_view[label].append(None) |
---|
| 447 | return grid_view |
---|
| 448 | |
---|
[24adb89] | 449 | class Notebook(nb, PanelBase): |
---|
| 450 | """ |
---|
| 451 | ## Internal name for the AUI manager |
---|
| 452 | window_name = "Fit panel" |
---|
| 453 | ## Title to appear on top of the window |
---|
| 454 | """ |
---|
| 455 | window_caption = "Notebook " |
---|
| 456 | |
---|
| 457 | def __init__(self, parent, manager=None, data=None, *args, **kwargs): |
---|
| 458 | """ |
---|
| 459 | """ |
---|
| 460 | nb.__init__(self, parent, -1, |
---|
[f4b37d1] | 461 | style=wx.aui.AUI_NB_WINDOWLIST_BUTTON| |
---|
| 462 | wx.aui.AUI_BUTTON_DOWN| |
---|
[9c8f3ad] | 463 | wx.aui.AUI_NB_DEFAULT_STYLE| |
---|
| 464 | wx.CLIP_CHILDREN) |
---|
[24adb89] | 465 | PanelBase.__init__(self, parent) |
---|
[9c8f3ad] | 466 | self.enable_close_button() |
---|
[24adb89] | 467 | self.parent = parent |
---|
| 468 | self.manager = manager |
---|
| 469 | self.data = data |
---|
[d03a356] | 470 | #add empty page |
---|
| 471 | self.add_empty_page() |
---|
| 472 | |
---|
[9c8f3ad] | 473 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.on_close_page) |
---|
[7ad194fa] | 474 | |
---|
[d03a356] | 475 | def add_empty_page(self): |
---|
| 476 | """ |
---|
| 477 | """ |
---|
| 478 | grid = GridPage(self, panel=self.parent) |
---|
| 479 | self.AddPage(grid, "", True) |
---|
| 480 | pos = self.GetPageIndex(grid) |
---|
| 481 | title = "Batch " + str(self.GetPageCount()) |
---|
| 482 | self.SetPageText(pos, title) |
---|
| 483 | self.SetSelection(pos) |
---|
[f4b37d1] | 484 | return grid , pos |
---|
[d03a356] | 485 | |
---|
[9c8f3ad] | 486 | def enable_close_button(self): |
---|
| 487 | """ |
---|
| 488 | display the close button on tab for more than 1 tabs else remove the |
---|
| 489 | close button |
---|
| 490 | """ |
---|
| 491 | if self.GetPageCount() <= 1: |
---|
| 492 | style = self.GetWindowStyleFlag() |
---|
| 493 | flag = wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
| 494 | if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB == flag: |
---|
| 495 | style = style & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
| 496 | self.SetWindowStyle(style) |
---|
| 497 | else: |
---|
| 498 | style = self.GetWindowStyleFlag() |
---|
| 499 | flag = wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
| 500 | if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB != flag: |
---|
| 501 | style |= wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
| 502 | self.SetWindowStyle(style) |
---|
[9680906d] | 503 | |
---|
| 504 | def on_edit_axis(self): |
---|
| 505 | """ |
---|
| 506 | Return the select cell of a given selected column |
---|
| 507 | """ |
---|
| 508 | pos = self.GetSelection() |
---|
| 509 | grid = self.GetPage(pos) |
---|
[49ad00b] | 510 | if len(grid.selected_cols) > 1: |
---|
| 511 | msg = "Edit axis doesn't understand this selection.\n" |
---|
| 512 | msg += "Please select only one column" |
---|
| 513 | raise ValueError, msg |
---|
| 514 | if len(grid.selected_cols) == 1: |
---|
| 515 | col = grid.selected_cols[0] |
---|
[7ad194fa] | 516 | if len(grid.selected_cells) > 0: |
---|
| 517 | cell_row, cell_col = grid.selected_cells[0] |
---|
| 518 | if cell_col != col: |
---|
| 519 | msg = "Edit axis doesn't understand this selection.\n" |
---|
| 520 | msg += "Please select element of the same col" |
---|
| 521 | raise ValueError, msg |
---|
[dadf255] | 522 | return grid.selected_cells |
---|
| 523 | |
---|
[7ad194fa] | 524 | |
---|
[904830e] | 525 | def get_column_labels(self): |
---|
| 526 | """ |
---|
| 527 | return dictionary of columns labels of the current page |
---|
| 528 | """ |
---|
| 529 | pos = self.GetSelection() |
---|
| 530 | grid = self.GetPage(pos) |
---|
| 531 | labels = {} |
---|
| 532 | row = 0 |
---|
| 533 | for col in range(grid.GetNumberCols()): |
---|
| 534 | label = grid.GetCellValue(row, col) |
---|
| 535 | if label.strip() != "" : |
---|
| 536 | labels[label.strip()] = col |
---|
| 537 | return labels |
---|
| 538 | |
---|
[7ad194fa] | 539 | def create_axis_label(self, cell_list): |
---|
| 540 | """ |
---|
| 541 | Receive a list of cells and create a string presenting the selected |
---|
| 542 | cells. |
---|
| 543 | :param cell_list: list of tuple |
---|
[9680906d] | 544 | |
---|
[7ad194fa] | 545 | """ |
---|
| 546 | pos = self.GetSelection() |
---|
| 547 | grid = self.GetPage(pos) |
---|
| 548 | label = "" |
---|
| 549 | col_name = "" |
---|
[dadf255] | 550 | def create_label(col_name, row_min=None, row_max=None): |
---|
| 551 | """ |
---|
| 552 | """ |
---|
| 553 | result = "" |
---|
| 554 | if row_min is not None or row_max is not None: |
---|
| 555 | if row_min is None: |
---|
| 556 | result = str(row_max) + "]" |
---|
| 557 | elif row_max is None: |
---|
| 558 | result = str(col_name) + "[" + str(row_min) + ":" |
---|
| 559 | else: |
---|
| 560 | result = str(col_name) + "[" + str(row_min) + ":" |
---|
| 561 | result += str(col_name) + str(row_max) + "]" |
---|
| 562 | return result |
---|
| 563 | |
---|
[7ad194fa] | 564 | if len(cell_list) > 0: |
---|
[dadf255] | 565 | if len(cell_list) == 1: |
---|
| 566 | row_min, col = cell_list[0] |
---|
| 567 | col_name = grid.GetCellValue(0, col) |
---|
| 568 | label = create_label(col_name, row_min+1 , row_min+1) |
---|
| 569 | return label, col_name |
---|
| 570 | else: |
---|
| 571 | temp_list = copy.deepcopy(cell_list) |
---|
| 572 | temp_list.sort() |
---|
| 573 | length = len(temp_list) |
---|
| 574 | row_min, col = temp_list[0] |
---|
| 575 | row_max, _ = temp_list[length-1] |
---|
| 576 | col_name = grid.GetCellValue(0, col) |
---|
| 577 | index = 0 |
---|
| 578 | for row in xrange(row_min, row_max +1): |
---|
| 579 | if index > 0 and index < len(temp_list): |
---|
| 580 | new_row, _ = temp_list[index] |
---|
| 581 | if row != new_row: |
---|
| 582 | temp_list.insert(index, (None, None)) |
---|
| 583 | if index -1 >=0: |
---|
| 584 | new_row, _ = temp_list[index-1] |
---|
| 585 | label += create_label(col_name, None, new_row +1) |
---|
| 586 | label += "," |
---|
| 587 | if index + 1 < len(temp_list): |
---|
| 588 | new_row, _ = temp_list[index + 1] |
---|
| 589 | label += create_label(col_name, new_row+1, None) |
---|
| 590 | if index == 0: |
---|
| 591 | label += create_label(col_name, row_min+1, None) |
---|
| 592 | elif index == len(temp_list)-1: |
---|
| 593 | label += create_label(col_name, None, row_max+1) |
---|
| 594 | index += 1 |
---|
| 595 | return label, col_name |
---|
[7ad194fa] | 596 | |
---|
[9c8f3ad] | 597 | def on_close_page(self, event): |
---|
| 598 | """ |
---|
| 599 | close the page |
---|
| 600 | """ |
---|
| 601 | if self.GetPageCount() == 1: |
---|
| 602 | event.Veto() |
---|
| 603 | self.enable_close_button() |
---|
[24adb89] | 604 | |
---|
[71fa9028] | 605 | def set_data(self, data_inputs, data_outputs, details="", file_name=None): |
---|
[8523a1f2] | 606 | if data_outputs is None or data_outputs == {}: |
---|
[24adb89] | 607 | return |
---|
| 608 | |
---|
[f4b37d1] | 609 | for pos in range(self.GetPageCount()): |
---|
| 610 | grid = self.GetPage(pos) |
---|
| 611 | if grid.data is None: |
---|
| 612 | #Found empty page |
---|
[71fa9028] | 613 | grid.set_data(data_inputs=data_inputs, |
---|
| 614 | data_outputs=data_outputs, |
---|
| 615 | details=details, |
---|
| 616 | file_name=file_name) |
---|
[f4b37d1] | 617 | self.SetSelection(pos) |
---|
| 618 | return |
---|
| 619 | |
---|
| 620 | grid, pos = self.add_empty_page() |
---|
[a84ca2a] | 621 | grid.set_data(data_inputs=data_inputs, |
---|
| 622 | data_outputs=data_outputs, |
---|
| 623 | file_name=file_name, |
---|
| 624 | details=details) |
---|
[f4b37d1] | 625 | |
---|
[9c8f3ad] | 626 | def add_column(self): |
---|
| 627 | """ |
---|
| 628 | Append a new column to the grid |
---|
| 629 | """ |
---|
| 630 | pos = self.GetSelection() |
---|
| 631 | grid = self.GetPage(pos) |
---|
| 632 | grid.AppendCols(1, True) |
---|
| 633 | |
---|
[71fa9028] | 634 | |
---|
[f4b37d1] | 635 | |
---|
[24adb89] | 636 | |
---|
[9c8f3ad] | 637 | |
---|
[24adb89] | 638 | class GridPanel(SPanel): |
---|
[8523a1f2] | 639 | def __init__(self, parent, data_inputs=None, |
---|
| 640 | data_outputs=None, *args, **kwds): |
---|
[24adb89] | 641 | SPanel.__init__(self, parent , *args, **kwds) |
---|
[f4b37d1] | 642 | |
---|
[24adb89] | 643 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 644 | |
---|
[9680906d] | 645 | self.plotting_sizer = wx.FlexGridSizer(3, 7, 10, 5) |
---|
[75790dc] | 646 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[24adb89] | 647 | self.grid_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 648 | self.vbox.AddMany([(self.grid_sizer, 1, wx.EXPAND, 0), |
---|
| 649 | (wx.StaticLine(self, -1), 0, wx.EXPAND, 0), |
---|
[75790dc] | 650 | (self.plotting_sizer), |
---|
| 651 | (self.button_sizer)]) |
---|
[24adb89] | 652 | self.parent = parent |
---|
[8523a1f2] | 653 | self._data_inputs = data_inputs |
---|
| 654 | self._data_outputs = data_outputs |
---|
[24adb89] | 655 | self.x = [] |
---|
| 656 | self.y = [] |
---|
| 657 | self.x_axis_label = None |
---|
| 658 | self.y_axis_label = None |
---|
[904830e] | 659 | self.x_axis_title = None |
---|
| 660 | self.y_axis_title = None |
---|
[24adb89] | 661 | self.x_axis_unit = None |
---|
| 662 | self.y_axis_unit = None |
---|
[75790dc] | 663 | self.view_button = None |
---|
[24adb89] | 664 | self.plot_button = None |
---|
[904830e] | 665 | self.notebook = None |
---|
[fd51a7c] | 666 | self.list_plot_panels = {} |
---|
[24adb89] | 667 | self.layout_grid() |
---|
| 668 | self.layout_plotting_area() |
---|
| 669 | self.SetSizer(self.vbox) |
---|
[71fa9028] | 670 | |
---|
[904830e] | 671 | def set_xaxis(self, label="", x=None): |
---|
| 672 | """ |
---|
| 673 | """ |
---|
[24adb89] | 674 | if x is None: |
---|
| 675 | x = [] |
---|
| 676 | self.x = x |
---|
[904830e] | 677 | self.x_axis_label.SetValue("%s[:]" % str(label)) |
---|
| 678 | self.x_axis_title.SetValue(str(label)) |
---|
[24adb89] | 679 | |
---|
[904830e] | 680 | def set_yaxis(self, label="", y=None): |
---|
| 681 | """ |
---|
| 682 | """ |
---|
[24adb89] | 683 | if y is None: |
---|
| 684 | y = [] |
---|
| 685 | self.y = y |
---|
[904830e] | 686 | self.y_axis_label.SetValue("%s[:]" % str(label)) |
---|
| 687 | self.y_axis_title.SetValue(str(label)) |
---|
[24adb89] | 688 | |
---|
[904830e] | 689 | def get_plot_axis(self, col, list): |
---|
| 690 | """ |
---|
| 691 | |
---|
| 692 | """ |
---|
| 693 | axis = [] |
---|
| 694 | pos = self.notebook.GetSelection() |
---|
| 695 | grid = self.notebook.GetPage(pos) |
---|
| 696 | for row in list: |
---|
[c911f34] | 697 | label = grid.GetCellValue(0, col) |
---|
| 698 | value = grid.GetCellValue(row - 1, col).strip() |
---|
| 699 | if value != "": |
---|
| 700 | if label.lower().strip() == "data": |
---|
| 701 | axis.append(float(row - 1)) |
---|
| 702 | else: |
---|
[dadf255] | 703 | try: |
---|
| 704 | axis.append(float(value)) |
---|
| 705 | except: |
---|
| 706 | msg = "Invalid data in row %s column %s" % (str(row), |
---|
| 707 | str(col)) |
---|
| 708 | wx.PostEvent(self.parent.parent, |
---|
[75790dc] | 709 | StatusEvent(status=msg, info="error")) |
---|
[c911f34] | 710 | else: |
---|
| 711 | axis.append(None) |
---|
[904830e] | 712 | return axis |
---|
| 713 | |
---|
[656d65d] | 714 | def on_save_column(self, parent): |
---|
| 715 | """ |
---|
| 716 | """ |
---|
| 717 | pos = self.notebook.GetSelection() |
---|
| 718 | grid = self.notebook.GetPage(pos) |
---|
| 719 | if parent is not None and self.data is not None: |
---|
| 720 | parent.write_batch_tofile(data=grid.data, |
---|
| 721 | file_name=path, |
---|
| 722 | details=self.details) |
---|
| 723 | |
---|
[75790dc] | 724 | def on_view(self, event): |
---|
| 725 | """ |
---|
| 726 | Get object represented buy the given cell and plot them. |
---|
| 727 | """ |
---|
| 728 | pos = self.notebook.GetSelection() |
---|
| 729 | grid = self.notebook.GetPage(pos) |
---|
| 730 | title = self.notebook.GetPageText(pos) |
---|
[9400de6] | 731 | if len(grid.selected_cells) == 0: |
---|
| 732 | msg = "Highlight a Data or Chi2 column first..." |
---|
| 733 | wx.PostEvent(self.parent.parent, |
---|
| 734 | StatusEvent(status=msg, info="error")) |
---|
| 735 | return |
---|
[75790dc] | 736 | for cell in grid.selected_cells: |
---|
| 737 | row, col = cell |
---|
| 738 | label_row = 0 |
---|
| 739 | label = grid.GetCellValue(label_row, col) |
---|
| 740 | if label in grid.data: |
---|
| 741 | values = grid.data[label] |
---|
[9400de6] | 742 | if row < len(values): |
---|
| 743 | value = values[row -1] |
---|
| 744 | else: |
---|
| 745 | msg = "Invalid cell was chosen." |
---|
| 746 | #raise ValueError, msg |
---|
| 747 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg, |
---|
| 748 | info="error")) |
---|
| 749 | continue |
---|
[75790dc] | 750 | if issubclass(value.__class__, BatchCell): |
---|
[fe98127] | 751 | if value.object is None or len(value.object) == 0: |
---|
| 752 | msg = "Row %s , " % str(row) |
---|
| 753 | msg += "Column %s doesn't have a view" % str(label) |
---|
| 754 | #raise ValueError, msg |
---|
| 755 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg, |
---|
| 756 | info="error")) |
---|
| 757 | return |
---|
[75790dc] | 758 | for new_plot in value.object: |
---|
[fe98127] | 759 | if new_plot is None or \ |
---|
[1f83477] | 760 | not issubclass(new_plot.__class__, |
---|
[fe98127] | 761 | plottables.Plottable): |
---|
[75790dc] | 762 | msg = "Row %s , " % str(row) |
---|
| 763 | msg += "Column %s doesn't have a view" % str(label) |
---|
| 764 | #raise ValueError, msg |
---|
| 765 | wx.PostEvent(self.parent.parent, |
---|
| 766 | StatusEvent(status=msg, info="error")) |
---|
[7d47789] | 767 | continue |
---|
[fd51a7c] | 768 | |
---|
[75790dc] | 769 | if issubclass(new_plot.__class__, Data1D): |
---|
[fd51a7c] | 770 | if label in self.list_plot_panels.keys(): |
---|
| 771 | group_id = self.list_plot_panels[label] |
---|
| 772 | else: |
---|
| 773 | group_id = str(grid.uid) + str(new_plot.group_id) |
---|
| 774 | self.list_plot_panels[label] = group_id |
---|
| 775 | if group_id not in new_plot.list_group_id: |
---|
| 776 | new_plot.group_id = group_id |
---|
| 777 | new_plot.list_group_id.append(group_id) |
---|
[75790dc] | 778 | else: |
---|
[18a6556] | 779 | if label.lower() in ["data", "chi2"]: |
---|
[75790dc] | 780 | if len(grid.selected_cells) != 1: |
---|
[b18cf3d] | 781 | msg = "2D View: Please select one data set" |
---|
| 782 | msg += " at a time to view." |
---|
[75790dc] | 783 | wx.PostEvent(self.parent.parent, |
---|
| 784 | StatusEvent(status=msg, |
---|
| 785 | info="error")) |
---|
[7d47789] | 786 | continue |
---|
[75790dc] | 787 | wx.PostEvent(self.parent.parent, |
---|
[fd51a7c] | 788 | NewPlotEvent(action="clear", |
---|
| 789 | group_id=str(group_id), |
---|
| 790 | title=title)) |
---|
| 791 | wx.PostEvent(self.parent.parent, |
---|
[75790dc] | 792 | NewPlotEvent(plot=new_plot, |
---|
[fd51a7c] | 793 | group_id=str(group_id), |
---|
| 794 | title=title)) |
---|
[75790dc] | 795 | else: |
---|
| 796 | |
---|
| 797 | msg = "Row %s , " % str(row) |
---|
| 798 | msg += "Column %s doesn't have a view" % str(label) |
---|
| 799 | #raise ValueError, msg |
---|
| 800 | wx.PostEvent(self.parent.parent, |
---|
| 801 | StatusEvent(status=msg, info="error")) |
---|
[665fd06] | 802 | continue |
---|
[75790dc] | 803 | |
---|
| 804 | |
---|
| 805 | |
---|
| 806 | |
---|
[24adb89] | 807 | def on_plot(self, event): |
---|
| 808 | """ |
---|
[904830e] | 809 | Evaluate the contains of textcrtl and plot result |
---|
[24adb89] | 810 | """ |
---|
[904830e] | 811 | pos = self.notebook.GetSelection() |
---|
| 812 | grid = self.notebook.GetPage(pos) |
---|
| 813 | column_names = {} |
---|
| 814 | if grid is not None: |
---|
| 815 | column_names = self.notebook.get_column_labels() |
---|
| 816 | #evalue x |
---|
| 817 | sentence = self.x_axis_label.GetValue() |
---|
[1c86a37] | 818 | try: |
---|
| 819 | if sentence.strip() == "": |
---|
[9400de6] | 820 | msg = "Select column values for x axis and y axis" |
---|
[1c86a37] | 821 | raise ValueError, msg |
---|
| 822 | except: |
---|
| 823 | wx.PostEvent(self.parent.parent, |
---|
| 824 | StatusEvent(status=msg, info="error")) |
---|
| 825 | return |
---|
| 826 | |
---|
| 827 | |
---|
[904830e] | 828 | dict = parse_string(sentence, column_names.keys()) |
---|
| 829 | for tok, (col_name, list) in dict.iteritems(): |
---|
| 830 | col = column_names[col_name] |
---|
| 831 | xaxis = self.get_plot_axis(col, list) |
---|
| 832 | sentence = sentence.replace(tok, |
---|
| 833 | "numpy.array(%s)" % str(xaxis)) |
---|
| 834 | for key, value in FUNC_DICT.iteritems(): |
---|
| 835 | sentence = sentence.replace(key.lower(), value) |
---|
| 836 | x = eval(sentence) |
---|
| 837 | #evaluate y |
---|
| 838 | sentence = self.y_axis_label.GetValue() |
---|
| 839 | if sentence.strip() == "": |
---|
| 840 | msg = "select value for y axis" |
---|
| 841 | raise ValueError, msg |
---|
| 842 | dict = parse_string(sentence, column_names.keys()) |
---|
| 843 | for tok, (col_name, list) in dict.iteritems(): |
---|
| 844 | col = column_names[col_name] |
---|
| 845 | yaxis = self.get_plot_axis(col, list) |
---|
| 846 | sentence = sentence.replace(tok, |
---|
| 847 | "numpy.array(%s)" % str(yaxis)) |
---|
| 848 | for key, value in FUNC_DICT.iteritems(): |
---|
| 849 | sentence = sentence.replace(key, value) |
---|
| 850 | y = eval(sentence) |
---|
| 851 | #plotting |
---|
| 852 | new_plot = Data1D(x=x, y=y) |
---|
[24adb89] | 853 | new_plot.id = wx.NewId() |
---|
| 854 | new_plot.group_id = wx.NewId() |
---|
[904830e] | 855 | title = "%s vs %s" % (self.y_axis_title.GetValue(), |
---|
| 856 | self.x_axis_title.GetValue()) |
---|
| 857 | new_plot.xaxis(self.x_axis_title.GetValue(), self.x_axis_unit.GetValue()) |
---|
| 858 | new_plot.yaxis(self.y_axis_title.GetValue(), self.y_axis_unit.GetValue()) |
---|
| 859 | try: |
---|
| 860 | title = self.notebook.GetPageText(pos) |
---|
[dadf255] | 861 | new_plot.name = title |
---|
[1c86a37] | 862 | new_plot.xtransform = "x" |
---|
| 863 | new_plot.ytransform = "y" |
---|
[904830e] | 864 | wx.PostEvent(self.parent.parent, |
---|
[49ad00b] | 865 | NewPlotEvent(plot=new_plot, |
---|
[904830e] | 866 | group_id=str(new_plot.group_id), title =title)) |
---|
| 867 | except: |
---|
[dadf255] | 868 | wx.PostEvent(self.parent.parent, |
---|
[75790dc] | 869 | StatusEvent(status=msg, info="error")) |
---|
[904830e] | 870 | |
---|
[24adb89] | 871 | def layout_grid(self): |
---|
| 872 | """ |
---|
| 873 | Draw the area related to the grid |
---|
| 874 | """ |
---|
[904830e] | 875 | self.notebook = Notebook(parent=self) |
---|
[8523a1f2] | 876 | self.notebook.set_data(self._data_inputs, self._data_outputs) |
---|
[904830e] | 877 | self.grid_sizer.Add(self.notebook, 1, wx.EXPAND, 0) |
---|
[24adb89] | 878 | |
---|
| 879 | def layout_plotting_area(self): |
---|
| 880 | """ |
---|
| 881 | Draw area containing options to plot |
---|
| 882 | """ |
---|
[75790dc] | 883 | |
---|
[904830e] | 884 | self.x_axis_title = wx.TextCtrl(self, -1) |
---|
| 885 | self.y_axis_title = wx.TextCtrl(self, -1) |
---|
| 886 | self.x_axis_label = wx.TextCtrl(self, -1, size=(200, -1)) |
---|
| 887 | self.y_axis_label = wx.TextCtrl(self, -1, size=(200, -1)) |
---|
[9680906d] | 888 | self.x_axis_add = wx.Button(self, -1, "Add") |
---|
| 889 | self.x_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, |
---|
| 890 | id=self.x_axis_add.GetId()) |
---|
| 891 | self.y_axis_add = wx.Button(self, -1, "Add") |
---|
| 892 | self.y_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, |
---|
| 893 | id=self.y_axis_add.GetId()) |
---|
[24adb89] | 894 | self.x_axis_unit = wx.TextCtrl(self, -1) |
---|
| 895 | self.y_axis_unit = wx.TextCtrl(self, -1) |
---|
[1c86a37] | 896 | self.view_button = wx.Button(self, -1, "View Results") |
---|
[7d47789] | 897 | view_tip = "Highlight the data set or the Chi2 column first." |
---|
[b18cf3d] | 898 | self.view_button.SetToolTipString(view_tip) |
---|
[75790dc] | 899 | wx.EVT_BUTTON(self, self.view_button.GetId(), self.on_view) |
---|
[24adb89] | 900 | self.plot_button = wx.Button(self, -1, "Plot") |
---|
[7d47789] | 901 | plot_tip = "Highlight a column for each axis and \n" |
---|
| 902 | plot_tip += "click the Add buttons first." |
---|
[b18cf3d] | 903 | self.plot_button.SetToolTipString(plot_tip) |
---|
[75790dc] | 904 | self.button_sizer.AddMany( [ (500, 30), |
---|
| 905 | (self.view_button, 0, wx.RIGHT|wx.BOTTOM, 10), |
---|
| 906 | (self.plot_button, 0, wx.RIGHT|wx.BOTTOM, 10)]) |
---|
| 907 | |
---|
[24adb89] | 908 | wx.EVT_BUTTON(self, self.plot_button.GetId(), self.on_plot) |
---|
[9680906d] | 909 | self.plotting_sizer.AddMany([ |
---|
[9bfa73f] | 910 | (wx.StaticText(self, -1, |
---|
| 911 | "X-axis Label\nSelection Range"), 1, |
---|
[904830e] | 912 | wx.TOP|wx.BOTTOM|wx.LEFT, 10), |
---|
| 913 | (self.x_axis_label, 1, wx.TOP|wx.BOTTOM, 10), |
---|
| 914 | (self.x_axis_add, 1, wx.TOP|wx.BOTTOM|wx.RIGHT, 10), |
---|
[9bfa73f] | 915 | (wx.StaticText(self, -1, "X-axis Label"), 1, |
---|
[904830e] | 916 | wx.TOP|wx.BOTTOM|wx.LEFT, 10), |
---|
| 917 | (self.x_axis_title, 1, wx.TOP|wx.BOTTOM, 10), |
---|
[7124300] | 918 | (wx.StaticText(self, -1 , "X-axis Unit"), 1, |
---|
[904830e] | 919 | wx.TOP|wx.BOTTOM, 10), |
---|
| 920 | (self.x_axis_unit, 1, wx.TOP|wx.BOTTOM, 10), |
---|
[9bfa73f] | 921 | (wx.StaticText(self, -1, |
---|
| 922 | "Y-axis Label\nSelection Range"), 1, |
---|
[904830e] | 923 | wx.BOTTOM|wx.LEFT, 10), |
---|
| 924 | (self.y_axis_label, wx.BOTTOM, 10), |
---|
| 925 | (self.y_axis_add, 1, wx.BOTTOM|wx.RIGHT, 10), |
---|
[9bfa73f] | 926 | (wx.StaticText(self, -1, "Y-axis Label"), 1, |
---|
[904830e] | 927 | wx.BOTTOM|wx.LEFT, 10), |
---|
| 928 | (self.y_axis_title, wx.BOTTOM, 10), |
---|
[9bfa73f] | 929 | (wx.StaticText(self, -1 , "Y-axis Unit"), 1, wx.BOTTOM, 10), |
---|
[904830e] | 930 | (self.y_axis_unit, 1, wx.BOTTOM, 10), |
---|
[9680906d] | 931 | (-1, -1), |
---|
| 932 | (-1, -1), |
---|
| 933 | (-1, -1), |
---|
| 934 | (-1, -1), |
---|
| 935 | (-1, -1), |
---|
| 936 | (-1, -1), |
---|
[75790dc] | 937 | (-1, 1)]) |
---|
[24adb89] | 938 | |
---|
[9680906d] | 939 | def on_edit_axis(self, event): |
---|
| 940 | """ |
---|
| 941 | Get the selected column on the visible grid and set values for axis |
---|
| 942 | """ |
---|
[904830e] | 943 | cell_list = self.notebook.on_edit_axis() |
---|
| 944 | label, title = self.create_axis_label(cell_list) |
---|
| 945 | tcrtl = event.GetEventObject() |
---|
| 946 | if tcrtl == self.x_axis_add: |
---|
| 947 | self.edit_axis_helper(self.x_axis_label, self.x_axis_title, |
---|
| 948 | label, title) |
---|
| 949 | elif tcrtl == self.y_axis_add: |
---|
| 950 | self.edit_axis_helper(self.y_axis_label, self.y_axis_title, |
---|
| 951 | label, title) |
---|
| 952 | |
---|
[7ad194fa] | 953 | def create_axis_label(self, cell_list): |
---|
| 954 | """ |
---|
| 955 | Receive a list of cells and create a string presenting the selected |
---|
| 956 | cells. |
---|
| 957 | :param cell_list: list of tuple |
---|
[24adb89] | 958 | |
---|
[7ad194fa] | 959 | """ |
---|
[904830e] | 960 | if self.notebook is not None: |
---|
| 961 | return self.notebook.create_axis_label(cell_list) |
---|
[7ad194fa] | 962 | |
---|
[904830e] | 963 | def edit_axis_helper(self, tcrtl_label, tcrtl_title, label, title): |
---|
[9680906d] | 964 | """ |
---|
[904830e] | 965 | get controls to modify |
---|
[9680906d] | 966 | """ |
---|
[904830e] | 967 | tcrtl_label.SetValue(str(label)) |
---|
| 968 | tcrtl_title.SetValue(str(title)) |
---|
| 969 | |
---|
[24adb89] | 970 | def add_column(self): |
---|
[9c8f3ad] | 971 | """ |
---|
| 972 | """ |
---|
[904830e] | 973 | if self.notebook is not None: |
---|
| 974 | self.notebook.add_column() |
---|
[24adb89] | 975 | |
---|
[9c8f3ad] | 976 | def on_remove_column(self): |
---|
| 977 | """ |
---|
| 978 | """ |
---|
[904830e] | 979 | if self.notebook is not None: |
---|
| 980 | self.notebook.on_remove_column() |
---|
[9c8f3ad] | 981 | |
---|
[24adb89] | 982 | |
---|
| 983 | class GridFrame(wx.Frame): |
---|
[8523a1f2] | 984 | def __init__(self, parent=None, data_inputs=None, data_outputs=None, id=-1, |
---|
[cf0eb8e] | 985 | title="Batch Window", size=(800, 500)): |
---|
[24adb89] | 986 | wx.Frame.__init__(self, parent=parent, id=id, title=title, size=size) |
---|
| 987 | self.parent = parent |
---|
[8523a1f2] | 988 | self.panel = GridPanel(self, data_inputs, data_outputs) |
---|
[24adb89] | 989 | menubar = wx.MenuBar() |
---|
| 990 | self.SetMenuBar(menubar) |
---|
[71fa9028] | 991 | |
---|
| 992 | self.curr_col = None |
---|
| 993 | self.curr_grid = None |
---|
| 994 | self.curr_col_name = "" |
---|
| 995 | file = wx.Menu() |
---|
| 996 | menubar.Append(file, "&File") |
---|
| 997 | |
---|
| 998 | hint = "Open file containing batch results" |
---|
| 999 | open_menu = file.Append(wx.NewId(), 'Open ', hint) |
---|
| 1000 | wx.EVT_MENU(self, open_menu.GetId(), self.on_open) |
---|
| 1001 | |
---|
| 1002 | hint = "Open the the current grid into excel" |
---|
| 1003 | open_excel_menu = file.Append(wx.NewId(), 'Open with Excel', hint) |
---|
| 1004 | wx.EVT_MENU(self, open_excel_menu.GetId(), self.open_with_excel) |
---|
| 1005 | file.AppendSeparator() |
---|
| 1006 | save_menu = file.Append(wx.NewId(), 'Save As', 'Save into File') |
---|
| 1007 | wx.EVT_MENU(self, save_menu.GetId(), self.on_save_page) |
---|
| 1008 | |
---|
| 1009 | self.edit = wx.Menu() |
---|
| 1010 | hint = "Insert column before the selected column" |
---|
| 1011 | self.insert_before_menu = wx.Menu() |
---|
| 1012 | self.insert_sub_menu = self.edit.AppendSubMenu(self.insert_before_menu, |
---|
| 1013 | 'Insert Before', hint) |
---|
| 1014 | |
---|
| 1015 | hint = "Remove the selected column" |
---|
| 1016 | self.remove_menu = self.edit.Append(-1, 'Remove Column', hint) |
---|
| 1017 | wx.EVT_MENU(self, self.remove_menu.GetId(), self.on_remove_column) |
---|
| 1018 | |
---|
| 1019 | self.Bind(wx.EVT_MENU_OPEN, self.on_menu_open) |
---|
| 1020 | menubar.Append(self.edit, "&Edit") |
---|
[cb26857] | 1021 | self.Bind(wx.EVT_CLOSE, self.on_close) |
---|
[24adb89] | 1022 | |
---|
[71fa9028] | 1023 | def GetLabelText(self, id): |
---|
[656d65d] | 1024 | """ |
---|
| 1025 | """ |
---|
[71fa9028] | 1026 | for item in self.insert_before_menu.GetMenuItems(): |
---|
| 1027 | m_id = item.GetId() |
---|
| 1028 | if m_id == id: |
---|
| 1029 | return item.GetLabel() |
---|
| 1030 | |
---|
| 1031 | def on_remove_column(self, event): |
---|
[cb26857] | 1032 | """ |
---|
| 1033 | """ |
---|
[71fa9028] | 1034 | pos = self.panel.notebook.GetSelection() |
---|
| 1035 | grid = self.panel.notebook.GetPage(pos) |
---|
| 1036 | grid.on_remove_column(event=None) |
---|
[cb26857] | 1037 | |
---|
[71fa9028] | 1038 | def on_menu_open(self, event): |
---|
[9c8f3ad] | 1039 | """ |
---|
[71fa9028] | 1040 | |
---|
[9c8f3ad] | 1041 | """ |
---|
[71fa9028] | 1042 | if self.edit == event.GetMenu(): |
---|
| 1043 | #get the selected column |
---|
| 1044 | pos = self.panel.notebook.GetSelection() |
---|
| 1045 | grid = self.panel.notebook.GetPage(pos) |
---|
| 1046 | col_list = grid.GetSelectedCols() |
---|
| 1047 | if len(col_list) > 0: |
---|
| 1048 | self.remove_menu.Enable(True) |
---|
| 1049 | else: |
---|
| 1050 | self.remove_menu.Enable(False) |
---|
| 1051 | if len(col_list)== 0 or len(col_list) > 1: |
---|
| 1052 | self.insert_sub_menu.Enable(False) |
---|
| 1053 | |
---|
| 1054 | label = "Insert Column Before" |
---|
| 1055 | self.insert_sub_menu.SetText(label) |
---|
| 1056 | else: |
---|
| 1057 | self.insert_sub_menu.Enable(True) |
---|
| 1058 | |
---|
| 1059 | col = col_list[0] |
---|
| 1060 | #GetColLabelValue(self, col) |
---|
| 1061 | col_name = grid.GetCellValue(row=0, col=col) |
---|
| 1062 | label = "Insert Column Before " + str(col_name) |
---|
| 1063 | self.insert_sub_menu.SetText(label) |
---|
| 1064 | for item in self.insert_before_menu.GetMenuItems(): |
---|
| 1065 | self.insert_before_menu.DeleteItem(item) |
---|
| 1066 | grid.insert_col_menu(menu=self.insert_before_menu, |
---|
| 1067 | label=col_name, window=self) |
---|
| 1068 | event.Skip() |
---|
[9c8f3ad] | 1069 | |
---|
[71fa9028] | 1070 | |
---|
| 1071 | |
---|
| 1072 | def on_save_page(self, event): |
---|
| 1073 | """ |
---|
| 1074 | """ |
---|
| 1075 | if self.parent is not None: |
---|
| 1076 | pos = self.panel.notebook.GetSelection() |
---|
| 1077 | grid = self.panel.notebook.GetPage(pos) |
---|
[7b48b08] | 1078 | if grid.file_name is None or grid.file_name.strip() == "" or \ |
---|
| 1079 | grid.data is None or len(grid.data) == 0: |
---|
| 1080 | name = self.panel.notebook.GetPageText(pos) |
---|
| 1081 | msg = " %s has not data to save" % str(name) |
---|
| 1082 | wx.PostEvent(self.parent, |
---|
| 1083 | StatusEvent(status=msg, info="error")) |
---|
| 1084 | |
---|
| 1085 | return |
---|
[71fa9028] | 1086 | reader, ext = os.path.splitext(grid.file_name) |
---|
| 1087 | path = None |
---|
| 1088 | if self.parent is not None: |
---|
| 1089 | location = os.path.dirname(grid.file_name) |
---|
| 1090 | dlg = wx.FileDialog(self, "Save Project file", |
---|
| 1091 | location, grid.file_name, ext, wx.SAVE) |
---|
| 1092 | path = None |
---|
| 1093 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1094 | path = dlg.GetPath() |
---|
| 1095 | dlg.Destroy() |
---|
| 1096 | if path != None: |
---|
| 1097 | if self.parent is not None: |
---|
| 1098 | data = grid.get_grid_view() |
---|
| 1099 | self.parent.write_batch_tofile(data=data, |
---|
| 1100 | file_name=path, |
---|
| 1101 | details=grid.details) |
---|
| 1102 | |
---|
| 1103 | def on_open(self, event): |
---|
[656d65d] | 1104 | """ |
---|
[71fa9028] | 1105 | Open file containg batch result |
---|
[656d65d] | 1106 | """ |
---|
[71fa9028] | 1107 | if self.parent is not None: |
---|
| 1108 | self.parent.on_read_batch_tofile(event) |
---|
| 1109 | |
---|
| 1110 | def open_with_excel(self, event): |
---|
| 1111 | """ |
---|
| 1112 | open excel and display batch result in Excel |
---|
| 1113 | """ |
---|
| 1114 | if self.parent is not None: |
---|
| 1115 | pos = self.panel.notebook.GetSelection() |
---|
| 1116 | grid = self.panel.notebook.GetPage(pos) |
---|
| 1117 | data = grid.get_grid_view() |
---|
[7b48b08] | 1118 | if grid.file_name is None or grid.file_name.strip() == "" or \ |
---|
| 1119 | grid.data is None or len(grid.data) == 0: |
---|
| 1120 | name = self.panel.notebook.GetPageText(pos) |
---|
| 1121 | msg = " %s has not data to open on excel" % str(name) |
---|
| 1122 | wx.PostEvent(self.parent, |
---|
| 1123 | StatusEvent(status=msg, info="error")) |
---|
| 1124 | |
---|
| 1125 | return |
---|
[71fa9028] | 1126 | self.parent.open_with_externalapp(data=data, |
---|
| 1127 | file_name=grid.file_name, |
---|
| 1128 | details=grid.details) |
---|
| 1129 | |
---|
| 1130 | def on_close(self, event): |
---|
| 1131 | """ |
---|
| 1132 | """ |
---|
| 1133 | self.Hide() |
---|
[656d65d] | 1134 | |
---|
[71fa9028] | 1135 | |
---|
[656d65d] | 1136 | def on_append_column(self, event): |
---|
[cb26857] | 1137 | """ |
---|
[9c8f3ad] | 1138 | Append a new column to the grid |
---|
[cb26857] | 1139 | """ |
---|
[24adb89] | 1140 | self.panel.add_column() |
---|
[cb26857] | 1141 | |
---|
[71fa9028] | 1142 | def set_data(self, data_inputs, data_outputs, details="", file_name=None): |
---|
[cb26857] | 1143 | """ |
---|
| 1144 | """ |
---|
[a84ca2a] | 1145 | |
---|
| 1146 | self.panel.notebook.set_data(data_inputs=data_inputs, |
---|
[71fa9028] | 1147 | file_name=file_name, |
---|
| 1148 | details=details, |
---|
| 1149 | data_outputs=data_outputs) |
---|
[24adb89] | 1150 | |
---|
| 1151 | |
---|
[83eb1b52] | 1152 | class BatchOutputFrame(wx.Frame): |
---|
[73197d0] | 1153 | """ |
---|
| 1154 | Allow to select where the result of batch will be displayed or stored |
---|
| 1155 | """ |
---|
[8523a1f2] | 1156 | def __init__(self, parent, data_inputs, data_outputs, file_name="", |
---|
[850525c] | 1157 | details="", *args, **kwds): |
---|
[73197d0] | 1158 | """ |
---|
| 1159 | :param parent: Window instantiating this dialog |
---|
| 1160 | :param result: result to display in a grid or export to an external |
---|
| 1161 | application. |
---|
| 1162 | """ |
---|
[850525c] | 1163 | #kwds['style'] = wx.CAPTION|wx.SYSTEM_MENU |
---|
[83eb1b52] | 1164 | wx.Frame.__init__(self, parent, *args, **kwds) |
---|
[73197d0] | 1165 | self.parent = parent |
---|
[83eb1b52] | 1166 | self.panel = wx.Panel(self) |
---|
[850525c] | 1167 | self.file_name = file_name |
---|
| 1168 | self.details = details |
---|
[8523a1f2] | 1169 | self.data_inputs = data_inputs |
---|
| 1170 | self.data_outputs = data_outputs |
---|
| 1171 | self.data = {} |
---|
| 1172 | for item in (self.data_outputs, self.data_inputs): |
---|
| 1173 | self.data.update(item) |
---|
[73197d0] | 1174 | self.flag = 1 |
---|
| 1175 | self.SetSize((300, 200)) |
---|
| 1176 | self.local_app_selected = None |
---|
| 1177 | self.external_app_selected = None |
---|
| 1178 | self.save_to_file = None |
---|
| 1179 | self._do_layout() |
---|
[8523a1f2] | 1180 | |
---|
[73197d0] | 1181 | def _do_layout(self): |
---|
| 1182 | """ |
---|
| 1183 | Draw the content of the current dialog window |
---|
| 1184 | """ |
---|
| 1185 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[83eb1b52] | 1186 | box_description = wx.StaticBox(self.panel, -1, str("Batch Outputs")) |
---|
[73197d0] | 1187 | hint_sizer = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
[83eb1b52] | 1188 | selection_sizer = wx.GridBagSizer(5, 5) |
---|
[73197d0] | 1189 | button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[caf3a08f] | 1190 | text = "Open with %s" % self.parent.application_name |
---|
[83eb1b52] | 1191 | self.local_app_selected = wx.RadioButton(self.panel, -1, text, |
---|
[73197d0] | 1192 | style=wx.RB_GROUP) |
---|
| 1193 | self.Bind(wx.EVT_RADIOBUTTON, self.onselect, |
---|
| 1194 | id=self.local_app_selected.GetId()) |
---|
| 1195 | text = "Open with Excel" |
---|
[83eb1b52] | 1196 | self.external_app_selected = wx.RadioButton(self.panel, -1, text) |
---|
[73197d0] | 1197 | self.Bind(wx.EVT_RADIOBUTTON, self.onselect, |
---|
| 1198 | id=self.external_app_selected.GetId()) |
---|
[caf3a08f] | 1199 | text = "Save to File" |
---|
[83eb1b52] | 1200 | self.save_to_file = wx.CheckBox(self.panel, -1, text) |
---|
[73197d0] | 1201 | self.Bind(wx.EVT_CHECKBOX, self.onselect, |
---|
| 1202 | id=self.save_to_file.GetId()) |
---|
| 1203 | self.local_app_selected.SetValue(True) |
---|
| 1204 | self.external_app_selected.SetValue(False) |
---|
| 1205 | self.save_to_file.SetValue(False) |
---|
[83eb1b52] | 1206 | button_close = wx.Button(self.panel, -1, "Close") |
---|
| 1207 | button_close.Bind(wx.EVT_BUTTON, id=button_close.GetId(), |
---|
| 1208 | handler=self.on_close) |
---|
| 1209 | button_apply = wx.Button(self.panel, -1, "Apply") |
---|
| 1210 | button_apply.Bind(wx.EVT_BUTTON, id=button_apply.GetId(), |
---|
| 1211 | handler=self.on_apply) |
---|
| 1212 | button_apply.SetFocus() |
---|
[73197d0] | 1213 | hint = "" |
---|
[83eb1b52] | 1214 | hint_sizer.Add(wx.StaticText(self.panel, -1, hint)) |
---|
[73197d0] | 1215 | hint_sizer.Add(selection_sizer) |
---|
| 1216 | #draw area containing radio buttons |
---|
| 1217 | ix = 0 |
---|
| 1218 | iy = 0 |
---|
| 1219 | selection_sizer.Add(self.local_app_selected, (iy, ix), |
---|
| 1220 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1221 | iy += 1 |
---|
| 1222 | selection_sizer.Add(self.external_app_selected, (iy, ix), |
---|
| 1223 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1224 | iy += 1 |
---|
| 1225 | selection_sizer.Add(self.save_to_file, (iy, ix), |
---|
| 1226 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1227 | #contruction the sizer contaning button |
---|
| 1228 | button_sizer.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[caf3a08f] | 1229 | |
---|
| 1230 | button_sizer.Add(button_close, 0, |
---|
| 1231 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[83eb1b52] | 1232 | button_sizer.Add(button_apply, 0, |
---|
[73197d0] | 1233 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
| 1234 | vbox.Add(hint_sizer, 0, wx.EXPAND|wx.ALL, 10) |
---|
[83eb1b52] | 1235 | vbox.Add(wx.StaticLine(self.panel, -1), 0, wx.EXPAND, 0) |
---|
[73197d0] | 1236 | vbox.Add(button_sizer, 0 , wx.TOP|wx.BOTTOM, 10) |
---|
| 1237 | self.SetSizer(vbox) |
---|
| 1238 | |
---|
[83eb1b52] | 1239 | def on_apply(self, event): |
---|
| 1240 | """ |
---|
| 1241 | Get the user selection and display output to the selected application |
---|
| 1242 | """ |
---|
| 1243 | if self.flag == 1: |
---|
[8523a1f2] | 1244 | self.parent.open_with_localapp(data_inputs=self.data_inputs, |
---|
| 1245 | data_outputs=self.data_outputs) |
---|
[83eb1b52] | 1246 | elif self.flag == 2: |
---|
| 1247 | self.parent.open_with_externalapp(data=self.data, |
---|
| 1248 | file_name=self.file_name, |
---|
| 1249 | details=self.details) |
---|
| 1250 | def on_close(self, event): |
---|
| 1251 | """ |
---|
| 1252 | close the Window |
---|
| 1253 | """ |
---|
| 1254 | self.Close() |
---|
| 1255 | |
---|
[73197d0] | 1256 | def onselect(self, event=None): |
---|
| 1257 | """ |
---|
| 1258 | Receive event and display data into third party application |
---|
| 1259 | or save data to file. |
---|
| 1260 | |
---|
| 1261 | """ |
---|
| 1262 | if self.save_to_file.GetValue(): |
---|
[850525c] | 1263 | reader, ext = os.path.splitext(self.file_name) |
---|
| 1264 | path = None |
---|
| 1265 | location = os.getcwd() |
---|
| 1266 | if self.parent is not None: |
---|
[83eb1b52] | 1267 | location = os.path.dirname(self.file_name) |
---|
[850525c] | 1268 | dlg = wx.FileDialog(self, "Save Project file", |
---|
| 1269 | location, self.file_name, ext, wx.SAVE) |
---|
| 1270 | path = None |
---|
| 1271 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1272 | path = dlg.GetPath() |
---|
| 1273 | dlg.Destroy() |
---|
| 1274 | if path != None: |
---|
| 1275 | if self.parent is not None and self.data is not None: |
---|
[83eb1b52] | 1276 | self.parent.write_batch_tofile(data=self.data, |
---|
[850525c] | 1277 | file_name=path, |
---|
| 1278 | details=self.details) |
---|
| 1279 | if self.local_app_selected.GetValue(): |
---|
[73197d0] | 1280 | self.flag = 1 |
---|
| 1281 | else: |
---|
| 1282 | self.flag = 2 |
---|
| 1283 | return self.flag |
---|
| 1284 | |
---|
| 1285 | |
---|
| 1286 | |
---|
[24adb89] | 1287 | if __name__ == "__main__": |
---|
| 1288 | app = wx.App() |
---|
| 1289 | |
---|
| 1290 | try: |
---|
| 1291 | data = {} |
---|
| 1292 | j = 0 |
---|
| 1293 | for i in range(4): |
---|
| 1294 | j += 1 |
---|
| 1295 | data["index"+str(i)] = [i/j, i*j, i, i+j] |
---|
[656d65d] | 1296 | |
---|
| 1297 | data_input = copy.deepcopy(data) |
---|
| 1298 | data_input["index5"] = [10,20,40, 50] |
---|
| 1299 | frame = GridFrame(data_outputs=data, data_inputs=data_input) |
---|
[24adb89] | 1300 | frame.Show(True) |
---|
| 1301 | except: |
---|
| 1302 | print sys.exc_value |
---|
| 1303 | |
---|
| 1304 | app.MainLoop() |
---|