Skip to content

Commit cd6ccd9

Browse files
committed
modifications
1 parent 3ece81c commit cd6ccd9

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

image_in_window_screensaver/argument_handler.py

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
_file_path: str = None
55
_ignore_keyword: str = None
66
_backup_path: str = None
7+
_start_image_path: str = None
78

89
def get_path() -> str:
910
global _file_path
@@ -29,19 +30,28 @@ def get_backup()->str:
2930
_get_arguments()
3031
return _backup_path
3132

33+
def get_start_image_path()->str:
34+
global _start_image_path
35+
if not _start_image_path:
36+
_get_arguments()
37+
return _start_image_path
3238

3339
def _get_arguments():
3440
l.log("parsing arguments")
3541
global _file_path
3642
global _ignore_keyword
3743
global _backup_path
44+
global _start_image_path
3845

3946
parser = argparse.ArgumentParser()
4047
parser.add_argument('--ignore', type=str, help='keywords to be ignored while parsing files')
4148
parser.add_argument('--path', type=str, help='address from where images will be pursed', required=True)
4249
parser.add_argument('--backup', type=str, help='directory path for backing up non-compressed images')
50+
parser.add_argument('--start_image', type=str, help='start image path')
4351
args = parser.parse_args()
4452
_file_path = args.path
4553
_backup_path = args.backup
54+
if args.start_image:
55+
_start_image_path = args.start_image
4656
if args.ignore:
4757
_ignore_keyword = args.ignore

image_in_window_screensaver/bad_practise_global.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
max_pause_secs = 1500
1212
pause_secs = 300
1313

14+
shuffle_from_start = True
1415
autoplay = True

image_in_window_screensaver/image_widget.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
QKeySequence
99
from qtpy.QtWidgets import QWidget, QLabel, QSizePolicy, QVBoxLayout
1010
from send2trash import send2trash
11-
11+
import argument_handler as argh
1212
import bad_practise_global as bpg
1313
import custom_log as l
1414
import file_walker
@@ -48,6 +48,19 @@ def __init__(self):
4848
self._layout.addWidget(self._image_label)
4949
self.setLayout(self._layout)
5050
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+
5164

5265
def initialize_images(self, mode=None, current_image_path=None,
5366
to_sort: bool = False,
@@ -60,7 +73,6 @@ def initialize_images(self, mode=None, current_image_path=None,
6073
self._current_index = self.get_index_from_image_path(
6174
current_image_path)
6275
self._shuffle_start_index = self._current_index
63-
self.image_shuffle()
6476
self._set_image(self._current_index)
6577

6678
def is_image_landscape(self, image: QPixmap):
@@ -73,7 +85,12 @@ def get_index_from_image_path(self, image_path: str):
7385
# for i in range(0, len(self._all_images)):
7486
# if self._all_images[i] is image_path:
7587
# 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
7794

7895
def image_shuffle(self):
7996
l.log("shuffle")
@@ -89,15 +106,15 @@ def image_shuffle(self):
89106
# self._set_image(self._current_index)
90107

91108
def reverse_sort(self):
92-
l.log("reverse sort")
109+
l.log("reversing current sort")
93110
print(self._current_index)
94111
current_image_path = self._all_images[self._current_index]
95112
self._all_images.reverse()
96113
self._current_index = self.get_index_from_image_path(current_image_path)
97114

98115

99116
def sort_by_date(self, reverse_sort: bool = False):
100-
l.log("sorting images")
117+
l.log("sorting images by date")
101118
print(self._current_index)
102119
current_image_path = self._all_images[self._current_index]
103120
self.initialize_images(mode=file_walker.get_mode(),
@@ -201,10 +218,14 @@ def keyReleaseEvent(self, event: QKeyEvent):
201218
self._shuffle_start_index = self._current_index
202219
elif key == Qt.Key_1:
203220
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()
205224
elif key == Qt.Key_2:
206225
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()
208229
elif key == Qt.Key_0:
209230
l.log("Key 0 --> go to index 0")
210231
if self._shuffle_start_index != 0:

image_in_window_screensaver/runme.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
/Users/amitseal/git/automating-boring-tasks-using-python/image_in_window_screensaver/venv/bin/python /Users/amitseal/git/automating-boring-tasks-using-python/image_in_window_screensaver/main_window.py --path /Users/amitseal/Pictures/x/
2+
/Users/amitseal/git/automating-boring-tasks-using-python/image_in_window_screensaver/venv/bin/python /Users/amitseal/git/automating-boring-tasks-using-python/image_in_window_screensaver/main_window.py --path /Users/amitseal/Pictures/x/ --start_image /Users/amitseal/Pictures/x/landscape/11736680_036_5fe3.jpg

0 commit comments

Comments
 (0)