source: sasview/calculatorview/src/sans/perspectives/calculator/data_operator.py @ 33c671e

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

trying to fix data operation panel problem on MAC

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