-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkflow.py
More file actions
97 lines (80 loc) · 2.96 KB
/
Copy pathworkflow.py
File metadata and controls
97 lines (80 loc) · 2.96 KB
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
from xml.etree import ElementTree
from xml.dom import minidom
from upload import imgur_Upload, dropbox_Upload, twitter_Upload
from edit_image import edit
from qr_code import generate_QRCode
import gtk
import subprocess
class Workflow(object):
def __init__(self, workflowNumber):
"""Initialize workflow settings based on workflow number"""
self.workflowNumber = workflowNumber
self.updateSettings()
self.keys = [False for key in self.hotkeys]
self.URL = ""
def run(self):
"""Activate the workflow"""
#Handle different capture methods
if self.capture_method == "def_rect":
subprocess.call(["/usr/bin/python2.7", "./capture.py"]) #Spawn a new process that takes a screenshot
#Handle things to do after capturing
if "edit" in self.after_capture:
edit("screenshot.png")
if "upload" in self.after_capture:
if "twitter" in self.destinations:
self.URL = twitter_Upload("screenshot.png", "Test of UploadX")
if "dropbox" in self.destinations:
self.URL = dropbox_Upload("screenshot.png", "screenshot.png")
if "imgur" in self.destinations:
self.URL = imgur_Upload("screenshot.png")
#Handle things to do after uploading
if "copy_link_to_clipboard" in self.after_upload:
if "upload" in self.after_capture:
clipboard = gtk.clipboard_get()
clipboard.set_text(self.URL)
clipboard.store()
if "generate_qr_code" in self.after_upload:
if "upload" in self.after_capture:
if self.URL != "":
generate_QRCode(self.URL)
def keyDown(self, key):
"""Register that a key was depressed"""
self.updateSettings()
if key in self.hotkeys:
self.keys[self.hotkeys.index(key)] = True
if all(key is True for key in self.keys): #If all keys are held down, run workflow
self.run()
def keyUp(self, key):
"""Register that a key was unpressed"""
if key in self.hotkeys:
self.keys[self.hotkeys.index(key)] = False
def updateSettings(self):
"""Re-Read settings from settings.xml to update parameters"""
self.settings = ElementTree.parse('settings.xml').getroot()
self.subsettings = self.settings.find('workflows').find('workflow' + str(self.workflowNumber)) #Find sub-branch of settings for this workflow
try:
self.destinations = self.settings.find('destinations').text.split(',') #Grab destinations from top level settings
except:
self.destinations = ""
try:
self.capture_method = self.subsettings.find('capture_method').text
except:
self.capture_method = ""
try:
old_len = len(self.hotkeys)
self.hotkeys = self.subsettings.find('hotkeys').text.split('+')
if old_len != len(self.hotkeys):
self.keys = [False for key in self.hotkeys]
except:
self.hotkeys = [""]
try:
self.after_capture = self.subsettings.find('after_capture').text.split(',')
except:
self.after_capture = [""]
try:
self.after_upload = self.subsettings.find('after_upload').text.split(',')
except:
self.after_upload = [""]
if __name__ == "__main__":
workflow1 = Workflow(1) #Workflow defined by number
workflow1.run()