Skip to content

Commit

Permalink
checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed Jul 30, 2024
1 parent ea03ec0 commit bb40785
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 160 deletions.
Binary file added simba/assets/icons/counter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simba/assets/icons/finish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simba/assets/icons/green_check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simba/assets/icons/hierarchy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simba/assets/icons/plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simba/assets/icons/segment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simba/assets/icons/table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simba/assets/icons/timer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions simba/mixins/pop_up_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,8 @@ def create_dropdown_frame(self,
def create_time_bin_entry(self):
if hasattr(self, "time_bin_frm"):
self.time_bin_frm.destroy()
self.time_bin_frm = LabelFrame(
self.main_frm, text="TIME BIN", font=Formats.FONT_HEADER.value
)
self.time_bin_entrybox = Entry_Box(
self.time_bin_frm, "Time-bin size (s): ", "12"
)
self.time_bin_frm = LabelFrame(self.main_frm, text="TIME BIN", font=Formats.FONT_HEADER.value)
self.time_bin_entrybox = Entry_Box(self.time_bin_frm, "TIME-BIN SIZE (S): ", "15")
self.time_bin_entrybox.grid(row=0, column=0, sticky=NW)
self.time_bin_frm.grid(row=self.children_cnt_main(), column=0, sticky=NW)

Expand Down Expand Up @@ -348,7 +344,7 @@ def children_cnt_main(self) -> int:

return int(len(list(self.main_frm.children.keys())))

def frame_children(self, frame: Frame) -> int:
def frame_children(self, frame: Union[Frame, Toplevel, Canvas, LabelFrame]) -> int:
"""
Find the number of children (e.g., labelframes) currently exist within specified frame.Similar to ``children_cnt_main``,
but accepts a specific frame rather than the main frame beeing hardcoded.
Expand Down
46 changes: 21 additions & 25 deletions simba/roi_tools/ROI_define.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def apply_rois_from_other_video(self):

def apply_from_other_videos_menu(self):
self.get_other_videos_w_data()
self.apply_from_other_video = LabelFrame( self.master, text="Apply shapes from another video", font=("Arial", 16, "bold"), padx=5, pady=5)
self.select_video_label = Label(self.apply_from_other_video, text="Select video: ").grid(row=1, column=0)
self.apply_from_other_video = LabelFrame( self.master, text="APPLY SHAPES FROM ANOTHER VIDEO", font=Formats.FONT_HEADER.value, padx=5, pady=5)
self.select_video_label = Label(self.apply_from_other_video, text="SELECT VIDEO: ", font=Formats.FONT_REGULAR.value).grid(row=1, column=0)
self.selected_other_video = StringVar()
self.selected_other_video.set(self.other_videos_w_ROIs[0])
self.video_dropdown = OptionMenu(self.apply_from_other_video, self.selected_other_video, *self.other_videos_w_ROIs)
Expand All @@ -255,8 +255,8 @@ def apply_from_other_videos_menu(self):
self.apply_button.grid(row=1, column=3, sticky=W, pady=10)

def select_shape(self):
self.new_shape_frame = LabelFrame(self.master, text="New shape", font=("Arial", 16, "bold"), padx=5, pady=5, bd=5)
self.shape_frame = LabelFrame(self.new_shape_frame, text="Shape type", font=("Arial", 14, "bold"), padx=5, pady=5)
self.new_shape_frame = LabelFrame(self.master, text="NEW SHAPE", font=Formats.FONT_HEADER.value, padx=5, pady=5, bd=5)
self.shape_frame = LabelFrame(self.new_shape_frame, text="SHAPE TYPE", font=Formats.FONT_REGULAR.value, padx=5, pady=5)

self.rectangle_button = SimbaButton(parent=self.shape_frame, txt='RECTANGLE', txt_clr=self.non_select_color, font=Formats.FONT_REGULAR.value, img='rectangle', cmd=self.set_current_shape, cmd_kwargs={'c_shape': lambda: "rectangle"})
self.circle_button = SimbaButton(parent=self.shape_frame, txt='CIRCLE', txt_clr=self.non_select_color, font=Formats.FONT_REGULAR.value, img='circle_2', cmd=self.set_current_shape, cmd_kwargs={'c_shape': lambda: "circle"})
Expand All @@ -268,16 +268,16 @@ def select_shape(self):
self.polygon_button.grid(row=1, column=2, sticky=W, pady=10, padx=10)

def select_shape_attr(self):
self.shape_attr_frame = LabelFrame(self.new_shape_frame, text="Shape attributes", font=("Arial", 16, "bold"), padx=5, pady=5)
self.shape_attr_frame = LabelFrame(self.new_shape_frame, text="SHAPE ATTRIBUTES", font=Formats.FONT_HEADER.value, padx=5, pady=5)
self.shape_attr_frame.grid_configure(ipadx=50)
self.thickness_label = Label(self.shape_attr_frame, text="Shape thickness: ")
self.color_label = Label(self.shape_attr_frame, text="Shape color: ")
self.thickness_label = Label(self.shape_attr_frame, text="SHAPE THICKNESS: ", font=Formats.FONT_REGULAR.value)
self.color_label = Label(self.shape_attr_frame, text="SHAPE COLOR: ", font=Formats.FONT_REGULAR.value)
self.shape_thickness = IntVar()
self.shape_thickness.set(5)
self.shape_thickness_dropdown = OptionMenu(self.shape_attr_frame, self.shape_thickness, *self.shape_thickness_list, command=None)
self.shape_thickness_dropdown.config(width=3)

self.ear_tag_sizes_lbl = Label(self.shape_attr_frame, text="Ear tag size: ")
self.ear_tag_sizes_lbl = Label(self.shape_attr_frame, text="EAR TAG SIZE: ", font=Formats.FONT_REGULAR.value)
self.ear_tag_size = IntVar()
self.ear_tag_size.set(10)
self.ear_tag_size_dropdown = OptionMenu(self.shape_attr_frame, self.ear_tag_size, *list(self.ear_tag_size_list))
Expand All @@ -295,15 +295,15 @@ def select_shape_attr(self):
self.color_dropdown.grid(row=1, column=5, sticky=W, pady=10)

def select_shape_name(self):
self.set_shape_name = LabelFrame(self.new_shape_frame, text="Shape name", font=("Arial", 16, "bold"), padx=5, pady=5)
self.set_shape_name = LabelFrame(self.new_shape_frame, text="SHAPE NAME", font=Formats.FONT_HEADER.value, padx=5, pady=5)
self.set_shape_name.grid_configure(ipadx=105)
self.name_label = Label(self.set_shape_name, text="Shape name: ").grid(row=1, column=0)
self.name_label = Label(self.set_shape_name, text="SHAPE NAME: ", font=Formats.FONT_REGULAR.value).grid(row=1, column=0)
self.name_box = Entry(self.set_shape_name, width=55)
self.set_shape_name.grid(row=3, sticky=W, pady=10)
self.name_box.grid(row=1, column=2, sticky=W, pady=10)

def interact_menus(self):
self.interact_frame = LabelFrame(self.master, text="Shape interaction", font=Formats.FONT_HEADER.value, padx=5, pady=5)
self.interact_frame = LabelFrame(self.master, text="SHAPE INTERACTION", font=Formats.FONT_HEADER.value, padx=5, pady=5)
self.interact_frame.grid_configure(ipadx=30)


Expand Down Expand Up @@ -345,7 +345,7 @@ def draw_menu(self):
self.draw_button = SimbaButton(parent=self.draw_frame, txt='DRAW', img='paint', txt_clr=self.non_select_color, cmd=self.create_draw)
self.delete_all_rois_btn = SimbaButton(parent=self.draw_frame, txt='DELETE ALL', img='trash', txt_clr=self.non_select_color, cmd=self.call_delete_all_rois)

self.select_roi_label = Label(self.draw_frame, text="Select ROI: ", font=Formats.FONT_REGULAR.value)
self.select_roi_label = Label(self.draw_frame, text="SELECT ROI: ", font=Formats.FONT_REGULAR.value)
self.selected_video = StringVar()
self.selected_video.set(self.video_ROIs[0])
self.roi_dropdown = OptionMenu(self.draw_frame, self.selected_video, *self.video_ROIs)
Expand Down Expand Up @@ -408,8 +408,8 @@ def show_shape_information(self):
self.image_data.insert_all_ROIs_into_image()

def save_menu(self):
self.save_frame = LabelFrame(self.master, text="Save", font=("Arial", 16, "bold"), padx=5, pady=5)
self.save_button = SimbaButton(parent=self.save_frame, txt="Save ROI data", img='save', txt_clr=self.non_select_color, cmd=self.save_data)
self.save_frame = LabelFrame(self.master, text="SAVE", font=Formats.FONT_HEADER.value, padx=5, pady=5)
self.save_button = SimbaButton(parent=self.save_frame, txt="SAVE ROI DATA", img='save', txt_clr=self.non_select_color, cmd=self.save_data)
self.save_frame.grid(row=8, sticky=W)
self.save_button.grid(row=1, column=3, sticky=W, pady=10)

Expand Down Expand Up @@ -880,13 +880,13 @@ def __init__(self, image_data):
padx=5,
fg="black",
)
line_type_label = Label(pref_lbl_frame, text="Shape line type: ")
text_size_label = Label(pref_lbl_frame, text="Text size: ")
text_thickness_label = Label(pref_lbl_frame, text="Text thickness: ")
line_type_label = Label(pref_lbl_frame, text="SHAPE LINE TYPE: ", font=Formats.FONT_REGULAR.value)
text_size_label = Label(pref_lbl_frame, text="TEXT SIZE: ",font=Formats.FONT_REGULAR.value)
text_thickness_label = Label(pref_lbl_frame, text="TEXT THICKNESS: ", font=Formats.FONT_REGULAR.value)
line_type_list = [4, 8, 16, -1]
text_size_list = list(range(1, 20))
text_thickness_list = list(range(1, 15))
click_sensitivity_lbl = Label(pref_lbl_frame, text="Mouse click sensitivity: ")
click_sensitivity_lbl = Label(pref_lbl_frame, text="MOUSE CLICK SENSITIVITY (PIXELS): ", font=Formats.FONT_REGULAR.value)
click_sensitivity_list = list(range(1, 50, 5))
self.click_sens = IntVar()
self.line_type = IntVar()
Expand All @@ -896,14 +896,12 @@ def __init__(self, image_data):
self.text_size.set(text_size_list[0])
self.click_sens.set(click_sensitivity_list[0])
line_type_dropdown = OptionMenu(pref_lbl_frame, self.line_type, *line_type_list)
text_thickness_dropdown = OptionMenu(
pref_lbl_frame, self.text_thickness, *text_thickness_list
)
text_thickness_dropdown = OptionMenu(pref_lbl_frame, self.text_thickness, *text_thickness_list)
text_size_dropdown = OptionMenu(pref_lbl_frame, self.text_size, *text_size_list)
click_sens_dropdown = OptionMenu(
pref_lbl_frame, self.click_sens, *click_sensitivity_list
)
duplicate_jump_size_lbl = Label(pref_lbl_frame, text="Duplicate shape jump: ")
duplicate_jump_size_lbl = Label(pref_lbl_frame, text="DUPLICATE SHAPE JUMP: ", font=Formats.FONT_REGULAR.value)
duplicate_jump_size_list = list(range(1, 100, 5))
self.duplicate_jump_size = IntVar()
self.duplicate_jump_size.set(20)
Expand All @@ -929,9 +927,7 @@ def save_prefs(self, image_data):
image_data.text_thickness = self.text_thickness.get()
image_data.line_type = self.line_type.get()
image_data.duplicate_jump_size = self.duplicate_jump_size.get()
stdout_success(
msg="Saved ROI preference settings.", source=self.__class__.__name__
)
stdout_success(msg="Saved ROI preference settings.", source=self.__class__.__name__)


# test = ROI_definitions(config_path='/Users/simon/Desktop/envs/simba/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini',
Expand Down
30 changes: 17 additions & 13 deletions simba/ui/pop_ups/animal_directing_other_animals_pop_up.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
import os
from tkinter import *
from typing import Union

from simba.data_processors.directing_other_animals_calculator import \
DirectingOtherAnimalsAnalyzer
from simba.data_processors.directing_other_animals_calculator import DirectingOtherAnimalsAnalyzer
from simba.mixins.config_reader import ConfigReader
from simba.mixins.pop_up_mixin import PopUpMixin
from simba.ui.tkinter_functions import CreateLabelFrameWithIcon
from simba.ui.tkinter_functions import CreateLabelFrameWithIcon,SimbaCheckbox
from simba.utils.enums import Formats, Keys, Links
from simba.utils.errors import (AnimalNumberError, InvalidInputError,
NoFilesFoundError)
from simba.utils.errors import (AnimalNumberError, InvalidInputError, NoFilesFoundError)


class AnimalDirectingAnimalPopUp(ConfigReader, PopUpMixin):
def __init__(self, config_path: str):

"""
:example:
>>> test = AnimalDirectingAnimalPopUp(config_path=r"C:\troubleshooting\two_black_animals_14bp\project_folder\project_config.ini")
"""
def __init__(self, config_path: Union[str, os.PathLike]):
ConfigReader.__init__(self, config_path=config_path)
if self.animal_cnt < 2:
raise AnimalNumberError(msg=f"Directionality between animals require at least two animals. The SimBA project is set to use {self.animal_cnt} animal.", source=self.__class__.__name__,)
if len(self.outlier_corrected_paths) == 0:
raise NoFilesFoundError(msg=f"No data files found in {self.outlier_corrected_dir}.", source=self.__class__.__name__)
PopUpMixin.__init__(self, title="ANALYZE DIRECTIONALITY BETWEEN ANIMALS", size=(400, 400))
self.settings_frm = CreateLabelFrameWithIcon( parent=self.main_frm, header="OUTPUT FORMATS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.DIRECTING_ANIMALS_PLOTS.value)
self.boolean_tables_var = BooleanVar(value=False)
self.summary_tables_var = BooleanVar(value=False)
self.aggregate_statistics_var = BooleanVar(value=False)
boolean_tables_cb = Checkbutton(self.settings_frm, text="CREATE BOOLEAN TABLES", font=Formats.FONT_REGULAR.value, variable=self.boolean_tables_var)
summary_table_cb = Checkbutton(self.settings_frm, text="CREATE DETAILED SUMMARY TABLES (INCLUDING COORDINATES)", font=Formats.FONT_REGULAR.value, variable=self.summary_tables_var,)
aggregate_statistics_cb = Checkbutton( self.settings_frm, text="CREATE AGGREGATE STATISTICS TABLE", font=Formats.FONT_REGULAR.value, variable=self.aggregate_statistics_var)

boolean_tables_cb, self.boolean_tables_var = SimbaCheckbox(parent=self.settings_frm, txt="CREATE BOOLEAN TABLES", txt_img='table')
summary_table_cb, self.summary_tables_var = SimbaCheckbox(parent=self.settings_frm, txt="CREATE DETAILED SUMMARY TABLES (INCLUDING COORDINATES)", txt_img='table')
aggregate_statistics_cb, self.aggregate_statistics_var = SimbaCheckbox(parent=self.settings_frm, txt="CREATE AGGREGATE STATISTICS TABLE", txt_img='table')

self.settings_frm.grid(row=0, column=0, sticky="NW")
boolean_tables_cb.grid(row=0, column=0, sticky="NW")
summary_table_cb.grid(row=1, column=0, sticky="NW")
aggregate_statistics_cb.grid(row=2, column=0, sticky="NW")
self.create_run_frm(run_function=self.run)
self.main_frm.mainloop()

def run(self):
if (
Expand All @@ -52,4 +56,4 @@ def run(self):
directing_animals_analyzer.run()


# test = AnimalDirectingAnimalPopUp(config_path='/Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini')
#test = AnimalDirectingAnimalPopUp(config_path=r"C:\troubleshooting\two_black_animals_14bp\project_folder\project_config.ini")
29 changes: 16 additions & 13 deletions simba/ui/pop_ups/clf_by_roi_pop_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
from simba.mixins.config_reader import ConfigReader
from simba.mixins.pop_up_mixin import PopUpMixin
from simba.roi_tools.ROI_clf_calculator import ROIClfCalculator
from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, DropDownMenu,
SimbaButton)
from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, DropDownMenu, SimbaButton, SimbaCheckbox)
from simba.utils.enums import Formats, Keys, Links
from simba.utils.errors import (NoChoosenClassifierError,
NoChoosenMeasurementError, NoChoosenROIError,
ROICoordinatesNotFoundError)
from simba.utils.errors import (NoChoosenClassifierError, NoChoosenMeasurementError, NoChoosenROIError, ROICoordinatesNotFoundError)


class ClfByROIPopUp(PopUpMixin, ConfigReader):

"""
:example:
>>> _ = ClfByROIPopUp(config_path=r"C:\troubleshooting\open_field_below\project_folder\project_config.ini")
"""

def __init__(self, config_path: str):
ConfigReader.__init__(self, config_path=config_path)
if not os.path.isfile(self.roi_coordinates_path):
Expand All @@ -26,12 +29,12 @@ def __init__(self, config_path: str):
ROI_menu = LabelFrame(self.main_frm, text="Select ROI(s)", font=Formats.FONT_HEADER.value, padx=5, pady=5)
classifier_menu = LabelFrame(self.main_frm, text="Select classifier(s)", font=Formats.FONT_HEADER.value, padx=5, pady=5)
measurements_menu = LabelFrame(self.main_frm, text="Select measurements", font=Formats.FONT_HEADER.value, padx=5, pady=5)
self.total_time_var = BooleanVar()
self.start_bouts_var = BooleanVar()
self.end_bouts_var = BooleanVar()
self.total_time_cb = Checkbutton( measurements_menu, font=Formats.FONT_REGULAR.value, text="Total time by ROI (s)", variable=self.total_time_var,)
self.start_bouts_cb = Checkbutton( measurements_menu, font=Formats.FONT_REGULAR.value, text="Started bouts by ROI (count)", variable=self.start_bouts_var,)
self.end_bouts_cb = Checkbutton(measurements_menu, text="Ended bouts by ROI (count)", font=Formats.FONT_REGULAR.value, variable=self.end_bouts_var,)


self.total_time_cb, self.total_time_var = SimbaCheckbox(parent=measurements_menu, txt="Total time by ROI (s)", txt_img='timer')
self.start_bouts_cb, self.start_bouts_var = SimbaCheckbox(parent=measurements_menu, txt="Started bouts by ROI (count)", txt_img='counter')
self.end_bouts_cb, self.end_bouts_var = SimbaCheckbox(parent=measurements_menu, txt="Ended bouts by ROI (count)", txt_img='counter')

self.ROI_check_boxes_status_dict = {}
self.clf_check_boxes_status_dict = {}

Expand Down Expand Up @@ -109,5 +112,5 @@ def run_clf_by_ROI_analysis(self):
)


#
# _ = ClfByROIPopUp(config_path='/Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini')


Loading

0 comments on commit bb40785

Please sign in to comment.