Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
so1der authored May 26, 2022
1 parent 0d879d4 commit d4f70f6
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 0 deletions.
Binary file added EIA96.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions EIA96.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
index = {"01": 100, "02": 102, "03": 105, "04": 107, "05": 110, "06": 113, "07": 115, "08": 118, "09": 121, "10": 124, "11": 127, "12": 130, "13": 133, "14": 137, "15": 140, "16": 143, "17": 147, "18": 150, "19": 154, "20": 158, "21": 162, "22": 165, "23": 169, "24": 174, "25": 178, "26": 182, "27": 187, "28": 191, "29": 169, "30": 200, "31": 205, "32": 210, "33": 215, "34": 221, "35": 226, "36": 232, "37": 237, "38": 243, "39": 249, "40": 255, "41": 261, "42": 267, "43": 274, "44": 280, "45": 287, "46": 294, "47": 301, "48": 309, "49": 316, "50": 324, "51": 332, "52": 340, "53": 348, "54": 357, "55": 365, "56": 374, "57": 383, "58": 392, "59": 402, "60": 412, "61": 422, "62": 432, "63": 442, "64": 453, "65": 464, "66": 475, "67": 487, "68": 499, "69": 511, "70": 523, "71": 536, "72": 549, "73": 562, "74": 576, "75": 590, "76": 604, "77": 619, "78": 634, "79": 649, "80": 665, "81": 681, "82": 698, "83": 715, "84": 732, "85": 750, "86": 768, "87": 787, "88": 806, "89": 825, "90": 845, "91": 866, "92": 887, "93": 909, "94": 931, "95": 953, "96": 976}
multipler = {"Z": 0.001, "Y": 0.01, "R": 0.01, "X": 0.1, "S": 0.1, "A": 1, "B": 10, "H": 10, "C": 100, "С": 100, "D": 1000, "E": 10000, "F": 100000}
2 changes: 2 additions & 0 deletions bin/EIA96.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
index = {"01": 100, "02": 102, "03": 105, "04": 107, "05": 110, "06": 113, "07": 115, "08": 118, "09": 121, "10": 124, "11": 127, "12": 130, "13": 133, "14": 137, "15": 140, "16": 143, "17": 147, "18": 150, "19": 154, "20": 158, "21": 162, "22": 165, "23": 169, "24": 174, "25": 178, "26": 182, "27": 187, "28": 191, "29": 169, "30": 200, "31": 205, "32": 210, "33": 215, "34": 221, "35": 226, "36": 232, "37": 237, "38": 243, "39": 249, "40": 255, "41": 261, "42": 267, "43": 274, "44": 280, "45": 287, "46": 294, "47": 301, "48": 309, "49": 316, "50": 324, "51": 332, "52": 340, "53": 348, "54": 357, "55": 365, "56": 374, "57": 383, "58": 392, "59": 402, "60": 412, "61": 422, "62": 432, "63": 442, "64": 453, "65": 464, "66": 475, "67": 487, "68": 499, "69": 511, "70": 523, "71": 536, "72": 549, "73": 562, "74": 576, "75": 590, "76": 604, "77": 619, "78": 634, "79": 649, "80": 665, "81": 681, "82": 698, "83": 715, "84": 732, "85": 750, "86": 768, "87": 787, "88": 806, "89": 825, "90": 845, "91": 866, "92": 887, "93": 909, "94": 931, "95": 953, "96": 976}
multipler = {"Z": 0.001, "Y": 0.01, "R": 0.01, "X": 0.1, "S": 0.1, "A": 1, "B": 10, "H": 10, "C": 100, "С": 100, "D": 1000, "E": 10000, "F": 100000}
Binary file added bin/ResistorsCalc.exe
Binary file not shown.
Binary file added bin/icon.ico
Binary file not shown.
Binary file added bin/resistor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon.ico
Binary file not shown.
Binary file added resistor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions resistors.pyw
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from tkinter import *
from PIL import ImageTk, Image
import re
#importing EIA-96 codes from EIA96.py:
from EIA96 import index, multipler

def calculate(e=None):
r_code = entry.get().upper().strip()
entry.delete(0, END)
entry.insert(0, r_code)
r_type = resistorCodeTypeCheker(r_code)
if r_type is None:
message_label.configure(text='Wrong Resistor Code!', fg='red')
r_label.configure(text='')
output_label.configure(text='')
return
message_label.configure(text='Enter Resistor Code:', fg='black')
resistance = resistanceСalculate(r_type, r_code)
resistance_value = unitAbbreviationsHandler(round(resistance, 3))
r_label.configure(text='Resistance:')
output_label.configure(text=resistance_value, fg='black')


def clearEntry():
entry.delete(0, END)
r_label.configure(text='')
output_label.configure(text='')
message_label.configure(text='Enter Resistor Code:', fg='black')


def unitAbbreviationsHandler(value):
if value < 1000:
answer = str(value) + " Ohms"
return(answer)
value = value/1000
answer = str(value) + " kOhms"
if value >= 1000:
value = value/1000
answer = str(value) + " MOhms"
return(answer)


def entryMaxCharacters():
entry.delete(4, END)


def resistorCodeTypeCheker(r_code):
patterns = ['^\d{4}$', '^\d{3}$', '^[R]+\d{1,3}$', '^\d{,2}[R]\d{1,3}$', '^\d{2}[A-F H R-S X-Z]$', '^[0]$']
types = ['4digits', '3digits', 'R+digits', 'digitsRdigits', 'EIA-96', 'zero']

for index, pattern in enumerate(patterns):
if re.match(pattern, r_code):
return types[index]


def resistanceСalculate(r_type, r_code):
match r_type:
case '3digits':
value = r_code[0] + r_code[1]
power = r_code[2]
resistance = int(value)*(10**int(power))
return resistance
case '4digits':
value = r_code[0] + r_code[1] + r_code[2]
power = r_code[3]
resistance = int(value)*(10**int(power))
return resistance
case 'EIA-96':
value = index[r_code[0] + r_code[1]]
power = str(r_code[2])
resistance = int(value)*multipler[power]
return resistance
case 'R+digits':
value = r_code.replace('R', '.')
resistance = "0" + str(value)
return float(resistance)
case 'digitsRdigits':
value = r_code.replace('R', '.')
return float(value)
case 'zero':
return 0


#Window elements initialization
main_window = Tk()
entry_text = StringVar()
main_window.resizable(0, 0)
main_window.minsize(300, 325)
r_label = Label(font=('Courier', 16))
main_window.bind('<Return>', calculate)
main_window.title("SMD Code Calculator")
ico = ImageTk.PhotoImage(Image.open("icon.ico"))
main_window.wm_iconphoto(False, ico)
output_label = Label(font=('Courier', 16), justify=CENTER)
resistor_image = ImageTk.PhotoImage(Image.open("resistor.png"))
r_image = Label(image=resistor_image)
autor_label = Label(text='by CTL', font=('Courier', 8), fg='gray')
message_label = Label(text='Enter Resistor Code:', font=('Courier', 16))
clear_button = Button(text='Clear', font=('Courier', 16), command=clearEntry)
calc_button = Button(text='Calculate', font=('Courier', 16), command=calculate)
entry = Entry(font=('Courier', 21), width=4, bg='black', fg='white', relief=FLAT, textvariable=entry_text, justify=CENTER)

#Window elements placement
clear_button.place(x=107, y=175)
message_label.place(x=18, y=10)
calc_button.place(x=82, y=125)
output_label.place(x=76, y=266)
r_image.place(x=101, y=50)
r_label.place(x=76, y=246)
autor_label.place(x=0, y=307)
entry.place(x=115, y=62)

entry_text.trace("w", lambda *args: entryMaxCharacters())
main_window.mainloop()

1 comment on commit d4f70f6

@primaxchannel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.