Skip to content

Commit 02b5096

Browse files
authored
Merge pull request #70 from NSoiffer/UserInterfaceUpdatesMarch2024
Add Copy As to dialog
2 parents 221ad70 + 3e02470 commit 02b5096

File tree

3 files changed

+68
-32
lines changed

3 files changed

+68
-32
lines changed

addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -306,33 +306,33 @@ def script_navigate(self, gesture: KeyboardInputGesture):
306306
)
307307
def script_rawdataToClip(self, gesture: KeyboardInputGesture):
308308
try:
309-
mathml = libmathcat.GetNavigationMathML()[0]
310-
if not re.match(self._startsWithMath, mathml):
311-
mathml = (
312-
"<math>\n" + mathml + "</math>"
313-
) # copy will fix up name spacing
314-
elif self.init_mathml != "":
315-
mathml = self.init_mathml
316-
copy_as = "mathml"
309+
copy_as = "mathml" # value used even if "CopyAs" pref is invalid
310+
text_to_copy = ""
317311
try:
318312
copy_as = libmathcat.GetPreference("CopyAs").lower()
319-
match copy_as:
320-
case "mathml" | "latex" | "asciimath":
321-
pass
322-
case _:
323-
copy_as = "mathml"
324313
except Exception as e:
325314
log.error(f"Not able to get 'CopyAs' preference: {e}")
326-
327-
mathml = self._wrapMathMLForClipBoard(mathml)
328-
if copy_as != "mathml":
315+
if copy_as == "asciimath" or copy_as == "latex":
316+
# save the old braille code, set the new one, get the braille, then reset the code
329317
saved_braille_code: str = libmathcat.GetPreference("BrailleCode")
330318
libmathcat.SetPreference("BrailleCode", "LaTeX" if copy_as == "latex" else "ASCIIMath")
331-
mathml = libmathcat.GetNavigationBraille()
319+
text_to_copy = libmathcat.GetNavigationBraille()
332320
libmathcat.SetPreference("BrailleCode", saved_braille_code)
333-
self._copyToClipAsMathML(mathml, copy_as == "mathml")
321+
if copy_as == "asciimath":
322+
copy_as = "ASCIIMath" # speaks better in at least some voices
323+
else:
324+
mathml = libmathcat.GetNavigationMathML()[0]
325+
if not re.match(self._startsWithMath, mathml):
326+
mathml = (
327+
"<math>\n" + mathml + "</math>"
328+
) # copy will fix up name spacing
329+
elif self.init_mathml != "":
330+
mathml = self.init_mathml
331+
text_to_copy = self._wrapMathMLForClipBoard(mathml)
332+
333+
self._copyToClipAsMathML(text_to_copy, copy_as == "mathml")
334334
# Translators: copy to clipboard
335-
ui.message(_("copy"))
335+
ui.message(_("copy as ") + copy_as)
336336
except Exception as e:
337337
log.error(e)
338338
# Translators: this message directs users to look in the log file

addon/globalPlugins/MathCAT/MathCATPreferences.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
# Navigation_OverView is boolean
3636
Navigation_NavVerbosity = ("Terse", "Medium", "Verbose")
3737
# Navigation_AutoZoomOut is boolean
38+
Navigation_CopyMathAs = ("MathML", "LaTeX", "ASCIIMath")
3839
Braille_BrailleNavHighlight = ("Off", "FirstChar", "EndPoints", "All")
3940

4041

@@ -400,6 +401,7 @@ def set_ui_values(self):
400401
self.m_sliderPauseFactor.SetValue(pause_factor)
401402
self.m_checkBoxSpeechSound.SetValue(user_preferences["Speech"]["SpeechSound"] == "Beep")
402403
self.m_choiceSpeechForChemical.SetSelection(Speech_Chemistry.index(user_preferences["Speech"]["Chemistry"]))
404+
403405
self.m_choiceNavigationMode.SetSelection(Navigation_NavMode.index(user_preferences["Navigation"]["NavMode"]))
404406
self.m_checkBoxResetNavigationMode.SetValue(user_preferences["Navigation"]["ResetNavMode"])
405407
self.m_choiceSpeechAmountNavigation.SetSelection(
@@ -411,6 +413,8 @@ def set_ui_values(self):
411413
self.m_choiceNavigationSpeech.SetSelection(0)
412414
self.m_checkBoxResetNavigationSpeech.SetValue(user_preferences["Navigation"]["ResetOverview"])
413415
self.m_checkBoxAutomaticZoom.SetValue(user_preferences["Navigation"]["AutoZoomOut"])
416+
self.m_choiceCopyMathAs.SetSelection(Navigation_CopyMathAs.index(user_preferences["Navigation"]["CopyMathAs"]))
417+
414418
self.m_choiceBrailleHighlights.SetSelection(
415419
Braille_BrailleNavHighlight.index(user_preferences["Braille"]["BrailleNavHighlight"])
416420
)
@@ -461,6 +465,8 @@ def get_ui_values(self):
461465
user_preferences["Navigation"]["Overview"] = self.m_choiceNavigationSpeech.GetSelection() != 0
462466
user_preferences["Navigation"]["ResetOverview"] = self.m_checkBoxResetNavigationSpeech.GetValue()
463467
user_preferences["Navigation"]["AutoZoomOut"] = self.m_checkBoxAutomaticZoom.GetValue()
468+
user_preferences["Navigation"]["CopyMathAs"] = Navigation_CopyMathAs[self.m_choiceCopyMathAs.GetSelection()]
469+
464470
user_preferences["Braille"]["BrailleNavHighlight"] = (
465471
Braille_BrailleNavHighlight[self.m_choiceBrailleHighlights.GetSelection()]
466472
)
@@ -575,6 +581,8 @@ def validate_user_preferences():
575581
UserInterface.validate("Navigation", "NavVerbosity", ["Terse", "Medium", "Full"], "Medium")
576582
# AutoZoomOut: true # Auto zoom out of 2D exprs (use shift-arrow to force zoom out if unchecked)
577583
UserInterface.validate("Navigation", "AutoZoomOut", [False, True], True)
584+
# NavCopyMathAs: MathML # MathML, LaTeX, ASCIIMath
585+
UserInterface.validate("Navigation", "CopyMathAs", ["MathML", "LaTeX", "ASCIIMath"], "MathML")
578586
# Braille:
579587
# BrailleNavHighlight: EndPoints
580588
# Highlight with dots 7 & 8 the current nav node -- values are Off, FirstChar, EndPoints, All

addon/globalPlugins/MathCAT/MathCATgui.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
3-
###########################################################################
4-
# Python code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
5-
# http://www.wxformbuilder.org/
6-
#
7-
# PLEASE DO *NOT* EDIT THIS FILE!
8-
###########################################################################
9-
101
import wx
112
# import wx.xrc
123
import gettext
@@ -205,7 +196,7 @@ def __init__(self, parent):
205196

206197
bSizerSpeech.Add(bSizerSpeechStyle, 1, wx.EXPAND, 5)
207198

208-
bSizer71 = wx.BoxSizer(wx.HORIZONTAL)
199+
bSizerSpeechAmount = wx.BoxSizer(wx.HORIZONTAL)
209200

210201
self.m_staticTextSpeechAmount = wx.StaticText(
211202
self.m_panelSpeech,
@@ -218,7 +209,7 @@ def __init__(self, parent):
218209
)
219210
self.m_staticTextSpeechAmount.Wrap(-1)
220211

221-
bSizer71.Add(self.m_staticTextSpeechAmount, 0, wx.ALL, 5)
212+
bSizerSpeechAmount.Add(self.m_staticTextSpeechAmount, 0, wx.ALL, 5)
222213

223214
# Translators: options for speech verbosity.
224215
m_choiceSpeechAmountChoices = [
@@ -238,9 +229,9 @@ def __init__(self, parent):
238229
0,
239230
)
240231
self.m_choiceSpeechAmount.SetSelection(0)
241-
bSizer71.Add(self.m_choiceSpeechAmount, 0, wx.ALL, 5)
232+
bSizerSpeechAmount.Add(self.m_choiceSpeechAmount, 0, wx.ALL, 5)
242233

243-
bSizerSpeech.Add(bSizer71, 1, wx.EXPAND, 5)
234+
bSizerSpeech.Add(bSizerSpeechAmount, 1, wx.EXPAND, 5)
244235

245236
bSizerRelativeSpeed = wx.BoxSizer(wx.HORIZONTAL)
246237

@@ -530,6 +521,43 @@ def __init__(self, parent):
530521

531522
bSizerNavigation.Add(bSizerNavigationZoom, 1, wx.EXPAND, 5)
532523

524+
bSizerCopyMathAs = wx.BoxSizer(wx.HORIZONTAL)
525+
526+
self.m_staticTextCopyMathAs = wx.StaticText(
527+
self.m_panelNavigation,
528+
wx.ID_ANY,
529+
# Translators: label for pull down to specify how math will be copied to the clipboard
530+
_("Copy math as:"),
531+
wx.DefaultPosition,
532+
wx.DefaultSize,
533+
0,
534+
)
535+
self.m_staticTextCopyMathAs.Wrap(-1)
536+
537+
bSizerCopyMathAs.Add(self.m_staticTextCopyMathAs, 0, wx.ALL, 5)
538+
539+
# Translators: options for copy math as.
540+
m_choiceCopyMathAsChoices = [
541+
# Translators: options for Copy expression to clipboard as -- "MathML"
542+
_("MathML"),
543+
# Translators: options for Copy expression to clipboard as -- "LaTeX"
544+
_("LaTeX"),
545+
# Translators: options for Copy expression to clipboard as -- "ASCIIMath"
546+
_("ASCIIMath"),
547+
]
548+
self.m_choiceCopyMathAs = wx.Choice(
549+
self.m_panelNavigation,
550+
wx.ID_ANY,
551+
wx.DefaultPosition,
552+
wx.DefaultSize,
553+
m_choiceCopyMathAsChoices,
554+
0,
555+
)
556+
self.m_choiceCopyMathAs.SetSelection(0)
557+
bSizerCopyMathAs.Add(self.m_choiceCopyMathAs, 0, wx.ALL, 5)
558+
559+
bSizerNavigation.Add(bSizerCopyMathAs, 1, wx.EXPAND, 5)
560+
533561
self.m_panelNavigation.SetSizer(bSizerNavigation)
534562
self.m_panelNavigation.Layout()
535563
bSizerNavigation.Fit(self.m_panelNavigation)

0 commit comments

Comments
 (0)