diff --git a/WallDit Qt.ui b/WallDit Qt.ui
index d5a32c1..191c6ab 100644
--- a/WallDit Qt.ui
+++ b/WallDit Qt.ui
@@ -10,7 +10,7 @@
0
0
341
- 241
+ 270
@@ -210,6 +210,13 @@
+ -
+
+
+ Save image to directory
+
+
+
-
@@ -221,6 +228,14 @@
+
+ subreddit_line
+ nsfw_checkbox
+ post_amount_spinbox
+ post_type_combo_box
+ boot_checkbox
+ start_btn
+
diff --git a/WallDit.py b/WallDit.py
index de72aa1..19dce7c 100644
--- a/WallDit.py
+++ b/WallDit.py
@@ -2,12 +2,15 @@
import requests
import shutil
import ctypes
+import ctypes.wintypes
import os
+import time
+from win32com.shell import shell, shellcon
from WallDit_QT import *
# All hope is lost, abandon now
-counter = 0
+counter = 0 # Counter for checking how many posts that don't fit parameters were skipped
user_agent = "windows/linux:WallDit:v1 (by /u/FilthyPeasantt)"
r = praw.Reddit(user_agent = user_agent)
@@ -38,10 +41,9 @@ def is_ok_submission_url(window, submission, link_search_limit):
elif counter == link_search_limit:
window.handle_status_label("Error: Submission are all invalid, up the counter or try again")
else:
- print("Submission: no errors.\n\n")
return True
-# Grabs link
+# Gets links that meet the specified parameter requirements
def get_link(window):
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
@@ -60,7 +62,7 @@ def get_link(window):
return submission.url
# Downloads image
-def get_image_download(window):
+def get_image_download(window, image_name):
url = get_link(window)
window.handle_status_label("Downloading image")
@@ -68,7 +70,8 @@ def get_image_download(window):
url += ".png"
response = requests.get(url, stream=True)
- with open('DownloadedImage.png', 'wb') as out_file:
+
+ with open(image_name, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
return url
@@ -87,14 +90,37 @@ def check_connectivity(window):
window.handle_status_label("No internet connection is available")
return False
+# Seriously, don't ask, yet another windows function
+def get_path_to_folder():
+ desktop_pidl = shell.SHGetFolderLocation (0, shellcon.CSIDL_DESKTOP, 0, 0)
+ pidl, display_name, image_list = shell.SHBrowseForFolder (0, desktop_pidl, "Choose a folder", 0, None, None)
+
+ return shell.SHGetPathFromIDList(pidl)
+
+def save_image(window):
+ date = time.strftime("%Y-%d-%m-%H-%M")
+ image_ext = ".png"
+ image = "DownloadedImage" + date + image_ext
+
+ # Adds the date and time to the downloaded image, before moving it to the Pictures directory
+ os.rename("DownloadedImage.png", image)
+
+ cwd = os.getcwd()
+ path = os.path.join(cwd, image)
+
+ # Copies image to a dir
+ shutil.copyfile(path, get_path_to_folder())
+
# Sets downloaded image as wallpaper
def set_wallpaper(window):
cwd = os.getcwd()
- path = os.path.join(cwd, "DownloadedImage.png")
- url = get_image_download(window)
+
+ image_name = "DownloadedImage.png"
+ path = os.path.join(cwd, image_name)
+ url = get_image_download(window, image_name)
window.handle_progress_bar(30)
window.handle_status_label("Setting image as desktop background...")
- if ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0): # Runs on magical pony farts, do not touch
+ if ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0): # Runs on magic, do not touch
window.handle_progress_bar(30)
window.handle_status_label("Desktop background set successfully.")
else:
diff --git a/WallDit_QT.pyw b/WallDit_QT.pyw
index 35531ae..d701a96 100644
--- a/WallDit_QT.pyw
+++ b/WallDit_QT.pyw
@@ -26,29 +26,32 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Buttons
self.start_btn.clicked.connect(self.handle_start_btn)
+ self.save_img_btn.clicked.connect(self.handle_save_img_btn)
+ # Handles NSFW posts
def handle_nsfw_checkbox(self):
if self.nsfw_checkbox.isChecked():
- print("NSFW: checked")
return True
else:
- print("NSFW: unchecked")
return False
def handle_post_spinbox(self):
spinbox_value = self.post_amount_spinbox.value()
return spinbox_value
- def handle_boot_checkbox(self): # when executable is released, gonna implement
+ # Going to implement when i figure out windows's shitty documentation
+ def handle_boot_checkbox(self):
if self.boot_checkbox.isChecked():
print("boot: checked")
else:
print("boot: unchecked")
+ # Handles the text input for the Subreddit line inside the GUI
def handle_subreddit_line(self):
sub_line = self.subreddit_line.text()
return sub_line
+ # Combo box for the post type (aka hot/top all time/etc.)
def handle_post_type_combo_box(self):
post_type = self.post_type_combo_box.currentIndex()
return post_type
@@ -56,12 +59,19 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def handle_progress_bar(self, percent):
self.progressBar.setValue(self.progressBar.value() + percent)
+ # Start button function, when pressed resets the progress bar and sets the wallpaper
def handle_start_btn(self):
if self.start_btn.isDown:
- print("Button pressed")
+ print("Start button pressed")
self.handle_progress_bar(-100)
WallDit.set_wallpaper(self)
+ # Not implemented yet, windows's magic functions again
+ def handle_save_img_btn(self):
+ if self.save_img_btn.isDown:
+ print("Save image button pressed")
+ WallDit.save_image(self)
+
def handle_status_label(self, text):
self.status_label.setText(text)
diff --git a/output_ui.py b/output_ui.py
index 6e9db94..294a020 100644
--- a/output_ui.py
+++ b/output_ui.py
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'WallDit Qt.ui'
#
-# Created: Sun Dec 6 12:35:28 2015
+# Created: Tue Dec 8 13:15:33 2015
# by: pyside-uic 0.2.15 running on PySide 1.2.4
#
# WARNING! All changes made in this file will be lost!
@@ -13,7 +13,7 @@ class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
- MainWindow.resize(341, 241)
+ MainWindow.resize(341, 270)
font = QtGui.QFont()
font.setUnderline(False)
MainWindow.setFont(font)
@@ -96,6 +96,9 @@ def setupUi(self, MainWindow):
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.verticalLayout_3.addWidget(self.progressBar)
+ self.save_img_btn = QtGui.QPushButton(MainWindow)
+ self.save_img_btn.setObjectName("save_img_btn")
+ self.verticalLayout_3.addWidget(self.save_img_btn)
self.start_btn = QtGui.QPushButton(MainWindow)
self.start_btn.setObjectName("start_btn")
self.verticalLayout_3.addWidget(self.start_btn)
@@ -103,6 +106,11 @@ def setupUi(self, MainWindow):
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
+ MainWindow.setTabOrder(self.subreddit_line, self.nsfw_checkbox)
+ MainWindow.setTabOrder(self.nsfw_checkbox, self.post_amount_spinbox)
+ MainWindow.setTabOrder(self.post_amount_spinbox, self.post_type_combo_box)
+ MainWindow.setTabOrder(self.post_type_combo_box, self.boot_checkbox)
+ MainWindow.setTabOrder(self.boot_checkbox, self.start_btn)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "WallDit by Disco Dolan", None, QtGui.QApplication.UnicodeUTF8))
@@ -126,5 +134,6 @@ def retranslateUi(self, MainWindow):
self.nsfw_checkbox.setToolTip(QtGui.QApplication.translate("MainWindow", "Toggle to enable searching for NSFW links", None, QtGui.QApplication.UnicodeUTF8))
self.nsfw_checkbox.setText(QtGui.QApplication.translate("MainWindow", "NSFW", None, QtGui.QApplication.UnicodeUTF8))
self.status_label.setText(QtGui.QApplication.translate("MainWindow", "Status:", None, QtGui.QApplication.UnicodeUTF8))
+ self.save_img_btn.setText(QtGui.QApplication.translate("MainWindow", "Save image to directory", None, QtGui.QApplication.UnicodeUTF8))
self.start_btn.setText(QtGui.QApplication.translate("MainWindow", "Start", None, QtGui.QApplication.UnicodeUTF8))