def submit_numeric_value(self): number = float(self.numeric_value_spinbox.get()) path = self.file_combobox.get() option = get.option_names_in_file(path)[ self.select_setting_combobox.current()] value = get.possible_value_by_number( path, option, self.select_value_combobox.current()) diff_from_step = check.diff_to_step(value['min'], value['max'], value['step'], number) if value['max'] != None and value['max'] != '' and number > float( value['max']): tk.messagebox.showwarning(title='Out of range', message="Number is bigger than max") elif value['min'] != None and value['min'] != '' and number < float( value['min']): tk.messagebox.showwarning(title='Out of range', message="Number is less than min") elif value['step'] != None and value[ 'step'] != '' and diff_from_step != 0: tk.messagebox.showwarning( title='Out of range', message='Number fails the step constraint by ' + str(diff_from_step)) else: response = set.option_value(path, option, number) if response == 200: self.switch_to_before_set_value() elif response == 701: tk.messagebox.showwarning(title="Error", message="701 Error")
def switch_to_possible_values(self): path = self.file_combobox.get() option = get.option_names_in_file(path)[ self.select_setting_combobox.current()] self.possible_values_current_label.configure( text=self.current_value_part_1 + extract.get_value(path, option)['Value']) self.possible_values = [] self.inside_file_frame.pack_forget() if self.has_dot_xml: i = 1 for value in get.option_values(path, option): comment = get.possible_value_by_number(path, option, i - 1)['comment'] if comment == None: comment = '' else: comment = ': ' + comment self.possible_values.append(value + comment) i += 1 self.possible_values.append('Manual Value') self.select_value_combobox.configure(values=self.possible_values) self.select_value_combobox.current(0) self.possible_values_frame.pack(side='top') else: self.generic_value_entery.delete(0, 'end') self.generic_value_frame.pack(side='top')
def on_ranged_save_event(self): """On ranged value add or edit 'Save' button is pressed""" min = self.ranged_value_min_entry.get() max = self.ranged_value_max_entry.get() step = self.ranged_value_step_entry.get() comment = self.ranged_value_comment_entry.get() file_value = get.possible_value_by_number( self.current_path, self.current_option_name, self.option_values_list_combobox.current( )) # Value which is currently saved if min == max == step == '': tk.messagebox.showerror(title='Error', message="All fields cannot be empty") elif ( ((self.is_value_new) or (file_value['min'] != min or file_value['max'] != max or file_value['step'] != step)) and (check.option_renage_value_exists( self.current_path, self.current_option_name, min, max, step))): tk.messagebox.showerror(title='Error', message="This range already exists") else: if self.is_value_new: response = common.add_range_value(self.current_path, self.current_option_name, min, max, step, comment) if response == 200: self.ranged_value_min_entry.delete(0, tk.END) self.ranged_value_max_entry.delete(0, tk.END) self.ranged_value_step_entry.delete(0, tk.END) self.ranged_value_comment_entry.delete(0, tk.END) tk.messagebox.showinfo(title='Success', message="Range saved successfully") else: tk.messagebox.showerror( title='Faild', message="Range failed to save unexpectedly") else: response_1 = common.set_value_comment_by_number( self.current_path, self.current_option_name, self.option_values_list_combobox.current(), comment) response_2 = response = common.set_ranged_possible_value_by_number( self.current_path, self.current_option_name, self.option_values_list_combobox.current(), min, max, step) if response_1 == 200 and response_2 == 200: tk.messagebox.showinfo(title='Success', message="Range saved successfully") else: tk.messagebox.showerror( title='Faild', message="Failed to save unexpectedly")
def select_possible_value_event(self): self.possible_values_frame.pack_forget() if self.select_value_combobox.current() == len( self.possible_values) - 1: self.generic_value_entery.delete(0, 'end') self.generic_value_frame.pack(side='top') else: path = self.file_combobox.get() option = get.option_names_in_file(path)[ self.select_setting_combobox.current()] value = get.possible_value_by_number( path, option, self.select_value_combobox.current()) if 'min' in value: # Check if value is ranged self.numeric_value_spinbox.delete(0, 'end') min = max = step = initial = 0 style = '' if value['min'] == None or value['min'] == '': min = -sys.maxsize else: initial = min = float(value['min']) if value['max'] == None or value['max'] == '': max = sys.maxsize else: max = float(value['max']) if value['step'] == None or value['step'] == '': step = 1 else: step = float(value['step']) style = '% ' + str(len(str(step).split('.')[1])) + 'f' self.numeric_value_spinbox.configure(from_=min, to=max, format=style, increment=step) self.numeric_value_spinbox.set(initial) self.numeric_value_frame.pack(side='top') elif 'name' in value: # Value is a single choice response = set.option_value(path, option, value['name']) if response == 200: self.switch_to_before_set_value() elif response == 701: tk.messagebox.showwarning(title="Error", message="701 Error")
def on_value_edit_event(self): self.is_value_new = False value = get.possible_value_by_number( self.current_path, self.current_option_name, self.option_values_list_combobox.current()) if value['comment'] == None: value['comment'] = '' if 'min' in value: #Check if value is ranged self.switch_to_ranged_values(min=value['min'], max=value['max'], step=value['step'], comment=value['comment']) elif 'name' in value: self.switch_to_simple_values(value=value['name'], comment=value['comment'])
break elif choice.isdecimal(): choice = int(choice) if choice < 1 or choice > len(option_list): print('\nNumber is not in range!\n') else: option_name = option_list[choice-1] if has_dot_xml: print('\nPossible values are: ', end ="" ) i = 1 for value in get.option_values(path, option_name): comment = get.possible_value_by_number(path, option_name, i-1)['comment'] if comment == None: comment = '' else: comment = ': ' + comment print(str(i) + '. ' + value + comment, end =", " ) i += 1 print(str(i) + '.Manual value') number_of_values = len(get.option_values(path, option_name)) while True: choice = input('\nEnter the number of value you want to set (1 to ' + str( number_of_values + 1) + ', 0 to get back): ').strip()
def edit(path_to_dot_setting): path = path_to_dot_setting print('\nThis file contains these options: ' + str(get.option_names_in_file(path))) while True: choice = input( "\nEnter '1' to edit a option\nEnter '2' to add a new option\n" "Enter '3' to remove a option\nEnter '4' to see the list of options in current file\n" "Enter '5' to set description for this file\nEnter 0 to get back\n\n->" ).strip() if choice == '0' or choice == '': break elif choice == '1': while True: name = input('Enter the option name: ').strip() name_check = check.option_name(name) if name_check == 701: print("\nName must not contain ':'\n") elif name_check == 702: print("\nName must not contain ','\n") elif name_check == 700: break elif name_check == 703: print("\nName cannot start with '#'\n") elif name_check == 704: print("\nError: Name includes new line\n") elif name_check != 200: print("\nUnspecified Error\n") elif not check.option_exists_in_file(path, name): print('\nOption not found!\n') else: while True: choice = input( "\nEnter '1' to change option name\nEnter '2' to change default value\n" "Enter '3' to change comment\nEnter '4' to manage possible values for this option\n" "Enter 0 to get back\n\n->").strip() if choice == '0' or choice == '': break elif choice == '1': while True: new_name = input( 'Enter new option name: ').strip() name_check = check.option_name(new_name) if name_check == 701: print("\nName must not contain ':'\n") elif name_check == 702: print("\nName must not contain ','\n") elif name_check == 703: print("\nName cannot start with '#'\n") elif name_check == 704: print("\nError: Name includes new line\n") elif name_check == 700: break elif name_check != 200: print("\nUnspecified Error\n") elif check.option_exists_in_file( path, new_name): print( '\nThis option name already exists!\n') else: response = common.change_option_name( path, name, new_name) if response == 200: print('\nName changed successfully.\n') elif response == 201: print( '\nName changed successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n' ) break elif choice == '2': while True: value = input('Enter default value: ').strip() check_value = check.general_value(value) if check_value == 700: print("\nValue must not contain ','\n") elif check_value == 701: print("\nError: Value includes new line\n") elif check_value != 200: print("\nUnspecified Error\n") elif value == '': break else: response = set.default(path, name, value) if response == 200: print( '\nDefault value set successfully.\n' ) elif response == 201: print( '\nDefault value set successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n' ) break elif choice == '3': while True: comment = input('Enter the comment: ').strip() if '\n' in comment: print( "\nError: Comment includes new line\n") elif comment == '': break else: response = set.option_comment( path, name, comment) if response == 200: print('\nComment set successfully.\n') elif response == 201: print( '\nComment set successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n' ) break elif choice == '4': show_option_values(path, name) while True: choice = input( "\nEnter '1' to add a value\nEnter '2' to edit a value\n" "Enter '3' to remove a value\nEnter '4' to see a list of current values\n" "Enter 0 to get back\n\n->").strip() if choice == '0' or choice == '': break elif choice == '1': while True: choice = input( "\nEnter '1' for simple value\nEnter '2' for number range value\n" "Enter 0 to get back\n\n->") if choice == '0' or choice == '': break elif choice == '1': while True: value = input( 'Enter the value: ').strip( ) check_value = check.general_value( value) if check_value == 700: print( "\nValue must not contain ','\n" ) elif check_value == 701: print( "\nError: Value includes new line\n" ) elif check_value != 200: print( "\nUnspecified Error\n" ) elif value == '': break elif check.option_simple_value_exists( path, name, value): print( '\nThis value already exists!\n' ) else: while True: comment = input( 'Enter the single line comment for option: ' ).strip() if '\n' in comment: print( "\nError: Comment includes new line\n" ) else: response = common.add_simple_value( path, name, value, comment) if response == 200: print( '\nValue added successfully\n' ) else: print( '\nSome error occured\n' ) break break elif choice == '2': while True: min = input( 'Enter the minimum (Enter nothing to skip): ' ).strip() if min == '': break try: float(min) break except: print( '\n' + min + ' is not a number!\n') while True: max = input( 'Enter the maximum (Enter nothing to skip): ' ).strip() if max == '': break try: float(max) break except: print( '\n' + max + ' is not a number!\n') while True: step = input( 'Enter the step (Enter nothing to skip): ' ).strip() if step == '': break try: float(step) break except: print( '\n' + step + ' is not a number!\n') if min == max == step == '': continue elif check.option_renage_value_exists( path, name, min, max, step): print( '\nThis range is already added!\n' ) else: while True: comment = input( 'Enter the single line comment for option: ' ).strip() if '\n' in comment: print( "\nError: Comment includes new line\n" ) else: response = common.add_range_value( path, name, min, max, step, comment) if response == 200: print( '\nRange added successfully\n' ) else: print( '\nSome error occured\n' ) break else: print('\nCommand not found!\n') elif choice == '2': number_of_values = len( get.option_values(path, name)) if number_of_values == 0: print('\nOption has no values\n') else: choice = input( '\nEnter the number of value you want to edit (1 to ' + str(number_of_values) + '): ').strip() if choice.isdecimal(): choice = int(choice) if choice < 1 or choice > number_of_values: print( '\nNumber is not in range\n' ) else: while True: action = input( "\nEnter '1' set comment\nEnter '2' edit value\n" "Enter 0 to get back\n\n->" ) if action == '0' or action == '': break elif action == '1': while True: comment = input( 'Enter the single line comment for option: ' ).strip() if '\n' in comment: print( "\nError: Comment includes new line\n" ) else: response = common.set_value_comment_by_number( path, name, choice - 1, comment) if response == 200: print( '\nCommented is set\n' ) else: print( '\nSome error occured\n' ) break elif action == '2': value = get.possible_value_by_number( path, name, choice - 1) if 'min' in value: #Check if value is ranged while True: action = input( "\nEnter '1' to set min\nEnter '2' to set max\nEnter '3' to set step\n" "Enter 0 to get back\n\n->" ).strip() if action == '0' or action == '': break elif action == '1': while True: min = input( 'Enter the min (Enter nothing for empty): ' ).strip( ) if min != '': try: float( min ) except: print( '\n' + min + ' is not a number!\n' ) continue if min == value[ 'max'] == value[ 'step'] == '': print( '\nCannot have min, max and step empty\n' ) elif check.option_renage_value_exists( path, name, min, value[ 'max'], value[ 'step'] ): print( '\nThis range is already added!\n' ) else: response = common.set_ranged_possible_value_by_number( path, name, choice - 1, min, value[ 'max'], value[ 'step'] ) if response == 200: print( '\nValue is set\n' ) else: print( '\nSome error occured\n' ) break break elif action == '2': while True: max = input( 'Enter the max (Enter nothing for empty): ' ).strip( ) if max != '': try: float( max ) except: print( '\n' + max + ' is not a number!\n' ) continue if value['min'] == max == value[ 'step'] == '': print( '\nCannot have min, max and step empty\n' ) elif check.option_renage_value_exists( path, name, value[ 'min'], max, value[ 'step'] ): print( '\nThis range is already added!\n' ) else: response = common.set_ranged_possible_value_by_number( path, name, choice - 1, value[ 'min'], max, value[ 'step'] ) if response == 200: print( '\nValue is set\n' ) else: print( '\nSome error occured\n' ) break break elif action == '3': while True: step = input( 'Enter the step (Enter nothing for empty): ' ).strip( ) if step != '': try: float( step ) except: print( '\n' + step + ' is not a number!\n' ) continue if value['min'] == value[ 'max'] == step == '': print( '\nCannot have min, max and step empty\n' ) elif check.option_renage_value_exists( path, name, value[ 'min'], value[ 'max'], step ): print( '\nThis range is already added!\n' ) else: response = common.set_ranged_possible_value_by_number( path, name, choice - 1, value[ 'min'], value[ 'max'], step ) if response == 200: print( '\nValue is set\n' ) else: print( '\nSome error occured\n' ) break break else: print( '\nCommand not found!\n' ) elif 'name' in value: while True: value = input( 'Enter the new value: ' ).strip() check_value = check.general_value( value) if check_value == 700: print( "\nValue must not contain ','\n" ) elif check_value == 701: print( "\nError: Value includes new line\n" ) elif check_value != 200: print( "\nUnspecified Error\n" ) elif value == '': break elif check.option_simple_value_exists( path, name, value): print( '\nThis value already exists!\n' ) else: response = common.set_simple_possible_value_by_number( path, name, choice - 1, value) if response == 200: print( '\nName has changed\n' ) else: print( '\nSome error occured\n' ) break break else: print( '\nCommand not found!\n' ) else: print('\nInput must be a number\n') elif choice == '3': number_of_values = len( get.option_values(path, name)) if number_of_values == 0: print('\nOption has no values\n') else: choice = input( '\nEnter the number of value you want to be removed (1 to ' + str(number_of_values) + '): ').strip() if choice.isdecimal(): choice = int(choice) if choice < 1 or choice > number_of_values: print( '\nNumber is not in range\n' ) else: common.remove_possible_value_by_number( path, name, choice - 1) print( '\nValue removed successfully\n' ) else: print('\nInput must be a number\n') elif choice == '4': show_option_values(path, name) else: print('\nCommand not found!\n') else: print('\nCommand not found!\n') break elif choice == '2': while True: name = input('Enter the option name: ').strip() name_check = check.option_name(name) if name_check == 701: print("\nName must not contain ':'\n") elif name_check == 702: print("\nName must not contain ','\n") elif name_check == 700: break elif name_check == 703: print("\nName cannot start with '#'\n") elif name_check == 704: print("\nError: Name includes new line\n") elif name_check != 200: print("\nUnspecified Error\n") elif check.option_exists_in_file(path, name): print('\nThis option name already exists!\n') else: while True: comment = input( 'Enter the single line comment for option: ' ).strip() if '\n' in comment: print("\nError: Comment includes new line\n") else: response = common.add_option_to_file( path, name, comment) if response == 200: print('\nOption created successfully\n') elif response == 201: print( '\nCaution: Option created successfully! Definition for option ' + name + ' already exists in setting.xml file\n') break break elif choice == '3': while True: name = input('Enter the option name: ').strip() name_check = check.option_name(name) if name_check == 701: print("\nName must not contain ':'\n") elif name_check == 702: print("\nName must not contain ','\n") elif name_check == 700: break elif name_check == 703: print("\nName cannot start with '#'\n") elif name_check == 704: print("\nError: Name includes new line\n") elif name_check != 200: print("\nUnspecified Error\n") elif not check.option_exists_in_file(path, name): print('\nOption with this name does not exist!\n') else: response = common.remove_option_from_file(path, name) if response == 200: print('\nOption removed successfully\n') elif response == 201: print( "\nCaution: Option removed successfully but Option '" + name + "' didn't exist in setting.xml file.\n" "It causes no problem in removing but means that your .setting.xml was corrupted.\n" ) break elif choice == '4': print('\nThis file contains these options: ' + str(get.option_names_in_file(path))) elif choice == '5': description = cli.get_multiline_input( '\nEnter any description you may have for this file') if description != '': set.file_description(path, description) print('\nDescription changed successfully\n') else: print('\nCommand not found!\n')
def on_simple_save_event(self): """On simple value add or edit 'Save' button is pressed""" value = self.simple_value_value_entry.get() if value == '': tk.messagebox.showerror(title='Error', message="Value cannot be empty") else: check_value = check.general_value(value) if check_value == 700: tk.messagebox.showerror(title='Error', message="Value must not contain ','") elif check_value == 701: tk.messagebox.showerror( title='Error', message="Error: Value includes new line") elif check_value != 200: tk.messagebox.showerror(title='Error', message="Unspecified Value Error") elif (((self.is_value_new) or (get.possible_value_by_number( self.current_path, self.current_option_name, self.option_values_list_combobox.current())['name'] != value)) and (check.option_simple_value_exists( self.current_path, self.current_option_name, value))): tk.messagebox.showerror(title='Error', message="This value already exists") else: comment = self.simple_value_comment_entry.get() if self.is_value_new: response = common.add_simple_value( self.current_path, self.current_option_name, value, comment) if response == 200: self.simple_value_value_entry.delete(0, tk.END) self.simple_value_comment_entry.delete(0, tk.END) tk.messagebox.showinfo( title='Success', message="Value saved successfully") else: tk.messagebox.showerror( title='Faild', message="Value failed to save unexpectedly") else: response_1 = common.set_value_comment_by_number( self.current_path, self.current_option_name, self.option_values_list_combobox.current(), comment) response_2 = common.set_simple_possible_value_by_number( self.current_path, self.current_option_name, self.option_values_list_combobox.current(), value) if response_1 == 200 and response_2 == 200: tk.messagebox.showinfo( title='Success', message="Value saved successfully") else: tk.messagebox.showerror( title='Faild', message="Failed to save unexpectedly")