Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Solving few small issues #47

Merged
merged 5 commits into from Aug 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/data/preferences.xml
Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions src/liblookit.py
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/lookitconfig.py
Expand Up @@ -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': '',
Expand Down
68 changes: 64 additions & 4 deletions src/lookitindicator.py
Expand Up @@ -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:

Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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()
21 changes: 10 additions & 11 deletions src/uploader.py
Expand Up @@ -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')),
Expand All @@ -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')),
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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