1313import core
1414import globalPluginHandler
1515import gui
16+ import queueHandler
1617import wx
18+ from gui .message import DisplayableError
1719from logHandler import log
18- from synthDriverHandler import getSynth , synthChanged
20+ from synthDriverHandler import findAndSetNextSynth , getSynth , synthChanged
1921
2022from globalPlugins .hear2readng_global_plugin .english_settings import (
2123 EnglishSpeechSettingsDialog ,
@@ -31,9 +33,16 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
3133 def __init__ (self , * args , ** kwargs ):
3234 super ().__init__ (* args , ** kwargs )
3335 self .__voice_manager_shown = False
36+ curr_synth_name = getSynth ().name
3437 self ._voice_checker = lambda : wx .CallLater (2000 ,
35- self ._perform_voice_check )
38+ self ._perform_voice_check )
3639 core .postNvdaStartup .register (self ._voice_checker )
40+
41+ # if "Hear2Read NG" not in curr_synth_name:
42+ # self._voice_checker = lambda: wx.CallLater(2000,
43+ # self._perform_voice_check)
44+ # core.postNvdaStartup.register(self._voice_checker)
45+
3746 self .itemHandle = gui .mainFrame .sysTrayIcon .menu .Insert (
3847 4 ,
3948 wx .ID_ANY ,
@@ -45,14 +54,10 @@ def __init__(self, *args, **kwargs):
4554 gui .mainFrame .sysTrayIcon .menu .Bind (wx .EVT_MENU , self .on_manager ,
4655 self .itemHandle )
4756
48- # TODO make this work?
49- # if "Hear2Read NG" not in getSynth().name:
50- # return
51-
5257 self .eng_settings_active = False
5358 self .eng_settings_id = wx .Window .NewControlId ()
5459
55- if "Hear2Read NG" in getSynth (). name :
60+ if "Hear2Read NG" in curr_synth_name :
5661 # self.eng_settings_id = wx.Window.NewControlId()
5762 self .make_eng_settings_menu ()
5863 self .eng_settings_active = True
@@ -64,6 +69,7 @@ def on_synth_changed(self, synth):
6469 # self.eng_settings_id = wx.Window.NewControlId()
6570 self .make_eng_settings_menu ()
6671 self .eng_settings_active = True
72+ self ._perform_voice_check ()
6773
6874 elif self .eng_settings_active :
6975 gui .mainFrame .sysTrayIcon .menu .Remove (self .eng_settings_id )
@@ -83,20 +89,43 @@ def make_eng_settings_menu(self):
8389 EnglishSpeechSettingsDialog ),
8490 self .itemHandle )
8591
86- def on_manager (self , event ):
92+ def on_manager (self , event = None ):
8793 manager_dialog = Hear2ReadNGVoiceManagerDialog ()
8894 try :
89- gui .runScriptModalDialog (manager_dialog )
95+ gui .runScriptModalDialog (manager_dialog , callback = self . on_manager_close )
9096 self .__voice_manager_shown = True
9197 except Exception as e :
9298 log .error (f"Failed to open Manager: { e } " )
9399
94- def _perform_voice_check (self ):
95- if self .__voice_manager_shown :
96- return
97-
100+ def on_manager_close (self , res ):
98101 if not any (Hear2ReadNGVoiceManagerDialog .get_installed_voices ()):
102+ self .on_no_voices (getSynth ().name )
99103
104+ def on_no_voices (self , curr_synth_name ):
105+
106+ if "Hear2Read NG" in curr_synth_name :
107+ msg_res = gui .messageBox (
108+ # Translators: message telling the user that no voice is installed
109+ _ (
110+ "No Indic Hear2Read voice was found.\n "
111+ "Please download a voice from the manager to continue using Hear2Read Synthesizer.\n "
112+ "Do you want to open the voice manager now?"
113+ ),
114+ # Translators: title of a message telling the user that no Hear2Read Indic voice was found
115+ _ ("Hear2Read Indic Voices" ),
116+ wx .YES_NO | wx .ICON_WARNING ,)
117+
118+ if msg_res == wx .YES :
119+ wx .CallAfter (self .on_manager )
120+ else :
121+ noVoiceDisplayError = DisplayableError (
122+ titleMessage = "Shutting Hear2Read Down" ,
123+ displayMessage = "No Hear2Read voices found. \n "
124+ "Please install voices to use Hear2Read. \n "
125+ "Voices can be installed from the Hear2Read voice manager in the NVDA menu" )
126+ noVoiceDisplayError .displayError (gui .mainFrame )
127+ queueHandler .queueFunction (queueHandler .eventQueue , findAndSetNextSynth , curr_synth_name )
128+ else :
100129 if wx .YES == gui .messageBox (
101130 # Translators: message telling the user that no voice is installed
102131 _ (
@@ -107,9 +136,17 @@ def _perform_voice_check(self):
107136 # Translators: title of a message telling the user that no Hear2Read Indic voice was found
108137 _ ("Hear2Read Indic Voices" ),
109138 wx .YES_NO | wx .ICON_WARNING ,):
139+ wx .CallAfter (self .on_manager )
110140
111- self .on_manager (None )
141+ # @gui.blockAction.when(gui.blockAction.Context.MODAL_DIALOG_OPEN)
142+ def _perform_voice_check (self ):
143+ if self .__voice_manager_shown :# or gui.isModalMessageBoxActive():
144+ return
112145
146+ if not any (Hear2ReadNGVoiceManagerDialog .get_installed_voices ()):
147+ curr_synth_name = getSynth ().name
148+ # queueHandler.queueFunction(queueHandler.eventQueue, self.on_no_voices, curr_synth_name)
149+ self .on_no_voices (curr_synth_name )
113150
114151 def terminate (self ):
115152 try :
0 commit comments