Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 26b6d33

Browse files
committed
Added save image to dir button
1 parent 6e9bef7 commit 26b6d33

File tree

4 files changed

+75
-15
lines changed

4 files changed

+75
-15
lines changed

WallDit Qt.ui

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<x>0</x>
1111
<y>0</y>
1212
<width>341</width>
13-
<height>241</height>
13+
<height>270</height>
1414
</rect>
1515
</property>
1616
<property name="font">
@@ -210,6 +210,13 @@
210210
</property>
211211
</widget>
212212
</item>
213+
<item>
214+
<widget class="QPushButton" name="save_img_btn">
215+
<property name="text">
216+
<string>Save image to directory</string>
217+
</property>
218+
</widget>
219+
</item>
213220
<item>
214221
<widget class="QPushButton" name="start_btn">
215222
<property name="text">
@@ -221,6 +228,14 @@
221228
</item>
222229
</layout>
223230
</widget>
231+
<tabstops>
232+
<tabstop>subreddit_line</tabstop>
233+
<tabstop>nsfw_checkbox</tabstop>
234+
<tabstop>post_amount_spinbox</tabstop>
235+
<tabstop>post_type_combo_box</tabstop>
236+
<tabstop>boot_checkbox</tabstop>
237+
<tabstop>start_btn</tabstop>
238+
</tabstops>
224239
<resources/>
225240
<connections/>
226241
</ui>

WallDit.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
import requests
33
import shutil
44
import ctypes
5+
import ctypes.wintypes
56
import os
7+
import time
8+
from win32com.shell import shell, shellcon
69
from WallDit_QT import *
710

811
# All hope is lost, abandon now
912

10-
counter = 0
13+
counter = 0 # Counter for checking how many posts that don't fit parameters were skipped
1114

1215
user_agent = "windows/linux:WallDit:v1 (by /u/FilthyPeasantt)"
1316
r = praw.Reddit(user_agent = user_agent)
@@ -38,10 +41,9 @@ def is_ok_submission_url(window, submission, link_search_limit):
3841
elif counter == link_search_limit:
3942
window.handle_status_label("Error: Submission are all invalid, up the counter or try again")
4043
else:
41-
print("Submission: no errors.\n\n")
4244
return True
4345

44-
# Grabs link
46+
# Gets links that meet the specified parameter requirements
4547
def get_link(window):
4648
link_search_limit = window.handle_post_spinbox() # how many links it's gonna search for images that fit the criteria till it gives up and dies in a fire
4749

@@ -60,15 +62,16 @@ def get_link(window):
6062
return submission.url
6163

6264
# Downloads image
63-
def get_image_download(window):
65+
def get_image_download(window, image_name):
6466
url = get_link(window)
6567
window.handle_status_label("Downloading image")
6668

6769
if ('i.' not in url and 'imgur' in url) and url:
6870
url += ".png"
6971

7072
response = requests.get(url, stream=True)
71-
with open('DownloadedImage.png', 'wb') as out_file:
73+
74+
with open(image_name, 'wb') as out_file:
7275
shutil.copyfileobj(response.raw, out_file)
7376
del response
7477
return url
@@ -87,14 +90,37 @@ def check_connectivity(window):
8790
window.handle_status_label("No internet connection is available")
8891
return False
8992

93+
# Seriously, don't ask, yet another windows function
94+
def get_path_to_folder():
95+
desktop_pidl = shell.SHGetFolderLocation (0, shellcon.CSIDL_DESKTOP, 0, 0)
96+
pidl, display_name, image_list = shell.SHBrowseForFolder (0, desktop_pidl, "Choose a folder", 0, None, None)
97+
98+
return shell.SHGetPathFromIDList(pidl)
99+
100+
def save_image(window):
101+
date = time.strftime("%Y-%d-%m-%H-%M")
102+
image_ext = ".png"
103+
image = "DownloadedImage" + date + image_ext
104+
105+
# Adds the date and time to the downloaded image, before moving it to the Pictures directory
106+
os.rename("DownloadedImage.png", image)
107+
108+
cwd = os.getcwd()
109+
path = os.path.join(cwd, image)
110+
111+
# Copies image to a dir
112+
shutil.copyfile(path, get_path_to_folder())
113+
90114
# Sets downloaded image as wallpaper
91115
def set_wallpaper(window):
92116
cwd = os.getcwd()
93-
path = os.path.join(cwd, "DownloadedImage.png")
94-
url = get_image_download(window)
117+
118+
image_name = "DownloadedImage.png"
119+
path = os.path.join(cwd, image_name)
120+
url = get_image_download(window, image_name)
95121
window.handle_progress_bar(30)
96122
window.handle_status_label("Setting image as desktop background...")
97-
if ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0): # Runs on magical pony farts, do not touch
123+
if ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0): # Runs on magic, do not touch
98124
window.handle_progress_bar(30)
99125
window.handle_status_label("Desktop background set successfully.")
100126
else:

WallDit_QT.pyw

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,52 @@ class MainWindow(QMainWindow, Ui_MainWindow):
2626

2727
# Buttons
2828
self.start_btn.clicked.connect(self.handle_start_btn)
29+
self.save_img_btn.clicked.connect(self.handle_save_img_btn)
2930

31+
# Handles NSFW posts
3032
def handle_nsfw_checkbox(self):
3133
if self.nsfw_checkbox.isChecked():
32-
print("NSFW: checked")
3334
return True
3435
else:
35-
print("NSFW: unchecked")
3636
return False
3737

3838
def handle_post_spinbox(self):
3939
spinbox_value = self.post_amount_spinbox.value()
4040
return spinbox_value
4141

42-
def handle_boot_checkbox(self): # when executable is released, gonna implement
42+
# Going to implement when i figure out windows's shitty documentation
43+
def handle_boot_checkbox(self):
4344
if self.boot_checkbox.isChecked():
4445
print("boot: checked")
4546
else:
4647
print("boot: unchecked")
4748

49+
# Handles the text input for the Subreddit line inside the GUI
4850
def handle_subreddit_line(self):
4951
sub_line = self.subreddit_line.text()
5052
return sub_line
5153

54+
# Combo box for the post type (aka hot/top all time/etc.)
5255
def handle_post_type_combo_box(self):
5356
post_type = self.post_type_combo_box.currentIndex()
5457
return post_type
5558

5659
def handle_progress_bar(self, percent):
5760
self.progressBar.setValue(self.progressBar.value() + percent)
5861

62+
# Start button function, when pressed resets the progress bar and sets the wallpaper
5963
def handle_start_btn(self):
6064
if self.start_btn.isDown:
61-
print("Button pressed")
65+
print("Start button pressed")
6266
self.handle_progress_bar(-100)
6367
WallDit.set_wallpaper(self)
6468

69+
# Not implemented yet, windows's magic functions again
70+
def handle_save_img_btn(self):
71+
if self.save_img_btn.isDown:
72+
print("Save image button pressed")
73+
WallDit.save_image(self)
74+
6575
def handle_status_label(self, text):
6676
self.status_label.setText(text)
6777

output_ui.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Form implementation generated from reading ui file 'WallDit Qt.ui'
44
#
5-
# Created: Sun Dec 6 12:35:28 2015
5+
# Created: Tue Dec 8 13:15:33 2015
66
# by: pyside-uic 0.2.15 running on PySide 1.2.4
77
#
88
# WARNING! All changes made in this file will be lost!
@@ -13,7 +13,7 @@ class Ui_MainWindow(object):
1313
def setupUi(self, MainWindow):
1414
MainWindow.setObjectName("MainWindow")
1515
MainWindow.setEnabled(True)
16-
MainWindow.resize(341, 241)
16+
MainWindow.resize(341, 270)
1717
font = QtGui.QFont()
1818
font.setUnderline(False)
1919
MainWindow.setFont(font)
@@ -96,13 +96,21 @@ def setupUi(self, MainWindow):
9696
self.progressBar.setProperty("value", 0)
9797
self.progressBar.setObjectName("progressBar")
9898
self.verticalLayout_3.addWidget(self.progressBar)
99+
self.save_img_btn = QtGui.QPushButton(MainWindow)
100+
self.save_img_btn.setObjectName("save_img_btn")
101+
self.verticalLayout_3.addWidget(self.save_img_btn)
99102
self.start_btn = QtGui.QPushButton(MainWindow)
100103
self.start_btn.setObjectName("start_btn")
101104
self.verticalLayout_3.addWidget(self.start_btn)
102105
self.horizontalLayout.addLayout(self.verticalLayout_3)
103106

104107
self.retranslateUi(MainWindow)
105108
QtCore.QMetaObject.connectSlotsByName(MainWindow)
109+
MainWindow.setTabOrder(self.subreddit_line, self.nsfw_checkbox)
110+
MainWindow.setTabOrder(self.nsfw_checkbox, self.post_amount_spinbox)
111+
MainWindow.setTabOrder(self.post_amount_spinbox, self.post_type_combo_box)
112+
MainWindow.setTabOrder(self.post_type_combo_box, self.boot_checkbox)
113+
MainWindow.setTabOrder(self.boot_checkbox, self.start_btn)
106114

107115
def retranslateUi(self, MainWindow):
108116
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "WallDit by Disco Dolan", None, QtGui.QApplication.UnicodeUTF8))
@@ -126,5 +134,6 @@ def retranslateUi(self, MainWindow):
126134
self.nsfw_checkbox.setToolTip(QtGui.QApplication.translate("MainWindow", "Toggle to enable searching for NSFW links", None, QtGui.QApplication.UnicodeUTF8))
127135
self.nsfw_checkbox.setText(QtGui.QApplication.translate("MainWindow", "NSFW", None, QtGui.QApplication.UnicodeUTF8))
128136
self.status_label.setText(QtGui.QApplication.translate("MainWindow", "Status:", None, QtGui.QApplication.UnicodeUTF8))
137+
self.save_img_btn.setText(QtGui.QApplication.translate("MainWindow", "Save image to directory", None, QtGui.QApplication.UnicodeUTF8))
129138
self.start_btn.setText(QtGui.QApplication.translate("MainWindow", "Start", None, QtGui.QApplication.UnicodeUTF8))
130139

0 commit comments

Comments
 (0)