~ubuntu-branches/ubuntu/trusty/pitivi/trusty

« back to all changes in this revision

Viewing changes to pitivi/dialogs/startupwizard.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-04-05 15:28:16 UTC
  • mfrom: (6.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140405152816-6lijoax4cngiz5j5
Tags: 0.93-3
* debian/control:
  + Depend on python-gi (>= 3.10), older versions do not work
    with pitivi (Closes: #732813).
  + Add missing dependency on gir1.2-clutter-gst-2.0 (Closes: #743692).
  + Add suggests on gir1.2-notify-0.7 and gir1.2-gnomedesktop-3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
""" This module implements a startup wizard"""
 
2
# Pitivi video editor
 
3
#
 
4
#       pitivi/dialogs/startupwizard.py
 
5
#
 
6
# Copyright (c) 2010 Mathieu Duponchelle <seeed@laposte.net>
 
7
#
 
8
# This program is free software; you can redistribute it and/or
 
9
# modify it under the terms of the GNU Lesser General Public
 
10
# License as published by the Free Software Foundation; either
 
11
# version 2.1 of the License, or (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
# Lesser General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU Lesser General Public
 
19
# License along with this program; if not, write to the
 
20
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 
21
# Boston, MA 02110-1301, USA.
 
22
 
 
23
import os
 
24
 
 
25
from gi.repository import Gtk
 
26
from gi.repository import Gdk
 
27
from gi.repository import GES
 
28
 
 
29
from gettext import gettext as _
 
30
 
 
31
from pitivi.configure import get_ui_dir
 
32
from pitivi.dialogs.depsmanager import DepsManager
 
33
from pitivi.check import missing_soft_deps
 
34
from pitivi.utils.misc import show_user_manual
 
35
 
 
36
 
 
37
class StartUpWizard(object):
 
38
    """A Wizard displaying recent projects.
 
39
 
 
40
    Allows the user to:
 
41
    - create a new project and open the settings dialog (Create button),
 
42
    - create a new project with the default settings (dialog close or ESC),
 
43
    - load a recently opened project (double click recent chooser),
 
44
    - load a project (Browse button),
 
45
    - see the quick start manual (User Manual button).
 
46
    """
 
47
 
 
48
    @staticmethod
 
49
    def _userManualCb(unused_button):
 
50
        """Handle a click on the Help button."""
 
51
        show_user_manual()
 
52
 
 
53
    @staticmethod
 
54
    def _cheatsheetCb(unused_button):
 
55
        """Show the cheatsheet section of the user manual"""
 
56
        show_user_manual("cheatsheet")
 
57
 
 
58
    def __init__(self, app):
 
59
        self.app = app
 
60
        self.builder = Gtk.Builder()
 
61
        self.builder.add_from_file(os.path.join(get_ui_dir(), "startupwizard.ui"))
 
62
        self.builder.connect_signals(self)
 
63
 
 
64
        self.window = self.builder.get_object("window1")
 
65
 
 
66
        self.recent_chooser = self.builder.get_object("recentchooser2")
 
67
        # FIXME: gtk creates a combo box with only one item, but there is no
 
68
        # simple way to hide it.
 
69
        _filter = Gtk.RecentFilter()
 
70
        _filter.set_name(_("Projects"))
 
71
 
 
72
        for asset in GES.list_assets(GES.Formatter):
 
73
            _filter.add_pattern('*.' + asset.get_meta(GES.META_FORMATTER_EXTENSION))
 
74
 
 
75
        self.recent_chooser.add_filter(_filter)
 
76
 
 
77
        missing_button = self.builder.get_object("missing_deps_button")
 
78
 
 
79
        if not missing_soft_deps:
 
80
            missing_button.hide()
 
81
 
 
82
        self.app.projectManager.connect("new-project-failed", self._projectFailedCb)
 
83
        self.app.projectManager.connect("new-project-loaded", self._projectLoadedCb)
 
84
        self.app.projectManager.connect("new-project-loading", self._projectLoadingCb)
 
85
 
 
86
        vbox = self.builder.get_object("topvbox")
 
87
        self.infobar = Gtk.InfoBar()
 
88
        vbox.pack_start(self.infobar, True, True, 0)
 
89
        if self.app.getLatest():
 
90
            self._appVersionInfoReceivedCb(self.app, None)
 
91
        else:
 
92
            self.app.connect("version-info-received", self._appVersionInfoReceivedCb)
 
93
 
 
94
    def _newProjectCb(self, unused_button):
 
95
        """Handle a click on the New (Project) button."""
 
96
        self.app.projectManager.newBlankProject()
 
97
        self.app.gui.showProjectSettingsDialog()
 
98
 
 
99
    def _loadCb(self, unused_recent_chooser):
 
100
        """
 
101
        Handle choosing a project on the recent chooser.
 
102
        This calls the project manager to load the associated URI.
 
103
        """
 
104
        uri = self.recent_chooser.get_current_uri()
 
105
        self.app.projectManager.loadProject(uri)
 
106
 
 
107
    def _keyPressCb(self, unused_widget, event):
 
108
        """Handle a key press event on the dialog."""
 
109
        if event.keyval == Gdk.KEY_Escape:
 
110
            # The user pressed "Esc".
 
111
            self.app.projectManager.newBlankProject()
 
112
 
 
113
    def _onBrowseButtonClickedCb(self, unused_button6):
 
114
        """Handle a click on the Browse button."""
 
115
        self.app.gui.openProject()
 
116
 
 
117
    def _onMissingDepsButtonClickedCb(self, unused_button):
 
118
        """Handle a click on the Missing Deps button."""
 
119
        DepsManager(self.app, parent_window=self.window)
 
120
 
 
121
    def _deleteCb(self, unused_widget, unused_event):
 
122
        """Handle a click on the X button of the dialog."""
 
123
        self.app.projectManager.newBlankProject()
 
124
 
 
125
    def show(self):
 
126
        """Will show the interal window and position the wizard"""
 
127
        self.window.set_transient_for(self.app.gui)
 
128
        self.window.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
 
129
        self.window.show()
 
130
 
 
131
    def hide(self):
 
132
        """Will hide the internal window"""
 
133
        self.window.hide()
 
134
 
 
135
    def _projectFailedCb(self, unused_project_manager, unused_uri,
 
136
            unused_exception):
 
137
        """Handle the failure of a project open operation."""
 
138
        self.show()
 
139
 
 
140
    def _projectLoadedCb(self, unused_project_manager, unused_project, fully_loaded):
 
141
        """Handle the success of a project load operation.
 
142
 
 
143
        All the create or load project usage scenarios must generate
 
144
        a new-project-loaded signal from self.app.projectManager!
 
145
        """
 
146
        if fully_loaded:
 
147
            self.app.projectManager.disconnect_by_function(self._projectFailedCb)
 
148
            self.app.projectManager.disconnect_by_function(self._projectLoadedCb)
 
149
            self.app.projectManager.disconnect_by_function(self._projectLoadingCb)
 
150
 
 
151
    def _projectLoadingCb(self, unused_project_manager, unused_project):
 
152
        """Handle the start of a project load operation."""
 
153
        self.hide()
 
154
 
 
155
    def _appVersionInfoReceivedCb(self, app, unused_version_information):
 
156
        """Handle version info"""
 
157
        if app.isLatest():
 
158
            # current version, don't show message
 
159
            return
 
160
 
 
161
        latest_version = app.getLatest()
 
162
        if self.app.settings.lastCurrentVersion != latest_version:
 
163
            # new latest version, reset counter
 
164
            self.app.settings.lastCurrentVersion = latest_version
 
165
            self.app.settings.displayCounter = 0
 
166
 
 
167
        if self.app.settings.displayCounter >= 5:
 
168
            # current version info already showed 5 times, don't show again
 
169
            return
 
170
 
 
171
        # increment counter, create infobar and show info
 
172
        self.app.settings.displayCounter = self.app.settings.displayCounter + 1
 
173
        text = _("Pitivi %s is available." % latest_version)
 
174
        label = Gtk.Label(label=text)
 
175
        self.infobar.get_content_area().add(label)
 
176
        self.infobar.set_message_type(Gtk.MessageType.INFO)
 
177
        self.infobar.show_all()