Skip to content

Commit

Permalink
Clean up to prep PR for final review
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmukai committed Aug 5, 2023
1 parent 32953ee commit ac5c4d9
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 70 deletions.
11 changes: 0 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
from time import time
master_start = time()


start = time()
from seedsigner.controller import Controller
print("main.py time elapsed to import Controller:", time() - start)

# Get the one and only Controller instance and start our main loop
start = time()
controller = Controller.get_instance()
print("main.py time elapsed to import and initialize Controller:", time() - start)

print("*" * 80)
print("\nmain.py OVERALL time elapsed until Controller.start():", time() - master_start)
print("\n" + "*" * 80)
controller.start()
47 changes: 7 additions & 40 deletions src/seedsigner/controller.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
print("controller.py")

import time

from seedsigner.models.threads import BaseThread

start = time.time()
print("Starting Controller import...")

import logging

import traceback

from PIL.Image import Image

from seedsigner.models.settings import Settings
from seedsigner.models.singleton import Singleton
from seedsigner.models.threads import BaseThread
from seedsigner.views.view import Destination

from .models.settings import Settings
from .models.singleton import Singleton


logger = logging.getLogger(__name__)

print("Total Controller import time:", time.time() - start)


class BackStack(list[Destination]):
Expand Down Expand Up @@ -52,17 +44,17 @@ class FlowBasedTestException(Exception):
pass



class BackgroundImportThread(BaseThread):
def run(self):
start = time.time()
from importlib import import_module

# import seedsigner.hardware.buttons # slowly imports GPIO along the way

def time_import(module_name):
last = time.time()
import_module(module_name)
print(time.time() - last, module_name)
# print(time.time() - last, module_name)

time_import('embit')
time_import('seedsigner.helpers.embit_utils')
Expand All @@ -81,13 +73,6 @@ def time_import(module_name):

time_import('seedsigner.views.settings_views')

# Lowest priority costly initializations
# time_import('picamera')
# time_import('picamera.array')
# time_import('seedsigner.hardware.pivideostream')

print("Total BackgroundImportThread import time:", time.time() - start)



class Controller(Singleton):
Expand Down Expand Up @@ -166,7 +151,6 @@ def configure_instance(cls, disable_hardware=False):
each time you try to re-initialize a Controller.
"""
start = time.time()
from seedsigner.gui.renderer import Renderer
from seedsigner.hardware.microsd import MicroSD

Expand Down Expand Up @@ -195,13 +179,9 @@ def configure_instance(cls, disable_hardware=False):

# Other behavior constants
controller.screensaver_activation_ms = 120 * 1000

print(f"Controller configured in {time.time() - start:.3f}s")

start = time.time()
background_import_thread = BackgroundImportThread()
background_import_thread.start()
print("Time elapsed through BackgroundImportThread.start():", time.time() - start)

return cls._instance

Expand All @@ -214,15 +194,10 @@ def camera(self):

@property
def storage(self):
start = time.time()
did_sleep = False
while not self._storage:
# Wait for the BackgroundImportThread to finish initializing the storage.
# This is a rare timing issue that likely only occurs in the test suite.
did_sleep = True
time.sleep(0.001)
if did_sleep:
print(f"Controller.storage waited {time.time() - start:.3f}s for BackgroundImportThread")
return self._storage


Expand Down Expand Up @@ -265,15 +240,7 @@ def start(self, initial_destination: Destination = None) -> None:
from .views import MainMenuView, BackStackView
from .views.screensaver import OpeningSplashScreen

start = time.time()

opening_splash = OpeningSplashScreen()

print(f"Instantiating opening splash screen took {time.time() - start:.3f}s")
start = time.time()
opening_splash.start()

print(f"Opening splash screen took {time.time() - start:.3f}s")
OpeningSplashScreen().start()

""" Class references can be stored as variables in python!
Expand Down
1 change: 0 additions & 1 deletion src/seedsigner/helpers/embit_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
print("embit_utils.py")
import embit
from embit import bip32
from embit.bip32 import HDKey
Expand Down
2 changes: 0 additions & 2 deletions src/seedsigner/models/decode_qr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
print("decode_qr.py")

import base64
import json
import logging
Expand Down
2 changes: 0 additions & 2 deletions src/seedsigner/models/encode_qr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
print("encode_qr.py")

import math

from embit import bip32
Expand Down
2 changes: 0 additions & 2 deletions src/seedsigner/models/psbt_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
print("psbt_parser.py")

from binascii import hexlify
from embit import psbt, script, ec, bip32
from embit.descriptor import Descriptor
Expand Down
1 change: 0 additions & 1 deletion src/seedsigner/models/seed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
print("seed.py")
import unicodedata

from binascii import hexlify
Expand Down
2 changes: 0 additions & 2 deletions src/seedsigner/models/seed_storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
print("seed_storage.py")

from typing import List
from seedsigner.models.seed import Seed, InvalidSeedException
from seedsigner.models.settings_definition import SettingsConstants
Expand Down
2 changes: 0 additions & 2 deletions src/seedsigner/views/psbt_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
print("psbt_views.py")

import logging

from embit.psbt import PSBT
Expand Down
7 changes: 2 additions & 5 deletions src/seedsigner/views/seed_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
print("seed_views.py")

import embit
import random
import time
Expand All @@ -12,10 +10,10 @@

from seedsigner.controller import Controller
from seedsigner.gui.components import FontAwesomeIconConstants, SeedSignerCustomIconConstants
from seedsigner.helpers import embit_utils
from seedsigner.gui.screens import (RET_CODE__BACK_BUTTON, ButtonListScreen,
WarningScreen, DireWarningScreen, seed_screens)
from seedsigner.gui.screens.screen import LargeIconStatusScreen, QRDisplayScreen
from seedsigner.helpers import embit_utils
from seedsigner.models.decode_qr import DecodeQR
from seedsigner.models.encode_qr import EncodeQR
from seedsigner.models.psbt_parser import PSBTParser
Expand All @@ -26,8 +24,7 @@
from seedsigner.models.threads import BaseThread, ThreadsafeCounter
from seedsigner.views.psbt_views import PSBTChangeDetailsView
from seedsigner.views.scan_views import ScanView

from .view import NotYetImplementedView, View, Destination, BackStackView, MainMenuView
from seedsigner.views.view import NotYetImplementedView, View, Destination, BackStackView, MainMenuView



Expand Down
2 changes: 0 additions & 2 deletions src/seedsigner/views/tools_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
print("tools_views.py")

import hashlib
import os

Expand Down

0 comments on commit ac5c4d9

Please sign in to comment.