|
| 1 | +"""Subclass of dialog_text_base, which is generated by wxFormBuilder.""" |
| 2 | +from logging import exception |
| 3 | +import os |
| 4 | +import wx |
| 5 | +import sys |
| 6 | + |
| 7 | +from . import dialog_text_base |
| 8 | + |
| 9 | +_APP_NAME = "SparkFun KiCad BOM Generator" |
| 10 | + |
| 11 | +# sub folder for our resource files |
| 12 | +_RESOURCE_DIRECTORY = os.path.join("..", "resource") |
| 13 | + |
| 14 | +#https://stackoverflow.com/a/50914550 |
| 15 | +def resource_path(relative_path): |
| 16 | + """ Get absolute path to resource, works for dev and for PyInstaller """ |
| 17 | + base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) |
| 18 | + return os.path.join(base_path, _RESOURCE_DIRECTORY, relative_path) |
| 19 | + |
| 20 | +def get_version(rel_path: str) -> str: |
| 21 | + try: |
| 22 | + with open(resource_path(rel_path), encoding='utf-8') as fp: |
| 23 | + for line in fp.read().splitlines(): |
| 24 | + if line.startswith("__version__"): |
| 25 | + delim = '"' if '"' in line else "'" |
| 26 | + return line.split(delim)[1] |
| 27 | + raise RuntimeError("Unable to find version string.") |
| 28 | + except: |
| 29 | + raise RuntimeError("Unable to find _version.py.") |
| 30 | + |
| 31 | +_APP_VERSION = get_version("_version.py") |
| 32 | + |
| 33 | +class Dialog(dialog_text_base.DIALOG_TEXT_BASE): |
| 34 | + |
| 35 | + def __init__(self, parent): |
| 36 | + dialog_text_base.DIALOG_TEXT_BASE.__init__(self, parent) |
| 37 | + |
| 38 | + # hack for some gtk themes that incorrectly calculate best size |
| 39 | + #best_size = self.BestSize |
| 40 | + #best_size.IncBy(dx=0, dy=30) |
| 41 | + #self.SetClientSize(best_size) |
| 42 | + |
| 43 | + self.SetTitle(_APP_NAME + " - " + _APP_VERSION) |
| 44 | + |
| 45 | + self.Bind(wx.EVT_SIZE, self.OnSize) |
| 46 | + |
| 47 | + def OnSize(self, event): |
| 48 | + size = self.GetClientSize() |
| 49 | + |
| 50 | + # Limit Refs column width |
| 51 | + |
| 52 | + cols = self.bomGrid.GetNumberCols() |
| 53 | + colWidth = 0 |
| 54 | + for col in range(cols - 1): |
| 55 | + colWidth += self.bomGrid.GetColSize(col) |
| 56 | + newWidth = size.width - (colWidth |
| 57 | + + 50 |
| 58 | + ) # TODO: figure out how to do this properly! |
| 59 | + if newWidth < 0: |
| 60 | + newWidth = -1 |
| 61 | + self.bomGrid.SetColSize(cols - 1, newWidth) |
| 62 | + |
| 63 | + cols = self.nonBomGrid.GetNumberCols() |
| 64 | + colWidth = 0 |
| 65 | + for col in range(cols - 1): |
| 66 | + colWidth += self.nonBomGrid.GetColSize(col) |
| 67 | + newWidth = size.width - (colWidth |
| 68 | + + 50 |
| 69 | + ) # TODO: figure out how to do this properly! |
| 70 | + if newWidth < 0: |
| 71 | + newWidth = -1 |
| 72 | + self.nonBomGrid.SetColSize(cols - 1, newWidth) |
| 73 | + |
| 74 | + if event is not None: |
| 75 | + event.Skip() |
| 76 | + |
| 77 | + |
0 commit comments