Changeset 3477478 in sasview


Ignore:
Timestamp:
Mar 5, 2015 12:38:29 PM (9 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
b9dbd6b
Parents:
2df0b74
Message:

pylint fixes

Location:
src/sas/plottools
Files:
1 added
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • src/sas/plottools/PlotPanel.py

    r121f72c r3477478  
    4040        for a in obj.get_children(): show_tree(a, d + 1) 
    4141 
    42 from unitConverter import UnitConvertion as convertUnit 
     42from convert_units import convert_unit 
    4343 
    4444 
     
    17901790            if self.xLabel == "x^(2)": 
    17911791                item.transformX(transform.toX2, transform.errToX2) 
    1792                 xunits = convertUnit(2, xunits) 
     1792                xunits = convert_unit(2, xunits) 
    17931793                self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 
    17941794            if self.xLabel == "x^(4)": 
    17951795                item.transformX(transform.toX4, transform.errToX4) 
    1796                 xunits = convertUnit(4, xunits) 
     1796                xunits = convert_unit(4, xunits) 
    17971797                self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 
    17981798            if self.xLabel == "ln(x)": 
     
    18051805            if self.xLabel == "log10(x^(4))": 
    18061806                item.transformX(transform.toX4, transform.errToX4) 
    1807                 xunits = convertUnit(4, xunits) 
     1807                xunits = convert_unit(4, xunits) 
    18081808                self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 
    18091809                _xscale = 'log' 
     
    18201820            if self.yLabel == "y^(2)": 
    18211821                item.transformY(transform.toX2, transform.errToX2) 
    1822                 yunits = convertUnit(2, yunits) 
     1822                yunits = convert_unit(2, yunits) 
    18231823                self.graph._yaxis_transformed("%s^{2}" % yname, "%s" % yunits) 
    18241824            if self.yLabel == "1/y": 
    18251825                item.transformY(transform.toOneOverX, transform.errOneOverX) 
    1826                 yunits = convertUnit(-1, yunits) 
     1826                yunits = convert_unit(-1, yunits) 
    18271827                self.graph._yaxis_transformed("1/%s" % yname, "%s" % yunits) 
    18281828            if self.yLabel == "y*x^(4)": 
    18291829                item.transformY(transform.toYX4, transform.errToYX4) 
    1830                 xunits = convertUnit(4, self.xaxis_unit) 
     1830                xunits = convert_unit(4, self.xaxis_unit) 
    18311831                self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 
    18321832                                              "%s%s" % (yunits, xunits)) 
     
    18341834                item.transformY(transform.toOneOverSqrtX, 
    18351835                                transform.errOneOverSqrtX) 
    1836                 yunits = convertUnit(-0.5, yunits) 
     1836                yunits = convert_unit(-0.5, yunits) 
    18371837                self.graph._yaxis_transformed("1/\sqrt{%s}" % yname, 
    18381838                                              "%s" % yunits) 
     
    18431843            if self.yLabel == "ln(y*x^(2))": 
    18441844                item.transformY(transform.toLogYX2, transform.errToLogYX2) 
    1845                 xunits = convertUnit(2, self.xaxis_unit) 
     1845                xunits = convert_unit(2, self.xaxis_unit) 
    18461846                self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname), 
    18471847                                              "%s%s" % (yunits, xunits)) 
    18481848            if self.yLabel == "ln(y*x^(4))": 
    18491849                item.transformY(transform.toLogYX4, transform.errToLogYX4) 
    1850                 xunits = convertUnit(4, self.xaxis_unit) 
     1850                xunits = convert_unit(4, self.xaxis_unit) 
    18511851                self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname), 
    18521852                                              "%s%s" % (yunits, xunits)) 
    18531853            if self.yLabel == "log10(y*x^(4))": 
    18541854                item.transformY(transform.toYX4, transform.errToYX4) 
    1855                 xunits = convertUnit(4, self.xaxis_unit) 
     1855                xunits = convert_unit(4, self.xaxis_unit) 
    18561856                _yscale = 'log' 
    18571857                self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 
     
    18591859            if self.viewModel == "Guinier lny vs x^(2)": 
    18601860                item.transformX(transform.toX2, transform.errToX2) 
    1861                 xunits = convertUnit(2, xunits) 
     1861                xunits = convert_unit(2, xunits) 
    18621862                self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 
    18631863                item.transformY(transform.toLogX, transform.errToLogX) 
     
    18651865            if self.viewModel == "Porod y*x^(4) vs x^(4)": 
    18661866                item.transformX(transform.toX4, transform.errToX4) 
    1867                 xunits = convertUnit(4, self.xaxis_unit) 
     1867                xunits = convert_unit(4, self.xaxis_unit) 
    18681868                self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 
    18691869                item.transformY(transform.toYX4, transform.errToYX4) 
  • src/sas/plottools/PropertyDialog.py

    r79492222 r3477478  
    88    def __init__(self, parent, id=-1, title="Select the scale of the graph"): 
    99        wx.Dialog.__init__(self, parent, id, title) 
    10         """ 
    11         for the properties window 
    12         """ 
    1310        self.parent = parent 
    1411        vbox = wx.BoxSizer(wx.VERTICAL) 
    15         sizer = wx.GridBagSizer(5,5) 
     12        sizer = wx.GridBagSizer(5, 5) 
    1613 
    1714        x_size = 70 
     
    2825        self.xvalue = wx.ComboBox(self, -1) 
    2926        x_size += self.xvalue.GetSize()[0] 
    30         sizer.Add(self.xvalue, (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    31          
     27        sizer.Add(self.xvalue, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     28 
    3229        ix += 2 
    3330        self.yvalue = wx.ComboBox(self, -1) 
    3431        x_size += self.yvalue.GetSize()[0] 
    35         sizer.Add(self.yvalue, (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    36          
     32        sizer.Add(self.yvalue, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     33 
    3734        ix += 2 
    3835        self.view = wx.ComboBox(self, -1) 
    3936        x_size += self.view.GetSize()[0] 
    4037        self.view.SetMinSize((160, 30)) 
    41         sizer.Add(self.view, (iy,ix), (1,1), 
    42                   wx.EXPAND|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
     38        sizer.Add(self.view, (iy, ix), (1, 1), 
     39                  wx.EXPAND | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
    4340        self.SetMinSize((x_size, 50)) 
    44         vbox.Add(sizer, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    45         
    46         btCancel = wx.Button(self, wx.ID_CANCEL,'Cancel') 
    47         btOk = wx.Button(self, wx.ID_OK, "OK") 
     41        vbox.Add(sizer, 0, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     42 
     43        cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel') 
     44        ok_button = wx.Button(self, wx.ID_OK, "OK") 
    4845        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    49         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    50         sizer_button.Add(btOk, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    51         sizer_button.Add(btCancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
     46        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     47        sizer_button.Add(ok_button, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     48        sizer_button.Add(cancel_button, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
    5249        vbox.Add(sizer_button, 0, 
    53                  wx.EXPAND|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 10) 
     50                 wx.EXPAND | wx.TOP | wx.BOTTOM | wx.ADJUST_MINSIZE, 10) 
    5451        # scale value for x 
    5552        self.xvalue.SetValue("ln(x)") 
     
    6057        self.xvalue.Insert("log10(x)", 4) 
    6158        self.xvalue.Insert("log10(x^(4))", 5) 
    62          
     59 
    6360        # scale value for y 
    6461        self.yvalue.SetValue("ln(y)") 
     
    8178        self.view.Insert("XS Guinier ln(y*x) vs x^(2)", 3) 
    8279        self.view.Insert("Porod y*x^(4) vs x^(4)", 4) 
    83         self.view.Insert("Kratky y*x^(2) vs x",5)         
     80        self.view.Insert("Kratky y*x^(2) vs x", 5) 
    8481        self.SetSizer(vbox) 
    8582        self.Fit() 
    8683        self.Centre() 
    87             
     84 
    8885    def setValues(self, x, y, view): 
    8986        """ 
    9087        """ 
    91         return  self.xvalue.SetValue(x), self.yvalue.SetValue(y),\ 
     88        return  self.xvalue.SetValue(x), self.yvalue.SetValue(y), \ 
    9289                    self.view.SetValue(view) 
    93          
     90 
    9491    def getValues(self): 
    9592        """ 
    9693        """ 
    97         return self.xvalue.GetValue(), self.yvalue.GetValue(),\ 
     94        return self.xvalue.GetValue(), self.yvalue.GetValue(), \ 
    9895                            self.view.GetValue() 
  • src/sas/plottools/SimpleFont.py

    r79492222 r3477478  
    2020 
    2121class SimpleFont(wx.Dialog): 
    22     def __init__(self,parent,id,title): 
     22    def __init__(self, parent, id, title): 
    2323 
    24         wx.Dialog.__init__(self,parent,id,title,size=(440,160)) 
     24        wx.Dialog.__init__(self, parent, id, title, size=(440, 160)) 
    2525        self.parent = parent 
    2626#        self.SetWindowVariant(variant=FONT_VARIANT) 
     
    3535        self.Centre() 
    3636        self.Show() 
    37          
     37 
    3838    def InitUI(self): 
    39         vbox = wx.BoxSizer(wx.VERTICAL) 
    40         hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
    41         hbox2 = wx.BoxSizer(wx.HORIZONTAL) 
    42         hbox3 = wx.BoxSizer(wx.HORIZONTAL) 
     39        self.font_family = wx.ComboBox(self, pos=(80, 10), style=wx.CB_READONLY, size=(100, -1)) 
     40        self.font_style = wx.ComboBox(self, pos=(80, 60), style=wx.CB_READONLY, size=(100, -1)) 
     41        self.font_point = wx.ComboBox(self, pos=(300, 10), style=wx.CB_READONLY, size=(100, -1)) 
     42        self.font_weight = wx.ComboBox(self, pos=(300, 60), style=wx.CB_READONLY, size=(100, -1)) 
     43        self.tick_label_check = wx.CheckBox(self, -1, label='', pos=(80, 100), size=(15, -1)) 
     44        self.tick_label_check.SetValue(False) 
     45        wx.Button(self, wx.ID_OK, 'OK', pos=(215, 100)) 
     46        wx.Button(self, wx.ID_CANCEL, 'Cancel', pos=(315, 100)) 
    4347 
    44         gs = wx.GridSizer(2,4,-1,-1) 
    45  
    46         self.fontFamily = wx.ComboBox(self,pos=(80,10),style=wx.CB_READONLY, 
    47                                       size=(100,-1)) 
    48         self.fontStyle = wx.ComboBox(self,pos=(80,60),style=wx.CB_READONLY, 
    49                                      size=(100,-1)) 
    50  
    51         self.fontPoint = wx.ComboBox(self,pos=(300,10),style=wx.CB_READONLY, 
    52                                      size=(100,-1)) 
    53         self.fontWeight = wx.ComboBox(self,pos=(300,60), 
    54                                       style=wx.CB_READONLY,size=(100,-1)) 
    55         self.tick_label_check = wx.CheckBox(self, -1, label='', pos=(80, 100),  
    56                                                                                 size=(15, -1)) 
    57         self.tick_label_check.SetValue(False) 
    58         self.okButton = wx.Button(self,wx.ID_OK,'OK',pos=(215,100)) 
    59         self.closeButton = wx.Button(self,wx.ID_CANCEL,'Cancel',pos=(315,100)) 
    60          
    6148        self._set_family_list() 
    6249        self._set_style_list() 
    6350        self._set_weight_list() 
    6451        self._set_point_list() 
    65          
    66         familyText = wx.StaticText(self, label='Family:', pos=(10,12)) 
    67         sizeText = wx.StaticText(self, label='Size:',pos=(220,12)) 
    68         styleText = wx.StaticText(self, label='Style:',pos=(10,62)) 
    69         weightText = wx.StaticText(self, label='Weight:',pos=(220,62)) 
    70         tick_label_text = wx.StaticText(self,label='Tick label?', pos=(10, 100)) 
     52 
     53        wx.StaticText(self, label='Family:', pos=(10, 12)) 
     54        wx.StaticText(self, label='Size:', pos=(220, 12)) 
     55        wx.StaticText(self, label='Style:', pos=(10, 62)) 
     56        wx.StaticText(self, label='Weight:', pos=(220, 62)) 
     57        tick_label_text = wx.StaticText(self, label='Tick label?', pos=(10, 100)) 
    7158        tick_label_text.SetToolTipString("Apply to tick label too.") 
    72                  
     59 
    7360    def _set_family_list(self): 
    7461        # list of font family 
    75         list = FAMILY 
    76         for idx in range(len(list)): 
    77             self.fontFamily.Append(list[idx],idx) 
     62        for idx in range(len(FAMILY)): 
     63            self.font_family.Append(FAMILY[idx], idx) 
    7864 
    7965    def _set_style_list(self): 
    8066        # list of styles 
    81         list = STYLE 
    82         for idx in range(len(list)): 
    83             self.fontStyle.Append(list[idx],idx) 
     67        for idx in range(len(STYLE)): 
     68            self.font_style.Append(STYLE[idx], idx) 
    8469 
    8570    def _set_weight_list(self): 
    86         #list of weights 
    87         list = WEIGHT 
    88         for idx in range(len(list)): 
    89             self.fontWeight.Append(list[idx],idx) 
     71        # list of weights 
     72        for idx in range(len(WEIGHT)): 
     73            self.font_weight.Append(WEIGHT[idx], idx) 
    9074 
    9175    def _set_point_list(self): 
    9276        # list of point sizes 
    93         list = SIZE 
    94         for idx in range(len(list)): 
    95             self.fontPoint.Append(str(list[idx]),idx) 
     77        for idx in range(len(SIZE)): 
     78            self.font_point.Append(str(SIZE[idx]), idx) 
    9679 
    9780    def get_ticklabel_check(self): 
     
    10891        self.tick_label_check.SetValue(check) 
    10992 
    110     def set_default_font(self,font): 
    111          
     93    def set_default_font(self, font): 
     94 
    11295        if not font: 
    113             self.fontFamily.SetSelection(1) 
    114             self.fontWeight.SetSelection(1) 
    115             self.fontPoint.SetSelection(3) 
    116             self.fontStyle.SetSelection(0) 
     96            self.font_family.SetSelection(1) 
     97            self.font_weight.SetSelection(1) 
     98            self.font_point.SetSelection(3) 
     99            self.font_style.SetSelection(0) 
    117100        else: 
    118                 self.fontWeight.SetStringSelection(str(font.get_weight())) 
    119                 self.fontPoint.SetStringSelection(str(int(font.get_size()))) 
    120                 self.fontFamily.SetStringSelection(str(font.get_family()[0])) 
    121                 self.fontStyle.SetStringSelection(str(font.get_style())) 
    122                  
     101            self.font_weight.SetStringSelection(str(font.get_weight())) 
     102            self.font_point.SetStringSelection(str(int(font.get_size()))) 
     103            self.font_family.SetStringSelection(str(font.get_family()[0])) 
     104            self.font_style.SetStringSelection(str(font.get_style())) 
     105 
    123106    def get_font(self): 
    124         FONT = FontProperties() 
    125         font = FONT.copy() 
    126         font.set_size(str(self.fontPoint.GetValue())) 
    127         font.set_name(str(self.fontFamily.GetValue())) 
    128         font.set_slant(str(self.fontStyle.GetValue())) 
    129         font.set_weight(str(self.fontWeight.GetValue())) 
     107        font_properties = FontProperties() 
     108        font = font_properties.copy() 
     109        font.set_size(str(self.font_point.GetValue())) 
     110        font.set_name(str(self.font_family.GetValue())) 
     111        font.set_slant(str(self.font_style.GetValue())) 
     112        font.set_weight(str(self.font_weight.GetValue())) 
    130113 
    131114        return font 
  • src/sas/plottools/SizeDialog.py

    r79492222 r3477478  
    1111        hbox = wx.BoxSizer(wx.HORIZONTAL) 
    1212        text1 = "Enter in a custom size (> 0 accepted)" 
    13         msg = wx.StaticText(self, -1, text1, (30,15), style=wx.ALIGN_CENTRE) 
     13        msg = wx.StaticText(self, -1, text1, (30, 15), style=wx.ALIGN_CENTRE) 
    1414        msg.SetLabel(text1) 
    15         self.myTxtCtrl = wx.TextCtrl(self, -1, '', (100, 50)) 
    16          
    17         textbox.Add(self.myTxtCtrl, flag=wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 
    18                  border=10) 
     15        self.text_ctrl = wx.TextCtrl(self, -1, '', (100, 50)) 
     16 
     17        textbox.Add(self.text_ctrl, flag=wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, border=10) 
    1918        vbox.Add(msg, flag=wx.ALL, border=10, proportion=1) 
    20         vbox.Add(textbox, flag=wx.EXPAND|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 
    21                  border=10) 
    22         self.myTxtCtrl.SetValue(str(5)) 
    23          
    24         okButton = wx.Button(self, wx.ID_OK, 'OK', size=(70, 25)) 
    25         closeButton = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25)) 
     19        vbox.Add(textbox, flag=wx.EXPAND | wx.TOP | wx.BOTTOM | wx.ADJUST_MINSIZE, border=10) 
     20        self.text_ctrl.SetValue(str(5)) 
    2621 
    27         hbox.Add(okButton) 
     22        ok_button = wx.Button(self, wx.ID_OK, 'OK', size=(70, 25)) 
     23        close_button = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25)) 
     24 
     25        hbox.Add(ok_button) 
    2826        hbox.Add((20, 20)) 
    29         hbox.Add(closeButton) 
    30          
     27        hbox.Add(close_button) 
     28 
    3129        mainbox.Add(vbox, flag=wx.ALL, border=10) 
    32         mainbox.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5) 
    33         mainbox.Add(hbox, flag=wx.CENTER, 
    34                     border=10) 
     30        mainbox.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 5) 
     31        mainbox.Add(hbox, flag=wx.CENTER, border=10) 
    3532        self.SetSizer(mainbox) 
    36      
     33 
    3734    def getText(self): 
    3835        """ 
    3936        Get text typed 
    4037        """ 
    41         return self.myTxtCtrl.GetValue() 
     38        return self.text_ctrl.GetValue() 
  • src/sas/plottools/TextDialog.py

    r79492222 r3477478  
    2222        wx.Dialog.__init__(self, parent, id, title, size=(PNL_WIDTH, 280)) 
    2323        self.parent = parent 
    24         #Font 
     24        # Font 
    2525        self.SetWindowVariant(variant=FONT_VARIANT) 
    2626        # default 
     
    3131        self.color = COLOR[0] 
    3232        self.tick_label = False 
    33         #Dialog interface 
    34         vbox  = wx.BoxSizer(wx.VERTICAL) 
     33        # Dialog interface 
     34        vbox = wx.BoxSizer(wx.VERTICAL) 
    3535        text_box = wx.BoxSizer(wx.HORIZONTAL) 
    3636        sizer = wx.GridBagSizer(1, 3) 
    3737        _BOX_WIDTH = 60 
    38         font_size = 12 
    39         font_description= wx.StaticBox(self, -1, 'Font', 
    40                                        size=(PNL_WIDTH-20, 70)) 
     38        font_description = wx.StaticBox(self, -1, 'Font', size=(PNL_WIDTH - 20, 70)) 
    4139        font_box = wx.StaticBoxSizer(font_description, wx.VERTICAL) 
    4240        family_box = wx.BoxSizer(wx.HORIZONTAL) 
    4341        style_box = wx.BoxSizer(wx.HORIZONTAL) 
    44         #tcA 
     42        # tcA 
    4543        if unit != None: 
    4644            styles = wx.TAB_TRAVERSAL 
     
    5351            tick_label_text = wx.StaticText(self, -1, 'Tick label') 
    5452            tick_label_text.SetToolTipString("Apply to tick label too.") 
    55             self.tick_label_check = wx.CheckBox(self, -1,  
    56                                                 '', (10, 10)) 
     53            self.tick_label_check = wx.CheckBox(self, -1, '', (10, 10)) 
    5754            self.tick_label_check.SetValue(False) 
    5855            self.tick_label_check.SetToolTipString("Apply to tick label too.") 
    59             wx.EVT_CHECKBOX(self, self.tick_label_check.GetId(),  
     56            wx.EVT_CHECKBOX(self, self.tick_label_check.GetId(), 
    6057                            self.on_tick_label) 
    6158            enter_text = 'Enter text:' 
    6259        else: 
    63             styles = wx.TAB_TRAVERSAL|wx.TE_MULTILINE|wx.TE_LINEWRAP|\ 
    64                               wx.TE_PROCESS_ENTER|wx.SUNKEN_BORDER|wx.HSCROLL 
     60            styles = wx.TAB_TRAVERSAL | wx.TE_MULTILINE | wx.TE_LINEWRAP | \ 
     61                              wx.TE_PROCESS_ENTER | wx.SUNKEN_BORDER | wx.HSCROLL 
    6562            height = 60 
    6663            unit_text = None 
     
    7471            else: 
    7572                enter_text += ":" 
    76         self.textString = wx.TextCtrl(self, -1, size=(PNL_WIDTH-30, height ),\ 
    77                                                         style=styles) 
    78         self.textString.SetValue(str(label)) 
    79         self.textString.SetToolTipString("The text that will be displayed.") 
    80         #font family 
    81         self.fontFamily = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    82         wx.EVT_COMBOBOX(self.fontFamily, -1, self.on_family) 
    83         self.fontFamily.SetMinSize((_BOX_WIDTH, -1)) 
     73        self.text_string = wx.TextCtrl(self, -1, size=(PNL_WIDTH - 30, height), style=styles) 
     74        self.text_string.SetValue(str(label)) 
     75        self.text_string.SetToolTipString("The text that will be displayed.") 
     76        # font family 
     77        self.font_family = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     78        wx.EVT_COMBOBOX(self.font_family, -1, self.on_family) 
     79        self.font_family.SetMinSize((_BOX_WIDTH, -1)) 
    8480        self._set_family_list() 
    85         self.fontFamily.SetSelection(1) 
    86         self.fontFamily.SetToolTipString("Font family of the text.") 
    87         #font weight 
    88         self.fontWeight = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    89         wx.EVT_COMBOBOX(self.fontWeight, -1, self.on_weight) 
    90         self.fontWeight.SetMinSize((_BOX_WIDTH, -1)) 
     81        self.font_family.SetSelection(1) 
     82        self.font_family.SetToolTipString("Font family of the text.") 
     83        # font weight 
     84        self.font_weight = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     85        wx.EVT_COMBOBOX(self.font_weight, -1, self.on_weight) 
     86        self.font_weight.SetMinSize((_BOX_WIDTH, -1)) 
    9187        self._set_weight_list() 
    92         self.fontWeight.SetSelection(1) 
    93         self.fontWeight.SetToolTipString("Font weight of the text.") 
    94         #font family 
    95         self.fontSize = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    96         wx.EVT_COMBOBOX(self.fontSize, -1, self.on_size) 
    97         self.fontSize.SetMinSize((_BOX_WIDTH, -1)) 
     88        self.font_weight.SetSelection(1) 
     89        self.font_weight.SetToolTipString("Font weight of the text.") 
     90        # font family 
     91        self.font_size = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     92        wx.EVT_COMBOBOX(self.font_size, -1, self.on_size) 
     93        self.font_size.SetMinSize((_BOX_WIDTH, -1)) 
    9894        self._set_size_list() 
    99         self.fontSize.SetSelection(5) 
    100         self.fontSize.SetToolTipString("Font size of the text.") 
    101         #font style 
    102         self.fontStyle = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    103         wx.EVT_COMBOBOX(self.fontStyle, -1, self.on_style) 
    104         self.fontStyle.SetMinSize((_BOX_WIDTH, -1)) 
     95        self.font_size.SetSelection(5) 
     96        self.font_size.SetToolTipString("Font size of the text.") 
     97        # font style 
     98        self.font_style = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     99        wx.EVT_COMBOBOX(self.font_style, -1, self.on_style) 
     100        self.font_style.SetMinSize((_BOX_WIDTH, -1)) 
    105101        self._set_style_list() 
    106         self.fontStyle.SetSelection(0) 
    107         self.fontStyle.SetToolTipString("Font style of the text.") 
    108         #font color 
    109         self.fontColor = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    110         wx.EVT_COMBOBOX(self.fontColor, -1, self.on_color) 
    111         self.fontColor.SetMinSize((_BOX_WIDTH, -1)) 
     102        self.font_style.SetSelection(0) 
     103        self.font_style.SetToolTipString("Font style of the text.") 
     104        # font color 
     105        self.font_color = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     106        wx.EVT_COMBOBOX(self.font_color, -1, self.on_color) 
     107        self.font_color.SetMinSize((_BOX_WIDTH, -1)) 
    112108        self._set_color_list() 
    113         self.fontColor.SetSelection(0) 
    114         self.fontColor.SetToolTipString("Font color of the text.") 
     109        self.font_color.SetSelection(0) 
     110        self.font_color.SetToolTipString("Font color of the text.") 
    115111        # Buttons on the bottom 
    116112        self.static_line_1 = wx.StaticLine(self, -1) 
    117         self.okButton = wx.Button(self,wx.ID_OK, 'OK', size=(_BOX_WIDTH, 25)) 
    118         self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', 
    119                                      size=(_BOX_WIDTH, 25)) 
    120          
     113        self.ok_button = wx.Button(self, wx.ID_OK, 'OK', size=(_BOX_WIDTH, 25)) 
     114        self.close_button = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(_BOX_WIDTH, 25)) 
     115 
    121116        # Intro 
    122117        explanation = "Select font properties :" 
     
    125120        iy = 1 
    126121        sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 
    127                  (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     122                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    128123        family_box.Add(wx.StaticText(self, -1, 'Family :'), -1, 0) 
    129         family_box.Add(self.fontFamily, -1, 0) 
    130         family_box.Add((_BOX_WIDTH/2,-1)) 
     124        family_box.Add(self.font_family, -1, 0) 
     125        family_box.Add((_BOX_WIDTH / 2, -1)) 
    131126        family_box.Add(wx.StaticText(self, -1, 'Size :'), -1, 0) 
    132         family_box.Add(self.fontSize, -1, 0) 
     127        family_box.Add(self.font_size, -1, 0) 
    133128        if unit_box != None: 
    134             family_box.Add((_BOX_WIDTH/2, -1)) 
     129            family_box.Add((_BOX_WIDTH / 2, -1)) 
    135130            family_box.Add(tick_label_text, -1, 0) 
    136131            family_box.Add(self.tick_label_check, -1, 0) 
    137132        style_box.Add(wx.StaticText(self, -1, 'Style :'), -1, 0) 
    138         style_box.Add(self.fontStyle, -1, 0) 
    139         style_box.Add((_BOX_WIDTH/2,-1)) 
     133        style_box.Add(self.font_style, -1, 0) 
     134        style_box.Add((_BOX_WIDTH / 2, -1)) 
    140135        style_box.Add(wx.StaticText(self, -1, 'Weight :'), -1, 0) 
    141         style_box.Add(self.fontWeight, -1, 0) 
    142         style_box.Add((_BOX_WIDTH/2,-1)) 
     136        style_box.Add(self.font_weight, -1, 0) 
     137        style_box.Add((_BOX_WIDTH / 2, -1)) 
    143138        style_box.Add(wx.StaticText(self, -1, 'Color :'), -1, 0) 
    144         style_box.Add(self.fontColor, -1, 0) 
     139        style_box.Add(self.font_color, -1, 0) 
    145140        font_box.Add(family_box, -1, 10) 
    146141        font_box.Add(style_box, -1, 10) 
     
    148143        ix = 0 
    149144        sizer.Add(font_box, (iy, ix), 
    150                   (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     145                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    151146        iy += 2 
    152147        ix = 0 
    153148        sizer.Add(wx.StaticText(self, -1, enter_text), (iy, ix), 
    154                  (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     149                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    155150        text_box.Add((15, 10)) 
    156         text_box.Add(self.textString) 
     151        text_box.Add(self.text_string) 
    157152        vbox.Add(text_box, 0, wx.EXPAND, 15) 
    158153        if unit_box != None: 
    159154            unit_box.Add(unit_text, -1, 0) 
    160155            unit_box.Add(self.unit_ctrl, -1, 0) 
    161             vbox.Add((5,5)) 
    162             vbox.Add(unit_box, 0,wx.LEFT, 15) 
    163          
     156            vbox.Add((5, 5)) 
     157            vbox.Add(unit_box, 0, wx.LEFT, 15) 
     158 
    164159        vbox.Add((10, 10)) 
    165160        vbox.Add(self.static_line_1, 0, wx.EXPAND, 10) 
    166161        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    167         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    168         sizer_button.Add(self.okButton, 0,  
    169                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    170         sizer_button.Add(self.closeButton, 0, 
    171                           wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    172         vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
     162        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     163        sizer_button.Add(self.ok_button, 0, 
     164                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     165        sizer_button.Add(self.close_button, 0, 
     166                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     167        vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
    173168        self.SetSizer(vbox) 
    174169        self.Centre() 
    175          
     170 
    176171    def _set_family_list(self): 
    177172        """ 
     
    179174        """ 
    180175        # list of family choices 
    181         list = FAMILY 
    182         for idx in range(len(list)): 
    183             self.fontFamily.Append(list[idx], idx) 
    184                   
     176        for idx in range(len(FAMILY)): 
     177            self.font_family.Append(FAMILY[idx], idx) 
     178 
    185179    def _set_size_list(self): 
    186180        """ 
     
    188182        """ 
    189183        # list of size choices 
    190         list = SIZE 
    191         for idx in range(len(list)): 
    192             self.fontSize.Append(str(list[idx]),idx)    
    193                   
     184        for idx in range(len(SIZE)): 
     185            self.font_size.Append(str(SIZE[idx]), idx) 
     186 
    194187    def _set_weight_list(self): 
    195188        """ 
     
    197190        """ 
    198191        # list of weight choices 
    199         list = WEIGHT 
    200         for idx in range(len(list)): 
    201             self.fontWeight.Append(list[idx], idx) 
    202              
     192        for idx in range(len(WEIGHT)): 
     193            self.font_weight.Append(WEIGHT[idx], idx) 
     194 
    203195    def _set_style_list(self): 
    204196        """ 
     
    206198        """ 
    207199        # list of style choices 
    208         list = STYLE 
    209         for idx in range(len(list)): 
    210             self.fontStyle.Append(list[idx], idx) 
    211              
     200        for idx in range(len(STYLE)): 
     201            self.font_style.Append(STYLE[idx], idx) 
     202 
    212203    def _set_color_list(self): 
    213204        """ 
     
    215206        """ 
    216207        # list of tyle choices 
    217         list = COLOR 
    218         for idx in range(len(list)): 
    219             self.fontColor.Append(list[idx], idx) 
    220              
     208        for idx in range(len(COLOR)): 
     209            self.font_color.Append(COLOR[idx], idx) 
     210 
    221211    def on_tick_label(self, event): 
    222212        """ 
     
    225215        event.Skip() 
    226216        self.tick_label = self.tick_label_check.GetValue() 
    227                     
     217 
    228218    def on_family(self, event): 
    229219        """ 
     
    231221        """ 
    232222        event.Skip() 
    233         self.family = self.fontFamily.GetValue() 
    234                   
     223        self.family = self.font_family.GetValue() 
     224 
    235225    def on_style(self, event): 
    236226        """ 
     
    238228        """ 
    239229        event.Skip() 
    240         self.style = self.fontStyle.GetValue() 
    241              
     230        self.style = self.font_style.GetValue() 
     231 
    242232    def on_weight(self, event): 
    243233        """ 
     
    245235        """ 
    246236        event.Skip() 
    247         self.weight = self.fontWeight.GetValue() 
    248      
     237        self.weight = self.font_weight.GetValue() 
     238 
    249239    def on_size(self, event): 
    250240        """ 
     
    252242        """ 
    253243        event.Skip() 
    254         self.size = self.fontSize.GetValue() 
    255      
     244        self.size = self.font_size.GetValue() 
     245 
    256246    def on_color(self, event): 
    257247        """ 
     
    259249        """ 
    260250        event.Skip() 
    261         self.color = self.fontColor.GetValue() 
    262             
     251        self.color = self.font_color.GetValue() 
     252 
    263253    def getText(self): 
    264254        """ 
    265255        Returns text string as input by user. 
    266256        """ 
    267         return self.textString.GetValue() 
    268      
     257        return self.text_string.GetValue() 
     258 
    269259    def getUnit(self): 
    270260        """ 
     
    272262        """ 
    273263        return self.unit_ctrl.GetValue() 
    274          
    275     def getX(self):   
    276         """ 
    277         Returns x coordinate of text box 
    278         """ 
    279         return float(self.xString.GetValue()) 
    280          
    281     def getY(self): 
    282         """ 
    283         Returns y coordinate of text box 
    284         """ 
    285         return float(self.yString.GetValue()) 
    286      
     264 
    287265    def getFamily(self): 
    288266        """ 
     
    290268        """ 
    291269        return str(self.family) 
    292      
     270 
    293271    def getStyle(self): 
    294272        """ 
     
    302280        """ 
    303281        return str(self.weight) 
    304            
     282 
    305283    def getSize(self): 
    306284        """ 
     
    308286        """ 
    309287        return int(self.size) 
    310      
     288 
    311289    def getColor(self): 
    312290        """ 
     
    314292        """ 
    315293        return str(self.color) 
    316      
     294 
    317295    def getTickLabel(self): 
    318296        """ 
  • src/sas/plottools/plottable_interactor.py

    r79492222 r3477478  
    22    This module allows more interaction with the plot 
    33""" 
    4 import plottables 
    54from BaseInteractor import _BaseInteractor 
    65 
     
    2625        self._dragged = False 
    2726        self.connect_markers([self.axes]) 
    28          
     27 
    2928    def _color(self, c): 
    3029        """Return a particular colour""" 
    3130        return self.colorlist[c % len(self.colorlist)] 
    32      
     31 
    3332    def _symbol(self, s): 
    3433        """Return a particular symbol""" 
    3534        return self.symbollist[s % len(self.symbollist)] 
    3635 
    37     def points(self, x, y, dx=None, dy=None, color=0, symbol=0, zorder=1,  
     36    def points(self, x, y, dx=None, dy=None, color=0, symbol=0, zorder=1, 
    3837               markersize=5, label=None, hide_error=False): 
    3938        """ 
    4039        """ 
    41         #Draw curve 
     40        # Draw curve 
    4241        if self._symbol(symbol) == '-' or self._symbol(symbol) == '--': 
    4342            l_width = markersize * 0.4 
    44             return self.curve(x=x, y=y, color=color, symbol=symbol,  
     43            return self.curve(x=x, y=y, color=color, symbol=symbol, 
    4544                              label=label, width=l_width) 
    46             #return 
     45            # return 
    4746        if self._symbol(symbol) == 'vline': 
    4847            l_width = markersize * 0.4 
    49             return self.vline(x=x, y=y, color=color,  
    50                                 label=label, width=l_width) 
     48            return self.vline(x=x, y=y, color=color, label=label, width=l_width) 
    5149        if self._symbol(symbol) == 'step': 
    5250            l_width = markersize * 0.4 
    53             return self.step(x=x, y=y, color=color,  
    54                                 label=label, width=l_width) 
     51            return self.step(x=x, y=y, color=color, label=label, width=l_width) 
    5552        if not self.marker == None: 
    5653            self.base.connect.clear([self.marker]) 
     
    6057        # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 
    6158        if dx != None and type(dx) == type(()): 
    62             dx = nx.vstack((x-dx[0], dx[1]-x)).transpose() 
     59            dx = nx.vstack((x - dx[0], dx[1] - x)).transpose() 
    6360        if dy != None and type(dy) == type(()): 
    64             dy = nx.vstack((y-dy[0], dy[1]-y)).transpose() 
    65          
     61            dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 
     62 
    6663        if dx == None and dy == None: 
    67             #zorder = 1 
     64            # zorder = 1 
    6865            self.marker = self.axes.plot(x, y, color=self.color, 
    6966                                         marker=self._symbol(symbol), 
     
    7269                                         zorder=zorder)[0] 
    7370        else: 
    74              
     71 
    7572            if hide_error: 
    76                 #zorder = 1 
     73                # zorder = 1 
    7774                self.marker = self.axes.plot(x, y, color=self.color, 
    7875                                             marker=self._symbol(symbol), 
     
    8178                                             zorder=1)[0] 
    8279            else: 
    83                 #zorder = 2 
     80                # zorder = 2 
    8481                self.marker = self.axes.errorbar(x, y, yerr=dy, 
    8582                                                 xerr=None, 
     
    9592                                                 label=label, 
    9693                                                 zorder=1)[0] 
    97              
    98         self.connect_markers([self.marker]) 
    99         self.update() 
    100          
    101     def curve(self, x, y, dy=None, color=0, symbol=0, zorder=10,  
     94 
     95        self.connect_markers([self.marker]) 
     96        self.update() 
     97 
     98    def curve(self, x, y, dy=None, color=0, symbol=0, zorder=10, 
    10299              label=None, width=2.0): 
    103100        """ 
     
    109106                                     marker='', linestyle=self._symbol(symbol), 
    110107                                     label=label, zorder=zorder)[0] 
    111              
    112         self.connect_markers([self.marker]) 
    113         self.update() 
    114  
    115          
    116     def vline(self, x, y, dy=None, color=0, symbol=0, zorder=1,  
     108 
     109        self.connect_markers([self.marker]) 
     110        self.update() 
     111 
     112 
     113    def vline(self, x, y, dy=None, color=0, symbol=0, zorder=1, 
    117114              label=None, width=2.0): 
    118115        """ 
     
    124121            y_min = 0.0 
    125122        else: 
    126             y_min = min(y)*9/10 
    127         self.marker = self.axes.vlines(x=x, ymin=y_min, ymax=y,  
    128                                       color=self.color,  
    129                                       linestyle='-', label=label, 
    130                                       lw=width, zorder=zorder)     
     123            y_min = min(y) * 9 / 10 
     124        self.marker = self.axes.vlines(x=x, ymin=y_min, ymax=y, 
     125                                       color=self.color, 
     126                                       linestyle='-', label=label, 
     127                                       lw=width, zorder=zorder) 
    131128        self.connect_markers([self.marker]) 
    132129        self.update() 
    133130 
    134131    def step(self, x, y, dy=None, color=0, symbol=0, zorder=1, 
    135               label=None, width=2.0): 
    136         """ 
    137         """ 
    138         if not self.marker == None: 
    139             self.base.connect.clear([self.marker]) 
    140         self.color = self._color(color) 
    141         if self.markersize != None: 
    142             markersize = self.markersize 
    143              
     132             label=None, width=2.0): 
     133        """ 
     134        """ 
     135        if not self.marker == None: 
     136            self.base.connect.clear([self.marker]) 
     137        self.color = self._color(color) 
    144138        self.marker = self.axes.step(x, y, color=self.color, 
    145                                          marker='', 
    146                                          linestyle='-', label=label, 
    147                                          lw=width, zorder=zorder)[0] 
    148         self.connect_markers([self.marker]) 
    149         self.update() 
    150                 
     139                                     marker='', 
     140                                     linestyle='-', label=label, 
     141                                     lw=width, zorder=zorder)[0] 
     142        self.connect_markers([self.marker]) 
     143        self.update() 
     144 
    151145    def connect_markers(self, markers): 
    152146        """ 
     
    163157    def clear(self): 
    164158        print "plottable_interactor.clear()" 
    165          
     159 
    166160    def _on_click(self, evt): 
    167161        """ 
     
    183177        if evt.button == 3: 
    184178            self._context_menu = True 
    185          
     179 
    186180    def _on_enter(self, evt): 
    187181        """ 
     
    191185        if not evt.artist.__class__.__name__ == "AxesSubplot": 
    192186            self.base.plottable_selected(self.id) 
    193              
     187 
    194188            if evt.artist.get_color() == 'y': 
    195189                try: 
     
    212206 
    213207            self.axes.figure.canvas.draw_idle() 
    214          
     208 
    215209    def _on_leave(self, evt): 
    216210        """ 
     
    230224                    evt.artist.set_edgecolor(self.color) 
    231225                self.axes.figure.canvas.draw_idle() 
    232      
     226 
    233227    def update(self): 
    234228        """ 
  • src/sas/plottools/plottables.py

    r79492222 r3477478  
    4545import numpy 
    4646import sys 
    47  
     47import logging 
    4848 
    4949if 'any' not in dir(__builtins__): 
     
    5353                return True 
    5454        return False 
    55      
     55 
    5656    def all(L): 
    5757        for cond in L: 
     
    6161 
    6262 
    63 class Graph: 
     63class Graph(object): 
    6464    """ 
    6565    Generic plottables graph structure. 
    66      
     66 
    6767    Plot styles are based on color/symbol lists.  The user gets to select 
    6868    the list of colors/symbols/sizes to choose from, not the application 
     
    7777    the plottable objects themselves will need to provide the transformations. 
    7878    Here are some examples from reflectometry: :: 
    79      
     79 
    8080       independent: x -> f(x) 
    8181          monitor scaling: y -> M*y 
     
    9191          spin asymmetry: x -> x1, y -> (y1 - y2)/(y1 + y2) 
    9292          vector net: x -> x1, y -> y1*cos(y2*pi/180) 
    93            
     93 
    9494    Multiple transformations are possible, such as Q4 spin asymmetry 
    9595 
     
    122122    Graphs need to be printable.  A page layout program for entire plots 
    123123    would be nice. 
    124      
     124 
    125125    """ 
    126126    def _xaxis_transformed(self, name, units): 
     
    134134        self.prop["xlabel"] = name 
    135135        self.prop["xunit"] = units 
    136          
     136 
    137137    def _yaxis_transformed(self, name, units): 
    138138        """ 
     
    145145        self.prop["ylabel"] = name 
    146146        self.prop["yunit"] = units 
    147          
     147 
    148148    def xaxis(self, name, units): 
    149149        """ 
     
    167167        self.prop["ylabel_base"] = name 
    168168        self.prop["yunit_base"] = units 
    169          
     169 
    170170    def title(self, name): 
    171171        """ 
     
    173173        """ 
    174174        self.prop["title"] = name 
    175          
     175 
    176176    def get(self, key): 
    177177        """ 
     
    216216        """Detect if any graphed plottables have changed""" 
    217217        return any([p.changed() for p in self.plottables]) 
    218      
     218 
    219219    def get_range(self): 
    220220        """ 
    221221        Return the range of all displayed plottables 
    222222        """ 
    223         min = None 
    224         max = None 
     223        min_value = None 
     224        max_value = None 
    225225        for p in self.plottables: 
    226226            if p.hidden == True: 
     
    228228            if not p.x == None: 
    229229                for x_i in p.x: 
    230                     if min == None or x_i < min: 
    231                         min = x_i 
    232                     if max == None or x_i > max: 
    233                         max = x_i 
    234         return min, max 
    235      
     230                    if min_value == None or x_i < min_value: 
     231                        min_value = x_i 
     232                    if max_value == None or x_i > max_value: 
     233                        max_value = x_i 
     234        return min_value, max_value 
     235 
    236236    def replace(self, plottable): 
    237237        """Replace an existing plottable from the graph""" 
     
    252252            del self.plottables[plottable] 
    253253            self.color = len(self.plottables) 
    254              
     254 
    255255    def reset_scale(self): 
    256256        """ 
     
    268268                     "title": ""} 
    269269        self.plottables = {} 
    270      
     270 
    271271    def _make_labels(self): 
    272272        """ 
     
    284284            labels.update(c.labels(sets[c])) 
    285285        return labels 
    286      
     286 
    287287    def get_plottable(self, name): 
    288288        """ 
     
    294294                return item 
    295295        return None 
    296      
     296 
    297297    def returnPlottable(self): 
    298298        """ 
     
    302302        """ 
    303303        return self.plottables 
    304      
    305     def render(self,plot): 
     304 
     305    def render(self, plot): 
    306306        """Redraw the graph""" 
    307307        plot.connect.clearall() 
     
    312312            if p.custom_color is not None: 
    313313                p.render(plot, color=p.custom_color, symbol=0, 
    314                 markersize=p.markersize, label=labels[p]) 
     314                         markersize=p.markersize, label=labels[p]) 
    315315            else: 
    316316                p.render(plot, color=self.plottables[p], symbol=0, 
    317                      markersize=p.markersize, label=labels[p]) 
     317                         markersize=p.markersize, label=labels[p]) 
    318318        plot.render() 
    319     
     319 
    320320    def __init__(self, **kw): 
    321321        self.reset() 
     
    328328# No need to inherit from this class, just need to provide 
    329329# the same methods. 
    330 class Transform: 
     330class Transform(object): 
    331331    """ 
    332332    Define a transform plugin to the plottable architecture. 
    333      
     333 
    334334    Transforms operate on axes.  The plottable defines the 
    335335    set of transforms available for it, and the axes on which 
    336336    they operate.  These transforms can operate on the x axis 
    337337    only, the y axis only or on the x and y axes together. 
    338      
     338 
    339339    This infrastructure is not able to support transformations 
    340340    such as log and polar plots as these require full control 
    341341    over the drawing of axes and grids. 
    342      
     342 
    343343    A transform has a number of attributes. 
    344      
     344 
    345345    name 
    346346      user visible name for the transform.  This will 
    347347      appear in the context menu for the axis and the transform 
    348348      menu for the graph. 
    349          
     349 
    350350    type 
    351351      operational axis.  This determines whether the 
     
    353353      menus, or if it should appear in the context menu for 
    354354      the graph. 
    355          
     355 
    356356    inventory 
    357       (not implemented)  
     357      (not implemented) 
    358358      a dictionary of user settable parameter names and 
    359359      their associated types.  These should appear as keyword 
    360360      arguments to the transform call.  For example, Fresnel 
    361361      reflectivity requires the substrate density: 
    362       ``{ 'rho': type.Value(10e-6/units.angstrom**2) }``        
     362      ``{ 'rho': type.Value(10e-6/units.angstrom**2) }`` 
    363363      Supply reasonable defaults in the callback so that 
    364364      limited plotting clients work even though they cannot 
    365365      set the inventory. 
    366          
     366 
    367367    """ 
    368368    def __call__(self, plottable, **kwargs): 
     
    375375        plottable should store the underlying data but set 
    376376        the standard x,dx,y,dy,z,dz attributes appropriately. 
    377          
     377 
    378378        If the call raises a NotImplemented error the dataline 
    379379        will not be plotted.  The associated string will usually 
     
    381381        The application may or may not display the message to the 
    382382        user, along with an indication of which plottable was at fault. 
    383          
     383 
    384384        """ 
    385385        raise NotImplemented, "Not a valid transform" 
     
    428428    name = None 
    429429    # Data 
    430     x  = None 
    431     y  = None 
     430    x = None 
     431    y = None 
    432432    dx = None 
    433433    dy = None 
     
    438438    custom_color = None 
    439439    markersize = 5  # default marker size is 'size 5' 
    440      
     440 
    441441    def __init__(self): 
    442442        self.view = View() 
     
    445445        self._yaxis = "" 
    446446        self._yunit = "" 
    447          
     447 
    448448    def __setattr__(self, name, value): 
    449449        """ 
     
    454454        if name in ['x', 'y', 'dx', 'dy']: 
    455455            self.reset_view() 
    456             #print "self.%s has been called" % name 
     456            # print "self.%s has been called" % name 
    457457 
    458458    def set_data(self, x, y, dx=None, dy=None): 
     
    464464        self.dx = dx 
    465465        self.transformView() 
    466      
     466 
    467467    def xaxis(self, name, units): 
    468468        """ 
    469469        Set the name and unit of x_axis 
    470          
     470 
    471471        :param name: the name of x-axis 
    472472        :param units: the units of x_axis 
    473          
     473 
    474474        """ 
    475475        self._xaxis = name 
     
    479479        """ 
    480480        Set the name and unit of y_axis 
    481          
     481 
    482482        :param name: the name of y-axis 
    483483        :param units: the units of y_axis 
    484          
     484 
    485485        """ 
    486486        self._yaxis = name 
    487487        self._yunit = units 
    488          
     488 
    489489    def get_xaxis(self): 
    490490        """Return the units and name of x-axis""" 
    491491        return self._xaxis, self._xunit 
    492      
     492 
    493493    def get_yaxis(self): 
    494494        """ Return the units and name of y- axis""" 
     
    500500        Construct a set of unique labels for a collection of plottables of 
    501501        the same type. 
    502          
     502 
    503503        Returns a map from plottable to name. 
    504          
     504 
    505505        """ 
    506506        n = len(collection) 
    507         map = {} 
     507        label_dict = {} 
    508508        if n > 0: 
    509509            basename = str(cls).split('.')[-1] 
    510510            if n == 1: 
    511                 map[collection[0]] = basename 
     511                label_dict[collection[0]] = basename 
    512512            else: 
    513513                for i in xrange(len(collection)): 
    514                     map[collection[i]] = "%s %d" % (basename, i) 
    515         return map 
    516  
    517     ##Use the following if @classmethod doesn't work 
     514                    label_dict[collection[i]] = "%s %d" % (basename, i) 
     515        return label_dict 
     516 
     517    # #Use the following if @classmethod doesn't work 
    518518    # labels = classmethod(labels) 
    519519    def setLabel(self, labelx, labely): 
    520520        """ 
    521521        It takes a label of the x and y transformation and set View parameters 
    522          
     522 
    523523        :param transx: The label of x transformation is sent by Properties Dialog 
    524524        :param transy: The label of y transformation is sent Properties Dialog 
    525          
     525 
    526526        """ 
    527527        self.view.xLabel = labelx 
    528528        self.view.yLabel = labely 
    529      
     529 
    530530    def set_View(self, x, y): 
    531531        """Load View""" 
     
    533533        self.y = y 
    534534        self.reset_view() 
    535          
     535 
    536536    def reset_view(self): 
    537537        """Reload view with new value to plot""" 
     
    541541        self.view.DXreel = self.view.dx 
    542542        self.view.DYreel = self.view.dy 
    543          
     543 
    544544    def render(self, plot): 
    545545        """ 
    546546        The base class makes sure the correct units are being used for 
    547547        subsequent plottable. 
    548          
     548 
    549549        For now it is assumed that the graphs are commensurate, and if you 
    550         put a Qx object on a Temperature graph then you had better hope  
     550        put a Qx object on a Temperature graph then you had better hope 
    551551        that it makes sense. 
    552          
     552 
    553553        """ 
    554554        plot.xaxis(self._xaxis, self._xunit) 
    555555        plot.yaxis(self._yaxis, self._yunit) 
    556          
     556 
    557557    def is_empty(self): 
    558558        """ 
     
    563563            return True 
    564564        return False 
    565          
     565 
    566566    def colors(self): 
    567567        """Return the number of colors need to render the object""" 
    568568        return 1 
    569      
     569 
    570570    def transformView(self): 
    571571        """ 
     
    573573        """ 
    574574        self.view.transform(self.x, self.y, self.dx, self.dy) 
    575          
     575 
    576576    def returnValuesOfView(self): 
    577577        """ 
     
    579579        """ 
    580580        return self.view.returnXview() 
    581      
     581 
    582582    def check_data_PlottableX(self): 
    583583        """ 
     
    586586        """ 
    587587        self.view.check_data_logX() 
    588          
     588 
    589589    def check_data_PlottableY(self): 
    590590        """ 
    591         Since no transformation is made for log10(y), check that  
     591        Since no transformation is made for log10(y), check that 
    592592        no negative values is plot in log scale 
    593593        """ 
    594594        self.view.check_data_logY() 
    595          
     595 
    596596    def transformX(self, transx, transdx): 
    597597        """ 
    598598        Receive pointers to function that transform x and dx 
    599599        and set corresponding View pointers 
    600          
     600 
    601601        :param transx: pointer to function that transforms x 
    602602        :param transdx: pointer to function that transforms dx 
    603          
     603 
    604604        """ 
    605605        self.view.setTransformX(transx, transdx) 
    606          
     606 
    607607    def transformY(self, transy, transdy): 
    608608        """ 
    609609        Receive pointers to function that transform y and dy 
    610610        and set corresponding View pointers 
    611          
     611 
    612612        :param transy: pointer to function that transforms y 
    613613        :param transdy: pointer to function that transforms dy 
    614          
     614 
    615615        """ 
    616616        self.view.setTransformY(transy, transdy) 
    617          
     617 
    618618    def onReset(self): 
    619619        """ 
     
    621621        """ 
    622622        self.view.onResetView() 
    623          
     623 
    624624    def onFitRange(self, xmin=None, xmax=None): 
    625625        """ 
    626626        It limits View data range to plot from min to max 
    627          
     627 
    628628        :param xmin: the minimum value of x to plot. 
    629629        :param xmax: the maximum value of x to plot 
    630          
     630 
    631631        """ 
    632632        self.view.onFitRangeView(xmin, xmax) 
    633      
    634      
    635 class View: 
     633 
     634 
     635class View(object): 
    636636    """ 
    637637    Representation of the data that might include a transformation 
     
    672672        :param dx: array of  errors values on x 
    673673        :param dy: array of error values on y 
    674          
     674 
    675675        """ 
    676676        # Sanity check 
     
    678678        has_err_x = not (dx == None or len(dx) == 0) 
    679679        has_err_y = not (dy == None or len(dy) == 0) 
    680          
     680 
    681681        if(x != None) and (y != None): 
    682682            if not dx == None and not len(dx) == 0 and not len(x) == len(dx): 
     
    689689                msg += "and x are not of the same length" 
    690690                raise ValueError, msg 
    691          
     691 
    692692            if not dy == None and not len(dy) == 0 and not len(y) == len(dy): 
    693693                msg = "Plottable.View: Given y and dy are not of the same " 
     
    750750            self.DXreel = self.dx 
    751751            self.DYreel = self.dy 
    752                  
     752 
    753753    def onResetView(self): 
    754754        """ 
     
    760760        self.dx = self.DXreel 
    761761        self.dy = self.DYreel 
    762          
     762 
    763763    def setTransformX(self, funcx, funcdx): 
    764764        """ 
    765765        Receive pointers to function that transform x and dx 
    766766        and set corresponding View pointers 
    767          
     767 
    768768        :param transx: pointer to function that transforms x 
    769769        :param transdx: pointer to function that transforms dx 
     
    771771        self.funcx = funcx 
    772772        self.funcdx = funcdx 
    773          
     773 
    774774    def setTransformY(self, funcy, funcdy): 
    775775        """ 
    776776        Receive pointers to function that transform y and dy 
    777777        and set corresponding View pointers 
    778          
     778 
    779779        :param transx: pointer to function that transforms y 
    780780        :param transdx: pointer to function that transforms dy 
     
    782782        self.funcy = funcy 
    783783        self.funcdy = funcdy 
    784     
     784 
    785785    def returnXview(self): 
    786786        """ 
     
    788788        """ 
    789789        return self.x, self.y, self.dx, self.dy 
    790      
     790 
    791791    def check_data_logX(self): 
    792792        """ 
     
    805805            for i in range(len(self.x)): 
    806806                try: 
    807                     if (self.x[i] > 0): 
     807                    if self.x[i] > 0: 
    808808                        tempx.append(self.x[i]) 
    809809                        tempdx.append(self.dx[i]) 
     
    811811                        tempdy.append(self.dy[i]) 
    812812                except: 
    813                     print "check_data_logX: skipping point x %g" % self.x[i] 
    814                     print sys.exc_value 
    815                     pass  
     813                    logging.error("check_data_logX: skipping point x %g", self.x[i]) 
     814                    logging.error(sys.exc_value) 
    816815            self.x = tempx 
    817816            self.y = tempy 
    818817            self.dx = tempdx 
    819818            self.dy = tempdy 
    820          
     819 
    821820    def check_data_logY(self): 
    822821        """ 
    823822        Remove negative value in y vector 
    824823        to avoid plotting negative value of Log10 
    825          
     824 
    826825        """ 
    827826        tempx = [] 
     
    833832        if self.dy == None: 
    834833            self.dy = numpy.zeros(len(self.y)) 
    835         if (self.yLabel == "log10(y)"): 
     834        if self.yLabel == "log10(y)": 
    836835            for i in range(len(self.x)): 
    837836                try: 
    838                     if (self.y[i] > 0): 
     837                    if self.y[i] > 0: 
    839838                        tempx.append(self.x[i]) 
    840839                        tempdx.append(self.dx[i]) 
     
    842841                        tempdy.append(self.dy[i]) 
    843842                except: 
    844                     print "check_data_logY: skipping point %g" % self.y[i] 
    845                     print sys.exc_value 
    846                     pass 
     843                    logging.error("check_data_logY: skipping point %g", self.y[i]) 
     844                    logging.error(sys.exc_value) 
     845 
    847846            self.x = tempx 
    848847            self.y = tempy 
    849848            self.dx = tempdx 
    850849            self.dy = tempdy 
    851              
     850 
    852851    def onFitRangeView(self, xmin=None, xmax=None): 
    853852        """ 
    854853        It limits View data range to plot from min to max 
    855          
     854 
    856855        :param xmin: the minimum value of x to plot. 
    857856        :param xmax: the maximum value of x to plot 
    858          
     857 
    859858        """ 
    860859        tempx = [] 
     
    866865        if self.dy == None: 
    867866            self.dy = numpy.zeros(len(self.y)) 
    868         if (xmin != None) and (xmax != None): 
     867        if xmin != None and xmax != None: 
    869868            for i in range(len(self.x)): 
    870                 if (self.x[i] >= xmin) and (self.x[i] <= xmax): 
     869                if self.x[i] >= xmin and self.x[i] <= xmax: 
    871870                    tempx.append(self.x[i]) 
    872871                    tempdx.append(self.dx[i]) 
     
    878877            self.dy = tempdy 
    879878 
    880                
     879 
    881880class Data2D(Plottable): 
    882881    """ 
     
    884883    """ 
    885884    def __init__(self, image=None, qx_data=None, qy_data=None, 
    886                   err_image=None, xmin=None, xmax=None, ymin=None, 
    887                   ymax=None, zmin=None, zmax=None): 
     885                 err_image=None, xmin=None, xmax=None, ymin=None, 
     886                 ymax=None, zmin=None, zmax=None): 
    888887        """ 
    889888        Draw image 
     
    898897        self.source = None 
    899898        self.detector = [] 
    900      
    901         ## Units for Q-values 
     899 
     900        # # Units for Q-values 
    902901        self.xy_unit = 'A^{-1}' 
    903         ## Units for I(Q) values 
     902        # # Units for I(Q) values 
    904903        self.z_unit = 'cm^{-1}' 
    905904        self._zaxis = '' 
     
    910909        self._yaxis = '\\rm{Q_{y}}' 
    911910        self._yunit = 'A^{-1}' 
    912          
    913         ### might remove that later 
    914         ## Vector of Q-values at the center of each bin in x 
     911 
     912        # ## might remove that later 
     913        # # Vector of Q-values at the center of each bin in x 
    915914        self.x_bins = [] 
    916         ## Vector of Q-values at the center of each bin in y 
     915        # # Vector of Q-values at the center of each bin in y 
    917916        self.y_bins = [] 
    918          
    919         #x and y boundaries 
     917 
     918        # x and y boundaries 
    920919        self.xmin = xmin 
    921920        self.xmax = xmax 
    922921        self.ymin = ymin 
    923922        self.ymax = ymax 
    924          
     923 
    925924        self.zmin = zmin 
    926925        self.zmax = zmax 
    927926        self.id = None 
    928          
     927 
    929928    def xaxis(self, label, unit): 
    930929        """ 
    931930        set x-axis 
    932          
     931 
    933932        :param label: x-axis label 
    934933        :param unit: x-axis unit 
    935          
     934 
    936935        """ 
    937936        self._xaxis = label 
    938937        self._xunit = unit 
    939          
     938 
    940939    def yaxis(self, label, unit): 
    941940        """ 
    942941        set y-axis 
    943          
     942 
    944943        :param label: y-axis label 
    945944        :param unit: y-axis unit 
    946          
     945 
    947946        """ 
    948947        self._yaxis = label 
    949948        self._yunit = unit 
    950          
     949 
    951950    def zaxis(self, label, unit): 
    952951        """ 
    953952        set z-axis 
    954          
     953 
    955954        :param label: z-axis label 
    956955        :param unit: z-axis unit 
    957          
     956 
    958957        """ 
    959958        self._zaxis = label 
    960959        self._zunit = unit 
    961          
     960 
    962961    def setValues(self, datainfo=None): 
    963962        """ 
    964963        Use datainfo object to initialize data2D 
    965          
     964 
    966965        :param datainfo: object 
    967          
     966 
    968967        """ 
    969968        self.image = copy.deepcopy(datainfo.data) 
     
    971970        self.qy_data = copy.deepcopy(datainfo.qy_data) 
    972971        self.err_image = copy.deepcopy(datainfo.err_data) 
    973          
     972 
    974973        self.xy_unit = datainfo.Q_unit 
    975974        self.z_unit = datainfo.I_unit 
    976975        self._zaxis = datainfo._zaxis 
    977         
     976 
    978977        self.xaxis(datainfo._xunit, datainfo._xaxis) 
    979978        self.yaxis(datainfo._yunit, datainfo._yaxis) 
    980         #x and y boundaries 
     979        # x and y boundaries 
    981980        self.xmin = datainfo.xmin 
    982981        self.xmax = datainfo.xmax 
    983982        self.ymin = datainfo.ymin 
    984983        self.ymax = datainfo.ymax 
    985         ## Vector of Q-values at the center of each bin in x 
     984        # # Vector of Q-values at the center of each bin in x 
    986985        self.x_bins = datainfo.x_bins 
    987         ## Vector of Q-values at the center of each bin in y 
     986        # # Vector of Q-values at the center of each bin in y 
    988987        self.y_bins = datainfo.y_bins 
    989          
     988 
    990989    def set_zrange(self, zmin=None, zmax=None): 
    991990        """ 
     
    996995        else: 
    997996            raise "zmin is greater or equal to zmax " 
    998          
     997 
    999998    def render(self, plot, **kw): 
    1000999        """ 
    10011000        Renders the plottable on the graph 
    1002          
     1001 
    10031002        """ 
    10041003        plot.image(self.data, self.qx_data, self.qy_data, 
    10051004                   self.xmin, self.xmax, self.ymin, 
    10061005                   self.ymax, self.zmin, self.zmax, **kw) 
    1007         
     1006 
    10081007    def changed(self): 
    10091008        """ 
    10101009        """ 
    10111010        return False 
    1012      
     1011 
    10131012    @classmethod 
    10141013    def labels(cls, collection): 
    10151014        """Build a label mostly unique within a collection""" 
    1016         map = {} 
     1015        label_dict = {} 
    10171016        for item in collection: 
    1018             #map[item] = label(item, collection) 
    1019             #map[item] = r"$\rm{%s}$" % item.name 
    10201017            if item.label == "Data2D": 
    10211018                item.label = item.name 
    1022             map[item] = item.label 
    1023         return map 
     1019            label_dict[item] = item.label 
     1020        return label_dict 
    10241021 
    10251022 
     
    10281025    Data plottable: scatter plot of x,y with errors in x and y. 
    10291026    """ 
    1030      
     1027 
    10311028    def __init__(self, x, y, dx=None, dy=None): 
    10321029        """ 
     
    10561053        self.zorder = 1 
    10571054        self.hide_error = False 
    1058        
     1055 
    10591056    def render(self, plot, **kw): 
    10601057        """ 
     
    10681065            plot.interactive_points(self.view.x, self.view.y, 
    10691066                                    dx=self.view.dx, dy=self.view.dy, 
    1070               name=self.name, zorder=self.zorder, **kw) 
     1067                                    name=self.name, zorder=self.zorder, **kw) 
    10711068        else: 
    1072             kw['id'] =  self.id 
     1069            kw['id'] = self.id 
    10731070            kw['hide_error'] = self.hide_error 
    10741071            kw['symbol'] = self.symbol 
     
    10761073            kw['markersize'] = self.markersize 
    10771074            plot.points(self.view.x, self.view.y, dx=self.view.dx, 
    1078                 dy=self.view.dy, zorder=self.zorder,  
    1079                 marker=self.symbollist[self.symbol], **kw) 
    1080         
     1075                        dy=self.view.dy, zorder=self.zorder, 
     1076                        marker=self.symbollist[self.symbol], **kw) 
     1077 
    10811078    def changed(self): 
    10821079        return False 
     
    10851082    def labels(cls, collection): 
    10861083        """Build a label mostly unique within a collection""" 
    1087         map = {} 
     1084        label_dict = {} 
    10881085        for item in collection: 
    1089             #map[item] = label(item, collection) 
    1090             #map[item] = r"$\rm{%s}$" % item.name 
    10911086            if item.label == "data": 
    10921087                item.label = item.name 
    1093             map[item] = item.label 
    1094         return map 
    1095      
    1096      
     1088            label_dict[item] = item.label 
     1089        return label_dict 
     1090 
     1091 
    10971092class Theory1D(Plottable): 
    10981093    """ 
    10991094    Theory plottable: line plot of x,y with confidence interval y. 
    1100      
    11011095    """ 
    11021096    def __init__(self, x, y, dy=None): 
     
    11051099        Confidence intervals in x are given by dx[i] or by (xlo[i],xhi[i]) 
    11061100        if the limits are asymmetric. 
    1107          
     1101 
    11081102        The title is the name that will show up on the legend. 
    11091103        """ 
    11101104        Plottable.__init__(self) 
    1111         msg = "Theory1D is no longer supported, please use Data1D and change" 
    1112         msg += " symbol.\n" 
     1105        msg = "Theory1D is no longer supported, please use Data1D and change symbol.\n" 
    11131106        raise DeprecationWarning, msg 
    1114         self.name = "theory" 
    1115         self.label = "theory" 
    1116         self.x = x 
    1117         self.y = y 
    1118         self.dy = dy 
    1119         self.xaxis('', '') 
    1120         self.yaxis('', '') 
    1121         self.view = View(self.x, self.y, None, self.dy) 
    1122         self.symbol = 0 
    1123         self.id = None 
    1124         self.zorder = 10 
    1125          
    1126     def render(self, plot, **kw): 
    1127         """ 
    1128         """ 
    1129         if self.interactive == True: 
    1130             kw['id'] = self.id 
    1131             plot.interactive_curve(self.view.x, self.view.y, 
    1132                                    dy=self.view.dy, 
    1133                                    name=self.name, zorder=self.zorder, **kw) 
    1134         else: 
    1135             kw['id'] = self.id 
    1136             plot.curve(self.view.x, self.view.y, dy=self.view.dy,  
    1137                        zorder=self.zorder, **kw) 
    1138              
    1139     def changed(self): 
    1140         return False 
    1141      
    1142     @classmethod 
    1143     def labels(cls, collection): 
    1144         """Build a label mostly unique within a collection""" 
    1145         map = {} 
    1146         for item in collection: 
    1147             if item.label == "theory": 
    1148                 item.label = item.name 
    1149             map[item] = item.label 
    1150         return map 
    1151     
    1152     
     1107 
    11531108class Fit1D(Plottable): 
    11541109    """ 
     
    11591114 
    11601115    The color of the data and theory will be shared. 
    1161      
     1116 
    11621117    """ 
    11631118    def __init__(self, data=None, theory=None): 
     
    11941149        self.xpos = xpos 
    11951150        self.ypos = ypos 
    1196          
     1151 
    11971152    def render(self, plot, **kw): 
    11981153        """ 
     
    12061161                          self.text, 
    12071162                          label=self.name, 
    1208                           transform=xcoords, 
    1209                           ) 
    1210              
     1163                          transform=xcoords) 
     1164 
    12111165    def setText(self, text): 
    12121166        """Set the text string.""" 
     
    12301184        """ 
    12311185        self.ypos = y 
    1232       
     1186 
    12331187 
    12341188# --------------------------------------------------------------- 
     
    12441198        Plottable.__init__(self) 
    12451199        self.name = "chisq" 
    1246         #super( Chisq, self).__init__(None, None, None, None) 
    12471200        self._chisq = chisq 
    12481201        self.xpos = 0.5 
    12491202        self.ypos = 0.9 
    1250          
     1203 
    12511204    def render(self, plot, **kw): 
    12521205        """ 
     
    12601213 
    12611214        xcoords = transforms.blended_transform_factory(plot.subplot.transAxes, 
    1262                                                      plot.subplot.transAxes) 
     1215                                                      plot.subplot.transAxes) 
    12631216        plot.subplot.text(self.xpos, 
    12641217                          self.ypos, 
    12651218                          chisqTxt, label='chisq', 
    1266                           transform=xcoords,) 
    1267              
     1219                          transform=xcoords) 
     1220 
    12681221    def setChisq(self, chisq): 
    12691222        """ 
     
    12771230def sample_graph(): 
    12781231    import numpy as nx 
    1279      
     1232 
    12801233    # Construct a simple graph 
    12811234    if False: 
    1282         x = nx.array([1,2,3,4,5,6], 'd') 
    1283         y = nx.array([4,5,6,5,4,5], 'd') 
     1235        x = nx.array([1, 2, 3, 4, 5, 6], 'd') 
     1236        y = nx.array([4, 5, 6, 5, 4, 5], 'd') 
    12841237        dy = nx.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) 
    12851238    else: 
     
    13001253    import wx 
    13011254    from pylab_plottables import Plotter 
    1302     #from mplplotter import Plotter 
     1255    # from mplplotter import Plotter 
    13031256 
    13041257    # Make a frame to show it 
     
    13101263    # render the graph to the pylab plotter 
    13111264    graph.render(plotter) 
    1312      
    1313     class GraphUpdate: 
     1265 
     1266    class GraphUpdate(object): 
    13141267        callnum = 0 
    1315          
     1268 
    13161269        def __init__(self, graph, plotter): 
    13171270            self.graph, self.plotter = graph, plotter 
    1318          
     1271 
    13191272        def __call__(self): 
    13201273            if self.graph.changed(): 
     
    13221275                return True 
    13231276            return False 
    1324          
     1277 
    13251278        def onIdle(self, event): 
    13261279            self.callnum = self.callnum + 1 
    1327             if self.__call__():  
     1280            if self.__call__(): 
    13281281                pass  # event.RequestMore() 
    13291282    update = GraphUpdate(graph, plotter) 
  • src/sas/plottools/toolbar.py

    r79492222 r3477478  
    99# Event binding code changed after version 2.5 
    1010if wx.VERSION_STRING >= '2.5': 
    11     def bind(actor,event,action,**kw): 
    12         actor.Bind(event,action,**kw) 
     11    def bind(actor, event, action, **kw): 
     12        actor.Bind(event, action, **kw) 
    1313else: 
    14     def bind(actor,event,action,id=None): 
     14    def bind(actor, event, action, id=None): 
    1515        if id is not None: 
    1616            event(actor, id, action) 
    1717        else: 
    18             event(actor,action) 
     18            event(actor, action) 
    1919 
    2020class NavigationToolBar(NavigationToolbar2WxAgg): 
     
    2828    try: save_figure = NavigationToolbar2WxAgg.save 
    2929    except AttributeError: pass 
     30     
    3031    def _init_toolbar(self): 
    3132        self._parent = self.canvas.GetParent() 
    32         _NTB2_HOME         = wx.NewId() 
    33         self._NTB2_BACK    = wx.NewId() 
     33        _NTB2_HOME = wx.NewId() 
     34        self._NTB2_BACK = wx.NewId() 
    3435        self._NTB2_FORWARD = wx.NewId() 
    35         self._NTB2_PAN     = wx.NewId() 
    36         self._NTB2_ZOOM    = wx.NewId() 
    37         _NTB2_SAVE         = wx.NewId() 
    38         _NTB2_PRINT        = wx.NewId() 
    39         _NTB2_RESET        = wx.NewId() 
     36        self._NTB2_PAN = wx.NewId() 
     37        self._NTB2_ZOOM = wx.NewId() 
     38        _NTB2_SAVE = wx.NewId() 
     39        _NTB2_PRINT = wx.NewId() 
     40        _NTB2_RESET = wx.NewId() 
    4041 
    4142        # for mpl 1.2+ compatibility 
     
    4647        self.wx_ids['Zoom'] = self._NTB2_ZOOM 
    4748 
    48         self.SetToolBitmapSize(wx.Size(24,24)) 
     49        self.SetToolBitmapSize(wx.Size(24, 24)) 
    4950 
    5051        context_tip = 'Graph Menu: \n' 
     
    5556 
    5657        self.InsertSeparator(1) 
    57          
     58 
    5859        self.AddSimpleTool(self._NTB2_BACK, _load_bitmap('back.png'), 
    5960                           'Back', 'Back navigation view') 
     
    6263        # todo: get new bitmap 
    6364        self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'), 
    64                            shortHelp='Pan', 
    65                            longHelp='Pan with left, zoom with right') 
     65                          shortHelp='Pan', 
     66                          longHelp='Pan with left, zoom with right') 
    6667        self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'), 
    67                            shortHelp='Zoom', longHelp='Zoom to rectangle') 
     68                          shortHelp='Zoom', longHelp='Zoom to rectangle') 
    6869 
    6970        self.AddSeparator() 
    7071        self.AddSimpleTool(_NTB2_SAVE, _load_bitmap('filesave.png'), 
    7172                           'Save', 'Save plot contents to file') 
    72          
     73 
    7374        print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 
    7475        self.AddSimpleTool(_NTB2_PRINT, print_bmp, 'Print', 'Print plot') 
    75          
     76 
    7677        reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR) 
    7778        self.AddSimpleTool(_NTB2_RESET, reset_bmp, 'Reset', 'Reset graph range') 
     
    114115        except: 
    115116            logging.error("Plot toolbar could not print") 
    116          
  • src/sas/plottools/transform.py

    r79492222 r3477478  
    11import math 
    2           
    3           
     2 
     3 
    44def toX(x, y=None): 
    55    """ 
    66    This function is used to load value on Plottable.View 
    7      
     7 
    88    :param x: Float value 
    9      
     9 
    1010    :return: x 
    11      
     11 
    1212    """ 
    1313    return x 
     
    1717    """ 
    1818    This function is used to load value on Plottable.View 
    19      
     19 
    2020    :param x: Float value 
    21      
     21 
    2222    :return: x 
    23      
     23 
    2424    """ 
    2525    if not x > 0: 
     
    3232    """ 
    3333    This function is used to load value on Plottable.View 
    34      
     34 
    3535    Calculate x^(2) 
    36      
    37     :param x: float value 
    38      
     36 
     37    :param x: float value 
     38 
    3939    """ 
    4040    return x * x 
     
    4545    This function is used to load value on Plottable.View 
    4646    Calculate square root of x 
    47       
    48     :param x: float value 
    49       
     47 
     48    :param x: float value 
     49 
    5050    """ 
    5151    if not x >= 0: 
     
    5858    """ 
    5959    This function is used to load value on Plottable.View 
    60      
     60 
    6161    Calculate x^(4) 
    62      
    63     :param x: float value 
    64      
     62 
     63    :param x: float value 
     64 
    6565    """ 
    6666    return x * x * x * x 
     
    7171    This function is used to load value on Plottable.View 
    7272    Calculate square root of x 
    73       
    74     :param x: float value 
    75       
     73 
     74    :param x: float value 
     75 
    7676    """ 
    7777    if not x >= 0: 
     
    7979    else: 
    8080        return math.sqrt(math.sqrt(x)) 
    81           
     81 
    8282 
    8383def toLogX(x, y=None): 
     
    8585    This function is used to load value on Plottable.View 
    8686    calculate log x 
    87      
    88     :param x: float value 
    89      
     87 
     88    :param x: float value 
     89 
    9090    """ 
    9191    if not x > 0: 
     
    9393    else: 
    9494        return math.log(x) 
    95      
     95 
    9696def toOneOverX(x, y=None): 
    9797    """ 
    9898    """ 
    9999    if x != 0: 
    100         return 1/x 
     100        return 1 / x 
    101101    else: 
    102102        raise ValueError, "cannot divide by zero" 
    103      
    104      
     103 
     104 
    105105def toOneOverSqrtX(y, x=None): 
    106106    """ 
    107107    """ 
    108108    if y > 0: 
    109         return 1/math.sqrt(y) 
     109        return 1 / math.sqrt(y) 
    110110    else: 
    111111        raise ValueError, "transform.toOneOverSqrtX: cannot be computed" 
    112      
    113      
     112 
     113 
    114114def toLogYX2(y, x): 
    115115    """ 
    116116    """ 
    117     if (y * (x**2)) > 0: 
    118         return math.log(y * (x**2)) 
     117    if (y * (x ** 2)) > 0: 
     118        return math.log(y * (x ** 2)) 
    119119    else: 
    120120        raise ValueError, "transform.toLogYX2: cannot be computed" 
    121       
    122       
     121 
     122 
    123123def toLogYX4(y, x): 
    124124    """ 
    125125    """ 
    126126    if (math.pow(x, 4) * y) > 0: 
    127         return math.log(math.pow(x,4) * y) 
    128     else: 
    129         raise ValueError,"transform.toLogYX4: input error" 
    130       
    131       
     127        return math.log(math.pow(x, 4) * y) 
     128    else: 
     129        raise ValueError, "transform.toLogYX4: input error" 
     130 
     131 
    132132def toYX4(y, x): 
    133133    """ 
     
    144144    This function is used to load value on Plottable.View 
    145145    calculate log x 
    146      
    147     :param x: float value 
    148      
     146 
     147    :param x: float value 
     148 
    149149    """ 
    150150    if not (x * y) > 0: 
     
    157157    """ 
    158158    calculate error of x**2 
    159      
    160     :param x: float value 
    161     :param dx: float value 
    162      
     159 
     160    :param x: float value 
     161    :param dx: float value 
     162 
    163163    """ 
    164164    if dx == None: 
     
    170170    """ 
    171171    calculate error of x**2 
    172      
    173     :param x: float value 
    174     :param dx: float value 
    175      
     172 
     173    :param x: float value 
     174    :param dx: float value 
     175 
    176176    """ 
    177177    if dx == None: 
     
    183183    """ 
    184184    calculate error of x**2 
    185      
    186     :param x: float value 
    187     :param dx: float value 
    188      
     185 
     186    :param x: float value 
     187    :param dx: float value 
     188 
    189189    """ 
    190190    if  dx != None: 
     
    193193    else: 
    194194        return 0.0 
    195      
    196      
     195 
     196 
    197197def errFromX2(x, y=None, dx=None, dy=None): 
    198198    """ 
    199199    calculate error of sqrt(x) 
    200      
    201     :param x: float value 
    202     :param dx: float value 
    203      
    204     """ 
    205     if (x > 0): 
    206         if(dx != None): 
     200 
     201    :param x: float value 
     202    :param dx: float value 
     203 
     204    """ 
     205    if x > 0: 
     206        if dx != None: 
    207207            err = dx / (2 * math.sqrt(x)) 
    208208        else: 
     
    217217    """ 
    218218    calculate error of x**4 
    219      
    220     :param x: float value 
    221     :param dx: float value 
    222      
    223     """ 
    224     if  dx != None: 
     219 
     220    :param x: float value 
     221    :param dx: float value 
     222 
     223    """ 
     224    if dx != None: 
    225225        err = 4 * math.pow(x, 3) * dx 
    226226        return math.fabs(err) 
    227227    else: 
    228228        return 0.0 
    229      
    230      
     229 
     230 
    231231def errFromX4(x, y=None, dx=None, dy=None): 
    232232    """ 
    233233    calculate error of x^1/4 
    234      
    235     :param x: float value 
    236     :param dx: float value 
    237      
    238     """ 
    239     if (x > 0): 
    240         if(dx != None): 
    241             err = dx / (4 * math.pow(x, 3/4)) 
     234 
     235    :param x: float value 
     236    :param dx: float value 
     237 
     238    """ 
     239    if x > 0: 
     240        if dx != None: 
     241            err = dx / (4 * math.pow(x, 3 / 4)) 
    242242        else: 
    243243            err = 0 
     
    246246        msg = "transform.errFromX4: can't compute error of negative x" 
    247247        raise ValueError, msg 
    248   
    249   
     248 
     249 
    250250def errToLog10X(x, y=None, dx=None, dy=None): 
    251251    """ 
    252252    calculate error of Log(x) 
    253      
    254     :param x: float value 
    255     :param dx: float value 
    256      
    257     """ 
    258     if dx == None: 
    259         dx = 0 
    260          
     253 
     254    :param x: float value 
     255    :param dx: float value 
     256 
     257    """ 
     258    if dx == None: 
     259        dx = 0 
     260 
    261261    # Check that the point on the graph is positive 
    262262    # within errors 
     
    270270        raise ValueError, "errToLogX: divide by zero" 
    271271    return dx 
    272      
    273      
     272 
     273 
    274274def errToLogX(x, y=None, dx=None, dy=None): 
    275275    """ 
    276276    calculate error of Log(x) 
    277      
    278     :param x: float value 
    279     :param dx: float value 
    280      
    281     """ 
    282     if dx == None: 
    283         dx = 0 
    284              
     277 
     278    :param x: float value 
     279    :param dx: float value 
     280 
     281    """ 
     282    if dx == None: 
     283        dx = 0 
     284 
    285285    # Check that the x point on the graph is zero 
    286286    if x != 0: 
    287         dx = dx/x 
     287        dx = dx / x 
    288288    else: 
    289289        raise ValueError, "errToLogX: divide by zero" 
     
    298298    if dy == None: 
    299299        dy = 0 
    300     err = math.sqrt((2 * x * y * dx)**2 + ((x**2) * dy)**2) 
     300    err = math.sqrt((2 * x * y * dx) ** 2 + ((x ** 2) * dy) ** 2) 
    301301    return err 
    302      
    303      
     302 
     303 
    304304def errToLogXY(x, y, dx=None, dy=None): 
    305305    """ 
    306306    calculate error of Log(xy) 
    307      
     307 
     308    """ 
     309    # Check that the point on the graph is positive 
     310    # within errors 
     311    if not (x - dx) > 0 or not (y - dy) > 0: 
     312        msg = "Transformation does not accept point " 
     313        msg += " that are consistent with zero." 
     314        raise ValueError, msg 
     315    if x != 0 and y != 0: 
     316        if dx == None: 
     317            dx = 0 
     318        if dy == None: 
     319            dy = 0 
     320        err = (dx / x) ** 2 + (dy / y) ** 2 
     321    else: 
     322        raise ValueError, "cannot compute this error" 
     323 
     324    return math.sqrt(math.fabs(err)) 
     325 
     326 
     327def errToLogYX2(x, y, dx=None, dy=None): 
     328    """ 
     329    calculate error of Log(yx**2) 
     330 
     331    """ 
     332    # Check that the point on the graph is positive 
     333    # within errors 
     334    if not (x - dx) > 0 or not (y - dy) > 0: 
     335        msg = "Transformation does not accept point" 
     336        msg += " that are consistent with zero." 
     337        raise ValueError, msg 
     338    if x > 0 and y > 0: 
     339        if dx == None: 
     340            dx = 0 
     341        if dy == None: 
     342            dy = 0 
     343        err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 
     344    else: 
     345        raise ValueError, "cannot compute this error" 
     346    return math.sqrt(math.fabs(err)) 
     347 
     348 
     349def errOneOverX(x, y=None, dx=None, dy=None): 
     350    """ 
     351    calculate error on 1/x 
     352 
     353    """ 
     354    if x != 0: 
     355        if dx == None: 
     356            dx = 0 
     357        err = dx / x ** 2 
     358    else: 
     359        raise ValueError, "Cannot compute this error" 
     360    return math.fabs(err) 
     361 
     362 
     363def errOneOverSqrtX(x, y=None, dx=None, dy=None): 
     364    """ 
     365    Calculate error on 1/sqrt(x) 
     366 
     367    """ 
     368    if x > 0: 
     369        if dx == None: 
     370            dx = 0 
     371        err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 
     372    else: 
     373        raise ValueError, "Cannot compute this error" 
     374    return math.fabs(err) 
     375 
     376 
     377def errToLogYX4(x, y=None, dx=None, dy=None): 
     378    """ 
     379    error for ln(y*x^(4)) 
     380 
     381    :param x: float value 
     382 
    308383    """ 
    309384    # Check that the point on the graph is positive 
     
    313388        msg += " that are consistent with zero." 
    314389        raise ValueError, msg 
    315     if (x != 0) and (y != 0): 
    316         if dx == None: 
    317             dx = 0 
    318         if dy == None: 
    319             dy = 0 
    320         err = (dx/x)**2 + (dy/y)**2 
    321     else: 
    322         raise ValueError, "cannot compute this error" 
    323     
    324     return math.sqrt(math.fabs(err)) 
    325      
    326      
    327 def errToLogYX2(x, y, dx=None, dy=None): 
    328     """ 
    329     calculate error of Log(yx**2) 
    330      
     390    if dx == None: 
     391        dx = 0 
     392    if dy == None: 
     393        dy = 0 
     394    err = math.sqrt((4.0 * dx / x) ** 2 + (dy / y) ** 2) 
     395    return err 
     396 
     397 
     398def errToYX4(x, y=None, dx=None, dy=None): 
     399    """ 
     400    error for (y*x^(4)) 
     401 
     402    :param x: float value 
     403 
    331404    """ 
    332405    # Check that the point on the graph is positive 
    333406    # within errors 
    334     if (not (x - dx) > 0) or (not (y - dy) > 0): 
    335         msg = "Transformation does not accept point" 
    336         msg += " that are consistent with zero." 
    337         raise ValueError, msg 
    338     if (x > 0) and (y > 0): 
    339         if (dx == None): 
    340             dx = 0 
    341         if (dy == None): 
    342             dy = 0 
    343         err = (2.0*dx/x)**2 + (dy/y)**2 
    344     else: 
    345         raise ValueError, "cannot compute this error" 
    346     return math.sqrt(math.fabs(err)) 
    347          
    348          
    349 def errOneOverX(x, y=None, dx=None, dy=None): 
    350     """ 
    351     calculate error on 1/x 
    352      
    353     """ 
    354     if (x != 0): 
    355         if dx == None: 
    356             dx = 0 
    357         err = dx/x**2 
    358     else: 
    359         raise ValueError, "Cannot compute this error" 
    360     return math.fabs(err) 
    361  
    362  
    363 def errOneOverSqrtX(x, y=None, dx=None, dy=None): 
    364     """ 
    365     Calculate error on 1/sqrt(x) 
    366      
    367     """ 
    368     if (x > 0): 
    369         if dx == None: 
    370             dx = 0 
    371         err = -1/2*math.pow(x, -3.0/2.0) * dx 
    372     else: 
    373         raise ValueError, "Cannot compute this error" 
    374     return math.fabs(err) 
    375  
    376  
    377 def errToLogYX4(x, y=None, dx=None, dy=None): 
    378     """ 
    379     error for ln(y*x^(4)) 
    380      
    381     :param x: float value 
    382      
    383     """ 
    384     # Check that the point on the graph is positive 
    385     # within errors 
    386     if (not (x - dx) > 0) or (not (y - dy) > 0): 
    387         msg = "Transformation does not accept point " 
    388         msg += " that are consistent with zero." 
    389         raise ValueError, msg 
     407 
    390408    if dx == None: 
    391409        dx = 0 
    392410    if dy == None: 
    393411        dy = 0 
    394     err = math.sqrt((4.0 * dx/x)**2  + (dy/y)**2) 
     412    err = math.sqrt((dy * pow(x, 4)) ** 2 + (4 * y * dx * math.pow(x, 3)) ** 2) 
    395413    return err 
    396  
    397  
    398 def errToYX4(x, y=None, dx=None, dy=None): 
    399     """ 
    400     error for (y*x^(4)) 
    401      
    402     :param x: float value 
    403      
    404     """ 
    405     # Check that the point on the graph is positive 
    406     # within errors 
    407  
    408     if dx == None: 
    409         dx = 0 
    410     if dy == None: 
    411         dy = 0 
    412     err = math.sqrt((dy * pow(x, 4))**2  + (4 * y * dx * math.pow(x, 3))**2) 
    413     return err 
Note: See TracChangeset for help on using the changeset viewer.