示例#1
0
    def Invert(self):
        """
        Invert the atoms of the selected chunk(s) around the chunk centers
        """
        mc = env.begin_op("Invert")
        cmd = greenmsg("Invert: ")

        if not self.selmols:
            msg = redmsg("No selected chunks to invert")
            env.history.message(cmd + msg)
            return
        self.changed()
        for m in self.selmols:
            m.stretch(-1.0)
        self.o.gl_update()

        info = fix_plurals( "Inverted %d chunk(s)" % len(self.selmols))
        env.history.message( cmd + info)
        env.end_op(mc) #e try/finally?
示例#2
0
 def Invert(self):
     """
     Invert the atoms of the selected chunk(s) around the chunk centers
     """
     mc = env.begin_op("Invert")
     cmd = greenmsg("Invert: ")
     
     if not self.selmols:
         msg = redmsg("No selected chunks to invert")
         env.history.message(cmd + msg)
         return
     self.changed()
     for m in self.selmols:
         m.stretch(-1.0)
     self.o.gl_update()
     
     info = fix_plurals( "Inverted %d chunk(s)" % len(self.selmols))
     env.history.message( cmd + info)
     env.end_op(mc) #e try/finally?
示例#3
0
    def Stretch(self):
        """
        stretch a Chunk
        """
        mc = env.begin_op("Stretch")
        try:
            cmd = greenmsg("Stretch: ")

            if not self.selmols:
                msg =  redmsg("No selected chunks to stretch")
                env.history.message(cmd + msg)
            else:
                self.changed()
                for m in self.selmols:
                    m.stretch(1.1)
                self.o.gl_update()

                # Added history message.  Mark 050413.
                info = fix_plurals( "Stretched %d chunk(s)" % len(self.selmols))
                env.history.message( cmd + info)
        finally:
            env.end_op(mc)
        return
示例#4
0
 def Stretch(self):
     """
     stretch a Chunk
     """
     mc = env.begin_op("Stretch")
     try:
         cmd = greenmsg("Stretch: ")
         
         if not self.selmols:
             msg =  redmsg("No selected chunks to stretch")
             env.history.message(cmd + msg)
         else:
             self.changed()
             for m in self.selmols:
                 m.stretch(1.1)
             self.o.gl_update()
             
             # Added history message.  Mark 050413.
             info = fix_plurals( "Stretched %d chunk(s)" % len(self.selmols))
             env.history.message( cmd + info)
     finally:
         env.end_op(mc)
     return
 def begin(self):
     ##        if 1: # 060121 debug code
     ##            try:
     ##                se = self.sender() # this can only be tried when we inherit from QObject, but it always had this exception.
     ##            except RuntimeError: # underlying C/C++ object has been deleted [common, don't yet know why, but have a guess]
     ##                print "no sender"
     ##                pass
     ##            else:
     ##                print "sender",se
     ## cp_fn = None # None, or a true thing enabling us to call undo_checkpoint_after_command
     if 1:  #060127
         in_event_loop = env._in_event_loop
         mc = env.begin_op(
             "(wr)"
         )  # should always change env._in_event_loop to False (or leave it False)
         assert not env._in_event_loop
     if in_event_loop:  #060121, revised 060127 and cond changed from 1 to in_event_loop
         #e if necessary we could find out whether innermost op_run in changes.py's stack still *wants* a cmdname to be guessed...
         # this would be especially important if it turns out this runs in inner calls and guesses it wrong,
         # overwriting a correct guess from somewhere else...
         # also don't we need to make sure that the cmd_seg we're guessing for is the right one, somehow???
         # doesn't that mean the same as, this begin_op is the one that changed the boundary? (ie call came from event loop?)
         sender = self.__sender
         ##print "sender",sender # or could grab its icon for insertion into history
         from foundation.whatsthis_utilities import map_from_id_QAction_to_featurename
         fn = map_from_id_QAction_to_featurename.get(id(sender))
         # When we used sender rather than id(sender), the UI seemed noticably slower!!
         # Possible problem with using id() is for temporary items -- when they're gone,
         # newly allocated ones with same id might seem to have those featurenames.
         # Perhaps we need to verify the name is still present in the whatsthis text?
         # But we don't have the item itself here! We could keep it in the value, and then
         # it would stick around forever anyway so its id wouldn't be reused,
         # but we'd have a memory leak for dynamic menus. Hmm... maybe we could add our own
         # key attribute to these items? And also somehow remove temporary ones from this dict
         # soon after they go away, or when new temp items are created for same featurename?
         # ... Decision [nim]: use our own key attr, don't bother removing old items from dict,
         # the leak per-cmenu is smaller than others we have per-user-command. ####@@@@ DOIT
         if fn:
             if 1:  #experiment 060121
                 from utilities.debug import print_compact_traceback
                 try:
                     win = env.mainwindow()
                     assert win.initialised  # make sure it's not too early
                     assy = win.assy
                 except:
                     if debug_flags.atom_debug:
                         print_compact_traceback(
                             "atom_debug: fyi: normal exception: ")
                     pass  # this is normal during init... or at least I thought it would be -- I never actually saw it yet.
                 else:
                     ##                        begin_retval = assy.undo_checkpoint_before_command(fn)
                     ##                        cp_fn = fn, begin_retval #e this should include a retval from that method, but must also always be true
                     if 1:  #060127
                         # note, ideally this assy and the one that subscribes to command_segment changes
                         # should be found in the same way (ie that one should sub to this too) -- could this just iterate over
                         # same list and call it differently, with a different flag?? ##e
                         assy.current_command_info(
                             cmdname=fn
                         )  #e cmdname might be set more precisely by the slot we're wrapping
             if 0:
                 print " featurename =", fn
                 # This works! prints correct names for toolbuttons and main menu items.
                 # Doesn't work for glpane cmenu items, but I bet it will when we fix them to have proper WhatsThis text.
                 # Hmm, how will we do that? There is presently no formal connection between them and the usual qactions
                 # or toolbuttons or whatsthis features for the main UI for the same method. We might have to detect the
                 # identity of the bound method they call as a slot! Not sure if this is possible. If not, we have to set
                 # command names from inside the methods that implement them (not the end of the world), or grab them from
                 # history text (doable).
         else:
             #060320 debug code; note, this shows signals that might not need undo cp's, but for almost all signals,
             # they might in theory need them in the future for some recipients, so it's not usually safe to exclude them.
             # Instead, someday we'll optimize this more when no changes actually occurred (e.g. detect that above).
             if 0 and env.debug():
                 print "debug: wrappedslot found no featurename, signal = %r, sender = %r" % (
                     self.__signal, sender)
     ## return cp_fn, mc  #060123 revised retval
     return mc
示例#6
0
    def begin(self):
##        if 1: # 060121 debug code
##            try:
##                se = self.sender() # this can only be tried when we inherit from QObject, but it always had this exception.
##            except RuntimeError: # underlying C/C++ object has been deleted [common, don't yet know why, but have a guess]
##                print "no sender"
##                pass
##            else:
##                print "sender",se
        ## cp_fn = None # None, or a true thing enabling us to call undo_checkpoint_after_command
        if 1: #060127
            in_event_loop = env._in_event_loop
            mc = env.begin_op("(wr)") # should always change env._in_event_loop to False (or leave it False)
            assert not env._in_event_loop
        if in_event_loop: #060121, revised 060127 and cond changed from 1 to in_event_loop
            #e if necessary we could find out whether innermost op_run in changes.py's stack still *wants* a cmdname to be guessed...
            # this would be especially important if it turns out this runs in inner calls and guesses it wrong,
            # overwriting a correct guess from somewhere else...
            # also don't we need to make sure that the cmd_seg we're guessing for is the right one, somehow???
            # doesn't that mean the same as, this begin_op is the one that changed the boundary? (ie call came from event loop?)
            sender = self.__sender
            ##print "sender",sender # or could grab its icon for insertion into history
            from foundation.whatsthis_utilities import map_from_id_QAction_to_featurename
            fn = map_from_id_QAction_to_featurename.get(id(sender))
                # When we used sender rather than id(sender), the UI seemed noticably slower!!
                # Possible problem with using id() is for temporary items -- when they're gone,
                # newly allocated ones with same id might seem to have those featurenames.
                # Perhaps we need to verify the name is still present in the whatsthis text?
                # But we don't have the item itself here! We could keep it in the value, and then
                # it would stick around forever anyway so its id wouldn't be reused,
                # but we'd have a memory leak for dynamic menus. Hmm... maybe we could add our own
                # key attribute to these items? And also somehow remove temporary ones from this dict
                # soon after they go away, or when new temp items are created for same featurename?
                # ... Decision [nim]: use our own key attr, don't bother removing old items from dict,
                # the leak per-cmenu is smaller than others we have per-user-command. ####@@@@ DOIT
            if fn:
                if 1: #experiment 060121
                    from utilities.debug import print_compact_traceback
                    try:
                        win = env.mainwindow()
                        assert win.initialised # make sure it's not too early
                        assy = win.assy
                    except:
                        if debug_flags.atom_debug:
                            print_compact_traceback("atom_debug: fyi: normal exception: ")
                        pass # this is normal during init... or at least I thought it would be -- I never actually saw it yet.
                    else:
##                        begin_retval = assy.undo_checkpoint_before_command(fn)
##                        cp_fn = fn, begin_retval #e this should include a retval from that method, but must also always be true
                        if 1: #060127
                            # note, ideally this assy and the one that subscribes to command_segment changes
                            # should be found in the same way (ie that one should sub to this too) -- could this just iterate over
                            # same list and call it differently, with a different flag?? ##e
                            assy.current_command_info(cmdname = fn) #e cmdname might be set more precisely by the slot we're wrapping
                if 0:
                    print " featurename =", fn
                    # This works! prints correct names for toolbuttons and main menu items.
                    # Doesn't work for glpane cmenu items, but I bet it will when we fix them to have proper WhatsThis text.
                    # Hmm, how will we do that? There is presently no formal connection between them and the usual qactions
                    # or toolbuttons or whatsthis features for the main UI for the same method. We might have to detect the
                    # identity of the bound method they call as a slot! Not sure if this is possible. If not, we have to set
                    # command names from inside the methods that implement them (not the end of the world), or grab them from
                    # history text (doable).
            else:
                #060320 debug code; note, this shows signals that might not need undo cp's, but for almost all signals,
                # they might in theory need them in the future for some recipients, so it's not usually safe to exclude them.
                # Instead, someday we'll optimize this more when no changes actually occurred (e.g. detect that above).
                if 0 and env.debug():
                    print "debug: wrappedslot found no featurename, signal = %r, sender = %r" % (self.__signal, sender)
        ## return cp_fn, mc  #060123 revised retval
        return mc