Skip to content

Commit

Permalink
Merge pull request #436 from jdlcdl/pr_434_label
Browse files Browse the repository at this point in the history
Uses grid_type to label TinySeed page ui
  • Loading branch information
odudex authored Aug 5, 2024
2 parents 4f18fbe + ed4b4d6 commit 36deb3f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/krux/pages/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def load_key_from_camera(self):
self.ctx,
[
(t("QR Code"), self.load_key_from_qr_code),
("Tiny Seed", lambda: self.load_key_from_tiny_seed_image("TinySeed")),
("Tiny Seed", lambda: self.load_key_from_tiny_seed_image("Tiny Seed")),
(
"OneKey KeyTag",
lambda: self.load_key_from_tiny_seed_image("OneKey KeyTag"),
Expand Down Expand Up @@ -681,7 +681,7 @@ def load_key_from_tiny_seed(self):
return self._load_key_from_words(words)
return MENU_CONTINUE

def load_key_from_tiny_seed_image(self, grid_type="TinySeed"):
def load_key_from_tiny_seed_image(self, grid_type="Tiny Seed"):
"""Menu handler to scan key from Tiny Seed sheet metal storage method"""
from .tiny_seed import TinyScanner

Expand Down
15 changes: 10 additions & 5 deletions src/krux/pages/tiny_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
class TinySeed(Page):
"""Class for handling Tinyseed fomat"""

def __init__(self, ctx):
def __init__(self, ctx, label=None):
super().__init__(ctx, None)
self.ctx = ctx
self.label = label
self.x_offset = MINIMAL_PADDING + 2 * FONT_WIDTH
self.printer = None
if self.ctx.display.width() > SMALLEST_WIDTH:
Expand Down Expand Up @@ -96,7 +97,7 @@ def _draw_grid(self):

def _draw_labels(self, page):
"""Draws labels for import and export Tinyseed UI"""
self.ctx.display.draw_hcentered_text("Tiny Seed")
self.ctx.display.draw_hcentered_text(self.label)

# case for non m5stickv, cube
if not MINIMAL_DISPLAY:
Expand Down Expand Up @@ -582,7 +583,7 @@ class TinyScanner(Page):

# Settings for different binary grid types
binary_grid_settings = {
"TinySeed": {
"Tiny Seed": {
"xpad_factor": (240 / (12 * 345)),
"ypad_factor": (210 / (12 * 272)),
"x_offset_factor_amigo_p0": 39 / 345,
Expand Down Expand Up @@ -628,7 +629,7 @@ class TinyScanner(Page):

grid_settings = None

def __init__(self, ctx, grid_type="TinySeed"):
def __init__(self, ctx, grid_type="Tiny Seed"):
super().__init__(ctx, None)
self.ctx = ctx
# Capturing flag used for first page of 24 words seed
Expand All @@ -638,8 +639,12 @@ def __init__(self, ctx, grid_type="TinySeed"):
self.y_regions = []
self.time_frame = time.ticks_ms()
self.previous_seed_numbers = [1] * 12
self.tiny_seed = TinySeed(self.ctx)
self.grid_settings = self.binary_grid_settings[grid_type]
if grid_type == "Binary Grid":
label = t("Binary Grid")
else:
label = grid_type
self.tiny_seed = TinySeed(self.ctx, label=label)

def _map_punches_region(self, rect_size, page=0):
# Think in portrait mode, with Tiny Seed tilted 90 degrees
Expand Down
27 changes: 27 additions & 0 deletions tests/pages/test_tiny_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,30 @@ def test_scan_tiny_seed_24w(all_devices, mocker):

assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
assert " ".join(words) == TEST_24_WORDS


def test_tinyscanner_initializes_tinyseed_with_label(all_devices, mocker):
import pytest
from krux.pages.tiny_seed import TinyScanner

test_cases = [
# TinyScanner grid_type param, expected exception, expected TinySeed label
(None, None, "Tiny Seed"),
("Tiny Seed", None, "Tiny Seed"),
("OneKey KeyTag", None, "OneKey KeyTag"),
("Binary Grid", None, "Binary Grid"),
("Unsupported Format", KeyError, None),
]

for i, (grid_type, expected_exception, expected_label) in enumerate(test_cases):
print(i, (grid_type, expected_exception, expected_label))
ctx = create_ctx(mocker, [])
if not expected_exception:
if grid_type:
tiny_scanner = TinyScanner(ctx, grid_type=grid_type)
else:
tiny_scanner = TinyScanner(ctx)
assert tiny_scanner.tiny_seed.label == expected_label
else:
with pytest.raises(expected_exception):
tiny_scanner = TinyScanner(ctx, grid_type=grid_type)

0 comments on commit 36deb3f

Please sign in to comment.