From 92a68edb7e19bce5acfe60056c3cef7c3918e5b8 Mon Sep 17 00:00:00 2001 From: Luke Davis Date: Wed, 17 Apr 2024 06:55:42 -0400 Subject: [PATCH] Setup basic repo structure and files. --- .github/workflows/build_addon.yml | 29 ++-- .../check-for-extended-ascii-and-utf-bom.yaml | 33 +++++ .github/workflows/lint.yaml | 29 ++++ .github/workflows/mergeTranslations.yaml | 26 ++++ _template_addon_release.json | 29 ---- addon/globalPlugins/ignoreKeys.py | 76 ++++++++++ buildVars.py | 26 ++-- readme.md | 135 +----------------- 8 files changed, 197 insertions(+), 186 deletions(-) create mode 100644 .github/workflows/check-for-extended-ascii-and-utf-bom.yaml create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/mergeTranslations.yaml delete mode 100644 _template_addon_release.json create mode 100644 addon/globalPlugins/ignoreKeys.py diff --git a/.github/workflows/build_addon.yml b/.github/workflows/build_addon.yml index 9b97cd9..79c1112 100644 --- a/.github/workflows/build_addon.yml +++ b/.github/workflows/build_addon.yml @@ -1,30 +1,31 @@ name: build addon +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: tags: ["*"] # To build on main/master branch, uncomment the following line: - # branches: [ main , master ] + #branches: [ main, master, prime ] pull_request: - branches: [ main, master ] + branches: [ main, master, prime ] workflow_dispatch: jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 - run: echo -e "pre-commit\nscons\nmarkdown">requirements.txt - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.11 cache: 'pip' - name: Install dependencies @@ -38,19 +39,23 @@ jobs: run: export SKIP=no-commit-to-branch; pre-commit run --all - name: building addon - run: scons + run: | + scons + scons pot - uses: actions/upload-artifact@v3 with: name: packaged_addon - path: ./*.nvda-addon + path: | + ./*.nvda-addon + ./*.pot upload_release: runs-on: ubuntu-latest if: ${{ startsWith(github.ref, 'refs/tags/') }} needs: ["build"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: download releases files uses: actions/download-artifact@v3 - name: Display structure of downloaded files @@ -59,6 +64,8 @@ jobs: - name: Release uses: softprops/action-gh-release@v1 with: - files: packaged_addon/*.nvda-addon + files: | + packaged_addon/*.nvda-addon + packaged_addon/*.pot fail_on_unmatched_files: true prerelease: ${{ contains(github.ref, '-') }} diff --git a/.github/workflows/check-for-extended-ascii-and-utf-bom.yaml b/.github/workflows/check-for-extended-ascii-and-utf-bom.yaml new file mode 100644 index 0000000..e4090cc --- /dev/null +++ b/.github/workflows/check-for-extended-ascii-and-utf-bom.yaml @@ -0,0 +1,33 @@ +name: Check that we dont have extended ascii or utf boms in our files + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - master + - main + - prime + pull_request: + branches: + - master + - main + - prime + +jobs: + extendedAsciiAndBom: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: check for files known to cause problems + run: find . -type f | grep -vP "^./.git" | xargs file | grep -iP "bom|extended|iso" + - name: + if: failure() + uses: unsplash/comment-on-pr@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + msg: "Please note that this push or pull request seems to contain files other than ascii or utf8 without bom." diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..3b9b3b2 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,29 @@ +name: Lint + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: [push, pull_request] +# push: +# branches: +# - master +# pull_request: +# branches: +# - master + +jobs: + lint: + runs-on: windows-latest + steps: + + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: pip install -r requirements.txt + - name: Lint + run: flake8 addon diff --git a/.github/workflows/mergeTranslations.yaml b/.github/workflows/mergeTranslations.yaml new file mode 100644 index 0000000..1e0a83d --- /dev/null +++ b/.github/workflows/mergeTranslations.yaml @@ -0,0 +1,26 @@ +# https://crontab.guru/crontab.5.html + +name: Check for and merge l10n updates + +on: + workflow_dispatch: + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '08 00 * * 6' # At 00:08 on Saturdays + +jobs: + update-translations: + runs-on: windows-latest + steps: + - name: Checkout master + uses: actions/checkout@v3 + - name: Merge changes + run: | + git config --global user.name github-actions + git config --global user.email github-actions@github.com + git pull + git remote add l10n https://github.com/nvdaaddons/speechLogger + git fetch l10n + git merge -q --ff -m "Translations automerge" l10n/stable + git push + diff --git a/_template_addon_release.json b/_template_addon_release.json deleted file mode 100644 index c6d3a5f..0000000 --- a/_template_addon_release.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "addonId": "easyAddonTech.XYZ", - "addonVersionNumber": { - "major": 21, - "minor": 6, - "patch": 0 - }, - "addonVersionName": "21.06", - "displayName": "My addon", - "publisher": "easyAddonTech", - "description": "Makes doing XYZ easier", - "homepage": "https://github.com/nvaccess/addon-datastore", - "minNVDAVersion": { - "major": 2019, - "minor": 3, - "patch": 0 - }, - "lastTestedVersion": { - "major": 2020, - "minor": 4, - "patch": 0 - }, - "channel": "beta", - "URL": "https://github.com/nvaccess/addon-datastore/releases/download/v0.1.0/myAddon.nvda-addon", - "sha256": "69D84CA8899800A5575CE31798293CD4FEBAB1D734A07C2E51E56A28E0DF8C82", - "sourceURL": "https://github.com/nvaccess/addon-datastore/", - "license": "GPL v2", - "licenseURL": "https://github.com/nvaccess/addon-datastore/license.MD" -} diff --git a/addon/globalPlugins/ignoreKeys.py b/addon/globalPlugins/ignoreKeys.py new file mode 100644 index 0000000..832aff3 --- /dev/null +++ b/addon/globalPlugins/ignoreKeys.py @@ -0,0 +1,76 @@ +# Ignore special keys +# Originally a private add-on by Tyler Spivey , on behalf of Sarah k Alawami +# With a subsequent rewrite and expansion by Luke Davis . +# Copyright (c) 2023-2024, Sarah k Alawami, Luke Davis, all rights reserved. + +import config +import gui +import ui +import addonHandler +import globalPluginHandler +import keyboardHandler +import tones +import winUser +import winInputHook +from scriptHandler import script +from logHandler import log +from globalCommands import SCRCAT_TOOLS + + +addonHandler.initTranslation() +globalPluginPointer: Optional[globalPluginHandler.GlobalPlugin] = None + +config.conf.spec["ignoreSpecialKeys"] = { + "resetSelectedLockKeys": "boolean(default=True)", + "keyGroup": "integer(default=0)", +} + +class GlobalPlugin(globalPluginHandler.GlobalPlugin): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.patched = False + global globalPluginPointer + globalPluginPointer = self + + def patch(self): + if self.patched: + return + else: + self.old_fn = keyboardHandler.internal_keyDownEvent + keyboardHandler.internal_keyDownEvent = internal_keyDownEvent + winInputHook.keyDownCallback = internal_keyDownEvent + self.patched = True + tones.beep(1000, 100) + + def unpatch(self, shouldBeep: bool = True): + if self.patched: + keyboardHandler.internal_keyDownEvent = self.old_fn + winInputHook.keyDownCallback = self.old_fn + self.patched = False + if shouldBeep: + tones.beep(700, 100) + + def terminate(self): + self.unpatch(False) + + @script( + description="Toggle to keep NVDA from intercepting foot pedal keys. Press again to restore normal keyboard.", + gesture="kb:NVDA+shift+f8", + category=SCRCAT_TOOLS + ) + def script_patch(self, gesture): + if self.patched: + self.unpatch() + else: + self.patch() + +def internal_keyDownEvent(vkCode, scanCode, extended, injected): + if ( + vkCode == winUser.VK_PAUSE + or vkCode == winUser.VK_CANCEL + or vkCode == winUser.VK_SCROLL + ): + return True + else: + return globalPluginPointer.old_fn(vkCode, scanCode, extended, injected) diff --git a/buildVars.py b/buildVars.py index 73ae47e..3b19631 100644 --- a/buildVars.py +++ b/buildVars.py @@ -16,37 +16,37 @@ def _(arg): # Add-on information variables addon_info = { # add-on Name/identifier, internal for NVDA - "addon_name": "addonTemplate", + "addon_name": "ignoreKeys", # Add-on summary, usually the user visible name of the addon. # Translators: Summary for this add-on # to be shown on installation and add-on information found in Add-ons Manager. - "addon_summary": _("Add-on user visible name"), + "addon_summary": _("Ignore Keys"), # Add-on description # Translators: Long description to be shown for this add-on on add-on information from add-ons manager - "addon_description": _("""Description for the add-on. -It can span multiple lines."""), + "addon_description": _("""An NVDA add-on which causes the chosen keys (for example: pause, break, F12) to be completely ignored by NVDA when the add-on is set to active mode. +Includes optional resetting of lock keys under certain circumstances."""), # version - "addon_version": "x.y", + "addon_version": "24.0.0", # Author(s) - "addon_author": "name ", + "addon_author": "Luke Davis , Sarah K Alawami , Tyler Spivey ", # URL for the add-on documentation support - "addon_url": None, + "addon_url": "https://github.com/opensourcesys/ignoreKeys/blob/master/readme.md#readme", # URL for the add-on repository where the source code can be found - "addon_sourceURL": None, + "addon_sourceURL": "https://github.com/opensourcesys/ignoreKeys", # Documentation file name "addon_docFileName": "readme.html", # Minimum NVDA version supported (e.g. "2018.3.0", minor version is optional) - "addon_minimumNVDAVersion": None, + "addon_minimumNVDAVersion": "2022.1.0", # Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version) - "addon_lastTestedNVDAVersion": None, + "addon_lastTestedNVDAVersion": "2024.1", # Add-on update channel (default is None, denoting stable releases, # and for development releases, use "dev".) # Do not change unless you know what you are doing! "addon_updateChannel": None, # Add-on license such as GPL 2 - "addon_license": None, + "addon_license": "GPL 2", # URL for the license document the ad-on is licensed under - "addon_licenseURL": None, + "addon_licenseURL": "https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html", } # Define the python files that are the sources of your add-on. @@ -57,7 +57,7 @@ def _(arg): # pythonSources = ["addon/globalPlugins/*.py"] # For more information on SCons Glob expressions please take a look at: # https://scons.org/doc/production/HTML/scons-user/apd.html -pythonSources = [] +pythonSources = ["addon/globalPlugins/*.py"] # Files that contain strings for translation. Usually your python sources i18nSources = pythonSources + ["buildVars.py"] diff --git a/readme.md b/readme.md index a6bdbd2..d321044 100644 --- a/readme.md +++ b/readme.md @@ -1,135 +1,4 @@ -# NVDA Add-on Scons Template # +# Ignore Keys -This package contains a basic template structure for NVDA add-on development, building, distribution and localization. -For details about NVDA add-on development, please see the [NVDA Add-on Development Guide](https://github.com/nvdaaddons/DevGuide/wiki/NVDA-Add-on-Development-Guide). -The NVDA add-on development/discussion list [is here](https://nvda-addons.groups.io/g/nvda-addons) -Information specific to NV Access add-on store [can be found here](https://github.com/nvaccess/addon-datastore). +Documentation coming soon. -Copyright (C) 2012-2023 NVDA Add-on team contributors. - -This package is distributed under the terms of the GNU General Public License, version 2 or later. Please see the file COPYING.txt for further details. - - - -[alekssamos](https://github.com/alekssamos/) added automatic package of add-ons through Github Actions. - -For details about Github Actions please see the [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions). - -Copyright (C) 2022 alekssamos - - -## Features - -This template provides the following features you can use during NVDA add-on development and packaging: - -* Automatic add-on package creation, with naming and version loaded from a centralized build variables file (buildVars.py) or command-line interface. - * See packaging section for details on using command-line switches when packaging add-ons with custom version information. - * This process will happen automatically when receiving a pull request, and there is also the possibility of manual launch. - * To let the workflow run automatically when pushing to main or master (development) branch, remove the comment for branches line in GitHub Actions (`.github/workflows/build_addon.yml`). - * If you have created a tag (E.G.: `git tag v1.0 && git push --tag`), then a release will be automatically created and the add-on file will be uploaded as an asset. - * Otherwise, with normal commits or with manual startup, you can download the artifacts from the Actions page of your repository. -* Manifest file creation using a template (manifest.ini.tpl). Build variables are replaced on this template. See below for add-on manifest specification. -* Compilation of gettext mo files before distribution, when needed. - * To generate a gettext pot file, please run `scons pot`. An `addon-name.pot` file will be created with all gettext messages for your add-on. You need to check the `buildVars.i18nSources` variable to comply with your requirements. -* Automatic generation of manifest localization files directly from gettext po files. Please make sure buildVars.py is included in i18nFiles. -* Automatic generation of HTML documents from markdown (.md) files, to manage documentation in different languages. -* Automatic generation of entries for NV Access add-on store (json format). - -In addition, this template includes configuration files for the following tools for use in add-on development and testing (see "additional tools" section for details): - -* Flake8 (flake8.ini): a base configuration file for Flake8 linting tool based on NVDA's own Flake8 configuration file. -* Configuration for VS Code. It requires NVDA's repo at the same level as the add-on folder containing your actual source files, with prepared source code (`scons source`). preparing the source code is a step in the instructions for building NVDA itself, see [The NVDA Repository](https://github.com/nvaccess/nvda) for details. - * Place the .vscode in this repo within the addon folder, where your add-on source files (will) reside. The settings file within this folder assumes the NVDA repository is within the parent folder of this folder. If your addon folder is within the addonTemplate folder, then your NVDA repository folder needs to also be within the addonTemplate folder, or the source will not be found. - * Open the addon folder in VS Code. This should initialize VS Code with the correct settings and provide you with code completion and other VS Code features. - * Press `control+shift+m` after saving a file to search for problems. - * Use arrow and tab keys for the autocompletion feature. - * Press `control+shift+p` to open the commands palette and search for recommended extensions to install or check if they are installed. - -## Requirements - -You need the following software to use this code for your NVDA add-on development and packaging: - -* a Python distribution (3.7 or later is recommended). Check the [Python Website](https://www.python.org) for Windows Installers. Please note that at present, preparing the NVDA source code requires the 32-bit version of Python 3.7. -* Scons - [Website](https://www.scons.org/) - version 4.3.0 or later. You can install it via PIP. -* GNU Gettext tools, if you want to have localization support for your add-on - Recommended. Any Linux distro or cygwin have those installed. You can find windows builds [here](https://gnuwin32.sourceforge.net/downlinks/gettext.php). -* Markdown 3.3.0 or later, if you want to convert documentation files to HTML documents. You can install it via PIP. - -Note, that you may not need these tools in a local build environment, if you are using [Appveyor](https://appveyor.com/) or [GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions), to build and package your add-ons. - -## Usage - -### To create a new NVDA add-on using this template: - -1. Create an empty folder to hold the files for your add-on. -2. Copy the folder: -``` -site_scons -``` -and the following files, into your new empty folder: -``` -buildVars.py -manifest.ini.tpl -manifest-translated.ini.tpl -sconstruct -.gitignore -.gitattributes -``` -3. If you intend to use the provided GitHub workflow, also copy the folder: -``` -.github -``` -and file: -``` -.pre-commit-config.yaml -``` -4. Create an `addon` folder inside your new folder. You will put your code in the usual folders for NVDA extensions, under the `addon` folder. For instance: `globalPlugins`, `synthDrivers`, etc. -5. In the `buildVars.py` file, change variable `addon_info` with your add-on's information (name, summary, description, version, author, url, source url, license, and license URL). Also, be sure to carefully set the paths contained in the other variables in that file. -6. Gettext translations must be placed into `addon\locale\/LC_MESSAGES\nvda.po`. - -#### Add-on manifest specification - -An add-on manifest generated manually or via `buildVars.py` must include the following information: - -* Name (string): a unique identifier for the add-on. It must use camel case (e.g. someModule). This is also used as part of add-on store to identify the add-on uniquely. -* Summary (string): name as shown on NVDA's Add-ons Manager. -* Description (string): a short detailed description about the add-on. -* Version (string), ideally number.number with an optional third number, denoting major.minor.patch. -* Author (string and an email address): one or more add-on author contact information in the form "name ". -* URL (string): a web address where the add-on information can be found (typically community add-ons website address (https://addons.nvda-project.org) is used). -* docFileName (string): name of the documentation file. -* minimumNVDAVersion (year.major or year.major.minor): the earliest version of NVDA the add-on is compatible with (e.g. 2019.3). Add-ons are expected to use features introduced in this version of NVDA or declare compatibility with it. -* lastTestedNVDAVersion (year.major or year.major.minor): the latest or last tested version of NVDA the add-on is said to be compatible with (e.g. 2020.3). Add-on authors are expected to declare this value after testing add-ons with the version of NVDA specified. -* addon_updateChannel (string or None): the update channel for the add-on release. - -In addition, the following information must be filled out (not used in the manifest but used elsewhere such as add-on store): - -* sourceURL (string): repository URL for the add-on source code. -* license (string): the license of the add-on and its source code. -* licenseURL: the URL for the license file. - -### To manage documentation files for your addon: - -1. Copy the `readme.md` file for your add-on to the first created folder, where you copied `buildVars.py`. You can also copy `style.css` to improve the presentation of HTML documents. -2. Documentation files (named `readme.md`) must be placed into `addon\doc\/`. - -### To package the add-on for distribution: - -1. Open a command line, change to the folder that has the `sconstruct` file (usually the root of your add-on development folder) and run the `scons` command. The created add-on, if there were no errors, is placed in the current directory. -2. You can further customize variables in the `buildVars.py` file. -3. You can also customize version and update channel information from command line by passing the following switches when running scons: - * version: add-on version string. - * versionNumber: add-on version number of the form major.minor.patch (all integers) - * channel: update channel (do not use this switch unless you know what you are doing). - * dev: suitable for development builds, names the add-on according to current date (yyyymmdd) and sets update channel to "dev". - -### Additional tools - -The template includes configuration files for use with additional tools such as linters. These include: - -* Flake8 (flake8.ini): a Python code linter (3.7.9 or later, can be installed with PIP). - -Read the documentation for the tools you wish to use when building and developing add-ons. - -Note that this template only provides a basic add-on structure and build infrastructure. You may need to adapt it for your specific needs such as using additional tools. - -If you have any issues please use the NVDA addon list mentioned above.