wx.FileDialog and scripts


Javi Domínguez
 

Hello.


Does anyone know why I can't use a wx.FileDialog in a globalPlugin script? NVDA crashes. However, elsewhere, for example calling it from the NVDA menu it works perfectly.


Thanks



DaVid
 

My driver IBMTTS launch a file dialog from the configuration settings,
it shows a category in the NVDA settings dialog.
You can use that add-on as reference.

But I have a personal add-on that launch a file dialog from a script,
I did not publish the add-on because is just for personal purposes,
but see the code I used here. This is the function called by the
script:

def setFile(self):
d = wx.FileDialog(gui.mainFrame, message= _("Select the text to show
in the document loader"),
# Translators: the label for the text document extension (txt) file type
wildcard=(_("text files (*.{ext})")+"|*.{ext}").format(ext="txt"))
def callback(result):
if result == wx.ID_OK:
text = open(d.GetPath(),encoding="utf-8").read()
self.document = SimpleTextResult(text)
self.documentUi = CustomTextUi(result = self.document)
self.documentUi.setFocus()
gui.runScriptModalDialog(d, callback)

Regards,
David CM.

2022-08-21 3:42 GMT-06:00, Javi Domínguez <fjavids@...>:

Hello.


Does anyone know why I can't use a wx.FileDialog in a globalPlugin
script? NVDA crashes. However, elsewhere, for example calling it from
the NVDA menu it works perfectly.


Thanks


Abdel
 

Hi Javi,

For me, the following three instructions entered in the Python console of NVDA work well, maybe you did not specify the parent?

import gui
fileDialog = wx.FileDialog(gui.mainFrame, message="Test", wildcard=("Text (*.txt)"), defaultDir="c:", style=wx.FD_OPEN)
fileDialog.ShowModal()

Hope this helps.

Kind regards,
Abdel.

Le 21/08/2022 à 11:42, Javi Domínguez a écrit :

Hello.


Does anyone know why I can't use a wx.FileDialog in a globalPlugin script? NVDA crashes. However, elsewhere, for example calling it from the NVDA menu it works perfectly.


Thanks



Javi Domínguez
 

Hello.


I know how launch a file dialog from the configuration settings and there it works fine for me but when i try to launch it from a script it crashes. I think the solution is in gui.runScriptModalDialog; I was trying to launch it via result = dlg.ShowModal(). Thanks.


El 21/08/2022 a las 14:12, DaVid escribió:

My driver IBMTTS launch a file dialog from the configuration settings,
it shows a category in the NVDA settings dialog.
You can use that add-on as reference.

But I have a personal add-on that launch a file dialog from a script,
I did not publish the add-on because is just for personal purposes,
but see the code I used here. This is the function called by the
script:

def setFile(self):	
		d = wx.FileDialog(gui.mainFrame, message= _("Select the text to show
in the document loader"),
			# Translators: the label for the text document extension (txt) file type
			wildcard=(_("text files (*.{ext})")+"|*.{ext}").format(ext="txt"))
		def callback(result):
			if result == wx.ID_OK:
				text = open(d.GetPath(),encoding="utf-8").read()
				self.document = SimpleTextResult(text)
				self.documentUi = CustomTextUi(result = self.document)
				self.documentUi.setFocus()
		gui.runScriptModalDialog(d, callback)

Regards,
David CM.

2022-08-21 3:42 GMT-06:00, Javi Domínguez <fjavids@...>:
Hello.


Does anyone know why I can't use a wx.FileDialog in a globalPlugin
script? NVDA crashes. However, elsewhere, for example calling it from
the NVDA menu it works perfectly.


Thanks





Javi Domínguez
 

Hello, Abdel.


Thanks. My code is very similar to this and in the console it works fine. The problem is that if I put that in a script NVDA crashes.


I think DaVid has given me the solution: use gui.runScriptModalDialog instead of dlg.ShowModal. I will try it and tell you.


Greetings
El 21/08/2022 a las 14:16, Abdel escribió:

Hi Javi,

For me, the following three instructions entered in the Python console of NVDA work well, maybe you did not specify the parent?

import gui
fileDialog = wx.FileDialog(gui.mainFrame, message="Test", wildcard=("Text (*.txt)"), defaultDir="c:", style=wx.FD_OPEN)
fileDialog.ShowModal()

Hope this helps.

Kind regards,
Abdel.
Le 21/08/2022 à 11:42, Javi Domínguez a écrit :

Hello.


Does anyone know why I can't use a wx.FileDialog in a globalPlugin script? NVDA crashes. However, elsewhere, for example calling it from the NVDA menu it works perfectly.


Thanks



DaVid
 

See the code I wrote in my previous e-mail, that function is launched
from a script (using a gesture) and works perfectly for me. Try that
function and if that function doesn't work for you, please send here
the log, because that function is working on my machine.

regards,
David CM.


2022-08-21 7:07 GMT-06:00, Javi Domínguez <fjavids@...>:

Hello.


I know how launch a file dialog from the configuration settingsand there
it works fine for me but when i try to launch it from a script it
crashes. I think the solution is in gui.runScriptModalDialog; I was
trying to launch it via result = dlg.ShowModal(). Thanks.


Javi Domínguez