Skip to content

Commit

Permalink
7/30 Highlight Column Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
FLwolfy committed Jul 30, 2024
1 parent 2d8f677 commit 31bb723
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
42 changes: 32 additions & 10 deletions UI/UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def create_interval_frame(self):

result_listbox = tk.Listbox(result_frame, yscrollcommand=scrollbar_y.set, selectmode=tk.SINGLE)
result_listbox.pack(side="left", fill="both", expand=True)
result_listbox.bind("<<ListboxSelect>>", self.show_options)
result_listbox.bind("<<ListboxSelect>>", self.show_options_color)

self.widgets["columns"] = result_listbox
scrollbar_y.config(command=result_listbox.yview)
Expand Down Expand Up @@ -320,11 +320,12 @@ def option_event(self, name: str):
Parameters:
- name (str): Name of the column option.
"""
try:
options_state = self.generator.option_list[self.widgets["columns"].get(self.widgets["columns"].curselection())]
except:
selection = self.widgets["columns"].curselection()
if selection:
options_state = self.generator.option_list[self.widgets["columns"].get(selection)]
else:
return

if name == "Remove Spaces":
options_state.remove_spaces = not options_state.remove_spaces
elif name == "Remove Extention":
Expand All @@ -336,37 +337,54 @@ def option_event(self, name: str):
options_state.number_to_string = not options_state.number_to_string
options_state.string_to_number = False

self.show_options()
self.show_options_color()

def show_options(self, event=None):
def show_options_color(self, event=None):
"""
Show the current state of column options.
"""
try:
options_state = self.generator.option_list[self.widgets["columns"].get(self.widgets["columns"].curselection())]
except:
selection = self.widgets["columns"].curselection()
if selection:
selected_index = selection[0]
options_state = self.generator.option_list[self.widgets["columns"].get(selection)]
else:
return

options_count = 0

if options_state.remove_spaces:
self.widgets["options"]["Remove Spaces"].config(fg="red")
options_count += 1
else:
self.widgets["options"]["Remove Spaces"].config(fg="black")

if options_state.remove_ext_name:
self.widgets["options"]["Remove Extention"].config(fg="red")
options_count += 1
else:
self.widgets["options"]["Remove Extention"].config(fg="black")

if options_state.string_to_number:
self.widgets["options"]["String to Number"].config(fg="red")
options_count += 1
else:
self.widgets["options"]["String to Number"].config(fg="black")

if options_state.number_to_string:
self.widgets["options"]["Number to String"].config(fg="red")
options_count += 1
else:
self.widgets["options"]["Number to String"].config(fg="black")

if options_count > 0:
self.widgets["columns"].itemconfig(selected_index, {'fg': 'red'})
elif self.widgets["columns"].itemcget(selected_index, 'fg') == 'red':
col_text = self.widgets["columns"].get(selected_index)
self.widgets["columns"].delete(selected_index)
self.widgets["columns"].insert(selected_index, col_text)
self.widgets["columns"].selection_set(selected_index)
self.widgets["columns"].activate(selected_index)


def browse(self, entry_widget:tk.Entry, kind: str = ""):
"""
Expand Down Expand Up @@ -422,6 +440,10 @@ def import_all(self):

if json_path != "":
self.generator.import_template(json_path)

# Clear Options Color
for button in self.widgets["options"].values():
button.config(fg="black")

def run(self):
"""
Expand Down
12 changes: 6 additions & 6 deletions utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __process_list(list_string: str):
try:
items[i] = float(item)
except ValueError:
items[i] = item.strip('\'"')
items[i] = item.strip('\'" ')

return items

Expand All @@ -39,13 +39,9 @@ def __process_column(dataset: list[dict], column: str, opt: Options) -> list[dic
processed_dataset = copy.deepcopy(dataset)

for row in range(len(processed_dataset)):
## process list
if type(processed_dataset[row][column]) is str:
processed_dataset[row][column] = __process_list(processed_dataset[row][column])

## process options
if opt.remove_spaces:
processed_dataset[row][column] = str(processed_dataset[row][column]).strip()
processed_dataset[row][column] = str(processed_dataset[row][column]).replace("\t", "").replace(" ", "")

if opt.remove_ext_name:
processed_dataset[row][column] = os.path.splitext(processed_dataset[row][column])[0]
Expand All @@ -59,6 +55,10 @@ def __process_column(dataset: list[dict], column: str, opt: Options) -> list[dic
# if opt.expression is not None:
# processed_dataset[row][column] = eval(processed_dataset[row][column], {'x': x})

## process list
if type(processed_dataset[row][column]) is str:
processed_dataset[row][column] = __process_list(processed_dataset[row][column])

return processed_dataset


Expand Down

0 comments on commit 31bb723

Please sign in to comment.