[pitivi/ges: 164/287] utils: Create a utils/ui.py file that contains UI constants and helpers
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges: 164/287] utils: Create a utils/ui.py file that contains UI constants and helpers
- Date: Thu, 15 Mar 2012 16:39:37 +0000 (UTC)
commit 6503cb7840fd4e70428db612e0efd7ccc349548e
Author: Thibault Saunier <thibault saunier collabora com>
Date: Mon Jan 9 15:30:42 2012 -0300
utils: Create a utils/ui.py file that contains UI constants and helpers
This basicly contains what ui/dnd.py and ui/common.py used to contain
+ Move GlobalSettings.addConfigSection("user-interface") to prefs.py where it
should have always been
pitivi/ui/Makefile.am | 2 -
pitivi/ui/basetabs.py | 2 +-
pitivi/ui/clipproperties.py | 9 ++-
pitivi/ui/curve.py | 2 +-
pitivi/ui/dnd.py | 46 --------------
pitivi/ui/dynamic.py | 4 +-
pitivi/ui/effectlist.py | 4 +-
pitivi/ui/encodingdialog.py | 2 +-
pitivi/ui/filechooserpreview.py | 4 +-
pitivi/ui/gstwidget.py | 2 +-
pitivi/ui/mainwindow.py | 12 ++--
pitivi/ui/prefs.py | 4 +-
pitivi/ui/projectsettings.py | 2 +-
pitivi/ui/sourcelist.py | 4 +-
pitivi/ui/timeline.py | 26 ++++----
pitivi/ui/timelinecanvas.py | 4 +-
pitivi/ui/timelinecontrols.py | 2 +-
pitivi/ui/track.py | 2 +-
pitivi/ui/trackobject.py | 6 +-
pitivi/ui/viewer.py | 2 +-
pitivi/utils/Makefile.am | 3 +-
pitivi/utils/misc.py | 32 ----------
pitivi/{ui/common.py => utils/ui.py} | 110 ++++++++++++++++++++++++++--------
po/POTFILES.in | 2 +-
tests/test_common.py | 2 +-
25 files changed, 137 insertions(+), 153 deletions(-)
---
diff --git a/pitivi/ui/Makefile.am b/pitivi/ui/Makefile.am
index c4559a6..4717a9d 100644
--- a/pitivi/ui/Makefile.am
+++ b/pitivi/ui/Makefile.am
@@ -3,10 +3,8 @@ uidir = $(libdir)/pitivi/python/pitivi/ui
ui_PYTHON = \
__init__.py \
alignmentprogress.py \
- common.py \
controller.py \
curve.py \
- dnd.py \
depsmanager.py \
dynamic.py \
encodingdialog.py \
diff --git a/pitivi/ui/basetabs.py b/pitivi/ui/basetabs.py
index c2b1bbe..d42ab87 100644
--- a/pitivi/ui/basetabs.py
+++ b/pitivi/ui/basetabs.py
@@ -20,7 +20,7 @@
# Boston, MA 02110-1301, USA.
import gtk
-from pitivi.ui.common import SPACING
+from pitivi.utils.ui import SPACING
class BaseTabs(gtk.Notebook):
diff --git a/pitivi/ui/clipproperties.py b/pitivi/ui/clipproperties.py
index a7f26d8..2723d6f 100644
--- a/pitivi/ui/clipproperties.py
+++ b/pitivi/ui/clipproperties.py
@@ -24,7 +24,6 @@ Class handling the midle pane
"""
import gtk
import pango
-import dnd
import os
import ges
@@ -33,12 +32,14 @@ from gettext import gettext as _
from pitivi.utils.playback import Seeker
from pitivi.check import soft_deps
from pitivi.configure import get_ui_dir
+
+from pitivi.utils.ui import EFFECT_TUPLE
from pitivi.utils.loggable import Loggable
from pitivi.effects import AUDIO_EFFECT, VIDEO_EFFECT
from pitivi.ui.depsmanager import DepsManager
-from pitivi.ui.common import PADDING, SPACING
+from pitivi.utils.ui import PADDING, SPACING
from pitivi.ui.effectlist import HIDDEN_EFFECTS
from pitivi.ui.gstwidget import GstElementSettingsWidget
from pitivi.ui.effectsconfiguration import EffectsPropertiesHandling
@@ -231,7 +232,7 @@ class EffectProperties(gtk.Expander, gtk.HBox):
namecol.add_attribute(namecell, "text", COL_NAME_TEXT)
self.treeview.drag_dest_set(gtk.DEST_DEFAULT_MOTION,
- [dnd.EFFECT_TUPLE],
+ [EFFECT_TUPLE],
gtk.gdk.ACTION_COPY)
self.selection = self.treeview.get_selection()
@@ -372,7 +373,7 @@ class EffectProperties(gtk.Expander, gtk.HBox):
self.drag_unhighlight()
def _dragMotionCb(self, unused, context, x, y, timestamp):
- atom = gtk.gdk.atom_intern(dnd.EFFECT_TUPLE[0])
+ atom = gtk.gdk.atom_intern(EFFECT_TUPLE[0])
if not self._factory:
self.drag_get_data(context, atom, timestamp)
self.drag_highlight()
diff --git a/pitivi/ui/curve.py b/pitivi/ui/curve.py
index 06b93f3..c5543b1 100644
--- a/pitivi/ui/curve.py
+++ b/pitivi/ui/curve.py
@@ -31,7 +31,7 @@ from pitivi.ui.zoominterface import Zoomable
import pitivi.ui.previewer as previewer
from pitivi.ui.view import View
from pitivi.ui.controller import Controller
-from pitivi.ui.common import LAYER_HEIGHT_EXPANDED, roundedrec
+from pitivi.utils.ui import LAYER_HEIGHT_EXPANDED, roundedrec
import pitivi.ui.point as point
from pitivi.utils.misc import between
diff --git a/pitivi/ui/dynamic.py b/pitivi/ui/dynamic.py
index b5288df..bf2a958 100644
--- a/pitivi/ui/dynamic.py
+++ b/pitivi/ui/dynamic.py
@@ -30,9 +30,9 @@ import sys
import gst
from gettext import gettext as _
from pitivi.utils.misc import time_to_string
-from pitivi.ui.common import unpack_color, pack_color_32, pack_color_64
+from pitivi.utils.ui import unpack_color, pack_color_32, pack_color_64
import pango
-from pitivi.ui.common import SPACING
+from pitivi.utils.ui import SPACING
class DynamicWidget(object):
diff --git a/pitivi/ui/effectlist.py b/pitivi/ui/effectlist.py
index 338064c..ef57447 100644
--- a/pitivi/ui/effectlist.py
+++ b/pitivi/ui/effectlist.py
@@ -28,13 +28,13 @@ import time
from gettext import gettext as _
from xml.sax.saxutils import escape
-import pitivi.ui.dnd as dnd
+import pitivi.utils.ui as dnd
from pitivi.configure import get_pixmap_dir
from pitivi.utils.loggable import Loggable
from pitivi.effects import AUDIO_EFFECT, VIDEO_EFFECT
-from pitivi.ui.common import SPACING
+from pitivi.utils.ui import SPACING
from pitivi.settings import GlobalSettings
SHOW_TREEVIEW = 1
diff --git a/pitivi/ui/encodingdialog.py b/pitivi/ui/encodingdialog.py
index 8be577a..21c0653 100644
--- a/pitivi/ui/encodingdialog.py
+++ b/pitivi/ui/encodingdialog.py
@@ -40,7 +40,7 @@ from pitivi.utils.signal import Signallable
from pitivi.utils.loggable import Loggable
from pitivi.ui.gstwidget import GstElementSettingsDialog
from pitivi.ui.ripple_update_group import RippleUpdateGroup
-from pitivi.ui.common import model, frame_rates, audio_rates, audio_depths, \
+from pitivi.utils.ui import model, frame_rates, audio_rates, audio_depths, \
audio_channels, get_combo_value, set_combo_value
from pitivi.ui.preset import RenderPresetManager, DuplicatePresetNameException
diff --git a/pitivi/ui/filechooserpreview.py b/pitivi/ui/filechooserpreview.py
index 38e9b3c..0fb62db 100644
--- a/pitivi/ui/filechooserpreview.py
+++ b/pitivi/ui/filechooserpreview.py
@@ -6,12 +6,12 @@ import pango
import os
from pitivi.utils.loggable import Loggable
-from pitivi.ui.common import beautify_stream
+from pitivi.utils.ui import beautify_stream
from pitivi.utils.misc import beautify_length, uri_is_valid
from pitivi.configure import get_pixmap_dir
from pitivi.settings import GlobalSettings
from gettext import gettext as _
-from pitivi.ui.common import SPACING
+from pitivi.utils.ui import SPACING
from pitivi.ui.viewer import ViewerWidget
DEFAULT_AUDIO_IMAGE = os.path.join(get_pixmap_dir(), "pitivi-sound.png")
diff --git a/pitivi/ui/gstwidget.py b/pitivi/ui/gstwidget.py
index 6e241ff..ee0b307 100644
--- a/pitivi/ui/gstwidget.py
+++ b/pitivi/ui/gstwidget.py
@@ -33,7 +33,7 @@ from gettext import gettext as _
from pitivi.utils.loggable import Loggable
from pitivi.configure import get_ui_dir
import pitivi.ui.dynamic as dynamic
-from pitivi.ui.common import SPACING
+from pitivi.utils.ui import SPACING
def make_property_widget(unused_element, prop, value=None):
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 527239f..94e2f7b 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -40,10 +40,9 @@ from pitivi.settings import GlobalSettings
from pitivi.sourcelist import SourceListError
from pitivi.utils.misc import show_user_manual
+from pitivi.utils.ui import SPACING, info_name, FILESOURCE_TUPLE, URI_TUPLE, \
+ TYPE_URI_LIST, TYPE_PITIVI_FILESOURCE
-from pitivi.ui import dnd
-from pitivi.ui.common import SPACING
-from pitivi.ui.common import info_name
from pitivi.ui.timeline import Timeline
from pitivi.ui.basetabs import BaseTabs
from pitivi.ui.viewer import PitiviViewer
@@ -119,6 +118,7 @@ GlobalSettings.addConfigOption('effectVPanedPosition',
key='effect-vpaned-position',
type_=int)
+
#FIXME Hacky, reimplement when avalaible in GES
formats = [(None, _("PiTiVi Native (XML)"), ('xptv',))]
@@ -410,7 +410,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
self.viewer = PitiviViewer(instance, undock_action=self.undock_action)
# drag and drop
self.viewer.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION,
- [dnd.FILESOURCE_TUPLE, dnd.URI_TUPLE],
+ [FILESOURCE_TUPLE, URI_TUPLE],
gtk.gdk.ACTION_COPY)
self.viewer.connect("drag_data_received", self._viewerDndDataReceivedCb)
self.mainhpaned.pack2(self.viewer, resize=False, shrink=False)
@@ -1075,9 +1075,9 @@ class PitiviMainWindow(gtk.Window, Loggable):
# FIXME : This should be handled by the main application who knows how
# to switch between pipelines.
self.info("context:%s, targetType:%s", context, targetType)
- if targetType == dnd.TYPE_URI_LIST:
+ if targetType == TYPE_URI_LIST:
uri = selection.data.strip().split("\n")[0].strip()
- elif targetType == dnd.TYPE_PITIVI_FILESOURCE:
+ elif targetType == TYPE_PITIVI_FILESOURCE:
uri = selection.data
else:
context.finish(False, False, ctime)
diff --git a/pitivi/ui/prefs.py b/pitivi/ui/prefs.py
index 41e321a..b0605db 100644
--- a/pitivi/ui/prefs.py
+++ b/pitivi/ui/prefs.py
@@ -30,9 +30,11 @@ import pitivi.ui.dynamic as dynamic
from pitivi.configure import get_ui_dir
from pitivi.settings import GlobalSettings
-from pitivi.ui.common import SPACING
+from pitivi.utils.ui import SPACING
from gettext import gettext as _
+GlobalSettings.addConfigSection("user-interface")
+
GlobalSettings.addConfigOption('prefsDialogWidth',
section="user-interface",
key="prefs-dialog-width",
diff --git a/pitivi/ui/projectsettings.py b/pitivi/ui/projectsettings.py
index f4e4867..5fb53bc 100644
--- a/pitivi/ui/projectsettings.py
+++ b/pitivi/ui/projectsettings.py
@@ -34,7 +34,7 @@ from pitivi.configure import get_ui_dir
from gettext import gettext as _
from pitivi.ui.dynamic import FractionWidget
from pitivi.ui.ripple_update_group import RippleUpdateGroup
-from pitivi.ui.common import\
+from pitivi.utils.ui import\
model,\
frame_rates,\
audio_rates,\
diff --git a/pitivi/ui/sourcelist.py b/pitivi/ui/sourcelist.py
index cccf6cd..4cfe947 100644
--- a/pitivi/ui/sourcelist.py
+++ b/pitivi/ui/sourcelist.py
@@ -32,7 +32,7 @@ from urllib import unquote
from gettext import gettext as _
from hashlib import md5
-import pitivi.ui.dnd as dnd
+import pitivi.utils.ui as dnd
from pitivi.configure import get_pixmap_dir
from pitivi.settings import GlobalSettings
@@ -41,7 +41,7 @@ from pitivi.utils.signal import SignalGroup
from pitivi.ui.pathwalker import PathWalker, quote_uri
from pitivi.ui.filelisterrordialog import FileListErrorDialog
-from pitivi.ui.common import beautify_info, info_name, \
+from pitivi.utils.ui import beautify_info, info_name, \
SPACING, PADDING
from pitivi.utils.loggable import Loggable
from pitivi.ui.filechooserpreview import PreviewWidget
diff --git a/pitivi/ui/timeline.py b/pitivi/ui/timeline.py
index 47208f5..e386ddb 100644
--- a/pitivi/ui/timeline.py
+++ b/pitivi/ui/timeline.py
@@ -26,7 +26,6 @@ Timeline widgets for the complex view
import gtk
import ruler
-import dnd
import gst
import gobject
import ges
@@ -41,19 +40,20 @@ from timelinecontrols import TimelineControls
from pitivi.effects import AUDIO_EFFECT, VIDEO_EFFECT
from pitivi.utils.timeline import MoveContext, SELECT
-from pitivi.ui.common import SPACING
from pitivi.ui.depsmanager import DepsManager
from pitivi.ui.filelisterrordialog import FileListErrorDialog
from pitivi.ui.alignmentprogress import AlignmentProgressDialog
-from pitivi.ui.common import TRACK_SPACING, LAYER_HEIGHT_EXPANDED, LAYER_SPACING
+from pitivi.utils.ui import SPACING, TRACK_SPACING, LAYER_HEIGHT_EXPANDED,\
+ LAYER_SPACING, TYPE_PITIVI_FILESOURCE, VIDEO_EFFECT_TUPLE, \
+ AUDIO_EFFECT_TUPLE, EFFECT_TUPLE, FILESOURCE_TUPLE, TYPE_PITIVI_EFFECT
# FIXME GES Port regression
# from pitivi.utils.align import AutoAligner
-DND_EFFECT_LIST = [[dnd.VIDEO_EFFECT_TUPLE[0], dnd.EFFECT_TUPLE[0]],\
- [dnd.AUDIO_EFFECT_TUPLE[0], dnd.EFFECT_TUPLE[0]]]
-VIDEO_EFFECT_LIST = [dnd.VIDEO_EFFECT_TUPLE[0], dnd.EFFECT_TUPLE[0]],
-AUDIO_EFFECT_LIST = [dnd.AUDIO_EFFECT_TUPLE[0], dnd.EFFECT_TUPLE[0]],
+DND_EFFECT_LIST = [[VIDEO_EFFECT_TUPLE[0], EFFECT_TUPLE[0]],\
+ [AUDIO_EFFECT_TUPLE[0], EFFECT_TUPLE[0]]]
+VIDEO_EFFECT_LIST = [VIDEO_EFFECT_TUPLE[0], EFFECT_TUPLE[0]],
+AUDIO_EFFECT_LIST = [AUDIO_EFFECT_TUPLE[0], EFFECT_TUPLE[0]],
# tooltip text for toolbar
DELETE = _("Delete Selected")
@@ -359,7 +359,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
# drag and drop
self.drag_dest_set(gtk.DEST_DEFAULT_MOTION,
- [dnd.FILESOURCE_TUPLE, dnd.EFFECT_TUPLE],
+ [FILESOURCE_TUPLE, EFFECT_TUPLE],
gtk.gdk.ACTION_COPY)
self.connect("drag-data-received", self._dragDataReceivedCb)
@@ -404,9 +404,9 @@ class Timeline(gtk.Table, Loggable, Zoomable):
if not self._factories:
if context.targets in DND_EFFECT_LIST:
- atom = gtk.gdk.atom_intern(dnd.EFFECT_TUPLE[0])
+ atom = gtk.gdk.atom_intern(EFFECT_TUPLE[0])
else:
- atom = gtk.gdk.atom_intern(dnd.FILESOURCE_TUPLE[0])
+ atom = gtk.gdk.atom_intern(FILESOURCE_TUPLE[0])
self.drag_get_data(context, atom, timestamp)
self.drag_highlight()
@@ -493,12 +493,12 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self.log("targetType:%d, selection.data:%s" % (targetType, selection.data))
self.selection_data = selection.data
- if targetType not in [dnd.TYPE_PITIVI_FILESOURCE,
- dnd.TYPE_PITIVI_EFFECT]:
+ if targetType not in [TYPE_PITIVI_FILESOURCE,
+ TYPE_PITIVI_EFFECT]:
context.finish(False, False, timestamp)
return
- if targetType == dnd.TYPE_PITIVI_FILESOURCE:
+ if targetType == TYPE_PITIVI_FILESOURCE:
uris = selection.data.split("\n")
self._factories = \
[self._project.sources.getInfoFromUri(uri) for uri in uris]
diff --git a/pitivi/ui/timelinecanvas.py b/pitivi/ui/timelinecanvas.py
index 01281ae..6cccd5e 100644
--- a/pitivi/ui/timelinecanvas.py
+++ b/pitivi/ui/timelinecanvas.py
@@ -31,11 +31,11 @@ from pitivi.ui.point import Point
from pitivi.ui.zoominterface import Zoomable
from pitivi.settings import GlobalSettings
from pitivi.ui.prefs import PreferencesDialog
-from pitivi.ui.common import TRACK_SPACING, unpack_cairo_pattern, \
+from pitivi.utils.ui import TRACK_SPACING, unpack_cairo_pattern, \
LAYER_HEIGHT_EXPANDED, LAYER_SPACING
from pitivi.ui.controller import Controller
from pitivi.ui.curve import KW_LABEL_Y_OVERFLOW
-from pitivi.ui.common import SPACING
+from pitivi.utils.ui import SPACING
# cursors to be used for resizing objects
ARROW = gtk.gdk.Cursor(gtk.gdk.ARROW)
diff --git a/pitivi/ui/timelinecontrols.py b/pitivi/ui/timelinecontrols.py
index eadd6d3..eeb3e85 100644
--- a/pitivi/ui/timelinecontrols.py
+++ b/pitivi/ui/timelinecontrols.py
@@ -1,7 +1,7 @@
import gtk
from pitivi.receiver import receiver, handler
from gettext import gettext as _
-from common import LAYER_HEIGHT_EXPANDED, LAYER_SPACING
+from pitivi.utils.ui import LAYER_HEIGHT_EXPANDED, LAYER_SPACING
from pitivi.utils.loggable import Loggable
TRACK_CONTROL_WIDTH = 75
diff --git a/pitivi/ui/track.py b/pitivi/ui/track.py
index 0dc57c1..956ac1c 100644
--- a/pitivi/ui/track.py
+++ b/pitivi/ui/track.py
@@ -28,7 +28,7 @@ from pitivi.utils.loggable import Loggable
from pitivi.ui.zoominterface import Zoomable
from pitivi.receiver import receiver, handler
from pitivi.ui.trackobject import TrackObject
-from pitivi.ui.common import LAYER_HEIGHT_EXPANDED,\
+from pitivi.utils.ui import LAYER_HEIGHT_EXPANDED,\
LAYER_HEIGHT_COLLAPSED, LAYER_SPACING
diff --git a/pitivi/ui/trackobject.py b/pitivi/ui/trackobject.py
index 7f28099..485453a 100644
--- a/pitivi/ui/trackobject.py
+++ b/pitivi/ui/trackobject.py
@@ -10,8 +10,8 @@ import controller
from view import View
from gettext import gettext as _
from zoominterface import Zoomable
-from common import LAYER_HEIGHT_EXPANDED, LAYER_HEIGHT_COLLAPSED
-from common import LAYER_SPACING, unpack_cairo_pattern, unpack_cairo_gradient
+from pitivi.utils.ui import LAYER_SPACING, unpack_cairo_pattern, \
+ unpack_cairo_gradient, LAYER_HEIGHT_EXPANDED, LAYER_HEIGHT_COLLAPSED
from pitivi.ui.point import Point
from pitivi.utils.loggable import Loggable
@@ -452,7 +452,7 @@ class TrackObject(View, goocanvas.Group, Zoomable):
def _setElement(self):
if self.element and not self.is_transition:
- from pitivi.ui.common import info_name
+ from pitivi.utils.ui import info_name
sources = self.app.current.sources
uri = self.element.props.uri
diff --git a/pitivi/ui/viewer.py b/pitivi/ui/viewer.py
index a82d598..60d9e17 100644
--- a/pitivi/ui/viewer.py
+++ b/pitivi/ui/viewer.py
@@ -30,7 +30,7 @@ from gettext import gettext as _
from pitivi.utils.loggable import Loggable
from pitivi.settings import GlobalSettings
from pitivi.utils.misc import togglePlayback
-from pitivi.ui.common import SPACING, hex_to_rgb
+from pitivi.utils.ui import SPACING, hex_to_rgb
from pitivi.ui.dynamic import TimeWidget
GlobalSettings.addConfigSection("viewer")
diff --git a/pitivi/utils/Makefile.am b/pitivi/utils/Makefile.am
index fae096b..97a9e79 100644
--- a/pitivi/utils/Makefile.am
+++ b/pitivi/utils/Makefile.am
@@ -8,7 +8,8 @@ utils_PYTHON = \
timeline.py \
loggable.py \
playback.py \
- signal.py \
+ signal.py \
+ ui.py \
misc.py
clean-local:
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 9177416..0935118 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -340,38 +340,6 @@ class Infinity(object):
infinity = Infinity()
-class CachedFactoryList(object):
- def __init__(self, factoryFilter=None):
- self._factoryFilter = factoryFilter
- self._factories = None
- self._registry = gst.registry_get_default()
- self._registry.connect("feature-added", self._registryFeatureAddedCb)
-
- def get(self):
- if self._factories is None:
- self._buildFactories()
-
- return self._factories
-
- def _buildFactories(self):
- # build the cache
- log.debug("utils", "Getting factories list")
- factories = self._registry.get_feature_list(gst.ElementFactory)
- if self._factoryFilter is not None:
- log.debug("utils", "filtering")
- factories = filter(self._factoryFilter, factories)
-
- log.debug("utils", "Sorting by rank")
- factories.sort(key=lambda factory: factory.get_rank(), reverse=True)
- self._factories = factories
- log.debug("utils", "Cached factories is now %r", self._factories)
-
- def _registryFeatureAddedCb(self, registry, feature):
- # invalidate the cache
- log.warning("utils", "New feature added, invalidating cached factories")
- self._factories = None
-
-
def profile(func, profiler_filename="result.prof"):
import os.path
counter = 1
diff --git a/pitivi/ui/common.py b/pitivi/utils/ui.py
similarity index 73%
rename from pitivi/ui/common.py
rename to pitivi/utils/ui.py
index d3a314c..c4c5fa3 100644
--- a/pitivi/ui/common.py
+++ b/pitivi/utils/ui.py
@@ -1,19 +1,47 @@
# -*- coding: utf-8 -*-
+# PiTiVi , Non-linear video editor
+#
+# pitivi/utils/ui.py
+#
+# Copyright (c) 2005, Edward Hervey <bilboed bilboed com>
+# Copyright (c) 2012, Thibault Saunier <thibault saunier collabora com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+"""
+UI utilities. This file contain the UI constants, and various functions and
+classes that help with UI drawing around the application
+"""
import gst
import gtk
import os
import cairo
-from xml.sax.saxutils import escape
+from itertools import izip
from urllib import unquote
-from gettext import ngettext
-
-from gettext import gettext as _
+from gettext import ngettext, gettext as _
+from xml.sax.saxutils import escape
-from pitivi.settings import GlobalSettings
from pitivi.utils.loggable import doLog, ERROR
-GlobalSettings.addConfigSection("user-interface")
+# ---------------------- Constants --------------------------------------------#
+
+##
+# UI pixels information constants
+##
LAYER_HEIGHT_EXPANDED = 50
LAYER_HEIGHT_COLLAPSED = 15
LAYER_SPACING = 15
@@ -22,7 +50,33 @@ TRACK_SPACING = 8
SPACING = 6
PADDING = 6
-
+##
+# Drag'n drop constants
+##
+TYPE_TEXT_PLAIN = 24
+TYPE_URI_LIST = 25
+
+# FileSourceFactory (or subclasses)
+TYPE_PITIVI_FILESOURCE = 26
+
+# What objects to these correspond to ???
+TYPE_PITIVI_EFFECT = 27
+TYPE_PITIVI_AUDIO_EFFECT = 28
+TYPE_PITIVI_VIDEO_EFFECT = 29
+TYPE_PITIVI_AUDIO_TRANSITION = 30
+TYPE_PITIVI_VIDEO_TRANSITION = 31
+
+FILE_TUPLE = ("text/plain", 0, TYPE_TEXT_PLAIN)
+URI_TUPLE = ("text/uri-list", 0, TYPE_URI_LIST)
+FILESOURCE_TUPLE = ("pitivi/file-source", 0, TYPE_PITIVI_FILESOURCE)
+EFFECT_TUPLE = ("pitivi/effect", 0, TYPE_PITIVI_EFFECT)
+AUDIO_EFFECT_TUPLE = ("pitivi/audio-effect", 0, TYPE_PITIVI_AUDIO_EFFECT)
+VIDEO_EFFECT_TUPLE = ("pitivi/video-effect", 0, TYPE_PITIVI_VIDEO_EFFECT)
+AUDIO_TRANSITION_TUPLE = ("pitivi/audio-transition", 0, TYPE_PITIVI_AUDIO_TRANSITION)
+VIDEO_TRANSITION_TUPLE = ("pitivi/video-transition", 0, TYPE_PITIVI_VIDEO_TRANSITION)
+
+
+# ---------------------- ARGB color helper-------------------------------------#
def pack_color_32(red, green, blue, alpha=0xFFFF):
"""Packs the specified 16bit color values in a 32bit RGBA value."""
red = red >> 8
@@ -96,6 +150,11 @@ def unpack_cairo_gradient(value):
return gradient
+def hex_to_rgb(value):
+ return tuple(float(int(value[i:i + 2], 16)) / 255.0 for i in range(0, 6, 2))
+
+
+#--- Utils to make gst.DiscovererInfo ready to be displayed in the UI --------#
def beautify_info(info):
ranks = {
gst.pbutils.DiscovererVideoInfo: 0,
@@ -152,6 +211,7 @@ def beautify_stream(stream):
raise NotImplementedError
+#--------------------- UI drawing helper -------------------------------------#
# from http://cairographics.org/cookbook/roundedrectangles/
def roundedrec(context, x, y, w, h, r=10):
"Draw a rounded rectangle"
@@ -175,12 +235,30 @@ def roundedrec(context, x, y, w, h, r=10):
return
+#--------------------- Gtk widget helpers ------------------------------------#
def model(columns, data):
ret = gtk.ListStore(*columns)
for datum in data:
ret.append(datum)
return ret
+
+def set_combo_value(combo, value, default_index=-1):
+ model = combo.props.model
+ for i, row in enumerate(model):
+ if row[1] == value:
+ combo.set_active(i)
+ return
+ combo.set_active(default_index)
+
+
+def get_combo_value(combo):
+ active = combo.get_active()
+ return combo.props.model[active][1]
+
+
+#------------------------ encoding datas ----------------------------------------#
+# FIXME This should into a special file
frame_rates = model((str, object), (
# Translators: fps is for frames per second
(_("%d fps") % 12, gst.Fraction(12.0, 1.0)),
@@ -216,21 +294,3 @@ audio_channels = model((str, int), (
(_("4 Channels (4.0)"), 4),
(_("Stereo"), 2),
(_("Mono"), 1)))
-
-
-def set_combo_value(combo, value, default_index=-1):
- model = combo.props.model
- for i, row in enumerate(model):
- if row[1] == value:
- combo.set_active(i)
- return
- combo.set_active(default_index)
-
-
-def get_combo_value(combo):
- active = combo.get_active()
- return combo.props.model[active][1]
-
-
-def hex_to_rgb(value):
- return tuple(float(int(value[i:i + 2], 16)) / 255.0 for i in range(0, 6, 2))
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e80afa9..24716d8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,7 +21,6 @@ pitivi/settings.py
pitivi/ui/alignmentprogress.py
pitivi/ui/basetabs.py
pitivi/ui/clipproperties.py
-pitivi/ui/common.py
pitivi/ui/dynamic.py
pitivi/ui/effectlist.py
pitivi/ui/effectsconfiguration.py
@@ -42,3 +41,4 @@ pitivi/ui/timeline.py
pitivi/ui/trackobject.py
pitivi/ui/viewer.py
pitivi/utils/misc.py
+pitivi/utils/ui.py
diff --git a/tests/test_common.py b/tests/test_common.py
index 7ed1808..9d20a1c 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -21,7 +21,7 @@
import common
from unittest import main
-from pitivi.ui import common as ui_common
+import pitivi.utils.ui as ui_common
class TestColors(common.TestCase):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]