-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuScript.py
167 lines (136 loc) · 6.57 KB
/
menuScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from tkinter import *
from tkinter.ttk import *
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"
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()