forked from noelprint/noelshack-screencloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
42 lines (32 loc) · 1.15 KB
/
main.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
from PythonQt.QtCore import QFile
from PythonQt.QtGui import QDesktopServices, QMessageBox
import ScreenCloud
from pynoelshack import NoelShack, NoelShackError
import time
# Random string
import uuid
class NoelShackUploader():
def showSettingsUI(self, parentWidget):
QMessageBox.information(parentWidget,
'NoelShack',
'This plugin has no settings.')
def isConfigured(self):
return True
def getFilename(self):
# Random string (uuid4) that we split (-) for to take last section (4)
rnd = str(uuid.uuid4())
rndspl = rnd.split('-')
rnstr = rndspl[4]
return ScreenCloud.formatFilename(rnstr)
def upload(self, screenshot, name):
temp = QDesktopServices.storageLocation(QDesktopServices.TempLocation)
file = temp + '/' + name
screenshot.save(QFile(file), ScreenCloud.getScreenshotFormat())
ns = NoelShack()
try:
url = ns.upload(file)
except NoelShackError as e:
ScreenCloud.setError(str(e))
return False
ScreenCloud.setUrl(url)
return True