Skip to content

Commit 5b53850

Browse files
authored
Merge pull request #3128 from SasView/3127-adding-custom-text-to-a-graph-causes-it-to-go-blank
3127 adding custom text to a graph causes it to go blank
2 parents 8b0da66 + 50bbddf commit 5b53850

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/sas/qtgui/Plotting/Plotter.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,9 @@ def onAddText(self):
531531
# MPL style names
532532
styles = ['normal', 'italic', 'oblique']
533533
# QFont::Style maps directly onto the above
534-
try:
535-
mpl_font.set_style(styles[extra_font.style()])
536-
except:
537-
pass
534+
# Get an index of the font style which we can then lookup in the styles list.
535+
font_index = extra_font.style().value
536+
mpl_font.set_style(styles[font_index])
538537

539538
if len(extra_text) > 0:
540539
new_text = self.ax.text(pos_x,
@@ -919,6 +918,13 @@ def onMplMouseDown(self, event):
919918
"""
920919
Left button down and ready to drag
921920
"""
921+
# Before checking if this mouse click is a left click, we need to update the position of the mouse regardless as
922+
# this may be needed by other events (e.g. adding text)
923+
try:
924+
self.x_click = float(event.xdata) # / size_x
925+
self.y_click = float(event.ydata) # / size_y
926+
except:
927+
self.position = None
922928
# Check that the LEFT button was pressed
923929
if event.button != 1:
924930
return
@@ -930,11 +936,6 @@ def onMplMouseDown(self, event):
930936
return
931937
if event.inaxes is None:
932938
return
933-
try:
934-
self.x_click = float(event.xdata) # / size_x
935-
self.y_click = float(event.ydata) # / size_y
936-
except:
937-
self.position = None
938939

939940
x_str = GuiUtils.formatNumber(self.x_click)
940941
y_str = GuiUtils.formatNumber(self.y_click)

0 commit comments

Comments
 (0)