Changeset eb1a386 in sasview for src/sas/qtgui/Plotting


Ignore:
Timestamp:
Jan 24, 2018 1:52:41 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
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
Children:
116dd4c1
Parents:
0764593
Message:

Fixed text add functionality on plots - SASVIEW-859

Location:
src/sas/qtgui/Plotting
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Plotting/Plotter.py

    r8f83719f reb1a386  
    282282        Show a dialog allowing adding custom text to the chart 
    283283        """ 
    284         if self.addText.exec_() == QtWidgets.QDialog.Accepted: 
    285             # Retrieve the new text, its font and color 
    286             extra_text = self.addText.text() 
    287             extra_font = self.addText.font() 
    288             extra_color = self.addText.color() 
    289  
    290             # Place the text on the screen at (0,0) 
    291             pos_x = self.x_click 
    292             pos_y = self.y_click 
    293  
    294             # Map QFont onto MPL font 
    295             mpl_font = FontProperties() 
    296             mpl_font.set_size(int(extra_font.pointSize())) 
    297             mpl_font.set_family(str(extra_font.family())) 
    298             mpl_font.set_weight(int(extra_font.weight())) 
    299             # MPL style names 
    300             styles = ['normal', 'italic', 'oblique'] 
    301             # QFont::Style maps directly onto the above 
    302             try: 
    303                 mpl_font.set_style(styles[extra_font.style()]) 
    304             except: 
    305                 pass 
    306  
    307             if len(extra_text) > 0: 
    308                 new_text = self.ax.text(str(pos_x), 
    309                                         str(pos_y), 
    310                                         extra_text, 
    311                                         color=extra_color, 
    312                                         fontproperties=mpl_font) 
    313                 # Update the list of annotations 
    314                 self.textList.append(new_text) 
    315                 self.canvas.draw_idle() 
    316                 pass 
     284        if self.addText.exec_() != QtWidgets.QDialog.Accepted: 
     285            return 
     286 
     287        # Retrieve the new text, its font and color 
     288        extra_text = self.addText.text() 
     289        extra_font = self.addText.font() 
     290        extra_color = self.addText.color() 
     291 
     292        # Place the text on the screen at the click location 
     293        pos_x = self.x_click 
     294        pos_y = self.y_click 
     295 
     296        # Map QFont onto MPL font 
     297        mpl_font = FontProperties() 
     298        mpl_font.set_size(int(extra_font.pointSize())) 
     299        mpl_font.set_family(str(extra_font.family())) 
     300        mpl_font.set_weight(int(extra_font.weight())) 
     301        # MPL style names 
     302        styles = ['normal', 'italic', 'oblique'] 
     303        # QFont::Style maps directly onto the above 
     304        try: 
     305            mpl_font.set_style(styles[extra_font.style()]) 
     306        except: 
     307            pass 
     308 
     309        if len(extra_text) > 0: 
     310            new_text = self.ax.text(pos_x, 
     311                                    pos_y, 
     312                                    extra_text, 
     313                                    color=extra_color, 
     314                                    fontproperties=mpl_font) 
     315 
     316            # Update the list of annotations 
     317            self.textList.append(new_text) 
     318            self.canvas.draw() 
    317319 
    318320    def onRemoveText(self): 
     
    325327        txt = self.textList[num_text - 1] 
    326328        text_remove = txt.get_text() 
    327         txt.remove() 
     329        try: 
     330            txt.remove() 
     331        except ValueError: 
     332            # Text got already deleted somehow 
     333            pass 
    328334        self.textList.remove(txt) 
    329335 
  • src/sas/qtgui/Plotting/PlotterBase.py

    r8f83719f reb1a386  
    66from PyQt5 import QtWidgets, QtPrintSupport 
    77 
    8 # TODO: Replace the qt4agg calls below with qt5 equivalent. 
    9 # Requires some code modifications. 
    10 # https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html 
    11 # 
    12 # matplotlib.use("Qt5Agg") 
    138from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 
    149from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar 
     
    3631 
    3732        #plt.style.use('ggplot') 
    38         plt.style.use('seaborn-darkgrid') 
     33        #plt.style.use('seaborn-darkgrid') 
    3934 
    4035        # a figure instance to plot on 
     
    176171    def xscale(self, scale='linear'): 
    177172        """ X-axis scale setter """ 
     173        self.ax.cla() 
    178174        self.ax.set_xscale(scale) 
    179175        self._xscale = scale 
Note: See TracChangeset for help on using the changeset viewer.