From a6a1f54455b550d779ac2365b7fdb0e7741ed32c Mon Sep 17 00:00:00 2001 From: Fish-in-a-Barrel Date: Sat, 16 Mar 2024 17:02:01 -0500 Subject: [PATCH 1/5] Added methods to quickly generate common series --- LabelGenerator.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/LabelGenerator.py b/LabelGenerator.py index b940646..9ae572c 100755 --- a/LabelGenerator.py +++ b/LabelGenerator.py @@ -117,6 +117,11 @@ def __init__( num_stickers_vertical=8, ) +E12 = [ 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2 ] + +# 1.1, 1.3, and 1.6 are commonly ommitted from the resistor E24 series +E24 = [ 1.0, 1.2, 1.5, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1] +E24_ALL = [ 1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1 ] class StickerRect: def __init__(self, c: Canvas, layout: PaperConfig, row: int, column: int, mirror: bool): @@ -602,6 +607,19 @@ def render_outlines(c: Canvas, layout: PaperConfig) -> None: c.setLineWidth(0) c.roundRect(rect.left, rect.bottom, rect.width, rect.height, rect.corner) +def generate_decade( + series: List[float], # the base series of resistor values + power: int # the power of 10 to scale the series by +) -> List[float]: + scalar = 10 ** power + return [scalar * x for x in series] + +def generate_decades( + series: List[float], + first_decade: int, + last_decade: int +) -> ResistorList: + return [generate_decade(series, x) for x in range(first_decade, last_decade)] def main() -> None: @@ -615,22 +633,13 @@ def main() -> None: # ############################################################################ # Put your own resistor values in here! # - # This has to be either a 2D grid or a 1D array. + # This has to be either a 2D grid or a 1D array. The E12, E24, and E24_ALL + # constants can be passed to the generate_decades function to create typical + # resistor value sets. # # Add "None" if no label should get generated at a specific position. # ############################################################################ - resistor_values: ResistorList = [ - [0, 0.02, .1], - [1, 12, 13], - [210, 220, 330], - [3100, 3200, 3300], - [41000, 42000, 43000], - [510000, None, 530000], - [6100000, 6200000, 6300000], - [71000000, 72000000, 73000000], - [810000000, 820000000, 830000000], - [9100000000, 9200000000, 3300000000], - ] + resistor_values: ResistorList = [0] + generate_decades(E24, 0, 6) + [ 1000000, None, 2000000 ] # ############################################################################ # Further configuration options From d935ac92af8b32e0c57ba3bd7d1230c8266f4e81 Mon Sep 17 00:00:00 2001 From: Fish-in-a-Barrel Date: Sat, 16 Mar 2024 17:41:53 -0500 Subject: [PATCH 2/5] Demoted the auto-generated values to an alternative method --- LabelGenerator.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/LabelGenerator.py b/LabelGenerator.py index 9ae572c..056f7e9 100755 --- a/LabelGenerator.py +++ b/LabelGenerator.py @@ -633,13 +633,28 @@ def main() -> None: # ############################################################################ # Put your own resistor values in here! # - # This has to be either a 2D grid or a 1D array. The E12, E24, and E24_ALL - # constants can be passed to the generate_decades function to create typical - # resistor value sets. + # This has to be either a 2D grid or a 1D array. # # Add "None" if no label should get generated at a specific position. # ############################################################################ - resistor_values: ResistorList = [0] + generate_decades(E24, 0, 6) + [ 1000000, None, 2000000 ] + resistor_values: ResistorList = [ + [0, 0.02, .1], + [1, 12, 13], + [210, 220, 330], + [3100, 3200, 3300], + [41000, 42000, 43000], + [510000, None, 530000], + [6100000, 6200000, 6300000], + [71000000, 72000000, 73000000], + [810000000, 820000000, 830000000], + [9100000000, 9200000000, 3300000000], + ] + + # ############################################################################ + # Alternatively, The E12, E24, and E24_ALL constants can be passed to the + # generate_decades function to create typical resistor value sets. + # ############################################################################ + # resistor_values: ResistorList = [ 0, 0.01 ] + generate_decades(E24, 0, 6) # ############################################################################ # Further configuration options From a05fe8d6fbfe49f6b1f1045096c33d0529ceaca2 Mon Sep 17 00:00:00 2001 From: Fish-in-a-Barrel Date: Sun, 17 Mar 2024 12:30:41 -0500 Subject: [PATCH 3/5] Additional documentation --- LabelGenerator.py | 57 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/LabelGenerator.py b/LabelGenerator.py index 056f7e9..f1b8be9 100755 --- a/LabelGenerator.py +++ b/LabelGenerator.py @@ -117,12 +117,6 @@ def __init__( num_stickers_vertical=8, ) -E12 = [ 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2 ] - -# 1.1, 1.3, and 1.6 are commonly ommitted from the resistor E24 series -E24 = [ 1.0, 1.2, 1.5, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1] -E24_ALL = [ 1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1 ] - class StickerRect: def __init__(self, c: Canvas, layout: PaperConfig, row: int, column: int, mirror: bool): self.left = layout.left_margin + layout.horizontal_stride * column @@ -607,19 +601,52 @@ def render_outlines(c: Canvas, layout: PaperConfig) -> None: c.setLineWidth(0) c.roundRect(rect.left, rect.bottom, rect.width, rect.height, rect.corner) -def generate_decade( + +# Resistor values typically come from an "E series of preferred numbers". This is why apparently +# random values such as 22, 39, or 47 are common, but some round numbers like 25, 40, or 50 +# are rarely seen. 10% resistors usually come from the E12 series, while 5% resistors usually +# come from to an abridged version of the E24 series. +# +# The list constants below can be used with the generate_values function to quickly create sets of +# common resistor values. +E12_VALUES = [ 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2 ] +E24_COMMON_VALUES = [ 1.0, 1.2, 1.5, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1 ] +E24_ALL_VALUES = [ 1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1 ] + +# Scales a list of values by a power of 10. The list may be one of the E constants above, or your +# own list of values. +# +# Examples: +# scale_values([1.0, 4.7, 7.5], 2) -> [100, 470, 750] +# +# scale_values(E12_VALUES, 1) -> [ 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82 ] +def scale_values( series: List[float], # the base series of resistor values power: int # the power of 10 to scale the series by ) -> List[float]: scalar = 10 ** power return [scalar * x for x in series] -def generate_decades( - series: List[float], - first_decade: int, - last_decade: int +# Expands a list of values into several lists, each scaled by increasing powers of 10. The list may +# be one of the E constants above, or your own list of values. +# +# Examples: +# generate_values([1.0, 4.7, 7.5], 0, 2) -> [ +# [ 1.0, 4.7, 7.5 ], # 10 ** 0 -> x1 +# [ 10, 47, 75 ], # 10 ** 1 -> x10 +# [ 100, 470, 750 ] # 10 ** 2 -> x100 +# ] +# +# generate_values(E12_VALUES, 1, 2) -> [ +# [ 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82 ], # 10 ** 1 -> x10 +# [ 100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680, 820 ] # 10 ** 2 -> x100 +# ] +def generate_values( + series: List[float], # the base series of resistor values + first_power: int, # the first power of 10 to scale the series by + last_power: int # the last power of 10 to scale the series by ) -> ResistorList: - return [generate_decade(series, x) for x in range(first_decade, last_decade)] + return [scale_values(series, x) for x in range(first_power, last_power)] def main() -> None: @@ -651,10 +678,10 @@ def main() -> None: ] # ############################################################################ - # Alternatively, The E12, E24, and E24_ALL constants can be passed to the - # generate_decades function to create typical resistor value sets. + # Alternatively, a set of common resistor values can be generated by the + # generate_values function. # ############################################################################ - # resistor_values: ResistorList = [ 0, 0.01 ] + generate_decades(E24, 0, 6) + # resistor_values: ResistorList = [ 0, 0.01 ] + generate_values(E24_COMMON_VALUES, 0, 6) # ############################################################################ # Further configuration options From 01df41f6f98631006e4e4da015524878d36f75d2 Mon Sep 17 00:00:00 2001 From: Fish-in-a-Barrel Date: Mon, 18 Mar 2024 10:59:17 -0500 Subject: [PATCH 4/5] Making linters happy. --- LabelGenerator.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/LabelGenerator.py b/LabelGenerator.py index f1b8be9..d072871 100755 --- a/LabelGenerator.py +++ b/LabelGenerator.py @@ -117,6 +117,7 @@ def __init__( num_stickers_vertical=8, ) + class StickerRect: def __init__(self, c: Canvas, layout: PaperConfig, row: int, column: int, mirror: bool): self.left = layout.left_margin + layout.horizontal_stride * column @@ -604,14 +605,17 @@ def render_outlines(c: Canvas, layout: PaperConfig) -> None: # Resistor values typically come from an "E series of preferred numbers". This is why apparently # random values such as 22, 39, or 47 are common, but some round numbers like 25, 40, or 50 -# are rarely seen. 10% resistors usually come from the E12 series, while 5% resistors usually -# come from to an abridged version of the E24 series. +# are rarely seen. 10% resistors usually come from the E12 series, while 5% resistors usually +# come from an abridged version of the E24 series. # # The list constants below can be used with the generate_values function to quickly create sets of # common resistor values. -E12_VALUES = [ 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2 ] -E24_COMMON_VALUES = [ 1.0, 1.2, 1.5, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1 ] -E24_ALL_VALUES = [ 1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1 ] +E12_VALUES = [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2] +E24_COMMON_VALUES = [1.0, 1.2, 1.5, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, + 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1] +E24_ALL_VALUES = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, + 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1] + # Scales a list of values by a power of 10. The list may be one of the E constants above, or your # own list of values. @@ -621,12 +625,13 @@ def render_outlines(c: Canvas, layout: PaperConfig) -> None: # # scale_values(E12_VALUES, 1) -> [ 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82 ] def scale_values( - series: List[float], # the base series of resistor values - power: int # the power of 10 to scale the series by + series: List[float], # the base series of resistor values + power: int # the power of 10 to scale the series by ) -> List[float]: scalar = 10 ** power return [scalar * x for x in series] + # Expands a list of values into several lists, each scaled by increasing powers of 10. The list may # be one of the E constants above, or your own list of values. # @@ -642,12 +647,13 @@ def scale_values( # [ 100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680, 820 ] # 10 ** 2 -> x100 # ] def generate_values( - series: List[float], # the base series of resistor values - first_power: int, # the first power of 10 to scale the series by - last_power: int # the last power of 10 to scale the series by -) -> ResistorList: + series: List[float], # the base series of resistor values + first_power: int, # the first power of 10 to scale the series by + last_power: int # the last power of 10 to scale the series by +) -> List[list[float]]: return [scale_values(series, x) for x in range(first_power, last_power)] + def main() -> None: # ############################################################################ @@ -678,7 +684,7 @@ def main() -> None: ] # ############################################################################ - # Alternatively, a set of common resistor values can be generated by the + # Alternatively, a set of common resistor values can be generated by the # generate_values function. # ############################################################################ # resistor_values: ResistorList = [ 0, 0.01 ] + generate_values(E24_COMMON_VALUES, 0, 6) From a062d6d06de5d7c90888acd6e772512958b72e1b Mon Sep 17 00:00:00 2001 From: Fish-in-a-Barrel Date: Mon, 18 Mar 2024 11:23:05 -0500 Subject: [PATCH 5/5] Make linters happier. --- LabelGenerator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LabelGenerator.py b/LabelGenerator.py index d072871..f44dd57 100755 --- a/LabelGenerator.py +++ b/LabelGenerator.py @@ -650,7 +650,7 @@ def generate_values( series: List[float], # the base series of resistor values first_power: int, # the first power of 10 to scale the series by last_power: int # the last power of 10 to scale the series by -) -> List[list[float]]: +) -> List[List[float]]: return [scale_values(series, x) for x in range(first_power, last_power)]