Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbalaci committed Jul 9, 2018
1 parent 47c37dc commit 9a70852
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 166 deletions.
45 changes: 16 additions & 29 deletions jive/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,17 @@ def __init__(self, parent):
self.message_label = self.statusbar.message_label
self.progressbar = self.statusbar.progressbar

def has_something_to_commit(self):
return self.parent.imgList.has_something_to_commit()

def to_save(self):
"""
Number of images flagged to be saved.
"""
return sum(1 for img in self.parent.imgList.list_of_images if img.to_save)
return self.parent.imgList.to_save()

def to_delete(self):
"""
Number of images flagged to be deleted.
"""
return sum(1 for img in self.parent.imgList.list_of_images if img.to_delete)
return self.parent.imgList.to_delete()

def to_wallpaper(self):
"""
Number of images flagged to be saved as wallpapers.
"""
return sum(1 for img in self.parent.imgList.list_of_images if img.to_wallpaper)

def has_something_to_commit(self):
val1 = self.to_save()
val2 = self.to_delete()
val3 = self.to_wallpaper()

return any([val1, val2, val3])
return self.parent.imgList.to_wallpaper()

def _save_files(self, folder, lst, msg, method):
"""
Expand Down Expand Up @@ -79,7 +66,7 @@ def save_wallpapers(self):
Return the number of images that were saved successfully.
"""
folder = cfg.PLATFORM_SETTINGS['wallpapers_dir']
lst = [img for img in self.parent.imgList.list_of_images if img.to_wallpaper]
lst = [img for img in self.parent.imgList.get_list_of_images() if img.to_wallpaper]

return self._save_files(folder, lst, "saving wallpapers", cfg.WALLPAPER_SAVE)

Expand All @@ -90,7 +77,7 @@ def save_others(self):
Return the number of images that were saved successfully.
"""
folder = cfg.PLATFORM_SETTINGS['saves_dir']
lst = [img for img in self.parent.imgList.list_of_images if img.to_save]
lst = [img for img in self.parent.imgList.get_list_of_images() if img.to_save]

return self._save_files(folder, lst, "saving", cfg.NORMAL_SAVE)

Expand All @@ -99,29 +86,29 @@ def delete_files(self):
return 0
# else, there's something to delete
pos_img = None
if not self.parent.imgList.curr_img.to_delete:
if not self.parent.imgList.get_curr_img().to_delete:
# we don't want to delete the current image
pos_img = self.parent.imgList.curr_img
pos_img = self.parent.imgList.get_curr_img()
else:
# we want to delete the current image
images_to_keep_right = [img for img in self.parent.imgList.list_of_images[self.parent.imgList.curr_img_idx + 1:] if
images_to_keep_right = [img for img in self.parent.imgList.get_list_of_images()[self.parent.imgList.get_curr_img_idx() + 1:] if
not img.to_delete]
if len(images_to_keep_right) > 0:
pos_img = images_to_keep_right[0]
else:
images_to_keep_left = [img for img in self.parent.imgList.list_of_images[:self.parent.imgList.curr_img_idx] if
images_to_keep_left = [img for img in self.parent.imgList.get_list_of_images()[:self.parent.imgList.get_curr_img_idx()] if
not img.to_delete]
if len(images_to_keep_left) > 0:
pos_img = images_to_keep_left[-1]
#
to_delete = [img for img in self.parent.imgList.list_of_images if img.to_delete]
to_delete = [img for img in self.parent.imgList.get_list_of_images() if img.to_delete]
result = self.delete_physically(to_delete)

to_keep = [img for img in self.parent.imgList.list_of_images if not img.to_delete]
self.parent.imgList.list_of_images = to_keep
to_keep = [img for img in self.parent.imgList.get_list_of_images() if not img.to_delete]
self.parent.imgList.set_list_of_images(to_keep)
if len(to_keep) > 0:
# there are remaining images, thus pos_img points to an image that we want to keep
idx = self.parent.imgList.list_of_images.index(pos_img)
idx = self.parent.imgList.get_list_of_images().index(pos_img)
# log.debug(f"index: {idx}")
self.parent.imgList.jump_to_image_and_dont_care_about_the_previous_image(idx)
else:
Expand Down
4 changes: 2 additions & 2 deletions jive/imageinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def grid_layout_creation_1(self):
def grid_layout_creation_2(self):
self.group_box_2 = QGroupBox("Summary")

length = len(self.parent.imgList.list_of_images)
length = len(self.parent.imgList.get_list_of_images())

layout = QGridLayout()
layout.addWidget(QLabel(bold("Marked to be saved:")), 0, 0)
Expand All @@ -84,7 +84,7 @@ def grid_layout_creation_2(self):

layout.addWidget(QLabel(bold("Marked to be deleted:")), 1, 0)
num = self.commit.to_delete()
remain = len(self.parent.imgList.list_of_images) - num
remain = len(self.parent.imgList.get_list_of_images()) - num
text = f"{num} (out of {length}) [remain {remain}]"
layout.addWidget(QLabel(text), 1, 1)

Expand Down
Loading

0 comments on commit 9a70852

Please sign in to comment.