-
Notifications
You must be signed in to change notification settings - Fork 0
/
SWG.py
147 lines (115 loc) · 4.26 KB
/
SWG.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from SaveToGoogleDrive import SaveToGoogleDrive
from datetime import datetime
from Utilities import File
import PyQt5.QtWidgets as Qtw
import PyQt5.QtGui as Qtg
import PyQt5.QtCore as Qtc
import json
import os
from threading import Thread
data = {
"syncTime": 'Not Yet',
"filesUploaded": []
}
try:
jsonfile = open("data.json")
data = json.load(jsonfile)
except FileNotFoundError:
with open('data.json', 'w') as fp:
json.dump(data, fp)
class MainWindow(Qtw.QWidget):
def __init__(self):
super().__init__()
self.destination_path = ""
# Add a title
self.setWindowTitle("Spotlight Wallpaper Grabber")
layout = Qtw.QFormLayout()
self.setLayout(layout)
self.setFont(Qtg.QFont("San Francisco", 10))
label = Qtw.QLabel("Save Wallpaper To ")
label.setFont(Qtg.QFont("San Francisco", 18))
# Path Entry Box
self.pathLabel = Qtw.QLineEdit(self)
# Browse Button
browseButton = Qtw.QPushButton("Browse")
browseButton.clicked.connect(lambda: self.browse())
# Save Button
self.saveButton = Qtw.QPushButton("Save")
self.saveButton.clicked.connect(lambda: Thread(target=self.execute).start())
# GDrive Connect Button
self.connectButton = Qtw.QPushButton("Connect")
self.connectButton.clicked.connect(lambda: Thread(target=self.connectToGDrive).start())
self.connectButton.setEnabled(False)
# GDrive Sync Button
self.syncButton = Qtw.QPushButton("Sync")
self.syncButton.clicked.connect(lambda: Thread(target=self.sync).start())
self.syncButton.setEnabled(False)
if os.path.exists('credentials.json'):
self.connectButton.setEnabled(True)
if os.path.exists('token.json'):
self.syncButton.setEnabled(True)
# Last Synced
lastSyncedLabel = Qtw.QLabel("Last Synced")
self.lastSyncedTimeLabel = Qtw.QLabel(data['syncTime'])
# Close Button
closeButton = Qtw.QPushButton("Close")
closeButton.clicked.connect(lambda: self.Close_all())
# Label HBox
HBox0 = Qtw.QHBoxLayout()
HBox0.addWidget(label)
# First HBox
HBox1 = Qtw.QHBoxLayout()
HBox1.addWidget(self.pathLabel)
HBox1.addWidget(browseButton)
HBox1.addWidget(self.saveButton)
# Second HBox
HBox2 = Qtw.QHBoxLayout()
HBox2.addWidget(self.connectButton)
HBox2.addWidget(self.syncButton)
# Third HBox
HBox3 = Qtw.QHBoxLayout()
HBox3.addWidget(lastSyncedLabel)
HBox3.addWidget(self.lastSyncedTimeLabel)
HBox3.setAlignment(Qtc.Qt.AlignCenter)
# Bottom HBox
HBottom = Qtw.QHBoxLayout()
HBottom.addWidget(closeButton)
HBottom.setAlignment(Qtc.Qt.AlignRight)
# Main Window Layout
layout.addRow(HBox0)
layout.addRow("Local Directory Path", HBox1)
layout.addRow("Google Drive", HBox2)
layout.addRow(HBox3)
layout.addRow(HBottom)
self.show()
def browse(self):
self.destination_path = Qtw.QFileDialog.getExistingDirectory()
self.pathLabel.setText(self.destination_path)
def connectToGDrive(self):
self.connectButton.setEnabled(False)
SaveToGoogleDrive()
self.connectButton.setEnabled(True)
if os.path.exists('token.json'):
self.syncButton.setEnabled(True)
def sync(self):
self.syncButton.setEnabled(False)
File().save_all(location='', dest='Googledrive')
self.syncButton.setEnabled(True)
with open("data.json") as jsonfile:
data = json.load(jsonfile)
data['syncTime'] = datetime.now().strftime("on %b %d %Y at %I:%M %p")
self.lastSyncedTimeLabel.setText(data['syncTime'])
with open('data.json', 'w') as fp:
json.dump(data, fp)
def Close_all(self):
self.close()
def execute(self):
self.saveButton.setEnabled(False)
if not self.destination_path:
self.browse()
if self.destination_path:
File().save_all(location=self.destination_path, dest='local')
self.saveButton.setEnabled(True)
app = Qtw.QApplication([])
mw = MainWindow()
app.exec_()