Skip to content

Commit

Permalink
Added save image to dir button
Browse files Browse the repository at this point in the history
  • Loading branch information
NullSense committed Dec 8, 2015
1 parent 6e9bef7 commit 26b6d33
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 15 deletions.
17 changes: 16 additions & 1 deletion WallDit Qt.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>341</width>
<height>241</height>
<height>270</height>
</rect>
</property>
<property name="font">
Expand Down Expand Up @@ -210,6 +210,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="save_img_btn">
<property name="text">
<string>Save image to directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="start_btn">
<property name="text">
Expand All @@ -221,6 +228,14 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>subreddit_line</tabstop>
<tabstop>nsfw_checkbox</tabstop>
<tabstop>post_amount_spinbox</tabstop>
<tabstop>post_type_combo_box</tabstop>
<tabstop>boot_checkbox</tabstop>
<tabstop>start_btn</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
42 changes: 34 additions & 8 deletions WallDit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -60,15 +62,16 @@ 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")

if ('i.' not in url and 'imgur' in url) and url:
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
Expand All @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions WallDit_QT.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,52 @@ 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

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)

Expand Down
13 changes: 11 additions & 2 deletions output_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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)
Expand Down Expand Up @@ -96,13 +96,21 @@ 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)
self.horizontalLayout.addLayout(self.verticalLayout_3)

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))
Expand All @@ -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))

0 comments on commit 26b6d33

Please sign in to comment.