Beispiel #1
0
  def __contains__( self, item):
    # try if we need to recode the name
    if item in name_recode_map:
      item = name_recode_map[item]

    if dict.__contains__(self, item):
      return 1
    else:
      try:
        self.__setitem__(item, Tkinter.PhotoImage(file=os_support.get_path(item + '.gif', 'pixmap')))
        return 1
      except:
        return 0
Beispiel #2
0
 def __getitem__(self, item):
   # try if we need to recode the name
   if item in name_recode_map:
     item = name_recode_map[item]
   try:
     return dict.__getitem__(self, item)
   except:
     try:
       i = Tkinter.PhotoImage(file=os_support.get_path(item + '.gif', 'pixmap'))
       self.__setitem__(item, i)
       return i
     except ValueError:
       raise KeyError
Beispiel #3
0
  def __contains__( self, item):
    # try if we need to recode the name
    try:
      item = name_recode_map[ item]
    except KeyError:
      pass

    if dict.__contains__( self, item):
      return 1
    else:
      try:
        self.__setitem__( item, Tkinter.PhotoImage( file = os_support.get_path( item+'.gif', 'pixmap')))
        return 1
      except:
        #print "pixmap not found: " + item
        return 0
Beispiel #4
0
    def __contains__(self, item):
        # try if we need to recode the name
        try:
            item = name_recode_map[item]
        except KeyError:
            pass

        if dict.__contains__(self, item):
            return 1
        else:
            try:
                self.__setitem__(
                    item,
                    Tkinter.PhotoImage(
                        file=os_support.get_path(item + '.gif', 'pixmap')))
                return 1
            except:
                #print "pixmap not found: " + item
                return 0
Beispiel #5
0
  def __init__( self):
    Tkinter.Toplevel.__init__( self)

    self.title(_('BKChem is starting...'))

    # splash image
    splash_image_path = 'logo.ppm'
    try:
      self.splash_image = Tkinter.PhotoImage( file = os_support.get_path( splash_image_path, 'image'))
    except:
      self.splash_image = None

    text = Tkinter.Label( self,
                          font=('Helvetica', 12, 'normal'),
                          relief = 'raised',
                          borderwidth = 2,
                          padx=50, pady=50,
                          image = self.splash_image,
                          text = messages.splash_text
                          )
    text.pack(fill = 'both', expand = 1)
Beispiel #6
0
  def __init__( self):
    Tkinter.Toplevel.__init__( self)

    self.title(_('BKChem is starting...'))

    # splash image
    splash_image_path = 'logo.ppm'
    try:
      self.splash_image = Tkinter.PhotoImage( file = os_support.get_path( splash_image_path, 'image'))
    except:
      self.splash_image = None

    text = Tkinter.Label( self,
                          font=('Helvetica', 12, 'normal'),
                          relief = 'raised',
                          borderwidth = 2,
                          padx=50, pady=50,
                          image = self.splash_image,
                          text = messages.splash_text
                          )
    text.pack(fill = 'both', expand = 1)
Beispiel #7
0
 def add_template_from_CDML( self, file):
   if not os.path.isfile( file):
     file = os_support.get_path( file, "template")
     if not file:
       warn( "template file %s does not exist - ignoring" % file)
       return
   try:
     doc = dom.parse( file).getElementsByTagName( 'cdml')[0]
   except xml.sax.SAXException:
     warn( "template file %s cannot be parsed - ignoring" % file)
     return
   # when loading old versions of CDML try to convert them, but do nothing when they cannot be converted
   import CDML_versions
   CDML_versions.transform_dom_to_version( doc, config.current_CDML_version)
   Store.app.paper.onread_id_sandbox_activate()
   added = []
   for tmp in doc.getElementsByTagName('molecule'):
     self.templates.append( tmp)
     m = molecule( Store.app.paper, package=tmp)
     self._prepared_templates.append( m)
     added.append( m)
   Store.app.paper.onread_id_sandbox_finish( apply_to=[]) # just switch the id_managers, no id mangling
Beispiel #8
0
 def add_template_from_CDML(self, file):
     if not os.path.isfile(file):
         file = os_support.get_path(file, "template")
         if not file:
             warn("template file %s does not exist - ignoring" % file)
             return
     try:
         doc = dom.parse(file).getElementsByTagName('cdml')[0]
     except xml.sax.SAXException:
         warn("template file %s cannot be parsed - ignoring" % file)
         return
     # when loading old versions of CDML try to convert them, but do nothing when they cannot be converted
     import CDML_versions
     CDML_versions.transform_dom_to_version(doc,
                                            config.current_CDML_version)
     Store.app.paper.onread_id_sandbox_activate()
     added = []
     for tmp in doc.getElementsByTagName('molecule'):
         self.templates.append(tmp)
         m = molecule(Store.app.paper, package=tmp)
         self._prepared_templates.append(m)
         added.append(m)
     Store.app.paper.onread_id_sandbox_finish(
         apply_to=[])  # just switch the id_managers, no id mangling
Beispiel #9
0
    def write_to_file(self, name):
        self.doc = dom.Document()
        out = self.doc
        root = dom_ext.elementUnder(
            out, 'office:document-content',
            (('office:class', 'drawing'), ('office:version', '1.0'),
             ('xmlns:draw', 'http://openoffice.org/2000/drawing'),
             ('xmlns:form', "http://openoffice.org/2000/form"),
             ('xmlns:office', "http://openoffice.org/2000/office"),
             ('xmlns:style', "http://openoffice.org/2000/style"),
             ('xmlns:svg', "http://www.w3.org/2000/svg"),
             ('xmlns:text', "http://openoffice.org/2000/text"),
             ('xmlns:fo', "http://www.w3.org/1999/XSL/Format")))

        self.styles_element = dom_ext.elementUnder(root,
                                                   'office:automatic-styles')
        # drawing page
        body = dom_ext.elementUnder(root, 'office:body')
        page = dom_ext.elementUnder(body, 'draw:page',
                                    (('draw:master-page-name', 'vychozi'),
                                     ('draw:name', 'page1')))
        for o in self.paper.stack:
            if o.object_type == 'molecule':
                group = dom_ext.elementUnder(page, 'draw:g')
                for b in o.bonds:
                    self.add_bond(b, group)
                for b in o.atoms:
                    self.add_atom(b, group)
            elif o.object_type == 'arrow':
                self.add_arrow(o, page)
            elif o.object_type == 'text':
                self.add_text(o, page)
            elif o.object_type == 'plus':
                self.add_plus(o, page)
            elif o.object_type == 'rect':
                self.add_rect(o, page)
            elif o.object_type == 'oval':
                self.add_oval(o, page)
            elif o.object_type == 'polygon':
                self.add_polygon(o, page)

#    dom_ext.safe_indent( root)

        import tempfile
        # content file
        cfname = tempfile.mktemp()
        with open(cfname, 'wb') as f:
            f.write(out.toxml('utf-8'))
        # styles file
        sfname = tempfile.mktemp()
        with open(sfname, 'wb') as f:
            f.write(self.create_styles_document().toxml('utf-8'))
        import zipfile
        zip = zipfile.ZipFile(name, 'w', zipfile.ZIP_DEFLATED)
        manifest = os_support.get_path('oo_manifest.xml', 'template')
        if manifest:
            zip.write(os_support.get_path('oo_manifest.xml', 'template'),
                      'META-INF/manifest.xml')
            zip.write(cfname, 'content.xml')
            zip.write(sfname, 'styles.xml')
            zip.close()
        else:
            zip.close()
            raise plugin.export_exception(
                _("The manifest file not found in the plugin directory"))
Beispiel #10
0
  def write_to_file( self, name):
    self.doc = dom.Document()
    out = self.doc
    root = dom_ext.elementUnder( out, 'office:document-content',
                                 (('office:class', 'drawing'),
                                  ('office:version', '1.0'),
                                  ('xmlns:draw', 'http://openoffice.org/2000/drawing'),
                                  ('xmlns:form', "http://openoffice.org/2000/form"),
                                  ('xmlns:office',"http://openoffice.org/2000/office"),
                                  ('xmlns:style',"http://openoffice.org/2000/style"),
                                  ('xmlns:svg',"http://www.w3.org/2000/svg"),
                                  ('xmlns:text',"http://openoffice.org/2000/text"),
                                  ('xmlns:fo',"http://www.w3.org/1999/XSL/Format")))

    self.styles_element = dom_ext.elementUnder( root, 'office:automatic-styles')
    # drawing page
    body = dom_ext.elementUnder( root, 'office:body')
    page = dom_ext.elementUnder( body, 'draw:page', (('draw:master-page-name','vychozi'),
                                                     ('draw:name', 'page1')))
    for o in self.paper.stack:
      if o.object_type == 'molecule':
        group = dom_ext.elementUnder( page, 'draw:g')
        for b in o.bonds:
          self.add_bond( b, group)
        for b in o.atoms:
          self.add_atom( b, group)
      elif o.object_type == 'arrow':
        self.add_arrow( o, page)
      elif o.object_type == 'text':
        self.add_text( o, page)
      elif o.object_type == 'plus':
        self.add_plus( o, page)
      elif o.object_type == 'rect':
        self.add_rect( o, page)
      elif o.object_type == 'oval':
        self.add_oval( o, page)
      elif o.object_type == 'polygon':
        self.add_polygon( o, page)

#    dom_ext.safe_indent( root)

    import tempfile
    # content file
    cfname = tempfile.mktemp()
    with open(cfname, 'wb') as f:
      f.write(out.toxml('utf-8'))
    # styles file
    sfname = tempfile.mktemp()
    with open(sfname, 'wb') as f:
      f.write(self.create_styles_document().toxml('utf-8'))
    import zipfile
    zip = zipfile.ZipFile( name, 'w', zipfile.ZIP_DEFLATED)
    manifest = os_support.get_path( 'oo_manifest.xml', 'template')
    if manifest:
      zip.write( os_support.get_path( 'oo_manifest.xml', 'template'), 'META-INF/manifest.xml')
      zip.write( cfname, 'content.xml')
      zip.write( sfname, 'styles.xml')
      zip.close()
    else:
      zip.close()
      raise plugin.export_exception( _("The manifest file not found in the plugin directory"))