source: sasview/calculatorview/src/sans/perspectives/calculator/data_operator.py @ 19b9e43

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 19b9e43 was 19b9e43, checked in by Jae Cho <jhjcho@…>, 12 years ago

trying to fix mac sum panel problem

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