[pitivi] mainwindow: Show the startup wizard when the project loading fails



commit e094e7fa970f7c95dd956aa9e057105febebf150
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Feb 9 14:07:20 2016 +0100

    mainwindow: Show the startup wizard when the project loading fails
    
    Simplified the StartUpWizard so it connects to a single signal when it
    is shown. Removed a bunch of newBlankProject calls.
    
    Fixes https://phabricator.freedesktop.org/T7320
    
    Differential Revision: https://phabricator.freedesktop.org/D749

 pitivi/application.py           |   24 ++++++++++++++----------
 pitivi/dialogs/startupwizard.py |   33 ++++++++-------------------------
 pitivi/mainwindow.py            |   22 +++++++++-------------
 pitivi/project.py               |   30 +++++++++++++++---------------
 pitivi/timeline/timeline.py     |    3 ++-
 5 files changed, 48 insertions(+), 64 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index fcb0d5d..d764ff2 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -1,10 +1,11 @@
+# -*- coding: utf-8 -*-
 # Pitivi video editor
 #
 #       pitivi/application.py
 #
 # Copyright (c) 2005-2009 Edward Hervey <bilboed bilboed com>
 # Copyright (c) 2008-2009 Alessandro Decina <alessandro d gmail com>
-# Copyright (c) 2014 <alexandru balut gmail com>
+# Copyright (c) 2014 Alexandru Băluț<alexandru balut gmail com>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -52,13 +53,11 @@ class Pitivi(Gtk.Application, Loggable):
     """
     Pitivi's application.
 
-    @type effects: L{EffectsManager}
-    @ivar gui: The main window of the app.
-    @type gui: L{PitiviMainWindow}
-    @ivar project_manager: The project manager object used in the application
-    @type project_manager: L{ProjectManager}
-    @ivar settings: Application-wide settings.
-    @type settings: L{pitivi.settings.GlobalSettings}.
+    Attributes:
+        effects (EffectsManager): The effects which can be applied to a clip.
+        gui (PitiviMainWindow): The main window of the app.
+        project_manager (ProjectManager): The holder of the current project.
+        settings (GlobalSettings): The application-wide settings.
     """
 
     __gsignals__ = {
@@ -83,7 +82,7 @@ class Pitivi(Gtk.Application, Loggable):
         self._last_action_time = Gst.util_get_timestamp()
 
         self.gui = None
-        self.welcome_wizard = None
+        self.__welcome_wizard = None
 
         self._version_information = {}
 
@@ -188,9 +187,14 @@ class Pitivi(Gtk.Application, Loggable):
             # No need to show the welcome wizard.
             return
         self.createMainWindow()
-        self.welcome_wizard = StartUpWizard(self)
         self.welcome_wizard.show()
 
+    @property
+    def welcome_wizard(self):
+        if not self.__welcome_wizard:
+            self.__welcome_wizard = StartUpWizard(self)
+        return self.__welcome_wizard
+
     def createMainWindow(self):
         if self.gui:
             return
diff --git a/pitivi/dialogs/startupwizard.py b/pitivi/dialogs/startupwizard.py
index 1688b49..b370a6f 100644
--- a/pitivi/dialogs/startupwizard.py
+++ b/pitivi/dialogs/startupwizard.py
@@ -86,11 +86,6 @@ class StartUpWizard(object):
         if not missing_soft_deps:
             missing_button.hide()
 
-        project_manager = self.app.project_manager
-        project_manager.connect("new-project-failed", self._projectFailedCb)
-        project_manager.connect("new-project-loaded", self._projectLoadedCb)
-        project_manager.connect("new-project-loading", self._projectLoadingCb)
-
         vbox = self.builder.get_object("topvbox")
         self.infobar = Gtk.InfoBar()
         vbox.pack_start(self.infobar, True, True, 0)
@@ -103,7 +98,6 @@ class StartUpWizard(object):
     def _newProjectCb(self, unused_button):
         """Handle a click on the New (Project) button."""
         self.app.project_manager.newBlankProject()
-        self.hide()
 
     def _loadCb(self, unused_recent_chooser):
         """
@@ -118,7 +112,6 @@ class StartUpWizard(object):
         if event.keyval == Gdk.KEY_Escape:
             # The user pressed "Esc".
             self.app.project_manager.newBlankProject()
-            self.hide()
 
     def _onBrowseButtonClickedCb(self, unused_button6):
         """Handle a click on the Browse button."""
@@ -131,33 +124,23 @@ class StartUpWizard(object):
     def _deleteCb(self, unused_widget, unused_event):
         """Handle a click on the X button of the dialog."""
         self.app.project_manager.newBlankProject()
-        self.hide()
 
     def show(self):
-        """Will show the interal window and position the wizard"""
+        if self.window.props.visible:
+            return
         self.window.set_transient_for(self.app.gui)
         self.window.show()
+        project_manager = self.app.project_manager
+        project_manager.connect("new-project-loading", self._projectLoadingCb)
 
     def hide(self):
-        """Will hide the internal window"""
+        if not self.window.props.visible:
+            return
         self.window.hide()
-
-    def _projectFailedCb(self, unused_project_manager, unused_uri,
-                         unused_exception):
-        """Handle the failure of a project open operation."""
-        self.show()
-
-    def _projectLoadedCb(self, project_manager, unused_project):
-        """
-        Handle the success of a project load operation.
-
-        @type project_manager: L{ProjectManager}
-        """
-        project_manager.disconnect_by_func(self._projectFailedCb)
-        project_manager.disconnect_by_func(self._projectLoadedCb)
+        project_manager = self.app.project_manager
         project_manager.disconnect_by_func(self._projectLoadingCb)
 
-    def _projectLoadingCb(self, unused_project_manager, unused_project):
+    def _projectLoadingCb(self, unused_project_manager, unused_uri):
         """Handle the start of a project load operation."""
         self.hide()
 
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 16272ee..ed5c442 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -687,11 +687,9 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
         if response == Gtk.ResponseType.OK:
             self.app.project_manager.loadProject(chooser.get_uri())
         else:
-            self.info(
-                "User cancelled loading a new project, but no other project is currently active. Resetting")
-            self.app.project_manager.newBlankProject()
+            self.info("User cancelled loading a new project")
+            self.app.welcome_wizard.show()
         chooser.destroy()
-        return True
 
     def _canLoadUri(self, filterinfo, unused_uri):
         try:
@@ -889,7 +887,7 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
                 return False
         return True
 
-    def _projectManagerNewProjectFailedCb(self, unused_project_manager, uri, exception):
+    def _projectManagerNewProjectFailedCb(self, unused_project_manager, uri, reason):
         project_filename = unquote(uri.split("/")[-1])
         dialog = Gtk.MessageDialog(transient_for=self,
                                    modal=True,
@@ -897,12 +895,13 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
                                    buttons=Gtk.ButtonsType.OK,
                                    text=_('Unable to load project "%s"') % project_filename)
         dialog.set_property("secondary-use-markup", True)
-        dialog.set_property("secondary-text", unquote(str(exception)))
+        dialog.set_property("secondary-text", unquote(str(reason)))
         dialog.set_transient_for(self)
         dialog.run()
         dialog.destroy()
+        self.app.welcome_wizard.show()
 
-    def _projectManagerMissingUriCb(self, unused_project_manager, project, unused_error, asset):
+    def _projectManagerMissingUriCb(self, project_manager, project, unused_error, asset):
         if project.at_least_one_asset_missing:
             # One asset is already missing so no point in spamming the user
             # with more file-missing dialogs, as we need all of them.
@@ -990,23 +989,20 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
         if response == Gtk.ResponseType.OK:
             self.log("User chose a new URI for the missing file")
             new_uri = chooser.get_uri()
-            self.app.project_manager.current_project.setModificationState(
-                False)
+            project_manager.current_project.setModificationState(False)
         else:
             dialog.hide()
 
             if not self.app.proxy_manager.checkProxyLoadingSucceeded(asset):
                 # Reset the project manager and disconnect all the signals.
-                self.app.project_manager.newBlankProject(
-                    ignore_unsaved_changes=True)
+                project_manager.closeRunningProject()
                 # Signal the project loading failure.
                 # You have to do this *after* successfully creating a blank project,
                 # or the startupwizard will still be connected to that signal too.
                 reason = _('No replacement file was provided for "<i>%s</i>".\n\n'
                            'Pitivi does not currently support partial projects.'
                            % info_name(asset))
-                self.app.project_manager.emit(
-                    "new-project-failed", project.uri, reason)
+                project_manager.emit("new-project-failed", project.uri, reason)
 
         dialog.destroy()
         return new_uri
diff --git a/pitivi/project.py b/pitivi/project.py
index efee8f7..8454d92 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -172,7 +172,7 @@ class ProjectManager(GObject.Object, Loggable):
     __gsignals__ = {
         "new-project-loading": (GObject.SIGNAL_RUN_LAST, None, (str,)),
         "new-project-created": (GObject.SIGNAL_RUN_LAST, None, (object,)),
-        "new-project-failed": (GObject.SIGNAL_RUN_LAST, None, (str, object)),
+        "new-project-failed": (GObject.SIGNAL_RUN_LAST, None, (str, str)),
         "new-project-loaded": (GObject.SIGNAL_RUN_LAST, None, (object,)),
         "save-project-failed": (GObject.SIGNAL_RUN_LAST, None, (str, object)),
         "project-saved": (GObject.SIGNAL_RUN_LAST, None, (object, str)),
@@ -318,28 +318,28 @@ class ProjectManager(GObject.Object, Loggable):
             uri = None
 
         # Load the project:
-        self.current_project = Project(self.app, uri=uri, scenario=scenario)
+        project = Project(self.app, uri=uri, scenario=scenario)
 
-        self.current_project.connect_after("missing-uri", self._missingURICb)
-        self.current_project.connect("loaded", self._projectLoadedCb)
+        project.connect_after("missing-uri", self._missingURICb)
+        project.connect("loaded", self._projectLoadedCb)
 
-        if self.current_project.createTimeline():
-            self.emit("new-project-created", self.current_project)
-            self.current_project.connect(
-                "project-changed", self._projectChangedCb)
-            self.current_project.pipeline.connect("died", self._projectPipelineDiedCb)
-
-            if is_validate_scenario:
-                self.current_project.setupValidateScenario()
-            return True
-        else:
+        if not project.createTimeline():
             self.emit("new-project-failed", uri,
                       _('This might be due to a bug or an unsupported project file format. '
                         'If you were trying to add a media file to your project, '
                         'use the "Import" button instead.'))
-            self.newBlankProject(ignore_unsaved_changes=True)
             return False
 
+        self.current_project = project
+        self.emit("new-project-created", self.current_project)
+        self.current_project.connect("project-changed", self._projectChangedCb)
+        self.current_project.pipeline.connect("died", self._projectPipelineDiedCb)
+
+        if is_validate_scenario:
+            self.current_project.setupValidateScenario()
+
+        return True
+
     def _restoreFromBackupDialog(self, time_diff):
         """
         Ask if we need to load the autosaved project backup or not.
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 8fb85ac..ae1858d 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -373,6 +373,8 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         if self.ges_timeline is None:
             return
 
+        self.ges_timeline.ui = self
+
         for bLayer in self.ges_timeline.get_layers():
             self._addLayer(bLayer)
 
@@ -381,7 +383,6 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         self.ges_timeline.connect("layer-removed", self._layerRemovedCb)
         self.ges_timeline.connect("snapping-started", self._snapCb)
         self.ges_timeline.connect("snapping-ended", self._snapEndedCb)
-        self.ges_timeline.ui = self
 
         self.queue_draw()
 


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