def getFilePath(): filepath = filedialog.askopenfilename(initialdir = qrMaker.getCurrentPath(), title = "Select Credentials File", filetypes=[("Json", '*.json'), ("All Fucken Files", "*.*")]) return str(filepath)
def openPreferences(): def testSheet(): try: creds = ServiceAccountCredentials.from_json_keyfile_name(jsonOperation.readFromJson('credentialsJsonEntry', jsonPath),scope) try: client = gspread.authorize(creds) sheet = client.open("spoolData").sheet1 try: openWeb.openChrome(sheetEntry.get()) statusText['text'] = "All tests successful" except: statusText['text'] = "Unable to open sheet" except: statusText['text'] = "Unable to authorize" except: statusText['text'] = 'Invalid credentials file' def updateJson(): try: for k, l in zip(entryNames, entry): if k == 'qrModeValue': mode = QRMode.get() settings[k]=mode elif l: value = str(l.get()) settings[k]=value jsonOperation.writeToJson(settings, jsonPath) statusText['text'] = 'Sucessfully updated status file' except: statusText['text'] = 'Unable to write to/create settings file' preferences = Tk() QRMode=IntVar(master=preferences) def getFilePath(): filepath = filedialog.askopenfilename(initialdir = qrMaker.getCurrentPath(), title = "Select Credentials File", filetypes=[("Json", '*.json'), ("All Fucken Files", "*.*")]) return str(filepath) def loadSettings(): try: if path.exists(jsonPath) != True: statusText['text'] = "Save some new settings first" else: for y, z in zip(entryNames, entry): if y == "qrModeValue": data = jsonOperation.readFromJson(y, jsonPath) if data != None: if data == 0: qrModeEntry0.invoke() elif data == 1: qrModeEntry1.invoke() elif z: z.delete(0, "end") data = jsonOperation.readFromJson(y, jsonPath) if data: z.insert(0, str(data)) statusText['text'] = "Successfully loaded settings file" except: statusText['text'] = 'Unable to load settings' def loadCreds(): data = getFilePath() if data: credentialsJsonEntry.delete(0, "end") credentialsJsonEntry.insert(0, data) def changeQRMode(): mode = QRMode.get() if mode == 0: qrHeightEntry['state']='disabled' elif mode == 1: qrHeightEntry['state']='enabled' preferences.title("Preferences") preferences.iconbitmap(qrMaker.getCurrentPath()+'icon.ico') preferences.geometry('500x600') topText = Label(preferences, width=20, text="Edit Preferences", font=("Enter Sansman Bold", 10)) cameraText = Label(preferences, width=25, text="Select Camera Instance:") cameraEntry = Combobox(preferences, width=10, values=qrReader.getCameras()) printerText = Label(preferences, width=25, text="Printer list(x, y, z...)") printerEntry = Entry(preferences, width=20) materialText = Label(preferences, width=25, text="Material list(x, y, z...)") materialEntry = Entry(preferences, width=20) qrWidthText = Label(preferences, width=25, text="QR Output Width (in.)") qrWidthEntry = Entry(preferences, width=10) qrHeightText = Label(preferences, width=25, text="QR Output Height (in.)") qrHeightEntry = Entry(preferences, width=10) qrModeText = Label(preferences, width=25, text="QR Output Mode") qrModeEntry0 = Radiobutton(preferences, text="Text beneath QR code", variable = QRMode, value = 0, command = changeQRMode) qrModeEntry1 = Radiobutton(preferences, text="Text right of QR code", variable = QRMode, value = 1, command = changeQRMode) settingsJsonText = Label(preferences, width=25, text="Load from settings") loadSettingsButton = Button(preferences, width=12, text="Load Settings", command=loadSettings) credentialsJsonText = Label(preferences, width=25, text="Path to Credentials file") credentialsJsonEntry = Entry(preferences, width=30) credentialsJsonButton = Button(preferences, width=7, text="Browse", command=loadCreds) sheetText = Label(preferences, width=25, text="Google Sheets Link") sheetEntry = Entry(preferences, width=30) sheetTest = Button(preferences, width=18, text="Test Auth and Link", command=testSheet) text = [cameraText, printerText, materialText, qrWidthText, qrHeightText, qrModeText, settingsJsonText, credentialsJsonText, sheetText] entry = [cameraEntry, printerEntry, materialEntry, qrWidthEntry, qrHeightEntry, False, False, credentialsJsonEntry, sheetEntry] entryNames = ['cameraEntry', 'printerEntry', 'materialEntry', 'qrWidthEntry', 'qrHeightEntry', 'qrModeValue', False, 'credentialsJsonEntry', 'sheetEntry'] updateJsonButton = Button(preferences, text="Save Preferences", command=updateJson) statusText = Label(preferences, width=30) for i in range(1, 100, 2): preferences.grid_rowconfigure(i, minsize=10) topText.grid(column = 1, row = 0) row=2 for i, j in zip(text, entry): if i: i.grid(sticky='w', column = 0, row = row) if j: j.grid(sticky='w', column = 1, row = row) row+=2 updateJsonButton.grid(sticky='w', column=1, row=row+4) credentialsJsonButton.grid(sticky='w', column=2, row=row-4) loadSettingsButton.grid(sticky='w', column=1, row=row-6) statusText.grid(sticky='w', column=1, row=row+6) sheetTest.grid(sticky='w', column=2, row=row-2) qrModeEntry0.grid(sticky='w', column=1, row=row-8) qrModeEntry1.grid(sticky='w', column=2, row=row-8) qrModeEntry1.invoke() if path.exists(jsonPath): loadSettings() preferences.mainloop() preferences.quit()
from tkinter import messagebox from tkinter import filedialog from tkinter.font import Font import qrMaker import jsonOperation import qrReader import json import os import os.path from os import path import openWeb import gspread from oauth2client.service_account import ServiceAccountCredentials settings = {} jsonPath = path.join(qrMaker.getCurrentPath(), "config\\settings.json") scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"] #only used for testing def openPreferences(): def testSheet(): try: creds = ServiceAccountCredentials.from_json_keyfile_name(jsonOperation.readFromJson('credentialsJsonEntry', jsonPath),scope) try: client = gspread.authorize(creds) sheet = client.open("spoolData").sheet1 try: openWeb.openChrome(sheetEntry.get()) statusText['text'] = "All tests successful" except: statusText['text'] = "Unable to open sheet"
import gspread from oauth2client.service_account import ServiceAccountCredentials import inspect import qrReader import time import soundPlayer import qrMaker import random import openWeb import menuScript import jsonOperation import os import assignPrinter import sheetOperation #data from first pyscript jsonPath = os.path.join(qrMaker.getCurrentPath(), "config\\settings.json") #someVars spreadsheetURL = jsonOperation.readFromJson("sheetEntry", jsonPath) class Spool: """A class that stores 9 pieces of data relating to each spool, like weight, cost, etc""" def __init__(self, spoolID, dateAdded, material, color, materialWeight, costPerSpool, spoolWeight, manufacturer, isArchived, activePrinter, comment): self.spoolID = spoolID #6 digit spool ID self.dateAdded = dateAdded #mmddyyyy self.material = material #PLA, PETG, NYLON, ABS, etc. self.color = color #color, string self.materialWeight = materialWeight #weight of plastic in grams
def assignPrinterWindow(): def saveChanges(): pass def getPrinterList(): data = jsonOperation.readFromJson("printerEntry", jsonPath) data = data.replace(" ", "") data = data.split(",") data.insert(0, "") data.insert(len(data), "None") return data printerList = getPrinterList() activePrinter.set(printerList[2]) def getQRID(): try: scanQREntry.delete(0, "end") scanQREntry.insert( 0, qrReader.getQR( int(jsonOperation.readFromJson('cameraEntry', jsonPath)))) statusText['text'] = "Successfully scanned QR Code" except: statusText['text'] = "Unable to scan QR Code" def changePrinter(cell, data): cell = sheetOperation.getCell(cell) if cell: sheetOperation.updateCell(cell.row, activePrinterColumn, data) else: print('couldnt fetch cell') assignPrinter = Tk() assignPrinter.title("Add Spool to Printer") assignPrinter.iconbitmap(qrMaker.getCurrentPath() + 'icon.ico') assignPrinter.geometry('400x600') scanQRText = Label(assignPrinter, width=10, text="Spool ID: ") scanQRButton = Button(assignPrinter, text="Scan", command=getQRID) scanQREntry = Entry(assignPrinter, width=10) printerText = Label(assignPrinter, width=20, text="Select active printer:") printerEntry = OptionMenu(assignPrinter, activePrinter, *printerList) uploadText = Label(assignPrinter, width=15, text="Assign Printer") uploadButton = Button( assignPrinter, width=20, text="Save Changes", command=lambda: changePrinter(scanQREntry.get(), activePrinter.get())) statusText = Label(assignPrinter, width=25) text = [scanQRText, printerText, uploadText] entry = [scanQREntry, printerEntry, uploadButton] for i in skippedRows: assignPrinter.grid_rowconfigure(i, minsize=10) row = 2 for text, entry in zip(text, entry): text.grid(column=0, row=row) entry.grid(column=1, row=row) row += 2 scanQRButton.grid(column=2, row=2) statusText.grid(column=0, row=row + 2) assignPrinter.mainloop() assignPrinter.quit()
def playChime(): currentLoc = qrMaker.getCurrentPath() playsound(f'{currentLoc}/sounds/qrChime.wav')