def Run(): global startWindow global finalCheck global startButtons startWindow = Window(app, title="Starting Screen", layout="grid") startWindow.width = 360; startWindow.height = 630; startWindow.bg = "Lime" playersQuestionText = Text(startWindow, text="How Many Players?", grid=[0, 0], align="top") playersQuestionText.text_size = 25 playerButtonContainer = Box(startWindow, layout="grid", grid=[0, 1], align="top", border=True) playerButtonContainer.set_border(10, "Lime") buttonOnePlayer = PushButton(playerButtonContainer, text="1 Player", grid=[1, 0], command=lambda: SetPlayerNumber(True, "1 Player")) buttonOnePlayer.width = 20; buttonOnePlayer.height = 10; buttonOnePlayer.bg = "White" buttonTwoPlayer = PushButton(playerButtonContainer, text="2 Player", grid=[2, 0], command=lambda: SetPlayerNumber(False, "2 Player")) buttonTwoPlayer.width = 20; buttonTwoPlayer.height = 10; buttonTwoPlayer.bg = "White" gameModeQuestionText = Text(startWindow, text="What Game Mode?", grid=[0, 2], align="top") gameModeQuestionText.text_size = 25 gameModeButtonContainer = Box(startWindow, layout="grid", grid=[0, 3], align="top", border=True) gameModeButtonContainer.set_border(10, "Lime") buttonAddition = PushButton(gameModeButtonContainer, text="Addition", grid=[1, 0], command=lambda: SetGameMode(True, "Addition")) buttonAddition.width = 20; buttonAddition.height = 10; buttonAddition.bg = "White" buttonSubtraction = PushButton(gameModeButtonContainer, text="Subtraction", grid=[2, 0], command=lambda: SetGameMode(False, "Subtraction")) buttonSubtraction.width = 20; buttonSubtraction.height = 10; buttonSubtraction.bg = "White" finalCheck = Box(startWindow, layout="grid", grid=[0, 4], align="top", border=True) finalCheck.set_border(10, "Lime") startButton = PushButton(finalCheck, text="Start!", grid=[0, 2], align="top", command=StartGame) startButton.width = 20; startButton.height = 5; startButton.bg = "White"; startButton.disable()
def build_runtime(app): global tfile global rt_getfile, rt_settings, rt_drawimage, rt_quit # box = for full window wbox = Box(app, layout="auto", width="fill", height="fill") heading_box = Box(wbox, layout="auto", width="fill") t = Text(heading_box, height=2, text="Runtime", font="Helvetica", size=16, align="left") #--------------file row file_box = Box(wbox, layout="auto", width="fill", height=60) file_val = display_file_name("File: " + str(DataDict["default_file"])) tfile = Text(file_box, text=file_val, height=60, align="left") #--------------Start spacer_box controls_box = Box(wbox, layout="auto", width="fill", height=5) pad = Text(controls_box, width="fill") #--------------Start buttons_box bbox = Box(wbox, layout="grid", width="fill", height=50) line = 0 col = -1 col += 1 pad = Text(bbox, grid=[col, line], width=2) col += 1 rt_getfile = PushButton(bbox, text="Get file", grid=[col, line], command=load_image_fileT) col += 1 pad = Text(bbox, grid=[col, line], width=2) col += 1 rt_drawimage = PushButton(bbox, text="Draw Image", grid=[col, line], command=draw_image) col += 1 pad = Text(bbox, grid=[col, line], width=2) col += 1 rt_settings = PushButton(bbox, text="Settings", grid=[col, line], command=activate_settings) col += 1 pad = Text(bbox, grid=[col, line], width=2) col += 1 rt_quit = PushButton(bbox, text="Quit", grid=[col, line], command=lasergui_quit) rt_drawimage.disable() # enable when we load a good file. return wbox
def ex(): file = open("filt.txt", "r") filt = file.read() file.close def ret_txt(): txt = "" if protocol == 1: for l in data[val.value * size:size + val.value * size]: txt += split(l, "/")[0] + "\n" else: for l in data[val.value * size:size + val.value * size]: txt += l[:-1] + "\n" return txt if filt == "aut": protocol = 1 file_name = "authors.txt" if filt == "xen": protocol = 0 file_name = "genres.txt" if filt == "alb": protocol = 1 file_name = "albumes.txt" if filt == "can": protocol = 1 file_name = "audio_data.txt" def go_next(): val.value = val.value + 1 text.clear() text.append(ret_txt()) prev.enable() if val.value * size + size > lenght: next_b.disable() def go_prev(): val.value = val.value - 1 text.clear() text.append(ret_txt()) if val.value == 0: prev.disable() next_b.enable() file = open(file_name, "r") data = file.readlines() file.close() lenght = len(data) appp = App(title="Menu", height=470) text = Text(appp, align='left') prev = PushButton(appp, command=go_prev, text="Prev") next_b = PushButton(appp, command=go_next, text="Next") val = Text(appp, grid=[10, 10]) val.hide() val.value = 0 text.append(ret_txt()) prev.disable() if size > lenght: next_b.disable() appp.display()
def new_thread(conn, chat_num): def ending(): app.destroy() def getinit(): data = conn.recv(4096) if not data: print_lock.release() app.destroy() if data.decode('ascii') == 'exit': print_lock.release() prompt.value = 'Patient has ended the chat session.\nPlease close this window.' app.disable() history4.value = "Patient: %s" % (data.decode('ascii')) prompt.value = "What is your message?" goahead.enable() def push(): def checknew(): data = conn.recv(4096) history1.value = history2.value history2.value = history3.value history3.value = history4.value history4.value = "Patient: %s" % (data.decode('ascii')) if data.decode('ascii') == 'exit': print_lock.release() prompt.value = "Patient has ended the chat session.\nPlease close this window." app.disable() conn.send(message.value.encode('ascii')) if message.value == 'exit': app.destroy() history1.value = history2.value history2.value = history3.value history3.value = history4.value history4.value = "You: %s" % (message.value) message.clear() checknew() app = App(title="Chat") nummessage = "Chat with patient number: %d" % (chat_num) chatnum = Text(app, text=nummessage) toptext = Text(app, text='Type "exit" at any time to leave this chat') history1 = Text(app, text="") history2 = Text(app, text="") history3 = Text(app, text="") history4 = Text(app, text="") prompt = Text(app, text="Waiting for message...") message = TextBox(app, width=25) goahead = PushButton(app, text="Send", command=push) goahead.disable() app.after(10, getinit) app.display() conn.close()
class NewTask(): '''NewTask GUI''' def __init__(self, app, callback): '''Class contructor''' self.callback = callback self.window_new = Window(app, title="Add Task") Text(self.window_new, "Add new task title") self.title = TextBox(self.window_new, command=self.check_empty, width="fill") Text(self.window_new, "Add new task description") self.desc_box = Box(self.window_new, align="top", width="fill", height="fill", border=True) self.btn_box = Box(self.window_new, align="bottom", width="fill", border=True) self.description = TextBox(self.desc_box, command=self.check_empty, width="fill", height="fill", multiline=True, scrollbar=True) PushButton(self.btn_box, command=self.window_new.destroy, align="left", width="fill", text="Cancel") self.add_btn = PushButton(self.btn_box, enabled=False, align="left", width="fill", command=self.add_task, text="Add") self.window_new.tk.resizable(True, False) self.window_new.show() def check_empty(self): '''disable add button if title and description are empty''' if self.title.value != "" and self.description.value != "\n": self.add_btn.enable() else: self.add_btn.disable() def add_task(self): '''callback with new title and description''' self.callback(self.title.value, self.description.value) self.window_new.destroy()
grid=[0, 2]) brightnessslider = Slider(app, grid=[1, 1], end="255", command=bright) brightnessslider.width = 150 button = PushButton(app, command=thread_starting, text="Start", grid=[1, 3]) button.bg = 'green' endbutton = PushButton(app, command=finishtimelapse, text="End", grid=[3, 3]) endbutton.bg = 'red' filename_choice = TextBox(app, text="Filename", grid=[1, 4]) picture = Picture(app, image="arse.png", grid=[0, 4]) picture.height = 180 picture.width = 240 colour = Combo(app, options=["white", "green", "red", "blue", "yellow", "pink"], selected="white", grid=[2, 1], command=set_motes) previewbutton = PushButton(app, text="Preview", command=previewstart, grid=[2, 3]) endbutton.disable() app.display()
divider.width = 10 divider.font = 'Source code pro' temp_led = PushButton(box, text='', grid=[1, 4]) ph_led = PushButton(box, text='', grid=[2, 4]) dox_led = PushButton(box, text='', grid=[3, 4]) temp_led.width = 2 ph_led.width = 2 dox_led.width = 2 temp_led.height = 1 ph_led.height = 1 dox_led.height = 1 temp_led.bg = 'red' ph_led.bg = 'red' dox_led.bg = 'red' temp_led.disable() ph_led.disable() dox_led.disable() divider2 = Text(box, text="", grid=[1, 5]) divider2.width = 10 divider2.font = 'Source code pro' values_tag = Text(box, text="Sensor Values", grid=[1, 6]) values_tag.size = 10 values_tag.font = 'Source code pro' temp_server = Text(box, text='', grid=[1, 7]) ph_server = Text(box, text='', grid=[2, 7]) dox_server = Text(box, text='', grid=[3, 7])
app = App(title="Back-it-up", layout="grid") stimelabel = Text(app, text="Spray time (msec)", grid=[0, 1]) stime = TextBox(app, grid=[1, 1], text="30") rdelaylabel = Text(app, text="Retraction delay (msec)", grid=[0, 2]) rdelay = TextBox(app, grid=[1, 2], text="50") pdelaylabel = Text(app, text="Plunge delay (msec)", grid=[0, 3]) pdelay = TextBox(app, grid=[1, 3], text="50") donotplunge = CheckBox(app, text="Do not plunge", grid=[0, 4]) button_up = PushButton(app, command=powerup, text="Ready", grid=[0, 5]) button_down = PushButton(app, command=powerdown, text="Abort", grid=[1, 5]) button_start = PushButton(app, command=startprocess, text="Spray & Plunge", grid=[0, 6]) button_up.bg = "orange" button_start.bg = "red" button_start.disable() cleancycleslabel = Text(app, text="Cleaning cycles", grid=[3, 1]) cleancycles = TextBox(app, text="5", grid=[4, 1]) cleantimelabel = Text(app, text="Cleaning pulse (msec)", grid=[3, 2]) cleantime = TextBox(app, text="200", grid=[4, 2]) clean = PushButton(app, command=cleanprocess, text="Clean", grid=[3, 5]) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) app.repeat(100, pedal) app.display()
def Main(): def finish(): err.destroy() def allfilled(): if (username.value != "" and password.value != "" and app.enabled): login.enable() else: login.disable() def verify(): passhashed = hashlib.sha256(password.value.encode()).hexdigest() if username.value in usernames: ind = usernames.index(username.value) if passhashed == passhashes[ind]: success.value = "Logged in" app.disable() cont.enable() cont.show() else: success.value = "Incorrect password" else: success.value = "Username not found" def endfunc(): if cont.enabled: ind = usernames.index(username.value) ret.append(username.value) ret.append(dochashes[ind]) ret.append(True) app.destroy() FILENAME = "patients.txt" dochashes = [] usernames = [] passhashes = [] ret = [] try: with open(FILENAME) as d: for line in d: fields = line.split("\t") usernames.append(fields[0]) dochashes.append(fields[1]) passhashes.append(fields[2].strip()) except: err = App(title = "Error") message = Text(err, text = "There are no patients in the database.\nPlease register first.") badending = PushButton(err, text = "Exit", command = finish) err.display() return["","",False] else: app = App(title = "Patient Login") greet = Text(app, text = "Welcome to AnonyComm!\nThis is the login for patients.\n") prompt1 = Text(app, text = "Username:"******"Password:"******"*") login = PushButton(app, text = "Login", command = verify) login.disable() success = Text(app, text = "") cont = PushButton(app, text = "Continue", command = endfunc) cont.hide() if app.enabled: success.repeat(100, allfilled) app.on_close(endfunc) app.display() if not ret: ret = ["","",False] return ret
from guizero import App, PushButton def do_start(): print("Start button was pressed") startbutton.toggle() stopbutton.toggle() def do_stop(): print("Stop button was pressed") startbutton.toggle() stopbutton.toggle() app = App() startbutton = PushButton(app, command=do_start, text='Start') stopbutton = PushButton(app, command=do_stop, text='Stop') stopbutton.disable() app.display()
class winMain: def __init__(self): # Setup the app self.app = App(title="ezBake", width=constants.APP_WIDTH, height=constants.APP_HEIGHT, visible=False) # Setup the toolbar toolbar_box = Box(self.app, width="fill", align="top", border=True, layout="grid") self.newButton = PushButton(toolbar_box, command=self.handle_newButton, text="New", width=6, grid=[0, 0]) self.openButton = PushButton(toolbar_box, command=self.handle_openButton, text="Open", width=6, grid=[1, 0]) self.startButton = PushButton(toolbar_box, command=self.handle_startButton, text="Start", width=6, grid=[2, 0]) self.stopButton = PushButton(toolbar_box, command=self.handle_stopButton, text="Stop", width=6, grid=[3, 0]) self.saveButton = PushButton(toolbar_box, command=self.handle_saveButton, text="Save", width=6, grid=[4, 0]) self.quitButton = PushButton(toolbar_box, command=self.handle_quitButton, text="Quit", width=6, grid=[5, 0]) # Set initual toolbar button states self.openButton.disable() self.startButton.disable() self.stopButton.disable() self.saveButton.disable() # Setup the status bar status_box = Box(self.app, width="fill", align="bottom", border=True) self.statusText = Text(status_box, align="left", text="Status") # Setup sensor feedback box data_box = Box(self.app, height="fill", align="right", border=True) Text(data_box) currTempText = Text(data_box, text="Current Temp") self.currTempTextBox = TextBox(data_box, text="0.0 °C", enabled=False) Text(data_box) targTempText = Text(data_box, text="Target Temp") self.targTempTextBox = TextBox(data_box, text="0.0 °C", enabled=False) Text(data_box) roomTempText = Text(data_box, text="Room Temp") self.roomTempTextBox = TextBox(data_box, text="0.0 °C", enabled=False) Text(data_box) runTempText = Text(data_box, text="Running Time") self.runTempTextBox = TextBox(data_box, text="00:00:00", enabled=False) Text(data_box) remTempText = Text(data_box, text="Remaining Time") self.remTempTextBox = TextBox(data_box, text="00:00:00", enabled=False) Text(data_box) pwmDutyCycleText = Text(data_box, text="PWM Duty Cycle") self.pwmDutyCycleTextBox = TextBox(data_box, text="0%", enabled=False) # Initialize Time and Temp arrays self.timePoints = [] self.tempPoints = [] self.timePoints.append(0.0) self.tempPoints.append(0.0) # Setup graph display self.graph_box = Box(self.app, align="top", width="fill", border=False) self.figure = Figure(figsize=(6.75, 5.3)) self.plot = self.figure.add_subplot(1, 1, 1) # Setup plot self.maxTime = constants.INIT_TIME self.maxTemp = constants.INIT_TEMP self.setupPlot() # Call handle_quitButtion() when Close Window selected self.app.when_closed = self.handle_quitButton # Call handle_repeat() every 1000 msec #self.app.repeat(1000, self.handle_repeat) # Center program on screen self.centerWindow() self.app.visible = True def main(self): self.app.display() def onPlotClick(self, event): # Ignore if outside plot if event.inaxes == None: return # Check data if event.xdata > max(self.timePoints): # Append plot data and replot self.timePoints.append(event.xdata) self.tempPoints.append(event.ydata) self.setupPlot() def onMouseMove(self, event): # Clear status if outside plot if event.inaxes == None: self.statusText.value = "" return # Round mouse coordinates for display xval = str(round(event.xdata, 2)) yval = str(round(event.ydata, 2)) # Display time and temp values in the status box self.statusText.value = "Time = " + xval + ", Temp = " + yval def handle_newButton(self): # Retrieve maximum time from user value = self.app.question("Maximum Time", "Enter maximum time in hours") if value == None or value == '': return self.maxTime = float(value) if self.maxTime <= constants.MIN_TIME or self.maxTime > constants.MAX_TIME: return # Retrieve maximum temp from user value = self.app.question("Maximum Temp", "Enter maximum temp in Celcius") if value == None: return self.maxTemp = float(value) if self.maxTemp <= constants.MIN_TEMP or self.maxTemp > constants.MAX_TEMP: return # Reset plot self.resetPlot() # Setup plot self.timePoints = [] self.tempPoints = [] self.timePoints.append(0.0) self.tempPoints.append(0.0) self.setupPlot() # Activate Start button self.startButton.enable() def resetPlot(self): # Reset plot self.plot.cla() def setupPlot(self): # Setup plot self.plot.set_title('Kiln Firing Schedule') self.plot.set_xlabel('Time (h)') self.plot.set_ylabel('Temp (°C)') self.plot.set_xlim(0, self.maxTime) self.plot.set_ylim(0, self.maxTemp) # Plot data self.plot.plot(self.timePoints, self.tempPoints, color="black") self.plot.scatter(self.timePoints, self.tempPoints, color="black") # Display plot self.canvas = FigureCanvasTkAgg(self.figure, self.graph_box.tk) self.canvas.get_tk_widget().grid(row=0, column=0) # Setup callback for plot clicks self.figure.canvas.mpl_connect('button_press_event', self.onPlotClick) self.figure.canvas.mpl_connect('motion_notify_event', self.onMouseMove) def handle_openButton(self): print("openButton pressed") def handle_startButton(self): print("startButton pressed") def handle_stopButton(self): print("stopButton pressed") def handle_saveButton(self): print("saveButton pressed") def handle_quitButton(self): print("quitButton pressed") # Shutdown program self.app.destroy() def handle_repeat(self): print("handle_repeat called") def centerWindow(self): # Gets both half the screen width/height and window width/height positionRight = int(self.app.tk.winfo_screenwidth() / 2 - constants.APP_WIDTH / 2) positionDown = int(self.app.tk.winfo_screenheight() / 2 - constants.APP_HEIGHT / 2) # Positions the window in the center of the page. self.app.tk.geometry("+{}+{}".format(positionRight, positionDown))
var_blue = get_sql_data('blue','Sensor_Data',sql_start,sql_end,j) tmp_textbox_log1 = tmp_textbox_log1 + "\nSQL Data Extracted OK" return var_Time, var_hostName,var_uptime,var_ip, var_cpuTemp,var_hatTemp,var_pressure,var_humidity, var_lumens,var_red,var_green,var_blue except: tmp_textbox_log1 = tmp_textbox_log1 + "\nSQL Data Extraction Failed" def save_to(): save_to_database = filedialog.askopenfilename() def combine_database(): print("hey") app2 = App(title="Sensor Graph DataBase Modifier", width=375, height=300, layout="grid") button_db1 = PushButton(app2, text="New Database", \ command = combine_database, grid=[1,1], align="left") button_db2 = PushButton(app2, text="Add Database", \ command = combine_database, grid=[2,1], align="left") button_db2.disable() button_db3 = PushButton(app2, text="Save Database", \ command = combine_database, grid=[3,1], align="left") button_db3.disable() app2.display()
def Main(): def finish(): quit() def adduser(): passhashed = hashlib.sha256(password.value.encode()).hexdigest() dockey = random.randint(100000, 999999) if not doctors: towrite = "%s\t%s\t%s\t%d" % (name.value, username.value, passhashed, dockey) else: towrite = "\n%s\t%s\t%s\t%d" % (name.value, username.value, passhashed, dockey) with open(FILENAME, "a") as d: d.write(towrite) success.value = "Registration successful! Your 6-digit verification key is %d" % ( dockey) exit.enable() exit.show() def checkgood(): if username.value in usernames: success.value = "This username is already taken. Please try another." else: success.value = "Registration successful!" app.disable() adduser() def allfilled(): if (name.value != "" and username.value != "" and password.value != "" and app.enabled): confirm.enable() else: confirm.disable() FILENAME = "doctors.txt" doctors = [] usernames = [] passhashes = [] try: with open(FILENAME) as d: for line in d: fields = line.split("\t") doctors.append(fields[0]) usernames.append(fields[1]) passhashes.append(fields[2].strip()) except: d = open(FILENAME, "w+") d.close() app = App(title="New doctor registration") intro = Text(app, text="Welcome to AnonyComm!\n") prompt1 = Text(app, text="Please enter your name (First Last).") name = TextBox(app, width=20) prompt2 = Text(app, text="Please enter your username.") username = TextBox(app, width=20) prompt3 = Text(app, text="Please enter your password.") password = TextBox(app, width=20) password.tk.config(show="*") txt2 = Text(app, text="") confirm = PushButton(app, text="Confirm registration", command=checkgood) confirm.disable() success = Text(app, text="") exit = PushButton(app, text="Finish", command=finish) exit.hide() if app.enabled: success.repeat(100, allfilled) app.display()
infotext = Text(s1Window, text = 'Press "Measure Plant" to take a 10 second measurement \n' 'do not touch the tower during the measurement', grid = [1,1,2,1], align = 'left') closeS1 = PushButton(s1Window, text='x', command = closeS1, grid = [3,1], align = 'right') closeS1.bg = 'red' igap = Text(s1Window, text = ' ', grid = [1,2]) infoText2 = Text(s1Window, text = 'If coherence is high (> 0.98), accept the measurement \n' 'otherwise, re-run the measurement', grid = [1,3,2,1], align = 'left') igap2 = Text(s1Window, text = '--------------------------------------------', grid = [1,4, 2,1], align = 'center') plantButton = PushButton(s1Window,text='Measure Plant', command=turnOnMeasurement, grid=[1,5], align='left') #topgap = Text(s1Window, text = ' ', grid = [2,1], align = 'left') plantTxt = Text(s1Window, text='Plant = [xxxxxx + xxxxx j]', grid = [1,6], align = 'left') coherenceTxt = Text(s1Window, 'Coherence = xxxx', grid = [1,7], align = 'left') acceptButton = PushButton(s1Window, text = 'Accept measurement', command = step2, grid = [1,8], align = 'left') acceptButton.disable() s2Window = Window(control_app, title='Setup 2', layout = 'grid') s2Window.hide() s2Window.height = 480 s2Window.width = 800 s2Window.tk.attributes('-fullscreen', fullScreen) s2Window.text_size = 16 s2Window.font = 'FreeMono' infoText = Text (s2Window, text = 'Press "Test" to run active vibration control\n' 'The error should decrease.\n' 'When it reaches a steady low value, stop the test', grid = [1,1,2,1], align = 'left') infoText2 = Text(s2Window, text = 'If the error increases, stop the test immediately', color = 'red', grid = [1,2,2,1], align = 'left') infoText3 = Text(s2Window, text = '---------------------------------------------',grid = [1,3,2,1])
# Reset the board def reset(): global score for i in range(board.width): for j in range(board.height): board[i, j].dotty = False board[i, j].color = "white" # Restart the game score = 0 score_text.value = "Score: 0" board.after(speed, light) reset_button.disable() # Keep track of the pixels lit = 0 speed = 1000 score = 0 # Create the GUI app = App() instructions = Text(app, "Click the dots to destroy them") board = Waffle(app, width=5, height=5, command=turn_off) message = Text(app) score_text = Text(app, text="Score: 0") reset_button = PushButton(app, reset, text="New game") reset_button.disable() # Light a new pixel after a given interval board.after(speed, light) app.display()
class GUI: # --------------------- Tooth Variables -------------------------------------------------------------------------- # statorToothLength = None statorToothHeight = None statorToothWidth = None statorWindHeight = None statorWindWidth = None statorShoeWidth = None distanceBetweenTeeth = None statorDiameter = None numberStatorTeeth = None numberWinds = None wireGauge = None wireMaterial = None # --------------------- Main Control Variables ------------------------------------------------------------------- # mainController = None # --------------------- GUI Construction Variables --------------------------------------------------------------- # app = None parameterWindow = None windingWindow = None postWindingWindow = None safetyInterruptWindow = None parameterButton = None windingButton = None postWindingButton = None predictedTimeMessage = None predictedFillFactorMessage = None predictedWindingResistanceMessage = None actualTimeMessage = None elongationMessage = None askStatorToothLength = None enteredStatorToothLength = None askStatorToothHeight = None enteredStatorToothHeight = None askStatorWindHeight = None enteredStatorWindHeight = None askStatorToothWidth = None enteredStatorToothWidth = None askStatorShoeWidth = None enteredStatorShoeWidth = None askNumberStatorTeeth = None enteredNumberStatorTeeth = None askNumberWinds = None enteredNumberWinds = None askWireGauge = None enteredWireGauge = None askWireMaterial = None enteredWireMaterial = None askDistanceBetweenTeeth = None enteredDistanceBetweenTeeth = None askStatorWindWidth = None enteredStatorWindWidth = None askStatorDiameter = None enteredStatorDiameter = None doneEnteringParamsButton = None parameterErrorMessage = None windingStatorMessage = None windingWindowCloseMessage = None postWindingTitle = None resistanceMessage = None capacitanceMessage = None inductanceMessage = None doneViewingPostWindingButton = None windingSafetyTitleMessage = None windingSafetyMessage = None windingSafetyTroubleshootMessage = None actualTime = None startWindingButton = None # --------------------- Functions -------------------------------------------------------------------------------- # # Float truncation def truncate(self, f, n): '''Truncates/pads a float f to n decimal places without rounding''' s = '{}'.format(f) if 'e' in s or 'E' in s: return '{0:.{1}f}'.format(f, n) i, p, d = s.partition('.') return '.'.join([i, (d + '0' * n)[:n]]) # function for opening parameterWindow and halting other window activity def openParameterWindow(self): self.parameterWindow.show(wait=True) # function for closing parameterWindow def closeParameterWindow(self): self.parameterWindow.hide() # function for opening windingWindow and halting other window activity def openWindingWindow(self): self.windingWindow.show(wait=True) # function for closing windingWindow def closeWindingWindow(self): self.windingWindow.hide() # function for opening postWindingWindow and halting other window activity def openPostWindingWindow(self): self.postWindingWindow.show(wait=True) # function for closing postWindingWindow def closePostWindingWindow(self): self.postWindingWindow.hide() # function for opening parameterWindow when button pressed def parameterButtonPressed(self): # Disable buttons self.parameterButton.disable() self.zeroButton.disable() self.windingButton.disable() self.postWindingButton.disable() self.parameterErrorMessage.clear() self.windingMessage.clear() self.actualTimeMessage.clear() self.actualTimeMessage.append("Actual time: None (wind a coil)") self.openParameterWindow() def getErrorMessage(self, lookupCode): errorMessage = { -1: "ErrorHitOverPositionSwitch\n", -2: "ErrorHitXZeroingSwitch\n", -3: "ErrorHitYZeroingSwitch\n", -4: "ErrorHitZZeroingSwitch\n", -5: "ErrorDestinationOutOfBounds\n", -6: "ErrorAlarmX1\n", -7: "ErrorAlarmX2\n", -8: "ErrorAlarmY\n", -9: "ErrorAlarmZ\n", -10: "ErrorFailedToHitXZeroingSwitch\n", -11: "ErrorFailedToHitYZeroingSwitch\n", -12: "ErrorFailedToHitZZeroingSwitch\n", -13: "ErrorBadCommand\n", -14: "ErrorNoWireDetected\n" } return errorMessage.get(lookupCode) # function for zeroing the machine when the zero button is pressed def zeroButtonPressed(self): # Have main send the zeroing signal to the arduino errorCode = self.mainController.sendZeroCommand() print("errorCode: " + str(errorCode)) # Use error code to print error message if needed if (errorCode != 0): safetyMessage = self.getErrorMessage(errorCode) # Update message on safety window self.windingSafetyMessage.clear() self.windingSafetyMessage.append(safetyMessage) # Display safety screen and lock out everything else self.safetyInterruptWindow.show() self.parameterWindow.hide() self.windingWindow.hide() self.postWindingWindow.hide() # Disable buttons self.parameterButton.disable() self.zeroButton.disable() self.windingButton.disable() self.postWindingButton.disable() else: return def startWindingButtonPressed(self): # Wind start = timer() errorCode = self.mainController.startWinding() # Use error code to print error message if (errorCode != 0): safetyMessage = self.getErrorMessage(errorCode) # Update message on safety window self.windingSafetyMessage.clear() self.windingSafetyMessage.append(safetyMessage) # Display safety screen and lock out everything else self.safetyInterruptWindow.show() self.parameterWindow.hide() self.windingWindow.hide() self.postWindingWindow.hide() # Disable buttons self.parameterButton.disable() self.zeroButton.disable() self.windingButton.disable() self.postWindingButton.disable() else: # End windingTimer end = timer() actualTime = end - start # Update actual time message self.actualTimeMessage.clear() timeHours, timeSec = divmod(actualTime, 3600) timeMin, timeSec = divmod(timeSec, 60) self.actualTimeMessage.append("Actual time: " + str( str(self.truncate(timeHours, 0)) + " hour " + str(self.truncate(timeMin, 0)) + " min " + str(self.truncate(timeSec, 3)) + " secs\n")) # Update elongation message # TODO: Test with Arduino Mega connected self.elongationMessage.clear() self.elongationMessage.append("Elongation: " + str(( self.truncate(self.mainController.getElongation(), 2)) + " %")) # Enable buttons after winding is completed self.parameterButton.enable() self.zeroButton.enable() self.windingButton.enable() self.postWindingButton.enable() # Close Window self.closeWindingWindow() return # function for opening windingWindow when button pressed and starting winding process def windingButtonPressed(self): self.openWindingWindow() # self.windingMessage.clear() # self.windingMessage.append("Winding the stator") # Disable buttons self.parameterButton.disable() self.zeroButton.disable() self.windingButton.disable() self.postWindingButton.disable() def postWindingButtonPressed(self): self.mainController.startPostWindingTest() # Update Messages self.resistanceMessage.clear() self.resistanceMessage.append(self.mainController.getResistance()) self.capacitanceMessage.clear() self.capacitanceMessage.append(self.mainController.getCapacitance()) self.inductanceMessage.clear() self.inductanceMessage.append(self.mainController.getInductance()) # Disable buttons self.parameterButton.disable() self.zeroButton.disable() self.windingButton.disable() self.postWindingButton.disable() # Open window self.openPostWindingWindow() def doneViewingPostWindingButtonPressed(self): # Enable buttons self.parameterButton.enable() self.zeroButton.enable() self.windingButton.enable() self.postWindingButton.enable() self.closePostWindingWindow() # ----------------------- Param Window Functions ----------------------------------------------------------------- # def doneEnteringParamsButtonPressed(self): try: # Set tooth parameters self.statorToothLength = float(self.enteredStatorToothLength.value) self.statorToothHeight = float(self.enteredStatorToothHeight.value) self.statorToothWidth = float(self.enteredStatorToothWidth.value) self.statorWindHeight = float(self.enteredStatorWindHeight.value) self.statorWindWidth = float(self.enteredStatorWindWidth.value) self.statorShoeWidth = float(self.enteredStatorShoeWidth.value) self.distanceBetweenTeeth = float( self.enteredDistanceBetweenTeeth.value) self.statorDiameter = float(self.enteredStatorDiameter.value) self.numberStatorTeeth = float(self.enteredNumberStatorTeeth.value) self.numberWinds = float(self.enteredNumberWinds.value) self.wireGauge = float(self.enteredWireGauge.value) self.wireMaterial = self.enteredWireMaterial.value # Instantiate Main and call the function for building gcode self.mainController.buildGCode( self.statorToothLength, self.statorToothHeight, self.statorWindHeight, self.statorToothWidth, self.statorShoeWidth, self.numberStatorTeeth, self.numberWinds, self.wireGauge, self.wireMaterial, self.distanceBetweenTeeth, self.statorWindWidth, self.statorDiameter) # Update predicted values self.predictedTimeMessage.clear() timeHours, timeSec = divmod(self.mainController.getPredictedTime(), 3600) timeMin, timeSec = divmod(timeSec, 60) self.predictedTimeMessage.append("Predicted time: " + str( str(self.truncate(timeHours, 0)) + " hour " + str(self.truncate(timeMin, 0)) + " min " + str(self.truncate(timeSec, 3)) + " secs\n")) self.predictedFillFactorMessage.clear() self.predictedTimeMessage.append("Predicted fill factor: " + str( self.truncate(self.mainController.getPredictedFillFactor(), 3) + " %\n")) self.predictedWindingResistanceMessage.clear() self.predictedWindingResistanceMessage.append( "Predicted winding resistance: " + str( self.truncate(self.mainController.getPredictedResistance(), 3) + " Ohms\n")) # Enable winding button self.parameterButton.enable() self.zeroButton.enable() self.windingButton.enable() # Close self.closeParameterWindow() except: self.parameterErrorMessage.clear() self.parameterErrorMessage.append("Non-valid parameters entered") self.parameterButton.enable() self.zeroButton.enable() # ----------------------- User Interface Creation ---------------------------------------------------------------- # def __init__(self): """Construct a new UserInterface """ self.mainController = MainController() # Creates the GUI named app and appropriate windows self.app = App(title="Main window") self.parameterWindow = Window(self.app, title="Parameter window", layout="grid") # parameterWindow = Window(app, title="Parameter window", layout = "grid", bg = "black") # parameterWindow.text_color = "white" self.parameterWindow.hide() self.windingWindow = Window(self.app, title="Winding window") self.windingWindow.hide() self.postWindingWindow = Window(self.app, title="Post winding window", layout="grid") self.postWindingWindow.hide() self.safetyInterruptWindow = Window(self.app, title="Safety interrupt window") self.safetyInterruptWindow.hide() # ----------------------- Main Window Event Loop ------------------------------------------------------------- # # Event loop - Coil winder GUI Main window widget (text, text boxes, buttons, etc) code here self.parameterButton = PushButton(self.app, command=self.parameterButtonPressed, text="Enter Stator Parameters") self.zeroButton = PushButton(self.app, command=self.zeroButtonPressed, text="Zero the machine") self.windingButton = PushButton(self.app, command=self.windingButtonPressed, text="Start winding") self.postWindingButton = PushButton( self.app, command=self.postWindingButtonPressed, text="Start post winding test") self.predictedTimeMessage = Text( self.app, text="Predicted time: None (enter parameters)") self.predictedFillFactorMessage = Text( self.app, text="Predicted fill factor: None (enter parameters)") self.predictedWindingResistanceMessage = Text( self.app, text="Predicted winding resistance: None (enter parameters)") self.actualTimeMessage = Text(self.app, text="Actual time: None (wind a coil)") self.elongationMessage = Text(self.app, text="Elongation: None (wind a coil)") self.windingMessage = Text(self.app, text="") # Disable other buttons except enter stator parameters self.windingButton.disable() self.postWindingButton.disable() # ----------------------- Parameter Window Event Loop -------------------------------------------------------- # # Event loop - Coil winder GUI Parameter window widget (text, text boxes, buttons, etc) code here i = 0 self.askStatorToothLength = Text(self.parameterWindow, text="Stator tooth length (mm):", grid=[0, i], align="left") self.enteredStatorToothLength = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askStatorToothHeight = Text(self.parameterWindow, text="Stator tooth height (mm):", grid=[0, i], align="left") self.enteredStatorToothHeight = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askStatorToothWidth = Text(self.parameterWindow, text="Stator tooth width (mm):", grid=[0, i], align="left") self.enteredStatorToothWidth = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askStatorWindHeight = Text(self.parameterWindow, text="Stator wind height (mm):", grid=[0, i], align="left") self.enteredStatorWindHeight = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askStatorWindWidth = Text(self.parameterWindow, text="Stator wind width (mm):", grid=[0, i], align="left") self.enteredStatorWindWidth = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askStatorShoeWidth = Text(self.parameterWindow, text="Stator shoe width (mm):", grid=[0, i], align="left") self.enteredStatorShoeWidth = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askDistanceBetweenTeeth = Text( self.parameterWindow, text="Distance between teeth: (mm)", grid=[0, i], align="left") self.enteredDistanceBetweenTeeth = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askStatorDiameter = Text(self.parameterWindow, text="Stator diameter:", grid=[0, i], align="left") self.enteredStatorDiameter = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askNumberStatorTeeth = Text(self.parameterWindow, text="Number stator teeth:", grid=[0, i], align="left") self.enteredNumberStatorTeeth = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askNumberWinds = Text(self.parameterWindow, text="Number winds per tooth:", grid=[0, i], align="left") self.enteredNumberWinds = TextBox(self.parameterWindow, width=40, grid=[1, i], align="left") i += 1 self.askWireGauge = Text(self.parameterWindow, text="Wire gauge:", grid=[0, i], align="left") self.enteredWireGauge = Combo( self.parameterWindow, options=["13", "14", "15", "16", "17", "18"], grid=[1, i], align="left") i += 1 self.askWireMaterial = Text(self.parameterWindow, text="Wire material:", grid=[0, i], align="left") self.enteredWireMaterial = Combo(self.parameterWindow, options=["Copper"], grid=[1, i], align="left") i += 1 self.doneEnteringParamsButton = PushButton( self.parameterWindow, command=self.doneEnteringParamsButtonPressed, text="Done", grid=[0, i], align="left") i += 1 self.parameterErrorMessage = Text(self.parameterWindow, text="", grid=[0, i], align="left") i += 1 # ----------------------- Winding Window Event Loop ---------------------------------------------------------- # # Event loop - Coil winder GUI Parameter window widget (text, text boxes, buttons, etc) code here self.windingStatorMessage = Text(self.windingWindow, text="Winding", size=30, color="green") self.windingWindowCloseMessage = Text( self.windingWindow, text= "Press the button to start winding.\n Window will close when winding is complete." ) self.startWindingButton = PushButton( self.windingWindow, command=self.startWindingButtonPressed, text="Start winding") # ----------------------- Post Winding Window Event Loop ----------------------------------------------------- # # Event loop - Coil winder GUI Parameter window widget (text, text boxes, buttons, etc) code here self.postWindingTitle = Text(self.postWindingWindow, text="Post Winding Results ", size=20, font="Times New Roman", grid=[0, 0], align="left") self.resistanceMessage = Text(self.postWindingWindow, text="Resistance: ", font="Times New Roman", grid=[0, 1], align="left") self.capacitanceMessage = Text(self.postWindingWindow, text="Capacitance: ", font="Times New Roman", grid=[0, 2], align="left") self.inductanceMessage = Text(self.postWindingWindow, text="Inductance: ", font="Times New Roman", grid=[0, 3], align="left") self.doneViewingPostWindingButton = PushButton( self.postWindingWindow, command=self.doneViewingPostWindingButtonPressed, text="Done", grid=[0, 4], align="left") # ----------------------- Safety Interrupt Window Event Loop ------------------------------------------------- # self.windingSafetyTitleMessage = Text(self.safetyInterruptWindow, text="Safety Error", size=40, font="Times New Roman", color="red") self.windingSafetyMessage = Text( self.safetyInterruptWindow, text="Something went wrong and the program was halted.", font="Times New Roman") self.windingSafetyTroubleshootMessage = Text( self.safetyInterruptWindow, text="Reset the machine and try again.", font="Times New Roman") self.app.display( ) # start the event loop - while true block - code after this doesn't execute
arguments = ["python3","Bltruserrun.py"] call(arguments) button_user.disable() button_timed.disable() button_align.disable() def align(): print("Power down") arguments = ["python3","Bltralign.py"] call(arguments) button_user.disable() button_timed.disable() button_align.disable() app = App(title="Blottinator4000", layout="grid") button_up = PushButton(app, command=powerup,text="Ready", grid=[0,1]) button_down = PushButton(app, command=powerdown, text="Abort", grid=[1,1]) button_align= PushButton(app, command=align, text="Align the blotting pad using the XYZ stage", grid=[0,2]) button_timed= PushButton(app, command=timed, text="Pre defined blotting time", grid=[0,3]) button_user = PushButton(app, command=userin, text="Blot until user input", grid=[0,4]) stimelabel = Text(app, text="Blot time (s)", grid=[1,3]) stime = TextBox(app, grid=[2,3], text="5") button_up.bg="yellow" button_down.bg = "red" button_timed.disable() button_user.disable() button_align.disable() app.display()
else: confirm.disable() FILENAME = "patients.txt" patients = [] usernames = [] passhashes = [] try: with open(FILENAME) as d: for line in d: fields = line.split("\t") usernames.append(fields[0]) passhashes.append(fields[1].strip()) except: d = open(FILENAME,"w+") d.close() app = App(title = "New user registration") intro = Text(app, text = "Welcome to Litlitlit!\n") prompt2 = Text(app, text = "Please enter your username.") username = TextBox(app, width = 20) prompt3 = Text(app, text = "Please enter your password.") password = TextBox(app, width = 20) password.tk.config(show="*") txt2 = Text(app, text = "") confirm = PushButton(app, text = "Confirm registration", command = checkgood) confirm.disable() success = Text(app, text = "") exit = PushButton(app, text = "Finish", command = finish) exit.hide() if app.enabled: success.repeat(100, allfilled) app.display()
def StartOnePlayer(): global onePlayerWindow global drawButtonOnePlayer global cardImagesOnePlayer global guessContainerOnePlayer global guessCheckButtonOnePlayer global guessTextBoxOnePlayer global correctOnePlayer global errorTextOnePlayer onePlayerWindow = Window(app, title="One Player Game", layout="grid") onePlayerWindow.width = 320; onePlayerWindow.height = 560; onePlayerWindow.bg = "Lime" drawButtonOnePlayer = PushButton(onePlayerWindow, text="Draw!", grid=[0, 0], align="top", command=ButtonSwapOnePlayer) drawButtonOnePlayer.width = 20; drawButtonOnePlayer.height = 5; drawButtonOnePlayer.bg = "White" cardImagesOnePlayer = Box(onePlayerWindow, layout="grid", grid=[0, 1], align="top", border=True) cardImagesOnePlayer.set_border(10, "Lime") guessContainerOnePlayer = Box(onePlayerWindow, layout="grid", grid=[0, 2], align="top", border=True) guessContainerOnePlayer.set_border(10, "Lime") guessTextBoxOnePlayer = TextBox(guessContainerOnePlayer, grid=[0, 0], align="top") guessTextBoxOnePlayer.text_size = 20; guessTextBoxOnePlayer.bg = "White"; guessTextBoxOnePlayer.disable(); guessCheckButtonOnePlayer = PushButton(guessContainerOnePlayer, text="Check!", grid=[0, 1], align="top", command=CheckValuesOnePlayer) guessCheckButtonOnePlayer.width = 20; guessCheckButtonOnePlayer.height = 5; guessCheckButtonOnePlayer.bg = "White"; guessCheckButtonOnePlayer.disable(); pointsTextOnePlayer = Text(guessContainerOnePlayer, text="Score: ", grid=[0, 2], align="top") correctOnePlayer = Text(onePlayerWindow, text="", grid=[0, 3]) errorTextOnePlayer = Text(onePlayerWindow, text="Please enter a number!", grid=[0, 4]) errorTextOnePlayer.hide()
def Main(): def finish(): quit() def writedata(): ind = docnames.index(docname.value) docHashed = hashlib.sha256(docusernames[ind].encode()).hexdigest() passhashed = hashlib.sha256(password.value.encode()).hexdigest() if not usernames: towrite = "%s\t%s\t%s" % (username.value, docHashed, passhashed) else: towrite = "\n%s\t%s\t%s" % (username.value, docHashed, passhashed) with open(FILENAME, "a") as p: p.write(towrite) findmatch.destroy() exit.enable() exit.show() def matchDoctor(): if docname.value in docnames: ind = docnames.index(docname.value) if checkkey.value == dockeys[ind]: earlyexit.hide() findmatch.disable() writedata() else: matchintro.value = "Incorrect key." earlyexit.show() else: matchintro.value = "Your doctor's name cannot be found.\n(S)he may not have created an account yet." earlyexit.show() def checkgood(): if username.value in usernames: success.value = "This username is already taken. Please try another." else: success.value = "Registration successful!" app.disable() findmatch.enable() findmatch.show() def allfilled(): if (username.value != "" and password.value != "" and app.enabled): confirm.enable() else: confirm.disable() FILENAME = "patients.txt" # Format: username TAB hashedDocUsername TAB hashedPassword DOCTORS = "doctors.txt" # Format: name TAB username TAB hashedPassword patients = [] usernames = [] docnames = [] docusernames = [] dockeys = [] try: with open(FILENAME) as p: for line in p: fields = line.split("\t") usernames.append(fields[0]) except: p = open(FILENAME, "w+") p.close() try: with open(DOCTORS) as d: for line in d: fields = line.split("\t") docnames.append(fields[0]) docusernames.append(fields[1]) dockeys.append(fields[3].strip()) except: err = App(title="Error") message = Text( err, text= "There are no doctors in the database.\nPlease ask your doctor to register first." ) badending = PushButton(err, text="Exit", command=finish) err.display() else: app = App(title="New patient registration") intro = Text(app, text="Welcome to AnonyComm!\n") prompt2 = Text(app, text="Please enter your username.") username = TextBox(app, width=20) prompt3 = Text(app, text="Please enter your password.") password = TextBox(app, width=20) password.tk.config(show="*") txt2 = Text(app, text="") confirm = PushButton(app, text="Confirm registration", command=checkgood) confirm.disable() success = Text(app, text="") exit = PushButton(app, text="Finish", command=finish) exit.hide() findmatch = Window(app, title="Doctor name entry") matchintro = Text(findmatch, text="Please enter your doctor's name (First Last)") docname = TextBox(findmatch, width=20) keyprompt = Text( findmatch, text="Enter your doctor's six-digit verification key.") checkkey = TextBox(findmatch, width=20) checkdoc = PushButton(findmatch, text="Find your doctor", command=matchDoctor) earlyexit = PushButton(findmatch, text="Quit", command=finish) earlyexit.hide() findmatch.hide() if app.enabled: success.repeat(100, allfilled) app.display()
class MainUI: def __init__(self): self.app = App(layout="grid", width=550, title="3080 Bot") self.amzn_input_data = self.load_amzn_options() self.amazon_executor = ThreadPoolExecutor(max_workers=3) self.nvidia_executor = ThreadPoolExecutor(max_workers=3) self.amazon_box = Box(self.app, grid=[0, 0], height="fill", width="550", layout="grid", align="left") self.amazon_status = Text(self.amazon_box, grid=[0, 1], align="left", bg="black", color="white", height="fill", text="") self.amazon_status.text_size = 10 self.amazon_inputs_box = Box(self.amazon_box, grid=[0, 0], border=1, height="fill", width="fill", layout="grid", align="left") self.start_button = PushButton(self.amazon_inputs_box, command=self.start_amzn, text="start", grid=[4, 0], align="right") self.stop_button = PushButton(self.amazon_inputs_box, command=self.stop_amzn, text="stop", enabled=False, grid=[4, 1], align="right") Text(self.amazon_inputs_box, text="Amazon Email", grid=[0, 0], align="left", ) self.amazon_email = TextBox(self.amazon_inputs_box, align="left", grid=[1, 0], width=20, text=self.amzn_input_data['amazon_email']) Text(self.amazon_inputs_box, text="Amazon Password", grid=[0, 1], align="left") self.amazon_password = TextBox( self.amazon_inputs_box, align="left", grid=[1, 1], hide_text=True, width=20, text=self.amzn_input_data['amazon_password'] ) Text(self.amazon_inputs_box, text="Item URL", grid=[2, 0], align="left") self.amazon_item_url = TextBox(self.amazon_inputs_box, align="left", grid=[3, 0], text=self.amzn_input_data['amazon_item_url'],width=20) Text(self.amazon_inputs_box, text="Price Limit", grid=[2, 1], align="left") self.amazon_price_limit = TextBox(self.amazon_inputs_box, align="left", grid=[3, 1], text=self.amzn_input_data['amazon_price_limit'], width=20) self.nvidia_box = Box(self.app, grid=[0, 1], border=1, height="fill", width=200, layout="grid", align="left") self.nvidia_inputs_box = Box(self.nvidia_box, grid=[0, 0], border=1, height="fill", width=200, layout="grid") self.start_button_nv = PushButton(self.nvidia_inputs_box, command=self.start_nv, text="start", grid=[1, 0]) self.stop_button_nv = PushButton(self.nvidia_inputs_box, command=self.stop_nv, text="stop", enabled=False, grid=[2, 0]) self.nv_status = Text(self.nvidia_box, grid=[0, 1], align="left", bg="black", color="white", height="fill", text="") self.nv_status.text_size = 10 self.nv_gpu = Combo(self.nvidia_inputs_box, options=list(GPU_DISPLAY_NAMES.keys()), grid=[0,0]) def save_amzn_options(self): data = { 'amazon_email': self.amazon_email.value, 'amazon_password': self.amazon_password.value, 'amazon_item_url': self.amazon_item_url.value, 'amazon_price_limit': self.amazon_price_limit.value } with open('amazon.json', 'w') as outfile: json.dump(data, outfile) def load_amzn_options(self): try: with open('amazon.json') as json_file: return json.load(json_file) except: return { 'amazon_email': None, 'amazon_password': None, 'amazon_item_url': None, 'amazon_price_limit': None } def amazon_run_item(self): amzn_obj = Amazon(username=self.amazon_email.value, password=self.amazon_password.value, debug=True) amzn_obj.run_item(item_url=self.amazon_item_url.value, price_limit=self.amazon_price_limit.value) def start_amzn(self): if self.amazon_email.value and self.amazon_password.value and self.amazon_price_limit.value and self.amazon_item_url.value: log.info("Starting amazon bot.") self.save_amzn_options() self.start_button.disable() self.stop_button.enable() self.amazon_status.value = "Running." self.amazon_executor.submit(self.amazon_run_item) def stop_amzn(self): self.amazon_executor.shutdown() self.amazon_status.value = "Stopped." self.start_button.enable() self.stop_button.disable() def nv_run(self): nv = NvidiaBuyer() nv.buy(self.nv_gpu.value) def start_nv(self): if self.nv_gpu.value: log.info("Starting NV bot.") self.nv_status.value = "Running." self.start_button_nv.disable() self.stop_button_nv.enable() self.amazon_executor.submit(self.nv_run) def stop_nv(self): self.nvidia_executor.shutdown() self.nv_status.value = "Stopped." self.start_button_nv.enable() self.stop_button_nv.disable()
def StartTwoPlayer(): global twoPlayerWindow global drawButtonTwoPlayer global cardImagesTwoPlayer1 global cardImagesTwoPlayer2 global guessContainerTwoPlayer1 global guessContainerTwoPlayer2 global guessTextBoxTwoPlayer1 global guessTextBoxTwoPlayer2 global guessCheckButtonTwoPlayer global correctTwoPlayer1 global correctTwoPlayer2 global errorTextTwoPlayer twoPlayerWindow = Window(app, title="Two Player Game", layout="grid") twoPlayerWindow.width = 660; twoPlayerWindow.height = 570; twoPlayerWindow.bg = "Lime" drawButtonTwoPlayer = PushButton(twoPlayerWindow, text="Draw!", grid=[0, 0], align="top", padx=20, command=ButtonSwapTwoPlayer) drawButtonTwoPlayer.width = 20; drawButtonTwoPlayer.height = 5; drawButtonTwoPlayer.bg = "White" cardImagesTwoPlayer1 = Box(twoPlayerWindow, layout="grid", grid=[0, 1], align="top", border=True) cardImagesTwoPlayer1.set_border(5, "Lime") cardImagesTwoPlayer2 = Box(twoPlayerWindow, layout="grid", grid=[1, 1], align="top", border=True) cardImagesTwoPlayer2.set_border(5, "Lime") guessContainerTwoPlayer1 = Box(twoPlayerWindow, layout="grid", grid=[0, 2], align="top", border=True) guessContainerTwoPlayer1.set_border(10, "Lime") guessTextBoxTwoPlayer1 = TextBox(guessContainerTwoPlayer1, grid=[0, 0], align="top") guessTextBoxTwoPlayer1.text_size = 20; guessTextBoxTwoPlayer1.bg = "White"; guessTextBoxTwoPlayer1.disable() guessContainerTwoPlayer2 = Box(twoPlayerWindow, layout="grid", grid=[1, 2], align="top", border=True) guessContainerTwoPlayer2.set_border(10, "Lime") guessTextBoxTwoPlayer2 = TextBox(guessContainerTwoPlayer2, grid=[0, 0], align="top") guessTextBoxTwoPlayer2.text_size = 20; guessTextBoxTwoPlayer2.bg = "White"; guessTextBoxTwoPlayer2.disable() pointsTextTwoPlayer1 = Text(guessContainerTwoPlayer1, text="Player One Score: ", grid=[0, 2], align="top") pointsTextTwoPlayer2 = Text(guessContainerTwoPlayer2, text="Player Two Score: ", grid=[0, 2], align="top") guessCheckButtonTwoPlayer = PushButton(twoPlayerWindow, text="Check!", grid=[0, 3], align="top", command=CheckValuesTwoPlayer) guessCheckButtonTwoPlayer.width = 20; guessCheckButtonTwoPlayer.height = 5; guessCheckButtonTwoPlayer.bg = "White"; guessCheckButtonTwoPlayer.disable() correctTwoPlayer1 = Text(guessContainerTwoPlayer1, text="", grid=[0, 3]) correctTwoPlayer2 = Text(guessContainerTwoPlayer2, text="", grid=[0, 3]) errorTextTwoPlayer = Text(twoPlayerWindow, text="Please Enter a Number!", grid=[0, 4]) errorTextTwoPlayer.hide()
else: app.destroy() menubar = MenuBar(app, toplevel=["File"], options=[[["open", open_file], ["save", save_file], ["exit", exit]]]) file_box = Box(app, align="top", width="fill") file_name = TextBox(file_box, text="text_file.txt", width=50, align="left") save_button = PushButton(file_box, text="SAVE", align="right", command=save_file) save_button.hide() save_button.disable() open_button = PushButton(file_box, text="OPEN", align="right", command=open_file) editor = TextBox(app, height="fill", width="fill", multiline=True, command=save_enable) func_box = Box(app, align="bottom", width="fill", border=True) font = Combo(func_box, options=["courier", "times new roman", "verdana"], align="left", command=change_font) size = Slider(func_box, command=change_size)