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()
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))
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()