Esempio n. 1
0
def _get_partname(assy):
    """
    Returns the base name of the part.  If the filename is not set,
    returns "Untitled".
    """
    if assy.filename:
        junk, basename, ext = filesplit(assy.filename)
        return basename
    else:
        return "Untitled"
Esempio n. 2
0
    def fileSaveMovie(self):
        """
        Save a copy of the current movie file loaded in the Movie Player.
        """
        # Make sure there is a moviefile to save.
        if not self.w.assy.current_movie or not self.w.assy.current_movie.filename \
           or not os.path.exists(self.w.assy.current_movie.filename):

            msg = redmsg("Save Movie File: No movie file to save.")
            env.history.message(msg)
            msg = "To create a movie, click on the <b>Simulator</b> <img source=\"simicon\"> icon."
            #QMimeSourceFactory.defaultFactory().setPixmap( "simicon",
            #            self.simSetupAction.iconSet().pixmap() )
            env.history.message(msg)
            return

        env.history.message(greenmsg("Save Movie File:"))

        if self.w.assy.filename: sdir = self.w.assy.filename
        else: sdir = env.prefs[workingDirectory_prefs_key]

        sfilter = QString("Differential Position Bytes Format (*.dpb)")

        # Removed .xyz as an option in the sfilter since the section of code below
        # to save XYZ files never worked anyway.  This also fixes bug 492.  Mark 050816.

        fn = QFileDialog.getSaveFileName(
            self, "Save As", sdir,
            "Differential Position Bytes Format (*.dpb);;POV-Ray Series (*.pov)",
            sfilter)

        if not fn:
            env.history.message("Cancelled.")
            return
        else:
            fn = str(fn)
            dir, fil, ext2 = filesplit(fn)
            del ext2  #bruce 050413
            ext = str(
                sfilter[-5:-1]
            )  # Get "ext" from the sfilter. It *can* be different from "ext2"!!! - Mark
            #bruce 050413 comment: the above assumes that len(ext) is always 4 (.xxx).
            # I'm speculating that this is ok for now since it has to be one of the ones
            # provided to the getSaveFileName method above.
            # Changed os.path.join > os.path.normpath to partially fix bug #956.  Mark 050911.
            safile = os.path.normpath(dir + "/" + fil +
                                      ext)  # full path of "Save As" filename

            if os.path.exists(
                    safile):  # ...and if the "Save As" file exists...

                # ... confirm overwrite of the existing file.
                ret = QMessageBox.warning(
                    self, "Confirm overwrite",
                    "The file \"" + fil + ext + "\" already exists.\n"\
                    "Do you want to overwrite the existing file or cancel?",
                    "&Overwrite", "&Cancel", "",
                    0,      # Enter == button 0
                    1 )     # Escape == button 1

                if ret == 1:  # The user cancelled
                    env.history.message("Cancelled.  File not saved.")
                    return  # Cancel clicked or Alt+C pressed or Escape pressed

            if ext == '.dpb':
                self.w.assy.current_movie._close()
                import shutil
                shutil.copy(self.w.assy.current_movie.filename, safile)

                # Get the trace file name.
                tfile1 = self.w.assy.current_movie.get_trace_filename()

                # Copy the tracefile
                if os.path.exists(tfile1):
                    fullpath, ext = os.path.splitext(safile)
                    tfile2 = fullpath + "-trace.txt"
                    shutil.copy(tfile1, tfile2)

                env.history.message("DPB movie file saved: " + safile)
                # note that we are still playing it from the old file and filename... does it matter? [bruce 050427 question]

                # Added "hflag=False" to suppress history msg, fixing bug #956.  Mark 050911.
                self.w.assy.current_movie.cueMovie(
                    propMgr=self,
                    hflag=False)  # Do not print info to history widget.

            elif ext == '.pov':
                self.w.assy.current_movie._write_povray_series(
                    os.path.normpath(dir + "/" + fil))

            else:  #.xyz (or something unexpected)
                #bruce 051115 added warning and immediate return, to verify that this code is never called
                QMessageBox.warning(
                    self, "ERROR",
                    "internal error: unsupported file extension %r" %
                    (ext, ))  # args are title, content

        return  # from fileSaveMovie
Esempio n. 3
0
    def fileOpenMovie(self):
        """
        Open a movie file to play.
        """
        # bruce 050327 comment: this is not yet updated for "multiple movie objects"
        # and bugfixing of bugs introduced by that is in progress (only done in a klugy
        # way so far). ####@@@@
        env.history.message(greenmsg("Open Movie File:"))
        assert self.w.assy.current_movie
        # (since (as a temporary kluge) we create an empty one, if necessary, before entering
        #  Movie Mode, of which this is a dashboard method [bruce 050328])
        if self.w.assy.current_movie and self.w.assy.current_movie.currentFrame != 0:
            ###k bruce 060108 comment: I don't know if this will happen when currentFrame != 0 due to bug 1273 fix... #####@@@@@
            env.history.message(
                redmsg(
                    "Current movie must be reset to frame 0 to load a new movie."
                ))
            return

        # Determine what directory to open. [bruce 050427 comment: if no moviefile, we should try assy.filename's dir next ###e]
        if self.w.assy.current_movie and self.w.assy.current_movie.filename:
            odir, fil, ext = filesplit(self.w.assy.current_movie.filename)
            del fil, ext  #bruce 050413
        else:
            odir = self.w.currentWorkingDirectory  # Fixes bug 291 (comment #4). Mark 060729.

        fn = QFileDialog.getOpenFileName(
            self, "Differential Position Bytes Format (*.dpb)", odir)

        if not fn:
            env.history.message("Cancelled.")
            return

        fn = str(fn)

        # Check if file with name fn is a movie file which is valid for the current Part
        # [bruce 050324 made that a function and made it print the history messages
        #  which I've commented out below.]
        from simulation.movie import _checkMovieFile
        r = _checkMovieFile(self.w.assy.part, fn)

        if r == 1:

            ##            msg = redmsg("Cannot play movie file [" + fn + "]. It does not exist.")
            ##            env.history.message(msg)
            return
        elif r == 2:
            ##            msg = redmsg("Movie file [" + fn + "] not valid for the current part.")
            ##            env.history.message(msg)
            if self.w.assy.current_movie and self.w.assy.current_movie.might_be_playable(
            ):  #bruce 050427 isOpen -> might_be_playable()
                msg = "(Previous movie file [" + self.w.assy.current_movie.filename + "] is still open.)"
                env.history.message(msg)
            return

        #bruce 050427 rewrote the following to use a new Movie object
        from simulation.movie import find_saved_movie
        new_movie = find_saved_movie(self.w.assy, fn)
        if new_movie:
            new_movie.set_alist_from_entire_part(
                self.w.assy.part)  # kluge? might need changing...
            if self.w.assy.current_movie:  #bruce 050427 no longer checking isOpen here
                self.w.assy.current_movie._close()
            self.w.assy.current_movie = new_movie
            self.w.assy.current_movie.cueMovie(propMgr=self)
            #Make sure to enable movie control buttons!
            self.command.enableMovieControls(True)
            self.updateFrameInformation()
            self._updateMessageInModePM()
        else:
            # should never happen due to _checkMovieFile call, so this msg is ok
            # (but if someday we do _checkMovieFile inside find_saved_movie and not here,
            #  then this will happen as an error return from find_saved_movie)
            msg = redmsg("Internal error in fileOpenMovie")
            self.command.enableMovieControls(False)
            self._updateMessageInModePM(msg)
            env.history.message(msg)
        return
    def fileSaveMovie(self):
        """
        Save a copy of the current movie file loaded in the Movie Player.
        """
        # Make sure there is a moviefile to save.
        if not self.w.assy.current_movie or not self.w.assy.current_movie.filename \
           or not os.path.exists(self.w.assy.current_movie.filename):

            msg = redmsg("Save Movie File: No movie file to save.")
            env.history.message(msg)
            msg = "To create a movie, click on the <b>Simulator</b> <img source=\"simicon\"> icon."
            #QMimeSourceFactory.defaultFactory().setPixmap( "simicon",
            #            self.simSetupAction.iconSet().pixmap() )
            env.history.message(msg)
            return

        env.history.message(greenmsg("Save Movie File:"))

        if self.w.assy.filename: sdir = self.w.assy.filename
        else: sdir = env.prefs[workingDirectory_prefs_key]

        sfilter = QString("Differential Position Bytes Format (*.dpb)")

        # Removed .xyz as an option in the sfilter since the section of code below
        # to save XYZ files never worked anyway.  This also fixes bug 492.  Mark 050816.

        fn = QFileDialog.getSaveFileName(
            self,
            "Save As",
            sdir,
            "Differential Position Bytes Format (*.dpb);;POV-Ray Series (*.pov)",
            sfilter)

        if not fn:
            env.history.message("Cancelled.")
            return
        else:
            fn = str(fn)
            dir, fil, ext2 = filesplit(fn)
            del ext2 #bruce 050413
            ext = str(sfilter[-5:-1]) # Get "ext" from the sfilter. It *can* be different from "ext2"!!! - Mark
                #bruce 050413 comment: the above assumes that len(ext) is always 4 (.xxx).
                # I'm speculating that this is ok for now since it has to be one of the ones
                # provided to the getSaveFileName method above.
            # Changed os.path.join > os.path.normpath to partially fix bug #956.  Mark 050911.
            safile = os.path.normpath(dir + "/" + fil + ext) # full path of "Save As" filename

            if os.path.exists(safile): # ...and if the "Save As" file exists...

                # ... confirm overwrite of the existing file.
                ret = QMessageBox.warning(
                    self, "Confirm overwrite",
                    "The file \"" + fil + ext + "\" already exists.\n"\
                    "Do you want to overwrite the existing file or cancel?",
                    "&Overwrite", "&Cancel", "",
                    0,      # Enter == button 0
                    1 )     # Escape == button 1

                if ret == 1: # The user cancelled
                    env.history.message( "Cancelled.  File not saved." )
                    return # Cancel clicked or Alt+C pressed or Escape pressed

            if ext == '.dpb':
                self.w.assy.current_movie._close()
                import shutil
                shutil.copy(self.w.assy.current_movie.filename, safile)

                # Get the trace file name.
                tfile1 = self.w.assy.current_movie.get_trace_filename()

                # Copy the tracefile
                if os.path.exists(tfile1):
                    fullpath, ext = os.path.splitext(safile)
                    tfile2 = fullpath + "-trace.txt"
                    shutil.copy(tfile1, tfile2)

                env.history.message("DPB movie file saved: " + safile)
                # note that we are still playing it from the old file and filename... does it matter? [bruce 050427 question]

                # Added "hflag=False" to suppress history msg, fixing bug #956.  Mark 050911.
                self.w.assy.current_movie.cueMovie(propMgr = self, hflag = False) # Do not print info to history widget.

            elif ext == '.pov':
                self.w.assy.current_movie._write_povray_series(
                    os.path.normpath(dir + "/" + fil))

            else: #.xyz (or something unexpected)
                #bruce 051115 added warning and immediate return, to verify that this code is never called
                QMessageBox.warning(self, "ERROR", "internal error: unsupported file extension %r" % (ext,) ) # args are title, content

        return # from fileSaveMovie
    def fileOpenMovie(self):
        """
        Open a movie file to play.
        """
        # bruce 050327 comment: this is not yet updated for "multiple movie objects"
        # and bugfixing of bugs introduced by that is in progress (only done in a klugy
        # way so far). ####@@@@
        env.history.message(greenmsg("Open Movie File:"))
        assert self.w.assy.current_movie
            # (since (as a temporary kluge) we create an empty one, if necessary, before entering
            #  Movie Mode, of which this is a dashboard method [bruce 050328])
        if self.w.assy.current_movie and self.w.assy.current_movie.currentFrame != 0:
            ###k bruce 060108 comment: I don't know if this will happen when currentFrame != 0 due to bug 1273 fix... #####@@@@@
            env.history.message(redmsg("Current movie must be reset to frame 0 to load a new movie."))
            return

        # Determine what directory to open. [bruce 050427 comment: if no moviefile, we should try assy.filename's dir next ###e]
        if self.w.assy.current_movie and self.w.assy.current_movie.filename:
            odir, fil, ext = filesplit(self.w.assy.current_movie.filename)
            del fil, ext #bruce 050413
        else:
            odir = self.w.currentWorkingDirectory # Fixes bug 291 (comment #4). Mark 060729.


        fn = QFileDialog.getOpenFileName(
            self,
            "Differential Position Bytes Format (*.dpb)",
            odir)

        if not fn:
            env.history.message("Cancelled.")
            return

        fn = str(fn)

        # Check if file with name fn is a movie file which is valid for the current Part
        # [bruce 050324 made that a function and made it print the history messages
        #  which I've commented out below.]
        from simulation.movie import _checkMovieFile
        r = _checkMovieFile(self.w.assy.part, fn)

        if r == 1:

##            msg = redmsg("Cannot play movie file [" + fn + "]. It does not exist.")
##            env.history.message(msg)
            return
        elif r == 2:
##            msg = redmsg("Movie file [" + fn + "] not valid for the current part.")
##            env.history.message(msg)
            if self.w.assy.current_movie and self.w.assy.current_movie.might_be_playable(): #bruce 050427 isOpen -> might_be_playable()
                msg = "(Previous movie file [" + self.w.assy.current_movie.filename + "] is still open.)"
                env.history.message(msg)
            return

        #bruce 050427 rewrote the following to use a new Movie object
        from simulation.movie import find_saved_movie
        new_movie = find_saved_movie( self.w.assy, fn )
        if new_movie:
            new_movie.set_alist_from_entire_part(self.w.assy.part) # kluge? might need changing...
            if self.w.assy.current_movie: #bruce 050427 no longer checking isOpen here
                self.w.assy.current_movie._close()
            self.w.assy.current_movie = new_movie
            self.w.assy.current_movie.cueMovie(propMgr = self)
            #Make sure to enable movie control buttons!
            self.parentMode.enableMovieControls(True)
            self.updateFrameInformation()
            self._updateMessageInModePM()
        else:
            # should never happen due to _checkMovieFile call, so this msg is ok
            # (but if someday we do _checkMovieFile inside find_saved_movie and not here,
            #  then this will happen as an error return from find_saved_movie)
            msg = redmsg("Internal error in fileOpenMovie")
            self.parentMode.enableMovieControls(False)
            self._updateMessageInModePM(msg)
            env.history.message(msg)
        return