From 688fe98e91192f5dcd8a2af36034fe62d488102a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Tue, 6 Mar 2012 06:51:39 +0100 Subject: [PATCH 1/4] Added option to temporary disable upload --- src/lookitconfig.py | 3 ++- src/lookitindicator.py | 24 +++++++++++++++++++++++- src/uploader.py | 11 +++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/lookitconfig.py b/src/lookitconfig.py index 61df7bb..9116afd 100644 --- a/src/lookitconfig.py +++ b/src/lookitconfig.py @@ -37,7 +37,8 @@ 'Hotkeys': {'capturearea': '4', 'capturescreen': '5', 'capturewindow': '6'}, - 'Upload': {'type': 'None', + 'Upload': {'enableupload': True, + 'type': 'None', 'hostname': '', 'port': 0, 'username': '', diff --git a/src/lookitindicator.py b/src/lookitindicator.py index efe8e22..e438286 100644 --- a/src/lookitindicator.py +++ b/src/lookitindicator.py @@ -12,7 +12,7 @@ from liblookit import enum cmd = enum('CAPTURE_AREA', 'CAPTURE_ACTIVE_WINDOW', 'CAPTURE_SCREEN', 'SHOW_PREFERENCES', 'SHOW_ABOUT', 'EXIT', - 'DELAY_0', 'DELAY_3', 'DELAY_5', 'DELAY_10') + 'DELAY_0', 'DELAY_3', 'DELAY_5', 'DELAY_10', 'TOGGLE_UPLOAD') class LookitIndicator: @@ -28,6 +28,8 @@ def __init__(self): self.add_menu_item('Capture Entire Screen', cmd.CAPTURE_SCREEN) self.add_menu_item('Capture Active Window', cmd.CAPTURE_ACTIVE_WINDOW) + self.add_menu_separator() + delaymenu = gtk.Menu() self.add_menu_item('0 seconds', cmd.DELAY_0, delaymenu) self.add_menu_item('3 seconds', cmd.DELAY_3, delaymenu) @@ -37,6 +39,11 @@ def __init__(self): sub.set_submenu(delaymenu) self.menu.append(sub) + + config = lookitconfig.LookitConfig() + enableupload = config.getboolean('Upload', 'enableupload') + self.add_check_menu_item('Upload to server', cmd.TOGGLE_UPLOAD, value=enableupload) + self.add_menu_separator() self.add_menu_item('Preferences', cmd.SHOW_PREFERENCES) self.add_menu_item('About', cmd.SHOW_ABOUT) @@ -53,6 +60,14 @@ def add_menu_item(self, label, command, menu=None): menu = self.menu menu.append(item) + def add_check_menu_item(self, label, command, menu=None, value=True): + item = gtk.CheckMenuItem(label) + item.set_active(value) + item.connect('activate', self.handle_menu_item, command) + if menu is None: + menu = self.menu + menu.append(item) + def add_menu_separator(self): item = gtk.SeparatorMenuItem() item.show() @@ -63,6 +78,11 @@ def set_delay(self, value): config.set('General', 'delay', value) config.save() + def set_upload(self, value): + config = lookitconfig.LookitConfig() + config.set('Upload', 'enableupload', value) + config.save() + def handle_menu_item(self, widget=None, command=None): if command == cmd.CAPTURE_AREA: liblookit.do_capture_area() @@ -84,6 +104,8 @@ def handle_menu_item(self, widget=None, command=None): self.set_delay(5) elif command == cmd.DELAY_10: self.set_delay(10) + elif command == cmd.TOGGLE_UPLOAD: + self.set_upload(widget.get_active()) else: print 'Error: reached end of handle_menu_item' diff --git a/src/uploader.py b/src/uploader.py index 5ee7d1b..5ccc7ea 100644 --- a/src/uploader.py +++ b/src/uploader.py @@ -207,8 +207,14 @@ def upload_file(image, existing_file=False): config = lookitconfig.LookitConfig() proto = config.get('Upload', 'type') + # Temporary disable upload + if not config.getboolean('Upload', 'enableupload'): + proto = 'None' - if proto == 'SSH': + if proto == 'None': + success = True + data = False + elif proto == 'SSH': liblookit.show_notification('Lookit', 'Uploading image to {0}...'.format(config.get('Upload', 'hostname'))) success, data = upload_file_sftp(image, config.get('Upload', 'hostname'), @@ -258,9 +264,6 @@ def upload_file(image, existing_file=False): success, data = upload_file_cloud(image, config.get('Upload', 'username'), config.get('Upload', 'password')) - elif proto == 'None': - success = True - data = False else: success = False data = "Error: no such protocol: {0}".format(proto) From 168443a8705d3b8249f113995ca62ea84c37d897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Tue, 6 Mar 2012 06:59:23 +0100 Subject: [PATCH 2/4] Set correct sensitivity to SSH Key file --- src/data/preferences.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/preferences.xml b/src/data/preferences.xml index 0ad5ddd..fd6c03e 100644 --- a/src/data/preferences.xml +++ b/src/data/preferences.xml @@ -581,6 +581,7 @@ True + False True False From b053cfa94edd535491706f7b431e1d43fae339b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Tue, 6 Mar 2012 07:02:39 +0100 Subject: [PATCH 3/4] Remove annoying slow notifications --- src/uploader.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/uploader.py b/src/uploader.py index 5ccc7ea..8280c58 100644 --- a/src/uploader.py +++ b/src/uploader.py @@ -215,7 +215,6 @@ def upload_file(image, existing_file=False): success = True data = False elif proto == 'SSH': - liblookit.show_notification('Lookit', 'Uploading image to {0}...'.format(config.get('Upload', 'hostname'))) success, data = upload_file_sftp(image, config.get('Upload', 'hostname'), int(config.get('Upload', 'port')), @@ -226,10 +225,8 @@ def upload_file(image, existing_file=False): config.get('Upload', 'url'), ) elif proto == 'HTTP': - liblookit.show_notification('Lookit', 'Upload image to {0}...'.format(config.get('Upload', 'URL'))) success, data = upload_file_http(image, config.get('Upload', 'URL')) elif proto == 'FTP': - liblookit.show_notification('Lookit', 'Uploading image to {0}...'.format(config.get('Upload', 'hostname'))) success, data = upload_file_ftp(image, config.get('Upload', 'hostname'), int(config.get('Upload', 'port')), @@ -239,7 +236,6 @@ def upload_file(image, existing_file=False): config.get('Upload', 'url'), ) elif proto == 'Omploader': - liblookit.show_notification('Lookit', 'Uploading image to Omploader...') success, data = upload_file_omploader(image) try: f = open(liblookit.LOG_FILE, 'ab') @@ -249,7 +245,6 @@ def upload_file(image, existing_file=False): finally: f.close() elif proto == 'Imgur': - liblookit.show_notification('Lookit', 'Uploading image to Imgur...') success, data = upload_file_imgur(image) try: f = open(liblookit.LOG_FILE, 'ab') @@ -260,7 +255,6 @@ def upload_file(image, existing_file=False): finally: f.close() elif proto == 'CloudApp': - liblookit.show_notification('Lookit', 'Uploading image to CloudApp...') success, data = upload_file_cloud(image, config.get('Upload', 'username'), config.get('Upload', 'password')) From bbff15b1412e884d3074482b6159cc078031cbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Tue, 6 Mar 2012 07:39:27 +0100 Subject: [PATCH 4/4] Remember 3 last screenshots --- src/liblookit.py | 6 +++--- src/lookitindicator.py | 46 ++++++++++++++++++++++++++++++++++++++---- src/uploader.py | 4 +++- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/liblookit.py b/src/liblookit.py index b1d6e76..4b8246c 100644 --- a/src/liblookit.py +++ b/src/liblookit.py @@ -65,17 +65,17 @@ def do_capture_area(): show_notification('Lookit', 'Selection cancelled') return pb = screencapper.capture_selection(selection) - uploader.upload_pixbuf(pb) + return uploader.upload_pixbuf(pb) def do_capture_window(): handle_delay() pb = screencapper.capture_active_window() - uploader.upload_pixbuf(pb) + return uploader.upload_pixbuf(pb) def do_capture_screen(): handle_delay() pb = screencapper.capture_screen() - uploader.upload_pixbuf(pb) + return uploader.upload_pixbuf(pb) def do_preferences(): preferences.PreferencesDialog().run() diff --git a/src/lookitindicator.py b/src/lookitindicator.py index e438286..5e84840 100644 --- a/src/lookitindicator.py +++ b/src/lookitindicator.py @@ -5,6 +5,8 @@ INDICATOR_SUPPORT = False import gtk +import time +import webbrowser import liblookit import lookitconfig @@ -13,6 +15,7 @@ cmd = enum('CAPTURE_AREA', 'CAPTURE_ACTIVE_WINDOW', 'CAPTURE_SCREEN', 'SHOW_PREFERENCES', 'SHOW_ABOUT', 'EXIT', 'DELAY_0', 'DELAY_3', 'DELAY_5', 'DELAY_10', 'TOGGLE_UPLOAD') +MAX_IMAGE_COUNTS = 3 class LookitIndicator: @@ -39,7 +42,6 @@ def __init__(self): sub.set_submenu(delaymenu) self.menu.append(sub) - config = lookitconfig.LookitConfig() enableupload = config.getboolean('Upload', 'enableupload') self.add_check_menu_item('Upload to server', cmd.TOGGLE_UPLOAD, value=enableupload) @@ -47,6 +49,10 @@ def __init__(self): self.add_menu_separator() self.add_menu_item('Preferences', cmd.SHOW_PREFERENCES) self.add_menu_item('About', cmd.SHOW_ABOUT) + + self.image_position = len(self.menu) + self.image_list = [] + self.add_menu_separator() self.add_menu_item('Exit', cmd.EXIT) @@ -83,13 +89,42 @@ def set_upload(self, value): config.set('Upload', 'enableupload', value) config.save() + def add_image(self, uri): + """ Add image into menu and throw away an old image """ + if len(self.image_list) == 0: + item = gtk.SeparatorMenuItem() + item.show() + self.menu.insert(item, self.image_position) + self.image_position += 1 + + if len(self.image_list) >= MAX_IMAGE_COUNTS: + item = self.image_list.pop(0) + self.menu.remove(item) + + label = time.strftime('%H:%M:%S') + item = gtk.MenuItem(label) + item.connect('activate', self.open_image, uri) + item.show() + position = self.image_position + len(self.image_list) + self.menu.insert(item, position) + self.image_list.append(item) + + def open_image(self, widget=None, uri=None): + """ Open image and copy URI into clipboard """ + clipboard = gtk.clipboard_get() + clipboard.set_text(uri) + clipboard.store() + + webbrowser.open(uri) + def handle_menu_item(self, widget=None, command=None): + uri = None if command == cmd.CAPTURE_AREA: - liblookit.do_capture_area() + uri = liblookit.do_capture_area() elif command == cmd.CAPTURE_ACTIVE_WINDOW: - liblookit.do_capture_window() + uri = liblookit.do_capture_window() elif command == cmd.CAPTURE_SCREEN: - liblookit.do_capture_screen() + uri = liblookit.do_capture_screen() elif command == cmd.SHOW_PREFERENCES: liblookit.do_preferences() elif command == cmd.SHOW_ABOUT: @@ -109,6 +144,9 @@ def handle_menu_item(self, widget=None, command=None): else: print 'Error: reached end of handle_menu_item' + if uri is not None: + self.add_image(uri) + if __name__ == '__main__': i = LookitIndicator() gtk.main() diff --git a/src/uploader.py b/src/uploader.py index 8280c58..3d09ce7 100644 --- a/src/uploader.py +++ b/src/uploader.py @@ -201,7 +201,7 @@ def upload_pixbuf(pb): pb.save_to_callback(ftmp.write, 'png') ftmp.flush() ftmp.close() - upload_file(ftmp.name) + return upload_file(ftmp.name) def upload_file(image, existing_file=False): config = lookitconfig.LookitConfig() @@ -302,6 +302,8 @@ def upload_file(image, existing_file=False): liblookit.show_notification('Lookit', 'Error: No upload type selected') else: liblookit.show_notification('Lookit', 'Image saved: ' + image) + return image else: liblookit.show_notification('Lookit', 'Upload complete: ' + url) + return url