[pitivi: 40/41] Created utils.show_user_manual which tries to open the offline or online user manual



commit 999025b8999efc6a44f3d686c1cab7781eed86db
Author: Alex BÄluÈ <alexandru balut gmail com>
Date:   Fri Aug 12 20:42:57 2011 +0200

    Created utils.show_user_manual which tries to open the offline or online user manual

 pitivi/configure.py.in     |   21 +++++++++++++++------
 pitivi/ui/mainwindow.py    |    6 +++---
 pitivi/ui/startupwizard.py |    4 ++--
 pitivi/utils.py            |   30 ++++++++++++++++++++++++------
 4 files changed, 44 insertions(+), 17 deletions(-)
---
diff --git a/pitivi/configure.py.in b/pitivi/configure.py.in
index e5da2f9..016504f 100644
--- a/pitivi/configure.py.in
+++ b/pitivi/configure.py.in
@@ -25,24 +25,33 @@ Enables identical use for installed and uninstalled versions.
 
 import os.path
 
+
+def _get_root_dir():
+    return '/'.join(os.path.dirname(os.path.abspath(__file__)).split('/')[:-1])
+
+def _in_devel():
+    rd = _get_root_dir()
+    return os.path.exists(os.path.join(rd, '.git'))
+
+
 LIBDIR = '@LIBDIR@'
 PKGDATADIR = '@DATADIR@/@PACKAGE@'
 pitivi_version = '@VERSION@'
 APPNAME = '@PACKAGE_NAME@'
 APPURL = 'http://www.pitivi.org/'
-APPMANUALURL = 'http://www.pitivi.org/?go=documentation'
 PYGTK_REQ = '@PYGTK_REQ@'
 PYGST_REQ = '@PYGST_REQ@'
 GST_REQ = '@GST_REQ@'
 GNONLIN_REQ = '@GNONLIN_REQ@'
 PYCAIRO_REQ = '@PYCAIRO_REQ@'
 
-def _get_root_dir():
-    return '/'.join(os.path.dirname(os.path.abspath(__file__)).split('/')[:-1])
+if _in_devel():
+    APPMANUALURL_OFFLINE = 'ghelp://%s' % os.path.join(_get_root_dir(), 'help/C')
+else:
+    APPMANUALURL_OFFLINE = 'ghelp:pitivi'
+
+APPMANUALURL_ONLINE = 'http://www.pitivi.org/manual'
 
-def _in_devel():
-    rd = _get_root_dir()
-    return os.path.exists(os.path.join(rd, '.git'))
 
 def get_data_dir():
     if _in_devel():
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index c82bf98..4877a46 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -48,7 +48,7 @@ from pitivi.log.loggable import Loggable
 from pitivi.ui.timeline import Timeline
 from pitivi.ui.basetabs import BaseTabs
 from pitivi.ui.viewer import PitiviViewer
-from pitivi.configure import pitivi_version, APPNAME, APPURL, APPMANUALURL, \
+from pitivi.configure import pitivi_version, APPNAME, APPURL, \
      get_pixmap_dir, LIBDIR, get_ui_dir
 from pitivi.ui import dnd
 from pitivi.pipeline import Pipeline
@@ -62,7 +62,7 @@ from pitivi.ui.effectlist import EffectList
 from pitivi.ui.clipproperties import ClipProperties
 from pitivi.ui.common import SPACING
 from pitivi.ui.common import factory_name
-from pitivi.utils import beautify_length
+from pitivi.utils import beautify_length, show_user_manual
 from pitivi.ui.zoominterface import Zoomable
 from pitivi.ui.filechooserpreview import PreviewWidget
 
@@ -616,7 +616,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
             action.props.active
 
     def _userManualCb(self, unused_action):
-        webbrowser.open_new(APPMANUALURL)
+        show_user_manual()
 
     def _aboutResponseCb(self, dialog, unused_response):
         dialog.destroy()
diff --git a/pitivi/ui/startupwizard.py b/pitivi/ui/startupwizard.py
index 7198b3f..6cf9e9d 100644
--- a/pitivi/ui/startupwizard.py
+++ b/pitivi/ui/startupwizard.py
@@ -26,9 +26,9 @@ import webbrowser
 from gettext import gettext as _
 
 from pitivi.configure import get_ui_dir
-from pitivi.configure import APPMANUALURL
 from pitivi.ui.depsmanager import DepsManager
 from pitivi.check import soft_deps
+from pitivi.utils import show_user_manual
 
 from urllib import unquote
 
@@ -100,7 +100,7 @@ class StartUpWizard(object):
 
     def _userManualCb(self, unused_button):
         """Handle a click on the Help button."""
-        webbrowser.open(APPMANUALURL)
+        show_user_manual()
 
     def _deleteCb(self, unused_widget, event):
         """Handle a click on the X button of the dialog."""
diff --git a/pitivi/utils.py b/pitivi/utils.py
index bf224c3..9a2254c 100644
--- a/pitivi/utils.py
+++ b/pitivi/utils.py
@@ -23,11 +23,16 @@
 # set of utility functions
 
 import sys
+import gio
 import gobject
 import gst
+import gtk
 import bisect
 import os
 import struct
+import time
+
+from pitivi.configure import APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE
 from pitivi.signalinterface import Signallable
 import pitivi.log.log as log
 from gettext import ngettext
@@ -36,8 +41,16 @@ try:
 except ImportError:
     pass
 
+
 UNKNOWN_DURATION = 2 ** 63 - 1
 
+native_endianness = struct.pack('=I', 0x34333231)
+
+big_to_cairo_alpha_mask = struct.unpack('=i', '\xFF\x00\x00\x00')[0]
+big_to_cairo_red_mask = struct.unpack('=i', '\x00\xFF\x00\x00')[0]
+big_to_cairo_green_mask = struct.unpack('=i', '\x00\x00\xFF\x00')[0]
+big_to_cairo_blue_mask = struct.unpack('=i', '\x00\x00\x00\xFF')[0]
+
 
 def between(a, b, c):
     return (a <= b) and (b <= c)
@@ -571,9 +584,14 @@ def quantize(input, interval):
     return (input // interval) * interval
 
 
-native_endianness = struct.pack('=I', 0x34333231)
-
-big_to_cairo_alpha_mask = struct.unpack('=i', '\xFF\x00\x00\x00')[0]
-big_to_cairo_red_mask = struct.unpack('=i', '\x00\xFF\x00\x00')[0]
-big_to_cairo_green_mask = struct.unpack('=i', '\x00\x00\xFF\x00')[0]
-big_to_cairo_blue_mask = struct.unpack('=i', '\x00\x00\x00\xFF')[0]
+def show_user_manual():
+    time_now = int(time.time())
+    for uri in (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE):
+        try:
+            gtk.show_uri(None, uri, time_now)
+            return
+        except Exception, e:
+            log.debug("utils", "Failed loading URI %s: %s", uri, e)
+            continue
+    log.warning("utils", "Failed loading URIs")
+    # TODO: Show an error message to the user.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]