Esempio n. 1
0
def simMoviePlayer(assy):
    """
    Plays a DPB movie file created by the simulator,
    either the current movie if any, or a previously saved
    dpb file with the same name as the current part, if one can be found.
    """
    from simulation.movie import find_saved_movie, Movie  #bruce 050329 precaution (in case of similar bug to bug 499)
    win = assy.w
    if not assy.molecules:  # No model, so no movie could be valid for current part.
        # bruce 050327 comment: even so, a movie file might be valid for some other Part...
        # not yet considered here. [050427 addendum: note that user can't yet autoload a new Part
        # just by opening a movie file, so there's no point in going into the mode -- it's only meant
        # for playing a movie for the *current contents of the current part*, for now.]
        env.history.message(redmsg("Movie Player: Need a model."))
        win.simMoviePlayerAction.setChecked(
            0)  # toggle on the Movie Player icon ninad 061113
        return

    if assy.current_movie and assy.current_movie.might_be_playable():
        win.commandSequencer.userEnterCommand('MOVIE', always_update=True)
        return

    # no valid current movie, look for saved one with same name as assy
    ## env.history.message("Plot Tool: No simulation has been run yet.")
    if assy.filename:
        if assy.part is not assy.tree.part:
            msg = "Movie Player: Warning: Looking for saved movie for main part, not for displayed clipboard item."
            env.history.message(orangemsg(msg))
        errorcode, partdir = assy.find_or_make_part_files_directory()
        if not errorcode:  # filename could be an MMP or PDB file.
            dir, fil = os.path.split(assy.filename)
            fil, ext = os.path.splitext(fil)
            mfile = os.path.join(partdir, fil + '.dpb')
        else:
            mfile = os.path.splitext(assy.filename)[0] + ".dpb"
        movie = find_saved_movie(assy, mfile)
        # checks existence -- should also check validity for current part or main part, but doesn't yet ###e
        # (neither did the pre-030527 code for this function, unless that's done in moviePlay, which it might be)
        if movie:
            # play this movie, and make it the current movie.
            assy.current_movie = movie
            #e should we switch to the part for which this movie was made? [might be done in moviePlay; if not:]
            # No current way to tell how to do that, and this might be done even if it's not valid
            # for any loaded Part. So let's not... tho we might presume (from filename choice we used)
            # it was valid for Main Part. Maybe print warning for clip item, and for not valid? #e
            env.history.message(
                "Movie Player: %s previously saved movie for this part." %
                ("playing" or "loading"))
            win.commandSequencer.userEnterCommand('MOVIE', always_update=True)
            return
    # else if no assy.filename or no movie found from that:
    # bruce 050327 comment -- do what the old code did, except for the moviePlay
    # which seems wrong and tracebacks now.
    assy.current_movie = Movie(assy)
    # temporary kluge until bugs in movieMode for no assy.current_movie are fixed
    win.commandSequencer.userEnterCommand('MOVIE', always_update=True)
    return
Esempio n. 2
0
def simPlot(assy):  # moved here from MWsemantics method, bruce 050327
    """Opens the "Make Graphs" dialog (and waits until it's dismissed),
    for the current movie if there is one, otherwise for a previously saved
    dpb file with the same name as the current part, if one can be found.
    Returns the dialog, after it's dismissed (probably useless),
    or None if no dialog was shown.
    """
    #bruce 050326 inferred docstring from code, then revised to fit my recent changes
    # to assy.current_movie, but didn't yet try to look for alternate dpb file names
    # when the current part is not the main part. (I'm sure that we'll soon have a wholly
    # different scheme for letting the user look around for preexisting related files to use,
    # like movie files applicable to the current part.)
    #    I did reorder the code, and removed the check on the current part having atoms
    # (since plotting from an old file shouldn't require movie to be valid for current part).
    #    This method should be moved into some other file.

    if assy.current_movie and assy.current_movie.filename:
        return PlotTool(assy, assy.current_movie.filename)
    else:
        msg = redmsg("There is no current movie file loaded.")
        env.history.message(cmd + msg)
        return None

    # wware 060317, bug 1484
    if assy.filename:
        return PlotTool(assy, assy.filename)

    # no valid current movie, look for saved one with same name as assy
    msg = redmsg("No simulation has been run yet.")
    env.history.message(cmd + msg)
    if assy.filename:
        if assy.part is not assy.tree.part:
            msg = redmsg(
                "Warning: Looking for saved movie for main part, not for displayed clipboard item."
            )
            env.history.message(cmd + msg)
        mfile = assy.filename[:-4] + ".dpb"
        movie = find_saved_movie(assy, mfile)
        # just checks existence, not validity for current part or main part
        if movie:
            #e should we set this as current_movie? I don't see a good reason to do that,
            # user can open it if they want to. But I'll do it if we don't have one yet.
            if not assy.current_movie:
                assy.current_movie = movie
            #e should we switch to the part for which this movie was made?
            # No current way to tell how to do that, and this might be done even if it's not valid
            # for any loaded Part. So let's not... tho we might presume (from filename choice we used)
            # it was valid for Main Part. Maybe print warning for clip item, and for not valid? #e
            msg = "Using previously saved movie for this part."
            env.history.message(cmd + msg)
            return PlotTool(assy, movie)
        else:
            msg = redmsg("Can't find previously saved movie for this part.")
            env.history.message(cmd + msg)
    return
Esempio n. 3
0
def simMoviePlayer(assy):
    """
    Plays a DPB movie file created by the simulator,
    either the current movie if any, or a previously saved
    dpb file with the same name as the current part, if one can be found.
    """
    from simulation.movie import find_saved_movie, Movie #bruce 050329 precaution (in case of similar bug to bug 499)
    win = assy.w
    if not assy.molecules: # No model, so no movie could be valid for current part.
        # bruce 050327 comment: even so, a movie file might be valid for some other Part...
        # not yet considered here. [050427 addendum: note that user can't yet autoload a new Part
        # just by opening a movie file, so there's no point in going into the mode -- it's only meant
        # for playing a movie for the *current contents of the current part*, for now.]
        env.history.message(redmsg("Movie Player: Need a model."))
        win.simMoviePlayerAction.setChecked(0) # toggle on the Movie Player icon ninad 061113
        return

    if assy.current_movie and assy.current_movie.might_be_playable():
        win.commandSequencer.userEnterCommand('MOVIE')
        return

    # no valid current movie, look for saved one with same name as assy
    ## env.history.message("Plot Tool: No simulation has been run yet.")
    if assy.filename:
        if assy.part is not assy.tree.part:
            msg = "Movie Player: Warning: Looking for saved movie for main part, not for displayed clipboard item."
            env.history.message(orangemsg(msg))
        errorcode, partdir = assy.find_or_make_part_files_directory()
        if not errorcode: # filename could be an MMP or PDB file.
            dir, fil = os.path.split(assy.filename)
            fil, ext = os.path.splitext(fil)
            mfile = os.path.join(partdir, fil + '.dpb')
        else:
            mfile = os.path.splitext(assy.filename)[0] + ".dpb"
        movie = find_saved_movie( assy, mfile)
            # checks existence -- should also check validity for current part or main part, but doesn't yet ###e
            # (neither did the pre-030527 code for this function, unless that's done in moviePlay, which it might be)
        if movie:
            # play this movie, and make it the current movie.
            assy.current_movie = movie
            #e should we switch to the part for which this movie was made? [might be done in moviePlay; if not:]
            # No current way to tell how to do that, and this might be done even if it's not valid
            # for any loaded Part. So let's not... tho we might presume (from filename choice we used)
            # it was valid for Main Part. Maybe print warning for clip item, and for not valid? #e
            env.history.message("Movie Player: %s previously saved movie for this part." % ("playing" or "loading"))
            win.commandSequencer.userEnterCommand('MOVIE')
            return
    # else if no assy.filename or no movie found from that:
    # bruce 050327 comment -- do what the old code did, except for the moviePlay
    # which seems wrong and tracebacks now.
    assy.current_movie = Movie(assy)
        # temporary kluge until bugs in movieMode for no assy.current_movie are fixed
    win.commandSequencer.userEnterCommand('MOVIE')
    return
Esempio n. 4
0
def simPlot(assy): # moved here from MWsemantics method, bruce 050327
    """Opens the "Make Graphs" dialog (and waits until it's dismissed),
    for the current movie if there is one, otherwise for a previously saved
    dpb file with the same name as the current part, if one can be found.
    Returns the dialog, after it's dismissed (probably useless),
    or None if no dialog was shown.
    """
    #bruce 050326 inferred docstring from code, then revised to fit my recent changes
    # to assy.current_movie, but didn't yet try to look for alternate dpb file names
    # when the current part is not the main part. (I'm sure that we'll soon have a wholly
    # different scheme for letting the user look around for preexisting related files to use,
    # like movie files applicable to the current part.)
    #    I did reorder the code, and removed the check on the current part having atoms
    # (since plotting from an old file shouldn't require movie to be valid for current part).
    #    This method should be moved into some other file.

    if assy.current_movie and assy.current_movie.filename:
        return PlotTool(assy, assy.current_movie.filename)
    else:
        msg = redmsg("There is no current movie file loaded.")
        env.history.message(cmd + msg)
        return None
        
    # wware 060317, bug 1484
    if assy.filename:
        return PlotTool(assy, assy.filename)

    # no valid current movie, look for saved one with same name as assy
    msg = redmsg("No simulation has been run yet.")
    env.history.message(cmd + msg)
    if assy.filename:
        if assy.part is not assy.tree.part:
            msg = redmsg("Warning: Looking for saved movie for main part, not for displayed clipboard item.")
            env.history.message(cmd + msg)
        mfile = assy.filename[:-4] + ".dpb"
        movie = find_saved_movie( assy, mfile)
            # just checks existence, not validity for current part or main part
        if movie:
            #e should we set this as current_movie? I don't see a good reason to do that,
            # user can open it if they want to. But I'll do it if we don't have one yet.
            if not assy.current_movie:
                assy.current_movie = movie
            #e should we switch to the part for which this movie was made?
            # No current way to tell how to do that, and this might be done even if it's not valid
            # for any loaded Part. So let's not... tho we might presume (from filename choice we used)
            # it was valid for Main Part. Maybe print warning for clip item, and for not valid? #e
            msg = "Using previously saved movie for this part."
            env.history.message(cmd + msg)
            return PlotTool(assy, movie)
        else:
            msg = redmsg("Can't find previously saved movie for this part.")
            env.history.message(cmd + msg)
    return
Esempio n. 5
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 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