Skip to content

Commit e657dc2

Browse files
committed
used default method for finding index
1 parent 6986e65 commit e657dc2

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

image_in_window_screensaver/image_widget.py

+24-15
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ def is_image_landscape(self, image: QPixmap):
4949
return False
5050

5151
def get_index_from_image_path(self, image_path: str):
52-
for i in range(0, len(self._all_images)):
53-
if self._all_images[i] is image_path:
54-
return i
55-
52+
# for i in range(0, len(self._all_images)):
53+
# if self._all_images[i] is image_path:
54+
# return i
55+
return self._all_images.index(image_path)
56+
5657
def image_shuffle(self):
5758
l.log("shuffle")
5859
image_path = self._all_images[self._current_index]
@@ -67,18 +68,23 @@ def image_shuffle(self):
6768

6869
def revert_shuffle(self):
6970
l.log("revert shuffle")
71+
print(self._current_index)
7072
current_image_path = self._all_images[self._current_index]
7173
self.initialize_images(file_walker.get_mode(), current_image_path)
7274

7375
def image_next(self):
7476
l.log("next")
7577
self._current_index += 1
78+
if self._current_index > len(self._all_images):
79+
self._current_index = 0
7680
self._set_image(self._current_index)
7781
# self.setFocus()
7882

7983
def image_previous(self):
8084
l.log("previous")
8185
self._current_index -= 1
86+
if self._current_index <= -1*len(self._all_images):
87+
self._current_index = 0
8288
self._set_image(self._current_index)
8389

8490
def image_delete(self):
@@ -92,7 +98,7 @@ def image_delete(self):
9298
def _set_image(self, index):
9399
if index > len(self._all_images)-1:
94100
l.log("error: shuffling again")
95-
self.image_shuffle()
101+
index = 0
96102
l.log("setting image")
97103
image_pix_map = QPixmap(self._all_images[index])
98104
print("image: ", image_pix_map.width(), image_pix_map.height())
@@ -124,37 +130,40 @@ def set_title(self, image_path):
124130

125131

126132
def keyReleaseEvent(self, event: QKeyEvent):
127-
l.log("Key event at top_level_widget: " + str(event.key()))
128-
if event.key() == Qt.Key_S:
133+
key = event.key()
134+
l.log("Key event at top_level_widget: " + str(key))
135+
if key == Qt.Key_S:
129136
l.log("Key S")
130137
self.image_shuffle()
131-
elif event.key() == Qt.Key_Left or event.key() == Qt.Key_Backspace or event.key() == Qt.Key_P:
138+
elif key == Qt.Key_Left or key == Qt.Key_Backspace or key == Qt.Key_P:
132139
l.log("Key left or backspace")
133140
self.image_previous()
134-
elif event.key() == Qt.Key_Right or event.key() == Qt.Key_N or event.key() == Qt.Key_Space:
141+
elif key == Qt.Key_Right or key == Qt.Key_N or key == Qt.Key_Space:
135142
l.log("Key Right / N / Space")
136143
self.image_next()
137-
elif event.key() == Qt.Key_Delete:
144+
elif key == Qt.Key_Delete:
138145
l.log("Key Delete")
139146
self.image_delete()
140-
elif event.key() == Qt.Key_F:
147+
elif key == Qt.Key_F:
141148
l.log("Key F")
142149
if self.is_full_screen:
143150
self.showNormal()
144151
else:
145152
self.showFullScreen()
146153
# toggle
147154
self.is_full_screen = not self.is_full_screen
148-
elif event.key() == Qt.Key_B:
155+
elif key == Qt.Key_B:
149156
l.log("Key B")
150157
self._browse_event()
151-
elif event.key() == Qt.Key_1 or event.key() == Qt.Key_L:
158+
elif key == Qt.Key_1 or key == Qt.Key_L:
152159
l.log("Key 1 / L --> landscape mode")
153160
self.initialize_images("landscape/")
154-
elif event.key() == Qt.Key_2 or event.key() == Qt.Key_P:
161+
elif key == Qt.Key_2 or key == Qt.Key_P:
155162
l.log("Key 2 / P --> Portrait mode")
156163
self.initialize_images("portrait/")
157-
elif event.key() == Qt.Key_3 or event.key() == Qt.Key_R:
164+
elif key == Qt.Key_R:
165+
self.revert_shuffle()
166+
elif key == Qt.Key_3:
158167
l.log("Key 3 / Reset all")
159168
self.initialize_images()
160169

0 commit comments

Comments
 (0)