Changeset 76aed53 in sasview for src/sas/guiframe
- Timestamp:
- Mar 4, 2015 2:20:18 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 49ab5d7, 66f21cd
- Parents:
- af6b53c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/data_processor.py
r79492222 r76aed53 10 10 import copy 11 11 from wx.lib.scrolledpanel import ScrolledPanel 12 import wx.grid as Grid13 12 import wx.aui 14 13 from wx.aui import AuiNotebook as nb 15 14 import wx.lib.sheet as sheet 16 15 from sas.guiframe.panel_base import PanelBase 17 from sas.guiframe.events import NewPlotEvent 18 from sas.guiframe.events import StatusEvent 16 from sas.guiframe.events import NewPlotEvent 17 from sas.guiframe.events import StatusEvent 19 18 from sas.plottools import plottables 20 19 from sas.guiframe.dataFitting import Data1D … … 23 22 "pow": "math.sqrt"} 24 23 25 class BatchCell :24 class BatchCell(object): 26 25 """ 27 26 Object describing a cell in the grid. 28 27 29 28 """ 30 29 def __init__(self): … … 34 33 self.row = -1 35 34 self.object = [] 36 35 37 36 38 37 def parse_string(sentence, list): … … 42 41 :param list: list of columns label 43 42 """ 44 toks = []45 43 p2 = re.compile(r'\d+') 46 44 p = re.compile(r'[\+\-\*\%\/]') … … 51 49 temp_arr = [] 52 50 for label in list: 53 label_pos = 54 separator_pos 51 label_pos = elt.find(label) 52 separator_pos = label_pos + len(label) 55 53 if label_pos != -1 and len(elt) >= separator_pos and\ 56 elt[separator_pos] == "[":54 elt[separator_pos] == "[": 57 55 # the label contain , meaning the range selected is not 58 56 # continuous … … 64 62 if range_pos != -1: 65 63 rang = p2.findall(item) 66 for i in xrange(int(rang[0]), int(rang[1]) +1):64 for i in xrange(int(rang[0]), int(rang[1]) + 1): 67 65 new_temp.append(i) 68 66 temp_arr += new_temp … … 75 73 if range_pos != -1: 76 74 rang = p2.findall(item) 77 for i in xrange(int(rang[0]), int(rang[1]) +1):75 for i in xrange(int(rang[0]), int(rang[1]) + 1): 78 76 temp_arr.append(i) 79 77 col_dict[elt] = (label, temp_arr) 80 78 return col_dict 81 79 82 83 80 84 81 class SPanel(ScrolledPanel): 85 82 def __init__(self, parent, *args, **kwds): 86 ScrolledPanel.__init__(self, parent 87 self.SetupScrolling() 88 83 ScrolledPanel.__init__(self, parent, *args, **kwds) 84 self.SetupScrolling() 85 89 86 class GridPage(sheet.CSheet): 90 87 """ … … 94 91 """ 95 92 sheet.CSheet.__init__(self, parent) 96 93 97 94 self.AdjustScrollbars() 98 95 #self.SetLabelBackgroundColour('#DBD4D4') … … 132 129 self.EnableEditing(True) 133 130 if self.GetNumberCols() > 0: 134 self.default_col_width = 131 self.default_col_width = self.GetColSize(0) 135 132 self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.on_left_click) 136 133 self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_right_click) … … 138 135 self.Bind(wx.grid.EVT_GRID_CMD_CELL_CHANGE, self.on_edit_cell) 139 136 self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.onContextMenu) 140 137 141 138 def on_edit_cell(self, event): 142 139 """ 143 140 """ 144 row, col= event.GetRow(), event.GetCol()141 row, _ = event.GetRow(), event.GetCol() 145 142 if row > self.max_row_touse: 146 143 self.max_row_touse = row … … 148 145 self.data = {} 149 146 event.Skip() 150 147 151 148 def on_selected_cell(self, event): 152 149 """ … … 154 151 """ 155 152 flag = event.CmdDown() or event.ControlDown() 156 flag_shift = 153 flag_shift = event.ShiftDown() 157 154 row, col = event.GetRow(), event.GetCol() 158 155 cell = (row, col) … … 181 178 else: 182 179 min_r = min(self.selected_rows) 183 for row_s in range(min_r, row +1):180 for row_s in range(min_r, row + 1): 184 181 cel = (row_s, col) 185 182 if cel not in self.selected_cells: 186 183 if row > 0: 187 184 self.selected_cells.append(cel) 188 self.selected_rows.append(row) 189 for row_s in self.selected_rows: 185 self.selected_rows.append(row) 186 for row_s in self.selected_rows: 190 187 cel = (row_s, col) 191 188 if row_s > row: … … 200 197 elif flag: 201 198 if cell not in self.selected_cells: 202 if row > 0 199 if row > 0: 203 200 self.selected_cells.append(cell) 204 201 self.selected_rows.append(row) … … 226 223 event.Skip() 227 224 flag = event.CmdDown() or event.ControlDown() 228 225 229 226 col = event.GetCol() 230 227 row = event.GetRow() 231 228 232 if not (flag):229 if not flag: 233 230 self.selected_cols = [] 234 231 self.selected_rows = [] … … 239 236 self.plottable_cells = [] 240 237 self.plottable_flag = False 241 238 242 239 self.last_selected_col = col 243 240 self.last_selected_row = row 244 241 if row != -1 and row not in self.selected_rows: 245 246 242 self.selected_rows.append(row) 243 247 244 if col != -1: 248 for row in range(1, self.GetNumberRows() + 1):245 for row in range(1, self.GetNumberRows() + 1): 249 246 cell = (row, col) 250 247 if row > 0 and row < self.max_row_touse: … … 253 250 else: 254 251 if flag: 255 252 self.selected_cells.remove(cell) 256 253 self.selected_cols.append(col) 257 254 self.axis_value = [] … … 263 260 if not self.axis_label: 264 261 self.axis_label = " " 265 262 266 263 def on_right_click(self, event): 267 264 """ 268 265 Catch the right click mouse 269 266 """ 270 271 267 col = event.GetCol() 272 268 row = event.GetRow() … … 278 274 # Slicer plot popup menu 279 275 slicerpop = wx.Menu() 280 col_label_menu 281 c_name = self.GetCellValue(0, col) 276 col_label_menu = wx.Menu() 277 c_name = self.GetCellValue(0, col) 282 278 label = "Insert column before %s " % str(c_name) 283 slicerpop.AppendSubMenu(col_label_menu , 284 '&%s' % str(label), str(label)) 285 col_name = [self.GetCellValue(0, c) 286 for c in range(self.GetNumberCols())] 279 slicerpop.AppendSubMenu(col_label_menu, '&%s' % str(label), str(label)) 287 280 row = 0 288 281 label = self.GetCellValue(row, col) 289 282 self.insert_col_menu(col_label_menu, label, self) 290 291 292 col_after_menu = wx.Menu() 283 284 col_after_menu = wx.Menu() 293 285 label = "Insert column after %s " % str(c_name) 294 slicerpop.AppendSubMenu(col_after_menu , 295 '&%s' % str(label), str(label)) 296 col_name = [self.GetCellValue(0, c) 297 for c in range(self.GetNumberCols())] 286 slicerpop.AppendSubMenu(col_after_menu, '&%s' % str(label), str(label)) 298 287 self.insert_after_col_menu(col_after_menu, label, self) 299 300 301 id = wx.NewId() 288 289 wx_id = wx.NewId() 302 290 hint = 'Remove selected column %s' 303 slicerpop.Append( id, '&Remove Column', hint)304 wx.EVT_MENU(self, id, self.on_remove_column)305 291 slicerpop.Append(wx_id, '&Remove Column', hint) 292 wx.EVT_MENU(self, wx_id, self.on_remove_column) 293 306 294 pos = wx.GetMousePosition() 307 295 pos = self.ScreenToClient(pos) 308 296 self.PopupMenu(slicerpop, pos) 309 297 event.Skip() 310 298 311 299 def insert_col_menu(self, menu, label, window): 312 300 """ … … 320 308 wx.EVT_MENU(window, id, self.on_insert_column) 321 309 row = 0 322 col_name = [self.GetCellValue(row, col) 310 col_name = [self.GetCellValue(row, col) for col in range(self.GetNumberCols())] 311 for c_name in self.data.keys(): 312 if c_name not in col_name and self.data[c_name]: 313 wx_id = wx.NewId() 314 hint = "Insert %s column before the " % str(c_name) 315 hint += " %s column" % str(label) 316 menu.Append(wx_id, '&%s' % str(c_name), hint) 317 wx.EVT_MENU(window, wx_id, self.on_insert_column) 318 319 def insert_after_col_menu(self, menu, label, window): 320 """ 321 """ 322 if self.data is None: 323 return 324 wx_id = wx.NewId() 325 title = "Empty" 326 hint = 'Insert empty column after %s' % str(label) 327 menu.Append(wx_id, title, hint) 328 wx.EVT_MENU(window, wx_id, self.on_insert_after_column) 329 row = 0 330 col_name = [self.GetCellValue(row, col) 323 331 for col in range(self.GetNumberCols())] 324 332 for c_name in self.data.keys(): 325 333 if c_name not in col_name and self.data[c_name]: 326 id = wx.NewId() 327 hint = "Insert %s column before the " % str(c_name) 328 hint += " %s column" % str(label) 329 menu.Append(id, '&%s' % str(c_name), hint) 330 wx.EVT_MENU(window, id, self.on_insert_column) 331 332 def insert_after_col_menu(self, menu, label, window): 333 """ 334 """ 335 if self.data is None: 336 return 337 id = wx.NewId() 338 title = "Empty" 339 hint = 'Insert empty column after %s' % str(label) 340 menu.Append(id, title, hint) 341 wx.EVT_MENU(window, id, self.on_insert_after_column) 342 row = 0 343 col_name = [self.GetCellValue(row, col) 344 for col in range(self.GetNumberCols())] 345 for c_name in self.data.keys(): 346 if c_name not in col_name and self.data[c_name]: 347 id = wx.NewId() 334 wx_id = wx.NewId() 348 335 hint = "Insert %s column after the " % str(c_name) 349 336 hint += " %s column" % str(label) 350 menu.Append( id, '&%s' % str(c_name), hint)351 wx.EVT_MENU(window, id, self.on_insert_after_column)352 337 menu.Append(wx_id, '&%s' % str(c_name), hint) 338 wx.EVT_MENU(window, wx_id, self.on_insert_after_column) 339 353 340 def on_remove_column(self, event=None): 354 341 """ … … 357 344 col = self.selected_cols[0] 358 345 self.remove_column(col=col, numCols=1) 359 346 360 347 def remove_column(self, col, numCols=1): 361 348 """ … … 370 357 value = self.GetCellValue(row, col) 371 358 self.data[col_name].append(value) 372 for k 359 for k, value_list in self.data.iteritems(): 373 360 if k != col_name: 374 361 length = len(value_list) … … 378 365 self.data[k].append("") 379 366 self.DeleteCols(pos=col, numCols=numCols, updateLabels=True) 380 367 381 368 def on_insert_column(self, event): 382 369 """ … … 384 371 if self.selected_cols is not None or len(self.selected_cols) > 0: 385 372 col = self.selected_cols[0] 386 # add data to the grid 387 row = 0 388 id = event.GetId() 389 col_name = event.GetEventObject().GetLabelText(id) 373 # add data to the grid 374 wx_id = event.GetId() 375 col_name = event.GetEventObject().GetLabelText(wx_id) 390 376 self.insert_column(col=col, col_name=col_name) 391 if not issubclass(event.GetEventObject().__class__ 377 if not issubclass(event.GetEventObject().__class__, wx.Menu): 392 378 col += 1 393 379 self.selected_cols[0] += 1 394 380 395 381 def on_insert_after_column(self, event): 396 382 """ … … 399 385 if self.selected_cols is not None or len(self.selected_cols) > 0: 400 386 col = self.selected_cols[0] + 1 401 # add data to the grid 402 row = 0 403 id = event.GetId() 404 col_name = event.GetEventObject().GetLabelText(id) 387 # add data to the grid 388 wx_id = event.GetId() 389 col_name = event.GetEventObject().GetLabelText(wx_id) 405 390 self.insert_column(col=col, col_name=col_name) 406 if not issubclass(event.GetEventObject().__class__ 391 if not issubclass(event.GetEventObject().__class__, wx.Menu): 407 392 self.selected_cols[0] += 1 408 393 409 394 def insert_column(self, col, col_name): 410 395 """ 411 """ 412 396 """ 413 397 row = 0 414 398 self.InsertCols(pos=col, numCols=1, updateLabels=True) … … 417 401 if col_name in self.data.keys(): 418 402 value_list = self.data[col_name] 419 cell_row = 403 cell_row = 1 420 404 for value in value_list: 421 405 label = value#format_number(value, high=True) … … 425 409 width = self.GetColSize(col) 426 410 if width < self.default_col_width: 427 self.SetColSize(col, self.default_col_width)411 self.SetColSize(col, self.default_col_width) 428 412 color = self.parent.GetBackgroundColour() 429 413 self.SetCellBackgroundColour(0, col, color) 430 414 self.ForceRefresh() 431 415 432 416 def on_set_x_axis(self, event): 433 417 """ 434 418 """ 435 419 self.panel.set_xaxis(x=self.axis_value, label=self.axis_label) 436 420 437 421 def on_set_y_axis(self, event): 438 422 """ 439 423 """ 440 self.panel.set_yaxis(y=self.axis_value, label=self.axis_label) 441 424 self.panel.set_yaxis(y=self.axis_value, label=self.axis_label) 425 442 426 def set_data(self, data_inputs, data_outputs, details, file_name): 443 427 """ … … 448 432 self.file_name = file_name 449 433 self.details = details 450 434 451 435 if data_outputs is None: 452 436 data_outputs = {} … … 458 442 for item in (self.data_outputs, self.data_inputs): 459 443 self.data.update(item) 460 461 #if len(self.data) + len(self.data_inputs) +len(self.data_outputs) == 0: 462 # self.EnableEditing(False) 463 #else: 464 # self.EnableEditing(True) 444 465 445 if len(self.data_outputs) > 0: 466 446 self._cols = self.GetNumberCols() 467 447 self._rows = self.GetNumberRows() 468 448 self.col_names = self.data_outputs.keys() 469 self.col_names.sort() 449 self.col_names.sort() 470 450 nbr_user_cols = len(self.col_names) 471 451 #Add more columns to the grid if necessary 472 452 if nbr_user_cols > self._cols: 473 new_col_nbr = nbr_user_cols - 453 new_col_nbr = nbr_user_cols - self._cols + 1 474 454 self.AppendCols(new_col_nbr, True) 475 #Add more rows to the grid if necessary 455 #Add more rows to the grid if necessary 476 456 nbr_user_row = len(self.data_outputs.values()[0]) 477 457 if nbr_user_row > self._rows + 1: 478 new_row_nbr = 458 new_row_nbr = nbr_user_row - self._rows + 1 479 459 self.AppendRows(new_row_nbr, True) 480 # add data to the grid 460 # add data to the grid 481 461 wx.CallAfter(self.set_grid_values) 482 462 self.ForceRefresh() 483 463 484 464 def set_grid_values(self): 485 465 """ 486 466 Set the values in grids 487 467 """ 488 # add data to the grid 468 # add data to the grid 489 469 row = 0 490 470 col = 0 … … 494 474 self.SetCellValue(row, col, str(col_name)) 495 475 col += 1 496 cell_row = 476 cell_row = 1 497 477 value_list = self.data_outputs[col_name] 498 478 499 479 for value in value_list: 500 480 label = value … … 510 490 width = self.GetColSize(cell_col) 511 491 if width < self.default_col_width: 512 self.SetColSize(cell_col, self.default_col_width)513 492 self.SetColSize(cell_col, self.default_col_width) 493 514 494 cell_row += 1 515 495 cell_col += 1 516 496 if cell_row > self.max_row_touse: 517 497 self.max_row_touse = cell_row 518 498 519 499 def get_grid_view(self): 520 500 """ … … 523 503 grid_view = {} 524 504 for col in xrange(self.GetNumberCols()): 525 label = self.GetCellValue(row=0, col=col) 505 label = self.GetCellValue(row=0, col=col) 526 506 label = label.strip() 527 507 if label != "": … … 530 510 value = self.GetCellValue(row=row, col=col) 531 511 if value != "": 532 grid_view[label].append(value) 512 grid_view[label].append(value) 533 513 else: 534 grid_view[label].append(None) 514 grid_view[label].append(None) 535 515 return grid_view 536 516 537 517 def get_nofrows(self): 538 518 """ … … 540 520 """ 541 521 return self._rows 542 522 543 523 def onContextMenu(self, event): 544 524 """ 545 Default context menu 546 """ 547 id = wx.NewId()525 Default context menu 526 """ 527 wx_id = wx.NewId() 548 528 c_menu = wx.Menu() 549 copy_menu = c_menu.Append( id, '&Copy', 'Copy the selected cells')550 wx.EVT_MENU(self, id, self.on_copy)551 552 id = wx.NewId()553 paste_menu = c_menu.Append(id, '&Paste', 'Paste the selected cells')554 wx.EVT_MENU(self, id, self.on_paste)555 556 id = wx.NewId()557 clear_menu = c_menu.Append( id, '&Clear', 'Clear the selected cells')558 wx.EVT_MENU(self, id, self.on_clear)559 529 copy_menu = c_menu.Append(wx_id, '&Copy', 'Copy the selected cells') 530 wx.EVT_MENU(self, wx_id, self.on_copy) 531 532 wx_id = wx.NewId() 533 c_menu.Append(wx_id, '&Paste', 'Paste the selected cells') 534 wx.EVT_MENU(self, wx_id, self.on_paste) 535 536 wx_id = wx.NewId() 537 clear_menu = c_menu.Append(wx_id, '&Clear', 'Clear the selected cells') 538 wx.EVT_MENU(self, wx_id, self.on_clear) 539 560 540 # enable from flag 561 541 has_selection = False … … 576 556 except: 577 557 return 578 558 579 559 def on_copy(self, event): 580 560 """ … … 592 572 self.file_name = 'copied_data' 593 573 self.Paste() 594 574 595 575 def on_clear(self, event): 596 576 """ … … 598 578 """ 599 579 self.Clear() 600 580 601 581 class Notebook(nb, PanelBase): 602 582 """ … … 606 586 """ 607 587 window_caption = "Notebook " 608 588 609 589 def __init__(self, parent, manager=None, data=None, *args, **kwargs): 610 590 """ 611 591 """ 612 592 nb.__init__(self, parent, -1, 613 style=wx.aui.AUI_NB_WINDOWLIST_BUTTON |614 wx.aui.AUI_BUTTON_DOWN |615 wx.aui.AUI_NB_DEFAULT_STYLE |593 style=wx.aui.AUI_NB_WINDOWLIST_BUTTON | 594 wx.aui.AUI_BUTTON_DOWN | 595 wx.aui.AUI_NB_DEFAULT_STYLE | 616 596 wx.CLIP_CHILDREN) 617 597 PanelBase.__init__(self, parent) … … 624 604 self.add_empty_page() 625 605 self.pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE 626 self.Bind(self.pageClosedEvent, self.on_close_page) 627 606 self.Bind(self.pageClosedEvent, self.on_close_page) 607 628 608 def add_empty_page(self): 629 609 """ … … 637 617 self.enable_close_button() 638 618 self.gpage_num += 1 639 return grid 640 619 return grid, pos 620 641 621 def enable_close_button(self): 642 622 """ 643 display the close button on tab for more than 1 tabs else remove the 623 display the close button on tab for more than 1 tabs else remove the 644 624 close button 645 625 """ 646 626 if self.GetPageCount() <= 1: 647 style = self.GetWindowStyleFlag() 627 style = self.GetWindowStyleFlag() 648 628 flag = wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB 649 629 if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB == flag: … … 656 636 style |= wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB 657 637 self.SetWindowStyle(style) 658 638 659 639 def on_edit_axis(self): 660 640 """ … … 672 652 msg += "Please select only one column" 673 653 raise ValueError, msg 674 for ( cell_row, cell_col) in grid.selected_cells:654 for (_, cell_col) in grid.selected_cells: 675 655 if cell_col != col: 676 656 msg = "Cannot use cells from different columns for " … … 678 658 msg += "Please select elements of the same col.\n" 679 659 raise ValueError, msg 680 660 681 661 # Finally check the highlighted cell if any cells missing 682 662 self.get_highlighted_row(True) … … 686 666 raise ValueError, msg 687 667 return grid.selected_cells 688 668 689 669 def get_highlighted_row(self, is_number=True): 690 670 """ … … 706 686 continue 707 687 if is_number: 708 try: 688 try: 709 689 float(grid.GetCellValue(row, col)) 710 690 except: … … 715 695 if cel not in grid.selected_cells: 716 696 grid.selected_cells.append(cel) 717 697 718 698 def get_column_labels(self): 719 699 """ … … 723 703 grid = self.GetPage(pos) 724 704 labels = {} 725 row = 0726 705 for col in range(grid.GetNumberCols()): 727 706 label = grid.GetColLabelValue(int(col)) 728 #label = grid.GetCellValue(row, col) 729 if label.strip() != "" : 707 if label.strip() != "": 730 708 labels[label.strip()] = col 731 709 return labels 732 710 733 711 def create_axis_label(self, cell_list): 734 712 """ 735 Receive a list of cells and create a string presenting the selected 736 cells. 713 Receive a list of cells and create a string presenting the selected 714 cells. 737 715 :param cell_list: list of tuple 738 716 739 717 """ 740 718 pos = self.GetSelection() … … 742 720 label = "" 743 721 col_name = "" 744 def create_label(col_name, 722 def create_label(col_name, row_min=None, row_max=None): 745 723 """ 746 724 """ … … 750 728 result = str(row_max) + "]" 751 729 elif row_max is None: 752 730 result = str(col_name) + "[" + str(row_min) + ":" 753 731 else: 754 result = str(col_name) + 732 result = str(col_name) + "[" + str(row_min) + ":" 755 733 result += str(row_max) + "]" 756 734 return str(result) 757 735 758 736 if len(cell_list) > 0: 759 737 if len(cell_list) == 1: 760 row_min, col = cell_list[0]761 col_name = 762 738 row_min, col = cell_list[0] 739 col_name = grid.GetColLabelValue(int(col)) 740 763 741 col_title = grid.GetCellValue(0, col) 764 label = create_label(col_name, row_min +1 , row_min+1)765 return label, 742 label = create_label(col_name, row_min + 1, row_min + 1) 743 return label, col_title 766 744 else: 767 745 temp_list = copy.deepcopy(cell_list) 768 746 temp_list.sort() 769 747 length = len(temp_list) 770 row_min, col = temp_list[0]771 row_max, _ = temp_list[length-1]748 row_min, col = temp_list[0] 749 row_max, _ = temp_list[length - 1] 772 750 col_name = grid.GetColLabelValue(int(col)) 773 751 col_title = grid.GetCellValue(0, col) … … 779 757 if row != new_row: 780 758 temp_list.insert(index, (None, None)) 781 if index - 1 >= 0:782 new_row, _ = temp_list[index -1]783 if not new_row == None and new_row != ' ' 784 label += create_label(col_name, None, 785 int(new_row) + 1)759 if index - 1 >= 0: 760 new_row, _ = temp_list[index - 1] 761 if not new_row == None and new_row != ' ': 762 label += create_label(col_name, None, 763 int(new_row) + 1) 786 764 else: 787 765 label += "]" … … 789 767 if index + 1 < len(temp_list): 790 768 new_row, _ = temp_list[index + 1] 791 if not new_row ==None:792 label += create_label(col_name, 793 int(new_row) +1, None)769 if not new_row == None: 770 label += create_label(col_name, 771 int(new_row) + 1, None) 794 772 if row_min != None and row_max != None: 795 773 if index == 0: 796 label += create_label(col_name, 797 int(row_min) +1, None)798 elif index == len(temp_list) -1:799 label += create_label(col_name, None, 800 int(row_max) +1)774 label += create_label(col_name, 775 int(row_min) + 1, None) 776 elif index == len(temp_list) - 1: 777 label += create_label(col_name, None, 778 int(row_max) + 1) 801 779 index += 1 802 780 # clean up the list … … 809 787 810 788 return label_out, col_title 811 789 812 790 def on_close_page(self, event): 813 791 """ … … 817 795 event.Veto() 818 796 wx.CallAfter(self.enable_close_button) 819 797 820 798 def set_data(self, data_inputs, data_outputs, details="", file_name=None): 821 799 if data_outputs is None or data_outputs == {}: … … 826 804 if grid.data is None: 827 805 #Found empty page 828 grid.set_data(data_inputs=inputs, 806 grid.set_data(data_inputs=inputs, 829 807 data_outputs=outputs, 830 808 details=details, 831 file_name=file_name) 832 self.SetSelection(pos) 809 file_name=file_name) 810 self.SetSelection(pos) 833 811 return 834 812 835 813 grid, pos = self.add_empty_page() 836 grid.set_data(data_inputs=inputs, 814 grid.set_data(data_inputs=inputs, 837 815 data_outputs=outputs, 838 816 file_name=file_name, 839 817 details=details) 840 818 841 819 def get_odered_results(self, inputs, outputs=None): 842 820 """ … … 868 846 else: 869 847 inputs[key] = [] 870 #print "Different length in %s: Removed from Listing."% key 871 848 872 849 return inputs, outputs 873 850 874 851 def add_column(self): 875 852 """ … … 879 856 grid = self.GetPage(pos) 880 857 grid.AppendCols(1, True) 881 858 882 859 def on_remove_column(self): 883 860 """ … … 887 864 grid = self.GetPage(pos) 888 865 grid.on_remove_column(event=None) 889 866 890 867 class GridPanel(SPanel): 891 868 def __init__(self, parent, data_inputs=None, 892 869 data_outputs=None, *args, **kwds): 893 SPanel.__init__(self, parent 894 870 SPanel.__init__(self, parent, *args, **kwds) 871 895 872 self.vbox = wx.BoxSizer(wx.VERTICAL) 896 873 897 874 self.plotting_sizer = wx.FlexGridSizer(3, 7, 10, 5) 898 875 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) … … 906 883 self._data_outputs = data_outputs 907 884 self.x = [] 908 self.y 909 self.dy 885 self.y = [] 886 self.dy = [] 910 887 self.x_axis_label = None 911 888 self.y_axis_label = None … … 919 896 self.notebook = None 920 897 self.plot_num = 1 921 898 922 899 self.layout_grid() 923 900 self.layout_plotting_area() … … 932 909 self.x_axis_label.SetValue("%s[:]" % str(label)) 933 910 self.x_axis_title.SetValue(str(label)) 934 911 935 912 def set_yaxis(self, label="", y=None): 936 913 """ … … 941 918 self.y_axis_label.SetValue("%s[:]" % str(label)) 942 919 self.y_axis_title.SetValue(str(label)) 943 920 944 921 def set_dyaxis(self, label="", dy=None): 945 922 """ … … 949 926 self.dy = dy 950 927 self.dy_axis_label.SetValue("%s[:]" % str(label)) 951 928 952 929 def get_plot_axis(self, col, list): 953 930 """ 954 931 955 932 """ 956 933 axis = [] … … 967 944 axis.append(float(value)) 968 945 except: 969 msg = "Invalid data in row %s column %s" % (str(row), 970 str(col)) 971 wx.PostEvent(self.parent.parent, 972 StatusEvent(status=msg, info="error")) 946 msg = "Invalid data in row %s column %s" % (str(row), str(col)) 947 wx.PostEvent(self.parent.parent, 948 StatusEvent(status=msg, info="error")) 973 949 return None 974 950 else: 975 axis.append(None) 951 axis.append(None) 976 952 return axis 977 953 978 954 def on_view(self, event): 979 955 """ … … 986 962 if len(grid.selected_cells) == 0: 987 963 msg = "Highlight a Data or Chi2 column first..." 988 wx.PostEvent(self.parent.parent, 989 StatusEvent(status=msg, info="error")) 964 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 990 965 return 991 966 elif len(grid.selected_cells) > 20: 992 967 msg = "Too many data (> 20) to plot..." 993 968 msg += "\n Please select no more than 20 data." 994 dial = wx.MessageDialog(self, msg, 'Plotting', wx.OK) 995 wx.PostEvent(self.parent.parent, 996 StatusEvent(status=msg, info="error")) 969 wx.MessageDialog(self, msg, 'Plotting', wx.OK) 970 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 997 971 return 998 972 … … 1004 978 values = grid.data[label] 1005 979 if row > len(values) or row < 1: 1006 msg = "Invalid cell was chosen." 1007 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 1008 info="error")) 980 msg = "Invalid cell was chosen." 981 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1009 982 continue 1010 983 else: 1011 value = values[row -1]984 value = values[row - 1] 1012 985 if issubclass(value.__class__, BatchCell): 1013 986 if value.object is None or len(value.object) == 0: … … 1015 988 msg += "Column %s is NOT " % str(label) 1016 989 msg += "the results of fits to view..." 1017 #raise ValueError, msg 1018 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 1019 info="error")) 990 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1020 991 return 1021 992 for new_plot in value.object: 1022 993 if new_plot is None or \ 1023 not issubclass(new_plot.__class__, 994 not issubclass(new_plot.__class__, 1024 995 plottables.Plottable): 1025 996 msg = "Row %s , " % str(row) 1026 997 msg += "Column %s is NOT " % str(label) 1027 998 msg += "the results of fits to view..." 1028 #raise ValueError, msg 1029 wx.PostEvent(self.parent.parent, 1030 StatusEvent(status=msg, info="error")) 999 wx.PostEvent(self.parent.parent, 1000 StatusEvent(status=msg, info="error")) 1031 1001 return 1032 #continue1033 #new_plot.name = title + ': ' + new_plot.title1034 1002 if issubclass(new_plot.__class__, Data1D): 1035 1003 if label in grid.list_plot_panels.keys(): … … 1046 1014 msg = "2D View: Please select one data set" 1047 1015 msg += " at a time for View Fit Results." 1048 wx.PostEvent(self.parent.parent, 1049 StatusEvent(status=msg, 1050 info="error")) 1016 wx.PostEvent(self.parent.parent, 1017 StatusEvent(status=msg, info="error")) 1051 1018 return 1052 1019 1053 wx.PostEvent(self.parent.parent, 1054 NewPlotEvent(plot=new_plot, 1055 group_id=str(new_plot.group_id),1056 title=title))1020 wx.PostEvent(self.parent.parent, 1021 NewPlotEvent(plot=new_plot, 1022 group_id=str(new_plot.group_id), 1023 title=title)) 1057 1024 msg = "Plotting the View Fit Results completed!" 1058 wx.PostEvent( self.parent.parent, 1059 StatusEvent(status=msg)) 1025 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1060 1026 else: 1061 1062 1027 msg = "Row %s , " % str(row) 1063 1028 msg += "Column %s is NOT " % str(label) 1064 1029 msg += "the results of fits to view..." 1065 wx.PostEvent(self.parent.parent, 1066 StatusEvent(status=msg, info="error")) 1030 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1067 1031 return 1068 1032 1069 1033 def on_plot(self, event): 1070 1034 """ 1071 1035 Evaluate the contains of textcrtl and plot result 1072 """ 1036 """ 1073 1037 pos = self.notebook.GetSelection() 1074 1038 grid = self.notebook.GetPage(pos) … … 1084 1048 except: 1085 1049 msg = "X axis value error." 1086 wx.PostEvent(self.parent.parent, 1087 StatusEvent(status=msg, info="error")) 1050 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1088 1051 return 1089 1052 dict = parse_string(sentence, column_names.keys()) 1090 1053 1091 1054 try: 1092 1055 sentence = self.get_sentence(dict, sentence, column_names) … … 1094 1057 except: 1095 1058 msg = "Need a proper x-range." 1096 wx.PostEvent(self.parent.parent, 1097 StatusEvent(status=msg, info="error")) 1059 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1098 1060 return 1099 1061 #evaluate y … … 1105 1067 except: 1106 1068 msg = "Y axis value error." 1107 wx.PostEvent(self.parent.parent, 1108 StatusEvent(status=msg, info="error")) 1069 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1109 1070 return 1110 1071 dict = parse_string(sentence, column_names.keys()) … … 1114 1075 except: 1115 1076 msg = "Need a proper y-range." 1116 wx.PostEvent(self.parent.parent, 1117 StatusEvent(status=msg, info="error")) 1077 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1118 1078 return 1119 1079 #evaluate y … … 1127 1087 except: 1128 1088 msg = "Need a proper dy-range." 1129 wx.PostEvent(self.parent.parent, 1130 StatusEvent(status=msg, info="error")) 1089 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1131 1090 return 1132 1091 if len(x) != len(y) or (len(x) == 0 or len(y) == 0): 1133 1092 msg = "Need same length for X and Y axis and both greater than 0" 1134 1093 msg += " to plot.\n" 1135 msg += "Got X length = %s, Y length = %s" % (str(len(x)), 1136 str(len(y))) 1137 wx.PostEvent(self.parent.parent, 1138 StatusEvent(status=msg, info="error")) 1094 msg += "Got X length = %s, Y length = %s" % (str(len(x)), str(len(y))) 1095 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1139 1096 return 1140 if dy != None and (len(y) != len(dy)): 1097 if dy != None and (len(y) != len(dy)): 1141 1098 msg = "Need same length for Y and dY axis and both greater than 0" 1142 1099 msg += " to plot.\n" 1143 msg += "Got Y length = %s, dY length = %s" % (str(len(y)), 1144 str(len(dy))) 1145 wx.PostEvent(self.parent.parent, 1146 StatusEvent(status=msg, info="error")) 1100 msg += "Got Y length = %s, dY length = %s" % (str(len(y)), str(len(dy))) 1101 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1147 1102 return 1148 1103 if dy == None: … … 1150 1105 #plotting 1151 1106 new_plot = Data1D(x=x, y=y, dy=dy) 1152 new_plot.id = 1107 new_plot.id = wx.NewId() 1153 1108 new_plot.is_data = False 1154 1109 new_plot.group_id = wx.NewId() 1155 1110 y_title = self.y_axis_title.GetValue() 1156 1111 x_title = self.x_axis_title.GetValue() 1157 title = "%s_vs_%s" % (y_title, 1158 x_title) 1159 new_plot.xaxis(x_title, 1160 self.x_axis_unit.GetValue()) 1161 new_plot.yaxis(y_title, 1162 self.y_axis_unit.GetValue()) 1112 title = "%s_vs_%s" % (y_title, x_title) 1113 new_plot.xaxis(x_title, self.x_axis_unit.GetValue()) 1114 new_plot.yaxis(y_title, self.y_axis_unit.GetValue()) 1163 1115 try: 1164 1116 title = y_title.strip() 1165 1166 1117 title += "_" + self.notebook.GetPageText(pos) 1167 1118 title += "_" + str(self.plot_num) … … 1169 1120 new_plot.name = title 1170 1121 new_plot.xtransform = "x" 1171 new_plot.ytransform = "y" 1172 #new_plot.is_data = False 1173 wx.PostEvent(self.parent.parent, 1174 NewPlotEvent(plot=new_plot, 1175 group_id=str(new_plot.group_id), title =title)) 1122 new_plot.ytransform = "y" 1123 wx.PostEvent(self.parent.parent, 1124 NewPlotEvent(plot=new_plot, 1125 group_id=str(new_plot.group_id), title=title)) 1176 1126 msg = "Plotting completed!" 1177 wx.PostEvent( self.parent.parent, 1178 StatusEvent(status=msg)) 1179 self.parent.parent.update_theory(data_id=new_plot.id, 1180 theory=new_plot) 1127 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1128 self.parent.parent.update_theory(data_id=new_plot.id, theory=new_plot) 1181 1129 except: 1182 wx.PostEvent(self.parent.parent, 1183 StatusEvent(status=msg, info="error")) 1184 1130 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1131 1185 1132 def get_sentence(self, dict, sentence, column_names): 1186 1133 """ … … 1192 1139 if axis == None: 1193 1140 return None 1194 sentence = sentence.replace(tok, 1195 "numpy.array(%s)" % str(axis)) 1141 sentence = sentence.replace(tok, "numpy.array(%s)" % str(axis)) 1196 1142 for key, value in FUNC_DICT.iteritems(): 1197 1143 sentence = sentence.replace(key.lower(), value) 1198 1144 return sentence 1199 1145 1200 1146 def layout_grid(self): 1201 1147 """ … … 1205 1151 self.notebook.set_data(self._data_inputs, self._data_outputs) 1206 1152 self.grid_sizer.Add(self.notebook, 1, wx.EXPAND, 0) 1207 1153 1208 1154 def layout_plotting_area(self): 1209 1155 """ … … 1221 1167 self.dy_axis_label = wx.TextCtrl(self, -1, size=(200, -1)) 1222 1168 self.x_axis_add = wx.Button(self, -1, "Add") 1223 self.x_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1224 id=self.x_axis_add.GetId())1169 self.x_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1170 id=self.x_axis_add.GetId()) 1225 1171 self.y_axis_add = wx.Button(self, -1, "Add") 1226 self.y_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1227 id=self.y_axis_add.GetId())1172 self.y_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1173 id=self.y_axis_add.GetId()) 1228 1174 self.dy_axis_add = wx.Button(self, -1, "Add") 1229 self.dy_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1230 id=self.dy_axis_add.GetId())1175 self.dy_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1176 id=self.dy_axis_add.GetId()) 1231 1177 self.x_axis_unit = wx.TextCtrl(self, -1) 1232 1178 self.y_axis_unit = wx.TextCtrl(self, -1) … … 1238 1184 plot_tip = "Highlight a column for each axis and \n" 1239 1185 plot_tip += "click the Add buttons first." 1240 1186 1241 1187 self.plot_button.SetToolTipString(plot_tip) 1242 1188 boxsizer1.AddMany([(note_text, 0, wx.LEFT, 10), 1243 (self.view_button, 0, wx.LEFT |wx.RIGHT, 10)])1244 self.button_sizer.AddMany([(boxsizer1, 0, 1245 wx.LEFT |wx.RIGHT|wx.BOTTOM, 10),1246 (self.plot_button, 0, 1247 wx.LEFT |wx.TOP|wx.BOTTOM|wx.EXPAND, 12)])1248 1189 (self.view_button, 0, wx.LEFT | wx.RIGHT, 10)]) 1190 self.button_sizer.AddMany([(boxsizer1, 0, 1191 wx.LEFT | wx.RIGHT | wx.BOTTOM, 10), 1192 (self.plot_button, 0, 1193 wx.LEFT | wx.TOP | wx.BOTTOM | wx.EXPAND, 12)]) 1194 1249 1195 wx.EVT_BUTTON(self, self.plot_button.GetId(), self.on_plot) 1250 self.plotting_sizer.AddMany([ 1251 (wx.StaticText(self, -1, 1252 "X-axis Label\nSelection Range"), 1, 1253 wx.TOP|wx.BOTTOM|wx.LEFT, 10), 1254 (self.x_axis_label, 1, wx.TOP|wx.BOTTOM, 10), 1255 (self.x_axis_add, 1, wx.TOP|wx.BOTTOM|wx.RIGHT, 10), 1256 (wx.StaticText(self, -1, "X-axis Label"), 1, 1257 wx.TOP|wx.BOTTOM|wx.LEFT, 10), 1258 (self.x_axis_title, 1, wx.TOP|wx.BOTTOM, 10), 1259 (wx.StaticText(self, -1 , "X-axis Unit"), 1, 1260 wx.TOP|wx.BOTTOM, 10), 1261 (self.x_axis_unit, 1, wx.TOP|wx.BOTTOM, 10), 1262 (wx.StaticText(self, -1, 1263 "Y-axis Label\nSelection Range"), 1, 1264 wx.BOTTOM|wx.LEFT, 10), 1196 self.plotting_sizer.AddMany(\ 1197 [(wx.StaticText(self, -1, "X-axis Label\nSelection Range"), 1, 1198 wx.TOP | wx.BOTTOM | wx.LEFT, 10), 1199 (self.x_axis_label, 1, wx.TOP | wx.BOTTOM, 10), 1200 (self.x_axis_add, 1, wx.TOP | wx.BOTTOM | wx.RIGHT, 10), 1201 (wx.StaticText(self, -1, "X-axis Label"), 1, wx.TOP | wx.BOTTOM | wx.LEFT, 10), 1202 (self.x_axis_title, 1, wx.TOP | wx.BOTTOM, 10), 1203 (wx.StaticText(self, -1, "X-axis Unit"), 1, wx.TOP | wx.BOTTOM, 10), 1204 (self.x_axis_unit, 1, wx.TOP | wx.BOTTOM, 10), 1205 (wx.StaticText(self, -1, "Y-axis Label\nSelection Range"), 1, 1206 wx.BOTTOM | wx.LEFT, 10), 1265 1207 (self.y_axis_label, wx.BOTTOM, 10), 1266 (self.y_axis_add, 1, wx.BOTTOM |wx.RIGHT, 10),1267 (wx.StaticText(self, -1, "Y-axis Label"), 1, 1268 wx.BOTTOM |wx.LEFT, 10),1269 (self.y_axis_title, 1270 (wx.StaticText(self, -1 1208 (self.y_axis_add, 1, wx.BOTTOM | wx.RIGHT, 10), 1209 (wx.StaticText(self, -1, "Y-axis Label"), 1, 1210 wx.BOTTOM | wx.LEFT, 10), 1211 (self.y_axis_title, wx.BOTTOM, 10), 1212 (wx.StaticText(self, -1, "Y-axis Unit"), 1, wx.BOTTOM, 10), 1271 1213 (self.y_axis_unit, 1, wx.BOTTOM, 10), 1272 (wx.StaticText(self, -1, 1273 "dY-Bar (Optional)\nSelection Range"), 1274 1, wx.BOTTOM|wx.LEFT, 10), 1214 (wx.StaticText(self, -1, "dY-Bar (Optional)\nSelection Range"), 1215 1, wx.BOTTOM | wx.LEFT, 10), 1275 1216 (self.dy_axis_label, wx.BOTTOM, 10), 1276 (self.dy_axis_add, 1, wx.BOTTOM|wx.RIGHT, 10), 1277 (-1, -1), 1278 (-1, -1), 1279 (-1, -1), 1280 #(-1, -1), 1281 #(-1, -1), 1282 #(-1, -1), 1283 (-1, 1)]) 1284 1217 (self.dy_axis_add, 1, wx.BOTTOM | wx.RIGHT, 10), 1218 (-1, -1), 1219 (-1, -1), 1220 (-1, -1), 1221 (-1, 1)]) 1222 1285 1223 def on_edit_axis(self, event): 1286 1224 """ … … 1292 1230 except: 1293 1231 msg = str(sys.exc_value) 1294 wx.PostEvent(self.parent.parent, 1295 StatusEvent(status=msg, info="error")) 1296 return 1232 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="error")) 1233 return 1297 1234 tcrtl = event.GetEventObject() 1298 1235 if tcrtl == self.x_axis_add: 1299 self.edit_axis_helper(self.x_axis_label, self.x_axis_title, 1300 label, title) 1236 self.edit_axis_helper(self.x_axis_label, self.x_axis_title, label, title) 1301 1237 elif tcrtl == self.y_axis_add: 1302 self.edit_axis_helper(self.y_axis_label, self.y_axis_title, 1303 label, title) 1238 self.edit_axis_helper(self.y_axis_label, self.y_axis_title, label, title) 1304 1239 elif tcrtl == self.dy_axis_add: 1305 self.edit_axis_helper(self.dy_axis_label, None, 1306 label, None) 1307 1240 self.edit_axis_helper(self.dy_axis_label, None, label, None) 1241 1308 1242 def create_axis_label(self, cell_list): 1309 1243 """ 1310 Receive a list of cells and create a string presenting the selected 1311 cells. 1244 Receive a list of cells and create a string presenting the selected 1245 cells. 1312 1246 :param cell_list: list of tuple 1313 1247 1314 1248 """ 1315 1249 if self.notebook is not None: 1316 1250 return self.notebook.create_axis_label(cell_list) 1317 1251 1318 1252 def edit_axis_helper(self, tcrtl_label, tcrtl_title, label, title): 1319 1253 """ … … 1324 1258 if title != None: 1325 1259 tcrtl_title.SetValue(str(title)) 1326 1260 1327 1261 def add_column(self): 1328 1262 """ … … 1330 1264 if self.notebook is not None: 1331 1265 self.notebook.add_column() 1332 1266 1333 1267 def on_remove_column(self): 1334 1268 """ … … 1336 1270 if self.notebook is not None: 1337 1271 self.notebook.on_remove_column() 1338 1339 1272 1273 1340 1274 class GridFrame(wx.Frame): 1341 def __init__(self, parent=None, data_inputs=None, data_outputs=None, id=-1, 1275 def __init__(self, parent=None, data_inputs=None, data_outputs=None, id=-1, 1342 1276 title="Grid Window", size=(800, 500)): 1343 1277 wx.Frame.__init__(self, parent=parent, id=id, title=title, size=size) … … 1346 1280 menubar = wx.MenuBar() 1347 1281 self.SetMenuBar(menubar) 1348 1282 1349 1283 self.curr_col = None 1350 1284 self.curr_grid = None … … 1352 1286 self.file = wx.Menu() 1353 1287 menubar.Append(self.file, "&File") 1354 1288 1355 1289 hint = "Open file containing batch results" 1356 1290 open_menu = self.file.Append(wx.NewId(), 'Open ', hint) 1357 1291 wx.EVT_MENU(self, open_menu.GetId(), self.on_open) 1358 1292 1359 1293 hint = "Open the the current grid into excel" 1360 1294 self.open_excel_menu = self.file.Append(wx.NewId(), 'Open with Excel', hint) … … 1363 1297 self.save_menu = self.file.Append(wx.NewId(), 'Save As', 'Save into File') 1364 1298 wx.EVT_MENU(self, self.save_menu.GetId(), self.on_save_page) 1365 1299 1366 1300 self.edit = wx.Menu() 1367 1368 add_table_menu = self.edit.Append(-1, 'New Table', 1301 1302 add_table_menu = self.edit.Append(-1, 'New Table', 1369 1303 'Add a New Table') 1370 1304 self.edit.AppendSeparator() 1371 1305 wx.EVT_MENU(self, add_table_menu.GetId(), self.add_table) 1372 1373 self.copy_menu = self.edit.Append(-1, 'Copy', 1306 1307 self.copy_menu = self.edit.Append(-1, 'Copy', 1374 1308 'Copy the selected cells') 1375 1309 wx.EVT_MENU(self, self.copy_menu.GetId(), self.on_copy) 1376 self.paste_menu = self.edit.Append(-1, 'Paste', 1310 self.paste_menu = self.edit.Append(-1, 'Paste', 1377 1311 'Paste the selected Cells') 1378 1312 wx.EVT_MENU(self, self.paste_menu.GetId(), self.on_paste) 1379 self.clear_menu = self.edit.Append(-1, 'Clear', 1313 self.clear_menu = self.edit.Append(-1, 'Clear', 1380 1314 'Clear the selected Cells') 1381 1315 wx.EVT_MENU(self, self.clear_menu.GetId(), self.on_clear) … … 1384 1318 hint = "Insert column before the selected column" 1385 1319 self.insert_before_menu = wx.Menu() 1386 self.insertb_sub_menu = self.edit.AppendSubMenu(self.insert_before_menu, 1387 'Insert Before', hint)1320 self.insertb_sub_menu = self.edit.AppendSubMenu(self.insert_before_menu, 1321 'Insert Before', hint) 1388 1322 hint = "Insert column after the selected column" 1389 1323 self.insert_after_menu = wx.Menu() 1390 self.inserta_sub_menu = self.edit.AppendSubMenu(self.insert_after_menu, 1391 'Insert After', hint)1324 self.inserta_sub_menu = self.edit.AppendSubMenu(self.insert_after_menu, 1325 'Insert After', hint) 1392 1326 hint = "Remove the selected column" 1393 1327 self.remove_menu = self.edit.Append(-1, 'Remove Column', hint) 1394 1328 wx.EVT_MENU(self, self.remove_menu.GetId(), self.on_remove_column) 1395 1329 1396 1330 self.Bind(wx.EVT_MENU_OPEN, self.on_menu_open) 1397 1331 menubar.Append(self.edit, "&Edit") 1398 1332 self.Bind(wx.EVT_CLOSE, self.on_close) 1399 1333 1400 1334 def on_copy(self, event): 1401 1335 """ … … 1407 1341 grid = self.panel.notebook.GetPage(pos) 1408 1342 grid.Copy() 1409 1343 1410 1344 def on_paste(self, event): 1411 1345 """ … … 1425 1359 grid = self.panel.notebook.GetPage(pos) 1426 1360 grid.Clear() 1427 1361 1428 1362 def GetLabelText(self, id): 1429 1363 """ … … 1431 1365 """ 1432 1366 for item in self.insert_before_menu.GetMenuItems(): 1433 m_id = item.GetId() 1367 m_id = item.GetId() 1434 1368 if m_id == id: 1435 return item.GetLabel() 1436 1369 return item.GetLabel() 1370 1437 1371 def on_remove_column(self, event): 1438 1372 """ … … 1442 1376 grid = self.panel.notebook.GetPage(pos) 1443 1377 grid.on_remove_column(event=None) 1444 1378 1445 1379 def on_menu_open(self, event): 1446 1380 """ … … 1451 1385 grid = self.panel.notebook.GetPage(pos) 1452 1386 has_data = (grid.data != None and grid.data != {}) 1453 self.open_excel_menu.Enable(has_data) 1454 self.save_menu.Enable(has_data) 1455 1387 self.open_excel_menu.Enable(has_data) 1388 self.save_menu.Enable(has_data) 1389 1456 1390 if self.edit == event.GetMenu(): 1457 1391 #get the selected column … … 1470 1404 self.copy_menu.Enable(has_selection) 1471 1405 self.clear_menu.Enable(has_selection) 1472 1406 1473 1407 if len(col_list) > 0: 1474 1408 self.remove_menu.Enable(True) … … 1485 1419 self.insertb_sub_menu.Enable(True) 1486 1420 self.inserta_sub_menu.Enable(True) 1487 1421 1488 1422 col = col_list[0] 1489 1423 col_name = grid.GetCellValue(row=0, col=col) … … 1492 1426 for item in self.insert_before_menu.GetMenuItems(): 1493 1427 self.insert_before_menu.DeleteItem(item) 1494 grid.insert_col_menu(menu=self.insert_before_menu, 1428 grid.insert_col_menu(menu=self.insert_before_menu, 1495 1429 label=col_name, window=self) 1496 1430 label = "Insert Column After " + str(col_name) … … 1498 1432 for item in self.insert_after_menu.GetMenuItems(): 1499 1433 self.insert_after_menu.DeleteItem(item) 1500 grid.insert_after_col_menu(menu=self.insert_after_menu, 1501 label=col_name, window=self)1434 grid.insert_after_col_menu(menu=self.insert_after_menu, 1435 label=col_name, window=self) 1502 1436 event.Skip() 1503 1504 1505 1437 1438 1439 1506 1440 def on_save_page(self, event): 1507 1441 """ … … 1514 1448 name = self.panel.notebook.GetPageText(pos) 1515 1449 msg = " %s has not data to save" % str(name) 1516 wx.PostEvent(self.parent, 1517 StatusEvent(status=msg, info="error")) 1518 1450 wx.PostEvent(self.parent, 1451 StatusEvent(status=msg, info="error")) 1452 1519 1453 return 1520 1454 reader, ext = os.path.splitext(grid.file_name) 1521 1455 path = None 1522 if self.parent is not None: 1456 if self.parent is not None: 1523 1457 location = os.path.dirname(grid.file_name) 1524 1458 dlg = wx.FileDialog(self, "Save Project file", 1525 location, grid.file_name, ext, wx.SAVE)1459 location, grid.file_name, ext, wx.SAVE) 1526 1460 path = None 1527 1461 if dlg.ShowModal() == wx.ID_OK: … … 1531 1465 if self.parent is not None: 1532 1466 data = grid.get_grid_view() 1533 self.parent.write_batch_tofile(data=data, 1534 file_name=path,1535 details=grid.details)1536 1467 self.parent.write_batch_tofile(data=data, 1468 file_name=path, 1469 details=grid.details) 1470 1537 1471 def on_open(self, event): 1538 1472 """ … … 1541 1475 if self.parent is not None: 1542 1476 self.parent.on_read_batch_tofile(self) 1543 1477 1544 1478 def open_with_excel(self, event): 1545 1479 """ … … 1554 1488 name = self.panel.notebook.GetPageText(pos) 1555 1489 msg = " %s has not data to open on excel" % str(name) 1556 wx.PostEvent(self.parent, 1557 StatusEvent(status=msg, info="error")) 1558 1490 wx.PostEvent(self.parent, 1491 StatusEvent(status=msg, info="error")) 1492 1559 1493 return 1560 1494 self.parent.open_with_externalapp(data=data, 1561 file_name=grid.file_name, 1495 file_name=grid.file_name, 1562 1496 details=grid.details) 1563 1497 1564 1498 def on_close(self, event): 1565 1499 """ 1566 1500 """ 1567 1501 self.Hide() 1568 1502 1569 1503 def on_append_column(self, event): 1570 1504 """ … … 1572 1506 """ 1573 1507 self.panel.add_column() 1574 1508 1575 1509 def set_data(self, data_inputs, data_outputs, details="", file_name=None): 1576 1510 """ 1577 1511 Set data 1578 1512 """ 1579 self.panel.notebook.set_data(data_inputs=data_inputs, 1580 file_name=file_name,1581 details=details,1582 data_outputs=data_outputs)1513 self.panel.notebook.set_data(data_inputs=data_inputs, 1514 file_name=file_name, 1515 details=details, 1516 data_outputs=data_outputs) 1583 1517 1584 1518 def add_table(self, event): … … 1587 1521 """ 1588 1522 # DO not event.Skip(): it will make 2 pages 1589 self.panel.notebook.add_empty_page() 1590 1523 self.panel.notebook.add_empty_page() 1524 1591 1525 class BatchOutputFrame(wx.Frame): 1592 1526 """ … … 1597 1531 """ 1598 1532 :param parent: Window instantiating this dialog 1599 :param result: result to display in a grid or export to an external 1533 :param result: result to display in a grid or export to an external 1600 1534 application. 1601 1535 """ 1602 #kwds['style'] = wx.CAPTION|wx.SYSTEM_MENU 1536 #kwds['style'] = wx.CAPTION|wx.SYSTEM_MENU 1603 1537 wx.Frame.__init__(self, parent, *args, **kwds) 1604 1538 self.parent = parent … … 1617 1551 self.save_to_file = None 1618 1552 self._do_layout() 1619 1553 1620 1554 def _do_layout(self): 1621 1555 """ … … 1627 1561 selection_sizer = wx.GridBagSizer(5, 5) 1628 1562 button_sizer = wx.BoxSizer(wx.HORIZONTAL) 1629 text = "Open with %s" % self.parent.application_name 1630 self.local_app_selected = wx.RadioButton(self.panel, -1, text, 1631 style=wx.RB_GROUP) 1563 text = "Open with %s" % self.parent.application_name 1564 self.local_app_selected = wx.RadioButton(self.panel, -1, text, style=wx.RB_GROUP) 1632 1565 self.Bind(wx.EVT_RADIOBUTTON, self.onselect, 1633 1566 id=self.local_app_selected.GetId()) 1634 1567 text = "Open with Excel" 1635 self.external_app_selected = wx.RadioButton(self.panel, -1, text) 1636 self.Bind(wx.EVT_RADIOBUTTON, self.onselect, 1637 id=self.external_app_selected.GetId()) 1568 self.external_app_selected = wx.RadioButton(self.panel, -1, text) 1569 self.Bind(wx.EVT_RADIOBUTTON, self.onselect, id=self.external_app_selected.GetId()) 1638 1570 text = "Save to File" 1639 1571 self.save_to_file = wx.CheckBox(self.panel, -1, text) 1640 self.Bind(wx.EVT_CHECKBOX, self.onselect, 1641 id=self.save_to_file.GetId()) 1572 self.Bind(wx.EVT_CHECKBOX, self.onselect, id=self.save_to_file.GetId()) 1642 1573 self.local_app_selected.SetValue(True) 1643 1574 self.external_app_selected.SetValue(False) 1644 1575 self.save_to_file.SetValue(False) 1645 1576 button_close = wx.Button(self.panel, -1, "Close") 1646 button_close.Bind(wx.EVT_BUTTON, id=button_close.GetId(), 1647 handler=self.on_close) 1577 button_close.Bind(wx.EVT_BUTTON, id=button_close.GetId(), handler=self.on_close) 1648 1578 button_apply = wx.Button(self.panel, -1, "Apply") 1649 button_apply.Bind(wx.EVT_BUTTON, id=button_apply.GetId(), 1650 handler=self.on_apply) 1579 button_apply.Bind(wx.EVT_BUTTON, id=button_apply.GetId(), handler=self.on_apply) 1651 1580 button_apply.SetFocus() 1652 1581 hint = "" … … 1657 1586 iy = 0 1658 1587 selection_sizer.Add(self.local_app_selected, (iy, ix), 1659 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)1588 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 1660 1589 iy += 1 1661 1590 selection_sizer.Add(self.external_app_selected, (iy, ix), 1662 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)1591 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 1663 1592 iy += 1 1664 1593 selection_sizer.Add(self.save_to_file, (iy, ix), 1665 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)1594 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 1666 1595 #contruction the sizer contaning button 1667 button_sizer.Add((20, 20), 1, wx.EXPAND |wx.ADJUST_MINSIZE, 0)1596 button_sizer.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 1668 1597 1669 1598 button_sizer.Add(button_close, 0, 1670 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)1599 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 1671 1600 button_sizer.Add(button_apply, 0, 1672 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)1673 vbox.Add(hint_sizer, 0, wx.EXPAND |wx.ALL, 10)1674 vbox.Add(wx.StaticLine(self.panel, -1), 1675 vbox.Add(button_sizer, 0, wx.TOP |wx.BOTTOM, 10)1601 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 1602 vbox.Add(hint_sizer, 0, wx.EXPAND | wx.ALL, 10) 1603 vbox.Add(wx.StaticLine(self.panel, -1), 0, wx.EXPAND, 0) 1604 vbox.Add(button_sizer, 0, wx.TOP | wx.BOTTOM, 10) 1676 1605 self.SetSizer(vbox) 1677 1606 1678 1607 def on_apply(self, event): 1679 1608 """ … … 1684 1613 data_outputs=self.data_outputs) 1685 1614 elif self.flag == 2: 1686 self.parent.open_with_externalapp(data=self.data, 1615 self.parent.open_with_externalapp(data=self.data, 1687 1616 file_name=self.file_name, 1688 1617 details=self.details) … … 1692 1621 """ 1693 1622 self.Close() 1694 1623 1695 1624 def onselect(self, event=None): 1696 1625 """ 1697 1626 Receive event and display data into third party application 1698 1627 or save data to file. 1699 1628 1700 1629 """ 1701 1630 if self.save_to_file.GetValue(): 1702 reader, ext = os.path.splitext(self.file_name)1631 _, ext = os.path.splitext(self.file_name) 1703 1632 path = None 1704 1633 location = os.getcwd() 1705 if self.parent is not None: 1634 if self.parent is not None: 1706 1635 location = os.path.dirname(self.file_name) 1707 1636 dlg = wx.FileDialog(self, "Save Project file", 1708 location, self.file_name, ext, wx.SAVE)1637 location, self.file_name, ext, wx.SAVE) 1709 1638 path = None 1710 1639 if dlg.ShowModal() == wx.ID_OK: … … 1713 1642 if path != None: 1714 1643 if self.parent is not None and self.data is not None: 1715 self.parent.write_batch_tofile(data=self.data, 1644 self.parent.write_batch_tofile(data=self.data, 1716 1645 file_name=path, 1717 1646 details=self.details) … … 1721 1650 self.flag = 2 1722 1651 return self.flag 1723 1724 1725 1652 1653 1654 1726 1655 if __name__ == "__main__": 1727 1656 app = wx.App() 1728 1657 1729 1658 try: 1730 1659 data = {} … … 1732 1661 for i in range(4): 1733 1662 j += 1 1734 data["index" +str(i)] = [i/j, i*j, i, i+j]1735 1736 data_input = copy.deepcopy(data)1663 data["index" + str(i)] = [i / j, i * j, i, i + j] 1664 1665 data_input = copy.deepcopy(data) 1737 1666 data_input["index5"] = [10, 20, 40, 50] 1738 1667 frame = GridFrame(data_outputs=data, data_inputs=data_input) … … 1740 1669 except: 1741 1670 print sys.exc_value 1742 1671 1743 1672 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.