Commit e73114c0 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

[preview] Cleanup code

parent 1a690149
......@@ -91,8 +91,8 @@ class UrlImagePreviewConfigDialog(SettingsDialog):
]
SettingsDialog.__init__(self, parent, _('UrlImagePreview Configuration'),
Gtk.DialogFlags.MODAL, settings, None,
extend=[
Gtk.DialogFlags.MODAL, settings, None,
extend=[
('PreviewSizeSpinSetting', SizeSpinSetting)])
def on_setting(self, value, data):
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-open</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-save-as</property>
</object>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-copy</property>
</object>
<object class="GtkImage" id="image4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">emblem-symbolic-link</property>
</object>
<object class="GtkImage" id="image5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">emblem-symbolic-link</property>
</object>
<object class="GtkImage" id="image6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">folder-download</property>
</object>
<requires lib="gtk+" version="3.20"/>
<object class="GtkMenu" id="context_menu">
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="open_menuitem">
<property name="label" translatable="yes">_Open</property>
<object class="GtkMenuItem" id="open_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Open</property>
<property name="use_underline">True</property>
<property name="image">image1</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="save_as_menuitem">
<property name="label" translatable="yes">_Save as</property>
<object class="GtkMenuItem" id="save_as_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Save as</property>
<property name="use_underline">True</property>
<property name="image">image2</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="open_folder_menuitem">
<property name="label" translatable="yes">Open _Folder</property>
<object class="GtkMenuItem" id="open_folder_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Open _Folder</property>
<property name="use_underline">True</property>
<property name="image">image6</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
</object>
</child>
<child>
......@@ -74,25 +35,19 @@
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="copy_link_location_menuitem">
<property name="label" translatable="yes">_Copy Link Location</property>
<object class="GtkMenuItem" id="copy_link_location_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Copy Link</property>
<property name="use_underline">True</property>
<property name="image">image3</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="open_link_in_browser_menuitem">
<property name="label" translatable="yes">Open Link in _Browser</property>
<object class="GtkMenuItem" id="open_link_in_browser_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Open Link in _Browser</property>
<property name="use_underline">True</property>
<property name="image">image4</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
</object>
</child>
<child>
......@@ -102,14 +57,11 @@
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="open_file_in_browser_menuitem">
<property name="label" translatable="yes">Open _Downloaded File in Browser</property>
<object class="GtkMenuItem" id="open_file_in_browser_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Open _Downloaded File in Browser</property>
<property name="use_underline">True</property>
<property name="image">image5</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
</object>
</child>
</object>
......
......@@ -47,17 +47,17 @@ def _get_http_head_direct(url, verify):
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
log.warning('CERT Verification disabled')
f = urllib2.urlopen(req, timeout=30, context=context)
file_ = urllib2.urlopen(req, timeout=30, context=context)
else:
if os.name == 'nt':
f = urllib2.urlopen(req, cafile=certifi.where())
file_ = urllib2.urlopen(req, cafile=certifi.where())
else:
f = urllib2.urlopen(req)
file_ = urllib2.urlopen(req)
except Exception as ex:
log.debug('Error', exc_info=True)
return ('', 0)
ctype = f.headers['Content-Type']
clen = f.headers['Content-Length']
ctype = file_.headers['Content-Type']
clen = file_.headers['Content-Length']
try:
clen = int(clen)
except (TypeError, ValueError):
......@@ -65,10 +65,10 @@ def _get_http_head_direct(url, verify):
return (ctype, clen)
def _get_http_direct(attrs):
"""
'''
Download a file. This function should
be launched in a separated thread.
"""
'''
log.info('Get request direct for URL: %s', attrs['src'])
mem, alt, max_size = b'', '', 2 * 1024 * 1024
if 'max_size' in attrs:
......@@ -81,12 +81,12 @@ def _get_http_direct(attrs):
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
log.warning('CERT Verification disabled')
f = urllib2.urlopen(req, timeout=30, context=context)
file_ = urllib2.urlopen(req, timeout=30, context=context)
else:
if os.name == 'nt':
f = urllib2.urlopen(req, cafile=certifi.where())
file_ = urllib2.urlopen(req, cafile=certifi.where())
else:
f = urllib2.urlopen(req)
file_ = urllib2.urlopen(req)
except Exception as ex:
log.debug('Error', exc_info=True)
pixbuf = None
......@@ -94,7 +94,7 @@ def _get_http_direct(attrs):
else:
while True:
try:
temp = f.read(100)
temp = file_.read(100)
except socket.timeout as ex:
log.debug('Timeout loading image %s', attrs['src'] + str(ex))
alt = attrs.get('alt', '')
......
......@@ -17,11 +17,11 @@ def resize_gif(mem, path, resize_to):
def analyse_image(mem):
"""
'''
Pre-process pass over the image to determine the mode (full or additive).
Necessary as assessing single frames isn't reliable. Need to know the mode
before processing all frames.
"""
'''
image = Image.open(BytesIO(mem))
results = {
'size': image.size,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment