Skip to content

Commit

Permalink
preview image scrolla nd change image working
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclifford1 committed Aug 5, 2024
1 parent 050f7e1 commit e70414e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
31 changes: 29 additions & 2 deletions IQM_Vis/UI/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,35 @@ def redo_plots(self, calc_range=False):
'''
change image in dataset
'''
def change_to_data_num(self, ind):
# change to an exact ind in the data list
def change_preview_images(self, ival):
if self.preview_num + ival < 0:
return
elif self.preview_num + ival + self.num_images_scroll_show > self.max_data_ind + 1:
return
else:
self.preview_num += ival
self.set_preview_images(self.preview_num)

def set_preview_images(self, preview_num):
for data_store in self.data_stores:
for i in range(self.num_images_scroll_show):
im_preview_ind = preview_num + i
if im_preview_ind <= self.max_data_ind:
# load image
im_preview_data = data_store.get_reference_image_by_index(
im_preview_ind)
self.widget_im_num_hash[i] = im_preview_ind
if isinstance(self.image_display_size, list) or isinstance(self.image_display_size, tuple):
preview_size = (self.image_display_size[0]//self.num_images_scroll_show, self.image_display_size[1]//self.num_images_scroll_show)
else:
preview_size = self.image_display_size//self.num_images_scroll_show
gui_utils.change_im(self.widget_controls['images'][i], im_preview_data,
resize=preview_size, rgb_brightness=self.rgb_brightness, display_brightness=self.display_brightness)

def change_data_click_im(self, widget_ind, *args): # args sent are position of mouse click on the image widget
self.change_to_data_num(self.widget_im_num_hash[widget_ind])

def change_to_data_num(self, ind): # change to an exact ind in the data list
# check the num is within the data limits
if ind < 0:
return
Expand Down
2 changes: 2 additions & 0 deletions IQM_Vis/UI/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def _init_generic_layout(self):
if self.dataset:
dataset_layout.addWidget(self.widget_controls['label']['data'])
dataset_layout.addWidget(self.widget_controls['button']['prev_data'])
for im in range(self.num_images_scroll_show):
dataset_layout.addWidget(self.widget_controls['images'][im])
dataset_layout.addWidget(self.widget_controls['button']['next_data'])
dataset_layout.addWidget(self.widget_controls['label']['data_num'])

Expand Down
5 changes: 5 additions & 0 deletions IQM_Vis/UI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self,
restrict_options=None,
num_steps_range=11,
num_step_experiment=6,
num_images_scroll_show=5,
test=False
):
super().__init__()
Expand All @@ -34,6 +35,7 @@ def __init__(self,
self.transformations = transformations
self.num_steps_range = num_steps_range
self.num_step_experiment = num_step_experiment
self.num_images_scroll_show = num_images_scroll_show
self.test = test

self.metrics_info_format = metrics_info_format
Expand Down Expand Up @@ -244,6 +246,9 @@ def construct_UI(self):
self.init_style() # layout.py
self.init_widgets() # widgets.py
self.change_data(0, _redo_plots=True) # images.py
if self.dataset:
self.preview_num = 0
self.set_preview_images(self.preview_num)
self.main = self.init_layout() # layout.py
self.tabs['slider'].setCurrentIndex(tabs_index['slider'])
self.tabs['graph'].setCurrentIndex(tabs_index['graph'])
Expand Down
12 changes: 9 additions & 3 deletions IQM_Vis/UI/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _init_widgets(self):


'''buttons'''
self.widget_controls = {'button': {}, 'slider': {}, 'label': {}, 'check_box': {}}
self.widget_controls = {'button': {}, 'slider': {}, 'label': {}, 'check_box': {}, 'images': {}}

if (self.metrics_avg_graph or self.metric_range_graph):
# Update graphs
Expand Down Expand Up @@ -136,13 +136,19 @@ def _init_widgets(self):
if self.dataset:
# control what image is used from the dataset
self.widget_controls['button']['next_data'] = QPushButton('->', self)
self.widget_controls['button']['next_data'].clicked.connect(partial(self.change_data, 1, True))
self.widget_controls['button']['next_data'].clicked.connect(partial(self.change_preview_images, 1))
self.widget_controls['button']['prev_data'] = QPushButton('<-', self)
self.widget_controls['button']['prev_data'].clicked.connect(partial(self.change_data, -1, True))
self.widget_controls['button']['prev_data'].clicked.connect(partial(self.change_preview_images, -1))
self.widget_controls['label']['data'] = QLabel(self)
self.widget_controls['label']['data'].setText('Change Image:')
self.widget_controls['label']['data_num'] = QLabel(self)
self.widget_controls['label']['data_num'].setText('1/1')
self.widget_im_num_hash = {}
for im in range(self.num_images_scroll_show):
self.widget_controls['images'][im] = QLabel( self)
self.widget_controls['images'][im].setAlignment(Qt.AlignmentFlag.AlignCenter)
self.widget_controls['images'][im].mousePressEvent = partial(self.change_data_click_im, im)
self.widget_im_num_hash[im] = im # store the ind number of each im widget preview

# launch experiment button
self.widget_controls['button']['launch_exp'] = QPushButton('Run Experiment', self)
Expand Down
7 changes: 7 additions & 0 deletions IQM_Vis/data_handlers/data_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ def __len__(self):
def __getitem__(self, i):
self._load_image_data(i)

def get_reference_image_by_index(self, index):
if index >= len(self.image_list):
raise IndexError('Index out of range of the length of the image list')
file_name = self.image_list[index]
image_data = self.image_loader(file_name)
return image_data

def get_reference_image_name(self):
return self.image_reference.name

Expand Down
4 changes: 4 additions & 0 deletions IQM_Vis/data_handlers/data_api_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ def __len__(self):
@abstractmethod
def __getitem__(self):
pass

@abstractmethod
def get_reference_image_by_index(self, index):
pass

0 comments on commit e70414e

Please sign in to comment.