@@ -21,13 +21,8 @@ def __init__(self):
21
21
self ._image_label .setSizePolicy (QSizePolicy .Ignored , QSizePolicy .Ignored )
22
22
self ._image_label .setScaledContents (True )
23
23
self .is_full_screen : bool = False
24
- # self._size_method = None
25
24
self ._seed = time .time ()
26
- # self._line_edit: QLineEdit = None
27
- # self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
28
-
29
- # self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
30
- # self.sizeHint()
25
+
31
26
random .seed (self ._seed )
32
27
33
28
# self._all_images: List = file_walker.walk(sys.argv[1])
@@ -37,27 +32,44 @@ def __init__(self):
37
32
self .setLayout (self ._layout )
38
33
self .initialize_images ()
39
34
40
- def initialize_images (self , mode = None ):
35
+ def initialize_images (self , mode = None , current_image_path = None ):
41
36
self ._all_images : List = file_walker .walk (mode )
42
37
self ._current_index = 0
43
- self .image_shuffle ()
44
-
38
+ if current_image_path :
39
+ self ._current_index = self .get_index_from_image_path (current_image_path )
40
+ # self.image_shuffle()
41
+ self ._set_image (self ._current_index )
45
42
43
+
46
44
47
45
def is_image_landscape (self , image : QPixmap ):
48
46
if image .width ()/ image .height () > 1 :
49
47
return True
50
48
else :
51
49
return False
52
50
51
+ 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
+
53
56
def image_shuffle (self ):
54
57
l .log ("shuffle" )
58
+ image_path = self ._all_images [self ._current_index ]
55
59
self ._seed = time .time ()
56
60
random .seed (self ._seed )
57
61
random .shuffle (self ._all_images )
58
- self ._current_index = 0
62
+ self ._current_index = self . get_index_from_image_path ( image_path )
59
63
self ._set_image (self ._current_index )
64
+
65
+ # self._current_index = 0
66
+ # self._set_image(self._current_index)
60
67
68
+ def revert_shuffle (self ):
69
+ l .log ("revert shuffle" )
70
+ current_image_path = self ._all_images [self ._current_index ]
71
+ self .initialize_images (file_walker .get_mode (), current_image_path )
72
+
61
73
def image_next (self ):
62
74
l .log ("next" )
63
75
self ._current_index += 1
@@ -82,23 +94,10 @@ def _set_image(self, index):
82
94
l .log ("error: shuffling again" )
83
95
self .image_shuffle ()
84
96
l .log ("setting image" )
85
-
86
97
image_pix_map = QPixmap (self ._all_images [index ])
87
-
88
-
89
- # if self.is_image_landscape(image_pix_map):
90
- # self._image_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Ignored)
91
- # else:
92
- # self._image_label.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
93
98
print ("image: " , image_pix_map .width (), image_pix_map .height ())
94
-
95
- # image_pix_map = image_pix_map.scaled(900, 900, Qt.KeepAspectRatio)
96
- # print(self.width(), self.height())
97
-
98
- #
99
99
self ._image_label .setPixmap (image_pix_map )
100
- # if self._line_edit:
101
- # self._line_edit.setText(self._all_images[index])
100
+ self .set_title (self ._all_images [index ])
102
101
103
102
# def set_line_edit(self, edit_line: QLineEdit):
104
103
# self._line_edit = edit_line
@@ -160,7 +159,7 @@ def keyReleaseEvent(self, event: QKeyEvent):
160
159
self .initialize_images ()
161
160
162
161
self .setFocus ()
163
- self .set_title (self .get_current_image_path_str ())
162
+ # self.set_title(self.get_current_image_path_str())
164
163
165
164
def get_current_image_path_str (self ) -> str :
166
165
return self ._all_images [self ._current_index ]
0 commit comments