Ignore:
Timestamp:
Mar 20, 2019 10:06:22 AM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
ticket-1249
Children:
9305b46
Parents:
09d7021
Message:

py3/wx4 compatibility changes for gui. Refs #1249

File:
1 edited

Legend:

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

    r82d88d5 r34f23c8  
    339339        # On Windows platform, default window size is incorrect, so set 
    340340        # toolbar width to figure width. 
    341         tw, th = self.toolbar.GetSizeTuple() 
    342         fw, fh = self.canvas.GetSizeTuple() 
     341        tw, th = self.toolbar.GetSize() 
     342        fw, fh = self.canvas.GetSize() 
    343343        # By adding toolbar in sizer, we are able to put it at the bottom 
    344344        # of the frame - so appearance is closer to GTK version. 
     
    439439            y = hi_y 
    440440        # Move the legend from its previous location by that same amount 
    441         loc_in_canvas = self.legend_x - mouse_diff_x, \ 
    442                         self.legend_y - mouse_diff_y 
     441        loc_in_canvas = (self.legend_x - mouse_diff_x, 
     442                         self.legend_y - mouse_diff_y) 
    443443        # Transform into legend coordinate system 
    444444        trans_axes = self.legend.parent.transAxes.inverted() 
     
    630630        Return values and labels used by Fit Dialog 
    631631        """ 
    632         return self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \ 
    633                 self.ErrAvalue, self.ErrBvalue, self.Chivalue 
     632        return (self.xLabel, self.yLabel, self.Avalue, self.Bvalue, 
     633                self.ErrAvalue, self.ErrBvalue, self.Chivalue) 
    634634 
    635635    def setTrans(self, xtrans, ytrans): 
     
    667667                            title='Linear Fit') 
    668668 
    669             if (self.xmin != 0.0)and (self.xmax != 0.0)\ 
    670                 and(self.xminView != 0.0)and (self.xmaxView != 0.0): 
     669            if ((self.xmin != 0.0) and (self.xmax != 0.0) 
     670                    and (self.xminView != 0.0) and (self.xmaxView != 0.0)): 
    671671                dlg.setFitRange(self.xminView, self.xmaxView, 
    672672                                self.xmin, self.xmax) 
     
    925925        except: 
    926926            # toolbar event 
    927             pos_x, pos_y = self.toolbar.GetPositionTuple() 
     927            pos_x, pos_y = self.toolbar.GetPosition() 
    928928            pos = (pos_x, pos_y + 5) 
    929929 
     
    10591059        Allows you to add text to the plot 
    10601060        """ 
    1061         xaxis_label, xaxis_unit, xaxis_font, xaxis_color, \ 
    1062                      is_ok, is_tick = self._on_axis_label(axis='x') 
     1061        xaxis_label, xaxis_unit, xaxis_font, xaxis_color, is_ok, is_tick \ 
     1062            = self._on_axis_label(axis='x') 
    10631063        if not is_ok: 
    10641064            return 
     
    10731073        if self.data is not None: 
    10741074            # 2D 
    1075             self.xaxis(self.xaxis_label, self.xaxis_unit, \ 
    1076                         self.xaxis_font, self.xaxis_color, self.xaxis_tick) 
     1075            self.xaxis(self.xaxis_label, self.xaxis_unit, 
     1076                       self.xaxis_font, self.xaxis_color, self.xaxis_tick) 
    10771077            self.subplot.figure.canvas.draw_idle() 
    10781078        else: 
     
    11061106        Allows you to add text to the plot 
    11071107        """ 
    1108         yaxis_label, yaxis_unit, yaxis_font, yaxis_color, \ 
    1109                         is_ok, is_tick = self._on_axis_label(axis='y') 
     1108        yaxis_label, yaxis_unit, yaxis_font, yaxis_color, is_ok, is_tick \ 
     1109            = self._on_axis_label(axis='y') 
    11101110        if not is_ok: 
    11111111            return 
     
    11201120        if self.data is not None: 
    11211121            # 2D 
    1122             self.yaxis(self.yaxis_label, self.yaxis_unit, \ 
     1122            self.yaxis(self.yaxis_label, self.yaxis_unit, 
    11231123                        self.yaxis_font, self.yaxis_color, self.yaxis_tick) 
    11241124            self.subplot.figure.canvas.draw_idle() 
     
    11561156                is_tick = textdial.getTickLabel() 
    11571157                label_temp = textdial.getText() 
    1158                 if label_temp.count("\%s" % "\\") > 0: 
     1158                if r"\\" in label_temp: 
     1159                    label = label_temp.replace(r"\\", r"??") 
    11591160                    if self.parent is not None: 
    1160                         msg = "Add Label: Error. Can not use double '\\' " 
     1161                        msg = r"Add Label error: Can not use double '\\' " 
    11611162                        msg += "characters..." 
    11621163                        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    15331534        """ 
    15341535        # No qx or qy given in a vector format 
    1535         if self.qx_data is None or self.qy_data is None \ 
    1536                 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 
     1536        if (self.qx_data is None or self.qy_data is None 
     1537                or self.qx_data.ndim != 1 or self.qy_data.ndim != 1): 
    15371538            # do we need deepcopy here? 
    15381539            return copy.deepcopy(self.data) 
     
    15931594        """ 
    15941595        # No qx or qy given in a vector format 
    1595         if self.qx_data is None or self.qy_data is None \ 
    1596                 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 
     1596        if (self.qx_data is None or self.qy_data is None 
     1597                or self.qx_data.ndim != 1 or self.qy_data.ndim != 1): 
    15971598            # do we need deepcopy here? 
    15981599            return copy.deepcopy(self.data) 
     
    16441645        """ 
    16451646        # No image matrix given 
    1646         if image is None or np.ndim(image) != 2 \ 
    1647                 or np.isfinite(image).all() \ 
    1648                 or weights is None: 
     1647        if (image is None or np.ndim(image) != 2 
     1648                or np.isfinite(image).all() or weights is None): 
    16491649            return image 
    16501650        # Get bin size in y and x directions 
     
    16761676                    # go 4 next nearest neighbors when no non-zero 
    16771677                    # neighbor exists 
    1678                     if n_y != 0 and n_x != 0 and \ 
    1679                             np.isfinite(image[n_y - 1][n_x - 1]): 
     1678                    if (n_y != 0 and n_x != 0 
     1679                            and np.isfinite(image[n_y - 1][n_x - 1])): 
    16801680                        temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 
    16811681                        weit[n_y][n_x] += 1 
    1682                     if n_y != len_y - 1 and n_x != 0 and \ 
    1683                             np.isfinite(image[n_y + 1][n_x - 1]): 
     1682                    if (n_y != len_y - 1 and n_x != 0 
     1683                            and np.isfinite(image[n_y + 1][n_x - 1])): 
    16841684                        temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 
    16851685                        weit[n_y][n_x] += 1 
    1686                     if n_y != len_y and n_x != len_x - 1 and \ 
    1687                             np.isfinite(image[n_y - 1][n_x + 1]): 
     1686                    if (n_y != len_y and n_x != len_x - 1 
     1687                            and np.isfinite(image[n_y - 1][n_x + 1])): 
    16881688                        temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 
    16891689                        weit[n_y][n_x] += 1 
    1690                     if n_y != len_y - 1 and n_x != len_x - 1 and \ 
    1691                             np.isfinite(image[n_y + 1][n_x + 1]): 
     1690                    if (n_y != len_y - 1 and n_x != len_x - 1 
     1691                            and np.isfinite(image[n_y + 1][n_x + 1])): 
    16921692                        temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 
    16931693                        weit[n_y][n_x] += 1 
     
    17841784                item.transformX(transform.toX2, transform.errToX2) 
    17851785                xunits = convert_unit(2, xunits) 
    1786                 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 
     1786                self.graph._xaxis_transformed("%s^2" % xname, "%s" % xunits) 
    17871787            if self.xLabel == "x^(4)": 
    17881788                item.transformX(transform.toX4, transform.errToX4) 
    17891789                xunits = convert_unit(4, xunits) 
    1790                 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 
     1790                self.graph._xaxis_transformed("%s^4" % xname, "%s" % xunits) 
    17911791            if self.xLabel == "ln(x)": 
    17921792                item.transformX(transform.toLogX, transform.errToLogX) 
    1793                 self.graph._xaxis_transformed("\ln{(%s)}" % xname, "%s" % xunits) 
     1793                self.graph._xaxis_transformed(r"\ln(%s)" % xname, "%s" % xunits) 
    17941794            if self.xLabel == "log10(x)": 
    17951795                item.transformX(transform.toX_pos, transform.errToX_pos) 
     
    17991799                item.transformX(transform.toX4, transform.errToX4) 
    18001800                xunits = convert_unit(4, xunits) 
    1801                 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 
     1801                self.graph._xaxis_transformed("%s^4" % xname, "%s" % xunits) 
    18021802                _xscale = 'log' 
    18031803            if self.yLabel == "ln(y)": 
    18041804                item.transformY(transform.toLogX, transform.errToLogX) 
    1805                 self.graph._yaxis_transformed("\ln{(%s)}" % yname, "%s" % yunits) 
     1805                self.graph._yaxis_transformed(r"\ln(%s)" % yname, "%s" % yunits) 
    18061806            if self.yLabel == "y": 
    18071807                item.transformY(transform.toX, transform.errToX) 
     
    18221822                item.transformY(transform.toYX2, transform.errToYX2) 
    18231823                xunits = convert_unit(2, self.xaxis_unit) 
    1824                 self.graph._yaxis_transformed("%s \ \ %s^{2}" % (yname, xname), 
     1824                self.graph._yaxis_transformed(r"%s \ \ %s^2" % (yname, xname), 
    18251825                                              "%s%s" % (yunits, xunits)) 
    18261826            if self.yLabel == "y*x^(4)": 
    18271827                item.transformY(transform.toYX4, transform.errToYX4) 
    18281828                xunits = convert_unit(4, self.xaxis_unit) 
    1829                 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 
     1829                self.graph._yaxis_transformed(r"%s \ \ %s^4" % (yname, xname), 
    18301830                                              "%s%s" % (yunits, xunits)) 
    18311831            if self.yLabel == "1/sqrt(y)": 
     
    18331833                                transform.errOneOverSqrtX) 
    18341834                yunits = convert_unit(-0.5, yunits) 
    1835                 self.graph._yaxis_transformed("1/\sqrt{%s}" % yname, 
     1835                self.graph._yaxis_transformed(r"1/\sqrt{%s}" % yname, 
    18361836                                              "%s" % yunits) 
    18371837            if self.yLabel == "ln(y*x)": 
    18381838                item.transformY(transform.toLogXY, transform.errToLogXY) 
    1839                 self.graph._yaxis_transformed("\ln{(%s \ \ %s)}" % (yname, xname), 
     1839                self.graph._yaxis_transformed(r"\ln(%s \ \ %s)" % (yname, xname), 
    18401840                                              "%s%s" % (yunits, self.xaxis_unit)) 
    18411841            if self.yLabel == "ln(y*x^(2))": 
    18421842                item.transformY(transform.toLogYX2, transform.errToLogYX2) 
    18431843                xunits = convert_unit(2, self.xaxis_unit) 
    1844                 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname), 
     1844                self.graph._yaxis_transformed(r"\ln(%s \ \ %s^2)" % (yname, xname), 
    18451845                                              "%s%s" % (yunits, xunits)) 
    18461846            if self.yLabel == "ln(y*x^(4))": 
    18471847                item.transformY(transform.toLogYX4, transform.errToLogYX4) 
    18481848                xunits = convert_unit(4, self.xaxis_unit) 
    1849                 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname), 
     1849                self.graph._yaxis_transformed(r"\ln(%s \ \ %s^4)" % (yname, xname), 
    18501850                                              "%s%s" % (yunits, xunits)) 
    18511851            if self.yLabel == "log10(y*x^(4))": 
     
    18531853                xunits = convert_unit(4, self.xaxis_unit) 
    18541854                _yscale = 'log' 
    1855                 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 
     1855                self.graph._yaxis_transformed(r"%s \ \ %s^4" % (yname, xname), 
    18561856                                              "%s%s" % (yunits, xunits)) 
    18571857            item.transformView() 
     
    18971897        # Saving value to redisplay in Fit Dialog when it is opened again 
    18981898        self.Avalue, self.Bvalue, self.ErrAvalue, \ 
    1899                       self.ErrBvalue, self.Chivalue = func 
     1899            self.ErrBvalue, self.Chivalue = func 
    19001900        self.xminView = xminView 
    19011901        self.xmaxView = xmaxView 
Note: See TracChangeset for help on using the changeset viewer.