Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Solving few small issues #47

Merged
merged 5 commits into from

2 participants

@izidormatusov

I love lookit and would contribute to it. My changes are:

  • Added option to temporary disable upload (Issue #46)
  • Set correct sensitivity to SSH Key file
  • Remove annoying slow notifications (I had to wait about 5 seconds until the first notification is away and I am sure the image was uploaded. The second notification is enough in my opinion)
  • Remember 3 last screenshots (Issue #43)
@izidormatusov

Is there any blocker why not to merge my changes? I would be glad to correct them :)

@zachtib
Owner

Hey, sorry, I'm really bad at paying attention to these pull requests :) Could you confirm that the same changes still work properly with the current source, and if so, I'll go ahead and merge them in.

Thanks

@izidormatusov

Yes, it works with the current master branch.

@zachtib zachtib merged commit 097f7aa into zachtib:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  src/data/preferences.xml
@@ -581,6 +581,7 @@
<child>
<object class="GtkEntry" id="ssh_key_file">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
<property name="primary_icon_activatable">False</property>
View
6 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()
View
3  src/lookitconfig.py
@@ -37,7 +37,8 @@
'Hotkeys': {'capturearea': '<Control><Alt>4',
'capturescreen': '<Control><Alt>5',
'capturewindow': '<Control><Alt>6'},
- 'Upload': {'type': 'None',
+ 'Upload': {'enableupload': True,
+ 'type': 'None',
'hostname': '',
'port': 0,
'username': '',
View
68 src/lookitindicator.py
@@ -5,6 +5,8 @@
INDICATOR_SUPPORT = False
import gtk
+import time
+import webbrowser
import liblookit
import lookitconfig
@@ -12,7 +14,8 @@
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')
+MAX_IMAGE_COUNTS = 3
class LookitIndicator:
@@ -28,6 +31,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,9 +42,17 @@ 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)
+
+ self.image_position = len(self.menu)
+ self.image_list = []
+
self.add_menu_separator()
self.add_menu_item('Exit', cmd.EXIT)
@@ -53,6 +66,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,13 +84,47 @@ 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 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:
@@ -84,9 +139,14 @@ 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'
+ if uri is not None:
+ self.add_image(uri)
+
if __name__ == '__main__':
i = LookitIndicator()
gtk.main()
View
21 src/uploader.py
@@ -201,15 +201,20 @@ 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()
proto = config.get('Upload', 'type')
+ # Temporary disable upload
+ if not config.getboolean('Upload', 'enableupload'):
+ proto = 'None'
- if proto == 'SSH':
- liblookit.show_notification('Lookit', 'Uploading image to {0}...'.format(config.get('Upload', 'hostname')))
+ if proto == 'None':
+ success = True
+ data = False
+ elif proto == 'SSH':
success, data = upload_file_sftp(image,
config.get('Upload', 'hostname'),
int(config.get('Upload', 'port')),
@@ -220,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')),
@@ -233,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')
@@ -243,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')
@@ -254,13 +255,9 @@ 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'))
- elif proto == 'None':
- success = True
- data = False
else:
success = False
data = "Error: no such protocol: {0}".format(proto)
@@ -305,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
Something went wrong with that request. Please try again.