Пример #1
0
 def updateMessage(self, msg = ""):
     """
     Updates the message box with an informative message based on the 
     current page and current selected atom type.
     
     @param msg: The message to display in the Property Manager message
                 box. If called with an empty string (the default), a
                 strandard message is displayed.
     @type  msg: str
     """
     if msg:
         self.MessageGroupBox.insertHtmlMessage(msg)
         return
     
     if not self.elementChooser:
         return
     
     element = self.elementChooser.element
     if element.symbol in ALL_PAM_ATOMS:
         atom_or_PAM_atom_string = ' pseudoatom'
     else:
         atom_or_PAM_atom_string = ' atom'
            
     if self.elementChooser.isVisible():
         msg = "Double click in empty space to insert a single " \
             + element.name + atom_or_PAM_atom_string + "."
         if not element.symbol in NOBLEGASES: 
             msg += "Click on an atom's <i>red bondpoint</i> to attach a " \
                + element.name + atom_or_PAM_atom_string +" to it." 
             if element.symbol in PAMATOMS:
                 msg ="Note: this pseudoatom can only be deposited onto a strand sugar"\
                     " and will disappear if deposited in free space"
     else: # Bonds Tool is selected
         if self.parentMode.cutBondsAction.isChecked():
             msg = "<b> Cut Bonds </b> tool is active. \
             Click on bonds in order to delete them."
             self.MessageGroupBox.insertHtmlMessage(msg)
             return          
         if not hasattr(self.parentMode, 'bondclick_v6'): 
             return
         if self.parentMode.bondclick_v6:
             name = btype_from_v6(self.parentMode.bondclick_v6)
             msg = "Click bonds or bondpoints to make them %s bonds." % name 
         
     # Post message.
     self.MessageGroupBox.insertHtmlMessage(msg)    
Пример #2
0
    def updateBuildAtomsMessage(self):
        """Updates the message box with an informative message based on the current page
        and current selected atom type.
        """
        msg = ""

        if self.MMKit_groupBox.isVisible():
            pageIndex = self.mmkit_tab.currentIndex()
            page = None

            if pageIndex is 0: # atomsPage
                msg = "Double click in empty space to insert a single " + self.elm.name + " atom. "
                if not self.elm.symbol in noblegases:
                    msg += "Click on an atom's <i>red bondpoint</i> to attach a " + self.elm.name + " atom to it."

            elif pageIndex is 1: # clipboardPage
                pastableItems = self.w.assy.shelf.get_pastable_chunks()
                if pastableItems:
                    msg = "Double click in empty space to insert a copy of the selected clipboard item. \
                    Click on a <i>red bondpoint</i> to attach a copy of the selected clipboard item."
                else:
                    msg = "There are no items on the clipboard."

            elif pageIndex is 2: # libraryPage
                msg = "Double click in empty space to insert a copy of the selected part in the library."

        else: # Bonds Tool is selected (MMKit groupbox is hidden).
            if self.parentMode.cutBondsAction.isChecked():
                msg = "<b> Cut Bonds </b> tool is active. \
                Click on bonds in order to delete them."
                self.MessageGroupBox.insertHtmlMessage(msg)
                return

            if not hasattr(self, 'bondclick_v6'): # Mark 2007-06-01
                return
            if self.bondclick_v6:
                name = btype_from_v6(self.bondclick_v6)
                msg = "Click bonds or bondpoints to make them %s bonds." % name # name is 'single' etc

        # Post message.
        self.MessageGroupBox.insertHtmlMessage(msg)
Пример #3
0
def _bond_type_menu_section(bond): #bruce 050716; replaces bond_type_submenu_spec for Alpha6
    """
    Return a menu_spec for changing the bond_type of this bond
    (as one or more checkmark items, one per permitted bond-type given the atomtypes),
    or if the bond-type is unchangeable, a disabled menu item for displaying the type
    (which looks the same as when the bond type is changeable, except for being disabled).
    (If the current bond type is not permitted, it's still present and checked, but disabled,
     and it might have a warning saying it's illegal.)
    """
    # this assert is true, but it would cause an import loop:
    ## assert isinstance(bond, Bond)
    btype_now = btype_from_v6(bond.v6)
    poss1 = possible_bond_types(bond) # a list of strings which are bond-type names, in order of increasing bond order
    poss, permitted1, permitted2 = possible_bond_types_for_elements(bond) # new feature 060703
    ##e could put weird ones (graphitic, carbomeric) last and/or in parens, in subtext below
    types = list(poss)
    for btype in poss1:
        if btype not in types:
            print "should never happen: %r not in %r" % (btype, poss) # intentional: "not in types" above, "not in poss" here
            types.append(btype)
    if btype_now not in types:
        types.append(btype_now) # put this one last, since it's illegal; warning for it is computed later
    assert len(types) > 0
    # types is the list of bond types for which to make menu items, in order;
    # now make them, and figure out which ones are checked and/or disabled;
    # we disable even legal ones iff there is only one bond type in types
    # (which means, if current type is illegal, it is disabled and the sole legal type is enabled).
    disable_legal_types = (len(types) == 1)
    res = []
    for btype in types: # include current value even if it's illegal
        subtext = "%s bond" % btype # this string might be extended below
        checked = (btype == btype_now)
        command = ( lambda arg1=None, arg2=None, btype=btype, bond=bond: apply_btype_to_bond(btype, bond) )
        warning = warning2 = ""
        if btype not in poss:
            # illegal btype (note: it will be the current one, and thus be the only checked one)
            warning = "illegal"
            disabled = True
        else:
            # legal btype
            warning = bond_type_warning(bond, btype) # might be "" (or None??) for no warning
            if btype not in poss1:
                # new feature 060703
                # try1: too long and boring (when in most menu entries):
                ## warning2 = "would change atomtypes"
                # try2: say which atomtypes we'd change to, in same order of atoms as the bond name
                v6 = v6_from_btype(btype)
                atype1 = best_atype(bond.atom1, permitted1[v6])
                atype2 = best_atype(bond.atom2, permitted2[v6])
                in_order = [atype1, atype2] ##e stub; see code in Bond.__str__
                warning2 = "%s<->%s" % tuple([atype.name for atype in in_order])
            disabled = disable_legal_types
                # might change this if some neighbor bonds are locked (nim), or if we want to show non-possible choices
        if warning2:
            subtext += " (%s)" % warning2
        if warning:
            subtext += " (%s)" % warning
        res.append(( subtext, command,
                         disabled and 'disabled' or None,
                         checked and 'checked' or None ))
    ##e if >1 legal value, maybe we should add a toggleable checkmark item to permit "locking" the bond to its current bond type;
    # this won't be needed until we have better bond inference (except maybe for bondpoints),
    # since right now [still true 060703] we never alter real bond types except when the user does an action on that specific bond.
    if not bond.is_open_bond():
        ## command = ( lambda arg1 = None, arg2 = None, bond = bond: bond.bust() )
        command = ( lambda bond = bond: delete_bond(bond) )
        res.append(None) # separator
        res.append(("Delete Bond", command))
    return res
Пример #4
0
def _bond_type_menu_section(
        bond):  #bruce 050716; replaces bond_type_submenu_spec for Alpha6
    """
    Return a menu_spec for changing the bond_type of this bond
    (as one or more checkmark items, one per permitted bond-type given the atomtypes),
    or if the bond-type is unchangeable, a disabled menu item for displaying the type
    (which looks the same as when the bond type is changeable, except for being disabled).
    (If the current bond type is not permitted, it's still present and checked, but disabled,
     and it might have a warning saying it's illegal.)
    """
    # this assert is true, but it would cause an import loop:
    ## assert isinstance(bond, Bond)
    btype_now = btype_from_v6(bond.v6)
    poss1 = possible_bond_types(
        bond
    )  # a list of strings which are bond-type names, in order of increasing bond order
    poss, permitted1, permitted2 = possible_bond_types_for_elements(
        bond)  # new feature 060703
    ##e could put weird ones (graphitic, carbomeric) last and/or in parens, in subtext below
    types = list(poss)
    for btype in poss1:
        if btype not in types:
            print "should never happen: %r not in %r" % (
                btype, poss
            )  # intentional: "not in types" above, "not in poss" here
            types.append(btype)
    if btype_now not in types:
        types.append(
            btype_now
        )  # put this one last, since it's illegal; warning for it is computed later
    assert len(types) > 0
    # types is the list of bond types for which to make menu items, in order;
    # now make them, and figure out which ones are checked and/or disabled;
    # we disable even legal ones iff there is only one bond type in types
    # (which means, if current type is illegal, it is disabled and the sole legal type is enabled).
    disable_legal_types = (len(types) == 1)
    res = []
    for btype in types:  # include current value even if it's illegal
        subtext = "%s bond" % btype  # this string might be extended below
        checked = (btype == btype_now)
        command = (lambda arg1=None, arg2=None, btype=btype, bond=bond:
                   apply_btype_to_bond(btype, bond))
        warning = warning2 = ""
        if btype not in poss:
            # illegal btype (note: it will be the current one, and thus be the only checked one)
            warning = "illegal"
            disabled = True
        else:
            # legal btype
            warning = bond_type_warning(
                bond, btype)  # might be "" (or None??) for no warning
            if btype not in poss1:
                # new feature 060703
                # try1: too long and boring (when in most menu entries):
                ## warning2 = "would change atomtypes"
                # try2: say which atomtypes we'd change to, in same order of atoms as the bond name
                v6 = v6_from_btype(btype)
                atype1 = best_atype(bond.atom1, permitted1[v6])
                atype2 = best_atype(bond.atom2, permitted2[v6])
                in_order = [atype1, atype2]  ##e stub; see code in Bond.__str__
                warning2 = "%s<->%s" % tuple(
                    [atype.name for atype in in_order])
            disabled = disable_legal_types
            # might change this if some neighbor bonds are locked (nim), or if we want to show non-possible choices
        if warning2:
            subtext += " (%s)" % warning2
        if warning:
            subtext += " (%s)" % warning
        res.append((subtext, command, disabled and 'disabled'
                    or None, checked and 'checked' or None))
    ##e if >1 legal value, maybe we should add a toggleable checkmark item to permit "locking" the bond to its current bond type;
    # this won't be needed until we have better bond inference (except maybe for bondpoints),
    # since right now [still true 060703] we never alter real bond types except when the user does an action on that specific bond.
    if not bond.is_open_bond():
        ## command = ( lambda arg1 = None, arg2 = None, bond = bond: bond.bust() )
        command = (lambda bond=bond: delete_bond(bond))
        res.append(None)  # separator
        res.append(("Delete Bond", command))
    return res