Changeset 49ab5d7 in sasview for src/sas/perspectives/calculator/data_operator.py
- Timestamp:
- Mar 4, 2015 1:28:39 PM (9 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:
- 2f732b0
- Parents:
- 76aed53
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/calculator/data_operator.py
rde69095 r49ab5d7 11 11 from sas.plottools import transform 12 12 from matplotlib.font_manager import FontProperties 13 from sas.guiframe.events import StatusEvent 13 from sas.guiframe.events import StatusEvent 14 14 from sas.perspectives.calculator import calculator_widgets as widget 15 15 from sas.guiframe.documentation_window import DocumentationWindow 16 16 17 17 #Control panel width 18 18 if sys.platform.count("win32") > 0: … … 28 28 FONT_VARIANT = 1 29 29 ON_MAC = True 30 30 31 31 class DataOperPanel(wx.ScrolledWindow): 32 32 """ … … 62 62 self.fill_oprator_combox() 63 63 self.Bind(wx.EVT_PAINT, self.set_panel_on_focus) 64 64 65 65 def _define_structure(self): 66 66 """ 67 define initial sizer 67 define initial sizer 68 68 """ 69 69 self.main_sizer = wx.BoxSizer(wx.VERTICAL) … … 75 75 self.name_sizer = wx.StaticBoxSizer(name_box, wx.HORIZONTAL) 76 76 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 77 77 78 78 def _layout_name(self): 79 79 """ … … 81 81 """ 82 82 new_data_sizer = wx.BoxSizer(wx.VERTICAL) 83 equal_sizer = 83 equal_sizer = wx.BoxSizer(wx.VERTICAL) 84 84 old_data1_sizer = wx.BoxSizer(wx.VERTICAL) 85 85 operator_sizer = wx.BoxSizer(wx.VERTICAL) 86 86 old_data2_sizer = wx.BoxSizer(wx.VERTICAL) 87 87 data2_hori_sizer = wx.BoxSizer(wx.HORIZONTAL) 88 data_name = wx.StaticText(self, -1, 'Output Data Name') 89 equal_name = wx.StaticText(self, -1, ' =', size=(50, 25)) 88 data_name = wx.StaticText(self, -1, 'Output Data Name') 89 equal_name = wx.StaticText(self, -1, ' =', size=(50, 25)) 90 90 data1_name = wx.StaticText(self, -1, 'Data1') 91 91 operator_name = wx.StaticText(self, -1, 'Operator') 92 92 data2_name = wx.StaticText(self, -1, 'Data2 (or Number)') 93 self.data_namectr = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 25), style=wx.TE_PROCESS_ENTER) 93 self.data_namectr = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 25), style=wx.TE_PROCESS_ENTER) 94 94 self.data_namectr.SetToolTipString("Hit 'Enter' key after typing.") 95 95 self.data_namectr.SetValue(str('MyNewDataName')) 96 self.numberctr = wx.TextCtrl(self, -1, size=(_BOX_WIDTH /3, 25), style=wx.TE_PROCESS_ENTER)96 self.numberctr = wx.TextCtrl(self, -1, size=(_BOX_WIDTH / 3, 25), style=wx.TE_PROCESS_ENTER) 97 97 self.numberctr.SetToolTipString("Hit 'Enter' key after typing.") 98 98 self.numberctr.SetValue(str(1.0)) 99 self.data1_cbox = wx.ComboBox(self, -1, size=(_BOX_WIDTH, 25), 99 self.data1_cbox = wx.ComboBox(self, -1, size=(_BOX_WIDTH, 25), 100 100 style=wx.CB_READONLY) 101 self.operator_cbox = wx.ComboBox(self, -1, size=(70, 25), 101 self.operator_cbox = wx.ComboBox(self, -1, size=(70, 25), 102 102 style=wx.CB_READONLY) 103 103 operation_tip = "Add: +, Subtract: -, " … … 105 105 operation_tip += "Append(Combine): | " 106 106 self.operator_cbox.SetToolTipString(operation_tip) 107 self.data2_cbox = wx.ComboBox(self, -1, size=(_BOX_WIDTH *2/3, 25),107 self.data2_cbox = wx.ComboBox(self, -1, size=(_BOX_WIDTH * 2 / 3, 25), 108 108 style=wx.CB_READONLY) 109 109 110 self.out_pic = SmallPanel(self, -1, True, 111 size=(_BOX_WIDTH, _BOX_WIDTH), 110 self.out_pic = SmallPanel(self, -1, True, 111 size=(_BOX_WIDTH, _BOX_WIDTH), 112 112 style=wx.NO_BORDER) 113 self.equal_pic = SmallPanel(self, -1, True, '=', 114 size=(50, _BOX_WIDTH), 113 self.equal_pic = SmallPanel(self, -1, True, '=', 114 size=(50, _BOX_WIDTH), 115 115 style=wx.NO_BORDER) 116 self.data1_pic = SmallPanel(self, -1, True, 117 size=(_BOX_WIDTH, _BOX_WIDTH), 116 self.data1_pic = SmallPanel(self, -1, True, 117 size=(_BOX_WIDTH, _BOX_WIDTH), 118 118 style=wx.NO_BORDER) 119 119 self.operator_pic = SmallPanel(self, -1, True, '+', 120 size=(70, _BOX_WIDTH), 120 size=(70, _BOX_WIDTH), 121 121 style=wx.NO_BORDER) 122 self.data2_pic = SmallPanel(self, -1, True, 123 size=(_BOX_WIDTH, _BOX_WIDTH), 122 self.data2_pic = SmallPanel(self, -1, True, 123 size=(_BOX_WIDTH, _BOX_WIDTH), 124 124 style=wx.NO_BORDER) 125 125 for ax in self.equal_pic.axes: … … 144 144 (data2_hori_sizer, 0, wx.LEFT, 3), 145 145 (self.data2_pic, 0, wx.LEFT, 3)]) 146 self.name_sizer.AddMany([(new_data_sizer, 0, wx.LEFT |wx.TOP, 5),146 self.name_sizer.AddMany([(new_data_sizer, 0, wx.LEFT | wx.TOP, 5), 147 147 (equal_sizer, 0, wx.TOP, 5), 148 148 (old_data1_sizer, 0, wx.TOP, 5), … … 152 152 153 153 self._show_numctrl(self.numberctr, False) 154 154 155 155 wx.EVT_TEXT_ENTER(self.data_namectr, -1, self.on_name) 156 wx.EVT_TEXT_ENTER(self.numberctr, -1, self.on_number) 157 wx.EVT_COMBOBOX(self.data1_cbox, -1, self.on_select_data1) 158 wx.EVT_COMBOBOX(self.operator_cbox, -1, self.on_select_operator) 156 wx.EVT_TEXT_ENTER(self.numberctr, -1, self.on_number) 157 wx.EVT_COMBOBOX(self.data1_cbox, -1, self.on_select_data1) 158 wx.EVT_COMBOBOX(self.operator_cbox, -1, self.on_select_operator) 159 159 wx.EVT_COMBOBOX(self.data2_cbox, -1, self.on_select_data2) 160 161 def _show_numctrl(self, ctrl, enable=True): 160 161 def _show_numctrl(self, ctrl, enable=True): 162 162 """ 163 163 Show/Hide on Win … … 170 170 ctrl.GetChildren()[0].SetBackGroundColour(self.color) 171 171 if enable: 172 wx.EVT_TEXT_ENTER(self.numberctr, -1, self.on_number) 172 wx.EVT_TEXT_ENTER(self.numberctr, -1, self.on_number) 173 173 else: 174 174 if not ctrl.IsEnabled(): 175 175 ctrl.Enable(True) 176 176 ctrl.Show(enable) 177 177 178 178 def on_name(self, event=None): 179 179 """ … … 189 189 text = item.GetValue().strip() 190 190 self._check_newname(text) 191 191 192 192 def _check_newname(self, name=None): 193 193 """ … … 220 220 self.name_sizer.Layout() 221 221 self.Refresh() 222 223 def _set_textctrl_color(self, ctrl, color): 224 """ 225 Set TextCtrl color 222 223 def _set_textctrl_color(self, ctrl, color): 224 """ 225 Set TextCtrl color 226 226 """ 227 227 if ON_MAC: 228 228 children = ctrl.GetChildren() 229 229 if len(children) > 0: 230 children[0].SetBackgroundColour(color) 231 else: 232 ctrl.SetBackgroundColour(color) 230 children[0].SetBackgroundColour(color) 231 else: 232 ctrl.SetBackgroundColour(color) 233 233 self.name_sizer.Layout() 234 234 235 235 def on_number(self, event=None): 236 236 """ … … 254 254 else: 255 255 self._set_textctrl_color(self.numberctr, self.color) 256 256 257 257 self.put_text_pic(self.data2_pic, content=str(val)) 258 258 self.check_data_inputs() … … 261 261 self.draw_output(self.output) 262 262 self.Refresh() 263 263 264 264 def on_select_data1(self, event=None): 265 265 """ … … 272 272 if data == None: 273 273 content = "?" 274 self.put_text_pic(self.data1_pic, content) 274 self.put_text_pic(self.data1_pic, content) 275 275 else: 276 276 self.data1_pic.add_image(data) … … 279 279 self.output.name = str(self.data_namectr.GetValue()) 280 280 self.draw_output(self.output) 281 281 282 282 def on_select_operator(self, event=None): 283 283 """ … … 287 287 item = event.GetEventObject() 288 288 text = item.GetValue().strip() 289 self.put_text_pic(self.operator_pic, content=text) 289 self.put_text_pic(self.operator_pic, content=text) 290 290 self.check_data_inputs() 291 291 if self.output != None: 292 292 self.output.name = str(self.data_namectr.GetValue()) 293 293 self.draw_output(self.output) 294 294 295 295 def on_select_data2(self, event=None): 296 296 """ … … 300 300 item = event.GetEventObject() 301 301 text = item.GetValue().strip().lower() 302 self._show_numctrl(self.numberctr, text =='number')302 self._show_numctrl(self.numberctr, text == 'number') 303 303 pos = item.GetCurrentSelection() 304 304 data = item.GetClientData(pos) … … 310 310 else: 311 311 self.data2_pic.add_image(data) 312 self.check_data_inputs() 312 self.check_data_inputs() 313 313 else: 314 314 content = str(self.numberctr.GetValue().strip()) … … 323 323 if data != None: 324 324 self.check_data_inputs() 325 326 self.put_text_pic(self.data2_pic, content) 327 325 326 self.put_text_pic(self.data2_pic, content) 327 328 328 if self.output != None: 329 329 self.output.name = str(self.data_namectr.GetValue()) 330 330 self.draw_output(self.output) 331 332 def put_text_pic(self, pic=None, content=''): 331 332 def put_text_pic(self, pic=None, content=''): 333 333 """ 334 334 Put text to the pic 335 335 """ 336 pic.set_content(content) 336 pic.set_content(content) 337 337 pic.add_text() 338 338 pic.draw() 339 339 340 340 def check_data_inputs(self): 341 341 """ … … 352 352 pos2 = self.data2_cbox.GetCurrentSelection() 353 353 data2 = self.data2_cbox.GetClientData(pos2) 354 354 355 355 if data2 == None: 356 356 self.output = None … … 375 375 return flag 376 376 else: 377 self._set_textctrl_color(self.numberctr, self.color 377 self._set_textctrl_color(self.numberctr, self.color) 378 378 elif data1.__class__.__name__ != data2.__class__.__name__: 379 379 self._set_textctrl_color(self.data1_cbox, 'pink') … … 394 394 return flag 395 395 return True 396 396 397 397 def make_data_out(self, data1, data2): 398 398 """ … … 403 403 operator = self.operator_cbox.GetClientData(pos) 404 404 try: 405 exec "output = data1 %s data2" % operator405 exec "output = data1 %s data2" % operator 406 406 except: 407 407 raise 408 408 return output 409 410 409 410 411 411 def draw_output(self, output): 412 412 """ … … 416 416 if output == None: 417 417 content = "?" 418 self.put_text_pic(out, content) 418 self.put_text_pic(out, content) 419 419 else: 420 420 out.add_image(output) … … 422 422 self.Layout() 423 423 self.Refresh() 424 425 def _layout_button(self): 424 425 def _layout_button(self): 426 426 """ 427 427 Do the layout for the button widgets 428 """ 429 self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH /2, -1))428 """ 429 self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH / 2, -1)) 430 430 app_tip = "Generate the Data and send to Data Explorer." 431 431 self.bt_apply.SetToolTipString(app_tip) 432 432 self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) 433 433 434 434 self.bt_help = wx.Button(self, -1, "HELP") 435 435 app_tip = "Get help on Data Operations." 436 436 self.bt_help.SetToolTipString(app_tip) 437 437 self.bt_help.Bind(wx.EVT_BUTTON, self.on_help) 438 439 self.bt_close = wx.Button(self, -1, 'Close', size=(_BOX_WIDTH /2, -1))438 439 self.bt_close = wx.Button(self, -1, 'Close', size=(_BOX_WIDTH / 2, -1)) 440 440 self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 441 441 self.bt_close.SetToolTipString("Close this panel.") 442 443 self.button_sizer.AddMany([(PANEL_WIDTH /2, 25),442 443 self.button_sizer.AddMany([(PANEL_WIDTH / 2, 25), 444 444 (self.bt_apply, 0, wx.RIGHT, 10), 445 445 (self.bt_help, 0, wx.RIGHT, 10), 446 446 (self.bt_close, 0, wx.RIGHT, 10)]) 447 447 448 448 def _do_layout(self): 449 449 """ … … 453 453 self._layout_name() 454 454 self._layout_button() 455 self.main_sizer.AddMany([(self.name_sizer, 0, wx.EXPAND |wx.ALL, 10),455 self.main_sizer.AddMany([(self.name_sizer, 0, wx.EXPAND | wx.ALL, 10), 456 456 (self.button_sizer, 0, 457 wx.EXPAND |wx.TOP|wx.BOTTOM, 5)])457 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 458 458 self.SetSizer(self.main_sizer) 459 459 self.SetScrollbars(20, 20, 25, 65) 460 460 self.SetAutoLayout(True) 461 461 462 462 def set_panel_on_focus(self, event): 463 463 """ … … 474 474 if self.FindFocus() in children: 475 475 self.fill_data_combox() 476 476 477 477 def fill_oprator_combox(self): 478 478 """ 479 479 fill the current combobox with the operator 480 """ 480 """ 481 481 operator_list = [' +', ' -', ' *', " /", " |"] 482 482 for oper in operator_list: … … 484 484 self.operator_cbox.SetClientData(pos, str(oper.strip())) 485 485 self.operator_cbox.SetSelection(0) 486 487 486 487 488 488 def fill_data_combox(self): 489 489 """ … … 545 545 self.data2_cbox.SetClientData(pos2, data) 546 546 if str(current1) == str(name): 547 pos_pre1 = pos1 547 pos_pre1 = pos1 548 548 if str(current2) == str(name): 549 549 pos_pre2 = pos2 … … 561 561 pos_pre2 = posth2 562 562 except: 563 continue 563 continue 564 564 self.data1_cbox.SetSelection(pos_pre1) 565 565 self.data2_cbox.SetSelection(pos_pre2) 566 566 567 567 def get_datalist(self): 568 568 """ … … 573 573 else: 574 574 return {} 575 575 576 576 def on_click_apply(self, event): 577 """ 577 """ 578 578 changes are saved in data object imported to edit 579 579 """ … … 616 616 #must post event here 617 617 event.Skip() 618 619 def on_help(self, event): 618 619 def on_help(self, event): 620 620 """ 621 621 Bring up the Data Operations Panel Documentation whenever 622 the HELP button is clicked. 623 622 the HELP button is clicked. 623 624 624 Calls DocumentationWindow with the path of the location within the 625 documentation tree (after /doc/ ....". Note that when using old 626 versions of Wx (before 2.9) and thus not the release version of 627 installers, the help comes up at the top level of the file as 625 documentation tree (after /doc/ ....". Note that when using old 626 versions of Wx (before 2.9) and thus not the release version of 627 installers, the help comes up at the top level of the file as 628 628 webbrowser does not pass anything past the # to the browser when it is 629 629 running "file:///...." 630 630 631 631 :param evt: Triggers on clicking the help button 632 632 """ 633 633 634 634 _TreeLocation = "user/perspectives/calculator/data_operator_help.html" 635 635 _doc_viewer = DocumentationWindow(self, -1, \ 636 _TreeLocation, "Data Operation Help")636 _TreeLocation, "Data Operation Help") 637 637 638 638 def disconnect_panels(self): … … 644 644 self.operator_pic.connect.disconnect() 645 645 self.data2_pic.connect.disconnect() 646 646 647 647 def on_close(self, event): 648 648 """ … … 650 650 """ 651 651 self.parent.OnClose() 652 652 653 653 def set_plot_unfocus(self): 654 654 """ 655 655 Unfocus on right click 656 656 """ 657 657 658 658 def send_warnings(self, msg='', info='info'): 659 659 """ … … 661 661 """ 662 662 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info=info)) 663 663 664 664 class SmallPanel(PlotPanel): 665 665 """ 666 666 PlotPanel for Quick plot and masking plot 667 667 """ 668 def __init__(self, parent, id= -1, is_number=False, content='?', **kwargs):669 """ 670 """ 668 def __init__(self, parent, id= -1, is_number=False, content='?', **kwargs): 669 """ 670 """ 671 671 PlotPanel.__init__(self, parent, id=id, **kwargs) 672 672 self.is_number = is_number … … 682 682 self.add_text() 683 683 self.figure.subplots_adjust(left=0.1, bottom=0.1) 684 684 685 685 def set_content(self, content=''): 686 686 """ … … 688 688 """ 689 689 self.content = str(content) 690 690 691 691 def add_toolbar(self): 692 """ 692 """ 693 693 Add toolbar 694 694 """ 695 695 # Not implemented 696 696 pass 697 697 698 698 def on_set_focus(self, event): 699 699 """ … … 730 730 #draw 731 731 self.graph.render(self) 732 732 733 733 try: 734 734 self.figure.delaxes(self.figure.axes[1]) … … 738 738 self.subplot.tick_params(axis='both', labelsize=9) 739 739 # Draw zero axis lines 740 self.subplot.axhline(linewidth = 1, color='r')741 self.subplot.axvline(linewidth = 1, color='r')740 self.subplot.axhline(linewidth=1, color='r') 741 self.subplot.axvline(linewidth=1, color='r') 742 742 743 743 self.erase_legend() … … 774 774 self.subplot.set_xlim((0, 1)) 775 775 self.subplot.set_ylim((0, 1)) 776 776 777 777 try: 778 778 if self.content != '?': … … 788 788 new_text = self.subplot.text(str(xpos), str(ypos), str(label), 789 789 fontproperties=font) 790 self.textList.append(new_text) 791 790 self.textList.append(new_text) 791 792 792 def erase_legend(self): 793 793 """ … … 796 796 #for ax in self.axes: 797 797 self.remove_legend(self.subplot) 798 798 799 799 def onMouseMotion(self, event): 800 800 """ 801 801 Disable dragging 2D image 802 802 """ 803 803 804 804 def onWheel(self, event): 805 805 """ 806 806 """ 807 807 808 808 def onLeftDown(self, event): 809 809 """ 810 810 Disables LeftDown 811 811 """ 812 812 813 813 def onPick(self, event): 814 814 """ … … 817 817 for ax in self.axes: 818 818 self.remove_legend(ax) 819 820 819 820 821 821 def draw(self): 822 822 """ … … 827 827 else: 828 828 self.subplot.figure.canvas.resizing = False 829 self.subplot.tick_params(axis='both', labelsize=9) 829 self.subplot.tick_params(axis='both', labelsize=9) 830 830 self.erase_legend() 831 self.subplot.figure.canvas.draw_idle() 831 self.subplot.figure.canvas.draw_idle() 832 832 try: 833 833 self.figure.delaxes(self.figure.axes[1]) 834 834 except: 835 835 pass 836 837 836 837 838 838 def onContextMenu(self, event): 839 839 """ … … 848 848 else: 849 849 slicerpop.Append(id, '&Toggle Linear/Log Scale') 850 wx.EVT_MENU(self, id, self.ontogglescale) 850 wx.EVT_MENU(self, id, self.ontogglescale) 851 851 try: 852 852 # mouse event … … 858 858 pos = (pos_x, pos_y + 5) 859 859 self.PopupMenu(slicerpop, pos) 860 861 def ontogglescale(self, event): 860 861 def ontogglescale(self, event): 862 862 """ 863 863 On toggle 2d scale 864 864 """ 865 self._onToggleScale(event) 865 self._onToggleScale(event) 866 866 try: 867 867 # mpl >= 1.1.0 868 868 self.figure.tight_layout() 869 869 except: 870 self.figure.subplots_adjust(left=0.1, bottom=0.1) 870 self.figure.subplots_adjust(left=0.1, bottom=0.1) 871 871 try: 872 872 self.figure.delaxes(self.figure.axes[1]) 873 873 except: 874 874 pass 875 875 876 876 def _onProperties(self, event): 877 877 """ … … 909 909 self._onEVT_FUNC_PROPERTY() 910 910 dial.Destroy() 911 911 912 912 def _onEVT_FUNC_PROPERTY(self, remove_fit=True): 913 913 """ … … 954 954 self.set_yscale(_yscale) 955 955 self.draw() 956 956 957 957 class DataOperatorWindow(widget.CHILD_FRAME): 958 958 def __init__(self, parent, manager, *args, **kwds): … … 965 965 self.SetPosition((25, 10)) 966 966 self.Show() 967 968 def OnClose(self, event=None): 967 968 def OnClose(self, event=None): 969 969 """ 970 970 On close event … … 975 975 self.Destroy() 976 976 977 977 978 978 if __name__ == "__main__": 979 979 980 app 980 app = wx.App() 981 981 widget.CHILD_FRAME = wx.Frame 982 982 window = DataOperatorWindow(parent=None, data=[], title="Data Editor") 983 983 app.MainLoop() 984 984
Note: See TracChangeset
for help on using the changeset viewer.