8
8
QKeySequence
9
9
from qtpy .QtWidgets import QWidget , QLabel , QSizePolicy , QVBoxLayout
10
10
from send2trash import send2trash
11
-
11
+ import argument_handler as argh
12
12
import bad_practise_global as bpg
13
13
import custom_log as l
14
14
import file_walker
@@ -48,6 +48,19 @@ def __init__(self):
48
48
self ._layout .addWidget (self ._image_label )
49
49
self .setLayout (self ._layout )
50
50
self .initialize_images ()
51
+ if bpg .shuffle_from_start :
52
+ self .image_shuffle ()
53
+ self ._set_start_image ()
54
+
55
+ def _set_start_image (self ):
56
+ self .start_image = argh .get_start_image_path ()
57
+ if self .start_image :
58
+ l .log ("setting start image: " + self .start_image )
59
+ index = self .get_index_from_image_path (
60
+ self .start_image )
61
+ self ._set_image (index )
62
+ self ._current_index = index
63
+
51
64
52
65
def initialize_images (self , mode = None , current_image_path = None ,
53
66
to_sort : bool = False ,
@@ -60,7 +73,6 @@ def initialize_images(self, mode=None, current_image_path=None,
60
73
self ._current_index = self .get_index_from_image_path (
61
74
current_image_path )
62
75
self ._shuffle_start_index = self ._current_index
63
- self .image_shuffle ()
64
76
self ._set_image (self ._current_index )
65
77
66
78
def is_image_landscape (self , image : QPixmap ):
@@ -73,7 +85,12 @@ def get_index_from_image_path(self, image_path: str):
73
85
# for i in range(0, len(self._all_images)):
74
86
# if self._all_images[i] is image_path:
75
87
# return i
76
- return self ._all_images .index (image_path )
88
+
89
+ try :
90
+ return self ._all_images .index (image_path )
91
+ except ValueError :
92
+ l .log ("requested image {} not found. returning 0." .format (image_path ))
93
+ return 0
77
94
78
95
def image_shuffle (self ):
79
96
l .log ("shuffle" )
@@ -89,15 +106,15 @@ def image_shuffle(self):
89
106
# self._set_image(self._current_index)
90
107
91
108
def reverse_sort (self ):
92
- l .log ("reverse sort" )
109
+ l .log ("reversing current sort" )
93
110
print (self ._current_index )
94
111
current_image_path = self ._all_images [self ._current_index ]
95
112
self ._all_images .reverse ()
96
113
self ._current_index = self .get_index_from_image_path (current_image_path )
97
114
98
115
99
116
def sort_by_date (self , reverse_sort : bool = False ):
100
- l .log ("sorting images" )
117
+ l .log ("sorting images by date " )
101
118
print (self ._current_index )
102
119
current_image_path = self ._all_images [self ._current_index ]
103
120
self .initialize_images (mode = file_walker .get_mode (),
@@ -201,10 +218,14 @@ def keyReleaseEvent(self, event: QKeyEvent):
201
218
self ._shuffle_start_index = self ._current_index
202
219
elif key == Qt .Key_1 :
203
220
l .log ("Key 1 --> landscape mode" )
204
- self .initialize_images ("landscape/" )
221
+ self .initialize_images ("landscape/" , current_image_path = self .start_image )
222
+ if bpg .shuffle_from_start :
223
+ self .image_shuffle ()
205
224
elif key == Qt .Key_2 :
206
225
l .log ("Key 2 --> Portrait mode" )
207
- self .initialize_images ("portrait/" )
226
+ self .initialize_images ("portrait/" , current_image_path = self .start_image )
227
+ if bpg .shuffle_from_start :
228
+ self .image_shuffle ()
208
229
elif key == Qt .Key_0 :
209
230
l .log ("Key 0 --> go to index 0" )
210
231
if self ._shuffle_start_index != 0 :
0 commit comments