From 5429bd5734a43b782e937acbd0ed3d3c3e3d3144 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Sun, 20 Sep 2020 02:25:21 -0600 Subject: [PATCH] stm_layout: Convert to an installable package; fix pylint/flake8 issues. --- .flake8 | 7 + .gitignore | 145 ++++++++++++++++-- .pylintrc | 17 ++ LICENSE | 21 +++ Makefile | 51 ++++-- README.txt => README.rst | 17 +- setup.cfg | 26 ++++ setup.py | 3 + stm_layout/__init__.py | 7 + chip_db.py => stm_layout/chip_db.py | 25 +-- chip_package.py => stm_layout/chip_package.py | 32 ++-- chip_stm.py => stm_layout/chip_stm.py | 32 ++-- stm_layout.py => stm_layout/stm_layout.py | 72 +++++---- 13 files changed, 342 insertions(+), 113 deletions(-) create mode 100644 .flake8 create mode 100644 .pylintrc create mode 100644 LICENSE rename README.txt => README.rst (65%) create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 stm_layout/__init__.py rename chip_db.py => stm_layout/chip_db.py (93%) rename chip_package.py => stm_layout/chip_package.py (88%) rename chip_stm.py => stm_layout/chip_stm.py (93%) rename stm_layout.py => stm_layout/stm_layout.py (89%) diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..46f3627 --- /dev/null +++ b/.flake8 @@ -0,0 +1,7 @@ +[flake8] +ignore = E123, E126, E201, E203, E211, E221, E222, E225, E226, E227, E241, \ + E741, W504 C901 +exclude = .git,__pycache__,build,dist +max-complexity = 20 +max-line-length = 80 +good-names = l diff --git a/.gitignore b/.gitignore index ee4af3b..18ceaba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,131 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + *.swp -*.elf -*.o -*.d -*.a -*.map -*.out -*.pyc -/build/ -/bin/ -/tests/ -tags -/.xml -/modm_devices -/modm-devices -/tgcurses* diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..8920271 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,17 @@ +[MESSAGES CONTROL] +disable=bad-whitespace, + missing-module-docstring, + invalid-name, + missing-function-docstring, + too-many-arguments, + missing-class-docstring, + too-few-public-methods, + too-many-instance-attributes, + too-many-locals, + too-many-statements, + too-many-branches, + protected-access, + fixme, + global-statement, + broad-except, + useless-super-delegation diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..24c159b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Terry Greeniaus + +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. diff --git a/Makefile b/Makefile index ce3ee73..ea0b72e 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,45 @@ -.PHONY: all -all: tgcurses modm_devices +MODULE := stm_layout +MODULE_VERS := 0.1.0 +MODULE_DEPS := \ + setup.cfg \ + setup.py \ + stm_layout/*.py +FLAKE_MODULES := stm_layout +LINT_MODULES := stm_layout -tgcurses: - @git clone https://github.com/tgree/tgcurses tgcurses.git - @ln -s tgcurses.git/tgcurses +.PHONY: all +all: $(MODULE) +.PHONY: clean +clean: + rm -rf dist *.egg-info build + find . -name "*.pyc" | xargs rm + find . -name __pycache__ | xargs rm -r -modm-devices: - @git clone -b feature/pinout https://github.com/salkinium/modm-devices +.PHONY: test +test: flake8 lint +.PHONY: flake8 +flake8: + python3 -m flake8 $(FLAKE_MODULES) -.xml: modm-devices - @cd modm-devices/tools/generator && make init - @cd modm-devices/tools/generator && make extract-stm32 - @cd modm-devices/tools/generator && make generate-stm32 - @touch .xml +.PHONY: lint +lint: + pylint $(LINT_MODULES) +.PHONY: $(MODULE) +$(MODULE): dist/$(MODULE)-$(MODULE_VERS)-py3-none-any.whl -modm_devices: modm-devices - @ln -s modm-devices/modm_devices +.PHONY: install +install: $(MODULE) + sudo pip3 uninstall -y $(MODULE) + sudo pip3 install dist/$(MODULE)-$(MODULE_VERS)-py3-none-any.whl +.PHONY: uninstall +uninstall: + sudo pip3 uninstall $(MODULE) -clean: - @rm -rf tgcurses modm-devices .xml 2>/dev/null or true +dist/$(MODULE)-$(MODULE_VERS)-py3-none-any.whl: $(MODULE_DEPS) Makefile + python3 setup.py --quiet sdist bdist_wheel + python3 -m twine check $@ diff --git a/README.txt b/README.rst similarity index 65% rename from README.txt rename to README.rst index d015dd5..11f6a30 100644 --- a/README.txt +++ b/README.rst @@ -1,21 +1,26 @@ -Python curses-based tool for configuring STM32 pins. +Curses-based tool for configuring STM32 pins. +============================================= This tool uses a fork of the amazing curated .xml from the modm-devices project. The modm-devices project provides metadata about all STM32 devices in machine-parseable .xml format and is really what makes any tool like this one possible. -Building: Just type 'make'. +Installing:: -Usage: ./stm_layout -c + pip3 install stm_layout + +Usage:: + + stm_layout -c If chip_name is not fully-specified (i.e. 'stm32g474' is only a partial chip name), then a list of available chips matching that part will be printed to -stdout. If the chip name is fully specified, (i.e. 'stm32g474cet'), then a -text UI will be brought up for browsing/searching pins and configuring them. +stdout. If the chip name is fully-specified, (i.e. 'stm32g474cet6'), then a +curses UI will be brought up for browsing/searching pins and configuring them. Navigate using the arrow keys and the tab key. Search using standard regex -queries in the search bar. In any pane but the search pane: +queries in the search bar. In any pane but the search pane:: q - quits w - writes /tmp/stm32_pinout.txt diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..7354023 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,26 @@ +[metadata] +name = stm_layout +version = 0.1.0 +author = Terry Greeniaus +author_email = terrygreeniaus@gmail.com +description = Curses-based tool for configuring STM32 pins. +long_description = file: README.rst +long_description_content_type = text/x-rst +keywords = stm32 modm-devices pin pinout +url = https://github.com/tgree/stm_layout +license = License :: OSI Approved :: MIT License +classifiers = + Operating System :: POSIX + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + +[options] +python_requires = >=3.6 +packages = stm_layout +install_requires = + modm-devices + tgcurses + +[options.entry_points] +console_scripts = + stm_layout = stm_layout.stm_layout:_main diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b908cbe --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +import setuptools + +setuptools.setup() diff --git a/stm_layout/__init__.py b/stm_layout/__init__.py new file mode 100644 index 0000000..781b3ff --- /dev/null +++ b/stm_layout/__init__.py @@ -0,0 +1,7 @@ +from . import chip_db +from . import chip_stm + + +__all__ = ['chip_db', + 'chip_stm', + ] diff --git a/chip_db.py b/stm_layout/chip_db.py similarity index 93% rename from chip_db.py rename to stm_layout/chip_db.py index a6e57c5..8af2f35 100644 --- a/chip_db.py +++ b/stm_layout/chip_db.py @@ -1,9 +1,11 @@ -import modm_devices.parser import glob import math import re -import chip_package +import modm_devices.parser +import modm_devices.pkg + +from . import chip_package DEVICES = None @@ -12,7 +14,8 @@ def _populate_devices(): global DEVICES DEVICES = {} - for filename in glob.glob('modm-devices/devices/**/*.xml'): + basedir = modm_devices.pkg.get_filename('modm_devices', 'resources/devices') + for filename in glob.glob('%s/**/*.xml' % basedir): parser = modm_devices.parser.DeviceParser() devfile = parser.parse(filename) for device in devfile.get_devices(): @@ -35,15 +38,16 @@ def pin_count(dev): # Unfortunately, sometimes R means 64 and sometimes it means 68. So, we # just count the pins. For some reason, counting the pins goes slower. # Maybe modm-devices does some deferred loading? Yes it does. -Niklas - return len(set(p['position'] for p in dev.get_driver("gpio")["package"][0]["pin"])) + return len(set(p['position'] + for p in dev.get_driver('gpio')['package'][0]['pin'])) def package(dev): try: - return dev.get_driver("gpio")["package"][0]["name"] - except: + return dev.get_driver('gpio')['package'][0]['name'] + except Exception: pass - raise Exception("Device %s has unknown package '%s'." + raise Exception('Device %s has unknown package "%s".' % (dev, dev.identifier.package)) @@ -58,12 +62,15 @@ def make_package(dev): else: dim = int(math.ceil(math.sqrt(float(n)))) return chip_package.BGA(dim, dim) - elif any(name in p for name in ('LQFP', 'UFQFPN', 'VFQFPN')): + + if any(name in p for name in ('LQFP', 'UFQFPN', 'VFQFPN')): dim = int(math.ceil(float(n)/4.)) return chip_package.LQFP(dim, dim) - elif any(name in p for name in ('TSSOP', 'SO8N')): + + if any(name in p for name in ('TSSOP', 'SO8N')): dim = int(math.ceil(float(n)/2.)) return chip_package.TSSOP(dim) + raise KeyError diff --git a/chip_package.py b/stm_layout/chip_package.py similarity index 88% rename from chip_package.py rename to stm_layout/chip_package.py index e5d0918..6732be9 100644 --- a/chip_package.py +++ b/stm_layout/chip_package.py @@ -1,9 +1,9 @@ BGA_Y_TO_LABEL = 'ABCDEFGHJKLMNPRTUVWY' -BGA_LABEL_TO_Y = {label:i for i, label in enumerate(BGA_Y_TO_LABEL)} +BGA_LABEL_TO_Y = {label: i for i, label in enumerate(BGA_Y_TO_LABEL)} -class Package(object): +class Package: def __init__(self, width, height): self.width = width self.height = height @@ -13,7 +13,7 @@ def __init__(self, width, height): class BGA(Package): - class Cursor(object): + class Cursor: def __init__(self, chip): self.chip = chip self.pos = (-1, 0) @@ -31,7 +31,7 @@ def move(self, delta): return if new_pos[1] < 0 or new_pos[1] >= self.chip.height: return - if self.chip.pins[new_pos[0]][new_pos[1]] == None: + if self.chip.pins[new_pos[0]][new_pos[1]] is None: continue self.pos = new_pos @@ -67,7 +67,7 @@ def cursor(self): class LQFP(Package): - class Cursor(object): + class Cursor: def __init__(self, chip): self.chip = chip self.pos = (0, 1) @@ -110,7 +110,7 @@ def rotate(self, delta): self.pos = (self.chip.width - 1, self.pos[1] + delta) if self.pos[1] == self.chip.height - 1: self.pos = (self.pos[0] - delta, self.chip.height - 1) - if self.pin != None: + if self.pin is not None: return def clockwise(self): @@ -124,34 +124,34 @@ def __init__(self, width, height): def __getitem__(self, key): key = int(key, 10) - 1 - if 0 <= key and key < self.height - 2: + if 0 <= key < self.height - 2: return self.pins[0][key] key -= self.height - 2 - if 0 <= key and key < self.width - 2: + if 0 <= key < self.width - 2: return self.pins[key][self.height - 1] key -= self.width - 2 - if 0 <= key and key < self.height - 2: + if 0 <= key < self.height - 2: return self.pins[self.width - 1][self.height - 1 - key - 1] key -= self.height - 2 - if 0 <= key and key < self.width - 2: + if 0 <= key < self.width - 2: return self.pins[self.width - 1 - key - 1][0] raise KeyError def __setitem__(self, key, val): key = int(key, 10) - 1 - if 0 <= key and key < self.height - 2: + if 0 <= key < self.height - 2: self.pins[0][key + 1] = val return key -= self.height - 2 - if 0 <= key and key < self.width - 2: + if 0 <= key < self.width - 2: self.pins[key + 1][self.height - 1] = val return key -= self.width - 2 - if 0 <= key and key < self.height - 2: + if 0 <= key < self.height - 2: self.pins[self.width - 1][self.height - 1 - key - 1] = val return key -= self.height - 2 - if 0 <= key and key < self.width - 2: + if 0 <= key < self.width - 2: self.pins[self.width - 1 - key - 1][0] = val return raise KeyError @@ -161,7 +161,7 @@ def cursor(self): class TSSOP(Package): - class Cursor(object): + class Cursor: def __init__(self, chip): self.chip = chip self.pos = (-1, 0) @@ -179,7 +179,7 @@ def move(self, delta): return if new_pos[1] < 0 or new_pos[1] >= self.chip.height: return - if self.chip.pins[new_pos[0]][new_pos[1]] == None: + if self.chip.pins[new_pos[0]][new_pos[1]] is None: continue self.pos = new_pos diff --git a/chip_stm.py b/stm_layout/chip_stm.py similarity index 93% rename from chip_stm.py rename to stm_layout/chip_stm.py index 6805f2b..4fa4794 100644 --- a/chip_stm.py +++ b/stm_layout/chip_stm.py @@ -1,11 +1,8 @@ #!/usr/bin/env python3 -import argparse -import collections +from . import chip_db -import chip_db - -class Choice(object): +class Choice: def __init__(self, name, choices, val): self.name = name self.choices = choices @@ -17,7 +14,7 @@ def reset(self): self.val = self.default_val -class Pin(object): +class Pin: def __init__(self, name, key, alt_fns, add_fns, full_name): super(Pin, self).__init__() self.name = name @@ -58,7 +55,6 @@ def __init__(self, name, key, alt_fns, add_fns, full_name, part): def _reset(self): self._default = True if hasattr(self, '_gpio'): - gpio = self._gpio self._choices[0].reset() self._choices[1].reset() self._choices[2].reset() @@ -125,7 +121,7 @@ def _update_choices(self): self._choices[3].val = self._choices[3].default_val -class Chip(object): +class Chip: def __init__(self, part, chip_package, pins): self.name = str(part).upper() self.part = part @@ -183,25 +179,25 @@ def serialize_settings(self): if mask_2[port] == 0xFFFFFFFF: continue s += '%s.MODER = (%s.MODER & 0x%08X) | 0x%08X\n' % ( - port, port, mask_2[port], moder[port]) + port, port, mask_2[port], moder[port]) s += '%s.OTYPER = (%s.OTYPER & 0x%08X) | 0x%08X\n' % ( - port, port, mask_1[port], otyper[port]) + port, port, mask_1[port], otyper[port]) s += '%s.OSPEEDR = (%s.OSPEEDR & 0x%08X) | 0x%08X\n' % ( - port, port, mask_2[port], ospeedr[port]) + port, port, mask_2[port], ospeedr[port]) s += '%s.PUPDR = (%s.PUPDR & 0x%08X) | 0x%08X\n' % ( - port, port, mask_2[port], pupdr[port]) + port, port, mask_2[port], pupdr[port]) m = (mask_4[port] >> 0) & 0xFFFFFFFF if m != 0xFFFFFFFF: s += '%s.AFRL = (%s.AFRL & 0x%08X) | 0x%08X\n' % ( - port, port, - (mask_4[port] >> 0) & 0xFFFFFFFF, - (altfnr[port] >> 0) & 0xFFFFFFFF) + port, port, + (mask_4[port] >> 0) & 0xFFFFFFFF, + (altfnr[port] >> 0) & 0xFFFFFFFF) m = (mask_4[port] >> 32) & 0xFFFFFFFF if m != 0xFFFFFFFF: s += '%s.AFRH = (%s.AFRH & 0x%08X) | 0x%08X\n' % ( - port, port, - (mask_4[port] >> 32) & 0xFFFFFFFF, - (altfnr[port] >> 32) & 0xFFFFFFFF) + port, port, + (mask_4[port] >> 32) & 0xFFFFFFFF, + (altfnr[port] >> 32) & 0xFFFFFFFF) return s diff --git a/stm_layout.py b/stm_layout/stm_layout.py similarity index 89% rename from stm_layout.py rename to stm_layout/stm_layout.py index 7e7d4c4..0b60628 100755 --- a/stm_layout.py +++ b/stm_layout/stm_layout.py @@ -4,11 +4,11 @@ import curses.ascii import re -import chip_db -import chip_stm import tgcurses import tgcurses.ui +from stm_layout import chip_db, chip_stm + # Errors in documentation: # UFBGA pin G3 is listed twice @@ -63,17 +63,17 @@ def draw_info(info_win, pin): info_win.content.erase() attr = curses.color_pair(1) if REGEX and REGEX.search(pin.full_name) else 0 info_win.content.addstr( - ' Name: %-*s' % (info_win.content.width - 12, pin.full_name), - pos=(0,1), attr=attr) + ' Name: %-*s' % (info_win.content.width - 12, pin.full_name), + pos=(0, 1), attr=attr) attr = curses.color_pair(1) if REGEX and REGEX.search(pin.key) else 0 info_win.content.addstr( - ' Pos: %-*s' % (info_win.content.width - 12, pin.key), - pos=(1,1), attr=attr) + ' Pos: %-*s' % (info_win.content.width - 12, pin.key), + pos=(1, 1), attr=attr) config = 'Custom' if not pin._default else 'Default' attr = curses.color_pair(1) if REGEX and REGEX.search(config) else 0 info_win.content.addstr( - ' Config: %-*s' % (info_win.content.width - 12, config), - pos=(2,1), attr=attr) + ' Config: %-*s' % (info_win.content.width - 12, config), + pos=(2, 1), attr=attr) y = 0 for c in pin._choices: pattr = (curses.color_pair(1) @@ -113,7 +113,7 @@ def draw_alt_fns(alt_fns_win, alt_fns, pin_altfn): attr |= curses.A_BOLD alt_fns_win.content.addstr( '[%c] %2u: %-*s' % (check, i, alt_fns_win.content.width - 10, f), - pos=(i,1), attr=attr) + pos=(i, 1), attr=attr) alt_fns_win.content.noutrefresh() @@ -122,7 +122,7 @@ def draw_add_fns(add_fns_win, add_fns): for i, f in enumerate(add_fns): attr = curses.color_pair(1) if REGEX and REGEX.search(f) else 0 add_fns_win.content.addstr('%-*s' % (add_fns_win.content.width - 2, f), - pos=(i,1), attr=attr) + pos=(i, 1), attr=attr) add_fns_win.content.noutrefresh() @@ -198,6 +198,7 @@ def main(screen, chip): global REGEX_POS global ALTFNS_POS global INFO_POS + global FOCUS_WIN # Get the geometry. w, h = chip.width, chip.height @@ -231,35 +232,35 @@ def main(screen, chip): # Add a search window. search_win = ws.make_anchored_window( - 'Regex', - left_anchor=cpu_win.frame.left_anchor(), - top_anchor=cpu_win.frame.bottom_anchor(), - right_anchor=cpu_win.frame.right_anchor(), - h=3) + 'Regex', + left_anchor=cpu_win.frame.left_anchor(), + top_anchor=cpu_win.frame.bottom_anchor(), + right_anchor=cpu_win.frame.right_anchor(), + h=3) search_win.content.timeout(100) search_win.content.keypad(1) # Add an info window. info_win = ws.make_anchored_window( - 'Pin Info', - left_anchor=ws.canvas.frame.left_anchor(), - top_anchor=search_win.frame.bottom_anchor(), - w=14+name_len, h=18) + 'Pin Info', + left_anchor=ws.canvas.frame.left_anchor(), + top_anchor=search_win.frame.bottom_anchor(), + w=14+name_len, h=18) # Add an alternate functions window. alt_fns_win = ws.make_anchored_window( - 'Alternate Functions', - left_anchor=info_win.frame.right_anchor(), - top_anchor=search_win.frame.bottom_anchor(), - w=alt_fn_len+12, h=18) + 'Alternate Functions', + left_anchor=info_win.frame.right_anchor(), + top_anchor=search_win.frame.bottom_anchor(), + w=alt_fn_len+12, h=18) # Add an additional functions window. add_fns_win = ws.make_anchored_window( - 'Additional Functions', - left_anchor=alt_fns_win.frame.right_anchor(), - top_anchor=search_win.frame.bottom_anchor(), - bottom_anchor=alt_fns_win.frame.bottom_anchor(), - w=add_fn_len+4) + 'Additional Functions', + left_anchor=alt_fns_win.frame.right_anchor(), + top_anchor=search_win.frame.bottom_anchor(), + bottom_anchor=alt_fns_win.frame.bottom_anchor(), + w=add_fn_len+4) # Handle user input. update_ui(cpu_win, info_win, alt_fns_win, add_fns_win, search_win, chip, @@ -267,13 +268,14 @@ def main(screen, chip): tgcurses.ui.curs_set(0) while True: tgcurses.ui.doupdate() - c = FOCUS_WIN.content.getch() + c = cpu_win.content.getch() if c == -1: continue if FOCUS != FOCUS_SEARCH and c == ord('q'): break - elif FOCUS != FOCUS_SEARCH and c == ord('/'): + + if FOCUS != FOCUS_SEARCH and c == ord('/'): set_focus(FOCUS_SEARCH, cpu_win, info_win, alt_fns_win, add_fns_win, search_win, chip, cursor) elif FOCUS != FOCUS_SEARCH and c == ord('w'): @@ -317,7 +319,7 @@ def main(screen, chip): REGEX_POS -= 1 try: REGEX = re.compile(REGEX_STR) if REGEX_STR else None - except: + except Exception: REGEX = None elif c == curses.KEY_LEFT: REGEX_POS = max(REGEX_POS - 1, 0) @@ -333,7 +335,7 @@ def main(screen, chip): REGEX_POS += 1 try: REGEX = re.compile(REGEX_STR) - except: + except Exception: REGEX = None elif FOCUS == FOCUS_INFO: if c in (ord('j'), curses.KEY_DOWN): @@ -354,7 +356,7 @@ def main(screen, chip): cursor) -if __name__ == '__main__': +def _main(): parser = argparse.ArgumentParser() parser.add_argument('--chip', '-c', required=True) rv = parser.parse_args() @@ -366,3 +368,7 @@ def main(screen, chip): else: chip = chip_stm.make_chip(parts[0]) tgcurses.wrapper(main, chip) + + +if __name__ == '__main__': + _main()