source: sasview/calculatorview/src/sans/perspectives/calculator/data_operator.py @ 79c8066

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 79c8066 was 79c8066, checked in by Jae Cho <jhjcho@…>, 12 years ago

updating combobox every time get it

  • Property mode set to 100644
File size: 26.2 KB
Line 
1"""
2GUI for the data operation
3"""
4import wx
5import sys
6import time
7import numpy
8from sans.dataloader.data_info import Data2D
9from sans.dataloader.data_info import Data1D
10from danse.common.plottools.PlotPanel import PlotPanel
11from danse.common.plottools.plottables import Graph
12from danse.common.plottools.canvas import FigureCanvas
13from matplotlib.font_manager import FontProperties
14from matplotlib.figure import Figure
15from sans.guiframe.events import StatusEvent
16       
17#Control panel width
18if sys.platform.count("win32") > 0:
19    PANEL_WIDTH = 780
20    PANEL_HEIGTH = 370
21    FONT_VARIANT = 0
22    _BOX_WIDTH = 200
23    ON_MAC = False
24else:
25    _BOX_WIDTH = 230
26    PANEL_WIDTH = 890
27    PANEL_HEIGTH = 470
28    FONT_VARIANT = 1
29    ON_MAC = True
30     
31class DataOperPanel(wx.ScrolledWindow):
32    """
33    :param data: when not empty the class can
34                same information into a data object
35        and post event containing the changed data object to some other frame
36    """
37    def __init__(self, parent, *args, **kwds):
38        kwds['name'] = "Data Operation"
39        kwds["size"] = (PANEL_WIDTH, PANEL_HEIGTH)
40        wx.ScrolledWindow.__init__(self, parent, *args, **kwds)
41        self.parent = parent
42        #sizers etc.
43        self.main_sizer = None
44        self.name_sizer = None
45        self.button_sizer = None
46        self.data_namectr = None
47        self.numberctr = None
48        self.data1_cbox = None
49        self.operator_cbox = None
50        self.data2_cbox = None
51        self.data_title_tcl = None
52        self.out_pic = None
53        self.equal_pic = None
54        self.data1_pic = None
55        self.operator_pic = None
56        self.data2_pic = None
57        self.output = None
58        self._notes = None
59        #data
60        self._data = self.get_datalist()
61        self._do_layout()
62        self.fill_data_combox()
63        self.fill_oprator_combox()
64        self.Bind(wx.EVT_PAINT, self.set_panel_on_focus)
65             
66    def _define_structure(self):
67        """
68        define initial sizer
69        """
70        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
71        title = "Data Operation "
72        title += "[ + (add); - (subtract); "
73        title += "* (multiply); / (divide); "
74        title += "| (append) ]"
75        name_box = wx.StaticBox(self, -1, title)
76        self.name_sizer = wx.StaticBoxSizer(name_box, wx.HORIZONTAL)
77        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)
78     
79    def _layout_name(self):
80        """
81        Do the layout for data name related widgets
82        """
83        new_data_sizer = wx.BoxSizer(wx.VERTICAL)
84        equal_sizer =  wx.BoxSizer(wx.VERTICAL)
85        old_data1_sizer = wx.BoxSizer(wx.VERTICAL)
86        operator_sizer = wx.BoxSizer(wx.VERTICAL)
87        old_data2_sizer = wx.BoxSizer(wx.VERTICAL)
88        data2_hori_sizer = wx.BoxSizer(wx.HORIZONTAL)
89        data_name = wx.StaticText(self, -1, 'Output Data Name') 
90        equal_name = wx.StaticText(self, -1, ' =',  size=(50, 23)) 
91        data1_name = wx.StaticText(self, -1, 'Data1')
92        operator_name = wx.StaticText(self, -1, 'Operator')
93        data2_name = wx.StaticText(self, -1, 'Data2 (or Number)')
94        self.data_namectr = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 25))
95        self.data_namectr.SetToolTipString("Hit 'Enter' key after typing.")
96        self.data_namectr.SetValue(str('MyNewDataName'))
97        self.numberctr = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, 25)) 
98        self.numberctr.SetToolTipString("Hit 'Enter' key after typing.")
99        self.numberctr.SetValue(str(1.0))
100        self.data1_cbox = wx.ComboBox(self, -1, size=(_BOX_WIDTH, 25), 
101                                      style=wx.CB_READONLY)
102        self.operator_cbox = wx.ComboBox(self, -1, size=(50, 25), 
103                                         style=wx.CB_READONLY)
104        operation_tip = "Add: +, Subtract: -, "
105        operation_tip += "Multiply: *, Divide: /, "
106        operation_tip += "Append(Combine): | "
107        self.operator_cbox.SetToolTipString(operation_tip)
108        self.data2_cbox = wx.ComboBox(self, -1, size=(_BOX_WIDTH*2/3, 25),
109                                       style=wx.CB_READONLY)
110
111        self.out_pic = SmallPanel(self, -1, True, size=(_BOX_WIDTH, _BOX_WIDTH), 
112                             style=wx.NO_BORDER)
113        self.equal_pic = SmallPanel(self, -1, True, '=',  size=(50, _BOX_WIDTH), 
114                              style=wx.NO_BORDER)
115        self.data1_pic = SmallPanel(self, -1, True, size=(_BOX_WIDTH, _BOX_WIDTH), 
116                             style=wx.NO_BORDER)
117        self.operator_pic = SmallPanel(self, -1, True, "+", size=(50, _BOX_WIDTH), 
118                             style=wx.NO_BORDER)
119        self.data2_pic = SmallPanel(self, -1, True, size=(_BOX_WIDTH, _BOX_WIDTH), 
120                             style=wx.NO_BORDER)
121        for ax in self.equal_pic.axes:
122            ax.set_frame_on(False)
123        for ax in self.operator_pic.axes:
124            ax.set_frame_on(False)
125
126        new_data_sizer.AddMany([(data_name, 0, wx.LEFT, 3),
127                                       (self.data_namectr, 0, wx.LEFT, 3),
128                                       (self.out_pic, 0, wx.LEFT, 3)])
129        equal_sizer.AddMany([(13, 15), (equal_name, 0, wx.LEFT, 3),
130                                       (self.equal_pic, 0, wx.LEFT, 3)])
131        old_data1_sizer.AddMany([(data1_name, 0, wx.LEFT, 3),
132                                       (self.data1_cbox, 0, wx.LEFT, 3),
133                                       (self.data1_pic, 0, wx.LEFT, 3)])
134        operator_sizer.AddMany([(operator_name, 0, wx.LEFT, 3),
135                                 (self.operator_cbox, 0, wx.LEFT, 3),
136                                 (self.operator_pic, 0, wx.LEFT, 3)])
137        data2_hori_sizer.AddMany([(self.data2_cbox, 0, wx.LEFT, 0),
138                                       (self.numberctr, 0, wx.LEFT, 0)])
139        old_data2_sizer.AddMany([(data2_name, 0, wx.LEFT, 3),
140                                       (data2_hori_sizer, 0, wx.LEFT, 3),
141                                       (self.data2_pic, 0, wx.LEFT, 3)])
142        self.name_sizer.AddMany([(new_data_sizer, 0, wx.LEFT|wx.TOP, 5),
143                                       (equal_sizer, 0, wx.TOP, 5),
144                                       (old_data1_sizer, 0, wx.TOP, 5),
145                                       (operator_sizer, 0, wx.TOP, 5),
146                                       (old_data2_sizer, 0, wx.TOP, 5)])
147        self.data2_cbox.Show(True)
148        self.numberctr.Hide()
149        wx.EVT_TEXT_ENTER(self.data_namectr, -1, self.on_name)
150        wx.EVT_TEXT_ENTER(self.numberctr, -1, self.on_number) 
151        wx.EVT_COMBOBOX(self.data1_cbox, -1, self.on_select_data1) 
152        wx.EVT_COMBOBOX(self.operator_cbox, -1, self.on_select_operator) 
153        wx.EVT_COMBOBOX(self.data2_cbox, -1, self.on_select_data2)
154       
155    def on_name(self, event=None):
156        """
157        On data name typing
158        """
159        item = event.GetEventObject()
160        item.SetBackgroundColour('white')
161        text = item.GetLabel().strip()
162        self._check_newname(text)
163   
164    def _check_newname(self, name=None):
165        """
166        Check name ctr strings
167        """
168        self.send_warnings('')
169        msg = ''
170        if name == None:
171            text = self.data_namectr.GetLabel().strip()
172        else:
173            text = name
174        state_list = self.get_datalist().values()
175        if text in [str(state.data.name) for state in state_list]:
176            self.data_namectr.SetBackgroundColour('pink')
177            msg = "DataOperation: The name already exists."
178        if len(text) == 0:
179            self.data_namectr.SetBackgroundColour('pink')
180            msg = "DataOperation: Type the data name first."
181        if self._notes:
182            self.send_warnings(msg, 'error')
183        self.name_sizer.Layout()
184        self.Refresh()
185               
186    def on_number(self, event=None):
187        """
188        On selecting Number for Data2
189        """
190        self.send_warnings('')
191        self.numberctr.SetBackgroundColour('white')
192        item = event.GetEventObject()
193        text = item.GetLabel().strip()
194        try:
195            val = float(text)
196            pos = self.data2_cbox.GetSelection()
197            self.data2_cbox.SetClientData(pos, val)
198        except:
199            self.numberctr.SetBackgroundColour('pink')
200            msg = "DataOperation: Number requires a float number."
201            self.send_warnings(msg, 'error')
202            return
203        self.put_text_pic(self.data2_pic, content=str(val)) 
204        self.check_data_inputs()
205        if self.output != None:
206            self.output.name = str(self.data_namectr.GetValue())
207        self.draw_output(self.output)
208       
209    def on_select_data1(self, event=None):
210        """
211        On select data1
212        """
213        self.send_warnings('')
214        item = event.GetEventObject()
215        pos = item.GetSelection()
216        data = item.GetClientData(pos)
217        if data == None:
218            content = "?"
219            self.put_text_pic(self.data1_pic, content) 
220        else:
221            self.data1_pic.add_image(data)
222        self.check_data_inputs()
223        if self.output != None:
224            self.output.name = str(self.data_namectr.GetValue())
225        self.draw_output(self.output)
226       
227    def on_select_operator(self, event=None):
228        """
229        On Select an Operator
230        """
231        self.send_warnings('')
232        item = event.GetEventObject()
233        text = item.GetLabel().strip()
234        self.put_text_pic(self.operator_pic, content=text) 
235        self.check_data_inputs()
236        if self.output != None:
237            self.output.name = str(self.data_namectr.GetValue())
238        self.draw_output(self.output)
239       
240    def on_select_data2(self, event=None):
241        """
242        On Selecting Data2
243        """
244        self.send_warnings('')
245        item = event.GetEventObject()
246        text = item.GetLabel().strip().lower()
247        self.numberctr.Show(text=='number')
248        pos = item.GetSelection()
249        data = item.GetClientData(pos)
250        if not self.numberctr.IsShown():
251            if data == None:
252                content = "?"
253                self.put_text_pic(self.data2_pic, content) 
254            else:
255                self.data2_pic.add_image(data)
256        else:
257            if data == None:
258                content = str(self.numberctr.GetValue().strip())
259                try:
260                    content = float(content)
261                    data = content
262                except:
263                    content = "?"
264                    data = None
265                item.SetClientData(pos, content)
266            self.put_text_pic(self.data2_pic, content)   
267        self.check_data_inputs()
268
269        if self.output != None:
270            self.output.name = str(self.data_namectr.GetValue())
271        self.draw_output(self.output)
272   
273    def put_text_pic(self, pic=None, content=''): 
274        """
275        Put text to the pic
276        """
277        pic.set_content(content) 
278        pic.add_text()
279        pic.draw()
280                 
281    def check_data_inputs(self):
282        """
283        Check data1 and data2 whether or not they are ready for operation
284        """
285        self.data1_cbox.SetBackgroundColour('white')
286        self.data2_cbox.SetBackgroundColour('white')
287        flag = False
288        pos1 = self.data1_cbox.GetCurrentSelection()
289        data1 = self.data1_cbox.GetClientData(pos1)
290        if data1 == None:
291            self.output = None
292            return flag
293        pos2 = self.data2_cbox.GetCurrentSelection()
294        data2 = self.data2_cbox.GetClientData(pos2)
295        if data2 == None:
296            self.output = None
297            return flag
298        if self.numberctr.IsShown():
299            self.numberctr.SetBackgroundColour('white')
300            try:
301                float(data2)
302                if self.operator_cbox.GetLabel().strip() == '|':
303                    msg = "DataOperation: This operation can not accept "
304                    msg += "a float number."
305                    self.send_warnings(msg, 'error')
306                    self.numberctr.SetBackgroundColour('pink')
307                    self.output = None
308                    return flag
309            except:
310                msg = "DataOperation: Number requires a float number."
311                self.send_warnings(msg, 'error')
312                self.numberctr.SetBackgroundColour('pink')
313                self.output = None
314                return flag
315        elif data1.__class__.__name__ != data2.__class__.__name__:
316            self.data1_cbox.SetBackgroundColour('pink')
317            self.data2_cbox.SetBackgroundColour('pink')
318            msg = "DataOperation: Data types must be same."
319            self.send_warnings(msg, 'error')
320            self.output = None
321            return flag
322        try:
323            self.output = self.make_data_out(data1, data2)
324        except:
325            self._check_newname()
326            self.data1_cbox.SetBackgroundColour('pink')
327            self.data2_cbox.SetBackgroundColour('pink')
328            msg = "DataOperation: Data types must be same."
329            self.send_warnings(msg, 'error')
330            self.output = None
331            return flag
332        return True
333   
334    def make_data_out(self, data1, data2):
335        """
336        Make a temp. data output set
337        """
338        output = None
339        pos = self.operator_cbox.GetCurrentSelection()
340        operator = self.operator_cbox.GetClientData(pos)
341        exec "output = data1 %s data2"% operator
342        return output
343   
344   
345    def draw_output(self, output):
346        """
347        Draw output data(temp)
348        """
349        out = self.out_pic
350        if output == None:
351            content = "?"
352            self.put_text_pic(out, content) 
353        else:
354            out.add_image(output)
355        self.name_sizer.Layout()
356        self.Refresh()
357                   
358    def _layout_button(self): 
359        """
360            Do the layout for the button widgets
361        """ 
362        self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH/2, -1))
363        app_tip = "Generate the Data and send to Data Explorer."
364        self.bt_apply.SetToolTipString(app_tip)
365        self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply)
366       
367        self.bt_close = wx.Button(self, -1, 'Close', size=(_BOX_WIDTH/2, -1))
368        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close)
369        self.bt_close.SetToolTipString("Close this panel.")
370       
371        self.button_sizer.AddMany([(PANEL_WIDTH/2, 25),
372                                   (self.bt_apply, 0, wx.RIGHT, 10),
373                                   (self.bt_close, 0, wx.RIGHT, 10)])
374       
375    def _do_layout(self):
376        """
377        Draw the current panel
378        """
379        self._define_structure()
380        self._layout_name()
381        self._layout_button()
382        self.main_sizer.AddMany([(self.name_sizer, 0, wx.EXPAND|wx.ALL, 10),
383                                (self.button_sizer, 0,
384                                          wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
385        self.SetSizer(self.main_sizer)
386        self.SetScrollbars(20, 20, 25, 65)
387        self.SetAutoLayout(True)
388   
389    def set_panel_on_focus(self, event):
390        """
391        On Focus at this window
392        """
393        if event != None:
394            event.Skip()
395        self._data = self.get_datalist()
396        children = self.GetChildren()
397        # update the list only when it is on the top
398        if self.FindFocus() in children:
399            self.fill_data_combox()
400         
401    def fill_oprator_combox(self):
402        """
403        fill the current combobox with the operator
404        """   
405        operator_list = [' +', ' -', ' *', " /", " |"]
406        for oper in operator_list:
407            pos = self.operator_cbox.Append(str(oper))
408            self.operator_cbox.SetClientData(pos, str(oper.strip()))
409        self.operator_cbox.SetSelection(0)
410       
411       
412    def fill_data_combox(self):
413        """
414        fill the current combobox with the available data
415        """
416        pos_pre1 = self.data1_cbox.GetCurrentSelection()
417        pos_pre2 = self.data2_cbox.GetCurrentSelection()
418        current1 = self.data1_cbox.GetLabel()
419        current2 = self.data2_cbox.GetLabel()
420        if pos_pre1 < 0:
421            pos_pre1 = 0
422        if pos_pre2 < 0:
423            pos_pre2 = 0
424        self.data1_cbox.Clear()
425        self.data2_cbox.Clear()
426        if not self._data:
427            pos = self.data1_cbox.Append('No Data Available')
428            self.data1_cbox.SetSelection(pos)
429            self.data1_cbox.SetClientData(pos, None)
430            pos2 = self.data2_cbox.Append('No Data Available')
431            self.data2_cbox.SetSelection(pos2)
432            self.data2_cbox.SetClientData(pos2, None)
433            pos3 = self.data2_cbox.Append("Number")
434            val = None
435            if self.numberctr.IsShown():
436                try:
437                    val = float(self.numberctr.GetLabel())
438                except:
439                    val = None
440            self.data2_cbox.SetClientData(pos3, val)
441            return
442        pos1 = self.data1_cbox.Append('Select Data')
443        self.data1_cbox.SetSelection(pos1)
444        self.data1_cbox.SetClientData(pos1, None)
445        pos2 = self.data2_cbox.Append('Select Data')
446        self.data2_cbox.SetSelection(pos2)
447        self.data2_cbox.SetClientData(pos2, None)
448        pos3 = self.data2_cbox.Append("Number")
449        val = None
450        if self.numberctr.IsShown():
451            try:
452                val = float(self.numberctr.GetLabel())
453            except:
454                val = None
455        self.data2_cbox.SetClientData(pos3, val)
456        dnames = []
457        for dstate in self._data.values():
458            if dstate != None:
459                if dstate.data != None:
460                    dnames.append(dstate.data.name)
461        if len(dnames) > 0:
462            ind = numpy.argsort(dnames)
463            for datastate in numpy.array(self._data.values())[ind]:
464                data = datastate.data
465                if data != None:
466                    name = data.name
467                    pos1 = self.data1_cbox.Append(str(name))
468                    self.data1_cbox.SetClientData(pos1, data)
469                    pos2 = self.data2_cbox.Append(str(name))
470                    self.data2_cbox.SetClientData(pos2, data)
471                    if str(current1) == str(name):
472                      pos_pre1 = pos1
473                    if str(current2) == str(name):
474                      pos_pre2 = pos2
475                try:
476                    theory_list = datastate.get_theory()
477                    for theory, _ in theory_list.values():
478                        th_name = theory.name
479                        posth1 = self.data1_cbox.Append(str(th_name))
480                        self.data1_cbox.SetClientData(posth1, theory)
481                        posth2 = self.data2_cbox.Append(str(th_name))
482                        self.data2_cbox.SetClientData(posth2, theory)
483                        if str(current1) == str(th_name):
484                            pos_pre1 = posth1
485                        if str(current2) == str(th_name):
486                            pos_pre2 = posth2
487                except:
488                    continue 
489        self.data1_cbox.SetSelection(pos_pre1)
490        self.data2_cbox.SetSelection(pos_pre2)
491   
492    def get_datalist(self):
493        """
494        """
495        data_manager = self.parent.parent.get_data_manager()
496        if data_manager != None:
497            return  data_manager.get_all_data()
498        else:
499            return {}
500           
501    def on_click_apply(self, event):
502        """   
503        changes are saved in data object imported to edit
504        """
505        self.send_warnings('')
506        self.data_namectr.SetBackgroundColour('white')
507        state_list = self.get_datalist().values()
508        name = self.data_namectr.GetLabel().strip()
509        if name in [str(state.data.name) for state in state_list]:
510            self.data_namectr.SetBackgroundColour('pink')
511            msg = "The Output Data Name already exists...   "
512            wx.MessageBox(msg, 'Error')
513            return
514        if name == '':
515            self.data_namectr.SetBackgroundColour('pink')
516            msg = "Please type the output data name first...   "
517            wx.MessageBox(msg, 'Error')
518            return
519        if self.output == None:
520            msg = "No Output Data has been generated...   "
521            wx.MessageBox(msg, 'Error')
522            return
523        # send data to data manager
524        self.output.name = name
525        self.output.run = "Data Operation"
526        self.output.instrument = "SansView"
527        self.output.id = str(name) + str(time.time())
528        data = {self.output.id :self.output}
529        self.parent.parent.add_data(data)
530        self.name_sizer.Layout()
531        self.Refresh()
532        #must post event here
533        event.Skip()
534   
535    def on_close(self, event):
536        """
537        leave data as it is and close
538        """
539        self.parent.OnClose()
540       
541    def set_plot_unfocus(self):
542        """
543        Unfocus on right click
544        """
545   
546    def send_warnings(self, msg='', info='info'):
547        """
548        Send warning to status bar
549        """
550        wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info=info))
551         
552class SmallPanel(PlotPanel):
553    """
554    PlotPanel for Quick plot and masking plot
555    """
556    def __init__(self, parent, id=-1, is_number=False, content='?', **kwargs):
557        """
558        """ 
559        PlotPanel.__init__(self, parent, id=id, **kwargs)
560        self.is_number = is_number
561        self.content = content
562        self.position = (0.4, 0.5)
563        self.scale = 'linear'
564        self.subplot.set_xticks([])
565        self.subplot.set_yticks([])
566        self.add_text()
567        self.figure.subplots_adjust(left=0.1, bottom=0.1)
568       
569    def set_content(self, content=''):
570        """
571        Set text content
572        """
573        self.content = str(content)
574         
575    def add_toolbar(self):
576        """
577        Add toolbar
578        """
579        # Not implemented
580        pass
581   
582    def on_set_focus(self, event):
583        """
584        send to the parenet the current panel on focus
585        """
586        pass
587
588    def add_image(self, plot):
589        """
590        Add Image
591        """
592        self.content = ''
593        self.textList = []
594        self.plots = {}
595        self.clear()
596        try:
597            self.figure.delaxes(self.figure.axes[0])
598            self.subplot = self.figure.add_subplot(111)
599            #self.figure.delaxes(self.figure.axes[1])
600        except:
601            pass
602        try:
603            name = plot.name
604        except:
605            name = plot.filename
606        self.plots[name] = plot
607
608        #init graph
609        self.graph = Graph()
610
611        #add plot
612        self.graph.add(plot)
613        #draw       
614        self.graph.render(self)
615       
616        try:
617            self.figure.delaxes(self.figure.axes[1])
618        except:
619            pass
620        self.subplot.figure.canvas.resizing = False
621        self.subplot.set_xticks([])
622        self.subplot.set_yticks([])
623        # Draw zero axis lines
624        self.subplot.axhline(linewidth = 1, color='r') 
625        self.subplot.axvline(linewidth = 1, color='r')       
626
627        self.erase_legend()
628        self.figure.tight_layout()
629        #self.figure.subplots_adjust(left=0.1, bottom=0.1)
630
631        self.subplot.figure.canvas.draw()
632
633    def add_text(self):
634        """
635        Text in the plot
636        """
637        if not self.is_number:
638            return
639
640        self.clear()
641        try:
642            self.figure.delaxes(self.figure.axes[0])
643            self.subplot = self.figure.add_subplot(111)
644            self.figure.delaxes(self.figure.axes[1])
645        except:
646            pass
647        self.subplot.set_xticks([])
648        self.subplot.set_yticks([])
649        label = self.content
650        FONT = FontProperties()
651        xpos, ypos = (0.4, 0.5)
652        font = FONT.copy()
653        font.set_size(14)
654
655        self.textList = []
656        self.subplot.set_xlim((0, 1))
657        self.subplot.set_ylim((0, 1))
658       
659        try:
660            if self.content != '?':
661                float(label)
662        except:
663            self.subplot.set_frame_on(False)
664        self.figure.tight_layout()
665        #self.figure.subplots_adjust(left=0.1, bottom=0.1)
666        if len(label) > 0 and xpos > 0 and ypos > 0:
667            new_text = self.subplot.text(str(xpos), str(ypos), str(label),
668                                           fontproperties=font)
669            self.textList.append(new_text) 
670       
671    def erase_legend(self):
672        """
673        Remove Legend
674        """
675        #for ax in self.axes:
676        self.remove_legend(self.subplot)
677                     
678    def onMouseMotion(self, event):
679        """
680        Disable dragging 2D image
681        """
682   
683    def onWheel(self, event):
684        """
685        """
686     
687    def onLeftDown(self, event):
688        """
689        Disables LeftDown
690        """
691   
692    def onPick(self, event):
693        """
694        Remove Legend
695        """
696        for ax in self.axes:
697            self.remove_legend(ax)
698                       
699   
700    def draw(self):
701        """
702        Draw
703        """
704        if self.dimension == 3:
705            pass
706        else:
707            self.subplot.figure.canvas.draw_idle() 
708       
709    def onContextMenu(self, event):
710        """
711        Default context menu for a plot panel
712        """
713               
714class DataOperatorWindow(wx.Frame):
715    def __init__(self, parent, *args, **kwds):
716        kwds["size"] = (PANEL_WIDTH, PANEL_HEIGTH)
717        wx.Frame.__init__(self, parent, *args, **kwds)
718        self.parent = parent
719        self.panel = DataOperPanel(parent=self)
720        wx.EVT_CLOSE(self, self.OnClose)
721        self.CenterOnParent()
722        self.Show()
723   
724    def OnClose(self, event=None): 
725        """
726        On close event
727        """
728        self.Show(False)
729
730       
731if __name__ == "__main__":
732   
733    app  = wx.App()
734    window = DataOperatorWindow(parent=None, data=[], title="Data Editor")
735    app.MainLoop()
736 
Note: See TracBrowser for help on using the repository browser.