Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented ADVANCED (no, really) workflow. Increased code smell. Unf…

…uckedup readme.
  • Loading branch information...
commit b7c8d9295b1f6c6fcfcd1902c81c3fec0bfeac8d 1 parent 203afb7
@Xifax authored
Showing with 108 additions and 25 deletions.
  1. +37 −3 README.md
  2. +3 −3 src/hotkeys.py
  3. +68 −19 tuci.pyw
View
40 README.md
@@ -3,8 +3,42 @@ tuci
Tiny thingamabob for consuming suzu-web api. Will be probably rewritten in QT (if it actully installs using pip, eh).
-Inane requirements for Windows (as always):
+# Inane requirements for Windows (as always):
-<!--* pyhk (included)-->
* pywin32: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/pywin32-217.win32-py2.7.exe/download
-<!--* pyhook: http://sourceforge.net/projects/pyhook/files/latest/download?source=files-->
+
+# Workflow
+
+In case single items should be added:
+
+1. Launch app
+2. Copy item
+3. Press Ctrl+Alt+A to add it to web-app DB
+4. Repeat steps 2 to 3
+5. Middle click on notification to quit
+
+In case an example and corresponding items should be added:
+
+1. Launch app
+2. Copy example (if not autocopied)
+3. Ctrl+Alt+E to set active example
+4. Ctrl+Alt+A to add item corresponding to active example and restore example in clipboard
+5. Ctrl+Alt+S to add example and corresponding items to web-app DB
+6. Middle click to quit
+
+# P.S.
+
+As of now it is ugly (and code is smelly), but usable (at least, in windows). Hooray!
+
+# TODO:
+
+0. FREEEZE (or at the very least try to) as standalone exe, w/e
+1. Port to PyQT|PySide
+2. Show&hide notification on action
+3. Allow to move notification
+4. Reimplement hotkey hooker (pyhk is VERY laggy) to allow for single thread handling
+5. Write log
+6. Allow drag & drop
+7. Options and stuff
+8. Pretty fonts (should be number 1, but Tkinter, yeah)
+9. CAN I HAZ makefile with autodownloaded dependencies..?
View
6 src/hotkeys.py
@@ -25,9 +25,9 @@ def __init__(self, function, key):
def registerHotkey(self):
if not self.user32.RegisterHotKey(None, self.id, self.modifiers, self.vk):
- print "Unable to register id", id
+ print 'Unable to register id', id, '\n'
else:
- print 'registered ' + str(self.id) + ' ' + self.key
+ print 'registered ' + str(self.id) + ' ' + self.key + '\n'
def messageLoop(self):
try:
@@ -42,7 +42,7 @@ def messageLoop(self):
finally:
self.unregisterHotkeys()
- print 'ok'
+ print 'Hotkey unregistered\n'
def unregisterHotkeys(self):
self.user32.UnregisterHotKey(None, self.id)
View
87 tuci.pyw
@@ -30,18 +30,45 @@ from src.hotkeys import GlobalHotkeyManager
class Application(Frame):
+
+ def add_example(self):
+ try:
+ self.example = self.master.clipboard_get()
+ self.copied.set('Example: \n' + self.example)
+ except TclError:
+ pass
+
+ def send_item(self):
+ """Send request to web-app"""
+ if self.example and self.items:
+ self.copied.set('Sending items: \n' + ','.join(self.items))
+ sleep(1)
+ try:
+ # Perform request
+ reply = get(
+ 'http://suzu.herokuapp.com/add/%s/%s' % (self.example, '/'.join(self.items))
+ ).json
+ self.copied.set(
+ 'Result: %s\nError: %s' %
+ (reply.get('result'), reply.get('reason', 'None'))
+ )
+ except RequestException as e:
+ print e
+ self.example = None
+ else:
+ self.copied.set('No items to send')
+
def add_item(self):
contents = None
try:
# Try to get clipboard contents
# NB: alternatives: paperclip
#contents = root.clipboard_get()
-
+
#if 'normal' != self.master.state():
#self.master.update()
#self.master.deiconify()
contents = self.master.clipboard_get()
- self.copied.set('Adding: \n' + contents)
except TclError:
# Clipboard is empty
pass
@@ -49,22 +76,34 @@ class Application(Frame):
# Clipboard is not empty
if contents:
# In case of very fast response
- sleep(1)
- try:
- # Perform request
- reply = get(
- 'http://suzu.herokuapp.com/add/%s' % contents
- ).json
- #print reply.get('result'), reply.get('reason', '')
- # TODO: log|notify on reply
- self.copied.set(
- 'Result: %s\nError: %s' %
- (reply.get('result'), reply.get('reason', 'None'))
- )
- except RequestException as e:
- print e
- #self.after(1000, self.master.withdraw)
- #self.master.deiconify()
+ if not self.example:
+ self.copied.set('Adding: \n' + contents)
+ sleep(1)
+ try:
+ # Should add standalone item if no example
+ # Perform request
+ reply = get(
+ 'http://suzu.herokuapp.com/add/%s' % contents
+ ).json
+ #print reply.get('result'), reply.get('reason', '')
+ # TODO: log|notify on reply
+ self.copied.set(
+ 'Result: %s\nError: %s' %
+ (reply.get('result'), reply.get('reason', 'None'))
+ )
+ except RequestException as e:
+ print e
+ #self.after(1000, self.master.withdraw)
+ #self.master.deiconify()
+ else:
+ message = 'Adding items: \n' + contents
+ if self.items:
+ message += '\n[' + ','.join(self.items) + ']'
+ self.copied.set(message)
+ self.items.append(contents)
+ self.master.clipboard_clear()
+ self.master.clipboard_append(string=self.example)
+ sleep(1)
def createWidgets(self):
self.copied = StringVar()
@@ -87,11 +126,21 @@ class Application(Frame):
self.master.bind('<Button-2>', quit)
self.pack()
self.createWidgets()
- # Bind global hotkey
+ # Bind global hotkey(s)
self.hooker = GlobalHotkeyManager(self.add_item , 'A')
+ self.exampleHooker = GlobalHotkeyManager(self.add_example , 'E')
+ self.sendHooker = GlobalHotkeyManager(self.send_item, 'S')
# Should terminate with GUI
self.hooker.setDaemon(True)
self.hooker.start()
+ self.exampleHooker.setDaemon(True)
+ self.exampleHooker.start()
+ self.sendHooker.setDaemon(True)
+ self.sendHooker.start()
+
+ # example
+ self.example = None
+ self.items = []
if __name__ == '__main__':

0 comments on commit b7c8d92

Please sign in to comment.
Something went wrong with that request. Please try again.