mirror of
https://github.com/SeedSigner/seedsigner.git
synced 2026-10-05 15:08:25 +00:00
Merge branch 'dev' into update-docs
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
name: GitHub Notify on Telegram
|
||||
on:
|
||||
pull_request_target:
|
||||
branches:
|
||||
- dev
|
||||
types:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
if_merged:
|
||||
if: github.event.pull_request.merged == true
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Notify on Telegram
|
||||
uses: EverythingSuckz/github-telegram-notify@main
|
||||
with:
|
||||
bot_token: '${{ secrets.BOT_TOKEN }}'
|
||||
chat_id: '${{ secrets.CHAT_ID }}'
|
||||
@@ -2,9 +2,6 @@ name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
|
||||
@@ -111,24 +111,25 @@ Instructions to build a SeedSigner OS image (using precisely the same process th
|
||||
|
||||
## Downloading the Software
|
||||
|
||||
Download the current Version (0.8.5) software image that is compatible with your Raspberry Pi Hardware. The Pi Zero 1.3 is the most common and recommended board.
|
||||
|
||||
Download the current Version (0.8.6) software image that is compatible with your Raspberry Pi Hardware. The Pi Zero 1.3 is the most common and recommended board.
|
||||
| Board | Download Image Link/Name |
|
||||
| --------------------- | --------------------------------- |
|
||||
|**[Raspberry Pi Zero 1.3](https://www.raspberrypi.com/products/raspberry-pi-zero/)** |[`seedsigner_os.0.8.5.pi0.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi0.img) |
|
||||
|[Raspberry Pi Zero W](https://www.raspberrypi.com/products/raspberry-pi-zero-w/) |[`seedsigner_os.0.8.5.pi0.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi0.img) |
|
||||
|[Raspberry Pi Zero 2 W](https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/) |[`seedsigner_os.0.8.5.pi02w.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi02w.img) |
|
||||
|[Raspberry Pi 1 Model B/B+](https://www.raspberrypi.com/products/raspberry-pi-1-model-b-plus/) |[`seedsigner_os.0.8.5.pi0.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi0.img) |
|
||||
|[Raspberry Pi 2 Model B](https://www.raspberrypi.com/products/raspberry-pi-2-model-b/) |[`seedsigner_os.0.8.5.pi2.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi2.img) |
|
||||
|[Raspberry Pi 3 Model B](https://www.raspberrypi.com/products/raspberry-pi-3-model-b/) |[`seedsigner_os.0.8.5.pi02w.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi02w.img) |
|
||||
|[Raspberry Pi 4 Model B](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/) |[`seedsigner_os.0.8.5.pi4.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi4.img) |
|
||||
|[Raspberry Pi 400](https://www.raspberrypi.com/products/raspberry-pi-400-unit/) |[`seedsigner_os.0.8.5.pi4.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner_os.0.8.5.pi4.img) |
|
||||
|**[Raspberry Pi Zero 1.3](https://www.raspberrypi.com/products/raspberry-pi-zero/)** |[`seedsigner_os.0.8.6.pi0.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi0.img) |
|
||||
|[Raspberry Pi Zero W](https://www.raspberrypi.com/products/raspberry-pi-zero-w/) |[`seedsigner_os.0.8.6.pi0.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi0.img) |
|
||||
|[Raspberry Pi Zero 2 W](https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/) |[`seedsigner_os.0.8.6.pi02w.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi02w.img) |
|
||||
|[Raspberry Pi 1 Model B/B+](https://www.raspberrypi.com/products/raspberry-pi-1-model-b-plus/) |[`seedsigner_os.0.8.6.pi0.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi0.img) |
|
||||
|[Raspberry Pi 2 Model B](https://www.raspberrypi.com/products/raspberry-pi-2-model-b/) |[`seedsigner_os.0.8.6.pi2.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi2.img) |
|
||||
|[Raspberry Pi 3 Model B](https://www.raspberrypi.com/products/raspberry-pi-3-model-b/) |[`seedsigner_os.0.8.6.pi02w.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi02w.img) |
|
||||
|[Raspberry Pi 4 Model B](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/) |[`seedsigner_os.0.8.6.pi4.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi4.img) |
|
||||
|[Raspberry Pi 400](https://www.raspberrypi.com/products/raspberry-pi-400-unit/) |[`seedsigner_os.0.8.6.pi4.img`](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner_os.0.8.6.pi4.img) |
|
||||
|
||||
Note: If you have physically removed the WiFi component from your board, you will still use the image file of the original (un-modified) hardware. (Our files are compiled/based on the *processor* architecture). Although it is better to spend a few minutes upfront to determine which specific Pi hardware/model you have, if you are still unsure which hardware you have, you can try using the pi0.img file. Making an incorrect choice here will not ruin your board, because this is software, not firmware.
|
||||
|
||||
**Also download** these 2 signature verification files to the same folder:
|
||||
[The Plaintext manifest file](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner.0.8.5.sha256.txt)
|
||||
[The Signature of the manifest file](https://github.com/SeedSigner/seedsigner/releases/download/0.8.5/seedsigner.0.8.5.sha256.txt.sig)
|
||||
**Also download** these 2 signature verification files to the same folder
|
||||
[The Plaintext manifest file](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner.0.8.6.sha256.txt)
|
||||
[The Signature of the manifest file](https://github.com/SeedSigner/seedsigner/releases/download/0.8.6/seedsigner.0.8.6.sha256.txt.sig)
|
||||
|
||||
|
||||
Users familiar with older versions of the SeedSigner software might be surprised with how fast their software downloads now are, because since version 0.6.0 the software image files are now 100x smaller! Each image file is now under 42 Megabytes so your downloads and verifications will be very quick now (and might even seem *too* quick)!
|
||||
|
||||
@@ -159,7 +160,7 @@ The result should confirm that 1 key was *either* imported or updated. *Ignore*
|
||||
|
||||
Next, you will run the *verify* command on the signature (.sig) file. (*Verify* must be run from inside the same folder that you downloaded the files into earlier.)
|
||||
```
|
||||
gpg --verify seedsigner.0.8.5.sha256.txt.sig
|
||||
gpg --verify seedsigner.0.8.6.sha256.txt.sig
|
||||
```
|
||||
|
||||
When the verify command completes successfully, it should display output like this:
|
||||
@@ -229,21 +230,22 @@ Now that you have confirmed that you do have the real SeedSigner Project's Publi
|
||||
|
||||
**On Linux or OSX:** Run this command
|
||||
```
|
||||
shasum -a 256 --ignore-missing --check seedsigner.0.8.5.sha256.txt
|
||||
shasum -a 256 --ignore-missing --check seedsigner.0.8.6.sha256.txt
|
||||
```
|
||||
Note: macOS versions earlier than v11 (Big Sur) do not support the `--ignore-missing` flag. You can omit it and disregard any missing file warnings.
|
||||
|
||||
**On Windows (inside Powershell):** Run this command
|
||||
```
|
||||
CertUtil -hashfile seedsigner_os.0.8.5.Insert_Your_Pi_Models_binary_here_For_Example_pi02w.img SHA256
|
||||
CertUtil -hashfile seedsigner_os.0.8.6.Insert_Your_Pi_Models_binary_here_For_Example_pi02w.img SHA256
|
||||
```
|
||||
On Windows, you must then manually compare the resulting file hash value to the corresponding hash value shown inside the .SHA256 cleartext file.
|
||||
<BR>
|
||||
|
||||
Wait up to 30 seconds for the command to complete, and it should display:
|
||||
```
|
||||
seedsigner_os.0.8.5.[Your_Pi_Model_For_Example:pi02w].img: OK
|
||||
seedsigner_os.0.8.6.[Your_Pi_Model_For_Example:pi02w].img: OK
|
||||
```
|
||||
**If you receive the "OK" message** for your **seedsigner_os.0.8.5.[Your_Pi_Model_For_Example:pi02w].img file**, as shown above, then your verification is fully complete!
|
||||
**If you receive the "OK" message** for your **seedsigner_os.0.8.6.[Your_Pi_Model_For_Example:pi02w].img file**, as shown above, then your verification is fully complete!
|
||||
**All of your downloaded files have now been confirmed as both authentic and unaltered!** You can proceed to create/write your MicroSD card😄😄 !!
|
||||
|
||||
If your file result shows "FAILED", then you must stop here immediately. Do not continue. Contact us for assistance at the Telegram group address above.
|
||||
|
||||
@@ -75,7 +75,7 @@ You will be prompted to enter the current password ("raspberry") and then to ent
|
||||
# * libsqlite3-dev: required by `coverage`
|
||||
sudo apt update && sudo apt install -y build-essential zlib1g-dev \
|
||||
libncurses5-dev libgdbm-dev libnss3-dev openssl libssl-dev \
|
||||
libreadline-dev libffi-dev wget libsqlite3-dev
|
||||
libreadline-dev libffi-dev wget libsqlite3-dev libraqm-dev
|
||||
|
||||
# Grab the python3.10 source
|
||||
wget https://www.python.org/ftp/python/3.10.10/Python-3.10.10.tgz
|
||||
|
||||
@@ -22,6 +22,8 @@ Specifications for each follow below, as well as discussion of the pros and cons
|
||||
## Quick Review of BIP-39 Mnemonic Seed Phrases
|
||||
The typical method for backing up a Bitcoin wallet is to store its [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase consisting of 12 or 24 words.
|
||||
|
||||
**SeedQR specifically assumes and recommends using the English BIP39 wordlist.** While BIP39 supports multiple language-specific wordlists (e.g., Japanese, Spanish, French), there is no mechanism to specify or detect which language wordlist was used when creating or scanning a SeedQR. Using a non-English wordlist may result in incorrect or invalid seeds.
|
||||
|
||||
Each word comes from a [list of 2048 words](https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt). The words themselves are meaningless; all that matters is the word's position number (aka index) in the word list.
|
||||
|
||||
For example, "tomato" is the 1,825th word in the list.
|
||||
|
||||
+26
-12
@@ -6,9 +6,9 @@
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: seedsigner 0.8.5-rc1\n"
|
||||
"Project-Id-Version: seedsigner 0.8.5\n"
|
||||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
|
||||
"POT-Creation-Date: 2025-01-28 13:28-0600\n"
|
||||
"POT-Creation-Date: 2025-05-20 09:27-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -319,7 +319,6 @@ msgstr ""
|
||||
msgid "Derivation"
|
||||
msgstr ""
|
||||
|
||||
#. Short for "BIP32 Extended Public Key"
|
||||
#: src/seedsigner/gui/screens/seed_screens.py
|
||||
msgid "Xpub"
|
||||
msgstr ""
|
||||
@@ -593,6 +592,11 @@ msgstr ""
|
||||
msgid "Wallet descriptor"
|
||||
msgstr ""
|
||||
|
||||
#. Insert the number of addrs displayed per screen (e.g. "Next 10")
|
||||
#: src/seedsigner/gui/screens/tools_screens.py
|
||||
msgid "Next {}"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/models/settings_definition.py
|
||||
msgid "Enabled"
|
||||
msgstr ""
|
||||
@@ -790,6 +794,17 @@ msgstr ""
|
||||
msgid "Show partner logos"
|
||||
msgstr ""
|
||||
|
||||
#. Hardware settings option to specify the screen driver (e.g. st7789 vs
|
||||
#. ili9341)
|
||||
#: src/seedsigner/models/settings_definition.py
|
||||
msgid "Display type"
|
||||
msgstr ""
|
||||
|
||||
#. Hardware settings option to invert how the screen driver displays colors.
|
||||
#: src/seedsigner/models/settings_definition.py
|
||||
msgid "Invert colors"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/models/settings_definition.py
|
||||
msgid "QR background color"
|
||||
msgstr ""
|
||||
@@ -1254,11 +1269,11 @@ msgid "Review SeedQR"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/seed_views.py
|
||||
msgid "Your transcribed SeedQR successfully scanned and yielded the same seed."
|
||||
msgid "Your transcribed SeedQR could not be read!"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/seed_views.py
|
||||
msgid "Your transcribed SeedQR could not be read!"
|
||||
msgid "Your transcribed SeedQR successfully scanned and yielded the same seed."
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/seed_views.py
|
||||
@@ -1291,11 +1306,15 @@ msgid "Signing messages for custom derivation paths not supported"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/settings_views.py
|
||||
msgid "I/O test"
|
||||
msgid "Advanced"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/settings_views.py
|
||||
msgid "Advanced"
|
||||
msgid "Hardware"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/settings_views.py
|
||||
msgid "I/O test"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/settings_views.py
|
||||
@@ -1399,11 +1418,6 @@ msgstr ""
|
||||
msgid "Single sig descriptors not yet supported"
|
||||
msgstr ""
|
||||
|
||||
#. Insert the number of addrs displayed per screen (e.g. "Next 10")
|
||||
#: src/seedsigner/views/tools_views.py
|
||||
msgid "Next {}"
|
||||
msgstr ""
|
||||
|
||||
#: src/seedsigner/views/tools_views.py
|
||||
msgid "Receive Addrs"
|
||||
msgstr ""
|
||||
|
||||
+4
-3
@@ -13,7 +13,7 @@ description = "Build an offline, airgapped Bitcoin signing device for less than
|
||||
name = "seedsigner"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
version = "0.8.5"
|
||||
version = "0.8.6"
|
||||
|
||||
[project.urls]
|
||||
"Bug Tracker" = "https://github.com/SeedSigner/seedsigner/issues"
|
||||
@@ -22,7 +22,7 @@ Repository = "https://github.com/SeedSigner/seedsigner"
|
||||
|
||||
[tool.coverage.html]
|
||||
directory = "coverage_html_report"
|
||||
skip_covered = false
|
||||
skip_covered = true
|
||||
skip_empty = true
|
||||
|
||||
[tool.coverage.report]
|
||||
@@ -48,8 +48,9 @@ omit = [
|
||||
"*/__init__.py",
|
||||
"*/tests/*",
|
||||
]
|
||||
skip_covered = false
|
||||
skip_covered = true
|
||||
skip_empty = true
|
||||
precision = 2
|
||||
|
||||
[tool.coverage.run]
|
||||
source = ["src"]
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ embit==0.8.0
|
||||
Pillow==10.0.1
|
||||
pyzbar @ git+https://github.com/seedsigner/pyzbar.git@c3c237821c6a20b17953efe59b90df0b514a1c03
|
||||
qrcode==7.3.1
|
||||
urtypes @ git+https://github.com/selfcustody/urtypes.git@7fb280eab3b3563dfc57d2733b0bf5cbc0a96a6a
|
||||
urtypes==1.0.1
|
||||
|
||||
@@ -99,7 +99,7 @@ class Controller(Singleton):
|
||||
rather than at the top in order avoid circular imports.
|
||||
"""
|
||||
|
||||
VERSION = "0.8.5"
|
||||
VERSION = "0.8.6"
|
||||
|
||||
# Declare class member vars with type hints to enable richer IDE support throughout
|
||||
# the code.
|
||||
|
||||
@@ -48,31 +48,32 @@ class GUIConstants:
|
||||
ICON_TOAST_FONT_SIZE = 30
|
||||
ICON_PRIMARY_SCREEN_SIZE = 50
|
||||
|
||||
TOP_NAV_TITLE_FONT_NAME = {
|
||||
"default": "OpenSans-SemiBold",
|
||||
# "ar": "multilanguage/NotoSansAR-Regular",
|
||||
# "he": "multilanguage/NotoSansHE-Regular",
|
||||
# "ja": "multilanguage/NotoSansJP-Regular",
|
||||
# "kr": "multilanguage/NotoSansKR-Regular",
|
||||
# "ru": "multilanguage/NotoSans-Regular",
|
||||
BASE_LOCALE_FONTS = {
|
||||
"default": "OpenSans-Regular",
|
||||
# SettingsConstants.LOCALE__ARABIC: "NotoSansAR-Regular",
|
||||
SettingsConstants.LOCALE__CHINESE_SIMPLIFIED: "NotoSansSC-Regular",
|
||||
# SettingsConstants.LOCALE__CHINESE_TRADITIONAL: "NotoSansTC-Regular",
|
||||
SettingsConstants.LOCALE__JAPANESE: "NotoSansJP-Regular",
|
||||
SettingsConstants.LOCALE__KOREAN: "NotoSansKR-Regular",
|
||||
}
|
||||
|
||||
TOP_NAV_TITLE_FONT_NAME = BASE_LOCALE_FONTS.copy()
|
||||
TOP_NAV_TITLE_FONT_NAME["default"] = "OpenSans-SemiBold"
|
||||
TOP_NAV_TITLE_FONT_SIZE = {
|
||||
"default": 20,
|
||||
SettingsConstants.LOCALE__JAPANESE: 22, # Titles won't render below 22px
|
||||
SettingsConstants.LOCALE__KOREAN: 23, # Titles won't render below 23px
|
||||
SettingsConstants.LOCALE__CHINESE_SIMPLIFIED: 23, # Some chars won't render below 23px
|
||||
}
|
||||
TOP_NAV_HEIGHT = 48
|
||||
TOP_NAV_BUTTON_SIZE = 32
|
||||
|
||||
BODY_FONT_NAME = {
|
||||
"default": "OpenSans-Regular",
|
||||
# "ar": "multilanguage/NotoSansAR-Regular",
|
||||
# "he": "multilanguage/NotoSansHE-Regular",
|
||||
# "ja": "multilanguage/NotoSansJP-Regular",
|
||||
# "kr": "multilanguage/NotoSansKR-Regular",
|
||||
# "ru": "multilanguage/NotoSans-Regular",
|
||||
}
|
||||
BODY_FONT_NAME = BASE_LOCALE_FONTS.copy()
|
||||
BODY_FONT_SIZE = {
|
||||
"default": 17,
|
||||
# "ar": 16,
|
||||
SettingsConstants.LOCALE__JAPANESE: 18,
|
||||
SettingsConstants.LOCALE__KOREAN: 18,
|
||||
SettingsConstants.LOCALE__CHINESE_SIMPLIFIED: 18,
|
||||
}
|
||||
BODY_FONT_MAX_SIZE = TOP_NAV_TITLE_FONT_SIZE["default"]
|
||||
BODY_FONT_MIN_SIZE = 15
|
||||
@@ -85,18 +86,14 @@ class GUIConstants:
|
||||
LABEL_FONT_SIZE = BODY_FONT_MIN_SIZE
|
||||
LABEL_FONT_COLOR = "#777777"
|
||||
|
||||
BUTTON_FONT_NAME = {
|
||||
"default": "OpenSans-SemiBold",
|
||||
# "ar": "multilanguage/NotoSansAR-Regular",
|
||||
# "he": "multilanguage/NotoSansHE-Regular",
|
||||
# "ja": "multilanguage/NotoSansJP-Regular",
|
||||
# "kr": "multilanguage/NotoSansKR-Regular",
|
||||
# "ru": "multilanguage/NotoSans-Regular",
|
||||
}
|
||||
BUTTON_FONT_NAME = BASE_LOCALE_FONTS.copy()
|
||||
BUTTON_FONT_NAME["default"] = "OpenSans-SemiBold"
|
||||
BUTTON_FONT_SIZE = {
|
||||
"default": 18,
|
||||
# "ar": 16,
|
||||
# "ja": 16,
|
||||
SettingsConstants.LOCALE__JAPANESE: 20,
|
||||
SettingsConstants.LOCALE__KOREAN: 20,
|
||||
SettingsConstants.LOCALE__CHINESE_SIMPLIFIED: 20,
|
||||
}
|
||||
BUTTON_FONT_COLOR = "#FCFCFC"
|
||||
BUTTON_BACKGROUND_COLOR = "#2C2C2C"
|
||||
@@ -107,7 +104,8 @@ class GUIConstants:
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_body_font_name():
|
||||
def get_body_font_name(locale=None):
|
||||
if not locale:
|
||||
locale = Settings.get_instance().get_value(SettingsConstants.SETTING__LOCALE)
|
||||
if locale in GUIConstants.BODY_FONT_NAME:
|
||||
return GUIConstants.BODY_FONT_NAME[locale]
|
||||
@@ -116,7 +114,8 @@ class GUIConstants:
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_body_font_size():
|
||||
def get_body_font_size(locale=None):
|
||||
if not locale:
|
||||
locale = Settings.get_instance().get_value(SettingsConstants.SETTING__LOCALE)
|
||||
if locale in GUIConstants.BODY_FONT_SIZE:
|
||||
return GUIConstants.BODY_FONT_SIZE[locale]
|
||||
@@ -143,7 +142,8 @@ class GUIConstants:
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_button_font_name():
|
||||
def get_button_font_name(locale=None):
|
||||
if not locale:
|
||||
locale = Settings.get_instance().get_value(SettingsConstants.SETTING__LOCALE)
|
||||
if locale in GUIConstants.BUTTON_FONT_NAME:
|
||||
return GUIConstants.BUTTON_FONT_NAME[locale]
|
||||
@@ -152,7 +152,8 @@ class GUIConstants:
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_button_font_size():
|
||||
def get_button_font_size(locale=None):
|
||||
if not locale:
|
||||
locale = Settings.get_instance().get_value(SettingsConstants.SETTING__LOCALE)
|
||||
if locale in GUIConstants.BUTTON_FONT_SIZE:
|
||||
return GUIConstants.BUTTON_FONT_SIZE[locale]
|
||||
@@ -431,10 +432,6 @@ class TextArea(BaseComponent):
|
||||
self.text_y = self.text_height_above_baseline
|
||||
|
||||
self.visible_width = self.width - max(self.edge_padding, self.min_text_x) - self.edge_padding
|
||||
if not ImageFont.core.HAVE_RAQM:
|
||||
# Fudge factor for imprecise width calcs w/out libraqm
|
||||
full_text_width = int(full_text_width * 1.05)
|
||||
self.visible_width = int(self.visible_width * 1.05)
|
||||
|
||||
if self.is_horizontal_scrolling_enabled or not self.auto_line_break:
|
||||
# Guaranteed to be a single line of text, possibly wider than self.width
|
||||
@@ -474,9 +471,9 @@ class TextArea(BaseComponent):
|
||||
# Multiply for the number of lines plus the spacer
|
||||
total_text_height = self.text_height_above_baseline * len(self.text_lines) + self.line_spacing * (len(self.text_lines) - 1)
|
||||
|
||||
if not self.height_ignores_below_baseline and re.findall(f"[gjpqy]", self.text_lines[-1]["text"]):
|
||||
# Last line has at least one char that dips below baseline
|
||||
total_text_height += self.text_height_below_baseline
|
||||
if not self.height_ignores_below_baseline:
|
||||
# Account for the last line possibly rendering below baseline
|
||||
total_text_height += self.text_lines[-1].get("px_below_baseline", 0)
|
||||
|
||||
self.text_offset_y = 0
|
||||
if self.height is None:
|
||||
@@ -581,17 +578,13 @@ class TextArea(BaseComponent):
|
||||
|
||||
# Crop off the top_padding and resize the result down to onscreen size
|
||||
if self.supersampling_factor > 1:
|
||||
resized = img.resize((image_width, total_text_height + 2*resample_padding), Image.LANCZOS)
|
||||
resized = img.resize((image_width, total_text_height + 2*resample_padding), Image.Resampling.LANCZOS)
|
||||
sharpened = resized.filter(ImageFilter.SHARPEN)
|
||||
|
||||
img = sharpened.crop((0, resample_padding, image_width, resample_padding + total_text_height))
|
||||
|
||||
self.rendered_text_img = img
|
||||
|
||||
if not ImageFont.core.HAVE_RAQM:
|
||||
# At this point we need the visible_width to be the "actual" (yet still incorrect) width
|
||||
self.visible_width = int(self.visible_width * 0.95)
|
||||
|
||||
self.horizontal_text_scroll_thread: TextArea.HorizontalTextScrollThread = None
|
||||
if self.is_horizontal_scrolling_enabled:
|
||||
self.horizontal_text_scroll_thread = TextArea.HorizontalTextScrollThread(
|
||||
@@ -1359,8 +1352,12 @@ class Button(BaseComponent):
|
||||
text_y_offset: int = 0
|
||||
background_color: str = GUIConstants.BUTTON_BACKGROUND_COLOR
|
||||
selected_color: str = GUIConstants.ACCENT_COLOR
|
||||
|
||||
# Cannot define these class attrs w/the get_*_font_*() methods because the attrs will
|
||||
# not be dynamically reinterpreted after initial class import.
|
||||
font_name: str = None
|
||||
font_size: int = None
|
||||
|
||||
font_color: str = GUIConstants.BUTTON_FONT_COLOR
|
||||
selected_font_color: str = GUIConstants.BUTTON_SELECTED_FONT_COLOR
|
||||
outline_color: str = None
|
||||
@@ -1673,8 +1670,12 @@ class TopNav(BaseComponent):
|
||||
background_color: str = GUIConstants.BACKGROUND_COLOR
|
||||
icon_name: str = None
|
||||
icon_color: str = GUIConstants.BODY_FONT_COLOR
|
||||
font_name: str = GUIConstants.get_top_nav_title_font_name()
|
||||
font_size: int = GUIConstants.get_top_nav_title_font_size()
|
||||
|
||||
# Cannot define these class attrs w/the get_*_font_*() methods because the attrs will
|
||||
# not be dynamically reinterpreted after initial class import.
|
||||
font_name: str = None
|
||||
font_size: int = None
|
||||
|
||||
font_color: str = GUIConstants.BODY_FONT_COLOR
|
||||
show_back_button: bool = True
|
||||
show_power_button: bool = False
|
||||
@@ -1687,7 +1688,6 @@ class TopNav(BaseComponent):
|
||||
|
||||
if not self.font_size:
|
||||
self.font_size = GUIConstants.get_top_nav_title_font_size()
|
||||
print(f"self.font_size: {self.font_size}")
|
||||
|
||||
super().__post_init__()
|
||||
if not self.width:
|
||||
@@ -1833,24 +1833,31 @@ def reflow_text_for_width(text: str,
|
||||
# font.
|
||||
font = Fonts.get_font(font_name=font_name, size=font_size)
|
||||
# Measure from left baseline ("ls")
|
||||
(left, top, full_text_width, bottom) = font.getbbox(text, anchor="ls")
|
||||
(left, top, full_text_width, px_below_baseline) = font.getbbox(text, anchor="ls")
|
||||
|
||||
if not ImageFont.core.HAVE_RAQM:
|
||||
# Fudge factor for imprecise width calcs w/out libraqm
|
||||
full_text_width = int(full_text_width * 1.05)
|
||||
# Assume we can break Asian text on any character
|
||||
treat_chars_as_words = Settings.get_instance().get_value(SettingsConstants.SETTING__LOCALE) in [
|
||||
SettingsConstants.LOCALE__CHINESE_SIMPLIFIED,
|
||||
SettingsConstants.LOCALE__CHINESE_TRADITIONAL,
|
||||
SettingsConstants.LOCALE__JAPANESE,
|
||||
SettingsConstants.LOCALE__KOREAN,
|
||||
]
|
||||
if treat_chars_as_words:
|
||||
# Relax UI constraints even if the result isn't optimal
|
||||
allow_text_overflow = True
|
||||
|
||||
# Stores each line of text and its rendering starting x-coord
|
||||
text_lines = []
|
||||
def _add_text_line(text, text_width):
|
||||
text_lines.append({"text": text, "text_width": text_width})
|
||||
def _add_text_line(text, text_width, px_below_baseline):
|
||||
text_lines.append(dict(text=text, text_width=text_width, px_below_baseline=px_below_baseline))
|
||||
|
||||
if "\n" not in text and full_text_width < width:
|
||||
# The whole text fits on one line
|
||||
_add_text_line(text, full_text_width)
|
||||
_add_text_line(text, full_text_width, px_below_baseline)
|
||||
|
||||
else:
|
||||
# Have to calc how to break text into multiple lines
|
||||
def _binary_len_search(min_index, max_index):
|
||||
def _binary_len_search(min_index, max_index, word_spacer):
|
||||
# Try the middle of the range
|
||||
index = math.ceil((max_index + min_index) / 2)
|
||||
if index == 0:
|
||||
@@ -1858,13 +1865,9 @@ def reflow_text_for_width(text: str,
|
||||
index = 1
|
||||
|
||||
# Measure rendered width from "left" anchor (anchor="l_")
|
||||
(left, top, right, bottom) = font.getbbox(" ".join(words[0:index]), anchor="ls")
|
||||
(left, top, right, px_below_baseline) = font.getbbox(word_spacer.join(words[0:index]), anchor="ls")
|
||||
line_width = right - left
|
||||
|
||||
if not ImageFont.core.HAVE_RAQM:
|
||||
# Fudge factor for imprecise width calcs w/out libraqm
|
||||
line_width = int(line_width * 1.05)
|
||||
|
||||
if line_width >= width:
|
||||
# Candidate line is still too long. Restrict search range down.
|
||||
if min_index + 1 == index:
|
||||
@@ -1872,33 +1875,50 @@ def reflow_text_for_width(text: str,
|
||||
# It's just one long, unbreakable word. There's no good
|
||||
# solution here. Just accept it as is and let it render off
|
||||
# the edges.
|
||||
return (index, line_width)
|
||||
return (index, line_width, px_below_baseline)
|
||||
else:
|
||||
# There's still room to back down the min_index in the next
|
||||
# round.
|
||||
index -= 1
|
||||
return _binary_len_search(min_index=min_index, max_index=index)
|
||||
return _binary_len_search(min_index=min_index, max_index=index, word_spacer=word_spacer)
|
||||
elif index == max_index:
|
||||
# We have converged
|
||||
return (index, line_width)
|
||||
return (index, line_width, px_below_baseline)
|
||||
else:
|
||||
# Candidate line is possibly shorter than necessary.
|
||||
return _binary_len_search(min_index=index, max_index=max_index)
|
||||
return _binary_len_search(min_index=index, max_index=max_index, word_spacer=word_spacer)
|
||||
|
||||
if len(text.split()) == 1 and not allow_text_overflow:
|
||||
if len(text.split()) == 1 and not allow_text_overflow and not treat_chars_as_words:
|
||||
# No whitespace chars to split on!
|
||||
raise TextDoesNotFitException("Text cannot fit in target rect with this font+size")
|
||||
|
||||
# Now we're ready to go line-by-line into our line break binary search!
|
||||
for line in text.split("\n"):
|
||||
if treat_chars_as_words:
|
||||
# Each char in `line` will be considered a word; lets us make line breaks
|
||||
# at any char.
|
||||
words = line
|
||||
|
||||
# When re-joining words, no additional spacer is used
|
||||
word_spacer = ""
|
||||
|
||||
# TODO: Don't break before 、。「」() etc.
|
||||
# TODO: If English terms are embedded, don't break mid-word
|
||||
|
||||
else:
|
||||
# Separate words by any whitespace (spaces, line breaks, etc)
|
||||
words = line.split()
|
||||
|
||||
# When re-joining words, separate with a space char
|
||||
word_spacer = " "
|
||||
|
||||
if not words:
|
||||
# It's a blank line
|
||||
_add_text_line("", 0)
|
||||
_add_text_line("", 0, 0)
|
||||
else:
|
||||
while words:
|
||||
(index, tw) = _binary_len_search(0, len(words))
|
||||
_add_text_line(" ".join(words[0:index]), tw)
|
||||
(index, tw, px_below_baseline) = _binary_len_search(0, len(words), word_spacer=word_spacer)
|
||||
_add_text_line(word_spacer.join(words[0:index]), tw, px_below_baseline)
|
||||
words = words[index:]
|
||||
|
||||
return text_lines
|
||||
@@ -1950,3 +1970,47 @@ def reflow_text_into_pages(text: str,
|
||||
pages.append("\n".join(lines[i:i+lines_per_page]))
|
||||
|
||||
return pages
|
||||
|
||||
|
||||
def resize_image_to_fill(img: Image, target_size_x: int, target_size_y: int, sampling_method=Image.Resampling.NEAREST) -> Image:
|
||||
"""
|
||||
Resizes the image to fill the target size, cropping the image if necessary.
|
||||
"""
|
||||
if img.width == target_size_x and img.height == target_size_y:
|
||||
# No need to resize
|
||||
return img
|
||||
|
||||
# if the image aspect ratio doesn't match the render area, we
|
||||
# need to provide an aspect ratio-aware crop box.
|
||||
render_aspect_ratio = target_size_x / target_size_y
|
||||
source_frame_aspect_ratio = img.width / img.height
|
||||
if render_aspect_ratio > source_frame_aspect_ratio:
|
||||
# Render surface is wider than the source frame; preserve
|
||||
# the width but crop the height
|
||||
cropped_height = (img.width * target_size_y / target_size_x)
|
||||
box = (
|
||||
0,
|
||||
int((img.height - cropped_height)/2),
|
||||
img.width,
|
||||
img.height - int((img.height - cropped_height)/2),
|
||||
)
|
||||
|
||||
elif render_aspect_ratio < source_frame_aspect_ratio:
|
||||
# Render surface is taller than the source frame; preserve
|
||||
# the height but crop the width
|
||||
box = (
|
||||
int((img.width - img.height * target_size_x / target_size_y) / 2),
|
||||
0,
|
||||
int(img.width - (img.width - img.height * target_size_x / target_size_y) / 2),
|
||||
img.height,
|
||||
)
|
||||
|
||||
else:
|
||||
# Render surface and source frame are the same aspect ratio
|
||||
box = None
|
||||
|
||||
return img.resize(
|
||||
(target_size_x, target_size_y),
|
||||
resample=sampling_method,
|
||||
box=box,
|
||||
)
|
||||
@@ -1,7 +1,11 @@
|
||||
from PIL import Image, ImageDraw
|
||||
from threading import Lock
|
||||
|
||||
from seedsigner.hardware.ST7789 import ST7789
|
||||
# from seedsigner.hardware.st7789_mpy import ST7789
|
||||
from seedsigner.hardware.displays.display_driver import ALL_DISPLAY_TYPES, DISPLAY_TYPE__ILI9341, DISPLAY_TYPE__ILI9486, DISPLAY_TYPE__ST7789, DisplayDriver
|
||||
from seedsigner.hardware.displays.ili9341 import ILI9341, ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT
|
||||
from seedsigner.models.settings import Settings
|
||||
from seedsigner.models.settings_definition import SettingsConstants
|
||||
from seedsigner.models.singleton import ConfigurableSingleton
|
||||
|
||||
|
||||
@@ -22,19 +26,44 @@ class Renderer(ConfigurableSingleton):
|
||||
renderer = cls.__new__(cls)
|
||||
cls._instance = renderer
|
||||
|
||||
# Eventually we'll be able to plug in other display controllers
|
||||
renderer.disp = ST7789()
|
||||
renderer.canvas_width = renderer.disp.width
|
||||
renderer.canvas_height = renderer.disp.height
|
||||
renderer.initialize_display()
|
||||
|
||||
renderer.canvas = Image.new('RGB', (renderer.canvas_width, renderer.canvas_height))
|
||||
renderer.draw = ImageDraw.Draw(renderer.canvas)
|
||||
|
||||
def initialize_display(self):
|
||||
# May be called while already running with a previous display driver; must
|
||||
# prevent any other screen writes while we're changing the display driver.
|
||||
self.lock.acquire()
|
||||
|
||||
display_config = Settings.get_instance().get_value(SettingsConstants.SETTING__DISPLAY_CONFIGURATION, default_if_none=True)
|
||||
self.display_type = display_config.split("_")[0]
|
||||
if self.display_type not in ALL_DISPLAY_TYPES:
|
||||
raise Exception(f"Invalid display type: {self.display_type}")
|
||||
|
||||
width, height = display_config.split("_")[1].split("x")
|
||||
self.disp = DisplayDriver(self.display_type, width=int(width), height=int(height))
|
||||
|
||||
if Settings.get_instance().get_value(SettingsConstants.SETTING__DISPLAY_COLOR_INVERTED, default_if_none=True) == SettingsConstants.OPTION__ENABLED:
|
||||
self.disp.invert()
|
||||
|
||||
if self.display_type == DISPLAY_TYPE__ST7789:
|
||||
self.canvas_width = self.disp.width
|
||||
self.canvas_height = self.disp.height
|
||||
|
||||
elif self.display_type in [DISPLAY_TYPE__ILI9341, DISPLAY_TYPE__ILI9486]:
|
||||
# Swap for the natively portrait-oriented displays
|
||||
self.canvas_width = self.disp.height
|
||||
self.canvas_height = self.disp.width
|
||||
|
||||
self.canvas = Image.new('RGB', (self.canvas_width, self.canvas_height))
|
||||
self.draw = ImageDraw.Draw(self.canvas)
|
||||
|
||||
self.lock.release()
|
||||
|
||||
|
||||
def show_image(self, image=None, alpha_overlay=None, show_direct=False):
|
||||
if show_direct:
|
||||
# Use the incoming image as the canvas and immediately render
|
||||
self.disp.ShowImage(image, 0, 0)
|
||||
self.disp.show_image(image, 0, 0)
|
||||
return
|
||||
|
||||
if alpha_overlay:
|
||||
@@ -46,7 +75,7 @@ class Renderer(ConfigurableSingleton):
|
||||
# Always write to the current canvas, rather than trying to replace it
|
||||
self.canvas.paste(image)
|
||||
|
||||
self.disp.ShowImage(self.canvas, 0, 0)
|
||||
self.disp.show_image(self.canvas, 0, 0)
|
||||
|
||||
|
||||
def show_image_pan(self, image, start_x, start_y, end_x, end_y, rate, alpha_overlay=None):
|
||||
@@ -80,7 +109,7 @@ class Renderer(ConfigurableSingleton):
|
||||
# Always keep a copy of the current display in the canvas
|
||||
self.canvas.paste(crop)
|
||||
|
||||
self.disp.ShowImage(crop, 0, 0)
|
||||
self.disp.show_image(crop, 0, 0)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from gettext import gettext as _
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from seedsigner.gui import renderer
|
||||
from seedsigner.gui.components import GUIConstants, Fonts
|
||||
from seedsigner.gui.components import GUIConstants, Fonts, resize_image_to_fill
|
||||
from seedsigner.models.decode_qr import DecodeQR
|
||||
from seedsigner.models.threads import BaseThread, ThreadsafeCounter
|
||||
|
||||
@@ -132,11 +132,8 @@ class ScanScreen(BaseScreen):
|
||||
scan_text += f" {cur_fps:0.2f} | {self.decoder_fps}"
|
||||
|
||||
with self.renderer.lock:
|
||||
if frame.width > self.render_width or frame.height > self.render_height:
|
||||
frame = frame.resize(
|
||||
(self.render_width, self.render_height),
|
||||
resample=Image.NEAREST # Use nearest neighbor for max speed
|
||||
)
|
||||
# Use nearest neighbor resizing for max speed
|
||||
frame = resize_image_to_fill(frame, self.render_width, self.render_height, sampling_method=Image.Resampling.NEAREST)
|
||||
|
||||
if scan_text:
|
||||
# Note: shadowed text (adding a 'stroke' outline) can
|
||||
@@ -287,5 +284,5 @@ class ScanScreen(BaseScreen):
|
||||
|
||||
if self.hw_inputs.check_for_low(HardwareButtonsConstants.KEY_RIGHT) or self.hw_inputs.check_for_low(HardwareButtonsConstants.KEY_LEFT):
|
||||
self.camera.stop_video_stream_mode()
|
||||
break
|
||||
return False
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import math
|
||||
import logging
|
||||
import time
|
||||
|
||||
@@ -277,6 +278,8 @@ class ButtonOption:
|
||||
button_label_color: str = None
|
||||
return_data: Any = None
|
||||
active_button_label: str = None # Changes displayed button label when button is active
|
||||
font_name: str = None # Optional override
|
||||
font_size: int = None # Optional override
|
||||
|
||||
|
||||
|
||||
@@ -286,15 +289,20 @@ class ButtonListScreen(BaseTopNavScreen):
|
||||
selected_button: int = 0
|
||||
is_button_text_centered: bool = True
|
||||
is_bottom_list: bool = False
|
||||
|
||||
# Cannot define these class attrs w/the get_*_font_*() methods because the attrs will
|
||||
# not be dynamically reinterpreted after initial class import.
|
||||
button_font_name: str = None
|
||||
button_font_size: int = None
|
||||
|
||||
button_selected_color: str = GUIConstants.ACCENT_COLOR
|
||||
|
||||
# Params for version of list used for Settings
|
||||
Button_cls = Button
|
||||
checked_buttons: List[int] = None
|
||||
|
||||
# Enables returning w/buttons rendered at the same place
|
||||
# Enables returning w/buttons rendered at the same place; default behavior will
|
||||
# ensure the screen is at least scrolled to reveal the `selected_button`.
|
||||
scroll_y_initial_offset: int = None
|
||||
|
||||
|
||||
@@ -322,40 +330,37 @@ class ButtonListScreen(BaseTopNavScreen):
|
||||
button_list_y = self.top_nav.height
|
||||
self.has_scroll_arrows = True
|
||||
|
||||
# How many buttons fit on the screen before we need to start scrolling?
|
||||
num_buttons_pre_scroll = math.floor((self.canvas_height - button_list_y - GUIConstants.EDGE_PADDING) / (button_height + GUIConstants.LIST_ITEM_PADDING))
|
||||
|
||||
# Force a scroll offset when necessary if none was provided
|
||||
if self.selected_button + 1 > num_buttons_pre_scroll and not self.scroll_y_initial_offset:
|
||||
# Scroll far enough to expose the selected button; +1 to account for the
|
||||
# height of the target button itself!
|
||||
self.scroll_y_initial_offset = (button_height + GUIConstants.LIST_ITEM_PADDING) * (self.selected_button - num_buttons_pre_scroll + 1)
|
||||
|
||||
self.buttons: List[Button] = []
|
||||
for i, button_option in enumerate(self.button_data):
|
||||
icon_name = None
|
||||
icon_color = None
|
||||
right_icon_name = None
|
||||
button_label_color = None
|
||||
|
||||
if type(button_option) == ButtonOption:
|
||||
button_label = button_option.button_label
|
||||
icon_name = button_option.icon_name
|
||||
icon_color = button_option.icon_color
|
||||
right_icon_name = button_option.right_icon_name
|
||||
button_label_color = button_option.button_label_color
|
||||
active_button_label = button_option.active_button_label
|
||||
|
||||
else:
|
||||
if type(button_option) != ButtonOption:
|
||||
raise Exception("Refactor to ButtonOption approach needed!")
|
||||
|
||||
# TODO: Refactor `Button` to optionally use ButtonOption directly?
|
||||
button_kwargs = dict(
|
||||
text=_(button_label), # Wrap here for just-in-time translations
|
||||
active_text=_(active_button_label), # Wrap here for just-in-time translations
|
||||
icon_name=icon_name,
|
||||
icon_color=icon_color if icon_color else GUIConstants.BUTTON_FONT_COLOR,
|
||||
text=_(button_option.button_label), # Wrap here for just-in-time translations
|
||||
active_text=_(button_option.active_button_label), # Wrap here for just-in-time translations
|
||||
icon_name=button_option.icon_name,
|
||||
icon_color=button_option.icon_color if button_option.icon_color else GUIConstants.BUTTON_FONT_COLOR,
|
||||
is_icon_inline=True,
|
||||
right_icon_name=right_icon_name,
|
||||
right_icon_name=button_option.right_icon_name,
|
||||
screen_x=GUIConstants.EDGE_PADDING,
|
||||
screen_y=button_list_y + i * (button_height + GUIConstants.LIST_ITEM_PADDING),
|
||||
scroll_y=self.scroll_y_initial_offset if self.scroll_y_initial_offset is not None else 0,
|
||||
width=self.canvas_width - (2 * GUIConstants.EDGE_PADDING),
|
||||
height=button_height,
|
||||
is_text_centered=self.is_button_text_centered,
|
||||
font_name=self.button_font_name,
|
||||
font_size=self.button_font_size,
|
||||
font_color=button_label_color if button_label_color else GUIConstants.BUTTON_FONT_COLOR,
|
||||
font_name=button_option.font_name if button_option.font_name else self.button_font_name,
|
||||
font_size=button_option.font_size if button_option.font_size else self.button_font_size,
|
||||
font_color=button_option.button_label_color if button_option.button_label_color else GUIConstants.BUTTON_FONT_COLOR,
|
||||
selected_color=self.button_selected_color,
|
||||
is_scrollable_text=True, # We need to use the ScrollableText class for long button labels
|
||||
)
|
||||
@@ -553,8 +558,12 @@ class ButtonListScreen(BaseTopNavScreen):
|
||||
@dataclass
|
||||
class LargeButtonScreen(BaseTopNavScreen):
|
||||
button_data: list = None
|
||||
|
||||
# Cannot define these class attrs w/the get_*_font_*() methods because the attrs will
|
||||
# not be dynamically reinterpreted after initial class import.
|
||||
button_font_name: str = None
|
||||
button_font_size: int = None
|
||||
|
||||
button_selected_color: str = GUIConstants.ACCENT_COLOR
|
||||
selected_button: int = 0
|
||||
|
||||
@@ -562,6 +571,7 @@ class LargeButtonScreen(BaseTopNavScreen):
|
||||
if not self.button_font_name:
|
||||
self.button_font_name = GUIConstants.get_button_font_name()
|
||||
if not self.button_font_size:
|
||||
# TODO: Define the +2 with a constant or via a formula (e.g. int(x * 1.1))
|
||||
self.button_font_size = GUIConstants.get_button_font_size() + 2
|
||||
|
||||
super().__post_init__()
|
||||
@@ -569,9 +579,11 @@ class LargeButtonScreen(BaseTopNavScreen):
|
||||
if len(self.button_data) not in [2, 4]:
|
||||
raise Exception("LargeButtonScreen only supports 2 or 4 buttons")
|
||||
|
||||
# Maximize 2-across width; calc height with a 4:3 aspect ratio
|
||||
# Maximize 2-across width
|
||||
button_width = int((self.canvas_width - (2 * GUIConstants.EDGE_PADDING) - GUIConstants.COMPONENT_PADDING) / 2)
|
||||
button_height = int(button_width * (3.0 / 4.0))
|
||||
|
||||
# Maximize 2-row height
|
||||
button_height = int((self.canvas_height - self.top_nav.height - (2 * GUIConstants.COMPONENT_PADDING) - GUIConstants.EDGE_PADDING) / 2)
|
||||
|
||||
# Vertically center the buttons
|
||||
if len(self.button_data) == 2:
|
||||
|
||||
@@ -31,8 +31,17 @@ class SeedMnemonicEntryScreen(BaseTopNavScreen):
|
||||
|
||||
self.possible_alphabet = "abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
# Measure the width required to display the longest word in the English bip39
|
||||
# wordlist.
|
||||
# TODO: If we ever support other wordlist languages, adjust accordingly.
|
||||
matches_list_highlight_font_name = GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME
|
||||
matches_list_highlight_font_size = GUIConstants.get_button_font_size() + 4
|
||||
(left, top, right, bottom) = Fonts.get_font(matches_list_highlight_font_name, matches_list_highlight_font_size).getbbox("mushroom", anchor="ls")
|
||||
matches_list_max_text_width = right - left
|
||||
matches_list_button_width = matches_list_max_text_width + 2*GUIConstants.COMPONENT_PADDING
|
||||
|
||||
# Set up the keyboard params
|
||||
self.keyboard_width = 128
|
||||
self.keyboard_width = self.canvas_width - GUIConstants.EDGE_PADDING - matches_list_button_width
|
||||
text_entry_display_y = self.top_nav.height
|
||||
text_entry_display_height = 30
|
||||
|
||||
@@ -78,7 +87,7 @@ class SeedMnemonicEntryScreen(BaseTopNavScreen):
|
||||
else:
|
||||
self.keyboard.set_selected_key(selected_letter=self.letters[-1])
|
||||
|
||||
self.matches_list_x = GUIConstants.EDGE_PADDING + self.keyboard.width + GUIConstants.COMPONENT_PADDING
|
||||
self.matches_list_x = self.canvas_width - matches_list_button_width
|
||||
self.matches_list_y = self.top_nav.height
|
||||
self.highlighted_row_y = int((self.canvas_height - GUIConstants.BUTTON_HEIGHT)/2)
|
||||
|
||||
@@ -634,12 +643,17 @@ class SeedExportXpubDetailsScreen(WarningEdgesMixin, ButtonListScreen):
|
||||
)
|
||||
self.components.append(self.derivation_line)
|
||||
|
||||
font_name = GUIConstants.FIXED_WIDTH_FONT_NAME
|
||||
font_size = GUIConstants.get_body_font_size() + 2
|
||||
left, top, right, bottom = Fonts.get_font(font_name, font_size).getbbox("X")
|
||||
char_width = right - left
|
||||
num_chars = int((self.canvas_width - GUIConstants.ICON_FONT_SIZE - 2*GUIConstants.COMPONENT_PADDING) / char_width) - 3 # ellipsis
|
||||
|
||||
self.xpub_line = IconTextLine(
|
||||
icon_name=FontAwesomeIconConstants.X,
|
||||
icon_color=GUIConstants.INFO_COLOR,
|
||||
# TRANSLATOR_NOTE: Short for "BIP32 Extended Public Key"
|
||||
label_text=_("Xpub"),
|
||||
value_text=f"{self.xpub[:18]}...",
|
||||
value_text=f"{self.xpub[:num_chars]}...",
|
||||
font_name=GUIConstants.FIXED_WIDTH_FONT_NAME,
|
||||
font_size=GUIConstants.get_body_font_size() + 2,
|
||||
screen_x=GUIConstants.COMPONENT_PADDING,
|
||||
@@ -997,9 +1011,9 @@ class SeedAddPassphraseScreen(BaseTopNavScreen):
|
||||
pass
|
||||
elif cursor_position == len(self.passphrase):
|
||||
self.passphrase = self.passphrase[:-1]
|
||||
cursor_position -= 1
|
||||
else:
|
||||
self.passphrase = self.passphrase[:cursor_position - 1] + self.passphrase[cursor_position:]
|
||||
|
||||
cursor_position -= 1
|
||||
|
||||
elif ret_val == Keyboard.KEY_CURSOR_LEFT["code"]:
|
||||
@@ -1181,68 +1195,81 @@ class SeedTranscribeSeedQRWholeQRScreen(WarningEdgesMixin, ButtonListScreen):
|
||||
|
||||
@dataclass
|
||||
class SeedTranscribeSeedQRZoomedInScreen(BaseScreen):
|
||||
"""
|
||||
QR codes are defined by the number of "modules" (squares), e.g. 21x21 modules.
|
||||
|
||||
Each module will be rendered as a square of pixels, e.g. 24x24 pixels.
|
||||
|
||||
In this Screen, a "zone" will mean a square module area, e.g. 5x5 modules, that
|
||||
corresponds to the SeedQR templates which include zone guidelines and labels
|
||||
(e.g. "B-3").
|
||||
"""
|
||||
qr_data: str = None
|
||||
num_modules: int = None
|
||||
initial_block_x: int = 0
|
||||
initial_block_y: int = 0
|
||||
initial_zone_x: int = 0
|
||||
initial_zone_y: int = 0
|
||||
|
||||
def __post_init__(self):
|
||||
super().__post_init__()
|
||||
|
||||
# Render an oversized QR code that we can view up close
|
||||
self.pixels_per_block = 24
|
||||
self.pixels_per_module = 24
|
||||
|
||||
# Border must accommodate the 3 blocks outside the center 5x5 mask plus up to
|
||||
# 1 empty block inside the 5x5 mask (29x29 has a 4-block final col/row).
|
||||
self.qr_border = 4
|
||||
self.num_qr_border_modules = 4
|
||||
if self.num_modules == 21:
|
||||
# Optimize for 21x21
|
||||
self.qr_blocks_per_zoom = 7
|
||||
self.modules_per_zone = 7 # i.e. a 7x7 group of modules
|
||||
else:
|
||||
self.qr_blocks_per_zoom = 5
|
||||
self.modules_per_zone = 5
|
||||
|
||||
self.qr_width = (self.qr_border + self.num_modules + self.qr_border) * self.pixels_per_block
|
||||
self.height = self.qr_width
|
||||
total_qr_image_width = (self.num_qr_border_modules + self.num_modules + self.num_qr_border_modules) * self.pixels_per_module
|
||||
qr = QR()
|
||||
self.qr_image = qr.qrimage(
|
||||
self.qr_image: Image = qr.qrimage(
|
||||
self.qr_data,
|
||||
width=self.qr_width,
|
||||
height=self.height,
|
||||
border=self.qr_border,
|
||||
width=total_qr_image_width,
|
||||
height=total_qr_image_width, # QR image is always square
|
||||
border=self.num_qr_border_modules,
|
||||
style=QR.STYLE__ROUNDED
|
||||
).convert("RGBA")
|
||||
# ).convert("RGBA")
|
||||
)
|
||||
|
||||
# Render gridlines but leave the 1-block border as-is
|
||||
draw = ImageDraw.Draw(self.qr_image)
|
||||
for i in range(self.qr_border, math.floor(self.qr_width/self.pixels_per_block) - self.qr_border):
|
||||
draw.line((i * self.pixels_per_block, self.qr_border * self.pixels_per_block, i * self.pixels_per_block, self.height - self.qr_border * self.pixels_per_block), fill="#bbb")
|
||||
draw.line((self.qr_border * self.pixels_per_block, i * self.pixels_per_block, self.qr_width - self.qr_border * self.pixels_per_block, i * self.pixels_per_block), fill="#bbb")
|
||||
# Render gridlines over the QR code but don't draw on its external white border
|
||||
qr_image_draw = ImageDraw.Draw(self.qr_image)
|
||||
for i in range(self.num_qr_border_modules, math.floor(self.qr_image.width/self.pixels_per_module) - self.num_qr_border_modules):
|
||||
qr_image_draw.line((i * self.pixels_per_module, self.num_qr_border_modules * self.pixels_per_module, i * self.pixels_per_module, self.qr_image.height - self.num_qr_border_modules * self.pixels_per_module), fill="#bbb")
|
||||
qr_image_draw.line((self.num_qr_border_modules * self.pixels_per_module, i * self.pixels_per_module, self.qr_image.width - self.num_qr_border_modules * self.pixels_per_module, i * self.pixels_per_module), fill="#bbb")
|
||||
|
||||
# Prep the semi-transparent mask overlay
|
||||
# make a blank image for the overlay, initialized to transparent
|
||||
self.block_mask = Image.new("RGBA", (self.canvas_width, self.canvas_height), (255,255,255,0))
|
||||
draw = ImageDraw.Draw(self.block_mask)
|
||||
|
||||
self.mask_width = int((self.canvas_width - self.qr_blocks_per_zoom * self.pixels_per_block)/2)
|
||||
self.mask_height = int((self.canvas_height - self.qr_blocks_per_zoom * self.pixels_per_block)/2)
|
||||
# Make a blank semi-transparent image for the overlay, initially across the
|
||||
# entire canvas.
|
||||
mask_rgba = (0, 0, 0, 226)
|
||||
draw.rectangle((0, 0, self.canvas_width, self.mask_height), fill=mask_rgba)
|
||||
draw.rectangle((0, self.canvas_height - self.mask_height - 1, self.canvas_width, self.canvas_height), fill=mask_rgba)
|
||||
draw.rectangle((0, self.mask_height, self.mask_width, self.canvas_height - self.mask_height), fill=mask_rgba)
|
||||
draw.rectangle((self.canvas_width - self.mask_width - 1, self.mask_height, self.canvas_width, self.canvas_height - self.mask_height), fill=mask_rgba)
|
||||
self.zone_mask = Image.new("RGBA", (self.canvas_width, self.canvas_height), mask_rgba)
|
||||
zone_mask_draw = ImageDraw.Draw(self.zone_mask)
|
||||
|
||||
# Draw a box around the cutout portion of the mask for better visibility
|
||||
draw.line((self.mask_width, self.mask_height, self.mask_width, self.canvas_height - self.mask_height), fill=GUIConstants.ACCENT_COLOR)
|
||||
draw.line((self.canvas_width - self.mask_width, self.mask_height, self.canvas_width - self.mask_width, self.canvas_height - self.mask_height), fill=GUIConstants.ACCENT_COLOR)
|
||||
draw.line((self.mask_width, self.mask_height, self.canvas_width - self.mask_width, self.mask_height), fill=GUIConstants.ACCENT_COLOR)
|
||||
draw.line((self.mask_width, self.canvas_height - self.mask_height, self.canvas_width - self.mask_width, self.canvas_height - self.mask_height), fill=GUIConstants.ACCENT_COLOR)
|
||||
# Now punch a hole in the center of the mask to highlight the current zone with
|
||||
# an accent outline.
|
||||
# The `zone_mask_offset_*` vars are the top left xy coords of the mask.
|
||||
self.zone_mask_offset_x = int((self.canvas_width - (self.modules_per_zone * self.pixels_per_module))/2)
|
||||
self.zone_mask_offset_y = int((self.canvas_height - (self.modules_per_zone * self.pixels_per_module))/2)
|
||||
zone_mask_draw.rectangle(
|
||||
(
|
||||
self.zone_mask_offset_x,
|
||||
self.zone_mask_offset_y,
|
||||
self.canvas_width - self.zone_mask_offset_x,
|
||||
self.canvas_height - self.zone_mask_offset_y
|
||||
),
|
||||
fill=(255, 255, 255, 0), # fully transparent mask area
|
||||
outline=GUIConstants.ACCENT_COLOR,
|
||||
width=1
|
||||
)
|
||||
|
||||
msg = _("click to exit")
|
||||
font = Fonts.get_font(GUIConstants.get_body_font_name(), GUIConstants.get_body_font_size())
|
||||
(left, top, right, bottom) = font.getbbox(msg, anchor="ls")
|
||||
msg_height = -1 * top + GUIConstants.COMPONENT_PADDING
|
||||
msg_width = right + 2*GUIConstants.COMPONENT_PADDING
|
||||
draw.rectangle(
|
||||
zone_mask_draw.rectangle(
|
||||
(
|
||||
int((self.canvas_width - msg_width)/2),
|
||||
self.canvas_height - msg_height,
|
||||
@@ -1251,7 +1278,7 @@ class SeedTranscribeSeedQRZoomedInScreen(BaseScreen):
|
||||
),
|
||||
fill=GUIConstants.BACKGROUND_COLOR,
|
||||
)
|
||||
draw.text(
|
||||
zone_mask_draw.text(
|
||||
(int(self.canvas_width/2), self.canvas_height - int(GUIConstants.COMPONENT_PADDING/2)),
|
||||
msg,
|
||||
fill=GUIConstants.BODY_FONT_COLOR,
|
||||
@@ -1261,103 +1288,103 @@ class SeedTranscribeSeedQRZoomedInScreen(BaseScreen):
|
||||
|
||||
|
||||
|
||||
def draw_block_labels(self):
|
||||
# Create overlay for block labels (e.g. "D-5")
|
||||
block_labels_x = ["1", "2", "3", "4", "5", "6"]
|
||||
block_labels_y = ["A", "B", "C", "D", "E", "F"]
|
||||
def draw_zone_labels(self):
|
||||
# Create overlay for zone labels (e.g. "D-5")
|
||||
# TODO: Discuss w/translators if these zone labels need to be translated; would
|
||||
# trigger a secondary need to have translated SeedQR printable templates as well.
|
||||
zone_labels_x = ["1", "2", "3", "4", "5", "6"]
|
||||
zone_labels_y = ["A", "B", "C", "D", "E", "F"]
|
||||
|
||||
block_labels = Image.new("RGBA", (self.canvas_width, self.canvas_height), (255,255,255,0))
|
||||
draw = ImageDraw.Draw(block_labels)
|
||||
draw.rectangle((self.mask_width, 0, self.canvas_width - self.mask_width, self.pixels_per_block), fill=GUIConstants.ACCENT_COLOR)
|
||||
draw.rectangle((0, self.mask_height, self.pixels_per_block, self.canvas_height - self.mask_height), fill=GUIConstants.ACCENT_COLOR)
|
||||
zone_labels = Image.new("RGBA", (self.canvas_width, self.canvas_height), (255,255,255,0))
|
||||
zone_labels_draw = ImageDraw.Draw(zone_labels)
|
||||
zone_labels_draw.rectangle((self.zone_mask_offset_x, 0, self.canvas_width - self.zone_mask_offset_x, self.pixels_per_module), fill=GUIConstants.ACCENT_COLOR)
|
||||
zone_labels_draw.rectangle((0, self.zone_mask_offset_y, self.pixels_per_module, self.canvas_height - self.zone_mask_offset_y), fill=GUIConstants.ACCENT_COLOR)
|
||||
|
||||
label_font = Fonts.get_font(GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME, 28)
|
||||
x_label = block_labels_x[self.cur_block_x]
|
||||
x_label = zone_labels_x[self.cur_zone_x]
|
||||
(left, top, right, bottom) = label_font.getbbox(x_label, anchor="ls")
|
||||
x_label_height = -1 * top
|
||||
|
||||
draw.text(
|
||||
(int(self.canvas_width/2), self.pixels_per_block - int((self.pixels_per_block - x_label_height)/2)),
|
||||
zone_labels_draw.text(
|
||||
(int(self.canvas_width/2), self.pixels_per_module - int((self.pixels_per_module - x_label_height)/2)),
|
||||
text=x_label,
|
||||
fill=GUIConstants.BUTTON_SELECTED_FONT_COLOR,
|
||||
font=label_font,
|
||||
anchor="ms", # Middle, baSeline
|
||||
)
|
||||
|
||||
y_label = block_labels_y[self.cur_block_y]
|
||||
y_label = zone_labels_y[self.cur_zone_y]
|
||||
(left, top, right, bottom) = label_font.getbbox(y_label, anchor="ls")
|
||||
y_label_height = -1 * top
|
||||
draw.text(
|
||||
(int(self.pixels_per_block/2), int((self.canvas_height + y_label_height) / 2)),
|
||||
zone_labels_draw.text(
|
||||
(int(self.pixels_per_module/2), int((self.canvas_height + y_label_height) / 2)),
|
||||
text=y_label,
|
||||
fill=GUIConstants.BUTTON_SELECTED_FONT_COLOR,
|
||||
font=label_font,
|
||||
anchor="ms", # Middle, baSeline
|
||||
)
|
||||
|
||||
return block_labels
|
||||
return zone_labels
|
||||
|
||||
|
||||
def _render(self):
|
||||
# Track our current coordinates for the upper left corner of our view
|
||||
self.cur_block_x = self.initial_block_x
|
||||
self.cur_block_y = self.initial_block_y
|
||||
self.cur_x = (self.cur_block_x * self.qr_blocks_per_zoom * self.pixels_per_block) + self.qr_border * self.pixels_per_block - self.mask_width
|
||||
self.cur_y = (self.cur_block_y * self.qr_blocks_per_zoom * self.pixels_per_block) + self.qr_border * self.pixels_per_block - self.mask_height
|
||||
self.next_x = self.cur_x
|
||||
self.next_y = self.cur_y
|
||||
# Track our current zone-level (macro-module) position and our actual pixel
|
||||
# coordinates as we pan around across the QR code image.
|
||||
self.cur_zone_x = self.initial_zone_x
|
||||
self.cur_zone_y = self.initial_zone_y
|
||||
self.cur_pixel_x = (self.cur_zone_x * self.modules_per_zone * self.pixels_per_module) + self.num_qr_border_modules * self.pixels_per_module - self.zone_mask_offset_x
|
||||
self.cur_pixel_y = (self.cur_zone_y * self.modules_per_zone * self.pixels_per_module) + self.num_qr_border_modules * self.pixels_per_module - self.zone_mask_offset_y
|
||||
self.next_pixel_x = self.cur_pixel_x
|
||||
self.next_pixel_y = self.cur_pixel_y
|
||||
|
||||
block_labels = self.draw_block_labels()
|
||||
zone_labels = self.draw_zone_labels()
|
||||
|
||||
self.renderer.show_image(
|
||||
self.qr_image.crop((self.cur_x, self.cur_y, self.cur_x + self.canvas_width, self.cur_y + self.canvas_height)),
|
||||
alpha_overlay=Image.alpha_composite(self.block_mask, block_labels)
|
||||
self.qr_image.crop((self.cur_pixel_x, self.cur_pixel_y, self.cur_pixel_x + self.canvas_width, self.cur_pixel_y + self.canvas_height)),
|
||||
alpha_overlay=Image.alpha_composite(self.zone_mask, zone_labels)
|
||||
)
|
||||
|
||||
|
||||
def _run(self):
|
||||
while True:
|
||||
input = self.hw_inputs.wait_for(HardwareButtonsConstants.KEYS__LEFT_RIGHT_UP_DOWN + HardwareButtonsConstants.KEYS__ANYCLICK)
|
||||
if input == HardwareButtonsConstants.KEY_RIGHT:
|
||||
self.next_x = self.cur_x + self.qr_blocks_per_zoom * self.pixels_per_block
|
||||
self.cur_block_x += 1
|
||||
if self.next_x > self.qr_width - self.canvas_width:
|
||||
self.next_x = self.cur_x
|
||||
self.cur_block_x -= 1
|
||||
elif input == HardwareButtonsConstants.KEY_LEFT:
|
||||
self.next_x = self.cur_x - self.qr_blocks_per_zoom * self.pixels_per_block
|
||||
self.cur_block_x -= 1
|
||||
if self.next_x < 0:
|
||||
self.next_x = self.cur_x
|
||||
self.cur_block_x += 1
|
||||
elif input == HardwareButtonsConstants.KEY_DOWN:
|
||||
self.next_y = self.cur_y + self.qr_blocks_per_zoom * self.pixels_per_block
|
||||
self.cur_block_y += 1
|
||||
if self.next_y > self.height - self.canvas_height:
|
||||
self.next_y = self.cur_y
|
||||
self.cur_block_y -= 1
|
||||
elif input == HardwareButtonsConstants.KEY_UP:
|
||||
self.next_y = self.cur_y - self.qr_blocks_per_zoom * self.pixels_per_block
|
||||
self.cur_block_y -= 1
|
||||
if self.next_y < 0:
|
||||
self.next_y = self.cur_y
|
||||
self.cur_block_y += 1
|
||||
elif input in HardwareButtonsConstants.KEYS__ANYCLICK:
|
||||
|
||||
if input in HardwareButtonsConstants.KEYS__ANYCLICK:
|
||||
# User clicked to exit
|
||||
return
|
||||
|
||||
# Create overlay for block labels (e.g. "D-5")
|
||||
block_labels = self.draw_block_labels()
|
||||
elif input == HardwareButtonsConstants.KEY_RIGHT and self.cur_zone_x + 1 < math.ceil(self.num_modules/self.modules_per_zone):
|
||||
self.next_pixel_x = self.cur_pixel_x + self.modules_per_zone * self.pixels_per_module
|
||||
self.cur_zone_x += 1
|
||||
|
||||
elif input == HardwareButtonsConstants.KEY_LEFT and self.cur_zone_x - 1 >= 0:
|
||||
self.next_pixel_x = self.cur_pixel_x - self.modules_per_zone * self.pixels_per_module
|
||||
self.cur_zone_x -= 1
|
||||
|
||||
elif input == HardwareButtonsConstants.KEY_DOWN and self.cur_zone_y + 1 < math.ceil(self.num_modules/self.modules_per_zone):
|
||||
self.next_pixel_y = self.cur_pixel_y + self.modules_per_zone * self.pixels_per_module
|
||||
self.cur_zone_y += 1
|
||||
|
||||
elif input == HardwareButtonsConstants.KEY_UP and self.cur_zone_y - 1 >= 0:
|
||||
self.next_pixel_y = self.cur_pixel_y - self.modules_per_zone * self.pixels_per_module
|
||||
self.cur_zone_y -= 1
|
||||
|
||||
else:
|
||||
# User selected a direction that we can't advance any further
|
||||
continue
|
||||
|
||||
# Create overlay for zone labels (e.g. "D-5")
|
||||
zone_labels = self.draw_zone_labels()
|
||||
|
||||
if self.cur_x != self.next_x or self.cur_y != self.next_y:
|
||||
with self.renderer.lock:
|
||||
self.renderer.show_image_pan(
|
||||
self.qr_image,
|
||||
self.cur_x, self.cur_y, self.next_x, self.next_y,
|
||||
rate=self.pixels_per_block,
|
||||
alpha_overlay=Image.alpha_composite(self.block_mask, block_labels)
|
||||
self.cur_pixel_x, self.cur_pixel_y, self.next_pixel_x, self.next_pixel_y,
|
||||
rate=self.pixels_per_module,
|
||||
alpha_overlay=Image.alpha_composite(self.zone_mask, zone_labels)
|
||||
)
|
||||
self.cur_x = self.next_x
|
||||
self.cur_y = self.next_y
|
||||
self.cur_pixel_x = self.next_pixel_x
|
||||
self.cur_pixel_y = self.next_pixel_y
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ class SettingsEntryUpdateSelectionScreen(ButtonListScreen):
|
||||
help_text: str = None
|
||||
checked_buttons: List[int] = None
|
||||
settings_entry_type: str = SettingsConstants.TYPE__ENABLED_DISABLED
|
||||
selected_button: int = 0
|
||||
|
||||
def __post_init__(self):
|
||||
self.title = _("Settings")
|
||||
|
||||
@@ -4,10 +4,11 @@ from dataclasses import dataclass
|
||||
from gettext import gettext as _
|
||||
from typing import Any
|
||||
from PIL.Image import Image
|
||||
from seedsigner.gui.renderer import Renderer
|
||||
from seedsigner.hardware.camera import Camera
|
||||
from seedsigner.gui.components import FontAwesomeIconConstants, Fonts, GUIConstants, IconTextLine, SeedSignerIconConstants, TextArea
|
||||
|
||||
from seedsigner.gui.screens.screen import RET_CODE__BACK_BUTTON, BaseScreen, ButtonListScreen, KeyboardScreen
|
||||
from seedsigner.gui.screens.screen import RET_CODE__BACK_BUTTON, BaseScreen, ButtonListScreen, ButtonOption, KeyboardScreen
|
||||
from seedsigner.hardware.buttons import HardwareButtonsConstants
|
||||
from seedsigner.models.settings_definition import SettingsConstants, SettingsDefinition
|
||||
|
||||
@@ -19,7 +20,12 @@ class ToolsImageEntropyLivePreviewScreen(BaseScreen):
|
||||
super().__post_init__()
|
||||
|
||||
self.camera = Camera.get_instance()
|
||||
self.camera.start_video_stream_mode(resolution=(self.canvas_width, self.canvas_height), framerate=24, format="rgb")
|
||||
|
||||
# If the stream is set to 320x240, we get pillarboxed frames (black bars on the
|
||||
# sides). But passing in square dims gives us an edge-to-edge image.
|
||||
# TODO: Figure out why (camera expecting frame dims of multiples other than 16?)
|
||||
max_dimension = max(self.canvas_width, self.canvas_height)
|
||||
self.camera.start_video_stream_mode(resolution=(max_dimension, max_dimension), framerate=24, format="rgb")
|
||||
|
||||
|
||||
def _run(self):
|
||||
@@ -36,13 +42,38 @@ class ToolsImageEntropyLivePreviewScreen(BaseScreen):
|
||||
self.camera.stop_video_stream_mode()
|
||||
return RET_CODE__BACK_BUTTON
|
||||
|
||||
frame = self.camera.read_video_stream(as_image=True)
|
||||
frame: Image = self.camera.read_video_stream(as_image=True)
|
||||
|
||||
if frame is None:
|
||||
# Camera probably isn't ready yet
|
||||
time.sleep(0.01)
|
||||
continue
|
||||
|
||||
with self.renderer.lock:
|
||||
# Account for the possibly different aspect ratio of the camera frame
|
||||
# vs the display; crop any excess.
|
||||
# TODO: This cropping may be unnecessary if the above TODO about the
|
||||
# camera resolution is solved.
|
||||
box = None
|
||||
if self.canvas_width != frame.width:
|
||||
half_width_diff = int(abs(self.canvas_width - frame.width)/2)
|
||||
box = (
|
||||
half_width_diff,
|
||||
0,
|
||||
frame.width - half_width_diff,
|
||||
frame.height
|
||||
)
|
||||
elif self.canvas_height != frame.height:
|
||||
half_height_diff = int(abs(self.canvas_height - frame.height)/2)
|
||||
box = (
|
||||
0,
|
||||
half_height_diff,
|
||||
frame.width,
|
||||
frame.height - half_height_diff
|
||||
)
|
||||
|
||||
self.renderer.canvas.paste(frame.crop(box=box))
|
||||
|
||||
# Check for ANYCLICK to take final entropy image
|
||||
if self.hw_inputs.check_for_low(keys=HardwareButtonsConstants.KEYS__ANYCLICK):
|
||||
# Have to manually update last input time since we're not in a wait_for loop
|
||||
@@ -50,8 +81,6 @@ class ToolsImageEntropyLivePreviewScreen(BaseScreen):
|
||||
self.camera.stop_video_stream_mode()
|
||||
|
||||
with self.renderer.lock:
|
||||
self.renderer.canvas.paste(frame)
|
||||
|
||||
self.renderer.draw.text(
|
||||
xy=(
|
||||
int(self.renderer.canvas_width/2),
|
||||
@@ -70,8 +99,6 @@ class ToolsImageEntropyLivePreviewScreen(BaseScreen):
|
||||
|
||||
# If we're still here, it's just another preview frame loop
|
||||
with self.renderer.lock:
|
||||
self.renderer.canvas.paste(frame)
|
||||
|
||||
self.renderer.draw.text(
|
||||
xy=(
|
||||
int(self.renderer.canvas_width/2),
|
||||
@@ -183,9 +210,11 @@ class ToolsCalcFinalWordFinalizePromptScreen(ButtonListScreen):
|
||||
self.is_button_text_centered = True
|
||||
super().__post_init__()
|
||||
|
||||
self.components.append(TextArea(
|
||||
# TRANSLATOR_NOTE: Final word calc. `mnemonic_length` = 12 or 24. `num_bits` = 7 or 3 (bits of entropy in final word).
|
||||
text=_("The {mnemonic_length}th word is built from {num_bits} more entropy bits plus auto-calculated checksum.").format(mnemonic_length=self.mnemonic_length, num_bits=self.num_entropy_bits),
|
||||
text=_("The {mnemonic_length}th word is built from {num_bits} more entropy bits plus auto-calculated checksum.").format(mnemonic_length=self.mnemonic_length, num_bits=self.num_entropy_bits)
|
||||
|
||||
self.components.append(TextArea(
|
||||
text=text,
|
||||
screen_y=self.top_nav.height + int(GUIConstants.COMPONENT_PADDING/2),
|
||||
))
|
||||
|
||||
@@ -238,13 +267,17 @@ class ToolsCalcFinalWordScreen(ButtonListScreen):
|
||||
super().__post_init__()
|
||||
|
||||
# First what's the total bit display width and where do the checksum bits start?
|
||||
bit_font_size = GUIConstants.get_button_font_size() + 2
|
||||
bit_font_size = GUIConstants.get_button_font_size(locale="default") + 2 # bit font size should not vary by locale
|
||||
font = Fonts.get_font(GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME, bit_font_size)
|
||||
(left, top, bit_display_width, bit_font_height) = font.getbbox("0" * 11, anchor="lt")
|
||||
(left, top, checksum_x, bottom) = font.getbbox("0" * (11 - len(self.checksum_bits)), anchor="lt")
|
||||
bit_display_x = int((self.canvas_width - bit_display_width)/2)
|
||||
checksum_x += bit_display_x
|
||||
|
||||
y_spacer = GUIConstants.COMPONENT_PADDING
|
||||
if GUIConstants.get_body_font_size() > GUIConstants.get_body_font_size("default"):
|
||||
y_spacer -= 1
|
||||
|
||||
# Display the user's additional entropy input
|
||||
if self.selected_final_word:
|
||||
selection_text = self.selected_final_word
|
||||
@@ -271,7 +304,7 @@ class ToolsCalcFinalWordScreen(ButtonListScreen):
|
||||
))
|
||||
|
||||
# ...and that entropy's associated 11 bits
|
||||
screen_y = self.components[-1].screen_y + self.components[-1].height + GUIConstants.COMPONENT_PADDING
|
||||
screen_y = self.components[-1].screen_y + self.components[-1].height + y_spacer
|
||||
first_bits_line = TextArea(
|
||||
text=keeper_selected_bits,
|
||||
font_name=GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME,
|
||||
@@ -298,18 +331,19 @@ class ToolsCalcFinalWordScreen(ButtonListScreen):
|
||||
is_text_centered=False,
|
||||
))
|
||||
|
||||
# Show the checksum..
|
||||
# Show the checksum...
|
||||
self.components.append(TextArea(
|
||||
# TRANSLATOR_NOTE: A function of "x" to be used for detecting errors in "x"
|
||||
text=_("Checksum"),
|
||||
edge_padding=0,
|
||||
screen_y=first_bits_line.screen_y + first_bits_line.height + 2*GUIConstants.COMPONENT_PADDING,
|
||||
height_ignores_below_baseline=True, # Keep the next line (bits display) snugged up, regardless of text rendering below the baseline
|
||||
))
|
||||
|
||||
# ...and its actual bits. Prepend spacers to keep vertical alignment
|
||||
checksum_spacer = "_" * (11 - len(self.checksum_bits))
|
||||
|
||||
screen_y = self.components[-1].screen_y + self.components[-1].height + GUIConstants.COMPONENT_PADDING
|
||||
screen_y = self.components[-1].screen_y + self.components[-1].height + y_spacer
|
||||
|
||||
# This time we de-emphasize the prepended spacers that are irrelevant
|
||||
self.components.append(TextArea(
|
||||
@@ -346,7 +380,7 @@ class ToolsCalcFinalWordScreen(ButtonListScreen):
|
||||
# Once again show the bits that came from the user's entropy...
|
||||
num_checksum_bits = len(self.checksum_bits)
|
||||
user_component = self.selected_final_bits[:11 - num_checksum_bits]
|
||||
screen_y = self.components[-1].screen_y + self.components[-1].height + GUIConstants.COMPONENT_PADDING
|
||||
screen_y = self.components[-1].screen_y + self.components[-1].height + y_spacer
|
||||
self.components.append(TextArea(
|
||||
text=user_component,
|
||||
font_name=GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME,
|
||||
@@ -460,3 +494,47 @@ class ToolsAddressExplorerAddressTypeScreen(ButtonListScreen):
|
||||
screen_x=GUIConstants.EDGE_PADDING,
|
||||
screen_y=self.top_nav.height + GUIConstants.COMPONENT_PADDING,
|
||||
))
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class ToolsAddressExplorerAddressListScreen(ButtonListScreen):
|
||||
start_index: int = 0
|
||||
addresses: list[str] = None
|
||||
|
||||
def __post_init__(self):
|
||||
self.button_font_name = GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME
|
||||
self.button_font_size = GUIConstants.get_button_font_size() + 4
|
||||
self.is_button_text_centered = False
|
||||
self.is_bottom_list = True
|
||||
|
||||
left, top, right, bottom = Fonts.get_font(self.button_font_name, self.button_font_size).getbbox("X")
|
||||
char_width = right - left
|
||||
|
||||
last_addr_index = self.start_index + len(self.addresses) - 1
|
||||
index_digits = len(str(last_addr_index))
|
||||
|
||||
# Calculate how many pixels we have available within each address button,
|
||||
# remembering to account for the index number that will be displayed.
|
||||
# Note: because we haven't called the parent's post_init yet, we don't have a
|
||||
# self.canvas_width set; have to use the Renderer singleton to get it.
|
||||
available_width = Renderer.get_instance().canvas_width - 2*GUIConstants.EDGE_PADDING - 2*GUIConstants.COMPONENT_PADDING - (index_digits + 1)*char_width
|
||||
displayable_chars = int(available_width / char_width) - 3 # ellipsis
|
||||
displayable_half = int(displayable_chars/2)
|
||||
|
||||
self.button_data = []
|
||||
for i, address in enumerate(self.addresses):
|
||||
cur_index = i + self.start_index
|
||||
|
||||
# TODO: Intentionally NOT marking these for translation, but we may need to in
|
||||
# the future.
|
||||
button_label = f"{cur_index}:{address[:displayable_half]}...{address[-1*displayable_half:]}"
|
||||
active_button_label = f"{cur_index}:{address}"
|
||||
|
||||
self.button_data.append(ButtonOption(button_label, active_button_label=active_button_label))
|
||||
|
||||
# TRANSLATOR_NOTE: Insert the number of addrs displayed per screen (e.g. "Next 10")
|
||||
button_label = _("Next {}").format(len(self.addresses))
|
||||
self.button_data.append(ButtonOption(button_label, right_icon_name=SeedSignerIconConstants.CHEVRON_RIGHT))
|
||||
|
||||
super().__post_init__()
|
||||
|
||||
@@ -114,7 +114,7 @@ class ST7789(object):
|
||||
self.data(0x20)
|
||||
self.data(0x23)
|
||||
|
||||
self.command(0x21)
|
||||
self.command(0x21) # inversion ON; 0x20 = inversion OFF
|
||||
|
||||
self.command(0x11)
|
||||
|
||||
@@ -146,7 +146,7 @@ class ST7789(object):
|
||||
|
||||
self.command(0x2C)
|
||||
|
||||
def ShowImage(self,Image,Xstart,Ystart):
|
||||
def show_image(self,Image,Xstart,Ystart):
|
||||
"""Set buffer to value of Python Imaging Library image."""
|
||||
"""Write display buffer to physical display"""
|
||||
imwidth, imheight = Image.size
|
||||
@@ -167,3 +167,7 @@ class ST7789(object):
|
||||
self.SetWindows ( 0, 0, self.width, self.height)
|
||||
GPIO.output(self._dc,GPIO.HIGH)
|
||||
self._spi.writebytes2(_buffer)
|
||||
|
||||
def invert(self, enabled: bool = True):
|
||||
"""Invert how the display interprets colors"""
|
||||
self.command(0x21 if enabled else 0x20)
|
||||
@@ -0,0 +1,60 @@
|
||||
DISPLAY_TYPE__ST7789 = "st7789"
|
||||
DISPLAY_TYPE__ILI9341 = "ili9341"
|
||||
DISPLAY_TYPE__ILI9486 = "ili9486"
|
||||
|
||||
ALL_DISPLAY_TYPES = [DISPLAY_TYPE__ST7789, DISPLAY_TYPE__ILI9341, DISPLAY_TYPE__ILI9486]
|
||||
|
||||
|
||||
class DisplayDriver:
|
||||
def __init__(self, display_type: str = DISPLAY_TYPE__ST7789, width: int = None, height: int = None):
|
||||
if display_type not in ALL_DISPLAY_TYPES:
|
||||
raise ValueError(f"Invalid display type: {display_type}")
|
||||
self.display_type = display_type
|
||||
|
||||
if self.display_type == DISPLAY_TYPE__ST7789:
|
||||
if width not in [240, 320] or height != 240:
|
||||
raise ValueError("ST7789 display only supports 240x240 or 320x240 resolutions")
|
||||
|
||||
if width == 240:
|
||||
# TODO: For now the original ST7789 driver has to be used for 240x240.
|
||||
# The mpy version below renders incorrectly (almost like each row of pixels
|
||||
# is one pixel short, so the entire screen exhibits a diagonal skew).
|
||||
from seedsigner.hardware.displays.ST7789 import ST7789
|
||||
self.display = ST7789()
|
||||
|
||||
elif width == 320:
|
||||
from seedsigner.hardware.displays.st7789_mpy import ST7789
|
||||
# Have to swap width and height; screen is natively 240x320
|
||||
self.display = ST7789(width=height, height=width)
|
||||
|
||||
elif self.display_type == DISPLAY_TYPE__ILI9341:
|
||||
from seedsigner.hardware.displays.ili9341 import ILI9341
|
||||
self.display = ILI9341()
|
||||
self.display.begin()
|
||||
|
||||
elif self.display_type == DISPLAY_TYPE__ILI9486:
|
||||
# TODO: improve performance of ili9486 driver
|
||||
raise Exception("ILI9486 display not implemented yet")
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"DisplayDriver(display_type={self.display_type}, width={self.width}, height={self.height})"
|
||||
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
return self.display.width
|
||||
|
||||
|
||||
@property
|
||||
def height(self):
|
||||
return self.display.height
|
||||
|
||||
|
||||
def invert(self, enabled: bool = True):
|
||||
"""Invert how the display interprets colors"""
|
||||
self.display.invert(enabled)
|
||||
|
||||
|
||||
def show_image(self, image, x_start: int = 0, y_start: int = 0):
|
||||
self.display.show_image(image, x_start, y_start)
|
||||
@@ -0,0 +1,376 @@
|
||||
# Copyright (c) 2014 Adafruit Industries
|
||||
# Author: Tony DiCola
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
"""
|
||||
Tested with a 320x240 IPS display (https://a.co/d/2Q9wDLo)
|
||||
* Framerate is excellent (~10fps)
|
||||
* Requires `invert()` and 90° rotation
|
||||
* Exhibits noticeable residual ghosting
|
||||
"""
|
||||
import numbers
|
||||
import time
|
||||
# import numpy as np
|
||||
import array
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
from spidev import SpiDev
|
||||
|
||||
|
||||
# Constants for interacting with display registers.
|
||||
ILI9341_TFTWIDTH = 240
|
||||
ILI9341_TFTHEIGHT = 320
|
||||
|
||||
ILI9341_NOP = 0x00
|
||||
ILI9341_SWRESET = 0x01
|
||||
ILI9341_RDDID = 0x04
|
||||
ILI9341_RDDST = 0x09
|
||||
|
||||
ILI9341_SLPIN = 0x10
|
||||
ILI9341_SLPOUT = 0x11
|
||||
ILI9341_PTLON = 0x12
|
||||
ILI9341_NORON = 0x13
|
||||
|
||||
ILI9341_RDMODE = 0x0A
|
||||
ILI9341_RDMADCTL = 0x0B
|
||||
ILI9341_RDPIXFMT = 0x0C
|
||||
ILI9341_RDIMGFMT = 0x0A
|
||||
ILI9341_RDSELFDIAG = 0x0F
|
||||
|
||||
ILI9341_INVOFF = 0x20
|
||||
ILI9341_INVON = 0x21
|
||||
ILI9341_GAMMASET = 0x26
|
||||
ILI9341_DISPOFF = 0x28
|
||||
ILI9341_DISPON = 0x29
|
||||
|
||||
ILI9341_CASET = 0x2A
|
||||
ILI9341_PASET = 0x2B
|
||||
ILI9341_RAMWR = 0x2C
|
||||
ILI9341_RAMRD = 0x2E
|
||||
|
||||
ILI9341_PTLAR = 0x30
|
||||
ILI9341_MADCTL = 0x36
|
||||
ILI9341_PIXFMT = 0x3A
|
||||
|
||||
ILI9341_FRMCTR1 = 0xB1
|
||||
ILI9341_FRMCTR2 = 0xB2
|
||||
ILI9341_FRMCTR3 = 0xB3
|
||||
ILI9341_INVCTR = 0xB4
|
||||
ILI9341_DFUNCTR = 0xB6
|
||||
|
||||
ILI9341_PWCTR1 = 0xC0
|
||||
ILI9341_PWCTR2 = 0xC1
|
||||
ILI9341_PWCTR3 = 0xC2
|
||||
ILI9341_PWCTR4 = 0xC3
|
||||
ILI9341_PWCTR5 = 0xC4
|
||||
ILI9341_VMCTR1 = 0xC5
|
||||
ILI9341_VMCTR2 = 0xC7
|
||||
|
||||
ILI9341_RDID1 = 0xDA
|
||||
ILI9341_RDID2 = 0xDB
|
||||
ILI9341_RDID3 = 0xDC
|
||||
ILI9341_RDID4 = 0xDD
|
||||
|
||||
ILI9341_GMCTRP1 = 0xE0
|
||||
ILI9341_GMCTRN1 = 0xE1
|
||||
|
||||
ILI9341_PWCTR6 = 0xFC
|
||||
|
||||
ILI9341_BLACK = 0x0000
|
||||
ILI9341_BLUE = 0x001F
|
||||
ILI9341_RED = 0xF800
|
||||
ILI9341_GREEN = 0x07E0
|
||||
ILI9341_CYAN = 0x07FF
|
||||
ILI9341_MAGENTA = 0xF81F
|
||||
ILI9341_YELLOW = 0xFFE0
|
||||
ILI9341_WHITE = 0xFFFF
|
||||
|
||||
|
||||
def color565(r, g, b):
|
||||
"""Convert red, green, blue components to a 16-bit 565 RGB value. Components
|
||||
should be values 0 to 255.
|
||||
"""
|
||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
|
||||
|
||||
def image_to_data(image):
|
||||
"""Generator function to convert a PIL image to 16-bit 565 RGB bytes."""
|
||||
#NumPy is much faster at doing this. NumPy code provided by:
|
||||
#Keith (https://www.blogger.com/profile/02555547344016007163)
|
||||
# pb = np.array(image.convert('RGB')).astype('uint16')
|
||||
# color = ((pb[:,:,0] & 0xF8) << 8) | ((pb[:,:,1] & 0xFC) << 3) | (pb[:,:,2] >> 3)
|
||||
# return np.dstack(((color >> 8) & 0xFF, color & 0xFF)).flatten().tolist()
|
||||
|
||||
# convert 24-bit RGB-8:8:8 to gBRG-3:5:5:3 ("BGR;16"):
|
||||
# 3 highest bits of green + 5 highest bits of blue in the first byte and
|
||||
# 5 highest bits of red + the next 3 highest bits of green (not yet expressed) in the second byte.
|
||||
# Then per-pixel byteswap to 16-bit RGB-5:6:5
|
||||
# This approach was measured to be ~3.4x faster than the numpy code above.
|
||||
arr = array.array("H", image.convert("BGR;16").tobytes())
|
||||
arr.byteswap()
|
||||
return arr.tobytes()
|
||||
|
||||
|
||||
class ILI9341(object):
|
||||
"""Representation of an ILI9341 TFT LCD."""
|
||||
|
||||
def __init__(self, dc=22, rst=13, led=12, width=ILI9341_TFTWIDTH,
|
||||
height=ILI9341_TFTHEIGHT, rotation=90):
|
||||
"""Create an instance of the display using SPI communication. Must
|
||||
provide the GPIO pin number for the D/C pin and the SPI driver. Can
|
||||
optionally provide the GPIO pin number for the reset pin as the rst
|
||||
parameter.
|
||||
"""
|
||||
spi = SpiDev(0, 0)
|
||||
# spi.mode = 0b10 # [CPOL|CPHA] -> polarity 1, phase 0
|
||||
spi.max_speed_hz = 64_000_000
|
||||
|
||||
self._dc = dc
|
||||
self._rst = rst
|
||||
self._spi = spi
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.rotation = rotation
|
||||
self.inverted = False
|
||||
# if self._gpio is None:
|
||||
# self._gpio = GPIO.get_platform_gpio()
|
||||
# Set DC as output.
|
||||
|
||||
GPIO.setmode(GPIO.BOARD) # Use physical pin nums, not gpio labels
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(self._dc, GPIO.OUT)
|
||||
GPIO.output(self._dc, GPIO.HIGH)
|
||||
GPIO.setup(led, GPIO.OUT)
|
||||
GPIO.output(led, GPIO.HIGH)
|
||||
if self._rst is not None:
|
||||
GPIO.setup(self._rst, GPIO.OUT)
|
||||
GPIO.output(self._rst, GPIO.HIGH)
|
||||
|
||||
# Create an image buffer.
|
||||
self.buffer = Image.new('RGB', (width, height))
|
||||
|
||||
# @property
|
||||
# def width(self):
|
||||
# return self.width
|
||||
|
||||
# @property
|
||||
# def height(self):
|
||||
# return self.height
|
||||
|
||||
|
||||
def send(self, data, is_data=True, chunk_size=4096):
|
||||
"""Write a byte or array of bytes to the display. Is_data parameter
|
||||
controls if byte should be interpreted as display data (True) or command
|
||||
data (False). Chunk_size is an optional size of bytes to write in a
|
||||
single SPI transaction, with a default of 4096.
|
||||
"""
|
||||
# Set DC low for command, high for data.
|
||||
GPIO.output(self._dc, is_data)
|
||||
# Convert scalar argument to list so either can be passed as parameter.
|
||||
if isinstance(data, numbers.Number):
|
||||
data = [data & 0xFF]
|
||||
# Write data a chunk at a time.
|
||||
# for start in range(0, len(data), chunk_size):
|
||||
# end = min(start+chunk_size, len(data))
|
||||
# self._spi.writebytes2(data[start:end])
|
||||
|
||||
self._spi.writebytes2(data)
|
||||
|
||||
def command(self, data):
|
||||
"""Write a byte or array of bytes to the display as command data."""
|
||||
self.send(data, False)
|
||||
|
||||
def data(self, data):
|
||||
"""Write a byte or array of bytes to the display as display data."""
|
||||
self.send(data, True)
|
||||
|
||||
def reset(self):
|
||||
"""Reset the display, if reset pin is connected."""
|
||||
if self._rst is not None:
|
||||
GPIO.output(self._rst, GPIO.HIGH)
|
||||
time.sleep(0.005)
|
||||
GPIO.output(self._rst, GPIO.LOW)
|
||||
time.sleep(0.02)
|
||||
GPIO.output(self._rst, GPIO.HIGH)
|
||||
time.sleep(0.150)
|
||||
|
||||
def _init(self):
|
||||
# Initialize the display. Broken out as a separate function so it can
|
||||
# be overridden by other displays in the future.
|
||||
self.command(0xEF)
|
||||
self.data(0x03)
|
||||
self.data(0x80)
|
||||
self.data(0x02)
|
||||
self.command(0xCF)
|
||||
self.data(0x00)
|
||||
self.data(0XC1)
|
||||
self.data(0X30)
|
||||
self.command(0xED)
|
||||
self.data(0x64)
|
||||
self.data(0x03)
|
||||
self.data(0X12)
|
||||
self.data(0X81)
|
||||
self.command(0xE8)
|
||||
self.data(0x85)
|
||||
self.data(0x00)
|
||||
self.data(0x78)
|
||||
self.command(0xCB)
|
||||
self.data(0x39)
|
||||
self.data(0x2C)
|
||||
self.data(0x00)
|
||||
self.data(0x34)
|
||||
self.data(0x02)
|
||||
self.command(0xF7)
|
||||
self.data(0x20)
|
||||
self.command(0xEA)
|
||||
self.data(0x00)
|
||||
self.data(0x00)
|
||||
self.command(ILI9341_PWCTR1) # Power control
|
||||
self.data(0x23) # VRH[5:0]
|
||||
self.command(ILI9341_PWCTR2) # Power control
|
||||
self.data(0x10) # SAP[2:0];BT[3:0]
|
||||
self.command(ILI9341_VMCTR1) # VCM control
|
||||
self.data(0x3e)
|
||||
self.data(0x28)
|
||||
self.command(ILI9341_VMCTR2) # VCM control2
|
||||
self.data(0x86) # --
|
||||
self.command(ILI9341_MADCTL) # Memory Access Control
|
||||
self.data(0x48)
|
||||
self.command(ILI9341_PIXFMT)
|
||||
self.data(0x55)
|
||||
self.command(ILI9341_FRMCTR1)
|
||||
self.data(0x00)
|
||||
self.data(0x18)
|
||||
self.command(ILI9341_DFUNCTR) # Display Function Control
|
||||
self.data(0x08)
|
||||
self.data(0x82)
|
||||
self.data(0x27)
|
||||
self.command(0xF2) # 3Gamma Function Disable
|
||||
self.data(0x00)
|
||||
self.command(ILI9341_GAMMASET) # Gamma curve selected
|
||||
self.data(0x01)
|
||||
self.command(ILI9341_GMCTRP1) # Set Gamma
|
||||
self.data(0x0F)
|
||||
self.data(0x31)
|
||||
self.data(0x2B)
|
||||
self.data(0x0C)
|
||||
self.data(0x0E)
|
||||
self.data(0x08)
|
||||
self.data(0x4E)
|
||||
self.data(0xF1)
|
||||
self.data(0x37)
|
||||
self.data(0x07)
|
||||
self.data(0x10)
|
||||
self.data(0x03)
|
||||
self.data(0x0E)
|
||||
self.data(0x09)
|
||||
self.data(0x00)
|
||||
self.command(ILI9341_GMCTRN1) # Set Gamma
|
||||
self.data(0x00)
|
||||
self.data(0x0E)
|
||||
self.data(0x14)
|
||||
self.data(0x03)
|
||||
self.data(0x11)
|
||||
self.data(0x07)
|
||||
self.data(0x31)
|
||||
self.data(0xC1)
|
||||
self.data(0x48)
|
||||
self.data(0x08)
|
||||
self.data(0x0F)
|
||||
self.data(0x0C)
|
||||
self.data(0x31)
|
||||
self.data(0x36)
|
||||
self.data(0x0F)
|
||||
self.command(ILI9341_SLPOUT) # Exit Sleep
|
||||
time.sleep(0.120)
|
||||
self.command(ILI9341_DISPON) # Display on
|
||||
|
||||
def begin(self):
|
||||
"""Initialize the display. Should be called once before other calls that
|
||||
interact with the display are called.
|
||||
"""
|
||||
self.reset()
|
||||
self._init()
|
||||
|
||||
def invert(self, state: bool = True):
|
||||
"""Sets display inversion to the specified state. If not provided, state
|
||||
is True, which inverts the display. If state is False, the display turns
|
||||
back into normal mode."""
|
||||
if state:
|
||||
self.command(ILI9341_INVON)
|
||||
else:
|
||||
self.command(ILI9341_INVOFF)
|
||||
self.inverted = state
|
||||
return self
|
||||
|
||||
def set_window(self, x0=0, y0=0, x1=None, y1=None):
|
||||
"""Set the pixel address window for proceeding drawing commands. x0 and
|
||||
x1 should define the minimum and maximum x pixel bounds. y0 and y1
|
||||
should define the minimum and maximum y pixel bound. If no parameters
|
||||
are specified the default will be to update the entire display from 0,0
|
||||
to 239,319.
|
||||
"""
|
||||
if x1 is None:
|
||||
x1 = self.width-1
|
||||
if y1 is None:
|
||||
y1 = self.height-1
|
||||
self.command(ILI9341_CASET) # Column addr set
|
||||
self.data(x0 >> 8)
|
||||
self.data(x0) # XSTART
|
||||
self.data(x1 >> 8)
|
||||
self.data(x1) # XEND
|
||||
self.command(ILI9341_PASET) # Row addr set
|
||||
self.data(y0 >> 8)
|
||||
self.data(y0) # YSTART
|
||||
self.data(y1 >> 8)
|
||||
self.data(y1) # YEND
|
||||
self.command(ILI9341_RAMWR) # write to RAM
|
||||
|
||||
def show_image(self, image=None, x_start: int = 0, y_start: int = 0):
|
||||
"""Write the display buffer or provided image to the hardware. If no
|
||||
image parameter is provided the display buffer will be written to the
|
||||
hardware. If an image is provided, it should be RGB format and the
|
||||
same dimensions as the display hardware.
|
||||
"""
|
||||
# By default write the internal buffer to the display.
|
||||
if image is None:
|
||||
image = self.buffer
|
||||
|
||||
output_image = image.rotate(self.rotation, expand=True)
|
||||
self.set_window(x_start, y_start, x_start + output_image.width - 1, y_start + output_image.height - 1)
|
||||
|
||||
# Convert image to array of 16bit 565 RGB data bytes.
|
||||
# Unfortunate that this copy has to occur, but the SPI byte writing
|
||||
# function needs to take an array of bytes and PIL doesn't natively
|
||||
# store images in 16-bit 565 RGB format.
|
||||
pixelbytes = image_to_data(output_image)
|
||||
|
||||
# Write data to hardware.
|
||||
self.data(pixelbytes)
|
||||
|
||||
def clear(self, color=(0,0,0)):
|
||||
"""Clear the image buffer to the specified RGB color (default black)."""
|
||||
width, height = self.buffer.size
|
||||
self.buffer.putdata([color]*(width*height))
|
||||
|
||||
def draw(self):
|
||||
"""Return a PIL ImageDraw instance for 2D drawing on the image buffer."""
|
||||
return ImageDraw.Draw(self.buffer)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,6 @@ import time
|
||||
|
||||
from seedsigner.models.singleton import Singleton
|
||||
from seedsigner.models.threads import BaseThread
|
||||
from seedsigner.models.settings import Settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -33,6 +32,8 @@ class MicroSD(Singleton, BaseThread):
|
||||
|
||||
@property
|
||||
def is_inserted(self):
|
||||
from seedsigner.models.settings import Settings # Import here to avoid circular import issues
|
||||
|
||||
if Settings.HOSTNAME == Settings.SEEDSIGNER_OS:
|
||||
return os.path.exists(MicroSD.MOUNT_POINT)
|
||||
else:
|
||||
@@ -47,6 +48,7 @@ class MicroSD(Singleton, BaseThread):
|
||||
def run(self):
|
||||
from seedsigner.controller import Controller
|
||||
from seedsigner.gui.toast import SDCardStateChangeToastManagerThread
|
||||
from seedsigner.models.settings import Settings # Import here to avoid circular import issues
|
||||
action = ""
|
||||
|
||||
# explicitly only microsd add/remove detection in seedsigner-os
|
||||
|
||||
@@ -2,6 +2,7 @@ import base64
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import zlib
|
||||
|
||||
from binascii import a2b_base64, b2a_base64
|
||||
from enum import IntEnum
|
||||
@@ -11,6 +12,7 @@ from pyzbar.pyzbar import ZBarSymbol
|
||||
from urtypes.crypto import PSBT as UR_PSBT
|
||||
from urtypes.crypto import Account, Output
|
||||
from urtypes.bytes import Bytes
|
||||
from base64 import b32encode, b32decode
|
||||
|
||||
from seedsigner.helpers.ur2.ur_decoder import URDecoder
|
||||
from seedsigner.models.qr_type import QRType
|
||||
@@ -74,6 +76,9 @@ class DecodeQR:
|
||||
elif self.qr_type == QRType.PSBT__BASE43:
|
||||
self.decoder = Base43PsbtQrDecoder() # Single Segment Base43
|
||||
|
||||
elif self.qr_type == QRType.PSBT__BBQR:
|
||||
self.decoder = BBQRPsbtQrDecoder() # BBQr Decoder
|
||||
|
||||
elif self.qr_type in [QRType.SEED__SEEDQR, QRType.SEED__COMPACTSEEDQR, QRType.SEED__MNEMONIC, QRType.SEED__FOUR_LETTER_MNEMONIC, QRType.SEED__UR2]:
|
||||
self.decoder = SeedQrDecoder(wordlist_language_code=self.wordlist_language_code)
|
||||
|
||||
@@ -229,7 +234,7 @@ class DecodeQR:
|
||||
if self.qr_type in [QRType.PSBT__UR2, QRType.OUTPUT__UR, QRType.ACCOUNT__UR, QRType.BYTES__UR]:
|
||||
return int(self.decoder.estimated_percent_complete(weight_mixed_frames=weight_mixed_frames) * 100)
|
||||
|
||||
elif self.qr_type in [QRType.PSBT__SPECTER]:
|
||||
elif self.qr_type in [QRType.PSBT__SPECTER, QRType.PSBT__BBQR]:
|
||||
if self.decoder.total_segments == None:
|
||||
return 0
|
||||
return int((self.decoder.collected_segments / self.decoder.total_segments) * 100)
|
||||
@@ -262,6 +267,7 @@ class DecodeQR:
|
||||
QRType.PSBT__SPECTER,
|
||||
QRType.PSBT__BASE64,
|
||||
QRType.PSBT__BASE43,
|
||||
QRType.PSBT__BBQR,
|
||||
]
|
||||
|
||||
|
||||
@@ -326,9 +332,6 @@ class DecodeQR:
|
||||
|
||||
@staticmethod
|
||||
def detect_segment_type(s, wordlist_language_code=None):
|
||||
# print("-------------- DecodeQR.detect_segment_type --------------")
|
||||
# print(type(s))
|
||||
# print(len(s))
|
||||
|
||||
try:
|
||||
# Convert to str data
|
||||
@@ -338,6 +341,9 @@ class DecodeQR:
|
||||
# TODO: Convert the test suite rather than handle here?
|
||||
s = s.decode('utf-8')
|
||||
|
||||
logger.debug(f"segment string: {s}")
|
||||
logger.debug(f"segment string length: {len(s)}")
|
||||
|
||||
# PSBT
|
||||
if re.search("^UR:CRYPTO-PSBT/", s, re.IGNORECASE):
|
||||
return QRType.PSBT__UR2
|
||||
@@ -357,6 +363,9 @@ class DecodeQR:
|
||||
elif DecodeQR.is_base64_psbt(s):
|
||||
return QRType.PSBT__BASE64
|
||||
|
||||
elif re.search(r"^B\$[2HZ]P[0-9A-Z]{4}", s): # https://github.com/coinkite/BBQr/blob/master/BBQr.md#spliting-the-data
|
||||
return QRType.PSBT__BBQR
|
||||
|
||||
# Wallet Descriptor
|
||||
desc_str = s.replace("\n","").replace(" ","")
|
||||
if re.search(r'^p(\d+)of(\d+) ', s, re.IGNORECASE):
|
||||
@@ -661,8 +670,9 @@ class BaseAnimatedQrDecoder(BaseQrDecoder):
|
||||
elif self.total_segments != self.total_segment_nums(segment):
|
||||
raise Exception('Segment total changed unexpectedly')
|
||||
|
||||
if self.segments[self.current_segment_num(segment) - 1] == None:
|
||||
self.segments[self.current_segment_num(segment) - 1] = self.parse_segment(segment)
|
||||
current_segment_num = self.current_segment_num(segment)
|
||||
if self.segments[current_segment_num - 1] == None:
|
||||
self.segments[current_segment_num - 1] = self.parse_segment(segment)
|
||||
self.collected_segments += 1
|
||||
if self.total_segments == self.collected_segments:
|
||||
if self.is_valid:
|
||||
@@ -711,6 +721,59 @@ class SpecterPsbtQrDecoder(BaseAnimatedQrDecoder):
|
||||
|
||||
|
||||
|
||||
class BBQRPsbtQrDecoder(BaseAnimatedQrDecoder):
|
||||
"""
|
||||
Used to decode BBQR Animated PSBT encoding.
|
||||
"""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.encoding = None
|
||||
|
||||
|
||||
def get_data(self) -> str:
|
||||
logger.debug("BBQRPsbtQrDecoder get_data")
|
||||
data = "".join(self.segments)
|
||||
if self.complete and self.encoding:
|
||||
if self.encoding == 'H':
|
||||
return b''.join(bytes.fromhex(s) for s in self.segments)
|
||||
|
||||
# base32 decode, but insert padding for API
|
||||
rv = b''
|
||||
for p in self.segments:
|
||||
padding = (8 - (len(p) % 8)) % 8
|
||||
rv += b32decode(p + (padding*'='))
|
||||
|
||||
if self.encoding == 'Z':
|
||||
# decompress
|
||||
z = zlib.decompressobj(wbits=-10)
|
||||
rv = z.decompress(rv)
|
||||
rv += z.flush()
|
||||
|
||||
return rv
|
||||
|
||||
return None
|
||||
|
||||
def current_segment_num(self, segment) -> int:
|
||||
current_segment = int(segment[6:8], 36) + 1
|
||||
logger.debug(f"BBQRPsbtQrDecoder current_segment_num {current_segment}")
|
||||
return current_segment
|
||||
|
||||
|
||||
def total_segment_nums(self, segment) -> int:
|
||||
total_segments = int(segment[4:6], 36)
|
||||
logger.debug(f"BBQRPsbtQrDecoder total_segment_nums {total_segments}")
|
||||
return total_segments
|
||||
|
||||
|
||||
def parse_segment(self, segment) -> str:
|
||||
self.encoding = segment[2]
|
||||
file_type = segment[3]
|
||||
data = segment[8:]
|
||||
|
||||
return data.strip()
|
||||
|
||||
|
||||
|
||||
class Base64PsbtQrDecoder(BaseSingleFrameQrDecoder):
|
||||
"""
|
||||
Decodes single frame base64 encoded qr image.
|
||||
|
||||
@@ -344,6 +344,9 @@ class UrXpubQrEncoder(BaseFountainQrEncoder, BaseXpubQrEncoder):
|
||||
return Keypath(arr, self.root.my_fingerprint, len(arr))
|
||||
|
||||
origin = derivation_to_keypath(self.derivation)
|
||||
|
||||
# Implemts "use_info" member on HDKey class (urtypes/crypto packages-libs folder) construct,
|
||||
# so if working on TESTNET, Xpub can be exported accordingly. Default case, MAINNET: None value.
|
||||
self.use_info = None if self.network == SettingsConstants.MAINNET else CoinInfo(type=None, network=1)
|
||||
|
||||
self.ur_hdkey = HDKey({ 'key': self.xpub.key.serialize(),
|
||||
|
||||
@@ -6,6 +6,7 @@ class QRType:
|
||||
PSBT__SPECTER = "psbt__specter"
|
||||
PSBT__BASE43 = "psbt__base43"
|
||||
PSBT__UR2 = "psbt__ur2"
|
||||
PSBT__BBQR = "psbt__bbqr"
|
||||
|
||||
SEED__SEEDQR = "seed__seedqr"
|
||||
SEED__COMPACTSEEDQR = "seed__compactseedqr"
|
||||
|
||||
@@ -123,7 +123,8 @@ class Settings(Singleton):
|
||||
|
||||
|
||||
def save(self):
|
||||
if self._data[SettingsConstants.SETTING__PERSISTENT_SETTINGS] == SettingsConstants.OPTION__ENABLED:
|
||||
from seedsigner.hardware.microsd import MicroSD
|
||||
if self._data[SettingsConstants.SETTING__PERSISTENT_SETTINGS] == SettingsConstants.OPTION__ENABLED and MicroSD.get_instance().is_inserted:
|
||||
with open(Settings.SETTINGS_FILENAME, 'w') as settings_file:
|
||||
json.dump(self._data, settings_file, indent=4)
|
||||
# SeedSignerOS makes removing the microsd possible, flush and then fsync forces persistent settings to disk
|
||||
@@ -191,13 +192,16 @@ class Settings(Singleton):
|
||||
self.load_locale()
|
||||
|
||||
|
||||
def get_value(self, attr_name: str):
|
||||
def get_value(self, attr_name: str, default_if_none: bool = None):
|
||||
"""
|
||||
Returns the attr's current value.
|
||||
|
||||
Note that for multiselect, the current value is a List.
|
||||
"""
|
||||
if attr_name not in self._data:
|
||||
if default_if_none:
|
||||
return SettingsDefinition.get_settings_entry(attr_name).default_value
|
||||
|
||||
raise Exception(f"Setting for {attr_name} not found")
|
||||
return self._data[attr_name]
|
||||
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, List
|
||||
|
||||
from seedsigner.helpers.l10n import mark_for_translation as _mft
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
class SettingsConstants:
|
||||
# Basic defaults
|
||||
@@ -46,31 +51,166 @@ class SettingsConstants:
|
||||
(COORDINATOR__KEEPER, "Keeper"),
|
||||
]
|
||||
|
||||
# Over-specifying current and possible future locales to reduce/eliminate main repo
|
||||
# changes when adding/testing new languages.
|
||||
LOCALE__ARABIC = "ar"
|
||||
LOCALE__BENGALI = "bn"
|
||||
LOCALE__BULGARIAN = "bg"
|
||||
LOCALE__CATALAN = "ca"
|
||||
LOCALE__CHINESE_SIMPLIFIED = "zh_Hans_CN"
|
||||
LOCALE__CHINESE_TRADITIONAL = "zh_Hant_TW"
|
||||
LOCALE__CROATIAN = "hr"
|
||||
LOCALE__CZECH = "cs"
|
||||
LOCALE__DANISH = "da"
|
||||
LOCALE__DUTCH = "nl"
|
||||
LOCALE__EGYPTIAN = "ar_EG"
|
||||
LOCALE__ENGLISH = "en"
|
||||
LOCALE__ESTONIAN = "et"
|
||||
LOCALE__FINNISH = "fi"
|
||||
LOCALE__FRENCH = "fr"
|
||||
LOCALE__GAELIC = "gd"
|
||||
LOCALE__GERMAN = "de"
|
||||
LOCALE__GREEK = "el"
|
||||
LOCALE__GUJARATI = "gu"
|
||||
LOCALE__HAUSA = "ha"
|
||||
LOCALE__HEBREW = "he"
|
||||
LOCALE__HINDI = "hi"
|
||||
LOCALE__HUNGARIAN = "hu"
|
||||
LOCALE__INDONESIAN = "id"
|
||||
LOCALE__ITALIAN = "it"
|
||||
LOCALE__JAPANESE = "ja"
|
||||
LOCALE__KOREAN = "kr"
|
||||
LOCALE__PORTUGUESE = "pt"
|
||||
LOCALE__JAVANESE = "jv"
|
||||
LOCALE__KOREAN = "ko"
|
||||
LOCALE__LAO = "lo"
|
||||
LOCALE__LATVIAN = "lv"
|
||||
LOCALE__LITHUANIAN = "lt"
|
||||
LOCALE__MALAY = "ms"
|
||||
LOCALE__MALTESE = "mt"
|
||||
LOCALE__MARATHI = "mr"
|
||||
LOCALE__NORWEGIAN = "no"
|
||||
LOCALE__PERSIAN = "fa"
|
||||
LOCALE__POLISH = "pl"
|
||||
LOCALE__PORTUGUESE_BR = "pt_BR"
|
||||
LOCALE__PORTUGUESE_PT = "pt_PT"
|
||||
LOCALE__PUNJABI = "pa"
|
||||
LOCALE__ROMANIAN = "ro"
|
||||
LOCALE__RUSSIAN = "ru"
|
||||
LOCALE__SLOVAK = "sk"
|
||||
LOCALE__SLOVENIAN = "sl"
|
||||
LOCALE__SPANISH = "es"
|
||||
# Do not wrap for translation; always present each language in its native form
|
||||
ALL_LOCALES = [
|
||||
# (LOCALE__ARABIC, "Arabic"),
|
||||
# (LOCALE__CZECH, "čeština"),
|
||||
(LOCALE__ENGLISH, "English"),
|
||||
# (LOCALE__FRENCH, "Français"),
|
||||
# (LOCALE__GERMAN, "Deutsch"),
|
||||
# (LOCALE__HEBREW, "Hebrew"),
|
||||
# (LOCALE__JAPANESE, "Japanese"),
|
||||
# (LOCALE__KOREAN, "Korean"),
|
||||
# (LOCALE__PORTUGUESE, "Português"),
|
||||
# (LOCALE__RUSSIAN, "русский"),
|
||||
(LOCALE__SPANISH, "Español"),
|
||||
]
|
||||
LOCALE__SWEDISH = "sv"
|
||||
LOCALE__TAGALOG = "tl"
|
||||
LOCALE__TAMIL = "ta"
|
||||
LOCALE__TELUGU = "te"
|
||||
LOCALE__THAI = "th"
|
||||
LOCALE__TURKISH = "tr"
|
||||
LOCALE__UKRANIAN = "uk"
|
||||
LOCALE__URDU = "ur"
|
||||
LOCALE__VIETNAMESE = "vi"
|
||||
|
||||
# Do not wrap for translation. Present each language in its native form (i.e. either
|
||||
# using its native chars or how they write it in Latin chars; e.g. Spanish is listed
|
||||
# and sorted as "Español").
|
||||
# Sort fully-vetted languages first, then beta languages, then the "placeholders /
|
||||
# coming soon" languages.
|
||||
# Sort by native form when written in Latin chars, otherwise sort by English name.
|
||||
# Include English name in parens for languages that don't use Latin chars.
|
||||
# Include region/country in parens for specific dialects (e.g. "Português (Brasil)").
|
||||
# Note that dicts preserve insertion order as of Python 3.7.
|
||||
ALL_LOCALES = {
|
||||
# --------- Fully supported languages -------------------------------------------
|
||||
LOCALE__CATALAN: "Català",
|
||||
LOCALE__GERMAN: "Deutsch",
|
||||
LOCALE__ENGLISH: "English",
|
||||
LOCALE__SPANISH: "Español",
|
||||
LOCALE__FRENCH: "Français",
|
||||
LOCALE__ITALIAN: "Italiano",
|
||||
LOCALE__DUTCH: "Nederlands",
|
||||
|
||||
# --------- Beta languages ------------------------------------------------------
|
||||
LOCALE__CHINESE_SIMPLIFIED: "(beta) 简体中文 (Chinese Simplified)",
|
||||
LOCALE__JAPANESE: "(beta) 日本語 (Japanese)",
|
||||
LOCALE__KOREAN: "(beta) 한국어 (Korean)",
|
||||
|
||||
# --------- Placeholders / Coming soon ------------------------------------------
|
||||
# Commented out options require explicit additional font support.
|
||||
# -------------------------------------------------------------------------------
|
||||
# LOCALE__ARABIC: "العربية (Arabic)",
|
||||
# LOCALE__BENGALI: "বাংলা (Bengali)",
|
||||
LOCALE__BULGARIAN: "български (Bulgarian)", # OpenSans includes cyrillic chars
|
||||
LOCALE__CZECH: "čeština",
|
||||
# LOCALE__CHINESE_TRADITIONAL: "繁體中文 (Chinese Traditional)",
|
||||
LOCALE__DANISH: "Dansk",
|
||||
LOCALE__ESTONIAN: "Eesti",
|
||||
# LOCALE__EGYPTIAN: "مصرى (Egyptian)",
|
||||
LOCALE__GAELIC: "Gaeilge",
|
||||
LOCALE__GREEK: "Ελληνικά (Greek)", # OpenSans includes Greek chars
|
||||
# LOCALE__GUJARATI: "ગુજરાતી (Gujarati)",
|
||||
LOCALE__HAUSA: "Hausa",
|
||||
# LOCALE__HEBREW: "עברית (Hebrew)",
|
||||
# LOCALE__HINDI: "हिन्दी (Hindi)",
|
||||
LOCALE__CROATIAN: "Hrvatski",
|
||||
LOCALE__INDONESIAN: "Indonesia",
|
||||
LOCALE__JAVANESE: "Jawa (Javanese)",
|
||||
# LOCALE__LAO: "ລາວ (Lao)",
|
||||
LOCALE__LATVIAN: "Latviešu",
|
||||
LOCALE__LITHUANIAN: "Lietuvių",
|
||||
LOCALE__HUNGARIAN: "Magyar",
|
||||
LOCALE__MALAY: "Melayu",
|
||||
LOCALE__MALTESE: "Malti",
|
||||
# LOCALE__MARATHI: "मराठी (Marathi)",
|
||||
LOCALE__NORWEGIAN: "Norsk",
|
||||
# LOCALE__PERSIAN: "فارسی (Persian)",
|
||||
LOCALE__POLISH: "Polski",
|
||||
LOCALE__PORTUGUESE_BR: "Português (Brasil)",
|
||||
LOCALE__PORTUGUESE_PT: "Português (Portugal)",
|
||||
# LOCALE__PUNJABI: "ਪੰਜਾਬੀ (Punjabi)",
|
||||
LOCALE__ROMANIAN: "Română",
|
||||
LOCALE__RUSSIAN: "русский (Russian)", # OpenSans includes cyrillic chars
|
||||
LOCALE__SLOVAK: "Slovenčina",
|
||||
LOCALE__SLOVENIAN: "Slovenščina",
|
||||
LOCALE__FINNISH: "Suomi",
|
||||
LOCALE__SWEDISH: "Svenska",
|
||||
LOCALE__TAGALOG: "Tagalog",
|
||||
# LOCALE__TAMIL: "தமிழ் (Tamil)",
|
||||
# LOCALE__TELUGU: "తెలుగు (Telugu)",
|
||||
# LOCALE__THAI: "ไทย (Thai)",
|
||||
LOCALE__TURKISH: "Türkçe",
|
||||
LOCALE__UKRANIAN: "українська (Ukranian)", # OpenSans includes cyrillic chars
|
||||
# LOCALE__URDU: "اردو (Urdu)",
|
||||
LOCALE__VIETNAMESE: "Tiếng Việt (Vietnamese)",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_detected_languages(cls) -> list[tuple[str, str]]:
|
||||
"""
|
||||
Return a list of tuples of language codes and their native names.
|
||||
|
||||
Scans the filesystem to autodiscover which language codes are onboard.
|
||||
"""
|
||||
# Will normally be the launch dir (where main.py is located)...
|
||||
cwd = os.getcwd()
|
||||
|
||||
# ...except when running the tests which happens one dir higher
|
||||
if "src" not in cwd:
|
||||
cwd = os.path.join(cwd, "src")
|
||||
|
||||
# Pre-load English since there's no "en" entry in the translations folder; also
|
||||
# it should always appear first in the list anyway.
|
||||
detected_languages = [(cls.LOCALE__ENGLISH, cls.ALL_LOCALES[cls.LOCALE__ENGLISH])]
|
||||
|
||||
locales_present = set()
|
||||
for root, dirs, files in os.walk(os.path.join(cwd, "seedsigner", "resources", "seedsigner-translations", "l10n")):
|
||||
for file in [f for f in files if f.endswith(".mo")]:
|
||||
# `root` will be [...]seedsigner/resources/seedsigner-translations/l10n/pt_BR/LC_MESSAGES
|
||||
locales_present.add(root.split(f"l10n{ os.sep }")[1].split(os.sep)[0])
|
||||
|
||||
for locale in cls.ALL_LOCALES.keys():
|
||||
if locale in locales_present:
|
||||
detected_languages.append((locale, cls.ALL_LOCALES[locale]))
|
||||
|
||||
return detected_languages
|
||||
|
||||
|
||||
BTC_DENOMINATION__BTC = "btc"
|
||||
BTC_DENOMINATION__SATS = "sats"
|
||||
@@ -172,7 +312,6 @@ class SettingsConstants:
|
||||
# (WORDLIST_LANGUAGE__PORTUGUESE, "Português"),
|
||||
]
|
||||
|
||||
|
||||
# Individual SettingsEntry attr_names
|
||||
# Note: attr_names are internal constants; do not wrap for translation
|
||||
SETTING__LOCALE = "locale"
|
||||
@@ -181,6 +320,9 @@ class SettingsConstants:
|
||||
SETTING__COORDINATORS = "coordinators"
|
||||
SETTING__BTC_DENOMINATION = "denomination"
|
||||
|
||||
SETTING__DISPLAY_CONFIGURATION = "display_config"
|
||||
SETTING__DISPLAY_COLOR_INVERTED = "color_inverted"
|
||||
|
||||
SETTING__NETWORK = "network"
|
||||
SETTING__QR_DENSITY = "qr_density"
|
||||
SETTING__XPUB_EXPORT = "xpub_export"
|
||||
@@ -200,6 +342,20 @@ class SettingsConstants:
|
||||
|
||||
SETTING__DEBUG = "debug"
|
||||
|
||||
|
||||
# Hardware config settings
|
||||
DISPLAY_CONFIGURATION__ST7789__240x240 = "st7789_240x240" # default; original Waveshare 1.3" display hat
|
||||
DISPLAY_CONFIGURATION__ST7789__320x240 = "st7789_320x240" # natively portrait dimensions; we apply a 90° rotation
|
||||
DISPLAY_CONFIGURATION__ILI9341__320x240 = "ili9341_320x240" # natively portrait dimensions; we apply a 90° rotation
|
||||
DISPLAY_CONFIGURATION__ILI9486__480x320 = "ili9486_480x320" # natively portrait dimensions; we apply a 90° rotation
|
||||
ALL_DISPLAY_CONFIGURATIONS = [
|
||||
(DISPLAY_CONFIGURATION__ST7789__240x240, "st7789 240x240"),
|
||||
(DISPLAY_CONFIGURATION__ST7789__320x240, "st7789 320x240"),
|
||||
(DISPLAY_CONFIGURATION__ILI9341__320x240, "ili9341 320x240 (beta)"),
|
||||
# (DISPLAY_CONFIGURATION__ILI9486__320x480, "ili9486 480x320"), # TODO: Enable when ili9486 driver performance is improved
|
||||
]
|
||||
|
||||
|
||||
# Hidden settings
|
||||
SETTING__QR_BRIGHTNESS = "qr_background_color"
|
||||
|
||||
@@ -213,6 +369,7 @@ class SettingsConstants:
|
||||
|
||||
VISIBILITY__GENERAL = "general"
|
||||
VISIBILITY__ADVANCED = "advanced"
|
||||
VISIBILITY__HARDWARE = "hardware"
|
||||
VISIBILITY__DEVELOPER = "developer"
|
||||
VISIBILITY__HIDDEN = "hidden" # For data-only (e.g. custom_derivation), not configurable by the user
|
||||
|
||||
@@ -382,7 +539,7 @@ class SettingsDefinition:
|
||||
abbreviated_name="lang",
|
||||
display_name=_mft("Language"),
|
||||
type=SettingsConstants.TYPE__SELECT_1,
|
||||
selection_options=SettingsConstants.ALL_LOCALES,
|
||||
selection_options=SettingsConstants.get_detected_languages(),
|
||||
default_value=SettingsConstants.LOCALE__ENGLISH),
|
||||
|
||||
# TODO: Support other bip-39 wordlist languages! Until then, type == HIDDEN
|
||||
@@ -542,6 +699,28 @@ class SettingsDefinition:
|
||||
visibility=SettingsConstants.VISIBILITY__ADVANCED,
|
||||
default_value=SettingsConstants.OPTION__ENABLED),
|
||||
|
||||
|
||||
# Hardware config
|
||||
SettingsEntry(category=SettingsConstants.CATEGORY__SYSTEM,
|
||||
attr_name=SettingsConstants.SETTING__DISPLAY_CONFIGURATION,
|
||||
abbreviated_name="disp_conf",
|
||||
# TRANSLATOR_NOTE: Hardware settings option to specify the screen driver (e.g. st7789 vs ili9341)
|
||||
display_name=_mft("Display type"),
|
||||
type=SettingsConstants.TYPE__SELECT_1,
|
||||
visibility=SettingsConstants.VISIBILITY__HARDWARE,
|
||||
selection_options=SettingsConstants.ALL_DISPLAY_CONFIGURATIONS,
|
||||
default_value=SettingsConstants.DISPLAY_CONFIGURATION__ST7789__240x240),
|
||||
|
||||
SettingsEntry(category=SettingsConstants.CATEGORY__SYSTEM,
|
||||
attr_name=SettingsConstants.SETTING__DISPLAY_COLOR_INVERTED,
|
||||
abbreviated_name="rgb_inv",
|
||||
# TRANSLATOR_NOTE: Hardware settings option to invert how the screen driver displays colors.
|
||||
display_name=_mft("Invert colors"),
|
||||
type=SettingsConstants.TYPE__ENABLED_DISABLED,
|
||||
visibility=SettingsConstants.VISIBILITY__HARDWARE,
|
||||
default_value=SettingsConstants.OPTION__DISABLED),
|
||||
|
||||
|
||||
# Developer options
|
||||
# TODO: No real Developer options needed yet. Disable for now.
|
||||
# SettingsEntry(category=SettingsConstants.CATEGORY__SYSTEM,
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Submodule src/seedsigner/resources/seedsigner-translations updated: 10ee02ae23...9f528ae075
@@ -77,6 +77,8 @@ class OpeningSplashScreen(LogoScreen):
|
||||
if self.force_partner_logos is not None:
|
||||
show_partner_logos = self.force_partner_logos
|
||||
|
||||
logo_offset_x = int((self.canvas_width - self.logo.width)/2)
|
||||
|
||||
if show_partner_logos:
|
||||
logo_offset_y = -56
|
||||
else:
|
||||
@@ -87,11 +89,14 @@ class OpeningSplashScreen(LogoScreen):
|
||||
# Fade in alpha
|
||||
for i in range(250, -1, -25):
|
||||
self.logo.putalpha(255 - i)
|
||||
self.renderer.canvas.paste(Image.alpha_composite(background, self.logo), (0, logo_offset_y))
|
||||
self.renderer.canvas.paste(
|
||||
Image.alpha_composite(background, self.logo),
|
||||
(logo_offset_x, logo_offset_y)
|
||||
)
|
||||
self.renderer.show_image()
|
||||
else:
|
||||
# Skip animation for the screenshot generator
|
||||
self.renderer.canvas.paste(self.logo, (0, logo_offset_y))
|
||||
self.renderer.canvas.paste(self.logo, (logo_offset_x, logo_offset_y))
|
||||
|
||||
# Display version num below SeedSigner logo
|
||||
font = Fonts.get_font(GUIConstants.get_body_font_name(), GUIConstants.get_top_nav_title_font_size())
|
||||
@@ -144,17 +149,24 @@ class ScreensaverScreen(LogoScreen):
|
||||
|
||||
self.buttons = buttons
|
||||
|
||||
# Paste the logo in a bigger image that is 2x the size of the logo
|
||||
self.image = Image.new("RGB", (2 * self.logo.size[0], 2 * self.logo.size[1]), (0,0,0))
|
||||
self.image.paste(self.logo, (int(self.logo.size[0] / 2), int(self.logo.size[1] / 2)))
|
||||
# Paste the logo in a bigger image that is the canvas + the logo dims (half the
|
||||
# logo will render off the canvas at each edge).
|
||||
self.image = Image.new("RGB", (self.renderer.canvas_width + self.logo.width, self.renderer.canvas_height + self.logo.height), (0,0,0))
|
||||
|
||||
# Place the logo centered on the larger image
|
||||
logo_x = int((self.image.width - self.logo.width) / 2)
|
||||
logo_y = int((self.image.height - self.logo.height) / 2)
|
||||
self.image.paste(self.logo, (logo_x, logo_y))
|
||||
|
||||
self.min_coords = (0, 0)
|
||||
self.max_coords = (self.logo.size[0], self.logo.size[1])
|
||||
self.max_coords = (self.renderer.canvas_width, self.renderer.canvas_height)
|
||||
|
||||
# Update our first rendering position so we're centered
|
||||
self.cur_x = int(self.logo.width / 2)
|
||||
self.cur_y = int(self.logo.height / 2)
|
||||
|
||||
self.increment_x = self.rand_increment()
|
||||
self.increment_y = self.rand_increment()
|
||||
self.cur_x = int(self.logo.size[0] / 2)
|
||||
self.cur_y = int(self.logo.size[1] / 2)
|
||||
|
||||
self._is_running = False
|
||||
self.last_screen = None
|
||||
@@ -197,7 +209,7 @@ class ScreensaverScreen(LogoScreen):
|
||||
crop = self.image.crop((
|
||||
self.cur_x, self.cur_y,
|
||||
self.cur_x + self.renderer.canvas_width, self.cur_y + self.renderer.canvas_height))
|
||||
self.renderer.disp.ShowImage(crop, 0, 0)
|
||||
self.renderer.disp.show_image(crop, 0, 0)
|
||||
|
||||
self.cur_x += self.increment_x
|
||||
self.cur_y += self.increment_y
|
||||
|
||||
@@ -1558,16 +1558,16 @@ class SeedTranscribeSeedQRWholeQRView(View):
|
||||
|
||||
class SeedTranscribeSeedQRZoomedInView(View):
|
||||
"""
|
||||
intial_block_x, initial_block_y: Used by the screenshot generator to shift the view
|
||||
intial_zone_x, initial_zone_y: Used by the screenshot generator to shift the view
|
||||
to a more interesting part of the QR code template.
|
||||
"""
|
||||
def __init__(self, seed_num: int, seedqr_format: str, initial_block_x: int = 0, initial_block_y: int = 0):
|
||||
def __init__(self, seed_num: int, seedqr_format: str, initial_zone_x: int = 0, initial_zone_y: int = 0):
|
||||
super().__init__()
|
||||
self.seed_num = seed_num
|
||||
self.seedqr_format = seedqr_format
|
||||
self.seed = self.controller.get_seed(seed_num)
|
||||
self.initial_block_x = initial_block_x
|
||||
self.initial_block_y = initial_block_y
|
||||
self.initial_zone_x = initial_zone_x
|
||||
self.initial_zone_y = initial_zone_y
|
||||
|
||||
|
||||
def run(self):
|
||||
@@ -1594,8 +1594,8 @@ class SeedTranscribeSeedQRZoomedInView(View):
|
||||
seed_screens.SeedTranscribeSeedQRZoomedInScreen(
|
||||
qr_data=data,
|
||||
num_modules=num_modules,
|
||||
initial_block_x=self.initial_block_x,
|
||||
initial_block_y=self.initial_block_y,
|
||||
initial_zone_x=self.initial_zone_x,
|
||||
initial_zone_y=self.initial_zone_y,
|
||||
).display()
|
||||
|
||||
return Destination(SeedTranscribeSeedQRConfirmQRPromptView, view_args={"seed_num": self.seed_num})
|
||||
@@ -1646,12 +1646,16 @@ class SeedTranscribeSeedQRConfirmScanView(View):
|
||||
|
||||
# Run the live preview and QR code capture process
|
||||
# TODO: Does this belong in its own BaseThread?
|
||||
self.run_screen(
|
||||
scanning_done=self.run_screen(
|
||||
ScanScreen,
|
||||
decoder=self.decoder,
|
||||
instructions_text=_("Scan your SeedQR")
|
||||
)
|
||||
|
||||
# If the scanning was canceled because the back button was pressed, return to BackStackView (SeedTranscribeSeedQRConfirmQRPromptView).
|
||||
if scanning_done==False:
|
||||
return Destination(BackStackView, skip_current_view=False)
|
||||
|
||||
if self.decoder.is_complete:
|
||||
if self.decoder.is_seed:
|
||||
seed_mnemonic = self.decoder.get_seed_phrase()
|
||||
@@ -1661,8 +1665,7 @@ class SeedTranscribeSeedQRConfirmScanView(View):
|
||||
else:
|
||||
return Destination(SeedTranscribeSeedQRConfirmSuccessView, view_args={"seed_num": self.seed_num})
|
||||
|
||||
else:
|
||||
# Will this case ever happen? Will trigger if a different kind of QR code is scanned
|
||||
# Will trigger if a different kind of QR code is scanned (non SeedQR)
|
||||
return Destination(SeedTranscribeSeedQRConfirmInvalidQRView, skip_current_view=True)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import logging
|
||||
from gettext import gettext as _
|
||||
|
||||
from seedsigner.gui.components import SeedSignerIconConstants
|
||||
from seedsigner.gui.components import GUIConstants, SeedSignerIconConstants
|
||||
from seedsigner.gui.screens import (RET_CODE__BACK_BUTTON, ButtonListScreen, settings_screens)
|
||||
from seedsigner.gui.screens.screen import ButtonOption
|
||||
from seedsigner.models.settings import Settings, SettingsConstants, SettingsDefinition
|
||||
@@ -13,6 +13,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SettingsMenuView(View):
|
||||
ADVANCED = ButtonOption("Advanced", right_icon_name=SeedSignerIconConstants.CHEVRON_RIGHT)
|
||||
HARDWARE = ButtonOption("Hardware", right_icon_name=SeedSignerIconConstants.CHEVRON_RIGHT)
|
||||
IO_TEST = ButtonOption("I/O test")
|
||||
DONATE = ButtonOption("Donate")
|
||||
|
||||
@@ -29,7 +31,7 @@ class SettingsMenuView(View):
|
||||
settings_entries = SettingsDefinition.get_settings_entries(
|
||||
visibility=self.visibility
|
||||
)
|
||||
button_data=[ButtonOption(e.display_name) for e in settings_entries]
|
||||
button_data: list[ButtonOption] = [ButtonOption(e.display_name) for e in settings_entries]
|
||||
|
||||
selected_button = 0
|
||||
if self.selected_attr:
|
||||
@@ -42,7 +44,7 @@ class SettingsMenuView(View):
|
||||
title = _("Settings")
|
||||
|
||||
# Set up the next nested level of menuing
|
||||
button_data.append(ButtonOption("Advanced", right_icon_name=SeedSignerIconConstants.CHEVRON_RIGHT))
|
||||
button_data.append(self.ADVANCED)
|
||||
next_destination = Destination(SettingsMenuView, view_args={"visibility": SettingsConstants.VISIBILITY__ADVANCED})
|
||||
|
||||
button_data.append(self.IO_TEST)
|
||||
@@ -51,9 +53,12 @@ class SettingsMenuView(View):
|
||||
elif self.visibility == SettingsConstants.VISIBILITY__ADVANCED:
|
||||
title = _("Advanced")
|
||||
|
||||
# So far there are no real Developer options; disabling for now
|
||||
# button_data.append(("Developer Options", None, None, None, SeedSignerIconConstants.CHEVRON_RIGHT))
|
||||
# next_destination = Destination(SettingsMenuView, view_args={"visibility": SettingsConstants.VISIBILITY__DEVELOPER})
|
||||
# The hardware options nest below "Advanced"
|
||||
button_data.append(self.HARDWARE)
|
||||
next_destination = Destination(SettingsMenuView, view_args={"visibility": SettingsConstants.VISIBILITY__HARDWARE})
|
||||
|
||||
elif self.visibility == SettingsConstants.VISIBILITY__HARDWARE:
|
||||
title = "Hardware"
|
||||
next_destination = None
|
||||
|
||||
elif self.visibility == SettingsConstants.VISIBILITY__DEVELOPER:
|
||||
@@ -80,20 +85,66 @@ class SettingsMenuView(View):
|
||||
else:
|
||||
return Destination(SettingsMenuView, view_args={"visibility": SettingsConstants.VISIBILITY__ADVANCED})
|
||||
|
||||
elif selected_menu_num == len(settings_entries):
|
||||
if button_data[selected_menu_num] == self.ADVANCED:
|
||||
return next_destination
|
||||
|
||||
elif len(button_data) > selected_menu_num and button_data[selected_menu_num] == self.IO_TEST:
|
||||
elif button_data[selected_menu_num] == self.HARDWARE:
|
||||
return next_destination
|
||||
|
||||
elif button_data[selected_menu_num] == self.IO_TEST:
|
||||
return Destination(IOTestView)
|
||||
|
||||
elif len(button_data) > selected_menu_num and button_data[selected_menu_num] == self.DONATE:
|
||||
elif button_data[selected_menu_num] == self.DONATE:
|
||||
return Destination(DonateView)
|
||||
|
||||
elif settings_entries[selected_menu_num].attr_name == SettingsConstants.SETTING__LOCALE:
|
||||
return Destination(LocaleSelectionView)
|
||||
|
||||
else:
|
||||
return Destination(SettingsEntryUpdateSelectionView, view_args=dict(attr_name=settings_entries[selected_menu_num].attr_name, parent_initial_scroll=initial_scroll))
|
||||
|
||||
|
||||
|
||||
class LocaleSelectionView(View):
|
||||
def run(self):
|
||||
cur_language_code = self.settings.get_value(SettingsConstants.SETTING__LOCALE)
|
||||
|
||||
selected_button = 0
|
||||
button_data: list[ButtonOption] = []
|
||||
for i, (language_code, display_name) in enumerate(SettingsConstants.get_detected_languages()):
|
||||
button_data.append(
|
||||
# Unique to this View: override each button's font so we can display each
|
||||
# language name in its native script.
|
||||
ButtonOption(
|
||||
button_label=display_name,
|
||||
return_data=language_code,
|
||||
font_name=GUIConstants.get_button_font_name(language_code),
|
||||
font_size=GUIConstants.get_button_font_size(language_code),
|
||||
)
|
||||
)
|
||||
|
||||
if language_code == cur_language_code:
|
||||
# Highlight the current selection
|
||||
selected_button = i
|
||||
|
||||
selected_menu_num = self.run_screen(
|
||||
settings_screens.SettingsEntryUpdateSelectionScreen,
|
||||
display_name=_(SettingsDefinition.get_settings_entry(attr_name=SettingsConstants.SETTING__LOCALE).display_name),
|
||||
button_data=button_data,
|
||||
selected_button=selected_button,
|
||||
checked_buttons=[selected_button],
|
||||
)
|
||||
|
||||
if selected_menu_num == RET_CODE__BACK_BUTTON:
|
||||
return Destination(SettingsMenuView)
|
||||
|
||||
# Set the new language
|
||||
self.settings.set_value(SettingsConstants.SETTING__LOCALE, button_data[selected_menu_num].return_data)
|
||||
|
||||
return Destination(SettingsMenuView)
|
||||
|
||||
|
||||
|
||||
class SettingsEntryUpdateSelectionView(View):
|
||||
"""
|
||||
Handles changes to all selection-type settings (Multiselect, SELECT_1,
|
||||
@@ -179,6 +230,12 @@ class SettingsEntryUpdateSelectionView(View):
|
||||
value=updated_value
|
||||
)
|
||||
|
||||
if self.settings_entry.attr_name == SettingsConstants.SETTING__DISPLAY_CONFIGURATION:
|
||||
self.renderer.initialize_display()
|
||||
|
||||
elif self.settings_entry.attr_name == SettingsConstants.SETTING__DISPLAY_COLOR_INVERTED:
|
||||
self.renderer.disp.invert(enabled=updated_value == SettingsConstants.OPTION__ENABLED)
|
||||
|
||||
if destination:
|
||||
return destination
|
||||
|
||||
@@ -198,8 +255,15 @@ class SettingsIngestSettingsQRView(View):
|
||||
# user.
|
||||
self.config_name, settings_update_dict = Settings.parse_settingsqr(data)
|
||||
|
||||
changes_display_driver = (
|
||||
SettingsConstants.SETTING__DISPLAY_CONFIGURATION in settings_update_dict and
|
||||
self.settings.get_value(SettingsConstants.SETTING__DISPLAY_CONFIGURATION) != settings_update_dict[SettingsConstants.SETTING__DISPLAY_CONFIGURATION])
|
||||
|
||||
self.settings.update(settings_update_dict)
|
||||
|
||||
if changes_display_driver:
|
||||
self.renderer.initialize_display()
|
||||
|
||||
if MicroSD.get_instance().is_inserted and self.settings.get_value(SettingsConstants.SETTING__PERSISTENT_SETTINGS) == SettingsConstants.OPTION__ENABLED:
|
||||
self.status_message = _("Persistent Settings enabled. Settings saved to SD card.")
|
||||
else:
|
||||
|
||||
@@ -5,7 +5,7 @@ import time
|
||||
|
||||
from gettext import gettext as _
|
||||
|
||||
from seedsigner.gui.components import FontAwesomeIconConstants, GUIConstants, SeedSignerIconConstants
|
||||
from seedsigner.gui.components import FontAwesomeIconConstants, GUIConstants, SeedSignerIconConstants, resize_image_to_fill
|
||||
from seedsigner.gui.screens import RET_CODE__BACK_BUTTON, ButtonListScreen
|
||||
from seedsigner.gui.screens.screen import ButtonOption
|
||||
from seedsigner.helpers import mnemonic_generation
|
||||
@@ -83,21 +83,25 @@ class ToolsImageEntropyFinalImageView(View):
|
||||
from seedsigner.hardware.camera import Camera
|
||||
# Take the final full-res image
|
||||
camera = Camera.get_instance()
|
||||
camera.start_single_frame_mode(resolution=(720, 480))
|
||||
max_dim = max(self.canvas_width, self.canvas_height)
|
||||
|
||||
# Final image will be at least 4x the number of pixels the screen can
|
||||
# actually display.
|
||||
camera.start_single_frame_mode(resolution=(2*max_dim, 2*max_dim))
|
||||
|
||||
time.sleep(0.25)
|
||||
self.controller.image_entropy_final_image = camera.capture_frame()
|
||||
camera.stop_single_frame_mode()
|
||||
|
||||
# Prep a copy of the image for display. The actual image data is 720x480
|
||||
# Present just a center crop and resize it to fit the screen and to keep some of
|
||||
# the data hidden.
|
||||
display_version = autocontrast(
|
||||
self.controller.image_entropy_final_image,
|
||||
cutoff=2
|
||||
).crop(
|
||||
(120, 0, 600, 480)
|
||||
).resize(
|
||||
(self.canvas_width, self.canvas_height), Image.Resampling.BICUBIC
|
||||
# Prep a copy of the image for display:
|
||||
# * Boost the contrast for better presentation (but preserve the original pixels)
|
||||
# * Resize it to fit the screen
|
||||
boosted_version = autocontrast(self.controller.image_entropy_final_image, cutoff=2)
|
||||
display_version = resize_image_to_fill(
|
||||
boosted_version,
|
||||
target_size_x=self.canvas_width,
|
||||
target_size_y=self.canvas_height,
|
||||
sampling_method=Image.Resampling.BICUBIC,
|
||||
)
|
||||
|
||||
ret = ToolsImageEntropyFinalImageScreen(
|
||||
@@ -130,6 +134,13 @@ class ToolsImageEntropyMnemonicLengthView(View):
|
||||
|
||||
mnemonic_length = button_data[selected_menu_num].return_data
|
||||
|
||||
# The entropy calculation can take time, especially with a full image buffer.
|
||||
# Show a loading spinner to provide feedback during this delay.
|
||||
from seedsigner.gui.screens.screen import LoadingScreenThread
|
||||
self.loading_screen = LoadingScreenThread(text=_("Calculating..."))
|
||||
self.loading_screen.start()
|
||||
|
||||
try:
|
||||
preview_images = self.controller.image_entropy_preview_frames
|
||||
seed_entropy_image = self.controller.image_entropy_final_image
|
||||
|
||||
@@ -175,6 +186,10 @@ class ToolsImageEntropyMnemonicLengthView(View):
|
||||
seed = Seed(mnemonic, wordlist_language_code=self.settings.get_value(SettingsConstants.SETTING__WORDLIST_LANGUAGE))
|
||||
self.controller.storage.set_pending_seed(seed)
|
||||
|
||||
finally:
|
||||
# Stop spinner even if an error occurs
|
||||
self.loading_screen.stop()
|
||||
|
||||
# Cannot return BACK to this View
|
||||
return Destination(SeedWordsWarningView, view_args={"seed_num": None}, clear_history=True)
|
||||
|
||||
@@ -619,6 +634,7 @@ class ToolsAddressExplorerAddressListView(View):
|
||||
|
||||
|
||||
def run(self):
|
||||
from seedsigner.gui.screens.tools_screens import ToolsAddressExplorerAddressListScreen
|
||||
self.loading_screen = None
|
||||
|
||||
addresses = []
|
||||
@@ -672,31 +688,11 @@ class ToolsAddressExplorerAddressListView(View):
|
||||
# Everything is set. Stop the loading screen
|
||||
self.loading_screen.stop()
|
||||
|
||||
for i, address in enumerate(addresses):
|
||||
cur_index = i + self.start_index
|
||||
|
||||
# Adjust the trailing addr display length based on available room
|
||||
# (the index number will push it out on each order of magnitude)
|
||||
if cur_index < 10:
|
||||
end_digits = -6
|
||||
elif cur_index < 100:
|
||||
end_digits = -5
|
||||
else:
|
||||
end_digits = -4
|
||||
button_data.append(ButtonOption(f"{cur_index}:{address[:8]}...{address[end_digits:]}", active_button_label=f"{cur_index}:{address}"))
|
||||
|
||||
# TRANSLATOR_NOTE: Insert the number of addrs displayed per screen (e.g. "Next 10")
|
||||
button_label = _("Next {}").format(addrs_per_screen)
|
||||
button_data.append(ButtonOption(button_label, right_icon_name=SeedSignerIconConstants.CHEVRON_RIGHT))
|
||||
|
||||
selected_menu_num = self.run_screen(
|
||||
ButtonListScreen,
|
||||
ToolsAddressExplorerAddressListScreen,
|
||||
title=_("Receive Addrs") if not self.is_change else _("Change Addrs"),
|
||||
button_data=button_data,
|
||||
button_font_name=GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME,
|
||||
button_font_size=GUIConstants.get_button_font_size() + 4,
|
||||
is_button_text_centered=False,
|
||||
is_bottom_list=True,
|
||||
start_index=self.start_index,
|
||||
addresses=addresses,
|
||||
selected_button=self.selected_button_index,
|
||||
scroll_y_initial_offset=self.initial_scroll,
|
||||
)
|
||||
|
||||
@@ -11,6 +11,8 @@ sys.modules['seedsigner.gui.toast'] = MagicMock()
|
||||
sys.modules['seedsigner.views.screensaver'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.buttons'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.camera'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.st7789_mpy'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.ili9341'] = MagicMock()
|
||||
|
||||
from seedsigner.controller import Controller, FlowBasedTestException, StopFlowBasedTest
|
||||
from seedsigner.gui.screens.screen import RET_CODE__BACK_BUTTON, RET_CODE__POWER_BUTTON, ButtonOption
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
coverage==7.3.1
|
||||
coverage==7.6.12
|
||||
pytest==7.4.2
|
||||
pytest-cov==4.1.0
|
||||
|
||||
@@ -6,6 +6,7 @@ import random
|
||||
import sys
|
||||
import time
|
||||
from unittest.mock import Mock, patch, MagicMock
|
||||
from PIL import ImageFont
|
||||
|
||||
from embit import compact
|
||||
from embit.psbt import PSBT, OutputScope
|
||||
@@ -13,17 +14,16 @@ from embit.script import Script
|
||||
|
||||
# Prevent importing modules w/Raspi hardware dependencies.
|
||||
# These must precede any SeedSigner imports.
|
||||
sys.modules['seedsigner.hardware.ST7789'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.displays.st7789_mpy'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.displays.ili9341'] = MagicMock()
|
||||
sys.modules['seedsigner.views.screensaver.ScreensaverScreen'] = MagicMock()
|
||||
sys.modules['RPi'] = MagicMock()
|
||||
sys.modules['RPi.GPIO'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.camera'] = MagicMock()
|
||||
sys.modules['seedsigner.hardware.microsd'] = MagicMock()
|
||||
|
||||
# Force the screenshots to mimic Pi Zero's output without libraqm
|
||||
patch('PIL.ImageFont.core.HAVE_RAQM', False).start()
|
||||
|
||||
from seedsigner.controller import Controller
|
||||
from seedsigner.gui.components import GUIConstants
|
||||
from seedsigner.gui.renderer import Renderer
|
||||
from seedsigner.gui.screens.seed_screens import SeedAddPassphraseScreen
|
||||
from seedsigner.gui.toast import RemoveSDCardToastManagerThread, SDCardStateChangeToastManagerThread
|
||||
@@ -45,10 +45,8 @@ from .utils import ScreenshotComplete, ScreenshotConfig, ScreenshotRenderer
|
||||
|
||||
import warnings; warnings.warn = lambda *args, **kwargs: None
|
||||
|
||||
|
||||
|
||||
# Dynamically generate a pytest test run for each locale
|
||||
@pytest.mark.parametrize("locale", [x for x, y in SettingsConstants.ALL_LOCALES])
|
||||
@pytest.mark.parametrize("locale", [x for x, y in SettingsConstants.get_detected_languages()])
|
||||
def test_generate_all(locale, target_locale):
|
||||
"""
|
||||
`target_locale` is a fixture created in conftest.py via the `--locale` command line arg.
|
||||
@@ -58,6 +56,11 @@ def test_generate_all(locale, target_locale):
|
||||
if target_locale and locale != target_locale:
|
||||
pytest.skip(f"Skipping {locale}")
|
||||
|
||||
if not ImageFont.core.HAVE_RAQM:
|
||||
# We can't generate pixel-perfect screenshots that match what gets rendered on
|
||||
# the device if we don't have libraqm.
|
||||
pytest.fail("libraqm is not installed.")
|
||||
|
||||
generate_screenshots(locale)
|
||||
|
||||
|
||||
@@ -160,36 +163,57 @@ def generate_screenshots(locale):
|
||||
"addr_format": embit_utils.parse_derivation_path(derivation_path)
|
||||
}
|
||||
|
||||
# Automatically populate all Settings options Views
|
||||
settings_views_list = []
|
||||
settings_views_list.append(ScreenshotConfig(settings_views.SettingsMenuView))
|
||||
settings_views_list.append(
|
||||
ScreenshotConfig(
|
||||
settings_views.SettingsMenuView,
|
||||
dict(
|
||||
visibility=SettingsConstants.VISIBILITY__ADVANCED,
|
||||
selected_attr=SettingsConstants.SETTING__ELECTRUM_SEEDS,
|
||||
initial_scroll=240, # Just guessing how many pixels to scroll down
|
||||
),
|
||||
screenshot_name="SettingsMenuView__Advanced"
|
||||
)
|
||||
)
|
||||
|
||||
# so we get a choice for transcribe seed qr format
|
||||
controller.settings.set_value(
|
||||
attr_name=SettingsConstants.SETTING__COMPACT_SEEDQR,
|
||||
value=SettingsConstants.OPTION__ENABLED
|
||||
)
|
||||
|
||||
# Automatically populate all Settings options Views
|
||||
settings_views_list = []
|
||||
def add_settings_entries(visibility = SettingsConstants.VISIBILITY__GENERAL):
|
||||
for settings_entry in SettingsDefinition.settings_entries:
|
||||
if settings_entry.visibility == SettingsConstants.VISIBILITY__HIDDEN:
|
||||
if settings_entry.visibility != visibility:
|
||||
continue
|
||||
|
||||
if settings_entry.attr_name == SettingsConstants.SETTING__LOCALE:
|
||||
# Locale selection has its own dedicated View
|
||||
settings_views_list.append(ScreenshotConfig(settings_views.LocaleSelectionView))
|
||||
else:
|
||||
# Generic SettingsEntry selection View
|
||||
settings_views_list.append(ScreenshotConfig(settings_views.SettingsEntryUpdateSelectionView, dict(attr_name=settings_entry.attr_name), screenshot_name=f"SettingsEntryUpdateSelectionView_{settings_entry.attr_name}"))
|
||||
|
||||
# Add the top level "General" settings menu and entries
|
||||
settings_views_list.append(ScreenshotConfig(settings_views.SettingsMenuView))
|
||||
add_settings_entries(SettingsConstants.VISIBILITY__GENERAL)
|
||||
|
||||
# Add the "Advanced" menu...
|
||||
settings_views_list.append(
|
||||
ScreenshotConfig(
|
||||
settings_views.SettingsMenuView,
|
||||
dict(
|
||||
visibility=SettingsConstants.VISIBILITY__ADVANCED,
|
||||
),
|
||||
screenshot_name="SettingsMenuView__Advanced"
|
||||
)
|
||||
)
|
||||
|
||||
# ...and Advanced entries
|
||||
add_settings_entries(SettingsConstants.VISIBILITY__ADVANCED)
|
||||
|
||||
# Render the nested "Advanced" -> "Hardware" submenu
|
||||
settings_views_list.append(
|
||||
ScreenshotConfig(
|
||||
settings_views.SettingsMenuView,
|
||||
dict(visibility=SettingsConstants.VISIBILITY__HARDWARE),
|
||||
screenshot_name="SettingsMenuView__Hardware"
|
||||
)
|
||||
)
|
||||
add_settings_entries(SettingsConstants.VISIBILITY__HARDWARE)
|
||||
|
||||
settingsqr_data_persistent = f"settings::v1 name=English_noob_mode persistent=E coords=spa,spd denom=thr network=M qr_density=M xpub_export=E sigs=ss scripts=nat xpub_details=E passphrase=E camera=0 compact_seedqr=E bip85=D priv_warn=E dire_warn=E partners=E locale={locale}"
|
||||
settingsqr_data_not_persistent = f"settings::v1 name=Mode_Ephemeral persistent=D coords=spa,spd denom=thr network=M qr_density=M xpub_export=E sigs=ss scripts=nat xpub_details=E passphrase=E camera=0 compact_seedqr=E bip85=D priv_warn=E dire_warn=E partners=E locale={locale}"
|
||||
|
||||
|
||||
# Set up screenshot-specific callbacks to inject data before the View is run and
|
||||
# reset data after the View is run.
|
||||
def load_basic_psbt_cb():
|
||||
@@ -293,8 +317,8 @@ def generate_screenshots(locale):
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRWholeQRView, dict(seed_num=0, seedqr_format=QRType.SEED__SEEDQR, num_modules=25), screenshot_name="SeedTranscribeSeedQRWholeQRView_12_Standard"),
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRWholeQRView, dict(seed_num=2, seedqr_format=QRType.SEED__COMPACTSEEDQR, num_modules=25), screenshot_name="SeedTranscribeSeedQRWholeQRView_24_Compact"),
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRWholeQRView, dict(seed_num=2, seedqr_format=QRType.SEED__SEEDQR, num_modules=29), screenshot_name="SeedTranscribeSeedQRWholeQRView_24_Standard"),
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRZoomedInView, dict(seed_num=0, seedqr_format=QRType.SEED__COMPACTSEEDQR, initial_block_x=1, initial_block_y=1), screenshot_name="SeedTranscribeSeedQRZoomedInView_12_Compact"),
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRZoomedInView, dict(seed_num=0, seedqr_format=QRType.SEED__SEEDQR, initial_block_x=2, initial_block_y=2), screenshot_name="SeedTranscribeSeedQRZoomedInView_12_Standard"),
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRZoomedInView, dict(seed_num=0, seedqr_format=QRType.SEED__COMPACTSEEDQR, initial_zone_x=1, initial_zone_y=1), screenshot_name="SeedTranscribeSeedQRZoomedInView_12_Compact"),
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRZoomedInView, dict(seed_num=0, seedqr_format=QRType.SEED__SEEDQR, initial_zone_x=2, initial_zone_y=2), screenshot_name="SeedTranscribeSeedQRZoomedInView_12_Standard"),
|
||||
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRConfirmQRPromptView, dict(seed_num=0)),
|
||||
ScreenshotConfig(seed_views.SeedTranscribeSeedQRConfirmWrongSeedView),
|
||||
@@ -428,7 +452,7 @@ def generate_screenshots(locale):
|
||||
with open(messages_source_path, 'r') as messages_source_file:
|
||||
num_source_messages = messages_source_file.read().count("msgid \"") - 1
|
||||
|
||||
locale_tuple_list = [locale_tuple for locale_tuple in SettingsConstants.ALL_LOCALES if locale_tuple[0] == locale]
|
||||
locale_tuple_list = [locale_tuple for locale_tuple in SettingsConstants.get_detected_languages() if locale_tuple[0] == locale]
|
||||
if not locale_tuple_list:
|
||||
raise Exception(f"Invalid locale: {locale}")
|
||||
|
||||
@@ -478,7 +502,7 @@ def generate_screenshots(locale):
|
||||
with open(os.path.join("tests", "screenshot_generator", "template.md"), 'r') as readme_template:
|
||||
main_readme = readme_template.read()
|
||||
|
||||
for locale, display_name in SettingsConstants.ALL_LOCALES:
|
||||
for locale, display_name in SettingsConstants.get_detected_languages():
|
||||
main_readme += f"* [{display_name}]({locale}/README.md)\n"
|
||||
|
||||
with open(os.path.join(screenshot_root, "README.md"), 'w') as readme_file:
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -13,7 +13,6 @@ from seedsigner.views.view import MainMenuView
|
||||
class TestL10nFlows(FlowTest):
|
||||
def test_change_locale(self):
|
||||
settings_entry = SettingsDefinition.get_settings_entry(SettingsConstants.SETTING__LOCALE)
|
||||
spanish_display_name = [locale_tuple[1] for locale_tuple in SettingsConstants.ALL_LOCALES if locale_tuple[0] == SettingsConstants.LOCALE__SPANISH][0]
|
||||
|
||||
# Initially we get English
|
||||
assert _(MainMenuView.SCAN.button_label) == "Scan"
|
||||
@@ -21,7 +20,7 @@ class TestL10nFlows(FlowTest):
|
||||
self.run_sequence([
|
||||
FlowStep(MainMenuView, button_data_selection=MainMenuView.SETTINGS),
|
||||
FlowStep(settings_views.SettingsMenuView, button_data_selection=ButtonOption(settings_entry.display_name)),
|
||||
FlowStep(settings_views.SettingsEntryUpdateSelectionView, button_data_selection=ButtonOption(spanish_display_name)),
|
||||
FlowStep(settings_views.LocaleSelectionView, screen_return_value=1), # Any index > 0 (English)
|
||||
])
|
||||
|
||||
# Now we don't get English
|
||||
|
||||
@@ -435,6 +435,9 @@ class TestSeedFlows(FlowTest):
|
||||
def load_completely_wrong_qr_type_into_decoder(view: View):
|
||||
view.decoder.add_data("I like cheese")
|
||||
|
||||
def load_recognized_qr_type_isnot_seed_into_decoder(view: View):
|
||||
view.decoder.add_data("UR:CRYPTO-PSBT/HKADHEJOJKIDJYZMADAEGMAOAEAEAEADHHGLEYKGBDSBKEMTSARLVYSGIABEDELFSKWLLUDKLYESJOFDLPJPFXSOHHWZTYWEAEAEAEAEAEZCZMZMZMADBKBZJEDEHEAEAEAECMAEBBVEPFDWDMBBGSPFZTKIMYCLKPSOBDDTRDWTWPYKGAQDKNAEAEGWADAAECLTTKAXWSWTUTSNLAAEAEAEPKCTBSHGISSSRETIVEWSGYNEPTHTESNSWMLBTARYEMHTBTBTLNWSBKJLMKYNFGHLAXJYBBTTIDHKDICHAMLEHHDSRKATGDLYSBIYHNHDNEWPJKZSZMDKVETYNSGOCXKNDNBEOLFSRSNSGHAEAELAADAEAELAAEAEAELAAEADADCTKSBZJEDEHEAEAEAECMAEBBVEPFDWDMBBGSPFZTKIMYCLKPSOBDDTRDWTWPYKGAADAXAAADAEAEAECPAMAODSFTLDTYFRECSKVWYLKNBANNKKZCRTHYJTPSHLHNHKNBPDCLCFDMSOLPDKFXLFQZCSOLFSRSNSGHAEAELAADAEAELAAEAEAELAAEAEAEAEAEAEAEAEAECPAOAODSFTLDTYFRECSKVWYLKNBANNKKZCRTHYJTPSHLHNHKNBPDCLCFDMSOLPDKFXLFQZCSOLFSRSNSGHAEAELAADAEAELAAEAEAELAAEAEAEAEAEAEAEAEAELGMKFZCW")
|
||||
|
||||
def load_right_seed_into_decoder(view: View):
|
||||
view.decoder.add_data("0000" * 11 + "0003")
|
||||
|
||||
@@ -460,6 +463,12 @@ class TestSeedFlows(FlowTest):
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRConfirmInvalidQRView),
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRZoomedInView, is_redirect=True), # Live interactive screens are still weird
|
||||
|
||||
# Intentionally scan QR data that makes no sense for this flow because is another QR recognized but is not a SeedQR (e.g., bitcoin address, psbt)
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRConfirmQRPromptView, button_data_selection=seed_views.SeedTranscribeSeedQRConfirmQRPromptView.SCAN),
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRConfirmScanView, before_run=load_recognized_qr_type_isnot_seed_into_decoder),
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRConfirmInvalidQRView),
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRZoomedInView, is_redirect=True), # Live interactive screens are still weird
|
||||
|
||||
# Now scan the correct SeedQR
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRConfirmQRPromptView, button_data_selection=seed_views.SeedTranscribeSeedQRConfirmQRPromptView.SCAN),
|
||||
FlowStep(seed_views.SeedTranscribeSeedQRConfirmScanView, before_run=load_right_seed_into_decoder),
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
from unittest.mock import Mock
|
||||
|
||||
from base import BaseTest
|
||||
from seedsigner.models.settings_definition import SettingsConstants
|
||||
|
||||
|
||||
class TestSettingsDefinition(BaseTest):
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
super().setup_class()
|
||||
|
||||
|
||||
def test__get_detected_languages(self):
|
||||
""" Should auto-detect onboard languages based on the supported locales list """
|
||||
detected_languages = [lang_tuple[0] for lang_tuple in SettingsConstants.get_detected_languages()]
|
||||
|
||||
# Find an unused language code; avoiding hard coding a language code to keep
|
||||
# this test future proof.
|
||||
absent_language_code = None
|
||||
for language_code in SettingsConstants.ALL_LOCALES.keys():
|
||||
if language_code not in detected_languages:
|
||||
absent_language_code = language_code
|
||||
break
|
||||
|
||||
# Should only fail if we've absolutely crushed the global translations!!!
|
||||
assert absent_language_code is not None
|
||||
|
||||
root = os.path.join(os.getcwd(), "src", "seedsigner", "resources", "seedsigner-translations", "l10n")
|
||||
|
||||
# We're going to mock the `root` results to include the absent language code's .mo file
|
||||
mocked_results = [(os.path.join(root, "en", "LC_MESSAGES"), [], ["messages.po", "messages.mo"])]
|
||||
mocked_results.append((os.path.join(root, absent_language_code, "LC_MESSAGES"), [], ["messages.po", "messages.mo"]))
|
||||
os.walk = Mock(return_value=mocked_results)
|
||||
|
||||
# Recheck w/our mocked dir listing:
|
||||
detected_languages = [lang_tuple[0] for lang_tuple in SettingsConstants.get_detected_languages()]
|
||||
assert absent_language_code in detected_languages
|
||||
Reference in New Issue
Block a user