Skip to content

Commit

Permalink
Use MessageDialog API available in NVDA 2025.1 (#56)
Browse files Browse the repository at this point in the history
* Use MessageDialog API available in NVDA 2025.1

* Fix year and lint
  • Loading branch information
nvdaes authored Jan 12, 2025
1 parent 1281b13 commit 21e8228
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 79 deletions.
42 changes: 18 additions & 24 deletions addon/globalPlugins/clipContentsDesigner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: UTF-8 -*-
# clipContentsDesigner: a global plugin for managing clipboard text
# Copyright (C) 2012-2024 Noelia Ruiz Martínez, other contributors
# Copyright (C) 2012-2025 Noelia Ruiz Martínez, other contributors
# Released under GPL 2

import addonHandler
Expand All @@ -18,13 +18,14 @@
import gui
from gui import guiHelper
from gui.settingsDialogs import SettingsPanel, NVDASettingsDialog
from gui.message import MessageDialog, ReturnCode
from keyboardHandler import KeyboardInputGesture
from scriptHandler import script
from logHandler import log
from typing import Callable, Dict, List
from typing import Dict, List
from collections.abc import Callable
import locale

from .securityUtils import secureBrowseableMessage # Created by Cyrille (@CyrilleB79)
from ui import browseableMessage


addonHandler.initTranslation()
Expand Down Expand Up @@ -220,13 +221,12 @@ def confirmAdd(self):
text = self.getTextToAdd()
if not text:
return
if gui.message.messageBox(
if MessageDialog(
# Translators: Label of a dialog.
_("Please, confirm if you want to add text to the clipboard"),
# Translators: Title of a dialog.
_("Adding text to clipboard"),
wx.OK | wx.CANCEL
) == wx.OK:
).confirm() == ReturnCode.OK:
if api.copyToClip(text):
# Translators: message presented when the text has been added to the clipboard.
core.callLater(200, ui.message, _("Added"))
Expand All @@ -253,21 +253,20 @@ def performAdd(self):
)
def script_add(self, gesture):
if (
config.conf["clipContentsDesigner"]["confirmToAdd"] and not gui.message.isModalMessageBoxActive()
config.conf["clipContentsDesigner"]["confirmToAdd"]
and self.requiredFormatInClip()
):
wx.CallAfter(self.confirmAdd)
else:
self.performAdd()

def confirmClear(self):
if gui.message.messageBox(
if MessageDialog(
# Translators: Label of a dialog.
_("Please, confirm if you want to clear the clipboard"),
# Translators: Title of a dialog.
_("Clearing clipboard"),
wx.OK | wx.CANCEL
) != wx.OK:
).confirm() != ReturnCode.OK:
return
self.clearClipboard()

Expand All @@ -279,7 +278,6 @@ def confirmClear(self):
def script_clear(self, gesture):
if (
config.conf["clipContentsDesigner"]["confirmToClear"]
and not gui.message.isModalMessageBoxActive()
):
wx.CallAfter(self.confirmClear)
else:
Expand All @@ -296,13 +294,12 @@ def copy(self):
gesture.send()

def confirmCopy(self):
if gui.message.messageBox(
if MessageDialog(
# Translators: Label of a dialog.
_("Please, confirm if you want to copy to the clipboard"),
# Translators: Title of a dialog.
_("Copying to clipboard"),
wx.OK | wx.CANCEL
) != wx.OK:
).confirm() != ReturnCode.OK:
return
core.callLater(200, self.copy)

Expand All @@ -313,7 +310,6 @@ def confirmCopy(self):
def script_copy(self, gesture):
if (
config.conf["clipContentsDesigner"]["confirmToCopy"]
and not gui.message.isModalMessageBoxActive()
and self.requiredFormatInClip()
):
wx.CallAfter(self.confirmCopy)
Expand All @@ -325,13 +321,12 @@ def cut(self):
KeyboardInputGesture.fromName(keyName).send()

def confirmCut(self):
if gui.message.messageBox(
if MessageDialog(
# Translators: Label of a dialog.
_("Please, confirm if you want to cut from the clipboard"),
# Translators: Title of a dialog.
_("Cutting from clipboard"),
wx.OK | wx.CANCEL
) != wx.OK:
).confirm() != ReturnCode.OK:
return
core.callLater(200, self.cut)

Expand All @@ -342,7 +337,6 @@ def confirmCut(self):
def script_cut(self, gesture):
if (
config.conf["clipContentsDesigner"]["confirmToCut"]
and not gui.message.isModalMessageBoxActive()
and self.requiredFormatInClip()
):
wx.CallAfter(self.confirmCut)
Expand Down Expand Up @@ -378,12 +372,12 @@ def script_showClipboardText(self, gesture):
browseableText = "<pre>%s</pre>" % text.strip()[:maxLength]
else:
browseableText = text.strip()[:maxLength]
secureBrowseableMessage(
browseableMessage(
browseableText,
# Translators: title of a browseable message.
_("Clipboard text ({max}/{current} - {formatForTitle})".format(
max=maxLength, current=len(text), formatForTitle=BROWSEABLETEXT_FORMATS[format]
)), html)
)), html, closeButton=True)

@script(
# Translators: message presented in input mode.
Expand All @@ -409,12 +403,12 @@ def script_showClipboardRawText(self, gesture):
else:
maxLength = len(text)
browseableText = text.strip()[:maxLength]
secureBrowseableMessage(
browseableMessage(
browseableText,
# Translators: title of a browseable message.
_("Clipboard text ({max}/{current} - {formatForTitle})".format(
max=maxLength, current=len(text), formatForTitle=RAW_TEXT
)), False)
)), False, closeButton=True)


class AddonSettingsPanel(SettingsPanel):
Expand Down
46 changes: 0 additions & 46 deletions addon/globalPlugins/clipContentsDesigner/securityUtils.py

This file was deleted.

11 changes: 4 additions & 7 deletions addon/installTasks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# -*- coding: UTF-8 -*-
# installTasks for clipContentsDesigner add-on
# Copyright (C) 2017-2022 Noelia Ruiz Martínez
# Copyright (C) 2017-2025 Noelia Ruiz Martínez
# Released under GPL 2

import wx

import addonHandler
import gui
import inputCore
import config
from gui import MessageDialog, ReturnCode

addonHandler.initTranslation()

Expand Down Expand Up @@ -38,15 +36,14 @@ def onInstall():
inputCore.manager.userGestureMap.remove(cutGesture, module, className, cutScriptName)
except ValueError:
pass
if gui.message.messageBox(
if MessageDialog.ask(
# Translators: label of a dialog.
_("""This add-on allows to confirm if you want to copy and cut, replacing the clipboard contents,
when pressing control+c and control+x. This is named Emulate copy and cut.
Do you want to configure Emulate copy and cut now? You may do or change this later."""),
# Translators: title of a dialog.
_("Configure Emulate copy and cut"),
wx.YES | wx.NO | wx.ICON_WARNING
) == wx.YES:
) == ReturnCode.YES:
config.conf.spec["clipContentsDesigner"] = confspec
config.conf["clipContentsDesigner"]["confirmToCopy"] = True
config.conf["clipContentsDesigner"]["confirmToCut"] = True
Expand Down
4 changes: 2 additions & 2 deletions buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
# Documentation file name
"addon_docFileName": "readme.html",
# Minimum NVDA version supported (e.g. "2018.3")
"addon_minimumNVDAVersion": "2023.2",
"addon_minimumNVDAVersion": "2025.1",
# Last NVDA version supported/tested (e.g. "2018.4", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion": "2024.4",
"addon_lastTestedNVDAVersion": "2025.1",
# Add-on update channel (default is stable or None)
"addon_updateChannel": None,
}
Expand Down

0 comments on commit 21e8228

Please sign in to comment.