Skip to content

Commit

Permalink
more bug fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Daniel Reis <[email protected]>
  • Loading branch information
veryprofessionaldodo committed Oct 22, 2021
1 parent e9f9095 commit c6c9b87
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
34 changes: 25 additions & 9 deletions photobash_images/photobash_images_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def setupInterface(self):
self.layout.previousButton.clicked.connect(lambda: self.updateCurrentPage(-1))
self.layout.nextButton.clicked.connect(lambda: self.updateCurrentPage(1))
self.layout.scaleSlider.valueChanged.connect(self.updateScale)
self.layout.paginationSlider.setMinimum(0)
self.layout.paginationSlider.valueChanged.connect(self.updatePage)
self.layout.fitCanvasCheckBox.stateChanged.connect(self.changedFitCanvas)

Expand Down Expand Up @@ -148,27 +149,33 @@ def initialize(self):
self.updateImages()

def reorganizeImages(self):
for fav in self.favouriteImages:
if fav in self.foundImages:
self.foundImages.remove(fav)
# organize images, taking into account favourites
# and their respective order
favouriteFoundImages = []
for image in self.favouriteImages:
if image in self.foundImages:
self.foundImages.remove(image)
favouriteFoundImages.append(image)

self.foundImages = self.favouriteImages + self.foundImages
self.foundImages = favouriteFoundImages + self.foundImages

def textFilterChanged(self):
stringsInText = self.layout.filterTextEdit.text().lower().split(" ")
if self.layout.filterTextEdit.text().lower() == "":
self.foundImages = copy.deepcopy(self.allImages)
self.reorganizeImages()
self.updateImages()
return

newImages = []
for word in stringsInText:
for path in self.allImages:
# exclude path outside from search
if word in path.replace(self.directoryPath, "").lower() and not path in newImages:
if word in path.replace(self.directoryPath, "").lower() and not path in newImages and word != "" and word != " ":
newImages.append(path)

self.foundImages = newImages
self.reorganizeImages()
self.updateImages()

def getImagesFromDirectory(self):
Expand Down Expand Up @@ -220,7 +227,7 @@ def updateScale(self, value):

def updatePage(self, value):
maxNumPage = math.ceil(len(self.foundImages) / len(self.layoutButtons))
self.currPage = max(0, min(self.currPage, maxNumPage - 1))
self.currPage = max(0, min(value, maxNumPage - 1))
self.updateImages()

def changedFitCanvas(self, state):
Expand Down Expand Up @@ -421,8 +428,14 @@ def unpinFromFavourites(self, path):

Application.writeSetting(self.applicationName, self.foundFavouritesSetting, str(self.favouriteImages))

# resets order to the default
self.foundImages = copy.deepcopy(self.allImages)
# resets order to the default, but checks if foundImages is only a subset
# in case it is searching
orderedImages = []
for image in self.allImages:
if image in self.foundImages:
orderedImages.append(image)

self.foundImages = orderedImages
self.reorganizeImages()
self.updateImages()

Expand Down Expand Up @@ -452,5 +465,8 @@ def changePath(self):

Application.writeSetting(self.applicationName, self.foundFavouritesSetting, "")

self.layout.changePathButton.setText("Change References Folder")
if self.directoryPath == "":
self.layout.changePathButton.setText("Set References Folder")
else:
self.layout.changePathButton.setText("Change References Folder")
self.getImagesFromDirectory()
2 changes: 1 addition & 1 deletion photobash_images/photobash_images_docker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<number>0</number>
</property>
<property name="spacing">
<number>4</number>
<number>0</number>
</property>
<item row="0" column="2">
<widget class="QWidget" name="imagesButtons2" native="true">
Expand Down
7 changes: 4 additions & 3 deletions photobash_images/photobash_images_modulo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from PyQt5 import QtWidgets, QtCore

DRAG_DELTA = 30
TRIANGLE_SIZE = 30
TRIANGLE_SIZE = 20

FAVOURITE_TRIANGLE = QPolygon([
QPoint(0, 0),
Expand Down Expand Up @@ -67,10 +67,11 @@ def customPaintEvent(instance, event):
painter.translate(offset_x, offset_y)
painter.scale(size, size)
painter.drawImage(0,0,instance.qimage)

# paint something if it is a favourite
if hasattr(instance, 'isFavourite'):
if instance.isFavourite:
# reset scale to draw favourite triangle
painter.scale(1/size, 1/size)
painter.drawPolygon(FAVOURITE_TRIANGLE)

# Restore Space
Expand All @@ -83,7 +84,7 @@ def customSetImage(instance, image):
instance.update()

def customMouseMoveEvent(self, event):
if event.modifiers() != QtCore.Qt.ShiftModifier and event.modifiers() != QtCore.Qt.ControlModifier and event.modifiers() != QtCore.Qt.AltModifier:
if event.modifiers() != QtCore.Qt.ShiftModifier and event.modifiers() != QtCore.Qt.AltModifier:
self.PREVIOUS_DRAG_X = None
return

Expand Down

0 comments on commit c6c9b87

Please sign in to comment.