Browse files

Merge pull request #47 from iyonius/master

Solving few small issues
  • Loading branch information...
2 parents 32a2357 + 5a8603a commit 097f7aa15d189637a439de0f5ade4e20979a4040 @zachtib committed Aug 3, 2012
Showing with 80 additions and 19 deletions.
  1. +1 −0 src/data/preferences.xml
  2. +3 −3 src/liblookit.py
  3. +2 −1 src/lookitconfig.py
  4. +64 −4 src/lookitindicator.py
  5. +10 −11 src/uploader.py
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,14 +5,17 @@
INDICATOR_SUPPORT = False
import gtk
+import time
+import webbrowser
import liblookit
import lookitconfig
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

0 comments on commit 097f7aa

Please sign in to comment.