def __init__(self, master, controller, img): ''' Sets up the validation scale view screen Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(ValidationScaleController object): The controller which will be in charge of the view img(Image): Confirm taken image from camera ''' BaseView.__init__(self, master) self.addTitle("Does this look okay?") self.imgPanel = Label(self ) self.imgPanel.pack(side=TOP) def resizeImgPanel(imgPanel,img): panelWidth = (master.winfo_width()-10) panelHeight = (master.winfo_height() -165) resizdeImg = AppUtils.converImgToTkinterImg(img, panelWidth, panelHeight) imgPanel.configure(width=panelWidth, height=panelHeight, image = resizdeImg) imgPanel.image = resizdeImg self.imgPanel.bind("<Configure>", lambda e: resizeImgPanel(self.imgPanel, img) ) self.noButton = Button(self, text="No, return to scale calibration screen", command=controller.noClicked) self.noButton.pack(side=BOTTOM) self.yesButton = Button(self, text="Yes, start calibrating scale", command=controller.yesClicked) self.yesButton.pack(side=BOTTOM)
def __init__(self, master, controller): ''' Sets up the skew view Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(SkewController object): The controller which will be in charge of the view ''' BaseView.__init__(self, master) self.addTitle("Skew Calibration") def resizeVideoCapturePanel(videoCapturePanel, controller): controller.updatePanel() videoCapturePanel.configure(width=master.winfo_width()-50, height=master.winfo_height()-195) controller.updatePanel() self.videoCapturePanel = Label( self, width=master.winfo_width()-50, height=master.winfo_height()-195 , relief=RIDGE, borderwidth=2) self.videoCapturePanel.bind("<Configure>", lambda e: resizeVideoCapturePanel(self.videoCapturePanel, controller) ) self.videoCapturePanel.pack(side=TOP) self.undoButton = Button(self, text="Undo last photo", state=DISABLED, command=controller.undoClicked) self.undoButton.pack(side=BOTTOM) self.photoButton = Button(self, text="Take photo", command=controller.takePhotoClicked) self.photoButton.pack(side=BOTTOM) self.calibrateButton = Button(self, text="Start Skew Calibration", command=controller.startSkewCalibration) self.calibrateButton.pack(side=BOTTOM)
def __init__(self, master, controller): ''' Sets up the contours view Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(ContoursController object): The controller which will be in charge of the view ''' BaseView.__init__(self, master) self.addTitle("Scan Board") #Video Capture frame for both cameras self.videoPanel = Label(self ) self.videoPanel.pack(side=TOP) def resizeVideoCapturePanels(videoPanel,controller): controller.updatePanel() panelWidth = (master.winfo_width()-10) panelHeight = (master.winfo_height() -140) videoPanel.configure(width=panelWidth, height=panelHeight) controller.updatePanel() self.videoPanel.bind("<Configure>", lambda e: resizeVideoCapturePanels(self.videoPanel, controller) ) self.photosButton = Button(self, text="Take photo", command=controller.takePhotosClicked) self.photosButton.pack(side=BOTTOM)
def __init__(self, master, controller, img): """ Sets up the validation contours view screen Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(ValidationContoursController object): The controller which will be in charge of the view img(Image): The resulting image from the contours model processing """ BaseView.__init__(self, master) self.addTitle("Does this look okay?") def configImgPanel(img, imgPanel): resizdeImg = AppUtils.converImgToTkinterImg(img, master.winfo_width() - 50, master.winfo_height() - 150) imgPanel.configure( width=master.winfo_width() - 50, height=master.winfo_height() - 150, relief=RIDGE, borderwidth=2, image=resizdeImg, ) imgPanel.image = resizdeImg self.imgPanel = Label(self) configImgPanel(img, self.imgPanel) self.imgPanel.bind("<Configure>", lambda e: configImgPanel(img, self.imgPanel)) self.imgPanel.pack(side=TOP) self.noButton = Button(self, text="No", command=controller.noClicked) self.noButton.pack(side=BOTTOM) self.yesButton = Button(self, text="Yes", command=controller.yesClicked) self.yesButton.pack(side=BOTTOM)
def post(self, request, client, client_id): data = json.loads(request.body.decode('utf-8')) account_data = {} account_data['login'] = data.pop('login') account_data['password'] = data.pop('password') data.pop('role', None) result = BaseAccontsView.user_validator(account_data) if result['status'] != 'Success': return result response = requests.post(settings.DANCERS_SERVICE_BASE_URL + 'dancers/sportsmans/', headers={ 'Authorization': settings.SERVICE_SECRET, 'From': settings.SERVICE_ID, 'To': 'Dancers' }, json=data) if response.status_code != 200: return { 'status': 'Failed', 'message': 'Service Error', 'code': 500 } print(response.json()) account_data['uuid'] = response.json()['data'] account_data['password'] = BaseView.hash_password( account_data['password']) response = Users.objects.create(**account_data).pk BaseView.log(user_auth_log, request, client, client_id) return {'status': 'Success', 'data': response, 'code': 200}
def __init__(self, master, controller, img): ''' Sets up the skew validation contours view screen Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(ValidationSkewController object): The controller which will be in charge of the view img(Image): The resulting image from the skew model processing ''' BaseView.__init__(self, master) self.addTitle("Does this look okay?") def configImgPanel(img, imgPanel): cv2.imwrite('IMPORTANTTEST.jpg', img) resizedImg = AppUtils.converImgToTkinterImg(img, master.winfo_width()-50, master.winfo_height()-165) imgPanel.configure(width=master.winfo_width()-50, height=master.winfo_height()-165, relief=RIDGE, borderwidth=2, image = resizedImg) imgPanel.image = resizedImg self.imgPanel = Label(self) configImgPanel(img, self.imgPanel) self.imgPanel.bind("<Configure>", lambda e: configImgPanel(img, self.imgPanel) ) self.imgPanel.pack(side=TOP) self.redoButton = Button(self, text="No, return to calibrating skew", command=controller.redoClicked) self.redoButton.pack(side=BOTTOM) continueText = "Yes, continue to scale calibration" self.continuteButton = Button(self, text=continueText, command=controller.continueClicked) self.continuteButton.pack(side=BOTTOM)
def post(self, request, client, client_id): # TODO отправка данных на сервис танцоров data = json.loads(request.body.decode('utf-8')) data['service_secret'] = BaseView.hash_password(data['service_secret']) response = Services.objects.create(**data).pk BaseView.log(service_log, request, client, client_id) return {'status': 'Success', 'data': response, 'code': 200}
def get(self, request, uuid, client, client_id): response = list(Application.objects.filter(pk=uuid).values()) if not response: return { 'status': 'Failed', 'message': 'Object does not exist', 'code': 404 } BaseView.log(log, request, client, client_id) return {'status': 'Success', 'data': response, 'code': 200}
def post(self, request): data = json.loads(request.body.decode('utf-8')) result = self.data_analizer(data) if result['status'] != 'Success': return result mode = result['mode'] if mode == 'Authorization': result = BaseView.token_verification(data['access_token'], 'uuid', 'role', 'type') if result['status'] != 'Success': return result return {'status': 'Success', 'data': result['data'], 'code': 200} elif mode == 'Authentication': result = self.authentication(data) return result elif mode == 'Update tokens': result = BaseUserAuthView.update_tokens(access_token_size, refresh_token_size, access_token_ttl, refresh_token_ttl, data['refresh_token'], 'uuid', 'role', 'type') return result
def post(self, request): data = json.loads(request.body.decode('utf-8')) result = self.data_analizer(data) if result['status'] != 'Success': return result mode = result['mode'] if mode == 'Authorization': result = BaseView.token_verification(data['access_token'], 'from_service', 'to_service', 'type') if result['status'] != 'Success': return result return {'status': 'Success', 'data': result['data'], 'code': 200} elif mode == 'Authentication': result = self.authentication(data) return result elif mode == 'Update tokens': result = BaseServiceAuthView.update_tokens( access_token_size, refresh_token_size, access_token_ttl, refresh_token_ttl, data['refresh_token'], 'from_service', 'to_service', 'type') # self.log.info('Обновление токенов пользователя') return result
def swipeLr(self, xs, xe, y): logging.info('========swipe lr========') l = BaseView.get_size(self) x1 = int(l[0] * xs) y1 = int(l[1] * y) x2 = int(l[0] * xe) self.driver.swipe(x1, y1, x2, y1, 1000) # 左/右滑动
def swipeUd(self, ys, ye, x): logging.info('========swipe ud========') l = BaseView.get_size(self) y1 = int(l[1] * ys) x1 = int(l[0] * x) y2 = int(l[1] * ye) self.driver.swipe(x1, y1, x1, y2, 1000) # 上/下滑动
def authentication(self, data): user = Users.objects.filter(login=data['login']) if not user or BaseView.hash_password( data['password']) != user[0].password: return { 'status': 'Failed', 'message': 'Invalid credentials', 'code': 400 } tokens = BaseView.get_tokens(access_token_size, refresh_token_size, access_token_ttl, refresh_token_ttl, uuid=user[0].uuid, role=user[0].role, type='User') return {'status': 'Success', 'data': tokens, 'code': 200}
def authentication(self, data): service = Services.objects.filter(service_id=data['service_id']) if not service or BaseView.hash_password( data['service_secret']) != service[0].service_secret: return { 'status': 'Failed', 'message': 'Invalid credentials', 'code': 400 } tokens = BaseView.get_tokens(access_token_size, refresh_token_size, access_token_ttl, refresh_token_ttl, from_service=service[0].service_id, to_service=data['service'], type='Service') return {'status': 'Success', 'data': tokens, 'code': 200}
def __init__(self, master, controller): ''' Sets up The PromptSkewView Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(PromptSkewController object): The controller which will be in charge of the view ''' BaseView.__init__(self, master) self.addTitle("Skew Calibration") self.panel = Frame(self,relief=RIDGE, borderwidth=2) self.panel.pack_propagate(0) self.panel.pack(side=TOP) scrollbar = Scrollbar(self.panel) scrollbar.pack(side=RIGHT, fill=Y) instructions = Text(self.panel, wrap=WORD, yscrollcommand=scrollbar.set, state=NORMAL) instructions.delete(1.0, END) instructions.insert(END, "Skew Calibration Instructions: \nSkew calibration is not necessary to proceed. If you skip Skew Calibration, however, your results will be less accurate. \nStep 0: Press Calibrate button \nStep 1: Print out <location of circlegrid pattern> \nStep 2: Place printout on machine bed, with entire pattern in view of camera. \nStep 3: Take two(2) photos. \nStep 4: Rotate image in bed by ~ 15-20 degrees. \nStep 5: Take photo. \nStep 6: Repeat steps 4 and 5 until you have taken at least 15 photos. \nStep 7: Press Start") instructions.config(state=DISABLED) instructions.pack(side=TOP, fill=BOTH, expand=True) def resizePanel(panel): panelWidth = (master.winfo_width()-10) panelHeight = (master.winfo_height() -195) panel.configure(width=panelWidth, height=panelHeight) self.panel.bind("<Configure>", lambda e: resizePanel(self.panel) ) scrollbar.config(command=instructions.yview) self.skipButton = Button(self, text="Skip skew", command=controller.skipClicked) self.skipButton.pack(side=BOTTOM) self.calibrateButton = Button(self, text="Calibrate skew", command=controller.calibrateClicked) self.calibrateButton.pack(side=BOTTOM) self.deleteButton = Button(self, text="Delete skew", command=controller.deleteClicked) self.deleteButton.pack(side=BOTTOM)
def __init__(self, master, controller, json): ''' Sets up the export view Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(ExportController object): The controller which will be in charge of the view jsonText(String): The json text which is displayed to the user after export ''' BaseView.__init__(self, master) self.addTitle("JSON Exported") self.panel = Frame(self,relief=RIDGE, borderwidth=2) self.panel.pack_propagate(0) self.panel.pack(side=TOP) scrollbar = Scrollbar(self.panel) scrollbar.pack(side=RIGHT, fill=Y) jsonText = Text(self.panel, wrap=WORD, yscrollcommand=scrollbar.set, state=NORMAL) jsonText.delete(1.0, END) jsonText.insert(END, json) jsonText.config(state=DISABLED) jsonText.pack(side=TOP, fill=BOTH, expand=True) def resizePanel(panel): panelWidth = (master.winfo_width()-10) panelHeight = (master.winfo_height() -110) panel.configure(width=panelWidth, height=panelHeight) self.panel.bind("<Configure>", lambda e: resizePanel(self.panel) ) scrollbar.config(command=jsonText.yview) self.skipButton = Button(self, text="Exit", command=master.destroy) self.skipButton.pack(side=BOTTOM)
def delete(self, request, uuid, client, client_id): response = requests.delete( settings.DANCERS_SERVICE_BASE_URL + 'dancers/sportsman/{}/'.format(uuid), headers={ 'Authorization': settings.SERVICE_SECRET, 'From': settings.SERVICE_ID, 'To': 'Dancers' }, ) print(response.status_code) if response.status_code != 200: return { 'status': 'Failed', 'message': 'Service Error', 'code': 500 } entry = Users.objects.filter(pk=uuid) entry.delete() BaseView.log(user_auth_log, request, client, client_id) return {'status': 'Success', 'code': 200}
def get(self, request, client, client_id): params = request.GET response = list(Application.objects.filter(**params).values()) BaseView.log(log, request, client, client_id) return {'status': 'Success', 'data': response, 'code': 200}
def post(self, request, client, client_id): # TODO отправка данных на сервис танцоров data = json.loads(request.body.decode('utf-8')) response = Application.objects.create(**data).pk BaseView.log(log, request, client, client_id) return {'status': 'Success', 'data': response, 'code': 200}
def patch(self, request, uuid, client, client_id): data = json.loads(request.body.decode('utf-8')) Application.objects.filter(pk=uuid).update(**data) response = list(Application.objects.filter(pk=uuid).values()) BaseView.log(log, request, client, client_id) return {'status': 'Success', 'data': response, 'code': 200}
def delete(self, request, uuid, client, client_id): # TODO отправлка данных на сервис танцоров entry = Application.objects.filter(pk=uuid) entry.delete() BaseView.log(log, request, client, client_id) return {'status': 'Success', 'code': 200}
def __init__(self, master, controller,formParams): ''' Sets up the ScaleView Args: master(Tk object): The toplevel widget of Tk which is the main window of an application controller(ScaleController object): The controller which will be in charge of the view formParams(Dictionary): The current form params ''' BaseView.__init__(self, master) self.addTitle("Scale Calibration") #Video Capture frame for both cameras self.videoPanel = Label(self ) self.videoPanel.pack(side=TOP) panelWidth = (master.winfo_width()-10) panelHeight = (master.winfo_height() -230) def resizeVideoCapturePanel(videoPanel, controller): controller.updatePanel() panelWidth = (master.winfo_width()-10) panelHeight = (master.winfo_height() -230) videoPanel.configure(width=panelWidth, height=panelHeight) controller.updatePanel() self.videoPanel.bind("<Configure>", lambda e: resizeVideoCapturePanel(self.videoPanel, controller) ) defaultFont = tkFont.nametofont("TkDefaultFont") #Width onEditVar= StringVar() onEditVar.set(str(formParams['width'])) onEditVar.trace("w", lambda name, index, mode, onEditVar=onEditVar: self.updateExportButton()) vcmd = (master.register(self.validate),'%P', '%S') widthPanel = Label(self) widthLabel = Label(widthPanel, text="Width:") widthLabel.pack(side=LEFT) self.widthInput = Entry(widthPanel, width=11, validate = 'key', validatecommand = vcmd, textvariable=onEditVar, font=defaultFont) self.widthInput.pack(side=RIGHT) widthPanel.pack(side=TOP) #Height onEditVar= StringVar() onEditVar.set(str(formParams['height'])) onEditVar.trace("w", lambda name, index, mode, onEditVar=onEditVar: self.updateExportButton()) heightPanel = Label(self) heightLabel = Label(heightPanel, text="Height:") heightLabel.pack(side=LEFT) self.heightInput = Entry(heightPanel, width=11, validate = 'key', validatecommand = vcmd, textvariable=onEditVar, font=defaultFont) self.heightInput.pack(side=RIGHT) heightPanel.pack(side=TOP) #Units unitsPanel = Label( self) calibrationLabel = Label(unitsPanel, text="Units:") calibrationLabel.pack(side=LEFT) self.unitsBox = ttk.Combobox(unitsPanel, width=10, state="readonly", font=defaultFont) self.unitsBox['values'] = ('cm', 'in', 'mm') self.unitsBox['state'] = 'readonly' self.unitsBox.set(formParams['units']) self.unitsBox.pack(side=RIGHT) unitsPanel.pack(side=TOP) #Export button self.photosButton = Button(self, text="Take photo", command=controller.photosClicked) self.photosButton.pack(side=TOP)