Commit 01295e53 authored by Thibault Saunier's avatar Thibault Saunier

autopep8 WORKS, let's just use it!

https://bugzilla.gnome.org/show_bug.cgi?id=739251
parent d74c0e8d
......@@ -46,6 +46,7 @@ import pitivi.utils.loggable as log
class Pitivi(Gtk.Application, Loggable):
"""
Pitivi's application.
......@@ -82,7 +83,8 @@ class Pitivi(Gtk.Application, Loggable):
uri = quote_uri(os.environ['PITIVI_SCENARIO_FILE'])
else:
cache_dir = get_dir(os.path.join(xdg_cache_home(), "scenarios"))
uri = os.path.join(cache_dir, str(time.strftime("%Y%m%d-%H%M%S")) + ".scenario")
uri = os.path.join(
cache_dir, str(time.strftime("%Y%m%d-%H%M%S")) + ".scenario")
uri = quote_uri(uri)
self._first_action = True
self.log_file = open(path_from_uri(uri), "w")
......@@ -98,7 +100,8 @@ class Pitivi(Gtk.Application, Loggable):
def write_action(self, structure):
if self._first_action:
self.log_file.write("description, seek=true, handles-states=true\n")
self.log_file.write(
"description, seek=true, handles-states=true\n")
self._first_action = False
self.log_file.write(structure.to_string() + "\n")
......@@ -106,7 +109,8 @@ class Pitivi(Gtk.Application, Loggable):
def _startupCb(self, unused_app):
# Init logging as early as possible so we can log startup code
enable_color = not os.environ.get('PITIVI_DEBUG_NO_COLOR', '0') in ('', '1')
enable_color = not os.environ.get(
'PITIVI_DEBUG_NO_COLOR', '0') in ('', '1')
# Let's show a human-readable Pitivi debug output by default, and only
# show a crazy unreadable mess when surrounded by gst debug statements.
enable_crack_output = "GST_DEBUG" in os.environ
......@@ -125,7 +129,8 @@ class Pitivi(Gtk.Application, Loggable):
self.timeline_log_observer = TimelineLogObserver(self.action_log)
self.project_log_observer = ProjectLogObserver(self.action_log)
self.project_manager.connect("new-project-loaded", self._newProjectLoaded)
self.project_manager.connect(
"new-project-loaded", self._newProjectLoaded)
self.project_manager.connect("project-closed", self._projectClosed)
self._createActions()
......@@ -179,7 +184,8 @@ class Pitivi(Gtk.Application, Loggable):
assert giofiles
self.createMainWindow()
if len(giofiles) > 1:
self.warning("Can open only one project file at a time. Ignoring the rest!")
self.warning(
"Can open only one project file at a time. Ignoring the rest!")
project_file = giofiles[0]
self.project_manager.loadProject(quote_uri(project_file.get_uri()))
return True
......@@ -194,7 +200,8 @@ class Pitivi(Gtk.Application, Loggable):
self.debug("shutting down")
# Refuse to close if we are not done with the current project.
if not self.project_manager.closeRunningProject():
self.warning("Not closing since running project doesn't want to close")
self.warning(
"Not closing since running project doesn't want to close")
return False
if self.welcome_wizard:
self.welcome_wizard.hide()
......@@ -245,12 +252,15 @@ class Pitivi(Gtk.Application, Loggable):
self.info("Latest software version is %s", current_version)
VERSION_split = [int(i) for i in VERSION.split(".")]
current_version_split = [int(i) for i in current_version.split(".")]
current_version_split = [int(i)
for i in current_version.split(".")]
if VERSION_split > current_version_split:
status = "CURRENT"
self.info("Running version %s, which is newer than the latest known version. Considering it as the latest current version.", VERSION)
self.info(
"Running version %s, which is newer than the latest known version. Considering it as the latest current version.", VERSION)
elif status is "UNSUPPORTED":
self.warning("Using an outdated version of Pitivi (%s)", VERSION)
self.warning(
"Using an outdated version of Pitivi (%s)", VERSION)
self._version_information["current"] = current_version
self._version_information["status"] = status
......
......@@ -213,12 +213,13 @@ def affinealign(reference, targets, max_drift=0.02):
for t in targets:
t -= numpy.mean(t)
ft = numpy.fft.rfft(t, L2)
#fxcorr is the FFT'd cross-correlation with the reference blocks
# fxcorr is the FFT'd cross-correlation with the reference blocks
fxcorr_blocks = numpy.zeros((L2 / 2 + 1, num_blocks),
dtype=numpy.complex)
for i in range(num_blocks):
fxcorr_blocks[:, i] = ft * freference_blocks[:, i]
fxcorr_blocks[:, i] /= numpy.sqrt(numpy.sum(fxcorr_blocks[:, i] ** 2))
fxcorr_blocks[:, i] /= numpy.sqrt(
numpy.sum(fxcorr_blocks[:, i] ** 2))
del ft
# At this point xcorr_blocks would show a distinct bright line, nearly
# orthogonal to time, indicating where each of these blocks found their
......@@ -253,16 +254,17 @@ def affinealign(reference, targets, max_drift=0.02):
halfautocorr[-1:2, -1:2] = 0 # NEEDS TUNING
# Normalize each column (appears to be necessary)
for i in range(2 * num_blocks):
halfautocorr[:, i] /= numpy.sqrt(numpy.sum(halfautocorr[:, i] ** 2))
#from matplotlib.pyplot import imshow,show
#imshow(halfautocorr,interpolation='nearest',aspect='auto');show()
halfautocorr[:, i] /= numpy.sqrt(
numpy.sum(halfautocorr[:, i] ** 2))
# from matplotlib.pyplot import imshow,show
# imshow(halfautocorr,interpolation='nearest',aspect='auto');show()
drift = _findslope(halfautocorr) / bspace
del halfautocorr
#inverse transform and shift everything into alignment
# inverse transform and shift everything into alignment
xcorr_blocks = numpy.fft.irfft(fxcorr_blocks, None, 0)
del fxcorr_blocks
#TODO: see if phase ramps are worthwhile here
# TODO: see if phase ramps are worthwhile here
for i in range(num_blocks):
blockcenter = i * bspace + bsize / 2
shift = int(blockcenter * drift)
......@@ -275,16 +277,16 @@ def affinealign(reference, targets, max_drift=0.02):
xcorr_blocks[-shift:, i] = xcorr_blocks[:shift, i].copy()
xcorr_blocks[:-shift, i] = temp
#from matplotlib.pyplot import imshow,show
#imshow(xcorr_blocks,interpolation='nearest',aspect='auto');show()
# from matplotlib.pyplot import imshow,show
# imshow(xcorr_blocks,interpolation='nearest',aspect='auto');show()
# xcorr is the drift-compensated cross-correlation
xcorr = numpy.sum(xcorr_blocks, axis=1)
del xcorr_blocks
offset = numpy.argmax(xcorr)
#from matplotlib.pyplot import plot,show
#plot(xcorr);show()
# from matplotlib.pyplot import plot,show
# plot(xcorr);show()
del xcorr
if offset >= len(t):
offset -= L2
......@@ -576,13 +578,15 @@ class AutoAligner(Loggable):
for clip, audiotrack in pairs:
# blocksize is the number of samples per block
blocksize = audiotrack.stream.rate // self.BLOCKRATE
extractee = EnvelopeExtractee(blocksize, self._envelopeCb, clip)
extractee = EnvelopeExtractee(
blocksize, self._envelopeCb, clip)
# numsamples is the total number of samples in the track,
# which is used by progress_aggregator to determine
# the percent completion.
numsamples = ((audiotrack.duration / Gst.SECOND) *
audiotrack.stream.rate)
extractee.addWatcher(progress_aggregator.getPortionCB(numsamples))
extractee.addWatcher(
progress_aggregator.getPortionCB(numsamples))
self._extraction_stack.append((audiotrack, extractee))
# After we return, start the extraction cycle.
# This GLib.idle_add call should not be necessary;
......@@ -647,13 +651,15 @@ class AutoAligner(Loggable):
class AlignmentProgressDialog:
""" Dialog indicating the progress of the auto-alignment process.
Code derived from L{RenderingProgressDialog}, but greatly simplified
(read-only, no buttons)."""
def __init__(self, app):
self.builder = Gtk.Builder()
self.builder.add_from_file(os.path.join(configure.get_ui_dir(), "alignmentprogress.ui"))
self.builder.add_from_file(
os.path.join(configure.get_ui_dir(), "alignmentprogress.ui"))
self.builder.connect_signals(self)
self.window = self.builder.get_object("align-progress")
......
......@@ -49,6 +49,7 @@ def _string_to_list(version):
class Dependency(object):
"""
This abstract class represents a module or component requirement.
@param modulename: The string allowing for import or lookup of the component.
......@@ -57,6 +58,7 @@ class Dependency(object):
@param additional_message: A string that will be displayed to the user to further
explain the purpose of the missing component.
"""
def __init__(self, modulename, version_required_string, additional_message=None):
self.version_required_string = version_required_string
self.modulename = modulename
......@@ -120,6 +122,7 @@ class Dependency(object):
class GIDependency(Dependency):
def _try_importing_component(self):
try:
__import__("gi.repository." + self.modulename)
......@@ -133,6 +136,7 @@ class GIDependency(Dependency):
class ClassicDependency(Dependency):
def _try_importing_component(self):
try:
__import__(self.modulename)
......@@ -146,10 +150,12 @@ class ClassicDependency(Dependency):
class GstPluginDependency(Dependency):
"""
Don't call check on its instances before actually checking
Gst is importable.
"""
def _try_importing_component(self):
try:
from gi.repository import Gst
......@@ -166,16 +172,19 @@ class GstPluginDependency(Dependency):
class GstDependency(GIDependency):
def _format_version(self, module):
return list(module.version())
class GtkOrClutterDependency(GIDependency):
def _format_version(self, module):
return [module.MAJOR_VERSION, module.MINOR_VERSION, module.MICRO_VERSION]
class CairoDependency(ClassicDependency):
def __init__(self, version_required_string):
ClassicDependency.__init__(self, "cairo", version_required_string)
......@@ -207,7 +216,8 @@ def check_requirements():
dependency.check()
if not dependency.satisfied:
if hard_dependencies_satisfied:
print((_("ERROR - The following hard dependencies are unmet:")))
print(
(_("ERROR - The following hard dependencies are unmet:")))
print("==================================================")
print(dependency)
hard_dependencies_satisfied = False
......@@ -229,7 +239,7 @@ def check_requirements():
if not _check_audiosinks():
print((_("Could not create audio output sink. "
"Make sure you have a valid one (pulsesink, alsasink or osssink).")))
"Make sure you have a valid one (pulsesink, alsasink or osssink).")))
return False
return True
......
......@@ -49,6 +49,7 @@ from pitivi.effects import AUDIO_EFFECT, VIDEO_EFFECT, HIDDEN_EFFECTS, \
class ClipPropertiesError(Exception):
"""Base Exception for errors happening in L{ClipProperties}s or L{EffectProperties}s"""
pass
......@@ -56,15 +57,16 @@ class ClipPropertiesError(Exception):
def compare_type(track, effect_type):
if (track.get_property("track_type") == GES.TrackType.AUDIO
and effect_type == AUDIO_EFFECT):
and effect_type == AUDIO_EFFECT):
return True
elif (track.get_property("track_type") == GES.TrackType.VIDEO
and effect_type == VIDEO_EFFECT):
and effect_type == VIDEO_EFFECT):
return True
return False
class ClipProperties(Gtk.ScrolledWindow, Loggable):
"""
Widget for configuring the selected clip.
......@@ -99,14 +101,16 @@ class ClipProperties(Gtk.ScrolledWindow, Loggable):
# vbox.pack_start(self.transformation_expander, False, True, 0)
effects_properties_manager = EffectsPropertiesManager(app)
self.effect_expander = EffectProperties(app, effects_properties_manager, self)
self.effect_expander = EffectProperties(
app, effects_properties_manager, self)
self.effect_expander.set_vexpand(False)
vbox.pack_start(self.effect_expander, True, True, 0)
def _setProject(self, project):
self._project = project
if project:
self.effect_expander._connectTimelineSelection(self.app.gui.timeline_ui.timeline)
self.effect_expander._connectTimelineSelection(
self.app.gui.timeline_ui.timeline)
# Transformation boxed DISABLED
# if self.transformation_expander:
# self.transformation_expander.timeline = self.app.gui.timeline_ui.timeline
......@@ -138,6 +142,7 @@ class ClipProperties(Gtk.ScrolledWindow, Loggable):
class EffectProperties(Gtk.Expander, Loggable):
"""
Widget for viewing and configuring effects
......@@ -165,7 +170,8 @@ class EffectProperties(Gtk.Expander, Loggable):
# The toolbar that will go between the list of effects and properties
self._toolbar = Gtk.Toolbar()
self._toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR)
self._toolbar.get_style_context().add_class(
Gtk.STYLE_CLASS_INLINE_TOOLBAR)
self._toolbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR)
removeEffectButton = Gtk.ToolButton()
removeEffectButton.set_icon_name("list-remove-symbolic")
......@@ -173,7 +179,8 @@ class EffectProperties(Gtk.Expander, Loggable):
removeEffectButton.set_is_important(True)
self._toolbar.insert(removeEffectButton, 0)
# Treeview to display a list of effects (checkbox, effect type and name)
# Treeview to display a list of effects (checkbox, effect type and
# name)
self.treeview_scrollwin = Gtk.ScrolledWindow()
self.treeview_scrollwin.set_policy(Gtk.PolicyType.NEVER,
Gtk.PolicyType.AUTOMATIC)
......@@ -203,7 +210,7 @@ class EffectProperties(Gtk.Expander, Loggable):
activatedcell.props.xpad = PADDING
activatedcell.connect("toggled", self._effectActiveToggleCb)
activatedcol = self.treeview.insert_column_with_attributes(-1,
_("Active"), activatedcell, active=COL_ACTIVATED)
_("Active"), activatedcell, active=COL_ACTIVATED)
typecol = Gtk.TreeViewColumn(_("Type"))
typecol.set_spacing(SPACING)
......@@ -242,7 +249,8 @@ class EffectProperties(Gtk.Expander, Loggable):
self._vcontent = Gtk.VPaned()
self._table = Gtk.Table(n_rows=3, n_columns=1, homogeneous=False)
self._table.attach(self.treeview_scrollwin, 0, 1, 0, 1)
self._table.attach(self._toolbar, 0, 1, 2, 3, yoptions=Gtk.AttachOptions.FILL)
self._table.attach(
self._toolbar, 0, 1, 2, 3, yoptions=Gtk.AttachOptions.FILL)
self._vcontent.pack1(self._table, resize=True, shrink=False)
self.add(self._vcontent)
self._vcontent.show()
......@@ -259,7 +267,8 @@ class EffectProperties(Gtk.Expander, Loggable):
self.treeview.connect("query-tooltip", self._treeViewQueryTooltipCb)
self._vcontent.connect("notify", self._vcontentNotifyCb)
removeEffectButton.connect("clicked", self._removeEffectCb)
self.app.project_manager.connect("new-project-loaded", self._newProjectLoadedCb)
self.app.project_manager.connect(
"new-project-loaded", self._newProjectLoadedCb)
self.connect('notify::expanded', self._expandedCb)
self.connected = False
......@@ -278,10 +287,12 @@ class EffectProperties(Gtk.Expander, Loggable):
def _setTimeline(self, timeline):
if self.connected:
self._timeline.selection.disconnect_by_func(self._selectionChangedCb)
self._timeline.selection.disconnect_by_func(
self._selectionChangedCb)
self._timeline = timeline
if timeline:
self._timeline.selection.connect("selection-changed", self._selectionChangedCb)
self._timeline.selection.connect(
"selection-changed", self._selectionChangedCb)
self.connected = bool(timeline)
timeline = property(_getTimeline, _setTimeline)
......@@ -338,7 +349,8 @@ class EffectProperties(Gtk.Expander, Loggable):
def addEffectToClip(self, clip, factory_name, priority=None):
"""Adds the specified effect if it can be applied to the clip."""
model = self.treeview.get_model()
media_type = self.app.effects.getFactoryFromName(factory_name).media_type
media_type = self.app.effects.getFactoryFromName(
factory_name).media_type
for track_element in clip.get_children(False):
track_type = track_element.get_track_type()
if track_type == GES.TrackType.AUDIO and media_type == AUDIO_EFFECT or \
......@@ -364,11 +376,13 @@ class EffectProperties(Gtk.Expander, Loggable):
self.addEffectToClip(clip, factory_name)
def _dragMotionCb(self, unused_tree_view, unused_drag_context, unused_x, unused_y, unused_timestamp):
self.debug("Something is being dragged in the clip properties' effects list")
self.debug(
"Something is being dragged in the clip properties' effects list")
self.drag_highlight()
def _dragLeaveCb(self, unused_tree_view, unused_drag_context, unused_timestamp):
self.info("The item being dragged has left the clip properties' effects list")
self.info(
"The item being dragged has left the clip properties' effects list")
self.drag_unhighlight()
def _dragDataReceivedCb(self, treeview, drag_context, x, y, selection_data, unused_info, timestamp):
......@@ -402,7 +416,8 @@ class EffectProperties(Gtk.Expander, Loggable):
if dest_row:
drop_path, drop_pos = dest_row
drop_index = drop_path.get_indices()[0]
drop_index = self.calculateEffectPriority(source_index, drop_index, drop_pos)
drop_index = self.calculateEffectPriority(
source_index, drop_index, drop_pos)
else:
# This should happen when dragging after the last row.
drop_index = len(model) - 1
......@@ -455,13 +470,15 @@ class EffectProperties(Gtk.Expander, Loggable):
self.updateAll()
def _treeViewQueryTooltipCb(self, view, x, y, keyboard_mode, tooltip):
is_row, x, y, model, path, tree_iter = view.get_tooltip_context(x, y, keyboard_mode)
is_row, x, y, model, path, tree_iter = view.get_tooltip_context(
x, y, keyboard_mode)
if not is_row:
return False
view.set_tooltip_row(tooltip, path)
description = self.storemodel.get_value(tree_iter, COL_DESC_TEXT)
bin_description = self.storemodel.get_value(tree_iter, COL_BIN_DESCRIPTION_TEXT)
bin_description = self.storemodel.get_value(
tree_iter, COL_BIN_DESCRIPTION_TEXT)
tooltip.set_text("%s\n%s" % (bin_description, description))
return True
......@@ -495,7 +512,8 @@ class EffectProperties(Gtk.Expander, Loggable):
elif track_type == GES.TrackType.VIDEO:
to_append.append("Video")
to_append.append(effect.props.bin_description)
effect_factory = self.app.effects.getFactoryFromName(effect.props.bin_description)
effect_factory = self.app.effects.getFactoryFromName(
effect.props.bin_description)
to_append.append(effect_factory.human_name)
to_append.append(asset.description)
to_append.append(effect)
......@@ -540,15 +558,18 @@ class EffectProperties(Gtk.Expander, Loggable):
def _showEffectConfigurationWidget(self, effect):
self._removeEffectConfigurationWidget()
self._effect_config_ui = self.effects_properties_manager.getEffectConfigurationUI(effect)
self._effect_config_ui = self.effects_properties_manager.getEffectConfigurationUI(
effect)
if not self._effect_config_ui:
return
self._vcontent.pack2(self._effect_config_ui, resize=False, shrink=False)
self._vcontent.pack2(
self._effect_config_ui, resize=False, shrink=False)
self._vcontent.set_position(int(self._config_ui_h_pos))
self._effect_config_ui.show_all()
class TransformationProperties(Gtk.Expander):
"""
Widget for viewing and configuring speed
"""
......@@ -671,7 +692,8 @@ class TransformationProperties(Gtk.Expander):
if not effect:
effect = GES.Effect.new(bin_description=name)
self._selected_clip.add(effect)
tracks = self.app.project_manager.current_project.timeline.get_tracks()
tracks = self.app.project_manager.current_project.timeline.get_tracks(
)
effect = self._findEffect(name)
# disable the effect on default
a = self.effect.get_gnlobject()
......@@ -692,7 +714,8 @@ class TransformationProperties(Gtk.Expander):
self.show()
if self.get_expanded():
self.effect = self._findOrCreateEffect("frei0r-filter-scale0tilt")
self.effect = self._findOrCreateEffect(
"frei0r-filter-scale0tilt")
self._updateSpinButtons()
else:
if self._selected_clip:
......@@ -715,6 +738,7 @@ class TransformationProperties(Gtk.Expander):
def _setTimeline(self, timeline):
self._timeline = timeline
if timeline:
self._timeline.selection.connect('selection-changed', self._selectionChangedCb)
self._timeline.selection.connect(
'selection-changed', self._selectionChangedCb)
timeline = property(_getTimeline, _setTimeline)
......@@ -31,6 +31,7 @@ from pitivi.utils.ui import frame_rates, audio_rates, \
class ClipMediaPropsDialog(object):
"""
Displays the properties of an asset, and allows applying them to a project.
......@@ -53,7 +54,8 @@ class ClipMediaPropsDialog(object):
self.dialog = builder.get_object("Import Settings")
# Checkbuttons (with their own labels) in the first table column:
self.size_checkbutton = builder.get_object("size_checkbutton")
self.framerate_checkbutton = builder.get_object("framerate_checkbutton")
self.framerate_checkbutton = builder.get_object(
"framerate_checkbutton")
self.PAR_checkbutton = builder.get_object("PAR_checkbutton")
self.channels_checkbutton = builder.get_object("channels_checkbutton")
self.samplerate_checkbutton = builder.get_object("samplerate_checkbtn")
......@@ -109,7 +111,8 @@ class ClipMediaPropsDialog(object):
# Translators: a label showing an invalid framerate value
self.frame_rate.set_text(_("invalid (%s fps)" % foo))
self.framerate_checkbutton.set_active(False)
# For consistency, insensitize the checkbox AND value labels
# For consistency, insensitize the checkbox AND value
# labels
self.framerate_checkbutton.set_sensitive(False)
self.frame_rate.set_sensitive(False)
......
......@@ -30,6 +30,7 @@ from pitivi.check import missing_soft_deps
class DepsManager(object):
"""Display a dialog listing missing soft dependencies.
The sane way to query and install is by using PackageKit's InstallResource()
"""
......@@ -37,7 +38,8 @@ class DepsManager(object):
def __init__(self, app, parent_window=None):
self.app = app
self.builder = Gtk.Builder()
self.builder.add_from_file(os.path.join(get_ui_dir(), "depsmanager.ui"))
self.builder.add_from_file(
os.path.join(get_ui_dir(), "depsmanager.ui"))
self.builder.connect_signals(self)
self.window = self.builder.get_object("window1")
self.window.set_modal(True)
......@@ -92,7 +94,8 @@ class DepsManager(object):
"""
label_contents = ""
for depname, dep in missing_soft_deps.items():
label_contents += "• %s (%s)\n" % (dep.modulename, dep.additional_message)
label_contents += "• %s (%s)\n" % (
dep.modulename, dep.additional_message)
self.builder.get_object("pkg_list").set_text(label_contents)
def show(self):
......
......@@ -37,6 +37,7 @@ from pitivi.utils.loggable import Loggable
class FileListErrorDialog(GObject.Object, Loggable):
""" Dialog box for showing errors in a list of files """
__gsignals__ = {
......@@ -48,7 +49,7 @@ class FileListErrorDialog(GObject.Object, Loggable):
Loggable.__init__(self)
self.builder = Gtk.Builder()
self.builder.add_from_file(os.path.join(get_ui_dir(),
"filelisterrordialog.ui"))
"filelisterrordialog.ui"))
self.builder.connect_signals(self)
self.window = self.builder.get_object("filelisterrordialog")
......@@ -95,7 +96,8 @@ class FileListErrorDialog(GObject.Object, Loggable):
if extra:
end = textbuffer.get_end_iter()
textbuffer.insert_with_tags(end, _("Extra information:") + " ", boldtag)
textbuffer.insert_with_tags(
end, _("Extra information:") + " ", boldtag)
end = textbuffer.get_end_iter()
textbuffer.insert(end, "%s\n" % extra)
......@@ -115,7 +117,7 @@ class FileListErrorDialog(GObject.Object, Loggable):
"""Destroy internal window"""
self.window.destroy()
## Callbacks from glade
# Callbacks from glade
def _closeCb(self, unused_dialog):
"""Emit the close signal"""
......
......@@ -36,17 +36,18 @@ from gettext import gettext as _
GlobalSettings.addConfigSection("user-interface")
GlobalSettings.addConfigOption('prefsDialogWidth',
section="user-interface",
key="prefs-dialog-width",
default=600)
section="user-interface",
key="prefs-dialog-width",
default=600)
GlobalSettings.addConfigOption('prefsDialogHeight',
section="user-interface",
key="prefs-dialog-height",
default=400)
section="user-interface",
key="prefs-dialog-height",
default=400)
class PreferencesDialog(object):
"""
This dialog displays preferences for pitivi.
"""
......@@ -85,11 +86,11 @@ class PreferencesDialog(object):
"""Run the internal dialog"""
self.dialog.run()
## Public API
# Public API
@classmethod
def addPreference(cls, attrname, label, description, section=None,
widget_class=None, **args):
widget_class=None, **args):
"""
Add a user preference. The preferences dialog will try
to guess the appropriate widget to use based on the type of the
......@@ -108,7 +109,7 @@ class PreferencesDialog(object):
"""
if not section:
section = "General"
if not section in cls.prefs:
if section not in cls.prefs:
cls.prefs[section] = {}
cls.prefs[section][attrname] = (label, description, widget_class, args)
......@@ -128,11 +129,11 @@ class PreferencesDialog(object):
@type section: C{str}
"""
cls.addPreference(attrname, label, description, section,
ptvWidgets.PathWidget)
ptvWidgets.PathWidget)
@classmethod
def addNumericPreference(cls, attrname, label, description, section=None,
upper=None, lower=None):
upper=None, lower=None):
"""
Add an auto-generated user preference that will show up as either a
Gtk.SpinButton or an horizontal Gtk.Scale, depending whether both the
......@@ -152,7 +153,7 @@ class PreferencesDialog(object):
@type lower: C{number}
"""
cls.addPreference(attrname, label, description, section,
ptvWidgets.NumericWidget, upper=upper, lower=lower)
ptvWidgets.NumericWidget, upper=upper, lower=lower)
@classmethod
def addTextPreference(cls, attrname, label, description, section=None, matches=None):
......@@ -171,7 +172,7 @@ class PreferencesDialog(object):
@type section: C{str}
"""
cls.addPreference(attrname, label, description, section,
ptvWidgets.TextWidget, matches=matches)
ptvWidgets.TextWidget, matches=matches)
@classmethod
def addChoicePreference(cls, attrname, label, description, choices, section=None):
......@@ -192,7 +193,7 @@ class PreferencesDialog(object):
@type section: C{str}
"""
cls.addPreference(attrname, label, description, section,
ptvWidgets.ChoiceWidget, choices=choices)
ptvWidgets.ChoiceWidget, choices=choices)
@classmethod
def addTogglePreference(cls, attrname, label, description, section=None):
......@@ -210,7 +211,7 @@ class PreferencesDialog(object):
@type section: C{str}
"""
cls.addPreference(attrname, label, description, section,
ptvWidgets.ToggleWidget)
ptvWidgets.ToggleWidget)
@classmethod
def addColorPreference(cls, attrname, label, description, section=None, value_type=int):
......@@ -230,7 +231,7 @@ class PreferencesDialog(object):
@type section: C{str}
"""
cls.addPreference(attrname, label, description, section,
ptvWidgets.ColorWidget, value_type=value_type)
ptvWidgets.ColorWidget, value_type=value_type)
@classmethod
def addFontPreference(cls, attrname, label, description, section=None):
......@@ -248,9 +249,9 @@ class PreferencesDialog(object):
@type section: C{str}
"""
cls.addPreference(attrname, label, description, section,
ptvWidgets.FontWidget)
ptvWidgets.FontWidget)
## Implementation
# Implementation
def __fillContents(self):
for section in sorted(self.prefs):
options = self.prefs[section]
......@@ -266,7 +267,8 @@ class PreferencesDialog(object):
label, description, widget_class, args = options[attrname]
widget = widget_class(**args)
widget.setWidgetValue(getattr(self.settings, attrname))
widget.connectValueChanged(self._valueChanged, widget, attrname)
widget.connectValueChanged(
self._valueChanged, widget, attrname)
self.widgets[attrname] = widget
if isinstance(widget, ptvWidgets.ToggleWidget):
# Don't add a semicolon for checkbuttons
......@@ -274,7 +276,8 @@ class PreferencesDialog(object):
else:
label_widget = Gtk.Label(label=_(label) + ":")
icon = Gtk.Image()
icon.set_from_icon_name("edit-clear-all-symbolic", Gtk.IconSize.MENU)
icon.set_from_icon_name(
"edit-clear-all-symbolic", Gtk.IconSize.MENU)
revert = Gtk.Button()
revert.add(icon)
revert.set_tooltip_text(_("Reset to default value"))
......@@ -295,13 +298,16 @@ class PreferencesDialog(object):
# Avoid the separating the label from the checkbox
widget.set_label(label.get_text())
widgets.attach(widget, 0, 2, y, y + 1, yoptions=0)
widgets.attach(revert, 2, 3, y, y + 1, xoptions=0, yoptions=0)