Solved Re: [nvda-addons] wx.FileDialog and scripts

Javi Domínguez


Checked. With gui.runScriptModalDialog it works perfectly. Thanks again.

    def script_loadFile(self, gesture):
        dlg = wx.FileDialog(gui.mainFrame,
        "Select a file",
        os.getenv('USERPROFILE'), "",
        "All files (*.*)|*.*", wx.FD_OPEN)
        def callback(result):
            path = dlg.GetPath()
        gui.runScriptModalDialog(dlg, callback)


El 21/08/2022 a las 15:07, Javi Domínguez via escribió:


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

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)
		gui.runScriptModalDialog(d, callback)

David CM.

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

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.


Join { to automatically receive all group messages.