def trigger_reconhecimento(): global imagem, img_window if imagem == 0: gui.warn('Erro', 'Selecione uma imagem') return False else: gui.info('Resultado', rcgTrigger.execute(imagem="./assets/" + imagem))
def _database_add_note_button(self): sql_note_datetime = self.current_config.get_str_datetime_now() utc_0_datetime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] sql_note = self.sterilize_notes(self.textbox_current_note.value) if self.checkbox_use_current_datetime.value: sql_note_user_datetime = sql_note_datetime else: sql_note_user_datetime = self.textbox_note_date.value.strip() self.database_notes.append(sql_note) self.database_notes_dates.append(utc_0_datetime) self.database_user_note_dates.append(sql_note_user_datetime) datetime_offset = self.current_config.datetime_offset sql_note_user_datetime_utc_0 = self.adjust_datetime(sql_note_user_datetime, datetime_offset * -1) if sql_note == "": guizero.warn("Empty Note", "Cannot add a blank Note") else: self.button_delete_note.enable() self.button_update_note.enable() self.button_back_note.enable() self.button_next_note.enable() sql_query = "INSERT OR IGNORE INTO " + \ self.sql_column_names.sql_other_table + " (" + \ self.sql_column_names.date_time + "," + \ self.sql_column_names.other_notes + "," + \ self.sql_column_names.other_user_datetime + \ ") VALUES ('" + utc_0_datetime + "','" + sql_note + "','" + sql_note_user_datetime_utc_0 + "')" self._sql_execute(sql_query) self._database_change_to_note_plus(0)
def no_hat_check(): global NOHAT global ONEMU NOHAT = yesno( "No SenseHAT detected", "No SenseHat detected - Do you want to carry on anyway?") if NOHAT: if "arm" in os.uname().machine: ONEMU = yesno( "Looks like a Pi", "Do you want to try to run in the SenseHat emulator?") if ONEMU: if not os.path.isfile("/usr/bin/sense_emu_gui"): warn( "Sorry", "It doesn't look like the SenseHAT emulator is installed" ) sys.exit() else: warn( "No pi!", "It doesn't look like the you're on a Raspberry Pi. You can still save animations and images." ) else: sys.exit()
def _sensor_update_note_button(self): current_note_number = int(self.textbox_on_number_notes.value.strip()) - 1 utc_0_datetime_current = self.database_notes_dates[current_note_number] reverse_datetime_offset = self.current_config.datetime_offset * -1 if self.checkbox_use_current_datetime.value: datetime_var = self.current_config.get_str_datetime_now() else: datetime_var = self.textbox_note_date.value.strip() self.database_user_note_dates[current_note_number] = datetime_var self.textbox_note_date.value = datetime_var utc_0_datetime_user = str(self.adjust_datetime(datetime_var, reverse_datetime_offset)) sql_note = self.sterilize_notes(self.textbox_current_note.value) try: on_note_number = int(self.textbox_on_number_notes.value.strip()) - 1 self.database_notes[on_note_number] = self.undue_sterilize_notes(sql_note) if sql_note == "": guizero.warn("Empty Note", "Cannot add a blank Note") else: command = self.network_send_commands.update_sql_note network_timeout = self.current_config.network_timeout_data sensor_command = sensor_commands.CreateSensorNetworkCommand(self.selected_ip, network_timeout, command) sensor_command.command_data = utc_0_datetime_current + \ self.network_send_commands.command_data_separator + \ utc_0_datetime_user + \ self.network_send_commands.command_data_separator + \ sql_note sensor_commands.put_command(sensor_command) except Exception as error: guizero.warn("Invalid Note Number", str(error))
def show_file(file_pointer): """show_file(file_pointer) shows a file in the global file list""" global canvas, current_image # in case they forgot to select directory if len(files) == 0: warn("Error", "No files selected") return 0 if file_pointer >= len(files): file_pointer = 0 if file_pointer < 0: file_pointer = len(files) - 1 fname = files[file_pointer] pathname = os.path.join(folder_selected, fname) try: # try to show a picture and associated observations if DEBUG: print("displaying {}".format(pathname)) current_image = observations.show_image_observations_by_filename( canvas, fname) except Exception as e: # in case of an error, flag it and show user msg = "Exception show_image(): {} (on attempt to render {})".format( str(e), pathname) warn("Exception", msg) # return the file_pointer return file_pointer
def completeTask(): """ function to mark a task as completed in the database : return : None """ if getList(task) != None: if database.retrieve_task(getList(task))[4] == 'True': # print(getList(task)) # if task is already completed, implement a warning if guizero.yesno( "Illegal action", "Task is already completed, Do you want to remove it instead?" ): database.delete_task(getList(task)) refreshScreen() else: # print(getList(task)) if database.complete_task(getList(task)): refreshScreen() else: # if there was a database error, raise a warning guizero.warn("Error", "Error completing task") else: # if no task has been selected guizero.warn("Task", "Select a task first")
def _database_update_note_button(self): current_note_number = int(self.textbox_on_number_notes.value.strip()) - 1 datetime_offset = self.current_config.datetime_offset user_note_datetime = self.textbox_note_date.value.strip() try: if self.checkbox_use_current_datetime.value: current_datetime = self.current_config.get_str_datetime_now() user_note_datetime_utc = str(self.adjust_datetime(current_datetime, datetime_offset * -1)) else: user_note_datetime_utc = self.adjust_datetime(user_note_datetime, datetime_offset * -1) except Exception as error: app_logger.app_logger.error("Unable to convert current Note's user set DateTime: " + str(error)) user_note_datetime_utc = user_note_datetime current_note_datetime_utc = self.database_notes_dates[current_note_number] self.database_user_note_dates[current_note_number] = user_note_datetime sql_note = self.sterilize_notes(self.textbox_current_note.value) if sql_note == "": guizero.warn("Empty Note", "Cannot add a blank Note") else: sql_query = "UPDATE " + self.sql_column_names.sql_other_table + \ " SET " + self.sql_column_names.other_notes + \ " = '" + sql_note + \ "', " + self.sql_column_names.other_user_datetime + \ " = '" + user_note_datetime_utc + \ "' WHERE " + self.sql_column_names.date_time + \ " = '" + current_note_datetime_utc + "'" self._sql_execute(sql_query) self._database_change_to_note_plus(0)
def _sensor_add_note_button(self): """ Send the note to selected sensor. """ if self.textbox_current_note.value.strip() == "": guizero.warn("Empty Note", "Cannot add a blank Note") else: if self.checkbox_use_current_datetime.value: self._reset_datetime() try: user_datetime_var = self.adjust_datetime(self.textbox_note_date.value, self.current_config.datetime_offset * -1) except Exception as error: user_datetime_var = self.textbox_note_date.value app_logger.sensor_logger.error("Unable to convert user entered DateTime: " + str(error)) command = self.network_send_commands.put_sql_note network_timeout = self.current_config.network_timeout_data sensor_command = sensor_commands.CreateSensorNetworkCommand(self.selected_ip, network_timeout, command) sensor_command.command_data = user_datetime_var + \ self.network_send_commands.command_data_separator + \ self.sterilize_notes(self.textbox_current_note.value) sensor_commands.put_command(sensor_command) guizero.info("Note Inserted into Sensors " + self.selected_ip, "Inserted with DateTime: " + user_datetime_var) app_logger.sensor_logger.info("Inserted note into sensors " + str(self.selected_ip) + " with DateTime " + user_datetime_var) self._connect_to_sensor()
def set_flow(): if ChkUsrInputX.chkUsrNumSetPoint(flow_rate_textbox.value): print(flow_rate_textbox.value) flow.set_Exp_flow_Rate(flow_rate_textbox.value) else: warn("Oops", "Not a Valid Number") select_flow()
def edit(self): if self.identity_card[self.directs.value]==1: self.option.text='Off' self.identity_card[self.directs.value]=0 guizero.info(title='Modification performed',text=[' Deactivated',self.directs.value,]) else: guizero.warn(title='Error modification',text=['It is impossible deactivated ',self.directs.value]) self.text_box.value = self.identity_card
def openFile(): global data app.filename = filedialog.askopenfilename(initialdir="/", title = "Open", filetypes=(("text files", "*.txt"),("all files", "*.*"))) warn("This File?", "Openning "+app.filename) theFile = open(app.filename, "r") data.value = theFile.read() app.title=app.filename theFile.close()
def OTPHandler(): """ A handler for generating the OTP """ global data length = len(data.value) generate_otp(1, length) warn("OTP", "Made 1 OTP Key of Length " + str(length))
def selection_chosen(): selection.hide() if selection.value == "1": info("well done", "you chose wisely") goodbye() else: warn("arrrgh", "next time, choose wisely!") app.after(2000, show_the_selection)
def saveFile(): global data app.filename = filedialog.asksaveasfilename(initialdir="/", title="Save as", filetypes = (("text files", "*.txt"),("all files", "*.*"))) warn("This File?", "Saving as "+app.filename) print(data.value) theFile = open(app.filename, "w") theFile.write(data.value) app.title=app.filename theFile.close()
def get_Text(): # Function to take value of number entered flowtext.value = input_box.get() if ChkUsrInputX.chkUsrNum(flowtext.value): #s.write(flow.SetPoint_Write(flowtext.value)) print("Worked") else: # Error message warn("Oops", "Not a Valid Number.")
def deleteAll(): """ Function to delete all items from the database and listbox : return : None """ if database.delete_all(): task.clear() else: guizero.warn("Error", "Could not delete all tasks from database")
def walk(matrix, identity_cards): x, y = location('o', matrix) identity_cards[x, y]['possible'] = 3 xo, yo = x, y crossing = [] step = [] error = 0 old_steps = ['fermo'] crossing.append('fermo') xf, yf = location('v', matrix) tmatrix = copy.copy(matrix) while tmatrix[xf, yf] == 'v': action = 0 priority = set_priority(x, y, matrix) for i in range(4): # controlla priorita if identity_cards[x, y][priority[i]] == 1: xt, yt = direct(priority[i], x, y) # controlla casella libera if tmatrix[xt, yt] == ' ' or tmatrix[xt, yt] == 'v': tmatrix[xt, yt] = 'O' if identity_cards[x, y]['possible'] > 2: # salva coordinate e direzione degli incroci crossing.append({ 'coordinate': [x, y], 'direct': priority[i] }) # avanzamento x, y = xt, yt action += 1 step.append(priority[i]) break if action == 0: error += 1 tmatrix = copy.copy(matrix) x, y = xo, yo old_steps.append(step[:]) step.clear() # controllo possibilita risoluzzione if old_steps[-1] == old_steps[-2]: guizero.warn(title='error', text='It is impossible go forward') return ['impossible'] else: # prova modifica incrocio try: xt, yt = crossing[-1]['coordinate'][0], crossing[-1][ 'coordinate'][1] identity_cards[xt, yt][crossing[-1]['direct']] = 0 identity_cards[xt, yt]['possible'] -= 1 except TypeError: guizero.warn(title='Error', text='It is impossible go forward') return ['impossible'] guizero.info(title='', text=('Error number ', error)) return step
def Tutorial(): # Open the project page if requested. go_to_tutorial = yesno("Open Tutorial", "Get more information about the project!") if go_to_tutorial == True: command = "chromium-browser https://theamplituhedron.com/projects/" call([command], shell=True) print("Project Tutorial!") else: warn("Close", "Return to the application!")
def set_moles(): if ChkUsrInputX.chkUsrNumMole(enter_moles_textbox.value): flow.set_Moles(enter_moles_textbox.value) flow.moles_to_ccm() select_flow() else: warn("Oops", "Not a Valid Number") select_moles() print("hide moles")
def SetOTPHandler(): """ A handler for telling the app which OTP to use """ global otpfilename otpfilename = filedialog.askopenfilename(title="Open OTP", filetypes=(("text files", "*.txt"), ("all files", "*.*"))) warn("OTP", "Using OTP " + otpfilename)
def encryptFile(): """ takes the otpfilename and uses load_sheet to open the correct OTP Then replaces the value of the textbox widget to the cyphertext """ global data, otpfilename if len(otpfilename) > 0: warn("Encryption", "Data Encrypted Using " + otpfilename) data.value = encrypt(data.value, load_sheet(otpfilename)) else: warn("Encryption", "No OTP file loaded so not Encrypted")
def decryptFile(): """ An event handler that manages a decryption """ global data, otpfilename if len(otpfilename) > 0: sheet = load_sheet(otpfilename) data.value = decrypt(data.value, sheet) warn("Decrypt", "Data Decrypted using key " + otpfilename) else: warn("Decrypt", "No OTP file loaded so not decrypted")
def evaluateSensorValue(): # Test your module, then define the value range - in this case between 0 and 60000. sensorValue = _range(channel_0.value, 0, 60000, 0, 1023) sensor_value.value = sensorValue # Threshold if (sensorValue > 300): status_text.value = "Status: DANGER" status_text.text_color = "yellow" warn("!!!DANGER!!!", "Air Quality Deteriorating!") else: status_text.value = "Status: OK" status_text.text_color = "green"
def addTask(): """ Function to add a task to the database : return: None """ if getValue(enterTask) == '': guizero.warn("Illegal action", "Enter a task first") else: if database.insert_task(getValue(enterTask), datetime.datetime.now()): refreshScreen() else: guizero.warn("Error", "Could not add Task")
def removeTask(): """ Function to remove a task from the listbox and the database : return None """ if getList(task) == None: # if a task has not been selected guizero.warn("Illegal action", "Select a task first") else: if database.delete_task(getList(task)): refreshScreen() else: guizero.warn("Error", "Error removing task")
def do_nothing(): c = my_input.get() if c == "treasure": info("BEST", "You are welcomed !") pwm.ChangeDutyCycle(4) GPIO.output(16, GPIO.HIGH) sleep(3) GPIO.output(16, GPIO.LOW) else: warn("BAD!", "Please Try again !") GPIO.output(10, GPIO.HIGH) sleep(3) GPIO.output(10, GPIO.LOW)
def delete_frame(): global current_frame_number global frames global blank_frame if current_frame_number != 1: if current_frame_number != len(frames): # not last frame for f in range(current_frame_number, len(frames)): frames[f] = frames[f + 1].copy() current_frame_number -= 1 del frames[len(frames)] load_frame() else: warn("Heads up", "Only one frame exits - you can't delete it")
def mark_function(): """initates marking operation""" global files global filename if DEBUG: print("Mark Images") try: # get files from current directory files = get_image_filenames(folder_selected) if len(files) < 0: warn("Error", "This folder contains no image files") show_file(file_pointer) except Exception as e: warn("Exception thrown", "Invalid folder. Please select valid folder.")
def _click_checkbox_offset(self): """ Enable or disable custom Env temperature offset for a graph. """ if self.checkbox_default_offset.value: self.textbox_temperature_offset.disable() self.current_config.enable_custom_temp_offset = False else: self.textbox_temperature_offset.enable() self.current_config.enable_custom_temp_offset = True try: self.current_config.temperature_offset = float( self.textbox_temperature_offset.value) except Exception as error: self.current_config.temperature_offset = 0 guizero.warn("Invalid Temperature Offset", "Please check and correct 'Env Temp Offset'") app_logger.app_logger.warning( "Invalid Graph 'Env Temp Offset': " + str(error))
def show_file(file_pointer): """show_file(file_pointer) shows a file in the global file list""" global canvas, current_image # in case they forgot to select directory if len(files) == 0: warn("Error", "No files selected") return 0 if file_pointer >= len(files): file_pointer = 0 if file_pointer < 0: file_pointer = len(files) - 1 fname = files[file_pointer] pathname = os.path.join(folder_selected, fname) try: # try to show a picture and associated observations if DEBUG: print("displaying {}".format(pathname)) # find existing observations image_observation_indices = observations.find_by_filename(fname) # if there is a non empty list, if image_observation_indices: # first index first = image_observation_indices[0] # show the current image current_image = observations.items[first].image current_image.show(canvas) # step through the individual observations and display the marker for index in image_observation_indices: current_observation = observations.items[index] current_observation.show_marker(canvas) else: # no observations yet, instantiate a new image and show on canvas current_image = Image(fname, folder_selected) current_image.show(canvas) except Exception as e: # in case of an error, flag it and show user msg = "Exception show_image(): {} (on attempt to render {})".format( str(e), pathname) warn("Exception", msg) # return the file_pointer return file_pointer
def admin_warn(): warn("NOTE!!", "You will need to provide authenications from here!") admin_menu_window.show(wait=True) # if user continues, show new window in modal mode app.hide() # hide app or main window