Changeset 418e59f in sasview for src/sas/guiframe
- Timestamp:
- Mar 4, 2015 2:51:37 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:
- 6b0fc72
- Parents:
- 4bf54044 (diff), 76aed53 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/guiframe
- Files:
-
- 3 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() -
src/sas/guiframe/gui_manager.py
r064723b r091e71a2 5 5 #This software was developed by the University of Tennessee as part of the 6 6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 #project funded by the US National Science Foundation. 7 #project funded by the US National Science Foundation. 8 8 # 9 9 #See the license text in license.txtz … … 58 58 logging.info("Using application path: %s", app_path) 59 59 return app_path 60 60 61 61 # Next, try the current working directory 62 62 if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")): 63 63 logging.info("Using application path: %s", os.getcwd()) 64 64 return os.path.abspath(os.getcwd()) 65 65 66 66 # Finally, try the directory of the sasview module 67 67 #TODO: gui_manager will have to know about sasview until we … … 79 79 Returns the user's home directory 80 80 """ 81 userdir = os.path.join(os.path.expanduser("~"), ".sasview")81 userdir = os.path.join(os.path.expanduser("~"), ".sasview") 82 82 if not os.path.isdir(userdir): 83 83 os.makedirs(userdir) 84 84 return userdir 85 85 86 86 def _find_local_config(file, path): 87 87 """ 88 88 Find configuration file for the current application 89 """ 89 """ 90 90 config_module = None 91 91 fObj = None 92 92 try: 93 93 fObj, path_config, descr = imp.find_module(file, [path]) 94 config_module = imp.load_module(file, fObj, path_config, descr) 94 config_module = imp.load_module(file, fObj, path_config, descr) 95 95 except: 96 96 logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value)) … … 102 102 103 103 # Get APP folder 104 PATH_APP = get_app_dir() 104 PATH_APP = get_app_dir() 105 105 DATAPATH = PATH_APP 106 106 107 # GUI always starts from the App folder 107 # GUI always starts from the App folder 108 108 #os.chdir(PATH_APP) 109 109 # Read in the local config, which can either be with the main … … 113 113 config = _find_local_config('local_config', os.getcwd()) 114 114 if config is None: 115 # Didn't find local config, load the default 115 # Didn't find local config, load the default 116 116 import sas.guiframe.config as config 117 logging.info("using default local_config") 117 logging.info("using default local_config") 118 118 else: 119 logging.info("found local_config in %s" % os.getcwd()) 119 logging.info("found local_config in %s" % os.getcwd()) 120 120 else: 121 logging.info("found local_config in %s" % PATH_APP) 122 121 logging.info("found local_config in %s" % PATH_APP) 122 123 123 from sas.guiframe.customdir import SetupCustom 124 124 c_conf_dir = SetupCustom().setup_dir(PATH_APP) … … 154 154 PLOPANEL_WIDTH = custom_config.PLOPANEL_WIDTH 155 155 DATAPANEL_WIDTH = custom_config.DATAPANEL_WIDTH 156 GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH 156 GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH 157 157 GUIFRAME_HEIGHT = custom_config.GUIFRAME_HEIGHT 158 CONTROL_WIDTH = custom_config.CONTROL_WIDTH 158 CONTROL_WIDTH = custom_config.CONTROL_WIDTH 159 159 CONTROL_HEIGHT = custom_config.CONTROL_HEIGHT 160 160 DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE … … 173 173 PLOPANEL_WIDTH = config.PLOPANEL_WIDTH 174 174 DATAPANEL_WIDTH = config.DATAPANEL_WIDTH 175 GUIFRAME_WIDTH = config.GUIFRAME_WIDTH 175 GUIFRAME_WIDTH = config.GUIFRAME_WIDTH 176 176 GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT 177 CONTROL_WIDTH = -1 177 CONTROL_WIDTH = -1 178 178 CONTROL_HEIGHT = -1 179 179 DEFAULT_PERSPECTIVE = None … … 183 183 DEFAULT_STYLE = config.DEFAULT_STYLE 184 184 185 PLUGIN_STATE_EXTENSIONS = 185 PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS 186 186 OPEN_SAVE_MENU = config.OPEN_SAVE_PROJECT_MENU 187 187 VIEW_MENU = config.VIEW_MENU … … 214 214 PARENT_FRAME = wx.Frame 215 215 CHILD_FRAME = wx.Frame 216 216 217 217 class ViewerFrame(PARENT_FRAME): 218 218 """ 219 219 Main application frame 220 220 """ 221 222 def __init__(self, parent, title, 221 222 def __init__(self, parent, title, 223 223 size=(GUIFRAME_WIDTH, GUIFRAME_HEIGHT), 224 gui_style=DEFAULT_STYLE, 224 gui_style=DEFAULT_STYLE, 225 225 style=wx.DEFAULT_FRAME_STYLE, 226 226 pos=wx.DefaultPosition): … … 232 232 # title 233 233 self.title = title 234 self.__gui_style = gui_style 234 self.__gui_style = gui_style 235 235 path = os.path.dirname(__file__) 236 temp_path = os.path.join(path, 'images')237 ico_file = os.path.join(temp_path, 'ball.ico')236 temp_path = os.path.join(path, 'images') 237 ico_file = os.path.join(temp_path, 'ball.ico') 238 238 if os.path.isfile(ico_file): 239 239 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 240 240 else: 241 temp_path = os.path.join(os.getcwd(), 'images')242 ico_file = os.path.join(temp_path, 'ball.ico')241 temp_path = os.path.join(os.getcwd(), 'images') 242 ico_file = os.path.join(temp_path, 'ball.ico') 243 243 if os.path.isfile(ico_file): 244 244 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 245 245 else: 246 246 ico_file = os.path.join(os.path.dirname(os.path.sys.path[0]), 247 'images', 'ball.ico')247 'images', 'ball.ico') 248 248 if os.path.isfile(ico_file): 249 249 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 250 250 self.path = PATH_APP 251 self.application_name = APPLICATION_NAME 251 self.application_name = APPLICATION_NAME 252 252 ## Application manager 253 253 self._input_file = None … … 294 294 295 295 # Default locations 296 self._default_save_location = DEFAULT_OPEN_FOLDER 296 self._default_save_location = DEFAULT_OPEN_FOLDER 297 297 # Welcome panel 298 298 self.defaultPanel = None … … 303 303 self.cpanel_on_focus = None 304 304 305 self.loader = Loader() 305 self.loader = Loader() 306 306 #data manager 307 307 self.batch_on = False … … 310 310 self._data_panel = None#DataPanel(parent=self) 311 311 if self.panel_on_focus is not None: 312 self._data_panel.set_panel_on_focus( 313 self.panel_on_focus.window_caption) 312 self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) 314 313 # list of plot panels in schedule to full redraw 315 314 self.schedule = False … … 318 317 self.schedule_full_draw_list = [] 319 318 self.idletimer = wx.CallLater(TIME_FACTOR, self._onDrawIdle) 320 319 321 320 self.batch_frame = GridFrame(parent=self) 322 321 self.batch_frame.Hide() 323 322 self.on_batch_selection(event=None) 324 323 self.add_icon() 325 324 326 325 # Register the close event so it calls our own method 327 326 wx.EVT_CLOSE(self, self.WindowClose) … … 338 337 # Preferred window size 339 338 self._window_width, self._window_height = size 340 339 341 340 def add_icon(self): 342 341 """ 343 get list of child and attempt to add the default icon 344 """ 345 346 list_children = self.GetChildren() 342 get list of child and attempt to add the default icon 343 """ 344 345 list_children = self.GetChildren() 347 346 for frame in list_children: 348 347 self.put_icon(frame) 349 350 def put_icon(self, frame): 348 349 def put_icon(self, frame): 351 350 """ 352 351 Put icon on the tap of a panel … … 358 357 frame.SetIcon(icon) 359 358 except: 360 pass 361 359 pass 360 362 361 def get_client_size(self): 363 362 """ … … 370 369 if toolbar != None: 371 370 _, tb_h = toolbar.GetSizeTuple() 372 height -= tb_h 371 height -= tb_h 373 372 return width, height 374 373 375 374 def on_change_categories(self, evt): 376 375 # ILL … … 382 381 383 382 if fitpanel != None: 384 for i in range(0, fitpanel.GetPageCount()):383 for i in range(0, fitpanel.GetPageCount()): 385 384 fitpanel.GetPage(i)._populate_listbox() 386 385 387 388 389 386 def on_set_batch_result(self, data_outputs, data_inputs=None, 390 387 plugin_name=""): 391 388 """ 392 389 Display data into a grid in batch mode and show the grid … … 395 392 time_str = time.strftime("%b %d %H;%M of %Y", t) 396 393 details = "File Generated by %s : %s" % (APPLICATION_NAME, 397 398 details += "on %s.\n" % time_str 394 str(plugin_name)) 395 details += "on %s.\n" % time_str 399 396 ext = ".csv" 400 file_name = "Batch_" + str(plugin_name) + "_" + time_str + ext397 file_name = "Batch_" + str(plugin_name) + "_" + time_str + ext 401 398 file_name = self._default_save_location + str(file_name) 402 399 403 400 self.open_with_localapp(file_name=file_name, 404 401 details=details, 405 402 data_inputs=data_inputs, 406 data_outputs=data_outputs) 407 408 403 data_outputs=data_outputs) 404 409 405 def open_with_localapp(self, data_inputs=None, details="", file_name=None, 410 406 data_outputs=None): … … 413 409 :param data: dictionary of string and list of items 414 410 """ 415 self.batch_frame.set_data(data_inputs=data_inputs, 411 self.batch_frame.set_data(data_inputs=data_inputs, 416 412 data_outputs=data_outputs, 417 413 details=details, 418 414 file_name=file_name) 419 415 self.show_batch_frame(None) 420 416 421 417 def on_read_batch_tofile(self, base): 422 418 """ … … 428 424 self._default_save_location = os.getcwd() 429 425 wildcard = "(*.csv; *.txt)|*.csv; *.txt" 430 dlg = wx.FileDialog(base, 431 "Choose a file", 426 dlg = wx.FileDialog(base, 427 "Choose a file", 432 428 self._default_save_location, "", 433 429 wildcard) 434 430 if dlg.ShowModal() == wx.ID_OK: 435 431 path = dlg.GetPath() … … 440 436 self.read_batch_tofile(file_name=path) 441 437 except: 442 msg = "Error occurred when reading the file; %s\n" % path443 msg += "%s\n" % sys.exc_value438 msg = "Error occurred when reading the file; %s\n" % path 439 msg += "%s\n" % sys.exc_value 444 440 wx.PostEvent(self, StatusEvent(status=msg, 445 446 441 info="error")) 442 447 443 def read_batch_tofile(self, file_name): 448 444 """ … … 457 453 if ext.lower() == ".csv": 458 454 separator = "," 459 buffer = fd.read()460 lines = buffer.split('\n')455 fd_buffer = fd.read() 456 lines = fd_buffer.split('\n') 461 457 fd.close() 462 column_names_line 458 column_names_line = "" 463 459 index = None 464 460 details = "" … … 487 483 if count >= 2: 488 484 column_names_line = line 489 break 490 485 break 486 491 487 if column_names_line.strip() == "" or index is None: 492 return 488 return 493 489 494 490 col_name_toks = column_names_line.split(separator) … … 500 496 try: 501 497 float(c_name) 502 col_name = "Column %s" % str(col_index + 1)498 col_name = "Column %s" % str(col_index + 1) 503 499 index_min = index 504 500 except: 505 501 col_name = c_name 506 502 index_min = index + 1 507 data[col_name] = [ 508 for row in range(index_min, len(lines)-1)]503 data[col_name] = [lines[row].split(separator)[c_index] 504 for row in range(index_min, len(lines) - 1)] 509 505 c_index += 1 510 506 511 507 self.open_with_localapp(data_outputs=data, data_inputs=None, 512 508 file_name=file_name, details=details) 513 509 514 510 def write_batch_tofile(self, data, file_name, details=""): 515 511 """ … … 541 537 max_index = max(max_list) 542 538 index = 0 543 while (index < max_index):539 while index < max_index: 544 540 for value_list in data.values(): 545 541 if index < len(value_list): … … 552 548 index += 1 553 549 fd.close() 554 550 555 551 def open_with_externalapp(self, data, file_name, details=""): 556 552 """ … … 559 555 if not os.path.exists(file_name): 560 556 self.write_batch_tofile(data=data, file_name=file_name, 561 557 details=details) 562 558 try: 563 559 from win32com.client import Dispatch 564 excel_app = Dispatch('Excel.Application') 565 wb = excel_app.Workbooks.Open(file_name)560 excel_app = Dispatch('Excel.Application') 561 excel_app.Workbooks.Open(file_name) 566 562 excel_app.Visible = 1 567 563 except: … … 570 566 msg += "check that %s really exists.\n" % str(file_name) 571 567 wx.PostEvent(self, StatusEvent(status=msg, 572 info="error")) 573 574 568 info="error")) 569 575 570 def on_batch_selection(self, event=None): 576 571 """ … … 583 578 for plug in self.plugins: 584 579 plug.set_batch_selection(self.batch_on) 585 580 586 581 def on_color_selection(self, event): 587 582 """ 588 583 :param event: contains parameters for id and color 589 """ 590 color, id = event.color, event.id584 """ 585 color, event_id = event.color, event.id 591 586 for plug in self.plugins: 592 plug.add_color(color, id) 593 594 587 plug.add_color(color, event_id) 588 595 589 def setup_custom_conf(self): 596 590 """ … … 599 593 if custom_config == None: 600 594 return 601 595 602 596 if not FIXED_PANEL: 603 597 self.__gui_style &= (~GUIFRAME.FIXED_PANEL) … … 611 605 612 606 if WELCOME_PANEL_SHOW: 613 self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON 614 607 self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON 608 615 609 def set_custom_default_perspective(self): 616 610 """ … … 622 616 try: 623 617 if plugin.sub_menu == DEFAULT_PERSPECTIVE: 624 618 625 619 plugin.on_perspective(event=None) 626 620 frame = plugin.get_frame() … … 629 623 else: 630 624 frame = plugin.get_frame() 631 frame.Show(False) 625 frame.Show(False) 632 626 except: 633 pass 634 return 635 627 pass 628 return 629 636 630 def on_load_data(self, event): 637 631 """ … … 640 634 if self._data_plugin is not None: 641 635 self._data_plugin.load_data(event) 642 636 643 637 def get_current_perspective(self): 644 638 """ … … 652 646 """ 653 647 return self._default_save_location 654 648 655 649 def set_input_file(self, input_file): 656 650 """ … … 658 652 """ 659 653 self._input_file = input_file 660 654 661 655 def get_data_manager(self): 662 656 """ … … 664 658 """ 665 659 return self._data_manager 666 660 667 661 def get_toolbar(self): 668 662 """ … … 670 664 """ 671 665 return self._toolbar 672 666 673 667 def set_panel_on_focus(self, event): 674 668 """ … … 698 692 self.enable_edit_menu() 699 693 700 def disable_app_menu(self, p_panel=None): 694 def disable_app_menu(self, p_panel=None): 701 695 """ 702 696 Disables all menus in the menubar 703 697 """ 704 698 return 705 706 def send_focus_to_datapanel(self, name): 699 700 def send_focus_to_datapanel(self, name): 707 701 """ 708 702 Send focusing on ID to data explorer … … 710 704 if self._data_panel != None: 711 705 self._data_panel.set_panel_on_focus(name) 712 706 713 707 def set_panel_on_focus_helper(self): 714 708 """ … … 722 716 combo_title = str(self.panel_on_focus.window_caption) 723 717 combo.SetStringSelection(combo_title) 724 combo.SetToolTip( wx.ToolTip(combo_title ))718 combo.SetToolTip(wx.ToolTip(combo_title)) 725 719 elif self.panel_on_focus != self._data_panel: 726 720 cpanel = self.panel_on_focus … … 728 722 cpanel.on_tap_focus() 729 723 self.cpanel_on_focus = self.panel_on_focus 730 724 731 725 def reset_bookmark_menu(self, panel): 732 726 """ 733 727 Reset Bookmark menu list 734 728 735 729 : param panel: a control panel or tap where the bookmark is 736 730 """ … … 745 739 if pos < 3: 746 740 continue 747 id = 741 id = bitem.GetId() 748 742 label = bitem.GetLabel() 749 743 self._toolbar.append_bookmark_item(id, label) 750 744 wx.EVT_MENU(self, id, cpanel._back_to_bookmark) 751 745 self._toolbar.Realize() 752 746 753 747 754 748 def build_gui(self): … … 771 765 self._setup_layout() 772 766 self._add_menu_application() 773 767 774 768 # Set up the menu 775 769 self._add_current_plugin_menu() … … 781 775 if not wx.VERSION_STRING >= '3.0.0.0': 782 776 self.SetMenuBar(self._menubar) 783 777 784 778 try: 785 779 self.load_from_cmd(self._input_file) 786 780 except: 787 msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME),788 str(self._input_file))781 msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME), 782 str(self._input_file)) 789 783 msg += str(sys.exc_value) + '\n' 790 784 logging.error(msg) … … 798 792 self._check_update(None) 799 793 800 def _setup_extra_custom(self): 794 def _setup_extra_custom(self): 801 795 """ 802 796 Set up toolbar and welcome view if needed … … 804 798 style = self.__gui_style & GUIFRAME.TOOLBAR_ON 805 799 if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): 806 self._on_toggle_toolbar() 807 800 self._on_toggle_toolbar() 801 808 802 # Set Custom deafult start page 809 803 welcome_style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON 810 804 if welcome_style == GUIFRAME.WELCOME_PANEL_ON: 811 805 self.show_welcome_panel(None) 812 806 813 807 def _setup_layout(self): 814 808 """ … … 822 816 self._load_panels() 823 817 self.set_default_perspective() 824 818 825 819 def SetStatusText(self, *args, **kwds): 826 820 """ … … 828 822 number = self.sb.get_msg_position() 829 823 wx.Frame.SetStatusText(self, number=number, *args, **kwds) 830 824 831 825 def PopStatusText(self, *args, **kwds): 832 826 """ … … 834 828 field = self.sb.get_msg_position() 835 829 wx.Frame.PopStatusText(self, field=field) 836 830 837 831 def PushStatusText(self, *args, **kwds): 838 832 """ 839 FIXME: No message is passed. What is this supposed to do? 833 FIXME: No message is passed. What is this supposed to do? 840 834 """ 841 835 field = self.sb.get_msg_position() 842 wx.Frame.PushStatusText(self, field=field, 843 string="FIXME: PushStatusText called without text")836 wx.Frame.PushStatusText(self, field=field, 837 string="FIXME: PushStatusText called without text") 844 838 845 839 def add_perspective(self, plugin): … … 855 849 msg = "Plugin %s already loaded" % plugin.sub_menu 856 850 logging.info(msg) 857 is_loaded = True 851 is_loaded = True 858 852 if not is_loaded: 859 self.plugins.append(plugin) 853 self.plugins.append(plugin) 860 854 msg = "Plugin %s appended" % plugin.sub_menu 861 855 logging.info(msg) 862 856 863 857 def _get_local_plugins(self): 864 858 """ 865 get plugins local to guiframe and others 859 get plugins local to guiframe and others 866 860 """ 867 861 plugins = [] … … 888 882 msg += "cannot import plotting plugin.\n %s" % sys.exc_value 889 883 logging.error(msg) 890 884 891 885 return plugins 892 886 893 887 def _find_plugins(self, dir="perspectives"): 894 888 """ 895 889 Find available perspective plug-ins 896 890 897 891 :param dir: directory in which to look for plug-ins 898 892 899 893 :return: list of plug-ins 900 894 901 895 """ 902 896 plugins = [] 903 897 # Go through files in panels directory 904 898 try: 905 list = os.listdir(dir)899 file_list = os.listdir(dir) 906 900 ## the default panel is the panel is the last plugin added 907 for item in list:901 for item in file_list: 908 902 toks = os.path.splitext(os.path.basename(item)) 909 903 name = '' … … 924 918 else: 925 919 (file, path, info) = imp.find_module(name, path) 926 module = imp.load_module( 920 module = imp.load_module(name, file, item, info) 927 921 if hasattr(module, "PLUGIN_ID"): 928 try: 922 try: 929 923 plug = module.Plugin() 930 924 if plug.set_default_perspective(): 931 925 self._current_perspective = plug 932 926 plugins.append(plug) 933 927 934 928 msg = "Found plug-in: %s" % module.PLUGIN_ID 935 929 logging.info(msg) … … 947 941 # Should raise and catch at a higher level and 948 942 # display error on status bar 949 pass943 logging.error(sys.exc_value) 950 944 951 945 return plugins … … 963 957 panel_width = DATAPANEL_WIDTH 964 958 panel_height = int(self._window_height) 965 style = self.__gui_style & (GUIFRAME.MANAGER_ON)966 959 if self._data_panel is not None and (p == self._data_panel): 967 960 return panel_width, panel_height … … 976 969 return self._window_width, panel_height 977 970 return panel_width, panel_height 978 971 979 972 def _load_panels(self): 980 973 """ … … 991 984 ps = item.get_panels(self) 992 985 panels.extend(ps) 993 986 994 987 # Set up welcome panel 995 988 #TODO: this needs serious simplification … … 1000 993 self.defaultPanel.set_frame(welcome_panel) 1001 994 welcome_panel.Show(False) 1002 995 1003 996 self.panels["default"] = self.defaultPanel 1004 997 size_t_bar = 70 … … 1012 1005 frame.SetPosition((0, mac_pos_y + size_t_bar)) 1013 1006 frame.Show(True) 1014 #add data panel 1007 #add data panel 1015 1008 win = MDIFrame(self, None, 'None', (100, 200)) 1016 data_panel = DataPanel(parent=win, 1009 data_panel = DataPanel(parent=win, id=-1) 1017 1010 win.set_panel(data_panel) 1018 1011 self.panels["data_panel"] = data_panel … … 1029 1022 for panel_class in panels: 1030 1023 frame = panel_class.get_frame() 1031 id = wx.NewId()1024 wx_id = wx.NewId() 1032 1025 # Check whether we need to put this panel in the center pane 1033 1026 if hasattr(panel_class, "CENTER_PANE") and panel_class.CENTER_PANE: 1034 1027 w, h = self._get_panels_size(panel_class) 1035 1028 if panel_class.CENTER_PANE: 1036 self.panels[str( id)] = panel_class1029 self.panels[str(wx_id)] = panel_class 1037 1030 _, pos_y = frame.GetPositionTuple() 1038 1031 frame.SetPosition((d_panel_width + 1, pos_y)) … … 1043 1036 continue 1044 1037 else: 1045 self.panels[str( id)] = panel_class1038 self.panels[str(wx_id)] = panel_class 1046 1039 frame.SetSize((w, h)) 1047 1040 frame.Show(False) … … 1061 1054 else: 1062 1055 self.SetSize((self._window_width, win_height)) 1063 1056 1064 1057 def update_data(self, prev_data, new_data): 1065 1058 """ 1066 1059 Update the data. 1067 1060 """ 1068 prev_id, data_state = self._data_manager.update_data( 1061 prev_id, data_state = self._data_manager.update_data( \ 1069 1062 prev_data=prev_data, new_data=new_data) 1070 1063 1071 1064 self._data_panel.remove_by_id(prev_id) 1072 1065 self._data_panel.load_data_list(data_state) 1073 1066 1074 1067 def update_theory(self, data_id, theory, state=None): 1075 1068 """ 1076 1069 Update the theory 1077 """ 1078 data_state = self._data_manager.update_theory(data_id=data_id, 1079 theory=theory,1080 state=state)1070 """ 1071 data_state = self._data_manager.update_theory(data_id=data_id, 1072 theory=theory, 1073 state=state) 1081 1074 wx.CallAfter(self._data_panel.load_data_list, data_state) 1082 1075 1083 1076 def onfreeze(self, theory_id): 1084 1077 """ … … 1088 1081 for data_state in data_state_list.values(): 1089 1082 new_plot = data_state.get_data() 1090 1083 1091 1084 wx.PostEvent(self, NewPlotEvent(plot=new_plot, 1092 1093 1085 title=new_plot.title)) 1086 1094 1087 def freeze(self, data_id, theory_id): 1095 1088 """ 1096 1089 """ 1097 data_state_list = self._data_manager.freeze_theory(data_id=data_id, 1098 theory_id=theory_id)1090 data_state_list = self._data_manager.freeze_theory(data_id=data_id, 1091 theory_id=theory_id) 1099 1092 self._data_panel.load_data_list(list=data_state_list) 1100 1093 for data_state in data_state_list.values(): 1101 1094 new_plot = data_state.get_data() 1102 1095 wx.PostEvent(self, NewPlotEvent(plot=new_plot, 1103 1104 1096 title=new_plot.title)) 1097 1105 1098 def delete_data(self, data): 1106 1099 """ … … 1108 1101 """ 1109 1102 self._current_perspective.delete_data(data) 1110 1111 1103 1104 1112 1105 def get_context_menu(self, plotpanel=None): 1113 1106 """ 1114 Get the context menu items made available 1115 by the different plug-ins. 1107 Get the context menu items made available 1108 by the different plug-ins. 1116 1109 This function is used by the plotting module 1117 1110 """ … … 1122 1115 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 1123 1116 return menu_list 1124 1117 1125 1118 def get_current_context_menu(self, plotpanel=None): 1126 1119 """ 1127 Get the context menu items made available 1128 by the current plug-in. 1120 Get the context menu items made available 1121 by the current plug-in. 1129 1122 This function is used by the plotting module 1130 1123 """ … … 1136 1129 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 1137 1130 return menu_list 1138 1131 1139 1132 def on_panel_close(self, event): 1140 1133 """ … … 1150 1143 break 1151 1144 self.cpanel_on_focus.SetFocus() 1152 1153 1145 1146 1154 1147 def popup_panel(self, p): 1155 1148 """ 1156 1149 Add a panel object to the AUI manager 1157 1150 1158 1151 :param p: panel object to add to the AUI manager 1159 1152 1160 1153 :return: ID of the event associated with the new panel [int] 1161 1154 1162 1155 """ 1163 1156 ID = wx.NewId() … … 1179 1172 # Append nummber 1180 1173 captions = self._get_plotpanel_captions() 1174 #FIXME: Fix this aweful loop 1181 1175 while (1): 1182 caption = windowcaption + '%s' % str(self.graph_num)1176 caption = windowcaption + '%s' % str(self.graph_num) 1183 1177 if caption not in captions: 1184 1178 break … … 1188 1182 break 1189 1183 if p.window_caption.split()[0] not in NOT_SO_GRAPH_LIST: 1190 p.window_caption = caption 1184 p.window_caption = caption 1191 1185 p.window_name = windowname + str(self.graph_num) 1192 1186 1193 1187 p.frame.SetTitle(p.window_caption) 1194 1188 p.frame.name = p.window_name … … 1214 1208 self._data_panel.cb_plotpanel.Append(str(caption), p) 1215 1209 return ID 1216 1210 1217 1211 def _get_plotpanel_captions(self): 1218 1212 """ 1219 1213 Get all the plotpanel cations 1220 1214 1221 1215 : return: list of captions 1222 1216 """ … … 1224 1218 for Id in self.plot_panels.keys(): 1225 1219 captions.append(self.plot_panels[Id].window_caption) 1226 1220 1227 1221 return captions 1228 1222 1229 1223 def _setup_tool_bar(self): 1230 1224 """ … … 1242 1236 self._update_toolbar_helper() 1243 1237 self._on_toggle_toolbar(event=None) 1244 1238 1245 1239 def _update_toolbar_helper(self): 1246 1240 """ … … 1249 1243 application_name = 'No Selected Analysis' 1250 1244 panel_name = 'No Panel on Focus' 1251 c_panel = self.cpanel_on_focus 1245 c_panel = self.cpanel_on_focus 1252 1246 if self._toolbar is None: 1253 1247 return … … 1262 1256 c_panel_state = None 1263 1257 self._toolbar.update_toolbar(c_panel_state) 1264 self._toolbar.update_button(application_name=application_name, 1265 1258 self._toolbar.update_button(application_name=application_name, 1259 panel_name=panel_name) 1266 1260 self._toolbar.Realize() 1267 1261 1268 1262 def _add_menu_tool(self): 1269 1263 """ … … 1287 1281 if self._tool_menu is not None: 1288 1282 self._menubar.Append(self._tool_menu, '&Tool') 1289 1283 1290 1284 def _add_current_plugin_menu(self): 1291 1285 """ 1292 1286 add current plugin menu 1293 1287 Look for plug-in menus 1294 Add available plug-in sub-menus. 1288 Add available plug-in sub-menus. 1295 1289 """ 1296 1290 if self._menubar is None or self._current_perspective is None \ 1297 or self._menubar.GetMenuCount() ==0:1291 or self._menubar.GetMenuCount() == 0: 1298 1292 return 1299 1293 #replace or add a new menu for the current plugin 1300 1294 1301 1295 pos = self._menubar.FindMenu(str(self._applications_menu_name)) 1302 1296 if pos != -1: … … 1304 1298 if menu_list: 1305 1299 for (menu, name) in menu_list: 1306 hidden_menu = self._menubar.Replace(pos, menu, name) 1307 self._applications_menu_name = name 1308 #self._applications_menu_pos = pos 1300 self._menubar.Replace(pos, menu, name) 1301 self._applications_menu_name = name 1309 1302 else: 1310 hidden_menu =self._menubar.Remove(pos)1303 self._menubar.Remove(pos) 1311 1304 self._applications_menu_name = None 1312 1305 #get the position of the menu when it first added 1313 self._applications_menu_pos = pos 1314 1306 self._applications_menu_pos = pos 1307 1315 1308 else: 1316 1309 menu_list = self._current_perspective.populate_menu(self) … … 1320 1313 self._menubar.Append(menu, name) 1321 1314 else: 1322 self._menubar.Insert(self._applications_menu_pos, 1315 self._menubar.Insert(self._applications_menu_pos, 1323 1316 menu, name) 1324 1317 self._applications_menu_name = name 1325 1318 1326 1319 def _add_help_menu(self): 1327 1320 """ 1328 1321 add help menu to menu bar. Includes welcome page, about page, 1329 tutorial PDF and documentation pages. 1322 tutorial PDF and documentation pages. 1330 1323 """ 1331 1324 # Help menu … … 1336 1329 # add the welcome panel menu item 1337 1330 if config.WELCOME_PANEL_ON and self.defaultPanel is not None: 1338 id = wx.NewId()1339 self._help_menu.Append( id, '&Welcome', '')1340 wx.EVT_MENU(self, id, self.show_welcome_panel)1331 wx_id = wx.NewId() 1332 self._help_menu.Append(wx_id, '&Welcome', '') 1333 wx.EVT_MENU(self, wx_id, self.show_welcome_panel) 1341 1334 1342 1335 self._help_menu.AppendSeparator() 1343 id = wx.NewId()1344 self._help_menu.Append( id, '&Documentation', '')1345 wx.EVT_MENU(self, id, self._onSphinxDocs)1346 1347 if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'):1336 wx_id = wx.NewId() 1337 self._help_menu.Append(wx_id, '&Documentation', '') 1338 wx.EVT_MENU(self, wx_id, self._onSphinxDocs) 1339 1340 if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'): 1348 1341 self._help_menu.AppendSeparator() 1349 id = wx.NewId()1350 self._help_menu.Append( id, '&Tutorial', 'Software tutorial')1351 wx.EVT_MENU(self, id, self._onTutorial)1352 1342 wx_id = wx.NewId() 1343 self._help_menu.Append(wx_id, '&Tutorial', 'Software tutorial') 1344 wx.EVT_MENU(self, wx_id, self._onTutorial) 1345 1353 1346 if config._do_acknowledge: 1354 1347 self._help_menu.AppendSeparator() 1355 id = wx.NewId()1356 self._help_menu.Append( id, '&Acknowledge', 'Acknowledging SasView')1357 wx.EVT_MENU(self, id, self._onAcknowledge)1358 1348 wx_id = wx.NewId() 1349 self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView') 1350 wx.EVT_MENU(self, wx_id, self._onAcknowledge) 1351 1359 1352 if config._do_aboutbox: 1360 1353 self._help_menu.AppendSeparator() 1361 1354 self._help_menu.Append(wx.ID_ABOUT, '&About', 'Software information') 1362 1355 wx.EVT_MENU(self, wx.ID_ABOUT, self._onAbout) 1363 1356 1364 1357 # Checking for updates 1365 id = wx.NewId()1366 self._help_menu.Append( id,'&Check for update',1367 'Check for the latest version of %s' % config.__appname__)1368 wx.EVT_MENU(self, id, self._check_update)1358 wx_id = wx.NewId() 1359 self._help_menu.Append(wx_id, '&Check for update', 1360 'Check for the latest version of %s' % config.__appname__) 1361 wx.EVT_MENU(self, wx_id, self._check_update) 1369 1362 self._menubar.Append(self._help_menu, '&Help') 1370 1363 1371 1364 def _add_menu_view(self): 1372 1365 """ … … 1376 1369 return 1377 1370 self._view_menu = wx.Menu() 1378 1379 id = wx.NewId()1371 1372 wx_id = wx.NewId() 1380 1373 hint = "Display the Grid Window for batch results etc." 1381 self._view_menu.Append( id, '&Show Grid Window', hint)1382 wx.EVT_MENU(self, id, self.show_batch_frame)1383 1374 self._view_menu.Append(wx_id, '&Show Grid Window', hint) 1375 wx.EVT_MENU(self, wx_id, self.show_batch_frame) 1376 1384 1377 self._view_menu.AppendSeparator() 1385 1378 style = self.__gui_style & GUIFRAME.MANAGER_ON 1386 id = wx.NewId()1387 self._data_panel_menu = self._view_menu.Append( id,1388 '&Show Data Explorer', '')1389 wx.EVT_MENU(self, id, self.show_data_panel)1379 wx_id = wx.NewId() 1380 self._data_panel_menu = self._view_menu.Append(wx_id, 1381 '&Show Data Explorer', '') 1382 wx.EVT_MENU(self, wx_id, self.show_data_panel) 1390 1383 if style == GUIFRAME.MANAGER_ON: 1391 1384 self._data_panel_menu.SetText('Hide Data Explorer') 1392 1385 else: 1393 1386 self._data_panel_menu.SetText('Show Data Explorer') 1394 1387 1395 1388 self._view_menu.AppendSeparator() 1396 id = wx.NewId()1389 wx_id = wx.NewId() 1397 1390 style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON 1398 1391 if style1 == GUIFRAME.TOOLBAR_ON: 1399 self._toolbar_menu = self._view_menu.Append( id, '&Hide Toolbar', '')1392 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '') 1400 1393 else: 1401 self._toolbar_menu = self._view_menu.Append( id, '&Show Toolbar', '')1402 wx.EVT_MENU(self, id, self._on_toggle_toolbar)1394 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '') 1395 wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar) 1403 1396 1404 1397 if custom_config != None: 1405 1398 self._view_menu.AppendSeparator() 1406 id = wx.NewId()1399 wx_id = wx.NewId() 1407 1400 hint_ss = "Select the current/default configuration " 1408 1401 hint_ss += "as a startup setting" 1409 preference_menu = self._view_menu.Append( id, 'Startup Setting',1402 preference_menu = self._view_menu.Append(wx_id, 'Startup Setting', 1410 1403 hint_ss) 1411 wx.EVT_MENU(self, id, self._on_preference_menu)1412 1413 id = wx.NewId()1404 wx.EVT_MENU(self, wx_id, self._on_preference_menu) 1405 1406 wx_id = wx.NewId() 1414 1407 self._view_menu.AppendSeparator() 1415 self._view_menu.Append( id, 'Category Manager', 'Edit model categories')1416 wx.EVT_MENU(self, id, self._on_category_manager)1417 1418 self._menubar.Append(self._view_menu, '&View') 1419 1408 self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories') 1409 wx.EVT_MENU(self, wx_id, self._on_category_manager) 1410 1411 self._menubar.Append(self._view_menu, '&View') 1412 1420 1413 def show_batch_frame(self, event=None): 1421 1414 """ … … 1425 1418 self.batch_frame.Show(False) 1426 1419 self.batch_frame.Show(True) 1427 1428 def on_category_panel(self, event): 1420 1421 def on_category_panel(self, event): 1429 1422 """ 1430 1423 On cat panel 1431 1424 """ 1432 1425 self._on_category_manager(event) 1433 1426 1434 1427 def _on_category_manager(self, event): 1435 1428 """ … … 1440 1433 frame.SetIcon(icon) 1441 1434 1442 def _on_preference_menu(self, event): 1435 def _on_preference_menu(self, event): 1443 1436 """ 1444 1437 Build a panel to allow to edit Mask … … 1446 1439 from sas.guiframe.startup_configuration \ 1447 1440 import StartupConfiguration as ConfDialog 1448 1441 1449 1442 dialog = ConfDialog(parent=self, gui=self.__gui_style) 1450 1443 result = dialog.ShowModal() … … 1454 1447 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info')) 1455 1448 dialog.Destroy() 1456 1449 1457 1450 def _add_menu_application(self): 1458 1451 """ … … 1461 1454 add menu application 1462 1455 """ 1463 if self._num_perspectives 1456 if self._num_perspectives > 1: 1464 1457 plug_data_count = False 1465 1458 plug_no_data_count = False … … 1471 1464 id = wx.NewId() 1472 1465 if plug.use_data(): 1473 1474 self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, 1475 "Switch to analysis: %s" % plug.sub_menu) 1466 self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \ 1467 "Switch to analysis: %s" % plug.sub_menu) 1476 1468 plug_data_count = True 1477 1469 pos += 1 1478 1470 else: 1479 1471 plug_no_data_count = True 1480 self._applications_menu.AppendCheckItem(id, plug.sub_menu, 1481 1472 self._applications_menu.AppendCheckItem(id, plug.sub_menu, \ 1473 "Switch to analysis: %s" % plug.sub_menu) 1482 1474 wx.EVT_MENU(self, id, plug.on_perspective) 1483 1475 1484 if (not plug_data_count or not plug_no_data_count):1476 if not plug_data_count or not plug_no_data_count: 1485 1477 self._applications_menu.RemoveItem(separator) 1486 1478 self._menubar.Append(self._applications_menu, '&Analysis') 1487 1479 self._check_applications_menu() 1488 1480 1489 1481 def _populate_file_menu(self): 1490 1482 """ … … 1499 1491 wx.EVT_MENU(self, id, m_handler) 1500 1492 self._file_menu.AppendSeparator() 1501 1493 1502 1494 style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 1503 1495 if OPEN_SAVE_MENU: 1504 1496 id = wx.NewId() 1505 1497 hint_load_file = "read all analysis states saved previously" 1506 self._save_appl_menu = self._file_menu.Append(id, 1507 '&Open Project', hint_load_file) 1498 self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file) 1508 1499 wx.EVT_MENU(self, id, self._on_open_state_project) 1509 1500 1510 1501 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1511 1502 # some menu of plugin to be seen under file menu … … 1513 1504 hint_load_file += " them into the analysis" 1514 1505 id = wx.NewId() 1515 self._save_appl_menu = self._file_menu.Append(id, 1516 '&Open Analysis', hint_load_file)1506 self._save_appl_menu = self._file_menu.Append(id, 1507 '&Open Analysis', hint_load_file) 1517 1508 wx.EVT_MENU(self, id, self._on_open_state_application) 1518 if OPEN_SAVE_MENU: 1509 if OPEN_SAVE_MENU: 1519 1510 self._file_menu.AppendSeparator() 1520 1511 id = wx.NewId() 1521 1512 self._file_menu.Append(id, '&Save Project', 1522 'Save the state of the whole analysis')1513 'Save the state of the whole analysis') 1523 1514 wx.EVT_MENU(self, id, self._on_save_project) 1524 1515 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1525 1516 id = wx.NewId() 1526 self._save_appl_menu = self._file_menu.Append(id, 1527 '&Save Analysis', 1528 'Save state of the current active analysis panel') 1517 self._save_appl_menu = self._file_menu.Append(id, \ 1518 '&Save Analysis', 'Save state of the current active analysis panel') 1529 1519 wx.EVT_MENU(self, id, self._on_save_application) 1530 if not sys.platform == 'darwin':1520 if not sys.platform == 'darwin': 1531 1521 self._file_menu.AppendSeparator() 1532 1522 id = wx.NewId() 1533 self._file_menu.Append(id, '&Quit', 'Exit') 1523 self._file_menu.Append(id, '&Quit', 'Exit') 1534 1524 wx.EVT_MENU(self, id, self.Close) 1535 1525 1536 1526 def _add_menu_file(self): 1537 1527 """ … … 1542 1532 # Add sub menus 1543 1533 self._menubar.Append(self._file_menu, '&File') 1544 1534 1545 1535 def _add_menu_edit(self): 1546 1536 """ … … 1551 1541 # Edit Menu 1552 1542 self._edit_menu = wx.Menu() 1553 self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', 1543 self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', 1554 1544 'Undo the previous action') 1555 1545 wx.EVT_MENU(self, GUIFRAME_ID.UNDO_ID, self.on_undo_panel) 1556 self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', 1546 self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', 1557 1547 'Redo the previous action') 1558 1548 wx.EVT_MENU(self, GUIFRAME_ID.REDO_ID, self.on_redo_panel) 1559 1549 self._edit_menu.AppendSeparator() 1560 self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params', 1550 self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params', 1561 1551 'Copy parameter values') 1562 1552 wx.EVT_MENU(self, GUIFRAME_ID.COPY_ID, self.on_copy_panel) 1563 self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params', 1553 self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params', 1564 1554 'Paste parameter values') 1565 1555 wx.EVT_MENU(self, GUIFRAME_ID.PASTE_ID, self.on_paste_panel) … … 1570 1560 #Sub menu for Copy As... 1571 1561 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel', 1572 'Copy parameter values in tabular format')1562 'Copy parameter values in tabular format') 1573 1563 wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel) 1574 1564 1575 1565 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX', 1576 'Copy parameter values in tabular format')1566 'Copy parameter values in tabular format') 1577 1567 wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel) 1578 1568 1579 1569 1580 self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', self._edit_menu_copyas,1581 'Copy parameter values in various formats')1582 1570 self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', 1571 self._edit_menu_copyas, 1572 'Copy parameter values in various formats') 1583 1573 1584 1574 self._edit_menu.AppendSeparator() 1585 1575 1586 1576 self._edit_menu.Append(GUIFRAME_ID.PREVIEW_ID, '&Report Results', 1587 1577 'Preview current panel') 1588 1578 wx.EVT_MENU(self, GUIFRAME_ID.PREVIEW_ID, self.on_preview_panel) 1589 1579 1590 self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page', 1580 self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page', 1591 1581 'Reset current panel') 1592 1582 wx.EVT_MENU(self, GUIFRAME_ID.RESET_ID, self.on_reset_panel) 1593 1594 self._menubar.Append(self._edit_menu, 1583 1584 self._menubar.Append(self._edit_menu, '&Edit') 1595 1585 self.enable_edit_menu() 1596 1586 1597 1587 def get_style(self): 1598 1588 """ … … 1600 1590 """ 1601 1591 return self.__gui_style 1602 1592 1603 1593 def _add_menu_data(self): 1604 1594 """ … … 1610 1600 for (menu, name) in menu_list: 1611 1601 self._menubar.Append(menu, name) 1612 1613 1602 1614 1603 def _on_toggle_toolbar(self, event=None): 1615 1604 """ … … 1627 1616 self._toolbar.Show() 1628 1617 self._toolbar.Realize() 1629 1618 1630 1619 def _on_status_event(self, evt): 1631 1620 """ … … 1634 1623 # This CallAfter fixes many crashes on MAC. 1635 1624 wx.CallAfter(self.sb.set_status, evt) 1636 1625 1637 1626 def on_view(self, evt): 1638 1627 """ 1639 1628 A panel was selected to be shown. If it's not already 1640 1629 shown, display it. 1641 1630 1642 1631 :param evt: menu event 1643 1632 1644 1633 """ 1645 1634 panel_id = str(evt.GetId()) 1646 1635 self.on_set_plot_focus(self.panels[panel_id]) 1647 wx.CallLater(5 *TIME_FACTOR, self.set_schedule(True))1636 wx.CallLater(5 * TIME_FACTOR, self.set_schedule(True)) 1648 1637 self.set_plot_unfocus() 1649 1638 1650 1639 def show_welcome_panel(self, event): 1651 """ 1640 """ 1652 1641 Display the welcome panel 1653 1642 """ 1654 1643 if self.defaultPanel is None: 1655 return 1644 return 1656 1645 frame = self.panels['default'].get_frame() 1657 1646 if frame == None: … … 1660 1649 if not frame.IsShown(): 1661 1650 frame.Show(True) 1662 1651 1663 1652 def on_close_welcome_panel(self): 1664 1653 """ … … 1666 1655 """ 1667 1656 if self.defaultPanel is None: 1668 return 1657 return 1669 1658 default_panel = self.panels["default"].frame 1670 1659 if default_panel.IsShown(): 1671 default_panel.Show(False) 1672 1660 default_panel.Show(False) 1661 1673 1662 def delete_panel(self, uid): 1674 1663 """ … … 1677 1666 ID = str(uid) 1678 1667 config.printEVT("delete_panel: %s" % ID) 1679 try:1680 caption = self.panels[ID].window_caption1681 except:1682 logging.error("delete_panel: No such plot id as %s" % ID)1683 return1684 1668 if ID in self.panels.keys(): 1685 1669 self.panel_on_focus = None … … 1691 1675 1692 1676 if panel in self.schedule_full_draw_list: 1693 self.schedule_full_draw_list.remove(panel) 1694 1677 self.schedule_full_draw_list.remove(panel) 1678 1695 1679 #delete uid number not str(uid) 1696 1680 if ID in self.plot_panels.keys(): … … 1698 1682 if ID in self.panels.keys(): 1699 1683 del self.panels[ID] 1700 return 1701 1684 else: 1685 logging.error("delete_panel: No such plot id as %s" % ID) 1686 1702 1687 def create_gui_data(self, data, path=None): 1703 1688 """ 1704 1689 """ 1705 1690 return self._data_manager.create_gui_data(data, path) 1706 1691 1707 1692 def get_data(self, path): 1708 1693 """ … … 1712 1697 output = [] 1713 1698 error_message = "" 1714 basename 1699 basename = os.path.basename(path) 1715 1700 root, extension = os.path.splitext(basename) 1716 1701 if extension.lower() not in EXTENSIONS: … … 1720 1705 logging.error(log_msg) 1721 1706 return 1722 1707 1723 1708 #reading a state file 1724 1709 for plug in self.plugins: … … 1734 1719 except: 1735 1720 msg = "DataLoader Error: Encounted Non-ASCII character" 1736 msg += "\n(%s)" % sys.exc_value1737 wx.PostEvent(self, StatusEvent(status=msg, 1738 info="error", type="stop"))1721 msg += "\n(%s)" % sys.exc_value 1722 wx.PostEvent(self, StatusEvent(status=msg, 1723 info="error", type="stop")) 1739 1724 return 1740 1725 1741 1726 style = self.__gui_style & GUIFRAME.MANAGER_ON 1742 1727 if style == GUIFRAME.MANAGER_ON: 1743 1728 if self._data_panel is not None: 1744 1729 self._data_panel.frame.Show(True) 1745 1746 def load_from_cmd(self, path):1730 1731 def load_from_cmd(self, path): 1747 1732 """ 1748 1733 load data from cmd or application 1749 """ 1734 """ 1750 1735 if path is None: 1751 1736 return … … 1754 1739 if not os.path.isfile(path) and not os.path.isdir(path): 1755 1740 return 1756 1741 1757 1742 if os.path.isdir(path): 1758 1743 self.load_folder(path) 1759 1744 return 1760 1745 1761 basename 1762 root, extension = os.path.splitext(basename)1746 basename = os.path.basename(path) 1747 _, extension = os.path.splitext(basename) 1763 1748 if extension.lower() not in EXTENSIONS: 1764 1749 self.load_data(path) … … 1767 1752 1768 1753 self._default_save_location = os.path.dirname(path) 1769 1770 def load_state(self, path, is_project=False): 1754 1755 def load_state(self, path, is_project=False): 1771 1756 """ 1772 1757 load data from command line or application 1773 1758 """ 1774 1759 if path and (path is not None) and os.path.isfile(path): 1775 basename 1760 basename = os.path.basename(path) 1776 1761 if APPLICATION_STATE_EXTENSION is not None \ 1777 1762 and basename.endswith(APPLICATION_STATE_EXTENSION): … … 1784 1769 else: 1785 1770 wx.PostEvent(self, StatusEvent(status=" ")) 1786 1771 1787 1772 def load_data(self, path): 1788 1773 """ … … 1791 1776 if not os.path.isfile(path): 1792 1777 return 1793 basename 1794 root, extension = os.path.splitext(basename)1778 basename = os.path.basename(path) 1779 _, extension = os.path.splitext(basename) 1795 1780 if extension.lower() in EXTENSIONS: 1796 1781 log_msg = "Data Loader cannot " … … 1804 1789 try: 1805 1790 logging.info("Loading Data...:\n" + str(path) + "\n") 1806 temp = 1791 temp = self.loader.load(path) 1807 1792 if temp.__class__.__name__ == "list": 1808 1793 for item in temp: … … 1812 1797 data = self.create_gui_data(temp, path) 1813 1798 output[data.id] = data 1814 1799 1815 1800 self.add_data(data_list=output) 1816 1801 except: … … 1819 1804 error_message += str(sys.exc_value) + "\n" 1820 1805 logging.error(error_message) 1821 1806 1822 1807 def load_folder(self, path): 1823 1808 """ 1824 1809 Load entire folder 1825 """ 1810 """ 1826 1811 if not os.path.isdir(path): 1827 1812 return … … 1834 1819 self._data_plugin.get_data(file_list) 1835 1820 else: 1836 return 1821 return 1837 1822 except: 1838 1823 error_message = "Error while loading" … … 1840 1825 error_message += str(sys.exc_value) + "\n" 1841 1826 logging.error(error_message) 1842 1827 1843 1828 def _on_open_state_application(self, event): 1844 1829 """ … … 1849 1834 wx.PostEvent(self, StatusEvent(status="Loading Analysis file...")) 1850 1835 plug_wlist = self._on_open_state_app_helper() 1851 dlg = wx.FileDialog(self, 1852 "Choose a file", 1836 dlg = wx.FileDialog(self, 1837 "Choose a file", 1853 1838 self._default_save_location, "", 1854 1839 plug_wlist) … … 1858 1843 self._default_save_location = os.path.dirname(path) 1859 1844 dlg.Destroy() 1860 self.load_state(path=path) 1861 1845 self.load_state(path=path) 1846 1862 1847 def _on_open_state_app_helper(self): 1863 1848 """ 1864 Helps '_on_open_state_application()' to find the extension of 1849 Helps '_on_open_state_application()' to find the extension of 1865 1850 the current perspective/application 1866 1851 """ 1867 1852 # No current perspective or no extension attr 1868 1853 if self._current_perspective is None: 1869 return PLUGINS_WLIST 1854 return PLUGINS_WLIST 1870 1855 try: 1871 # Find the extension of the perspective 1856 # Find the extension of the perspective 1872 1857 # and get that as 1st item in list 1873 1858 ind = None … … 1888 1873 1889 1874 except: 1890 plug_wlist = PLUGINS_WLIST 1891 1875 plug_wlist = PLUGINS_WLIST 1876 1892 1877 return plug_wlist 1893 1878 1894 1879 def _on_open_state_project(self, event): 1895 1880 """ … … 1899 1884 self._default_save_location = os.getcwd() 1900 1885 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1901 dlg = wx.FileDialog(self, 1902 "Choose a file", 1886 dlg = wx.FileDialog(self, 1887 "Choose a file", 1903 1888 self._default_save_location, "", 1904 1889 APPLICATION_WLIST) 1905 1890 if dlg.ShowModal() == wx.ID_OK: 1906 1891 path = dlg.GetPath() … … 1908 1893 self._default_save_location = os.path.dirname(path) 1909 1894 dlg.Destroy() 1910 1895 1911 1896 self.load_state(path=path, is_project=True) 1912 1897 1913 1898 def _on_save_application(self, event): 1914 1899 """ … … 1917 1902 if self.cpanel_on_focus is not None: 1918 1903 try: 1919 wx.PostEvent(self, 1904 wx.PostEvent(self, 1920 1905 StatusEvent(status="Saving Analysis file...")) 1921 1906 self.cpanel_on_focus.on_save(event) 1922 wx.PostEvent(self, 1907 wx.PostEvent(self, 1923 1908 StatusEvent(status="Completed saving.")) 1924 1909 except: 1925 1910 msg = "Error occurred while saving: " 1926 1911 msg += "To save, the application panel should have a data set.." 1927 wx.PostEvent(self, StatusEvent(status=msg)) 1928 1912 wx.PostEvent(self, StatusEvent(status=msg)) 1913 1929 1914 def _on_save_project(self, event): 1930 1915 """ … … 1934 1919 return 1935 1920 wx.PostEvent(self, StatusEvent(status="Saving Project file...")) 1936 reader, ext = self._current_perspective.get_extensions()1937 1921 path = None 1938 1922 extension = '*' + APPLICATION_STATE_EXTENSION 1939 1923 dlg = wx.FileDialog(self, "Save Project file", 1940 1924 self._default_save_location, "sasview_proj", 1941 extension,1942 1925 extension, 1926 wx.SAVE) 1943 1927 if dlg.ShowModal() == wx.ID_OK: 1944 1928 path = dlg.GetPath() … … 1956 1940 if temp is not None: 1957 1941 doc = temp 1958 1942 1959 1943 # Write the XML document 1960 1944 extens = APPLICATION_STATE_EXTENSION … … 1972 1956 msg += "No project was saved to %s" % (str(path)) 1973 1957 logging.error(msg) 1974 wx.PostEvent(self, StatusEvent(status=msg))1958 wx.PostEvent(self, StatusEvent(status=msg)) 1975 1959 except: 1976 1960 msg = "Error occurred while saving: " 1977 1961 msg += "To save, at least one application panel " 1978 1962 msg += "should have a data set.." 1979 wx.PostEvent(self, StatusEvent(status=msg)) 1980 1963 wx.PostEvent(self, StatusEvent(status=msg)) 1964 1981 1965 def on_save_helper(self, doc, reader, panel, path): 1982 1966 """ 1983 1967 Save state into a file 1984 1968 """ 1985 try: 1986 if reader is not None: 1987 # case of a panel with multi-pages 1988 if hasattr(panel, "opened_pages"): 1989 for uid, page in panel.opened_pages.iteritems(): 1990 data = page.get_data() 1991 # state must be cloned 1992 state = page.get_state().clone() 1993 if data is not None: 1994 new_doc = reader.write_toXML(data, state) 1995 if doc != None and hasattr(doc, "firstChild"): 1996 child = new_doc.firstChild.firstChild 1997 doc.firstChild.appendChild(child) 1998 else: 1999 doc = new_doc 2000 # case of only a panel 2001 else: 2002 data = panel.get_data() 2003 state = panel.get_state() 1969 if reader is not None: 1970 # case of a panel with multi-pages 1971 if hasattr(panel, "opened_pages"): 1972 for _, page in panel.opened_pages.iteritems(): 1973 data = page.get_data() 1974 # state must be cloned 1975 state = page.get_state().clone() 2004 1976 if data is not None: 2005 1977 new_doc = reader.write_toXML(data, state) 2006 1978 if doc != None and hasattr(doc, "firstChild"): 2007 1979 child = new_doc.firstChild.firstChild 2008 doc.firstChild.appendChild(child) 1980 doc.firstChild.appendChild(child) 2009 1981 else: 2010 doc = new_doc 2011 except: 2012 raise 2013 #pass 2014 1982 doc = new_doc 1983 # case of only a panel 1984 else: 1985 data = panel.get_data() 1986 state = panel.get_state() 1987 if data is not None: 1988 new_doc = reader.write_toXML(data, state) 1989 if doc != None and hasattr(doc, "firstChild"): 1990 child = new_doc.firstChild.firstChild 1991 doc.firstChild.appendChild(child) 1992 else: 1993 doc = new_doc 2015 1994 return doc 2016 1995 … … 2021 2000 message = "\nDo you really want to exit this application? \n\n" 2022 2001 dial = wx.MessageDialog(self, message, 'Confirm Exit', 2023 wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)2002 wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION) 2024 2003 if dial.ShowModal() == wx.ID_YES: 2025 2004 return True 2026 2005 else: 2027 return False 2028 2006 return False 2007 2029 2008 def WindowClose(self, event=None): 2030 2009 """ … … 2035 2014 _pylab_helpers.Gcf.figs = {} 2036 2015 self.Close() 2037 2016 2038 2017 def Close(self, event=None): 2039 2018 """ … … 2042 2021 wx.Exit() 2043 2022 sys.exit() 2044 2045 def _check_update(self, event=None): 2023 2024 def _check_update(self, event=None): 2046 2025 """ 2047 2026 Check with the deployment server whether a new version … … 2051 2030 """ 2052 2031 try: 2053 conn = httplib.HTTPConnection(config.__update_URL__[0], 2054 timeout=3.0)2032 conn = httplib.HTTPConnection(config.__update_URL__[0], 2033 timeout=3.0) 2055 2034 conn.request("GET", config.__update_URL__[1]) 2056 2035 res = conn.getresponse() … … 2059 2038 except: 2060 2039 content = "0.0.0" 2061 2040 2062 2041 version = content.strip() 2063 2042 if len(re.findall('\d+\.\d+\.\d+$', version)) < 0: 2064 2043 content = "0.0.0" 2065 self._process_version(content, standalone=event ==None)2066 2044 self._process_version(content, standalone=event == None) 2045 2067 2046 def _process_version(self, version, standalone=True): 2068 2047 """ … … 2071 2050 version number has been obtained. If the check is being done in the 2072 2051 background, the user will not be notified unless there's an update. 2073 2052 2074 2053 :param version: version string 2075 :param standalone: True of the update is being checked in 2054 :param standalone: True of the update is being checked in 2076 2055 the background, False otherwise. 2077 2056 2078 2057 """ 2079 2058 try: … … 2088 2067 webbrowser.open(config.__download_page__) 2089 2068 else: 2090 msg += "See the help menu to download it."2069 msg += "See the help menu to download it." 2091 2070 self.SetStatusText(msg) 2092 2071 else: … … 2103 2082 msg += " Please try again later." 2104 2083 self.SetStatusText(msg) 2105 2084 2106 2085 def _onAcknowledge(self, evt): 2107 2086 """ 2108 2087 Pop up the acknowledge dialog 2109 2088 2110 2089 :param evt: menu event 2111 2090 2112 2091 """ 2113 2092 if config._do_acknowledge: … … 2115 2094 dialog = AcknowledgeBox.DialogAcknowledge(None, -1, "") 2116 2095 dialog.ShowModal() 2117 2096 2118 2097 def _onAbout(self, evt): 2119 2098 """ 2120 2099 Pop up the about dialog 2121 2100 2122 2101 :param evt: menu event 2123 2102 2124 2103 """ 2125 2104 if config._do_aboutbox: 2126 2105 import sas.guiframe.aboutbox as AboutBox 2127 2106 dialog = AboutBox.DialogAbout(None, -1, "") 2128 dialog.ShowModal() 2129 2107 dialog.ShowModal() 2108 2130 2109 def _onTutorial(self, evt): 2131 2110 """ 2132 2111 Pop up the tutorial dialog 2133 2112 2134 2113 :param evt: menu event 2135 2136 """ 2137 if config._do_tutorial: 2114 2115 """ 2116 if config._do_tutorial: 2138 2117 path = config.TUTORIAL_PATH 2139 2118 if IS_WIN: … … 2142 2121 dialog = PDFFrame(None, -1, "Tutorial", path) 2143 2122 # put icon 2144 self.put_icon(dialog) 2145 dialog.Show(True) 2123 self.put_icon(dialog) 2124 dialog.Show(True) 2146 2125 except: 2147 2126 logging.error("Error in _onTutorial: %s" % sys.exc_value) … … 2175 2154 'documentation' is clicked. Calls DocumentationWindow with the top 2176 2155 level path of "index.html" 2177 2156 2178 2157 :param evt: menu event 2179 2158 """ … … 2181 2160 # different place than they would otherwise. 2182 2161 from documentation_window import DocumentationWindow 2183 2184 sphinx_doc_viewer = DocumentationWindow(self, -1, "index.html", \ 2185 "General Help") 2162 DocumentationWindow(self, -1, "index.html", "General Help") 2186 2163 2187 2164 def set_manager(self, manager): 2188 2165 """ 2189 2166 Sets the application manager for this frame 2190 2167 2191 2168 :param manager: frame manager 2192 2169 """ 2193 2170 self.app_manager = manager 2194 2171 2195 2172 def post_init(self): 2196 2173 """ 2197 This initialization method is called after the GUI 2174 This initialization method is called after the GUI 2198 2175 has been created and all plug-ins loaded. It calls 2199 2176 the post_init() method of each plug-in (if it exists) … … 2203 2180 if hasattr(item, "post_init"): 2204 2181 item.post_init() 2205 2182 2206 2183 def set_default_perspective(self): 2207 2184 """ 2208 Choose among the plugin the first plug-in that has 2185 Choose among the plugin the first plug-in that has 2209 2186 "set_default_perspective" method and its return value is True will be 2210 2187 as a default perspective when the welcome page is closed … … 2214 2191 if item.set_default_perspective(): 2215 2192 item.on_perspective(event=None) 2216 return 2217 2193 return 2194 2218 2195 def set_perspective(self, panels): 2219 2196 """ … … 2221 2198 Opens all the panels in the list, and closes 2222 2199 all the others. 2223 2200 2224 2201 :param panels: list of panels 2225 2202 """ … … 2228 2205 if hasattr(self.panels[item], "ALWAYS_ON"): 2229 2206 if self.panels[item].ALWAYS_ON: 2230 continue 2207 continue 2231 2208 if self.panels[item] == None: 2232 2209 continue … … 2252 2229 if frame.IsShown(): 2253 2230 frame.Show(False) 2254 2231 2255 2232 def show_data_panel(self, event=None, action=True): 2256 2233 """ … … 2263 2240 frame = pane.get_frame() 2264 2241 if label == 'Show Data Explorer': 2265 if action: 2242 if action: 2266 2243 frame.Show(True) 2267 2244 self.__gui_style = self.__gui_style | GUIFRAME.MANAGER_ON … … 2278 2255 if self._data_manager is not None: 2279 2256 self._data_manager.add_data(data_list) 2280 2257 2281 2258 def add_data(self, data_list): 2282 2259 """ 2283 2260 receive a dictionary of data from loader 2284 2261 store them its data manager if possible 2285 send to data the current active perspective if the data panel 2286 is not active. 2262 send to data the current active perspective if the data panel 2263 is not active. 2287 2264 :param data_list: dictionary of data's ID and value Data 2288 2265 """ … … 2293 2270 data_state = self._data_manager.get_data_state(data_list.keys()) 2294 2271 self._data_panel.load_data_list(data_state) 2295 #if the data panel is shown wait for the user to press a button 2272 #if the data panel is shown wait for the user to press a button 2296 2273 #to send data to the current perspective. if the panel is not 2297 2274 #show automatically send the data to the current perspective 2298 2275 style = self.__gui_style & GUIFRAME.MANAGER_ON 2299 2276 if style == GUIFRAME.MANAGER_ON: 2300 #wait for button press from the data panel to set_data 2277 #wait for button press from the data panel to set_data 2301 2278 if self._data_panel is not None: 2302 2279 self._data_panel.frame.Show(True) … … 2304 2281 #automatically send that to the current perspective 2305 2282 self.set_data(data_id=data_list.keys()) 2306 2307 def set_data(self, data_id, theory_id=None): 2283 2284 def set_data(self, data_id, theory_id=None): 2308 2285 """ 2309 2286 set data to current perspective … … 2316 2293 msg = "Guiframe does not have a current perspective" 2317 2294 logging.info(msg) 2318 2295 2319 2296 def set_theory(self, state_id, theory_id=None): 2320 2297 """ … … 2331 2308 msg = "Guiframe does not have a current perspective" 2332 2309 logging.info(msg) 2333 2334 def plot_data(self, 2310 2311 def plot_data(self, state_id, data_id=None, 2335 2312 theory_id=None, append=False): 2336 2313 """ 2337 2314 send a list of data to plot 2338 2315 """ 2339 total_plot_list = []2340 2316 data_list, _ = self._data_manager.get_by_id(data_id) 2341 2317 _, temp_list_theory = self._data_manager.get_by_id(theory_id) … … 2350 2326 message = "cannot append plot. No plot panel on focus!" 2351 2327 message += "please click on any available plot to set focus" 2352 wx.PostEvent(self, StatusEvent(status=message, 2328 wx.PostEvent(self, StatusEvent(status=message, 2353 2329 info='warning')) 2354 return 2330 return 2355 2331 else: 2356 2332 if self.enable_add_data(new_plot): … … 2359 2335 message = "Only 1D Data can be append to" 2360 2336 message += " plot panel containing 1D data.\n" 2361 message += "%s not be appended.\n" % str(new_plot.name)2337 message += "%s not be appended.\n" % str(new_plot.name) 2362 2338 message += "try new plot option.\n" 2363 wx.PostEvent(self, StatusEvent(status=message, 2364 info='warning'))2339 wx.PostEvent(self, StatusEvent(status=message, 2340 info='warning')) 2365 2341 else: 2366 2342 #if not append then new plot … … 2374 2350 title = "PLOT " + str(new_plot.title) 2375 2351 wx.PostEvent(self, NewPlotEvent(plot=new_plot, 2376 2377 group_id =new_plot.group_id))2378 2352 title=title, 2353 group_id=new_plot.group_id)) 2354 2379 2355 def remove_data(self, data_id, theory_id=None): 2380 2356 """ … … 2387 2363 for plug in self.plugins: 2388 2364 plug.delete_data(temp) 2389 total_plot_list = []2390 2365 data_list, _ = self._data_manager.get_by_id(data_id) 2391 2366 _, temp_list_theory = self._data_manager.get_by_id(theory_id) … … 2398 2373 for group_id in new_plot.list_group_id: 2399 2374 wx.PostEvent(self, NewPlotEvent(id=id, 2400 2401 2375 group_id=group_id, 2376 action='remove')) 2402 2377 #remove res plot: Todo: improve 2403 2378 wx.CallAfter(self._remove_res_plot, id) 2404 self._data_manager.delete_data(data_id=data_id, 2379 self._data_manager.delete_data(data_id=data_id, 2405 2380 theory_id=theory_id) 2406 2381 2407 2382 def _remove_res_plot(self, id): 2408 2383 """ 2409 2384 Try to remove corresponding res plot 2410 2385 2411 2386 : param id: id of the data 2412 2387 """ 2413 2388 try: 2414 wx.PostEvent(self, NewPlotEvent(id=("res" +str(id)),2415 group_id=("res"+str(id)),2416 action='remove'))2389 wx.PostEvent(self, NewPlotEvent(id=("res" + str(id)), 2390 group_id=("res" + str(id)), 2391 action='remove')) 2417 2392 except: 2418 pass2419 2393 logging.error(sys.exc_value) 2394 2420 2395 def save_data1d(self, data, fname): 2421 2396 """ … … 2424 2399 default_name = fname 2425 2400 wildcard = "Text files (*.txt)|*.txt|"\ 2426 "CanSAS 1D files(*.xml)|*.xml" 2401 "CanSAS 1D files(*.xml)|*.xml" 2427 2402 path = None 2428 2403 dlg = wx.FileDialog(self, "Choose a file", 2429 2404 self._default_save_location, 2430 default_name, wildcard 2431 2405 default_name, wildcard, wx.SAVE) 2406 2432 2407 if dlg.ShowModal() == wx.ID_OK: 2433 2408 path = dlg.GetPath() … … 2441 2416 path = os.path.splitext(path)[0] + format 2442 2417 mypath = os.path.basename(path) 2443 2444 #TODO: This is bad design. The DataLoader is designed 2445 #to recognize extensions. 2446 # It should be a simple matter of calling the . 2447 #save(file, data, '.xml') method 2448 # of the sas.dataloader.loader.Loader class. 2449 from sas.dataloader.loader import Loader 2450 #Instantiate a loader 2451 loader = Loader() 2418 2419 #Instantiate a loader 2420 loader = Loader() 2452 2421 format = ".txt" 2453 2422 if os.path.splitext(mypath)[1].lower() == format: … … 2465 2434 self._default_save_location = os.path.dirname(path) 2466 2435 except: 2467 pass 2436 pass 2468 2437 dlg.Destroy() 2469 2470 2438 2439 2471 2440 def _onsaveTXT(self, data, path): 2472 2441 """ 2473 Save file as txt 2442 Save file as txt 2474 2443 :TODO: Refactor and remove this method. See TODO in _onSave. 2475 2444 """ … … 2493 2462 else: 2494 2463 out.write("<X> <Y>\n") 2495 2464 2496 2465 for i in range(len(data.x)): 2497 2466 if has_errors: 2498 2467 if data.dx != None and data.dx != []: 2499 2468 if data.dx[i] != None: 2500 out.write("%g %g %g %g\n" % (data.x[i], 2501 data.y[i],2502 data.dy[i],2503 data.dx[i]))2469 out.write("%g %g %g %g\n" % (data.x[i], 2470 data.y[i], 2471 data.dy[i], 2472 data.dx[i])) 2504 2473 else: 2505 out.write("%g %g %g\n" % (data.x[i], 2474 out.write("%g %g %g\n" % (data.x[i], 2506 2475 data.y[i], 2507 2476 data.dy[i])) 2508 2477 else: 2509 out.write("%g %g %g\n" % (data.x[i], 2478 out.write("%g %g %g\n" % (data.x[i], 2510 2479 data.y[i], 2511 2480 data.dy[i])) 2512 2481 else: 2513 out.write("%g %g\n" % (data.x[i], 2482 out.write("%g %g\n" % (data.x[i], 2514 2483 data.y[i])) 2515 out.close() 2516 2484 out.close() 2485 2517 2486 def show_data1d(self, data, name): 2518 2487 """ 2519 2488 Show data dialog 2520 """ 2489 """ 2521 2490 try: 2522 2491 xmin = min(data.x) 2523 2492 ymin = min(data.y) 2524 2493 except: 2525 msg = "Unable to find min/max of \n data named %s" % \2526 data.filename 2494 msg = "Unable to find min/max of \n data named %s" % \ 2495 data.filename 2527 2496 wx.PostEvent(self, StatusEvent(status=msg, 2528 info="error"))2497 info="error")) 2529 2498 raise ValueError, msg 2530 2499 ## text = str(data) 2531 2500 text = data.__str__() 2532 2501 text += 'Data Min Max:\n' 2533 text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x))2534 text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y))2502 text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x)) 2503 text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y)) 2535 2504 if data.dy != None: 2536 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy))2505 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) 2537 2506 text += '\nData Points:\n' 2538 2507 x_st = "X" … … 2547 2516 dx_val = 0.0 2548 2517 if data.dxl != None and len(data.dxl) > index: 2549 if index == 0: 2518 if index == 0: 2550 2519 x_st = "Xl" 2551 2520 dx_val = data.dxl[index] 2552 2521 elif data.dxw != None and len(data.dxw) > index: 2553 if index == 0: 2522 if index == 0: 2554 2523 x_st = "Xw" 2555 2524 dx_val = data.dxw[index] 2556 2525 2557 2526 if index == 0: 2558 text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st2527 text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st 2559 2528 text += "%s \t%s \t%s \t%s \t%s\n" % (index, 2560 data.x[index],2561 data.y[index],2562 dy_val,2563 dx_val)2529 data.x[index], 2530 data.y[index], 2531 dy_val, 2532 dx_val) 2564 2533 from pdfview import TextFrame 2565 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text)2534 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 2566 2535 # put icon 2567 self.put_icon(frame) 2568 frame.Show(True) 2569 2570 def save_data2d(self, data, fname): 2536 self.put_icon(frame) 2537 frame.Show(True) 2538 2539 def save_data2d(self, data, fname): 2571 2540 """ 2572 2541 Save data2d dialog … … 2576 2545 dlg = wx.FileDialog(self, "Choose a file", 2577 2546 self._default_save_location, 2578 default_name, wildcard 2579 2547 default_name, wildcard, wx.SAVE) 2548 2580 2549 if dlg.ShowModal() == wx.ID_OK: 2581 2550 path = dlg.GetPath() … … 2589 2558 path = os.path.splitext(path)[0] + format 2590 2559 mypath = os.path.basename(path) 2591 2592 #TODO: This is bad design. The DataLoader is designed 2593 #to recognize extensions. 2594 # It should be a simple matter of calling the . 2595 #save(file, data, '.xml') method 2596 # of the DataLoader.loader.Loader class. 2597 from sas.dataloader.loader import Loader 2598 #Instantiate a loader 2599 loader = Loader() 2560 2561 #Instantiate a loader 2562 loader = Loader() 2600 2563 2601 2564 format = ".dat" … … 2608 2571 self._default_save_location = os.path.dirname(path) 2609 2572 except: 2610 pass 2611 dlg.Destroy() 2612 2573 pass 2574 dlg.Destroy() 2575 2613 2576 def show_data2d(self, data, name): 2614 2577 """ 2615 2578 Show data dialog 2616 """ 2617 2618 wx.PostEvent(self, StatusEvent(status = "Gathering Data2D Info.", 2619 type = 'start' )) 2620 text = data.__str__() 2579 """ 2580 wx.PostEvent(self, StatusEvent(status="Gathering Data2D Info.", 2581 type='start')) 2582 text = data.__str__() 2621 2583 text += 'Data Min Max:\n' 2622 text += 'I_min = %s\n' % min(data.data)2623 text += 'I_max = %s\n\n' % max(data.data)2584 text += 'I_min = %s\n' % min(data.data) 2585 text += 'I_max = %s\n\n' % max(data.data) 2624 2586 text += 'Data (First 2501) Points:\n' 2625 2587 text += 'Data columns include err(I).\n' … … 2629 2591 dx_val = 0.0 2630 2592 dy_val = 0.0 2631 #mask_val = True2632 2593 len_data = len(data.qx_data) 2633 2594 for index in xrange(0, len_data): … … 2635 2596 y_val = data.qy_data[index] 2636 2597 i_val = data.data[index] 2637 if data.err_data != None: 2598 if data.err_data != None: 2638 2599 di_val = data.err_data[index] 2639 if data.dqx_data != None: 2600 if data.dqx_data != None: 2640 2601 dx_val = data.dqx_data[index] 2641 if data.dqy_data != None: 2602 if data.dqy_data != None: 2642 2603 dy_val = data.dqy_data[index] 2643 2604 2644 2605 text += "%s \t%s \t%s \t%s \t%s \t%s \t%s\n" % (index, 2645 x_val,2646 y_val,2647 i_val,2648 di_val,2649 dx_val,2650 dy_val)2606 x_val, 2607 y_val, 2608 i_val, 2609 di_val, 2610 dx_val, 2611 dy_val) 2651 2612 # Takes too long time for typical data2d: Break here 2652 2613 if index >= 2500: … … 2655 2616 2656 2617 from pdfview import TextFrame 2657 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text)2618 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 2658 2619 # put icon 2659 2620 self.put_icon(frame) 2660 frame.Show(True) 2661 wx.PostEvent(self, StatusEvent(status = "Data2D Info Displayed",2662 type = 'stop'))2663 2621 frame.Show(True) 2622 wx.PostEvent(self, StatusEvent(status="Data2D Info Displayed", 2623 type='stop')) 2624 2664 2625 def set_current_perspective(self, perspective): 2665 2626 """ 2666 set the current active perspective 2627 set the current active perspective 2667 2628 """ 2668 2629 self._current_perspective = perspective … … 2680 2641 else: 2681 2642 frame.Show(False) 2682 #break2683 2643 name = self._current_perspective.sub_menu 2684 2644 if self._data_panel is not None: … … 2687 2647 #Set the SasView title 2688 2648 self._set_title_name(name) 2689 2649 2690 2650 def _set_title_name(self, name): 2691 2651 """ 2692 2652 Set the SasView title w/ the current application name 2693 2653 2694 2654 : param name: application name [string] 2695 2655 """ … … 2697 2657 title = self.title + " - " + name + " -" 2698 2658 self.SetTitle(title) 2699 2659 2700 2660 def _check_applications_menu(self): 2701 2661 """ … … 2710 2670 menu.Check(True) 2711 2671 else: 2712 menu.Check(False) 2713 2672 menu.Check(False) 2673 2714 2674 def enable_add_data(self, new_plot): 2715 2675 """ … … 2721 2681 is_theory = len(self.panel_on_focus.plots) <= 1 and \ 2722 2682 self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D" 2723 2683 2724 2684 is_data2d = hasattr(new_plot, 'data') 2725 2685 2726 2686 is_data1d = self.panel_on_focus.__class__.__name__ == "ModelPanel1D"\ 2727 2687 and self.panel_on_focus.group_id is not None 2728 2688 has_meta_data = hasattr(new_plot, 'meta_data') 2729 2689 2730 2690 #disable_add_data if the data is being recovered from a saved state file. 2731 2691 is_state_data = False 2732 2692 if has_meta_data: 2733 if 'invstate' in new_plot.meta_data: 2693 if 'invstate' in new_plot.meta_data: 2734 2694 is_state_data = True 2735 if 'prstate' in new_plot.meta_data: 2695 if 'prstate' in new_plot.meta_data: 2736 2696 is_state_data = True 2737 if 'fitstate' in new_plot.meta_data: 2697 if 'fitstate' in new_plot.meta_data: 2738 2698 is_state_data = True 2739 2699 2740 2700 return is_data1d and not is_data2d and not is_theory and not is_state_data 2741 2701 2742 2702 def check_multimode(self, perspective=None): 2743 2703 """ … … 2756 2716 self._data_panel.rb_single_mode.Enable(flag) 2757 2717 self._data_panel.rb_batch_mode.Enable(flag) 2758 2759 2760 2718 2761 2719 def enable_edit_menu(self): 2762 2720 """ … … 2775 2733 #Copy menu 2776 2734 flag = self.cpanel_on_focus.get_copy_flag() 2777 #self._edit_menu.ENABLE(GUIFRAME_ID.COPYAS_ID,flag)2778 2735 self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag) 2779 2736 self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYLAT_ID, flag) … … 2789 2746 self._edit_menu.Enable(GUIFRAME_ID.COPY_ID, flag) 2790 2747 self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) 2791 #self._edit_menu.Enable(GUIFRAME_ID.COPYEX_ID, flag)2792 #self._edit_menu.Enable(GUIFRAME_ID.COPYLAT_ID, flag)2793 #self._edit_menu.Enable(GUIFRAME_ID.COPYAS_ID, flag)2794 2748 self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) 2795 2749 self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) 2796 2750 2797 2751 def on_undo_panel(self, event=None): 2798 2752 """ … … 2801 2755 if self.cpanel_on_focus is not None: 2802 2756 self.cpanel_on_focus.on_undo(event) 2803 2757 2804 2758 def on_redo_panel(self, event=None): 2805 2759 """ … … 2808 2762 if self.cpanel_on_focus is not None: 2809 2763 self.cpanel_on_focus.on_redo(event) 2810 2764 2811 2765 def on_copy_panel(self, event=None): 2812 2766 """ … … 2815 2769 if self.cpanel_on_focus is not None: 2816 2770 self.cpanel_on_focus.on_copy(event) 2817 2771 2818 2772 def on_paste_panel(self, event=None): 2819 2773 """ … … 2822 2776 if self.cpanel_on_focus is not None: 2823 2777 self.cpanel_on_focus.on_paste(event) 2824 2778 2825 2779 def on_bookmark_panel(self, event=None): 2826 2780 """ … … 2829 2783 if self.cpanel_on_focus is not None: 2830 2784 self.cpanel_on_focus.on_bookmark(event) 2831 2785 2832 2786 def append_bookmark(self, event=None): 2833 2787 """ … … 2835 2789 """ 2836 2790 self._toolbar.append_bookmark(event) 2837 2791 2838 2792 def on_save_panel(self, event=None): 2839 2793 """ … … 2842 2796 if self.cpanel_on_focus is not None: 2843 2797 self.cpanel_on_focus.on_save(event) 2844 2798 2845 2799 def on_preview_panel(self, event=None): 2846 2800 """ … … 2849 2803 if self.cpanel_on_focus is not None: 2850 2804 self.cpanel_on_focus.on_preview(event) 2851 2805 2852 2806 def on_print_panel(self, event=None): 2853 2807 """ … … 2856 2810 if self.cpanel_on_focus is not None: 2857 2811 self.cpanel_on_focus.on_print(event) 2858 2812 2859 2813 def on_zoom_panel(self, event=None): 2860 2814 """ … … 2863 2817 if self.cpanel_on_focus is not None: 2864 2818 self.cpanel_on_focus.on_zoom(event) 2865 2819 2866 2820 def on_zoom_in_panel(self, event=None): 2867 2821 """ … … 2870 2824 if self.cpanel_on_focus is not None: 2871 2825 self.cpanel_on_focus.on_zoom_in(event) 2872 2826 2873 2827 def on_zoom_out_panel(self, event=None): 2874 2828 """ … … 2877 2831 if self.cpanel_on_focus is not None: 2878 2832 self.cpanel_on_focus.on_zoom_out(event) 2879 2833 2880 2834 def on_drag_panel(self, event=None): 2881 2835 """ … … 2884 2838 if self.cpanel_on_focus is not None: 2885 2839 self.cpanel_on_focus.on_drag(event) 2886 2840 2887 2841 def on_reset_panel(self, event=None): 2888 2842 """ … … 2891 2845 if self.cpanel_on_focus is not None: 2892 2846 self.cpanel_on_focus.on_reset(event) 2893 2894 def on_change_caption(self, name, old_caption, new_caption): 2847 2848 def on_change_caption(self, name, old_caption, new_caption): 2895 2849 """ 2896 2850 Change the panel caption 2897 2851 2898 2852 :param name: window_name of the pane 2899 2853 :param old_caption: current caption [string] … … 2901 2855 """ 2902 2856 # wx.aui.AuiPaneInfo 2903 pane_info = self.get_paneinfo(old_caption) 2857 pane_info = self.get_paneinfo(old_caption) 2904 2858 # update the data_panel.cb_plotpanel 2905 2859 if 'data_panel' in self.panels.keys(): … … 2909 2863 # Check if any panel has the same caption 2910 2864 has_newstring = data_panel.cb_plotpanel.FindString\ 2911 (str(new_caption)) 2865 (str(new_caption)) 2912 2866 caption = new_caption 2913 2867 if has_newstring != wx.NOT_FOUND: … … 2915 2869 # Append nummber 2916 2870 inc = 1 2871 #FIXME: fix this terrible loop 2917 2872 while (1): 2918 caption = new_caption + '_%s' % str(inc)2873 caption = new_caption + '_%s' % str(inc) 2919 2874 if caption not in captions: 2920 2875 break 2921 2876 inc += 1 2922 2877 # notify to users 2923 msg = "Found Same Title: Added '_%s'" % str(inc)2878 msg = "Found Same Title: Added '_%s'" % str(inc) 2924 2879 wx.PostEvent(self, StatusEvent(status=msg)) 2925 2880 # update data_panel cb 2926 pos = data_panel.cb_plotpanel.FindString(str(old_caption)) 2881 pos = data_panel.cb_plotpanel.FindString(str(old_caption)) 2927 2882 if pos != wx.NOT_FOUND: 2928 2883 data_panel.cb_plotpanel.SetString(pos, caption) … … 2931 2886 pane_info.SetTitle(caption) 2932 2887 return caption 2933 2888 2934 2889 def get_paneinfo(self, name): 2935 2890 """ 2936 2891 Get pane Caption from window_name 2937 2892 2938 2893 :param name: window_name in AuiPaneInfo 2939 2894 : return: AuiPaneInfo of the name … … 2943 2898 return panel.frame 2944 2899 return None 2945 2900 2946 2901 def enable_undo(self): 2947 2902 """ … … 2950 2905 if self.cpanel_on_focus is not None: 2951 2906 self._toolbar.enable_undo(self.cpanel_on_focus) 2952 2907 2953 2908 def enable_redo(self): 2954 2909 """ 2955 enable redo 2910 enable redo 2956 2911 """ 2957 2912 if self.cpanel_on_focus is not None: 2958 2913 self._toolbar.enable_redo(self.cpanel_on_focus) 2959 2914 2960 2915 def enable_copy(self): 2961 2916 """ … … 2964 2919 if self.cpanel_on_focus is not None: 2965 2920 self._toolbar.enable_copy(self.cpanel_on_focus) 2966 2921 2967 2922 def enable_paste(self): 2968 2923 """ 2969 enable paste 2924 enable paste 2970 2925 """ 2971 2926 if self.cpanel_on_focus is not None: 2972 2927 self._toolbar.enable_paste(self.cpanel_on_focus) 2973 2928 2974 2929 def enable_bookmark(self): 2975 2930 """ 2976 Bookmark 2931 Bookmark 2977 2932 """ 2978 2933 if self.cpanel_on_focus is not None: 2979 2934 self._toolbar.enable_bookmark(self.cpanel_on_focus) 2980 2935 2981 2936 def enable_save(self): 2982 2937 """ 2983 save 2938 save 2984 2939 """ 2985 2940 if self.cpanel_on_focus is not None: 2986 2941 self._toolbar.enable_save(self.cpanel_on_focus) 2987 2942 2988 2943 def enable_preview(self): 2989 2944 """ 2990 preview 2945 preview 2991 2946 """ 2992 2947 if self.cpanel_on_focus is not None: 2993 2948 self._toolbar.enable_preview(self.cpanel_on_focus) 2994 2949 2995 2950 def enable_print(self): 2996 2951 """ 2997 print 2952 print 2998 2953 """ 2999 2954 if self.cpanel_on_focus is not None: 3000 2955 self._toolbar.enable_print(self.cpanel_on_focus) 3001 2956 3002 2957 def enable_zoom(self): 3003 2958 """ 3004 zoom 2959 zoom 3005 2960 """ 3006 2961 if self.cpanel_on_focus is not None: 3007 2962 self._toolbar.enable_zoom(self.panel_on_focus) 3008 2963 3009 2964 def enable_zoom_in(self): 3010 2965 """ 3011 zoom in 2966 zoom in 3012 2967 """ 3013 2968 if self.cpanel_on_focus is not None: 3014 2969 self._toolbar.enable_zoom_in(self.panel_on_focus) 3015 2970 3016 2971 def enable_zoom_out(self): 3017 2972 """ 3018 zoom out 2973 zoom out 3019 2974 """ 3020 2975 if self.cpanel_on_focus is not None: 3021 2976 self._toolbar.enable_zoom_out(self.panel_on_focus) 3022 2977 3023 2978 def enable_drag(self, event=None): 3024 2979 """ 3025 drag 2980 drag 3026 2981 """ 3027 2982 #Not implemeted 3028 2983 3029 2984 def enable_reset(self): 3030 2985 """ … … 3033 2988 if self.cpanel_on_focus is not None: 3034 2989 self._toolbar.enable_reset(self.panel_on_focus) 3035 2990 3036 2991 def get_toolbar_height(self): 3037 2992 """ … … 3042 2997 _, size_y = self.GetToolBar().GetSizeTuple() 3043 2998 return size_y 3044 2999 3045 3000 def set_schedule_full_draw(self, panel=None, func='del'): 3046 3001 """ 3047 3002 Add/subtract the schedule full draw list with the panel given 3048 3003 3049 3004 :param panel: plot panel 3050 3005 :param func: append or del [string] … … 3054 3009 if func == 'append': 3055 3010 if not panel in self.schedule_full_draw_list: 3056 self.schedule_full_draw_list.append(panel) 3011 self.schedule_full_draw_list.append(panel) 3057 3012 # remove this panel from schedule list 3058 3013 elif func == 'del': … … 3065 3020 self.schedule = False 3066 3021 else: 3067 self.schedule = True 3068 3022 self.schedule = True 3023 3069 3024 def full_draw(self): 3070 3025 """ 3071 3026 Draw the panels with axes in the schedule to full dwar list 3072 3027 """ 3073 3028 3074 3029 count = len(self.schedule_full_draw_list) 3075 3030 #if not self.schedule: … … 3097 3052 # while any panel is capture. 3098 3053 frame = panel.frame 3099 3054 3100 3055 if not frame.GetCapture(): 3101 3056 # draw if possible … … 3105 3060 # Check if the panel is not shown 3106 3061 flag = frame.IsShown() 3107 frame.Show(flag) 3062 frame.Show(flag) 3108 3063 except: 3109 3064 pass 3110 3065 3111 3066 # Draw all panels 3112 3067 if count == 1: 3113 f_draw(self.schedule_full_draw_list[0]) 3068 f_draw(self.schedule_full_draw_list[0]) 3114 3069 else: 3115 3070 map(f_draw, self.schedule_full_draw_list) … … 3119 3074 else: 3120 3075 self.set_schedule(True) 3121 3122 def set_schedule(self, schedule=False): 3076 3077 def set_schedule(self, schedule=False): 3123 3078 """ 3124 3079 Set schedule 3125 3080 """ 3126 3081 self.schedule = schedule 3127 3128 def get_schedule(self): 3082 3083 def get_schedule(self): 3129 3084 """ 3130 3085 Get schedule 3131 3086 """ 3132 3087 return self.schedule 3133 3088 3134 3089 def on_set_plot_focus(self, panel): 3135 3090 """ … … 3139 3094 return 3140 3095 #self.set_plot_unfocus() 3141 panel.on_set_focus(None) 3096 panel.on_set_focus(None) 3142 3097 # set focusing panel 3143 self.panel_on_focus = panel 3098 self.panel_on_focus = panel 3144 3099 self.set_panel_on_focus(None) 3145 3100 3146 def set_plot_unfocus(self): 3101 def set_plot_unfocus(self): 3147 3102 """ 3148 3103 Un focus all plot panels … … 3150 3105 for plot in self.plot_panels.values(): 3151 3106 plot.on_kill_focus(None) 3152 3107 3153 3108 def get_window_size(self): 3154 3109 """ 3155 Get window size 3156 3110 Get window size 3111 3157 3112 :return size: tuple 3158 3113 """ … … 3163 3118 height -= 45 3164 3119 return (width, height) 3165 3120 3166 3121 def _onDrawIdle(self, *args, **kwargs): 3167 3122 """ … … 3175 3130 except: 3176 3131 pass 3177 3132 3178 3133 # restart idle 3179 3134 self._redraw_idle(*args, **kwargs) 3180 3135 3181 3136 3182 3137 def _redraw_idle(self, *args, **kwargs): 3183 3138 """ … … 3185 3140 """ 3186 3141 # restart idle 3187 self.idletimer.Restart(100 *TIME_FACTOR, *args, **kwargs)3188 3189 3142 self.idletimer.Restart(100 * TIME_FACTOR, *args, **kwargs) 3143 3144 3190 3145 class DefaultPanel(wx.Panel, PanelBase): 3191 3146 """ … … 3202 3157 wx.Panel.__init__(self, parent, *args, **kwds) 3203 3158 PanelBase.__init__(self, parent) 3204 3159 3205 3160 3206 3161 … … 3213 3168 When initialised 3214 3169 """ 3215 pos, size, self.is_max = self.window_placement((GUIFRAME_WIDTH, 3216 GUIFRAME_HEIGHT))3217 self.frame = ViewerFrame(parent=None, 3218 title=APPLICATION_NAME,3219 pos=pos,3220 gui_style =DEFAULT_STYLE,3221 size=size)3170 pos, size, self.is_max = self.window_placement((GUIFRAME_WIDTH, 3171 GUIFRAME_HEIGHT)) 3172 self.frame = ViewerFrame(parent=None, 3173 title=APPLICATION_NAME, 3174 pos=pos, 3175 gui_style=DEFAULT_STYLE, 3176 size=size) 3222 3177 self.frame.Hide() 3223 3178 if not IS_WIN: … … 3234 3189 try: 3235 3190 if os.path.isfile(SPLASH_SCREEN_PATH): 3236 self.s_screen = self.display_splash_screen(parent=self.frame, 3237 path=SPLASH_SCREEN_PATH)3191 self.s_screen = self.display_splash_screen(parent=self.frame, 3192 path=SPLASH_SCREEN_PATH) 3238 3193 else: 3239 self.frame.Show() 3194 self.frame.Show() 3240 3195 except: 3241 3196 if self.s_screen is not None: 3242 3197 self.s_screen.Close() 3243 3198 msg = "Cannot display splash screen\n" 3244 msg += str 3199 msg += str(sys.exc_value) 3245 3200 logging.error(msg) 3246 3201 self.frame.Show() 3247 3202 3248 3203 self.SetTopWindow(self.frame) 3249 3204 3250 3205 return True 3251 3206 3252 3207 def maximize_win(self): 3253 3208 """ … … 3266 3221 if len(sys.argv) >= 2: 3267 3222 cmd = sys.argv[0].lower() 3268 basename 3223 basename = os.path.basename(cmd) 3269 3224 app_base = str(APPLICATION_NAME).lower() 3270 3225 if os.path.isfile(cmd) or basename.lower() == app_base: … … 3274 3229 if basename.lower() in [app_py, app_exe, app_app, app_base]: 3275 3230 data_base = sys.argv[1] 3276 input_file = os.path.normpath(os.path.join(DATAPATH, 3231 input_file = os.path.normpath(os.path.join(DATAPATH, 3277 3232 data_base)) 3278 3233 if input_file is None: … … 3280 3235 if self.frame is not None: 3281 3236 self.frame.set_input_file(input_file=input_file) 3282 3283 def clean_plugin_models(self, path): 3237 3238 def clean_plugin_models(self, path): 3284 3239 """ 3285 3240 Delete plugin models in app folder 3286 3241 3287 3242 :param path: path of the plugin_models folder in app 3288 3243 """ 3289 3244 # do it only the first time app loaded 3290 # delete unused model folder 3245 # delete unused model folder 3291 3246 model_folder = os.path.join(PATH_APP, path) 3292 3247 if os.path.exists(model_folder) and os.path.isdir(model_folder): … … 3300 3255 logging.error("gui_manager.clean_plugin_models:\n %s" \ 3301 3256 % sys.exc_value) 3302 3257 3303 3258 def set_manager(self, manager): 3304 3259 """ 3305 3260 Sets a reference to the application manager 3306 of the GUI manager (Frame) 3261 of the GUI manager (Frame) 3307 3262 """ 3308 3263 self.frame.set_manager(manager) 3309 3264 3310 3265 def build_gui(self): 3311 3266 """ … … 3318 3273 raise 3319 3274 self.frame.build_gui() 3320 3275 3321 3276 def set_welcome_panel(self, panel_class): 3322 3277 """ 3323 3278 Set the welcome panel 3324 3279 3325 3280 :param panel_class: class of the welcome panel to be instantiated 3326 3281 3327 3282 """ 3328 3283 self.frame.welcome_panel_class = panel_class 3329 3284 3330 3285 def add_perspective(self, perspective): 3331 3286 """ … … 3333 3288 """ 3334 3289 self.frame.add_perspective(perspective) 3335 3290 3336 3291 def window_placement(self, size): 3337 3292 """ … … 3350 3305 displayRect = screen.GetClientArea() 3351 3306 break 3352 3353 posX, posY, displayWidth, displayHeight = displayRect 3307 3308 posX, posY, displayWidth, displayHeight = displayRect 3354 3309 customWidth, customHeight = size 3355 3310 3356 3311 # If the custom size is default, set 90% of the screen size 3357 3312 if customWidth <= 0 and customHeight <= 0: … … 3367 3322 if customHeight > displayHeight: 3368 3323 customHeight = displayHeight 3369 3324 3370 3325 # Note that when running Linux and using an Xming (X11) server on a PC 3371 3326 # with a dual monitor configuration, the reported display size may be … … 3374 3329 # screen 'too big'. If so, we assume a smaller width which means the 3375 3330 # application will be placed towards the left hand side of the screen. 3376 3331 3377 3332 # If dual screen registered as 1 screen. Make width half. 3378 3333 # MAC just follows the default behavior of pos 3379 3334 if IS_WIN: 3380 if displayWidth > (displayHeight *2):3381 if (customWidth == displayWidth):3382 customWidth = displayWidth /23335 if displayWidth > (displayHeight * 2): 3336 if customWidth == displayWidth: 3337 customWidth = displayWidth / 2 3383 3338 # and set the position to be the corner of the screen. 3384 3339 posX = 0 3385 3340 posY = 0 3386 3341 3387 3342 # Make the position the middle of the screen. (Not 0,0) 3388 3343 else: 3389 posX = (displayWidth - customWidth) /23390 posY = (displayHeight - customHeight) /23391 # Return the suggested position and size for the application frame. 3344 posX = (displayWidth - customWidth) / 2 3345 posY = (displayHeight - customHeight) / 2 3346 # Return the suggested position and size for the application frame. 3392 3347 return (posX, posY), (customWidth, customHeight), is_maximized 3393 3348 3394 3395 def display_splash_screen(self, parent, 3349 3350 def display_splash_screen(self, parent, 3396 3351 path=SPLASH_SCREEN_PATH): 3397 3352 """Displays the splash screen. It will exactly cover the main frame.""" 3398 3353 3399 3354 # Prepare the picture. On a 2GHz intel cpu, this takes about a second. 3400 3355 image = wx.Image(path, wx.BITMAP_TYPE_PNG) 3401 image.Rescale(SPLASH_SCREEN_WIDTH, 3356 image.Rescale(SPLASH_SCREEN_WIDTH, 3402 3357 SPLASH_SCREEN_HEIGHT, wx.IMAGE_QUALITY_HIGH) 3403 3358 bm = image.ConvertToBitmap() … … 3413 3368 # case the splash screen disappears upon entering the event loop. 3414 3369 s_screen = wx.SplashScreen(bitmap=bm, 3415 splashStyle=(wx.SPLASH_TIMEOUT |3370 splashStyle=(wx.SPLASH_TIMEOUT | 3416 3371 wx.SPLASH_CENTRE_ON_SCREEN), 3417 style=(wx.SIMPLE_BORDER |3418 wx.FRAME_NO_TASKBAR |3372 style=(wx.SIMPLE_BORDER | 3373 wx.FRAME_NO_TASKBAR | 3419 3374 wx.FRAME_FLOAT_ON_PARENT), 3420 3375 milliseconds=SS_MAX_DISPLAY_TIME, … … 3427 3382 s_screen.Show() 3428 3383 return s_screen 3429 3430 3384 3385 3431 3386 def on_close_splash_screen(self, event): 3432 3387 """ … … 3442 3397 Frame for panels 3443 3398 """ 3444 def __init__(self, parent, panel, title="Untitled", size=(300, 200)):3399 def __init__(self, parent, panel, title="Untitled", size=(300, 200)): 3445 3400 """ 3446 3401 comment … … 3456 3411 self.set_panel(panel) 3457 3412 self.Show(False) 3458 3413 3459 3414 def show_data_panel(self, action): 3460 3415 """ 3461 3416 """ 3462 3417 self.parent.show_data_panel(action) 3463 3418 3464 3419 def set_panel(self, panel): 3465 3420 """ … … 3471 3426 width, height = self.parent._get_panels_size(panel) 3472 3427 if hasattr(panel, "CENTER_PANE") and panel.CENTER_PANE: 3473 width *= 0.6 3428 width *= 0.6 3474 3429 self.SetSize((width, height)) 3475 3430 self.parent.put_icon(self) … … 3477 3432 self.Bind(wx.EVT_CLOSE, self.OnClose) 3478 3433 self.Show(False) 3479 3434 3480 3435 def set_panel_focus(self, event): 3481 3436 """ … … 3484 3439 self.panel.SetFocus() 3485 3440 self.parent.panel_on_focus = self.panel 3486 3441 3487 3442 def OnClose(self, event): 3488 3443 """ … … 3490 3445 """ 3491 3446 self.panel.on_close(event) 3492 3493 if __name__ == "__main__": 3447 3448 if __name__ == "__main__": 3494 3449 app = ViewApp(0) 3495 3450 app.MainLoop() -
src/sas/guiframe/config.py
rf53cd30 r4bf54044 31 31 '''If you found this software useful to your work please remember to acknowledge 32 32 its use in your publications as suggested below and reference the SasView website: 33 http://www.sasview.org/ index.html. Please also consider letting us know by sending us the33 http://www.sasview.org/. Please also consider letting us know by sending us the 34 34 reference to your work. This will help us to ensure the long term support and 35 35 development of the software. 36 36 ''' 37 37 _acknowledgement_publications = \ 38 '''This work originally developed as part of the DANSE project funded by the NSF39 under grant DMR-0520547,and currently maintained by NIST, UMD, ORNL, ISIS, ESS38 '''This work benefited from software developed by the DANSE project under NSF 39 award DMR-0520547 and currently maintained by NIST, UMD, ORNL, ISIS, ESS 40 40 and ILL. 41 41 '''
Note: See TracChangeset
for help on using the changeset viewer.