コード例 #1
0
    def _debug_profile_userEnterCommand(self):
        """
        Debug menu command for profiling userEnterCommand(commandName).

        This creates a profile.output file on each use
        (replacing a prior one if any, even if it was created
        during the same session).

        Note that for some commands, a lot more work will be done the
        first time they are entered during a session (or in some cases,
        the first time since opening a new file) than in subsequent times.
        """
        # Ninad 2008-10-03; renamed/revised by bruce 090305
        
        RECOGNIZED_COMMAND_NAMES = (
            'DEPOSIT', 
            'BUILD_DNA', 
            'DNA_SEGMENT', 
            'DNA_STRAND',
            'CRYSTAL', 
            'BUILD_NANOTUBE', 
            'EDIT_NANOTUBE',
            'EXTRUDE', 
            'MODIFY',
            'MOVIE'
         )
        
        ok, commandName =  grab_text_line_using_dialog(
            title = "profile entering given command", 
            label = "Enter the command.commandName e.g. 'BUILD_DNA' , 'DEPOSIT'"
         )
        if not ok:
            print "No command name entered, returning"
            return
        
        commandName = str(commandName)
        commandName = commandName.upper()
        if not commandName in RECOGNIZED_COMMAND_NAMES:
            #bruce 090305 changed this to just a warning, added try/except
            print "Warning: command name %r might or might not work. " \
                  "Trying it anyway." % (commandName,)
            pass 
        
        print "Profiling command enter for %s" % (commandName,)
                 
        win = self._debug_win
        meth = self.win.commandSequencer.userEnterCommand
        set_enabled_for_profile_single_call(True)
        tm0 = clock()
        try:
            profile_single_call_if_enabled(meth, commandName)
        except:
            print "exception entering command caught and discarded." #e improve
            sys.stdout.flush()
            pass
        tm1 = clock()
        set_enabled_for_profile_single_call(False)
        print "Profiling complete. Total CPU time to enter %s = %s" % \
              (commandName, (tm1 - tm0))
        return
コード例 #2
0
    def _debug_profile_userEnterCommand(self):
        """
        Debug menu command for profiling userEnterCommand(commandName).

        This creates a profile.output file on each use
        (replacing a prior one if any, even if it was created
        during the same session).

        Note that for some commands, a lot more work will be done the
        first time they are entered during a session (or in some cases,
        the first time since opening a new file) than in subsequent times.
        """
        # Ninad 2008-10-03; renamed/revised by bruce 090305

        RECOGNIZED_COMMAND_NAMES = ('DEPOSIT', 'BUILD_DNA', 'DNA_SEGMENT',
                                    'DNA_STRAND', 'CRYSTAL', 'BUILD_NANOTUBE',
                                    'EDIT_NANOTUBE', 'EXTRUDE', 'MODIFY',
                                    'MOVIE')

        ok, commandName = grab_text_line_using_dialog(
            title="profile entering given command",
            label="Enter the command.commandName e.g. 'BUILD_DNA' , 'DEPOSIT'")
        if not ok:
            print "No command name entered, returning"
            return

        commandName = str(commandName)
        commandName = commandName.upper()
        if not commandName in RECOGNIZED_COMMAND_NAMES:
            #bruce 090305 changed this to just a warning, added try/except
            print "Warning: command name %r might or might not work. " \
                  "Trying it anyway." % (commandName,)
            pass

        print "Profiling command enter for %s" % (commandName, )

        win = self._debug_win
        meth = self.win.commandSequencer.userEnterCommand
        set_enabled_for_profile_single_call(True)
        tm0 = clock()
        try:
            profile_single_call_if_enabled(meth, commandName)
        except:
            print "exception entering command caught and discarded."  #e improve
            sys.stdout.flush()
            pass
        tm1 = clock()
        set_enabled_for_profile_single_call(False)
        print "Profiling complete. Total CPU time to enter %s = %s" % \
              (commandName, (tm1 - tm0))
        return
コード例 #3
0
    def addFavorite(self):
        """
        create and add favorite to favorites directory and favorites combo box
        in PM
        @note: Rules and other info:
         - The new favorite is defined by the current Protein display style 
           settings.
         - The user is prompted to type in a name for the new
           favorite.
         - The Protein display style settings are written to a file in a special
           directory on the disk
          (i.e. $HOME/Nanorex/Favorites/ProteinDisplayStyle/$FAV_NAME.txt).
         - The name of the new favorite is added to the list of favorites in
           the combobox, which becomes the current option.
           Existence of a favorite with the same name is checked in the above
           mentioned location and if a duplicate exists, then the user can either
           overwrite and provide a new name.
        """


        # Prompt user for a favorite name to add.
        from widgets.simple_dialogs import grab_text_line_using_dialog

        ok1, name = \
          grab_text_line_using_dialog(
              title = "Add new favorite",
              label = "favorite name:",
              iconPath = "ui/actions/Properties Manager/AddFavorite.png",
              default = "" )
        if ok1:
            # check for duplicate files in the
            # $HOME/Nanorex/Favorites/DnaDisplayStyle/ directory

            fname = getFavoritePathFromBasename( name )
            if os.path.exists(fname):

                #favorite file already exists!

                _ext= ".txt"
                ret = QMessageBox.warning( self, "Warning!",
                "The favorite file \"" + name + _ext + "\"already exists.\n"
                "Do you want to overwrite the existing file?",
                "&Overwrite", "&Cancel", "",
                0,    # Enter == button 0
                1)   # Escape == button 1

                if ret == 0:
                    #overwrite favorite file
                    ok2, text = writeProteinDisplayStyleSettingsToFavoritesFile(name)
                    indexOfDuplicateItem = self.favoritesComboBox.findText(name)
                    self.favoritesComboBox.removeItem(indexOfDuplicateItem)
                    print "Add Favorite: removed duplicate favorite item."
                else:
                    env.history.message("Add Favorite: cancelled overwriting favorite item.")
                    return

            else:
                ok2, text = writeProteinDisplayStyleSettingsToFavoritesFile(name)
        else:
            # User cancelled.
            return
        if ok2:

            self.favoritesComboBox.addItem(name)
            _lastItem = self.favoritesComboBox.count()
            self.favoritesComboBox.setCurrentIndex(_lastItem - 1)
            msg = "New favorite [%s] added." % (text)
        else:
            msg = "Can't add favorite [%s]: %s" % (name, text) # text is reason why not

        env.history.message(msg)

        return
コード例 #4
0
    def addFavorite(self):
        """
        Adds a new favorite to the user's list of favorites.
        """
        # Rules and other info:
        # - The new favorite is defined by the current color scheme
        #    settings.

        # - The user is prompted to type in a name for the new
        #    favorite.
        # - The color scheme settings are written to a file in a special
        #    directory on the disk
        # (i.e. $HOME/Nanorex/Favorites/ColorScheme/$FAV_NAME.txt).
        # - The name of the new favorite is added to the list of favorites in
        #    the combobox, which becomes the current option.

        # Existence of a favorite with the same name is checked in the above
        # mentioned location and if a duplicate exists, then the user can either
        # overwrite and provide a new name.

        # Prompt user for a favorite name to add.
        from widgets.simple_dialogs import grab_text_line_using_dialog

        ok1, name = \
          grab_text_line_using_dialog(
              title = "Add new favorite",
              label = "favorite name:",
              iconPath = "ui/actions/Properties Manager/AddFavorite.png",
              default = "" )
        if ok1:
            # check for duplicate files in the
            # $HOME/Nanorex/Favorites/ColorScheme/ directory

            fname = getFavoritePathFromBasename( name )
            if os.path.exists(fname):

                #favorite file already exists!

                _ext= ".txt"
                ret = QMessageBox.warning( self, "Warning!",
                "The favorite file \"" + name + _ext + "\"already exists.\n"
                "Do you want to overwrite the existing file?",
                "&Overwrite", "&Cancel", "",
                0,    # Enter == button 0
                1)   # Escape == button 1

                if ret == 0:
                    #overwrite favorite file
                    ok2, text = writeColorSchemeToFavoritesFile(name)
                    indexOfDuplicateItem = self.favoritesComboBox.findText(name)
                    self.favoritesComboBox.removeItem(indexOfDuplicateItem)
                    print "Add Favorite: removed duplicate favorite item."
                else:
                    env.history.message("Add Favorite: cancelled overwriting favorite item.")
                    return

            else:
                ok2, text = writeColorSchemeToFavoritesFile(name)
        else:
            # User cancelled.
            return
        if ok2:

            self.favoritesComboBox.addItem(name)
            _lastItem = self.favoritesComboBox.count()
            self.favoritesComboBox.setCurrentIndex(_lastItem - 1)
            msg = "New favorite [%s] added." % (text)
        else:
            msg = "Can't add favorite [%s]: %s" % (name, text) # text is reason why not

        env.history.message(msg)
        return