コード例 #1
0
ファイル: special_parents.py プロジェクト: sctincman/bkchem
  def remove_mark( self, mark):
    """mark is either mark instance of type, in case of instance, the instance is removed,
    in case of type a random mark of this type (if present is removed).
    Returns the removed mark or None"""
    if misc.myisstr(mark):
      ms = [m for m in self.marks if m.__class__.__name__ == mark]
      if ms:
        m = ms[0]
      else:
        return None
    elif isinstance( mark, marks.mark):
      if mark in self.marks:
        m = mark
      else:
        raise ValueError("trying to remove a mark that does not belong to this atom")
    else:
      raise TypeError("mark is on unknown type " + str( mark))

    m.delete()
    self.marks.remove( m)
    self._set_mark_helper( m.__class__, sign=-1)
    return m
コード例 #2
0
ファイル: special_parents.py プロジェクト: insilichem/bkchem
    def remove_mark(self, mark):
        """mark is either mark instance of type, in case of instance, the instance is removed,
    in case of type a random mark of this type (if present is removed).
    Returns the removed mark or None"""
        if misc.myisstr(mark):
            ms = [m for m in self.marks if m.__class__.__name__ == mark]
            if ms:
                m = ms[0]
            else:
                return None
        elif isinstance(mark, marks.mark):
            if mark in self.marks:
                m = mark
            else:
                raise ValueError(
                    "trying to remove a mark that does not belong to this atom"
                )
        else:
            raise TypeError("mark is on unknown type " + str(mark))

        m.delete()
        self.marks.remove(m)
        self._set_mark_helper(m.__class__, sign=-1)
        return m
コード例 #3
0
ファイル: context_menu.py プロジェクト: sctincman/bkchem
  def __init__( self, selected, **kw):
    Tkinter.Menu.__init__( self, Store.app, tearoff=0, **kw)
    self.selected = selected
    self.changes_made = 0
    already_there = []
    self.configurable = {} # this is similar to configurable but is prepared on init to take dynamic things into account
    # at first prepare all the items
    items = {}
    for obj_type in configurable.keys():
      if misc.myisstr(obj_type):
        objs = [o for o in self.selected if o.object_type == obj_type]
      else:
        objs = [o for o in self.selected if isinstance( o, obj_type)]

      if not objs:
        continue
      for attr in configurable[ obj_type]:
        if misc.myisstr(attr):
          # attr can be either a string (key of config_values)
          vals = config_values[ attr]
        if isinstance(attr, collections.Callable):
          # or it can be a callable that takes list of objects and returns the desired tuple
          attr, vals = attr( [o for o in self.selected if o.object_type == obj_type])

        if vals and attr not in already_there:
          items[ vals[ I18N_NAME]] = []
          self.configurable[ obj_type] = self.configurable.get( obj_type, []) + [attr]
          for v in vals[ VALUES]:
            if isinstance(v, tuple):
              items[ vals[ I18N_NAME]].append( (v[1], attr, objs, v[0]))
            else:
              items[ vals[ I18N_NAME]].append( (v, attr, objs, v))
          # to know what is already there
          already_there.append( attr)
        elif vals: # attr is already there
          for tup in items[ vals[ I18N_NAME]]:
            tup[2].extend( objs)

    # then sort the items and polulate the menu
    keys = sorted(items.keys())
    for key in keys:
      casc = Tkinter.Menu( self, tearoff=0)
      self.add_cascade( label=key, menu=casc)
      for (v1, attr, objs, v0) in items[ key]:
        casc.add_command( label=v1, command=misc.lazy_apply( self.callback, (attr, objs, v0)))

    # commands
    if already_there and len( [o for o in self.selected if o.object_type != 'mark']):
      # marks do not have entry in properties dialog
      self.add_separator()
    i = False
    i += self.register_command_by_object_type( _("Center bond"), ('bond',), center)
    i += self.register_command_by_class_name( _("Expand group"), ('group',), expand_groups)
    i += self.register_command_by_object_type( _("Set atom number"), ('atom',), set_atom_number)
    i += self.register_command_through_filter( mark_template_atom_filter, objs)
    i += self.register_command_through_filter( mark_template_bond_filter, objs)

    # common commands
    if len( [o for o in self.selected if o.object_type != 'mark']):
      # marks do not have entry in properties dialog
      if i:
        self.add_separator()
      self.add_command( label=_("Properties"), command=Store.app.paper.config_selected)
コード例 #4
0
ファイル: PmwBlt.py プロジェクト: insilichem/bkchem
 def tab_configure(self, tabIndexes, option=None, **kw):
     # <tabIndexes> may be a list of tabs.
     if isinstance(tabIndexes, int) or misc.myisstr(tabIndexes):
         tabIndexes = [tabIndexes]
     subcommand = (self._w, 'tab', 'configure') + tuple(tabIndexes)
     return _doConfigure(self, subcommand, option, kw)
コード例 #5
0
ファイル: PmwBlt.py プロジェクト: insilichem/bkchem
 def marker_configure(self, names, option=None, **kw):
     # <names> may be a list of markerIds.
     if misc.myisstr(names):
         names = [names]
     subcommand = (self._w, 'marker', 'configure') + tuple(names)
     return _doConfigure(self, subcommand, option, kw)
コード例 #6
0
ファイル: PmwBlt.py プロジェクト: insilichem/bkchem
 def element_configure(self, names, option=None, **kw):
     # <names> may be a list of elemNames.
     if misc.myisstr(names):
         names = [names]
     subcommand = (self._w, 'element', 'configure') + tuple(names)
     return _doConfigure(self, subcommand, option, kw)
コード例 #7
0
ファイル: PmwBlt.py プロジェクト: insilichem/bkchem
 def axis_configure(self, axes, option=None, **kw):
     # <axes> may be a list of axisNames.
     if misc.myisstr(axes):
         axes = [axes]
     subcommand = (self._w, 'axis', 'configure') + tuple(axes)
     return _doConfigure(self, subcommand, option, kw)
コード例 #8
0
ファイル: PmwBlt.py プロジェクト: sctincman/bkchem
 def tab_configure(self, tabIndexes, option=None, **kw):
     # <tabIndexes> may be a list of tabs.
     if isinstance(tabIndexes, int) or misc.myisstr(tabIndexes):
         tabIndexes = [tabIndexes]
     subcommand = (self._w, 'tab', 'configure') + tuple(tabIndexes)
     return _doConfigure(self, subcommand, option, kw)
コード例 #9
0
ファイル: PmwBlt.py プロジェクト: sctincman/bkchem
 def marker_configure(self, names, option=None, **kw):
     # <names> may be a list of markerIds.
     if misc.myisstr(names):
         names = [names]
     subcommand = (self._w, 'marker', 'configure') + tuple(names)
     return _doConfigure(self, subcommand, option, kw)
コード例 #10
0
ファイル: PmwBlt.py プロジェクト: sctincman/bkchem
 def element_configure(self, names, option=None, **kw):
     # <names> may be a list of elemNames.
     if misc.myisstr(names):
         names = [names]
     subcommand = (self._w, 'element', 'configure') + tuple(names)
     return _doConfigure(self, subcommand, option, kw)
コード例 #11
0
ファイル: PmwBlt.py プロジェクト: sctincman/bkchem
 def axis_configure(self, axes, option=None, **kw):
     # <axes> may be a list of axisNames.
     if misc.myisstr(axes):
         axes = [axes]
     subcommand = (self._w, 'axis', 'configure') + tuple(axes)
     return _doConfigure(self, subcommand, option, kw)
コード例 #12
0
    def __init__(self, selected, **kw):
        Tkinter.Menu.__init__(self, Store.app, tearoff=0, **kw)
        self.selected = selected
        self.changes_made = 0
        already_there = []
        self.configurable = {
        }  # this is similar to configurable but is prepared on init to take dynamic things into account
        # at first prepare all the items
        items = {}
        for obj_type in configurable.keys():
            if misc.myisstr(obj_type):
                objs = [o for o in self.selected if o.object_type == obj_type]
            else:
                objs = [o for o in self.selected if isinstance(o, obj_type)]

            if not objs:
                continue
            for attr in configurable[obj_type]:
                if misc.myisstr(attr):
                    # attr can be either a string (key of config_values)
                    vals = config_values[attr]
                if isinstance(attr, collections.Callable):
                    # or it can be a callable that takes list of objects and returns the desired tuple
                    attr, vals = attr([
                        o for o in self.selected if o.object_type == obj_type
                    ])

                if vals and attr not in already_there:
                    items[vals[I18N_NAME]] = []
                    self.configurable[obj_type] = self.configurable.get(
                        obj_type, []) + [attr]
                    for v in vals[VALUES]:
                        if isinstance(v, tuple):
                            items[vals[I18N_NAME]].append(
                                (v[1], attr, objs, v[0]))
                        else:
                            items[vals[I18N_NAME]].append((v, attr, objs, v))
                    # to know what is already there
                    already_there.append(attr)
                elif vals:  # attr is already there
                    for tup in items[vals[I18N_NAME]]:
                        tup[2].extend(objs)

        # then sort the items and polulate the menu
        keys = sorted(items.keys())
        for key in keys:
            casc = Tkinter.Menu(self, tearoff=0)
            self.add_cascade(label=key, menu=casc)
            for (v1, attr, objs, v0) in items[key]:
                casc.add_command(label=v1,
                                 command=misc.lazy_apply(
                                     self.callback, (attr, objs, v0)))

        # commands
        if already_there and len(
            [o for o in self.selected if o.object_type != 'mark']):
            # marks do not have entry in properties dialog
            self.add_separator()
        i = False
        i += self.register_command_by_object_type(_("Center bond"), ('bond', ),
                                                  center)
        i += self.register_command_by_class_name(_("Expand group"),
                                                 ('group', ), expand_groups)
        i += self.register_command_by_object_type(_("Set atom number"),
                                                  ('atom', ), set_atom_number)
        i += self.register_command_through_filter(mark_template_atom_filter,
                                                  objs)
        i += self.register_command_through_filter(mark_template_bond_filter,
                                                  objs)

        # common commands
        if len([o for o in self.selected if o.object_type != 'mark']):
            # marks do not have entry in properties dialog
            if i:
                self.add_separator()
            self.add_command(label=_("Properties"),
                             command=Store.app.paper.config_selected)