ui.py
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ui.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2008-2016 NV Access Limited, Dinesh Kaushal, Davy Kager
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
"""User interface functionality.
This refers to the user interface presented by the screen reader alone, not the graphical user interface.
See L{gui} for the graphical user interface.
"""
import os
import sys
from ctypes import windll, byref, POINTER, addressof
from comtypes import IUnknown
from comtypes import automation
from logHandler import log
import gui
import speech
import braille
# From urlmon.h
URL_MK_UNIFORM = 1
# Dialog box properties
DIALOG_OPTIONS = "dialogWidth:350px;dialogHeight:140px;resizable:yes;center:yes;help:no"
#dwDialogFlags for ShowHTMLDialogEx from mshtmhst.h
HTMLDLG_NOUI = 0x0010
HTMLDLG_MODAL = 0x0020
HTMLDLG_MODELESS = 0x0040
HTMLDLG_PRINT_TEMPLATE = 0x0080
HTMLDLG_VERIFY = 0x0100
def browseableMessage(message,title=None , isHtml=False):
"""Present a message to the user that can be read in browse mode.
The message will be presented in an HTML document.
@param message: The message in either html or text.
@type message: unicode
@param title: The title for the message.
@type title: unicode
@param isHtml: Whether the message is html
@type isHtml: boolean
"""
htmlFileName = os.path.realpath( 'message.html' )
if not os.path.isfile(htmlFileName ):
raise LookupError(htmlFileName )
moniker = POINTER(IUnknown)()
windll.urlmon.CreateURLMonikerEx(0, unicode( htmlFileName ) , byref(moniker), URL_MK_UNIFORM)
if not title:
# Translators: The title for the dialog used to present general NVDA messages in browse mode.
title = _("NVDA Message")
isHtmlArgument = "true" if isHtml else "false"
dialogString = u"{isHtml};{title};{message}".format( isHtml = isHtmlArgument , title=title , message=message )
dialogArguements = automation.VARIANT( dialogString )
gui.mainFrame.prePopup()
windll.mshtml.ShowHTMLDialogEx( gui.mainFrame.Handle , moniker , HTMLDLG_MODELESS , addressof( dialogArguements ) , unicode(DIALOG_OPTIONS ), None)
gui.mainFrame.postPopup()
def message(text):
"""Present a message to the user.
The message will be presented in both speech and braille.
@param text: The text of the message.
@type text: str
"""
speech.speakMessage(text)
braille.handler.message(text)
def reviewMessage(text):
"""Present a message from review or object navigation to the user.
The message will always be presented in speech, and also in braille if it is tethered to review.
@param text: The text of the message.
@type text: str
"""
speech.speakMessage(text)
if braille.handler.tether == braille.handler.TETHER_REVIEW:
braille.handler.message(text)