aboutsummaryrefslogtreecommitdiffstats
path: root/lvc
diff options
context:
space:
mode:
authorJesús Eduardo <heckyel@hyperbola.info>2018-01-17 14:32:45 -0500
committerJesús Eduardo <heckyel@hyperbola.info>2018-01-17 14:32:45 -0500
commit403cc9605ffce315cb9476b044dbc0877c546dbd (patch)
treeb022b57a6b3a20b719f5a5cab8f309ee7f7d24e4 /lvc
parent7c6ef5aa86ed1171cb84a885109043aee90ec1a1 (diff)
downloadlibrevideoconverter-403cc9605ffce315cb9476b044dbc0877c546dbd.tar.lz
librevideoconverter-403cc9605ffce315cb9476b044dbc0877c546dbd.tar.xz
librevideoconverter-403cc9605ffce315cb9476b044dbc0877c546dbd.zip
pep8 en lvc/ui/widgets.py
Diffstat (limited to 'lvc')
-rw-r--r--lvc/ui/widgets.py232
1 files changed, 123 insertions, 109 deletions
diff --git a/lvc/ui/widgets.py b/lvc/ui/widgets.py
index 7849e2a..66f34b3 100644
--- a/lvc/ui/widgets.py
+++ b/lvc/ui/widgets.py
@@ -1,24 +1,20 @@
-import logging
-logging.basicConfig(level=logging.INFO)
-logger = logging.getLogger(__name__)
-
import os
import sys
-try:
- import lvc
-except ImportError:
- lvc_path = os.path.join(os.path.dirname(__file__), '..', '..')
- sys.path.append(lvc_path)
- import lvc
-
import copy
import tempfile
import urllib
import urlparse
+from lvc.converter import ConverterInfo
+from lvc.video import VideoFile
+from lvc.resources import image_path
+from lvc.utils import size_string, round_even, convert_path_for_subprocess
+from lvc import openfiles
+
from lvc.widgets import (initialize, idle_add, mainloop_start, mainloop_stop,
attach_menubar, reveal_file, get_conversion_directory)
+
from lvc.widgets import menus
from lvc.widgets import widgetset
from lvc.widgets import cellpack
@@ -26,17 +22,22 @@ from lvc.widgets import widgetconst
from lvc.widgets import widgetutil
from lvc.widgets import app
-from lvc.converter import ConverterInfo
-from lvc.video import VideoFile
-from lvc.resources import image_path
-from lvc.utils import size_string, round_even, convert_path_for_subprocess
-from lvc import openfiles
+import logging
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+
+try:
+ import lvc
+except ImportError:
+ lvc_path = os.path.join(os.path.dirname(__file__), '..', '..')
+ sys.path.append(lvc_path)
+ import lvc
BUTTON_FONT = widgetutil.font_scale_from_osx_points(15.0)
LARGE_FONT = widgetutil.font_scale_from_osx_points(13.0)
SMALL_FONT = widgetutil.font_scale_from_osx_points(10.0)
-DEFAULT_FONT="Helvetica"
+DEFAULT_FONT = "Helvetica"
CONVERT_TO_FONT = "Gill Sans Light"
CONVERT_TO_FONTSIZE = widgetutil.font_scale_from_osx_points(14.0)
@@ -54,8 +55,8 @@ DND_SMALL_FONTSIZE = widgetutil.font_scale_from_osx_points(12.0)
ITEM_TITLE_FONT = "Futura Medium"
ITEM_TITLE_FONTSIZE = widgetutil.font_scale_from_osx_points(13.0)
-ITEM_ICONS_FONT= "Century Gothic"
-ITEM_ICONS_FONTSIZE= widgetutil.font_scale_from_osx_points(10.0)
+ITEM_ICONS_FONT = "Century Gothic"
+ITEM_ICONS_FONTSIZE = widgetutil.font_scale_from_osx_points(10.0)
GRADIENT_TOP = widgetutil.css_to_color('#585f63')
GRADIENT_BOTTOM = widgetutil.css_to_color('#383d40')
@@ -71,6 +72,7 @@ TEXT_SHADOW = widgetutil.css_to_color('#000000')
TABLE_WIDTH, TABLE_HEIGHT = 470, 87
+
class CustomLabel(widgetset.Background):
def __init__(self, text=''):
widgetset.Background.__init__(self)
@@ -109,6 +111,7 @@ class CustomLabel(widgetset.Background):
def size_request(self, layout_manager):
return self.textbox(layout_manager).get_size()
+
class WebStyleButton(widgetset.CustomButton):
def __init__(self):
super(WebStyleButton, self).__init__()
@@ -141,16 +144,17 @@ class WebStyleButton(widgetset.CustomButton):
textbox.draw(context, 0, (context.height - size[1]) // 2,
context.width, context.height)
+
class FileDropTarget(widgetset.SolidBackground):
dropoff_on = widgetset.ImageDisplay(widgetset.Image(
- image_path("dropoff-icon-on.png")))
+ image_path("dropoff-icon-on.png")))
dropoff_off = widgetset.ImageDisplay(widgetset.Image(
- image_path("dropoff-icon-off.png")))
+ image_path("dropoff-icon-off.png")))
dropoff_small_on = widgetset.ImageDisplay(widgetset.Image(
- image_path("dropoff-icon-small-on.png")))
+ image_path("dropoff-icon-small-on.png")))
dropoff_small_off = widgetset.ImageDisplay(widgetset.Image(
- image_path("dropoff-icon-small-off.png")))
+ image_path("dropoff-icon-small-off.png")))
def __init__(self):
super(FileDropTarget, self).__init__()
@@ -174,7 +178,7 @@ class FileDropTarget(widgetset.SolidBackground):
self.small = False
def build_large_widgets(self):
- height = 40 # arbitrary, but the same for both
+ height = 40 # arbitrary, but the same for both
normal = widgetset.VBox(spacing=20)
normal.pack_start(widgetutil.align_center(self.dropoff_off,
top_pad=60))
@@ -198,14 +202,14 @@ class FileDropTarget(widgetset.SolidBackground):
top_pad=60))
hbox = widgetset.HBox(spacing=4)
hbox.pack_start(widgetutil.align_center(
- widgetset.Label("Release button to drop off",
- color=TEXT_COLOR)))
+ widgetset.Label("Release button to drop off",
+ color=TEXT_COLOR)))
hbox.set_size_request(-1, height)
drag.pack_start(hbox)
return normal, drag
def build_small_widgets(self):
- height = 40 # arbitrary, but the same for both
+ height = 40 # arbitrary, but the same for both
normal = widgetset.HBox(spacing=4)
normal.pack_start(widgetutil.align_middle(self.dropoff_small_off,
right_pad=7))
@@ -250,12 +254,13 @@ class FileDropTarget(widgetset.SolidBackground):
BUTTON_BACKGROUND = widgetutil.ThreeImageSurface('settings-base')
+
class SettingsButton(widgetset.CustomButton):
arrow_on = widgetset.ImageSurface(widgetset.Image(
- image_path('arrow-down-on.png')))
+ image_path('arrow-down-on.png')))
arrow_off = widgetset.ImageSurface(widgetset.Image(
- image_path('arrow-down-off.png')))
+ image_path('arrow-down-off.png')))
def __init__(self, name):
super(SettingsButton, self).__init__()
@@ -266,9 +271,9 @@ class SettingsButton(widgetset.CustomButton):
self.selected = False
if name != 'format':
self.surface_on = widgetset.ImageSurface(widgetset.Image(
- image_path('%s-icon-on.png' % name)))
+ image_path('%s-icon-on.png' % name)))
self.surface_off = widgetset.ImageSurface(widgetset.Image(
- image_path('%s-icon-off.png' % name)))
+ image_path('%s-icon-off.png' % name)))
if self.surface_on.height != self.surface_off.height:
raise ValueError('invalid surface: height mismatch')
self.image_padding = self.calc_image_padding(name)
@@ -397,7 +402,7 @@ class LabeledNumberEntry(widgetset.HBox):
class CustomOptions(widgetset.Background):
background = widgetset.ImageSurface(widgetset.Image(
- image_path('settings-dropdown-bottom-bg.png')))
+ image_path('settings-dropdown-bottom-bg.png')))
def __init__(self):
super(CustomOptions, self).__init__()
@@ -449,12 +454,12 @@ class CustomOptions(widgetset.Background):
hbox.pack_start(widgetutil.align(create_thumbnails, xalign=0.5),
expand=True)
# XXX: disabled until we can figure out how to do this properly.
- #button = widgetset.Button('...')
- #button.connect('clicked', self.on_destination_clicked)
- #reset = widgetset.Button('Reset')
- #reset.connect('clicked', self.on_destination_reset)
- #hbox.pack_start(button)
- #hbox.pack_start(reset)
+ # button = widgetset.Button('...')
+ # button.connect('clicked', self.on_destination_clicked)
+ # reset = widgetset.Button('Reset')
+ # reset.connect('clicked', self.on_destination_reset)
+ # hbox.pack_start(button)
+ # hbox.pack_start(reset)
return widgetutil.align(hbox, xscale=1.0, yalign=0.5)
def _get_save_to_path(self):
@@ -482,12 +487,12 @@ class CustomOptions(widgetset.Background):
self.width_widget = LabeledNumberEntry('Width')
self.width_widget.connect('focus-out', self.on_width_changed)
self.width_widget.entry.connect('activate',
- self.on_width_changed)
+ self.on_width_changed)
self.width_widget.disable()
self.height_widget = LabeledNumberEntry('Height')
self.height_widget.connect('focus-out', self.on_height_changed)
self.height_widget.entry.connect('activate',
- self.on_height_changed)
+ self.on_height_changed)
self.height_widget.disable()
bottom.pack_start(self.width_widget)
bottom.pack_start(self.height_widget)
@@ -608,7 +613,7 @@ class CustomOptions(widgetset.Background):
def on_destination_clicked(self, widget):
dialog = widgetset.DirectorySelectDialog('Destination Directory')
r = dialog.run()
- if r == 0: # picked a directory
+ if r == 0: # picked a directory
self._change_setting('destination', directory)
def on_destination_reset(self, widget):
@@ -669,19 +674,19 @@ EMPTY_CONVERTER = ConverterInfo("")
class ConversionModel(widgetset.TableModel):
def __init__(self):
super(ConversionModel, self).__init__(
- 'text', # filename
- 'numeric', # output_size
- 'text', # converter
- 'text', # status
- 'numeric', # duration
- 'numeric', # progress
- 'numeric', # eta,
- 'object', # image
- 'object', # the actual conversion
+ 'text', # filename
+ 'numeric', # output_size
+ 'text', # converter
+ 'text', # status
+ 'numeric', # duration
+ 'numeric', # progress
+ 'numeric', # eta,
+ 'object', # image
+ 'object', # the actual conversion
)
self.conversion_to_iter = {}
self.thumbnail_to_image = {None: widgetset.Image(
- image_path('audio.png'))}
+ image_path('audio.png'))}
def conversions(self):
return iter(self.conversion_to_iter)
@@ -719,9 +724,9 @@ class ConversionModel(widgetset.TableModel):
conversion.duration or 0,
conversion.progress or 0,
conversion.eta or 0,
- self.get_image(conversion.video.get_thumbnail(complete, 90, 70)),
- conversion
- )
+ self.get_image(conversion.video.get_thumbnail(complete,
+ 90, 70)),
+ conversion)
iter_ = self.conversion_to_iter.get(conversion)
if iter_ is None:
self.conversion_to_iter[conversion] = self.append(*values)
@@ -758,25 +763,25 @@ class ConversionCellRenderer(widgetset.CustomCellRenderer):
IGNORE_PADDING = True
clear = widgetset.ImageSurface(widgetset.Image(
- image_path("clear-icon.png")))
+ image_path("clear-icon.png")))
converted_to = widgetset.ImageSurface(widgetset.Image(
- image_path("converted_to-icon.png")))
+ image_path("converted_to-icon.png")))
queued = widgetset.ImageSurface(widgetset.Image(
- image_path("queued-icon.png")))
+ image_path("queued-icon.png")))
showfile = widgetset.ImageSurface(widgetset.Image(
- image_path("showfile-icon.png")))
+ image_path("showfile-icon.png")))
show_ffmpeg = widgetset.ImageSurface(widgetset.Image(
- image_path("error-icon.png")))
+ image_path("error-icon.png")))
progressbar_base = widgetset.ImageSurface(widgetset.Image(
- image_path("progressbar-base.png")))
+ image_path("progressbar-base.png")))
delete_on = widgetset.ImageSurface(widgetset.Image(
- image_path("item-delete-button-on.png")))
+ image_path("item-delete-button-on.png")))
delete_off = widgetset.ImageSurface(widgetset.Image(
- image_path("item-delete-button-off.png")))
+ image_path("item-delete-button-off.png")))
error = widgetset.ImageSurface(widgetset.Image(
- image_path("item-error.png")))
+ image_path("item-error.png")))
completed = widgetset.ImageSurface(widgetset.Image(
- image_path("item-completed.png")))
+ image_path("item-completed.png")))
def __init__(self):
super(ConversionCellRenderer, self).__init__()
@@ -871,16 +876,16 @@ class ConversionCellRenderer(widgetset.CustomCellRenderer):
width = max(int(percent * self.progressbar_base.width),
5)
stack.pack(cellpack.DrawingArea(
- width, self.progressbar_base.height,
- self.draw_progressbar, width))
+ width, self.progressbar_base.height,
+ self.draw_progressbar, width))
box.pack(cellpack.Alignment(stack,
yalign=0.5,
xscale=0, yscale=0))
textbox = layout_manager.textbox("%d%%" % (
- 100 * percent))
+ 100 * percent))
box.pack(textbox)
return box
- elif self.status == 'initialized': # queued
+ elif self.status == 'initialized': # queued
vbox = cellpack.VBox()
vbox.pack_space(2)
vbox.pack(IconWithText(self.queued,
@@ -906,20 +911,20 @@ class ConversionCellRenderer(widgetset.CustomCellRenderer):
else:
text = 'Canceled - Show FFmpeg Output'
top.pack(cellpack.Hotspot('show-log', IconWithText(
- self.show_ffmpeg,
- layout_manager.textbox(text, underline=True))))
+ self.show_ffmpeg,
+ layout_manager.textbox(text, underline=True))))
color = TEXT_CLICKED if hotspot == 'clear' else TEXT_COLOR
layout_manager.set_text_color(color)
top.pack(cellpack.Hotspot('clear', IconWithText(
- self.showfile,
- layout_manager.textbox('Clear', underline=True))))
+ self.showfile,
+ layout_manager.textbox('Clear', underline=True))))
vbox.pack(top)
if self.status == 'finished':
layout_manager.set_text_color(TEXT_INFO)
vbox.pack(IconWithText(
- self.converted_to,
- layout_manager.textbox("Converted to %s" % (
- size_string(self.output_size)))))
+ self.converted_to,
+ layout_manager.textbox("Converted to %s" % (
+ size_string(self.output_size)))))
return vbox
def hotspot_test(self, style, layout_manager, x, y, width, height):
@@ -929,15 +934,16 @@ class ConversionCellRenderer(widgetset.CustomCellRenderer):
if hotspot_info:
return hotspot_info[0]
+
class ConvertButton(widgetset.CustomButton):
off = widgetset.ImageSurface(widgetset.Image(
- image_path("convert-button-off.png")))
+ image_path("convert-button-off.png")))
clear = widgetset.ImageSurface(widgetset.Image(
- image_path("convert-button-off.png")))
+ image_path("convert-button-off.png")))
on = widgetset.ImageSurface(widgetset.Image(
- image_path("convert-button-on.png")))
+ image_path("convert-button-on.png")))
stop = widgetset.ImageSurface(widgetset.Image(
- image_path("convert-button-stop.png")))
+ image_path("convert-button-stop.png")))
def __init__(self):
super(ConvertButton, self).__init__()
@@ -1001,6 +1007,7 @@ class ConvertButton(widgetset.CustomButton):
yalign=0.5, yscale=0)
alignment.render_layout(context)
+
# XXX do we want to export this for general purpose use?
class TextDialog(widgetset.Dialog):
def __init__(self, title, description, window):
@@ -1018,6 +1025,7 @@ class TextDialog(widgetset.Dialog):
def set_text(self, text):
self.textbox.set_text(text)
+
class Application(lvc.Application):
def __init__(self, simultaneous=None):
lvc.Application.__init__(self, simultaneous)
@@ -1050,10 +1058,10 @@ class Application(lvc.Application):
self.table.set_show_headers(False)
c = widgetset.TableColumn("Data", ConversionCellRenderer(),
- **dict((n, v) for (v, n) in enumerate((
- 'input', 'output_size', 'converter', 'status',
- 'duration', 'progress', 'eta', 'thumbnail',
- 'conversion'))))
+ **dict((n, v) for (v, n) in enumerate((
+ 'input', 'output_size', 'converter',
+ 'status', 'duration', 'progress',
+ 'eta', 'thumbnail', 'conversion'))))
c.set_min_width(TABLE_WIDTH)
self.table.add_column(c)
self.table.connect('hotspot-clicked', self.hotspot_clicked)
@@ -1150,8 +1158,8 @@ class Application(lvc.Application):
self.convert_button.connect('clicked', self.convert)
bottom_box.pack_start(widgetutil.align(self.convert_button,
- xalign=0.5, yalign=0.5,
- top_pad=50, bottom_pad=50))
+ xalign=0.5, yalign=0.5,
+ top_pad=50, bottom_pad=50))
bottom.set_child(widgetutil.pad(bottom_box, left=20, right=20))
vbox.pack_start(bottom)
self.window.set_content_widget(vbox)
@@ -1211,7 +1219,7 @@ class Application(lvc.Application):
def choose_file(self):
dialog = widgetset.FileOpenDialog('Choose Files...')
dialog.set_select_multiple(True)
- if dialog.run() == 0: # success
+ if dialog.run() == 0: # success
for filename in dialog.get_filenames():
self.file_activated(None, filename)
dialog.destroy()
@@ -1230,8 +1238,10 @@ class Application(lvc.Application):
def _generate_suboptions_menu(self, widget, options):
submenu = []
for option, id_ in options:
- callback = lambda x, i: self.on_select_converter(widget,
- options[i][1])
+ def callback(x, i):
+ return self.on_select_converter(widget, options[i][1])
+ # callback = lambda x, i: self.on_select_converter(widget,
+ # options[i][1])
value = (option, callback)
submenu.append(value)
return submenu
@@ -1243,8 +1253,10 @@ class Application(lvc.Application):
if isinstance(submenu, list):
callback = self._generate_suboptions_menu(widget, submenu)
else:
- callback = lambda x, i: self.on_select_converter(widget,
- options[i][1])
+ def callback(x, i):
+ return self.on_select_converter(widget, options[i][1])
+ # callback = lambda x, i: self.on_select_converter(widget,
+ # options[i][1])
value = (option, callback)
optionlist.append(value)
menu = widgetset.ContextMenu(optionlist)
@@ -1272,7 +1284,7 @@ class Application(lvc.Application):
# been set.
# the converter has not been set.
if ((self.current_converter is EMPTY_CONVERTER and has_conversions) or
- all_done):
+ all_done):
for m in self.menus:
m.set_selected(True)
self.settings_button.set_selected(True)
@@ -1288,12 +1300,12 @@ class Application(lvc.Application):
if all_done:
self.convert_button.set_clear()
elif (self.current_converter is EMPTY_CONVERTER or not
- (can_cancel or can_start)):
+ (can_cancel or can_start)):
self.convert_button.set_off()
elif (self.current_converter is not EMPTY_CONVERTER and
- self.options.options['custom-size'] and
- (not self.options.options['width'] or
- not self.options.options['height'])):
+ self.options.options['custom-size'] and
+ (not self.options.options['width'] or
+ not self.options.options['height'])):
self.convert_button.set_off()
else:
self.convert_button.set_on()
@@ -1314,17 +1326,17 @@ class Application(lvc.Application):
return
# XXX disabled - don't want to allow individualized file outputs
# since the workflow isn't entirely clear for now.
- #if self.options.options['destination'] is None:
- # try:
- # tempfile.TemporaryFile(dir=os.path.dirname(filename))
- # except EnvironmentError:
- # # can't write to the destination directory; ask for a new one
- # self.options.on_destination_clicked(None)
+ # if self.options.options['destination'] is None:
+ # try:
+ # tempfile.TemporaryFile(dir=os.path.dirname(filename))
+ # except EnvironmentError:
+ # # can't write to the destination directory; ask for a new one
+ # self.options.on_destination_clicked(None)
try:
vf = VideoFile(filename)
except ValueError:
logging.info('invalid file %r, cannot parse', filename,
- exc_info=True)
+ exc_info=True)
return
c = self.conversion_manager.get_conversion(
vf,
@@ -1397,9 +1409,9 @@ class Application(lvc.Application):
if self.current_converter is not EMPTY_CONVERTER:
valid_resolution = True
if (self.options.options['custom-size'] and
- not (self.options.options['width'] and
- self.options.options['height'])):
- valid_resolution = False
+ not (self.options.options['width'] and
+ self.options.options['height'])):
+ valid_resolution = False
if valid_resolution:
for conversion in self.model.conversions():
if conversion.status == 'initialized':
@@ -1408,7 +1420,8 @@ class Application(lvc.Application):
# all done: no conversion job should be running at this point
all_done = self.model.all_conversions_done()
if all_done:
- # take stuff off one by one from the list until we have none!
+ # take stuff off one by one from the list
+ # until we have none!
# might not be very efficient.
iter_ = self.model.first_iter()
while iter_ is not None:
@@ -1502,13 +1515,14 @@ class Application(lvc.Application):
return
if (self.current_converter.identifier != 'custom' and
- setting != 'create-thumbnails'):
+ setting != 'create-thumbnails'):
if hasattr(self.current_converter, 'simple'):
self.current_converter = self.current_converter.simple(
self.current_converter.name)
else:
if self.current_converter is EMPTY_CONVERTER:
- self.current_converter = copy.copy(self.converter_manager.get_by_id('sameformat'))
+ self.current_converter = copy.copy(
+ self.converter_manager.get_by_id('sameformat'))
else:
self.current_converter = copy.copy(self.current_converter)
# If the current converter name is resize only, then we don't
@@ -1517,7 +1531,7 @@ class Application(lvc.Application):
self.current_converter.name = 'Custom'
self.current_converter.width = self.options.options['width']
self.current_converter.height = self.options.options['height']
- self.converter_changed(self.menus[-1]) # formats menu
+ self.converter_changed(self.menus[-1]) # formats menu
if setting in ('width', 'height'):
setattr(self.current_converter, setting, value)
elif setting == 'custom-size':