def submit_generic_value(self): value = self.generic_value_entery.get() check_value = check.general_value(value) if check_value == 700: tk.messagebox.showwarning(title='Bad Input', message="Value must not contain ','") elif check_value == 701: tk.messagebox.showwarning(title='Bad Input', message="Error: Value includes new line") elif check_value != 200: tk.messagebox.showwarning(title="Unspecified Error", message="Unspecified Error") else: path = self.file_combobox.get() option = get.option_names_in_file(path)[ self.select_setting_combobox.current()] response = set.option_value(path, option, value) if response == 200: self.switch_to_before_set_value() elif response == 701: tk.messagebox.showwarning(title="Error", message="701 Error")
choice = input('\nEnter the number of value you want to set (1 to ' + str( number_of_values + 1) + ', 0 to get back): ').strip() if choice == '0' or choice == '': break elif not choice.isdecimal(): print('\nInput must be a number\n') elif int(choice) < 1 or int(choice) > number_of_values + 1: print('\nNumber is not in range\n') else: choice = int(choice) if choice == number_of_values + 1: # Manual Value Chosen 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 else: response = set.option_value(path, option_name, value) if response == 200: print('\nValue set successfully.\n') elif response == 701:
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 new_option_save_event(self): error_list = '' success_list = '' new_name = self.new_option_name_entry.get() name_check = check.option_name(new_name) if name_check == 701: error_list += "Option name must not contain ':'\n" elif name_check == 702: error_list += "Option name must not contain ','\n" elif name_check == 703: error_list += "Option name cannot start with '#'\n" elif name_check == 704: error_list += "Error: Option name includes new line\n" elif name_check == 700: error_list += 'Option name cannot be empty!\n' elif name_check != 200: error_list += 'Unspecified Option Name Error\n' elif check.option_exists_in_file(self.current_path, new_name): error_list += 'This option name already exists!\n' else: comment = self.new_option_comment_entry.get() if '\n' in comment: error_list += 'Error: Comment includes new line\n' comment = '' response = common.add_option_to_file(self.current_path, new_name, comment) if response == 200: success_list += 'Option created successfully\n' elif response == 201: error_list += 'Caution: Option created successfully! Definition for option ' + new_name + ' already exists in setting.xml file\n' options_list = get.option_names_in_file(self.current_path) self.edit_file_list_combobox.config(state="normal") self.edit_file_edit_button.config(state="normal") self.edit_file_remove_button.config(state="normal") self.edit_file_list_combobox.configure(values=options_list) self.edit_file_list_combobox.current(len(options_list) - 1) new_default = self.new_option_default_value_entry.get() check_value = check.general_value(new_default) if check_value == 700: error_list += "Default must not contain ','\n" elif check_value == 701: error_list += "Error: Default includes new line\n" elif check_value != 200: error_list += 'Unspecified Default Error\n' else: response = set.default(self.current_path, new_name, new_default) if success_list != '': tk.messagebox.showinfo(title='Created Successfully', message=success_list) if error_list != '': tk.messagebox.showerror(title='Error', message=error_list) if success_list != '': self.switch_to_edit_option()
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")
def edit_option_save_event(self): error_list = '' success_list = '' new_name = self.edit_option_name_entry.get() if new_name != self.current_option_name: name_check = check.option_name(new_name) if name_check == 701: error_list += "Option name must not contain ':'\n" elif name_check == 702: error_list += "Option name must not contain ','\n" elif name_check == 703: error_list += "Option name cannot start with '#'\n" elif name_check == 704: error_list += "Error: Option name includes new line\n" elif name_check == 700: error_list += 'Option name cannot be empty!\n' elif name_check != 200: error_list += 'Unspecified Option Name Error\n' elif check.option_exists_in_file(self.current_path, new_name): error_list += 'This option name already exists!\n' else: response = common.change_option_name(self.current_path, self.current_option_name, new_name) if response == 200: self.current_option_name = self.edit_option_name_entry.get( ) success_list += 'Name changed successfully\n' else: error_list += 'Name changed successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n' new_default = self.edit_option_default_value_entry.get() if get.default_value(self.current_path, self.current_option_name) != new_default: check_value = check.general_value(new_default) if check_value == 700: error_list += "Default must not contain ','\n" elif check_value == 701: error_list += "Error: Default includes new line\n" elif check_value != 200: error_list += 'Unspecified Default Error\n' else: response = set.default(self.current_path, self.current_option_name, new_default) if response == 200: success_list += 'Default changed successfully\n' elif response == 201: error_list += 'Default changed successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n' comment = self.edit_option_comment_entry.get() if comment != get.option_comment(self.current_path, self.current_option_name): if '\n' in comment: error_list += 'Error: Comment includes new line\n' else: response = set.option_comment(self.current_path, self.current_option_name, comment) if response == 200: success_list += 'Comment changed successfully\n' elif response == 201: error_list += 'Comment changed successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n' if success_list != '': tk.messagebox.showinfo(title='Saved Successfully', message=success_list) if error_list != '': tk.messagebox.showerror(title='Error', message=error_list)