Example #1
0
    def save_project(self, project):
        """Save project to its save location, returns True if success, False if failed"""
        logging.info("App: save_project - Save project out to disk")

        # Create new writer
        t_writer = tcp_writer(self.activeproject.save_location(), "json")

        # Write out project
        ret = t_writer.write(project)

        # If saving worked, update current status
        if ret:
            project.saved(ret)
            project.update_hash()

            # Update frame to reflect change to active project
            if self.gui:
                self.frame.update()
                self.project_has_changed()
                self.set_status_text(gt("Project was saved successfully"))
            logging.debug(
                "App: save_project - save_project - Save project success")
            return True
        else:
            # Saving failed for some reason
            logging.error(
                "App: save_project - ERROR: save_project - Saving failed!")
            if self.gui:
                self.set_status_text(gt("ERROR: Failed to save project!"), 0)
                dlg = wx.MessageDialog(
                    None, "Error saving file, please see log file for details",
                    "Error", wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
            return False
Example #2
0
    def save_project(self, project):
        """Save project to its save location, returns True if success, False if failed"""
        debug(u"App: save_project - Save project out to disk")

        # Create new writer
        t_writer = tcp_writer(self.activeproject.save_location(), "json")

        # Write out project
        ret = t_writer.write(project)

        # If saving worked, update current status
        if ret:
            project.saved(ret)
            project.update_hash()

            # Update frame to reflect change to active project
            if self.gui:
                self.frame.update()
                self.project_has_changed()
                self.set_status_text(gt("Project was saved successfully"))
            debug(u"App: save_project - save_project - Save project success")
            return True
        else:
            # Saving failed for some reason
            debug(u"App: save_project - ERROR: save_project - Saving failed!")
            if self.gui:
                self.set_status_text(gt("ERROR: Failed to save project!"), 0)
                dlg = wx.MessageDialog(None, "Error saving file, please see log file for details", "Error", wx.OK|wx.ICON_ERROR)
                dlg.ShowModal()
            return False
Example #3
0
 def OnLoadProject(self, loadpath=None):
     """Init process of loading a project from file, if optional savepath is specified then skip the load file dialog"""
     logging.info("App: OnLoadProject")
     project = self.activeproject
     if self.activeproject.has_changed():
         ret = self.dialog_save_changes(project)  # Prompt to save project
         if ret == wx.ID_YES:  # If answer is yes
             if not project.saved():  #  Check if file has a save location
                 if not self.dialog_save_location(
                         project):  #  If it doesn't, prompt user for one
                     return False  #  If user cancels, quit out
             if not self.save_project(
                     project):  #  Otherwise save the project
                 return False  # If project saving fails abort loading or we'd lose changes
         elif ret == wx.ID_CANCEL:  # If answer is no
             return False  # Quit out
         # else ret is wx.ID_NO, so we don't want to save but can continue
     if loadpath is None:  # Check if a load path was passed into this function
         loadpath = self.dialog_load()  # If not prompt for file to load
     if loadpath != wx.ID_CANCEL and loadpath != False:  # If user picked a file and didn't cancel the dialog
         logging.debug(
             "App: OnLoadProject - Load dialog returned a path: %s" %
             loadpath)
         return self.load_project(
             loadpath
         )  # Load the project (returns project object or False depending on success)
     else:  # Otherwise
         return False  # Quit out
Example #4
0
 def OnSaveProject(self, project):
     """Init process of saving a project to file"""
     debug(u"App: OnSaveProject")
     if project.saved():
         return self.save_project(project)                       # Returns True on save success, False on failure
     else:
         if self.dialog_save_location(project):
             return self.save_project(project)                   # Returns True on save success, False on failure
         return False
     # Project already saved
     return True
Example #5
0
 def OnSaveProject(self, project):
     """Init process of saving a project to file"""
     logging.info("App: OnSaveProject")
     if project.saved():
         # Returns True on save success, False on failure
         return self.save_project(project)
     else:
         if self.dialog_save_location(project):
             # Returns True on save success, False on failure
             return self.save_project(project)
         return False
     # Project already saved
     return True
Example #6
0
 def OnNewProject(self):
     """Init process of starting a new project"""
     logging.info("App: OnNewProject")
     project = self.activeproject
     if self.activeproject.has_changed():
         ret = self.dialog_save_changes(project)
         if ret == wx.ID_YES:
             if not project.saved():
                 if not self.dialog_save_location(project):
                     return False
             if not self.save_project(project):
                 return False
         elif ret == wx.ID_CANCEL:
             return False
     self.new_project()
Example #7
0
 def OnNewProject(self):
     """Init process of starting a new project"""
     debug(u"App: OnNewProject")
     project = self.activeproject
     if self.activeproject.has_changed():
         ret = self.dialog_save_changes(project)
         if ret == wx.ID_YES:
             if not project.saved():
                 if not self.dialog_save_location(project):
                     return False
             if not self.save_project(project):
                 return False
         elif ret == wx.ID_CANCEL:
             return False
     self.new_project()
Example #8
0
 def OnLoadProject(self, loadpath=None):
     """Init process of loading a project from file, if optional savepath is specified then skip the load file dialog"""
     debug(u"App: OnLoadProject")
     project = self.activeproject
     if self.activeproject.has_changed():
         ret = self.dialog_save_changes(project)                 # Prompt to save project
         if ret == wx.ID_YES:                                    # If answer is yes
             if not project.saved():                             #  Check if file has a save location
                 if not self.dialog_save_location(project):      #  If it doesn't, prompt user for one
                     return False                                #  If user cancels, quit out
             if not self.save_project(project):                  #  Otherwise save the project
                 return False                                    # If project saving fails abort loading or we'd lose changes
         elif ret == wx.ID_CANCEL:                               # If answer is no
             return False                                        # Quit out
         # else ret is wx.ID_NO, so we don't want to save but can continue
     if loadpath is None:                                        # Check if a load path was passed into this function
         loadpath = self.dialog_load()                           # If not prompt for file to load
     if loadpath != wx.ID_CANCEL and loadpath != False:          # If user picked a file and didn't cancel the dialog
         debug(u"App: OnLoadProject - Load dialog returned a path: %s" % loadpath)
         return self.load_project(loadpath)                      # Load the project (returns project object or False depending on success)
     else:                                                       # Otherwise
         return False                                            # Quit out