コード例 #1
0
  def read_package( self, package, atom):
    typ = package.getAttribute( 'type')
    cls = globals().get( typ, None)
    if cls:
      auto = 0 #package.getAttribute( 'auto') != None and package.getAttribute( 'auto')) or 0
      x, y, z = Screen.read_xml_point( package)
      size = package.getAttribute( 'size') and float( package.getAttribute( 'size')) or None
      if size:
        m = cls( atom, x, y, size=size, auto=int(auto))
      else:
        m = cls( atom, x, y, auto=int(auto))

      # class specific attributes
      for (attr, typ) in m.meta__save_attrs.items():
        val = package.getAttribute( attr)
        if val != '':
          if typ == bool:
            value = bool( data.booleans.index( val))
          elif typ == int:
            value = int( val)
          else:
            value = val
          setattr( m, attr, value)

      if hasattr( m, "_after_read_package"):
        m._after_read_package()
      return m
    else:
      raise ValueError("no such mark type %s" % typ)
コード例 #2
0
ファイル: classes.py プロジェクト: yassineMrabet/bkchem
    def read_package(self, package):
        """reads the dom element package and sets internal state according to it"""
        if package.getAttribute('id'):
            self.id = package.getAttribute('id')
        pos = package.getElementsByTagName('point')[0]
        x, y, z = Screen.read_xml_point(pos)
        self.set_xy(x, y)
        ft = package.getElementsByTagName('ftext')
        try:
            self.xml_ftext = reduce(operator.add, [
                e.nodeValue
                for e in ft[0].childNodes if isinstance(e, dom.Text)
            ], '')
        except IndexError:
            self.xml_ftext = "?"

        fnt = package.getElementsByTagName('font')
        if fnt:
            fnt = fnt[0]
            self.font_size = int(fnt.getAttribute('size'))
            self.font_family = fnt.getAttribute('family')
            if fnt.getAttribute('color'):
                self.line_color = fnt.getAttribute('color')
        if package.getAttribute('background-color'):
            self.area_color = package.getAttribute('background-color')
コード例 #3
0
ファイル: classes.py プロジェクト: yassineMrabet/bkchem
 def read_package(self, package):
     """reads the dom element package and sets internal state according to it"""
     if package.getAttribute('id'):
         self.id = package.getAttribute('id')
     pnt = package.getElementsByTagName('point')[0]
     self.x, self.y, z = Screen.read_xml_point(pnt)
     if package.getAttribute('font_size'):
         self.font_size = int(package.getAttribute('font_size'))
     if package.getAttribute('color'):
         self.line_color = package.getAttribute('color')
     if package.getAttribute('background-color'):
         self.area_color = package.getAttribute('background-color')
コード例 #4
0
ファイル: classes.py プロジェクト: sctincman/bkchem
 def read_package( self, package):
   """reads the dom element package and sets internal state according to it"""
   if package.getAttribute( 'id'):
     self.id = package.getAttribute( 'id')
   pnt = package.getElementsByTagName( 'point')[0]
   self.x, self.y, z = Screen.read_xml_point( pnt)
   if package.getAttribute( 'font_size'):
     self.font_size = int( package.getAttribute( 'font_size'))
   if package.getAttribute( 'color'):
     self.line_color = package.getAttribute( 'color')
   if package.getAttribute( 'background-color'):
     self.area_color = package.getAttribute( 'background-color')
コード例 #5
0
ファイル: textatom.py プロジェクト: yassineMrabet/bkchem
    def read_package(self, package):
        """reads the dom element package and sets internal state according to it"""
        a = ['no', 'yes']
        on_off = ['off', 'on']
        self.id = package.getAttribute('id')
        # marks
        for m in package.getElementsByTagName('mark'):
            mrk = marks.mark.read_package(m, self)
            self.marks.add(mrk)

        # position
        self.pos = package.getAttribute('pos')
        position = package.getElementsByTagName('point')[0]
        # reading of coords regardless of their unit
        x, y, z = Screen.read_xml_point(position)
        if z != None:
            self.z = z * self.paper.real_to_screen_ratio()
        # needed to support transparent handling of molecular size
        x, y = self.paper.real_to_screen_coords((x, y))
        self.x = x
        self.y = y
        ft = package.getElementsByTagName('ftext')
        if ft:
            self.set_name(
                reduce(operator.add, [
                    e.nodeValue
                    for e in ft[0].childNodes if isinstance(e, dom.Text)
                ], '').encode('utf-8'))
        else:
            raise TypeError, "not text atom"
        # font and fill color
        fnt = package.getElementsByTagName('font')
        if fnt:
            fnt = fnt[0]
            self.font_size = int(fnt.getAttribute('size'))
            self.font_family = fnt.getAttribute('family')
            if fnt.getAttribute('color'):
                self.line_color = fnt.getAttribute('color')
        # background color
        if package.getAttributeNode('background-color'):
            self.area_color = package.getAttribute('background-color')
        # number
        if package.getAttribute('show_number'):
            self.show_number = bool(
                data.booleans.index(package.getAttribute('show_number')))
        if package.getAttribute('number'):
            self.number = package.getAttribute('number')
コード例 #6
0
    def read_package(self, package):
        """reads the dom element package and sets internal state according to it"""
        a = ['no', 'yes']
        on_off = ['off', 'on']
        self.id = package.getAttribute('id')
        self.pos = package.getAttribute('pos')
        position = package.getElementsByTagName('point')[0]
        # reading of coords regardless of their unit
        x, y, z = Screen.read_xml_point(position)
        if z is not None:
            self.z = z * self.paper.real_to_screen_ratio()
        # needed to support transparent handling of molecular size
        x, y = self.paper.real_to_screen_coords((x, y))
        self.x = x
        self.y = y

        self.symbol = package.getAttribute("name")

        # font and fill color
        fnt = package.getElementsByTagName('font')
        if fnt:
            fnt = fnt[0]
            self.font_size = int(fnt.getAttribute('size'))
            self.font_family = fnt.getAttribute('family')
            if fnt.getAttribute('color'):
                self.line_color = fnt.getAttribute('color')
        # background color
        if package.getAttributeNode('background-color'):
            self.area_color = package.getAttribute('background-color')

        # marks
        for m in package.getElementsByTagName('mark'):
            mrk = marks.mark.read_package(m, self)
            self.marks.add(mrk)
        # number
        if package.getAttribute('show_number'):
            self.show_number = bool(
                data.booleans.index(package.getAttribute('show_number')))
        if package.getAttribute('number'):
            self.number = package.getAttribute('number')
        # free_sites
        if package.getAttribute('free_sites'):
            self.free_sites = int(package.getAttribute('free_sites'))
コード例 #7
0
ファイル: textatom.py プロジェクト: sctincman/bkchem
  def read_package( self, package):
    """reads the dom element package and sets internal state according to it"""
    a = ['no','yes']
    on_off = ['off','on']
    self.id = package.getAttribute( 'id')
    # marks
    for m in package.getElementsByTagName( 'mark'):
      mrk = marks.mark.read_package( m, self)
      self.marks.add( mrk)

    # position
    self.pos = package.getAttribute( 'pos')
    position = package.getElementsByTagName( 'point')[0]
    # reading of coords regardless of their unit
    x, y, z = Screen.read_xml_point( position)
    if z != None:
      self.z = z* self.paper.real_to_screen_ratio()
    # needed to support transparent handling of molecular size
    x, y = self.paper.real_to_screen_coords( (x, y))
    self.x = x
    self.y = y
    ft = package.getElementsByTagName('ftext')
    if ft:
      self.set_name(''.join(e.nodeValue for e in ft[0].childNodes
                                          if isinstance(e, dom.Text)))
    else:
      raise TypeError("Not text atom.")
    # font and fill color
    fnt = package.getElementsByTagName('font')
    if fnt:
      fnt = fnt[0]
      self.font_size = int( fnt.getAttribute( 'size'))
      self.font_family = fnt.getAttribute( 'family')
      if fnt.getAttribute( 'color'):
        self.line_color = fnt.getAttribute( 'color')
    # background color
    if package.getAttributeNode( 'background-color'):
      self.area_color = package.getAttribute( 'background-color')
    # number
    if package.getAttribute( 'show_number'):
      self.show_number = bool( data.booleans.index( package.getAttribute( 'show_number')))
    if package.getAttribute( 'number'):
      self.number = package.getAttribute( 'number')
コード例 #8
0
ファイル: group.py プロジェクト: bartlebee/bkchem
  def read_package( self, package):
    """reads the dom element package and sets internal state according to it"""
    a = ['no','yes']
    on_off = ['off','on']
    self.id = package.getAttribute( 'id')
    self.pos = package.getAttribute( 'pos')
    position = package.getElementsByTagName( 'point')[0]
    # reading of coords regardless of their unit
    x, y, z = Screen.read_xml_point( position)
    if z != None:
      self.z = z* self.paper.real_to_screen_ratio()
    # needed to support transparent handling of molecular size
    x, y = self.paper.real_to_screen_coords( (x, y))
    self.x = x
    self.y = y
    self.group_type = package.getAttribute( "group-type")
    if self.group_type in ("implicit","explicit"):
      #read the graph once
      pass
    self.symbol = package.getAttribute( "name")

    # font and fill color
    fnt = package.getElementsByTagName('font')
    if fnt:
      fnt = fnt[0]
      self.font_size = int( fnt.getAttribute( 'size'))
      self.font_family = fnt.getAttribute( 'family')
      if fnt.getAttribute( 'color'):
        self.line_color = fnt.getAttribute( 'color')
    # background color
    if package.getAttributeNode( 'background-color'):
      self.area_color = package.getAttribute( 'background-color')

    # marks
    for m in package.getElementsByTagName( 'mark'):
      mrk = marks.mark.read_package( m, self)
      self.marks.add( mrk)
    # number
    if package.getAttribute( 'show_number'):
      self.show_number = bool( data.booleans.index( package.getAttribute( 'show_number')))
    if package.getAttribute( 'number'):
      self.number = package.getAttribute( 'number')
コード例 #9
0
ファイル: classes.py プロジェクト: bartlebee/bkchem
  def read_package( self, package):
    """reads the dom element package and sets internal state according to it"""
    if package.getAttribute( 'id'):
      self.id = package.getAttribute( 'id')
    pos = package.getElementsByTagName( 'point')[0]
    x, y, z = Screen.read_xml_point( pos)
    self.set_xy( x, y)
    ft = package.getElementsByTagName('ftext')
    try:
      self.xml_ftext = reduce( operator.add, [e.nodeValue for e in ft[0].childNodes if isinstance( e, dom.Text)], '')
    except IndexError:
      self.xml_ftext = "?"

    fnt = package.getElementsByTagName('font')
    if fnt:
      fnt = fnt[0]
      self.font_size = int( fnt.getAttribute( 'size'))
      self.font_family = fnt.getAttribute( 'family')
      if fnt.getAttribute( 'color'):
        self.line_color = fnt.getAttribute( 'color')
    if package.getAttribute( 'background-color'):
      self.area_color = package.getAttribute( 'background-color')
コード例 #10
0
ファイル: classes.py プロジェクト: yassineMrabet/bkchem
 def read_package(self, package):
     """reads the dom element package and sets internal state according to it"""
     x, y, z = Screen.read_xml_point(package)
     self.x, self.y = self.paper.real_to_screen_coords((x, y))
コード例 #11
0
ファイル: classes.py プロジェクト: sctincman/bkchem
 def read_package( self, package):
   """reads the dom element package and sets internal state according to it"""
   x, y, z = Screen.read_xml_point( package)
   self.x, self.y = self.paper.real_to_screen_coords( (x,y))
コード例 #12
0
ファイル: atom.py プロジェクト: caiyingchun/bkchem
 def read_package( self, package):
   """reads the dom element package and sets internal state according to it"""
   a = ['no','yes']
   on_off = ['off','on']
   self.id = package.getAttribute( 'id')
   # marks (we read them here because they influence the charge)
   for m in package.getElementsByTagName( 'mark'):
     mrk = marks.mark.read_package( m, self)
     self.marks.add( mrk)
   self.pos = package.getAttribute( 'pos')
   position = package.getElementsByTagName( 'point')[0]
   # reading of coords regardless of their unit
   x, y, z = Screen.read_xml_point( position)
   if z is not None:
     self.z = z* self.paper.real_to_screen_ratio()
   # needed to support transparent handling of molecular size
   x, y = self.paper.real_to_screen_coords( (x, y))
   self.x = x
   self.y = y
   ft = package.getElementsByTagName('ftext')
   if ft:
     self.set_name(''.join([e.toxml('utf-8') for e in ft[0].childNodes]),
                   check_valency=0,
                   interpret=0)
   else:
     self.set_name( package.getAttribute( 'name'), check_valency=0)
   # charge
   self.charge = package.getAttribute('charge') and int( package.getAttribute('charge')) or 0
   # hydrogens
   if package.getAttribute( 'hydrogens'):
     self.show_hydrogens = package.getAttribute('hydrogens')
   else:
     self.show_hydrogens = 0
   # font and fill color
   fnt = package.getElementsByTagName('font')
   if fnt:
     fnt = fnt[0]
     self.font_size = int( fnt.getAttribute( 'size'))
     self.font_family = fnt.getAttribute( 'family')
     if fnt.getAttribute( 'color'):
       self.line_color = fnt.getAttribute( 'color')
   # show
   if package.getAttribute( 'show'):
     self.show = package.getAttribute( 'show')
   else:
     self.show = (self.symbol!='C')
   # background color
   if package.getAttributeNode( 'background-color'):
     self.area_color = package.getAttribute( 'background-color')
   # multiplicity
   if package.getAttribute( 'multiplicity'):
     self.multiplicity = int( package.getAttribute( 'multiplicity'))
   # valency
   if package.getAttribute( 'valency'):
     self.valency = int( package.getAttribute( 'valency'))
   # number
   if package.getAttribute( 'show_number'):
     self.show_number = bool( data.booleans.index( package.getAttribute( 'show_number')))
   if package.getAttribute( 'number'):
     self.number = package.getAttribute( 'number')
   # free_sites
   if package.getAttribute( 'free_sites'):
     self.free_sites = int( package.getAttribute( 'free_sites'))