-
-
Save back-seat-driver/b9d7025fcb19347eef7c370bb7b2092d to your computer and use it in GitHub Desktop.
PDM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Tkinter import * | |
import csv | |
import win32clipboard | |
import os | |
def bat_exe(): | |
''' | |
Note that both methods will execute a batch file from your home directory. | |
''' | |
#os.system("F:/Anaconda3/pdm_open.bat") | |
os.system("pdm_open.bat") | |
def beep_exe(): | |
os.system("beep.bat") | |
def number_handel(data_base_str,make_str): | |
center_str = data_base_str[2:len(data_base_str)-2] | |
solidworks_index = str(int(center_str[1:len(center_str)])+1) | |
index_padd = '0' * (6-len(solidworks_index)) | |
new_part_str = make_str + index_padd + solidworks_index | |
return(new_part_str) | |
def write_line(list_of_list): | |
#This function will take a list where each element of the list | |
#is a list of variable length. Now if the element if the root list | |
#is a list with a length of 1 it gets passed as a string. If the | |
#sub-list has a length greater than one that element is passed | |
#to the file line as a string. Fix function when read line function | |
#gets made. Not write line will append to the file by calling "a". | |
#For out purpose no data element will be declared over a length of 1. | |
with open("ROOT_PDM.csv", "a") as myfile: | |
writer = csv.writer(myfile) | |
writer.writerows([list_of_list]) | |
myfile.close() | |
def line_trace_number_return(type_str): | |
#This function will iterate over ever element of the master list | |
#filtered by A number, B number, and M number and will return | |
#the next possible value that can be produced given the filter. | |
#All database types are written as strings just to be correct. | |
#End poits are '[' and '''. | |
with open("ROOT_PDM.csv", "r") as myfile: | |
reader = list(csv.reader(myfile)) | |
for i in range(1,len(reader)+1): | |
if reader[-i] != []: | |
list_to_check = reader[-i] | |
if list_to_check[0][2]==type_str: | |
return(number_handel(list_to_check[0],type_str)) | |
def sub_str_search(search_val_str,set_str): | |
#This function takes a string and searchs another string for this value. Have to | |
#use try index statement. | |
bound_range = len(search_val_str) | |
for i in range(len(set_str)): | |
try: | |
if search_val_str == set_str[i:i+bound_range]: | |
return(True) | |
except IndexError: | |
return(False) | |
return(False) | |
def clip_insert(str_insert): | |
win32clipboard.OpenClipboard() | |
win32clipboard.EmptyClipboard() | |
win32clipboard.SetClipboardText(str_insert) | |
win32clipboard.CloseClipboard() | |
def ept(a_str): | |
return(a_str[2:len(a_str)-2]) | |
class PDM_GUI: | |
def __init__(self, master): | |
self.master = master | |
master.title("TALOS PDM") | |
part_type_label=Label(master,text='PART TYPE',height=2,width=15,bg="green") | |
part_type_label.place(x=5,y=5) | |
read_me_label = Label(master,text='New part number is pushed to clip board when Enter Part is clicked',height=2,width=60,bg="orange red") | |
read_me_label.place(x=250,y=5) | |
global part_type_str | |
part_type_str = StringVar(master) | |
part_type_str.set("Make") | |
part_type_str_option = OptionMenu(master, part_type_str,"Make", "Buy", "Assembly") | |
part_type_str_option.place(x=120,y=7) | |
#Checked | |
Manufacturer_Part_Number=Label(master,text='MANUFACTURER PART NUMBER',height=2,width=30,bg="green") | |
Manufacturer_Part_Number.place(x=5,y=50) | |
global Manufacturer_Part_Number_Text | |
Manufacturer_Part_Number_Text = Text(master,height=1,width=50,bg="white") | |
Manufacturer_Part_Number_Text.place(x=225,y=50) | |
#Checked | |
Website = Label(master,text='WEBSITE',height=2,width=30,bg="green") | |
Website.place(x=5,y=100) | |
global Website_Text | |
Website_Text = Text(master,height=1,width=50,bg="white") | |
Website_Text.place(x=225,y=95) | |
#Checked | |
Description = Label(master,text='DESCRIPTION ',height=2,width=30,bg="green") | |
Description.place(x=5,y=145) | |
global Description_Text | |
Description_Text = Text(master,height=1,width=50,bg="white") | |
Description_Text.place(x=225,y=145) | |
#Checked | |
Material = Label(master,text='MATERIAL',height=2,width=30,bg="green") | |
Material.place(x=5,y=200) | |
global Material_Text | |
Material_Text = Text(master,height=1,width=50,bg="white") | |
Material_Text.place(x=225,y=200) | |
#Checked | |
Assembly_Number = Label(master,text='ASSEMBLY NUMBER',height=2,width=30,bg="green") | |
Assembly_Number.place(x=5,y=250) | |
global Assembly_Number_Text | |
Assembly_Number_Text = Text(master,height=1,width=50,bg="white") | |
Assembly_Number_Text.place(x=225,y=250) | |
#INSERTED REV B | |
wild_card = Label(master,text='WILD CARD',height=2,width=30,bg='deep sky blue') | |
wild_card.place(x=5,y=400) | |
global wild_card_text | |
wild_card_text = Text(master,height=1,width=50,bg="white") | |
wild_card_text.place(x=225,y=400) | |
#Checked | |
New_Part_Number = Label(master,text='NEW PART NUMBER',height=2,width=30,bg="green") | |
New_Part_Number.place(x=5,y=300) | |
global New_Part_Number_Text | |
New_Part_Number_Text = Text(master,height=1,width=15,bg="yellow") | |
New_Part_Number_Text.place(x=225,y=300) | |
def main(): | |
#Checked | |
Manufacturer_Part_Number=Label(master,text='MANUFACTURER PART NUMBER',height=2,width=30,bg="green") | |
Manufacturer_Part_Number.place(x=5,y=50) | |
global Manufacturer_Part_Number_Text | |
Manufacturer_Part_Number_Text = Text(master,height=1,width=50,bg="white") | |
Manufacturer_Part_Number_Text.place(x=225,y=50) | |
#Checked | |
Website = Label(master,text='WEBSITE',height=2,width=30,bg="green") | |
Website.place(x=5,y=100) | |
global Website_Text | |
Website_Text = Text(master,height=1,width=50,bg="white") | |
Website_Text.place(x=225,y=95) | |
#Checked | |
Description = Label(master,text='DESCRIPTION ',height=2,width=30,bg="green") | |
Description.place(x=5,y=145) | |
global Description_Text | |
Description_Text = Text(master,height=1,width=50,bg="white") | |
Description_Text.place(x=225,y=145) | |
#Checked | |
Material = Label(master,text='MATERIAL',height=2,width=30,bg="green") | |
Material.place(x=5,y=200) | |
global Material_Text | |
Material_Text = Text(master,height=1,width=50,bg="white") | |
Material_Text.place(x=225,y=200) | |
#Checked | |
Assembly_Number = Label(master,text='ASSEMBLY NUMBER',height=2,width=30,bg="green") | |
Assembly_Number.place(x=5,y=250) | |
global Assembly_Number_Text | |
Assembly_Number_Text = Text(master,height=1,width=50,bg="white") | |
Assembly_Number_Text.place(x=225,y=250) | |
#INSERTED REV B | |
wild_card = Label(master,text='WILD CARD',height=2,width=30,bg='deep sky blue') | |
wild_card.place(x=5,y=400) | |
global wild_card_text | |
wild_card_text = Text(master,height=1,width=50,bg="white") | |
wild_card_text.place(x=225,y=400) | |
#INSERTED REV B | |
#Checked | |
New_Part_Number = Label(master,text='NEW PART NUMBER',height=2,width=30,bg="green") | |
New_Part_Number.place(x=5,y=300) | |
global New_Part_Number_Text | |
New_Part_Number_Text = Text(master,height=1,width=15,bg="yellow") | |
New_Part_Number_Text.place(x=225,y=300) | |
def fetch(): | |
global Manufacturer_Part_Number_Text | |
global Website_Text | |
global Description_Text | |
global Material_Text | |
global Assembly_Number_Text | |
return([[Manufacturer_Part_Number_Text.get("1.0",'end-1c')], | |
[Website_Text.get("1.0",'end-1c')], | |
[Description_Text.get("1.0",'end-1c')], | |
[Material_Text.get("1.0",'end-1c')], | |
[Assembly_Number_Text.get("1.0",'end-1c')]]) | |
def on_click_enter_part(): | |
with open("check_out_state.txt") as a_file: | |
for line in a_file: | |
if line==get_name() or line==None: | |
#if True==True: | |
global part_type_str | |
global new_part_insert | |
global New_Part_Number_Text | |
import time | |
import datetime | |
time_stamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') | |
part_type = part_type_str.get() | |
if part_type == 'Make': | |
new_part_insert = line_trace_number_return('M') | |
if part_type == 'Buy': | |
new_part_insert = line_trace_number_return('B') | |
if part_type == 'Assembly': | |
new_part_insert = line_trace_number_return('A') | |
New_Part_Number_Text.insert('1.0',new_part_insert) | |
data_line=fetch() | |
write_line([[new_part_insert]]+data_line+[[str(time_stamp)]]) | |
clip_insert(new_part_insert) | |
print(data_line) | |
print(new_part_insert) | |
#a_file.close() | |
else: | |
print('PDM is checked out') | |
#a_file.close() | |
#a_file.close() | |
def on_click_pdm_search(): | |
to_find=wild_card_text.get("1.0",'end-1c') | |
with open("ROOT_PDM.csv","r") as myfile: | |
reader = list(csv.reader(myfile)) | |
for i in range(len(reader)): | |
if reader[i]!=[]: | |
for x in range(len(reader[i])): | |
if sub_str_search(to_find,ept(reader[i][x]))==True: | |
print(reader[i]) | |
myfile.close() | |
def on_click_clear_text(): | |
main() | |
print("CLEARED") | |
def on_click_PDM_EDIT(): | |
with open("check_out_state.txt") as a_file: | |
for line in a_file: | |
if line==get_name() or line=='None': | |
bat_exe() | |
else: | |
print("File is checked out") | |
def on_click_PDM_Check_Out(): | |
with open("check_out_state.txt") as a_file: | |
for line in a_file: | |
if line==get_name(): | |
print('File is checked out') | |
a_file.close() | |
#break | |
if line=='None': | |
myfile = open("check_out_state.txt","w") | |
myfile.writelines([get_name()]) | |
print('File successfully checked out') | |
myfile.close() | |
def on_click_PDM_Check_In(): | |
with open("check_out_state.txt") as a_file: | |
for line in a_file: | |
if line==get_name(): | |
myfile = open("check_out_state.txt","w") | |
myfile.writelines(['None']) | |
print('File successfully checked in') | |
myfile.close() | |
else: | |
print("File is checked out") | |
def on_click_clear_text_csv_search(): | |
if mpn_state_var.get() == 1: | |
with open("ROOT_PDM.csv", "r") as myfile: | |
reader = list(csv.reader(myfile)) | |
#BUG REPORT RETURNS 5 when 10 is declared | |
#BUG REPORT RETURNS 5 when 10 is declared | |
#BUG REPORT RETURNS 5 when 10 is declared | |
for i in range(1,21): | |
if reader[-i]!=[]: | |
print(reader[-i]) | |
myfile.close() | |
if full_state_var.get() == 1: | |
with open("ROOT_PDM.csv", "r") as myfile: | |
reader = list(csv.reader(myfile)) | |
for i in range(len(reader)): | |
if reader[i]!=[]: | |
print(reader[i]) | |
myfile.close() | |
if make_state_var.get() == 1: | |
with open("ROOT_PDM.csv", "r") as myfile: | |
reader = list(csv.reader(myfile)) | |
for i in range(len(reader)): | |
if reader[i]!=[]: | |
if reader[i][0][2]=='M': | |
print(reader[i]) | |
myfile.close() | |
if buy_state_var.get() == 1: | |
with open("ROOT_PDM.csv", "r") as myfile: | |
reader = list(csv.reader(myfile)) | |
for i in range(len(reader)): | |
if reader[i]!=[]: | |
if reader[i][0][2]=='B': | |
print(reader[i]) | |
myfile.close() | |
if assembly_state_var.get() == 1: | |
with open("ROOT_PDM.csv", "r") as myfile: | |
reader = list(csv.reader(myfile)) | |
for i in range(len(reader)): | |
if reader[i]!=[]: | |
if reader[i][0][2]=='A': | |
print(reader[i]) | |
myfile.close() | |
def get_name(): | |
import win32api | |
return(win32api.GetComputerName()) | |
#with open("check_out_state.txt") as a_file: | |
#for line in a_file: | |
#print(line) | |
def print_name(): | |
import win32api | |
beep_exe() | |
print(win32api.GetComputerName()) | |
#POSSIBLE BUG change label='Enter Part' or text='Enter Part' | |
self.write=Button(master,text='Enter Part',command=on_click_enter_part,height=2,width=15,bg="pink") | |
self.write.place(x=50,y=350) | |
self.write=Button(master,text='Clear Text',command=on_click_clear_text,height=2,width=15,bg="red") | |
self.write.place(x=200,y=350) | |
self.write=Button(master,text='Return',command=on_click_clear_text_csv_search,height=2,width=15,bg="purple") | |
self.write.place(x=350,y=350) | |
self.write=Button(master,text='PDM Search',command=on_click_pdm_search,height=2,width=15,bg="yellow") | |
self.write.place(x=500,y=350) | |
self.write=Button(master,text='PDM Edit',command=on_click_PDM_EDIT,height=2,width=12,bg="magenta") | |
self.write.place(x=600,y=450) | |
self.write=Button(master,text='PDM Check Out',command=on_click_PDM_Check_Out,height=2,width=12,bg="wheat") | |
self.write.place(x=500,y=450) | |
self.write=Button(master,text='PDM Check In',command=on_click_PDM_Check_In,height=2,width=12,bg="lawn green") | |
self.write.place(x=400,y=450) | |
self.write=Button(master,text='Print Name',command=print_name,height=2,width=12,bg='cyan') | |
self.write.place(x=50,y=450) | |
### | |
### | |
#BELOW CHECK BOX FORMATING | |
### | |
### | |
mpn_state_var = IntVar() | |
mpn_state=Checkbutton(master,text='Last 10',variable=mpn_state_var) | |
mpn_state.place(x=500,y=275) | |
full_state_var = IntVar() | |
full_state=Checkbutton(master,text='PDM Full',variable=full_state_var) | |
full_state.place(x=500,y=300) | |
#Assembly/Make/Buy | |
make_state_var = IntVar() | |
make_state=Checkbutton(master,text='Make',variable=make_state_var) | |
make_state.place(x=350,y=275) | |
buy_state_var = IntVar() | |
buy_state=Checkbutton(master,text='Buy',variable=buy_state_var) | |
buy_state.place(x=350,y=300) | |
assembly_state_var = IntVar() | |
assembly_state=Checkbutton(master,text='Assembly',variable=assembly_state_var) | |
assembly_state.place(x=350,y=325) | |
root = Tk() | |
root.geometry("700x500") | |
root.resizable(width=False,height=False) | |
PDM_GUI(root) | |
root.mainloop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment