Ejemplo n.º 1
0
    def default(self):

        if CONDA_ENV:
            qt_dir = CONDA_LIBRARY_PREFIX
            self._default["QTDIR"] = qt_dir
            self._default["QT5_BINPATH"] = pj(qt_dir, 'bin')
            self._default["QT5_CPPPATH"] = pj(qt_dir, 'include')
            self._default["QT5_LIBPATH"] = pj(qt_dir, 'lib')
            self._default["QT5_FRAMEWORK"] = False
            return

        qt_dir = os.getenv("QTDIR")
        qt_lib = '$QTDIR/lib'
        qt_bin = '$QTDIR/bin'
        qt_inc = '$QTDIR/include'
        qt_fmk = False

        if isinstance(platform, Linux):
            # Use LSB spec
            qt_dir = '/usr'
            qt_bin = '/usr/bin'
            qt_inc = '/usr/include/qt5'
            qt_lib = '/usr/lib'
        elif isinstance(platform, Darwin) and exists('/opt/local/libexec/qt5'):
            qt_dir = '/opt/local/libexec/qt5'
            qt_bin = '/opt/local/libexec/qt5/bin'
            qt_inc = '/opt/local/libexec/qt5/include'
            qt_lib = '/opt/local/libexec/qt5/lib'
        elif not qt_dir:
            try:
                if isinstance(platform, Win32) or isinstance(platform, Darwin):
                    # Try to use openalea egg
                    from openalea.deploy import get_base_dir
                    qt_dir = get_base_dir("qt5-dev")
            except:
                if isinstance(platform, Win32):
                    try:
                        from openalea.deploy import get_base_dir
                        qt_dir = get_base_dir("qt5")
                    except:
                        # Try to locate bin/moc in PATH
                        qt_dir = find_executable_path_from_env("moc.exe", strip_bin=True)

                elif isinstance(platform, Posix):
                    qt_dir = pj('/usr', 'lib', 'qt5')
                    if not exists(pj(qt_dir, 'bin')):
                        # Use LSB spec
                        qt_dir = '/usr'
                        qt_bin = '/usr/bin'
                        qt_inc = '/usr/include/qt5'
                        qt_lib = '/usr/lib'

        if isinstance(platform, Darwin):
            qt_fmk = True

        self._default["QTDIR"] = qt_dir
        self._default["QT5_BINPATH"] = qt_bin
        self._default["QT5_CPPPATH"] = qt_inc
        self._default["QT5_LIBPATH"] = qt_lib
        self._default["QT5_FRAMEWORK"] = qt_fmk
Ejemplo n.º 2
0
    def default(self):
        self._default['libs_suffix'] = '$compiler_libs_suffix'
        self._default['flags'] = ''
        self._default['defines'] = ''

        isPosix = isinstance(platform, Posix)        



        # -- lets now look for decent flags --
        self._default['flags'] = self.get_default_flags()
        self._default['defines'] = self.get_default_defines()

        # -- lets now look for decent include dirs --
        try:
            # Try to use openalea egg
            from openalea.deploy import get_base_dir
            try:
                base_dir = get_base_dir("boost")
            except:                
                base_dir = get_base_dir("boostpython")
            self._default['include'] = pj(base_dir, 'include')
            self._default['lib'] = pj(base_dir, 'lib')
            self.__usingEgg = True
        except:
            try:
                import openalea.config as conf
                self._default['include'] = conf.include_dir
                self._default['lib'] = conf.lib_dir

            except ImportError, e:                
                self._default['include'] = '/usr/include' if isPosix else pj(os.getcwd(), "include")
                self._default['lib']     = '/usr/lib' if isPosix else pj(os.getcwd(), "lib")
Ejemplo n.º 3
0
    def default(self):
        self._default['libs_suffix'] = '$compiler_libs_suffix'
        self._default['flags'] = ''
        self._default['defines'] = ''

        isPosix = isinstance(platform, Posix)

        # -- lets now look for decent flags --
        self._default['flags'] = self.get_default_flags()
        self._default['defines'] = self.get_default_defines()

        # -- lets now look for decent include dirs --
        if CONDA_ENV:
            self._default['include'] = join(CONDA_LIBRARY_PREFIX, 'include')
            self._default['libpath'] = join(CONDA_LIBRARY_PREFIX, 'lib')
            detectedsuffix = get_default_boost_libs_suffix(
                self._default['libpath'])
            if detectedsuffix:
                self._default['libs_suffix'] = detectedsuffix
            self.__usingEgg = False
        else:
            try:
                # Try to use openalea egg
                from openalea.deploy import get_base_dir
                try:
                    base_dir = get_base_dir("boost")
                except:
                    base_dir = get_base_dir("boostpython")
                self._default['include'] = join(base_dir, 'include')
                self._default['libpath'] = join(base_dir, 'lib')
                self.__usingEgg = True
            except:
                try:
                    import openalea.config as conf
                    self._default['include'] = conf.include_dir
                    self._default['libpath'] = conf.lib_dir

                except ImportError as e:
                    if isinstance(platform, Win32):
                        defdir = detect_win_project_installpath('boost')
                    else:
                        defdir = detect_posix_project_installpath(
                            'include/boost')

                    self._default['include'] = join(defdir, 'include')
                    self._default['libpath'] = join(defdir, 'lib')
                    detectedsuffix = get_default_boost_libs_suffix(
                        self._default['libpath'])
                    if detectedsuffix:
                        self._default['libs_suffix'] = detectedsuffix
Ejemplo n.º 4
0
    def default(self):

        self._default['libs_suffix'] = '$compiler_libs_suffix'

        if CONDA_ENV:
            base_dir = CONDA_LIBRARY_PREFIX
            self._default['include'] = pj(base_dir, 'include')
            self._default['libpath'] = pj(base_dir, 'lib')

        elif isinstance(platform, Win32):
            try:
                # Try to use openalea egg
                from openalea.deploy import get_base_dir
                base_dir = get_base_dir("qhull")
                self._default['include'] = pj(base_dir, 'include')
                self._default['libpath'] = pj(base_dir, 'lib')

            except:
                try:
                    import openalea.config as conf
                    self._default['include'] = conf.include_dir
                    self._default['libpath'] = conf.lib_dir

                except ImportError as e:
                    self._default['include'] = 'C:' + os.sep
                    self._default['libpath'] = 'C:' + os.sep

        elif isinstance(platform, Posix):
            defdir = detect_posix_project_installpath('include/libqhull')
            self._default['include'] = join(defdir, 'include')
            self._default['libpath'] = join(defdir, 'lib')
Ejemplo n.º 5
0
def install():
    from openalea.deploy.shortcut import create_win_shortcut
    from openalea.deploy import get_base_dir
    import sys
    from os.path import join as pj

    from openalea.oalab.project.symlink import create_project_shortcut

    create_project_shortcut()

    # Get the location of the installed egg
    base_dir = get_base_dir('openalea.oalab')
    share_dir = pj(base_dir, 'share')

    winexe = sys.executable
    winexe = winexe.replace('python.exe', 'pythonw.exe')

    prefix = base_dir.lower().split("lib")[0]

    create_win_shortcut(name='OALab',
                        target=winexe,
                        arguments='"' +
                        pj(sys.prefix, 'Scripts', 'oalab-script.pyw') + '"',
                        startin="",
                        icon=pj(share_dir, 'openalea_icon.ico'),
                        description="OpenAleaLab",
                        menugroup="OpenAlea")
Ejemplo n.º 6
0
def install():
    
    from openalea.deploy.shortcut import create_win_shortcut, set_win_reg, create_fd_shortcut
    from openalea.deploy import get_base_dir
    import sys
    from os.path import join as pj

    # Get the location of the installed egg
    base_dir = get_base_dir('openalea.visualea')
    share_dir = pj(base_dir, 'share')
    
    winexe = sys.executable
    winexe = winexe.replace('python.exe', 'pythonw.exe')
    
    prefix = base_dir.lower().split("lib")[0]
        
    create_win_shortcut(name = 'Visualea',
                        target = winexe,
                        arguments = '"'+pj(prefix, 'Scripts', 'visualea-script.pyw')+'"',
                        startin = "", 
                        icon = pj(share_dir, 'openalea_icon.ico'),
                        description = "Visual programming",
                        menugroup = "OpenAlea")

    create_win_shortcut(name = 'Python Shell',
                        target = winexe,
                        arguments = '"'+pj(prefix, 'Scripts', 'aleashell-script.pyw')+'"',
                        startin = "", 
                        icon = "",
                        description = "Python Shell",
                        menugroup = "OpenAlea")
Ejemplo n.º 7
0
   def default(self):

      if CONDA_ENV:
          if os.name == 'posix':
            base_dir = CONDA_LIBRARY_PREFIX
          else:
            # On windows, the conda package providing flex (m2-flex) is located in Library/usr
            base_dir = os.path.join(CONDA_LIBRARY_PREFIX, 'usr')
          self._default['bin'] = pj(base_dir, 'bin')
          self._default['include'] = pj(base_dir, 'include')
          if not isinstance(platform, Win32):
              self._default['libs'] = ['m','fl']
              self._default['libpath'] = pj(base_dir, 'lib')
      elif isinstance(platform, Win32):
         try:
              # Try to use openalea egg
              from openalea.deploy import get_base_dir
              base_dir = get_base_dir("bisonflex")
              self._default['bin'] = pj(base_dir, 'bin')
              self._default['include'] = pj(base_dir, 'include')
         except:
              self._default['bin'] = pj('C:\\', 'Tools', 'Bin')
              self._default['include'] = pj('C:\\', 'Tools', 'Include')

      elif isinstance(platform, Posix):
         defdir = detect_posix_project_installpath('bin/flex')
         self._default['bin'] = os.path.join(defdir, 'bin')
         self._default['libpath'] = os.path.join(defdir, 'lib')
         self._default['include'] = os.path.join(defdir, 'include')
         self._default['libs'] = ['m','fl']
Ejemplo n.º 8
0
def install():
    from openalea.deploy.shortcut import create_win_shortcut
    from openalea.deploy import get_base_dir
    import sys
    from os.path import join as pj

    from openalea.oalab.project.symlink import create_project_shortcut

    create_project_shortcut()

    # Get the location of the installed egg
    base_dir = get_base_dir("openalea.oalab")
    share_dir = pj(base_dir, "share")

    winexe = sys.executable
    winexe = winexe.replace("python.exe", "pythonw.exe")

    prefix = base_dir.lower().split("lib")[0]

    create_win_shortcut(
        name="OALab",
        target=winexe,
        arguments='"' + pj(sys.prefix, "Scripts", "oalab-script.pyw") + '"',
        startin="",
        icon=pj(share_dir, "openalea_icon.ico"),
        description="OpenAleaLab",
        menugroup="OpenAlea",
    )
Ejemplo n.º 9
0
   def default(self):

      self._default['libs_suffix'] = '$compiler_libs_suffix'

      if CONDA_ENV:
            base_dir = CONDA_LIBRARY_PREFIX
            self._default['include'] = pj(base_dir, 'include')
            self._default['libpath'] = pj(base_dir, 'lib')

      elif isinstance(platform, Win32):
         try:
            # Try to use openalea egg
            from openalea.deploy import get_base_dir
            base_dir = get_base_dir("qhull")
            self._default['include'] = pj(base_dir, 'include')
            self._default['libpath'] = pj(base_dir, 'lib')

         except:
            try:
                import openalea.config as conf
                self._default['include'] = conf.include_dir
                self._default['libpath'] = conf.lib_dir

            except ImportError as e:
                self._default['include'] = 'C:'+os.sep
                self._default['libpath'] = 'C:'+os.sep

      elif isinstance(platform, Posix):
           defdir = detect_posix_project_installpath('include/libqhull')
           self._default['include'] = join(defdir,'include')
           self._default['libpath']     = join(defdir,'lib') 
Ejemplo n.º 10
0
    def default(self):

        if CONDA_ENV:
            if os.name == 'posix':
                base_dir = CONDA_LIBRARY_PREFIX
            else:
                # On windows, the conda package providing flex (m2-flex) is located in Library/usr
                base_dir = os.path.join(CONDA_LIBRARY_PREFIX, 'usr')
            self._default['bin'] = pj(base_dir, 'bin')
            self._default['include'] = pj(base_dir, 'include')
            if not isinstance(platform, Win32):
                self._default['libs'] = ['m', 'fl']
                self._default['libpath'] = pj(base_dir, 'lib')
        elif isinstance(platform, Win32):
            try:
                # Try to use openalea egg
                from openalea.deploy import get_base_dir
                base_dir = get_base_dir("bisonflex")
                self._default['bin'] = pj(base_dir, 'bin')
                self._default['include'] = pj(base_dir, 'include')
            except:
                self._default['bin'] = pj('C:\\', 'Tools', 'Bin')
                self._default['include'] = pj('C:\\', 'Tools', 'Include')

        elif isinstance(platform, Posix):
            defdir = detect_posix_project_installpath('bin/flex')
            self._default['bin'] = os.path.join(defdir, 'bin')
            self._default['libpath'] = os.path.join(defdir, 'lib')
            self._default['include'] = os.path.join(defdir, 'include')
            self._default['libs'] = ['m', 'fl']
Ejemplo n.º 11
0
    def default(self):
        self._default['libs_suffix'] = '$compiler_libs_suffix'
        self._default['flags'] = ''
        self._default['defines'] = ''

        isPosix = isinstance(platform, Posix)



        # -- lets now look for decent flags --
        self._default['flags'] = self.get_default_flags()
        self._default['defines'] = self.get_default_defines()

        # -- lets now look for decent include dirs --
        if CONDA_ENV:
            self._default['include'] = join(CONDA_LIBRARY_PREFIX, 'include')
            self._default['libpath'] = join(CONDA_LIBRARY_PREFIX, 'lib')
            detectedsuffix = get_default_boost_libs_suffix(self._default['libpath']) 
            if detectedsuffix:
                self._default['libs_suffix'] = detectedsuffix 
            self.__usingEgg = False
        else:
            try:
                # Try to use openalea egg
                from openalea.deploy import get_base_dir
                try:
                    base_dir = get_base_dir("boost")
                except:
                    base_dir = get_base_dir("boostpython")
                self._default['include'] = join(base_dir, 'include')
                self._default['libpath'] = join(base_dir, 'lib')
                self.__usingEgg = True
            except:
                try:
                    import openalea.config as conf
                    self._default['include'] = conf.include_dir
                    self._default['libpath'] = conf.lib_dir

                except ImportError as e:
                    defdir = detect_posix_project_installpath('include/boost')
                    self._default['include'] = join(defdir,'include')
                    self._default['libpath']     = join(defdir,'lib')
                    detectedsuffix = get_default_boost_libs_suffix(self._default['libpath']) 
                    if detectedsuffix:
                        self._default['libs_suffix'] = detectedsuffix
Ejemplo n.º 12
0
Archivo: qt4.py Proyecto: gbaty/sconsx
    def default(self):

        qt_dir = os.getenv("QTDIR")
        qt_lib = '$QTDIR/lib'
        qt_bin = '$QTDIR/bin'
        qt_inc = '$QTDIR/include'

        if isinstance(platform, Linux):
            # Use LSB spec
            qt_dir = '/usr'
            qt_bin = '/usr/bin'
            qt_inc = '/usr/include/qt4'
            qt_lib = '/usr/lib'
        elif not qt_dir:
            try: 
                if isinstance(platform, Win32) or isinstance(platform, Darwin):
                    # Try to use openalea egg
                    from openalea.deploy import get_base_dir
                    qt_dir = get_base_dir("qt4-dev")
            except:
                if isinstance(platform, Win32):
                    try:                 
                        from openalea.deploy import get_base_dir
                        qt_dir = get_base_dir("qt4")
                    except:                                             
                        # Try to locate bin/moc in PATH
                        qt_dir = find_executable_path_from_env("moc.exe", strip_bin=True)
                
                elif isinstance(platform, Posix):
                    qt_dir = pj('/usr', 'lib', 'qt4')
                    if not exists(pj(qt_dir, 'bin')):
                        # Use LSB spec
                        qt_dir = '/usr'
                        qt_bin = '/usr/bin'
                        qt_inc = '/usr/include/qt4'
                        qt_lib = '/usr/lib'

        self._default["QTDIR"] = qt_dir
        self._default["QT4_BINPATH"] = qt_bin
        self._default["QT4_CPPPATH"] = qt_inc
        self._default["QT4_LIBPATH"] = qt_lib
Ejemplo n.º 13
0
 def default(self):
 
    if isinstance(platform, Win32):
       try:
          # Try to use openalea egg
          from openalea.deploy import get_base_dir
          base_dir = get_base_dir("bisonflex")
          self._default['bin'] = os.path.join(base_dir, 'bin')
       except:
          self._default['bin'] = r'C:\Tools\Bin'
              
    elif isinstance(platform, Posix):
       self._default['bin'] = '/usr/bin'
Ejemplo n.º 14
0
   def default( self ):
      """Set default tool values"""

      try:
         from openalea.deploy import get_inc_dirs, get_lib_dirs, get_base_dir

         bdir = get_base_dir(self.name)
         dirs = [os.path.join(bdir, x) for x in get_lib_dirs(self.name)]
         incs = [os.path.join(bdir, x) for x in get_inc_dirs(self.name)]
         
         self._default[self.lib_key] = dirs
         self._default[self.include_key] = incs

      except Exception as e:
         print("Cannot find build parameters for %s : "%(self.name,), e)
         self._default[self.lib_key] = ""
         self._default[self.include_key] = ""
Ejemplo n.º 15
0
    def default(self):
        """Set default tool values"""

        try:
            from openalea.deploy import get_inc_dirs, get_lib_dirs, get_base_dir

            bdir = get_base_dir(self.name)
            dirs = [os.path.join(bdir, x) for x in get_lib_dirs(self.name)]
            incs = [os.path.join(bdir, x) for x in get_inc_dirs(self.name)]

            self._default[self.lib_key] = dirs
            self._default[self.include_key] = incs

        except Exception as e:
            print(
                ("Cannot find build parameters for %s : " % (self.name, ), e))
            self._default[self.lib_key] = ""
            self._default[self.include_key] = ""
Ejemplo n.º 16
0
Archivo: flex.py Proyecto: gbaty/sconsx
   def default(self):

      if isinstance(platform, Win32):
         try:
              # Try to use openalea egg
              from openalea.deploy import get_base_dir
              base_dir = get_base_dir("bisonflex")
              self._default['bin'] = pj(base_dir, 'bin')
              self._default['include'] = pj(base_dir, 'include')
         except:
              self._default['bin'] = pj('C:\\', 'Tools', 'Bin')
              self._default['include'] = pj('C:\\', 'Tools', 'Include')
              
      elif isinstance(platform, Posix):
         self._default['bin'] = '/usr/bin'
         self._default['libpath'] = '/usr/lib'
         self._default['libs'] = ['m','fl']
         self._default['include'] = '/usr/include'
Ejemplo n.º 17
0
def install():
    
    from openalea.deploy.shortcut import create_win_shortcut, set_win_reg, create_fd_shortcut
    from openalea.deploy import get_base_dir
    import sys, os
    from os.path import join as pj

    # Get the location of the installed egg
    base_dir = get_base_dir('plantgl')

    bin_dir = pj(base_dir, "bin")
    print bin_dir
    
    create_win_shortcut(name = 'PlantGL Viewer',
                        target = pj(bin_dir, "pglviewer.exe",),
                        arguments = "",
                        startin = "", 
                        icon = pj(bin_dir, "pglviewer.exe",),
                        description = "PlantGL Viewer",
                        menugroup = "OpenAlea")
        

    # Windows registery (list of (key, subkey, name, value))
    winreg = [ ('HKCR', '.smb',   '', 'PGLFile') ,
               ('HKCR', '.lig',   '', 'PGLFile') ,
               ('HKCR', '.geom',  '', 'PGLFile') ,
               ('HKCR', '.bgeom', '', 'PGLFile') ,
               ('HKCR', 'PGLFile', '', 'PlantGL File') ,
               ('HKCR', 'PGLFile\\DefaultIcon', '', pj(bin_dir,'pglviewer.exe')+",1") ,
               ('HKCR', 'PGLFile\\shell', '', "open") ,
               ('HKCR', 'PGLFile\\shell\\open', '', "Open") ,
               ('HKCR', 'PGLFile\\shell\\open\\command', '', '"'+pj(bin_dir,'pglviewer.exe')+'" "%1"') ,
               ('HKCR', 'PGLFile\\shell\\add', '', "Add") ,
               ('HKCR', 'PGLFile\\shell\\add\\command', '', '"'+pj(bin_dir,'pglviewer.exe')+'" -a "%1"') ,
               # ('HKCR', 'PGLFile\\shell\\edit', '', "Edit") ,
               # ('HKCR', 'PGLFile\\shell\\edit\\command', '', '"'+pj(config.bin_dir,'pgleditor.exe')+'" "%1"') ,
               # ('HKCR', 'PGLFile\\shell\\geom2pov', '', "Translate To Povray") ,
               # ('HKCR', 'PGLFile\\shell\\geom2pov\\command', '', '"'+pj(config.bin_dir,'pgl2pov.exe')+'" "%1"') ,
               ]


    for t in winreg:
        set_win_reg(*t)
Ejemplo n.º 18
0
def install():
    """todo"""    
    from openalea.deploy.shortcut import create_win_shortcut, set_win_reg, create_fd_shortcut
    from openalea.deploy import get_base_dir
    import sys
    from os.path import join as pj

    # Get the location of the installed egg
    base_dir = get_base_dir('openalea.deploygui')
    share_dir = pj(base_dir, 'share')
    
    winexe = sys.executable
    winexe = winexe.replace('python.exe', 'pythonw.exe')
    create_win_shortcut(name = 'OpenAlea Installer',
                        target = winexe,
                        arguments = '"'+pj(sys.prefix, 'Scripts', 'alea_install_gui-script.pyw')+'"',
                        startin = "", 
                        icon = pj(share_dir, 'install_icon.ico'),
                        description = "OpenAlea Installation",
                        menugroup = "OpenAlea")
Ejemplo n.º 19
0
   def default(self):

      self._default['libs_suffix'] = '$compiler_libs_suffix'

      if isinstance(platform, Win32):
         try:
            # Try to use openalea egg
            from openalea.deploy import get_base_dir
            base_dir = get_base_dir("qhull")
            self._default['include'] = os.path.join(base_dir, 'include')
            self._default['lib'] = os.path.join(base_dir, 'lib')
            
         except:
            try:
                import openalea.config as conf
                self._default['include'] = conf.include_dir
                self._default['lib'] = conf.lib_dir

            except ImportError, e:
                self._default['include'] = 'C:'+os.sep
                self._default['lib'] = 'C:'+os.sep
Ejemplo n.º 20
0
    def default(self):

        if CONDA_ENV:
            if os.name == 'posix':
                self._default['bin'] = os.path.join(CONDA_LIBRARY_PREFIX,
                                                    'bin')
            else:
                # On windows, the conda package providing bison (m2-bison) is located in Library/usr
                self._default['bin'] = os.path.join(CONDA_LIBRARY_PREFIX,
                                                    'usr', 'bin')
        elif isinstance(platform, Win32):
            try:
                # Try to use openalea egg
                from openalea.deploy import get_base_dir
                base_dir = get_base_dir("bisonflex")
                self._default['bin'] = os.path.join(base_dir, 'bin')
            except:
                self._default['bin'] = r'C:\Tools\Bin'

        elif isinstance(platform, Posix):
            defdir = detect_posix_project_installpath('bin/bison')
            self._default['bin'] = os.path.join(defdir, 'bin')
Ejemplo n.º 21
0
def create_win_shortcut(name, target, arguments="",
                        startin="", icon="", description="",
                        menugroup="OpenAlea"):
    """ Create windows shortcut
    
    :param name: link name
    :param target: executable file path (ex : Pythonroot + pythonw.exe)
    :param arguments: (ex python module path)
    :param startin: execution path (same as python module path)
    :param icon: icon path (ex Pythonroot + '\\py.ico')
    :param description: ...
    :param menugroup: Menu group entry

    :example:
    
        >>> TempDir = os.environ["TEMP"]
        >>> Name        =  "New Link"
        >>> Target      =  Pythonroot + "pythonw.exe "
        >>> Arguments   =  TempDir + "\\test.py"
        >>> StartIn     =  TempDir
        >>> Icon        =  Pythonroot + "\\py.ico"
        >>> Description = "New Link"
        >>> create_win_shortcut(Path,Target,Arguments,StartIn,Icon,Description)
    """

    (Name, Target, Arguments, StartIn, Icon, Description, MenuGroup) = \
        (name, target, arguments, startin, icon, description, menugroup)

    if ((not 'win32' in sys.platform)):
        return
    
    try:
        from openalea.deploy import get_base_dir
        win32dir = get_base_dir('pywin32')
        os.environ['PATH'] += ';' + os.path.join(win32dir, 'pywin32_system32')
        from win32com.shell import shell, shellcon
    except Exception as e:
        print(e)
        print("ERROR : pywin32 is not installed. Cannot create shortcut.")
        return
    
    import win32api
    import pythoncom

    MenuRoot = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_PROGRAMS, 0, 0)
    MenuRoot = MenuRoot + "\\" + MenuGroup + "\\"
    
    if (not os.path.isdir(MenuRoot)):
        os.mkdir(MenuRoot)
    
    Path = MenuRoot + "\\%s.lnk" % (Name)
    Icon = (Icon, 0)
    
    # Get the shell interface.
    sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
                                    pythoncom.CLSCTX_INPROC_SERVER,
                                    shell.IID_IShellLink)

    # Set the data
    sh.SetPath(Target)
    sh.SetDescription(Description)
    sh.SetArguments(Arguments)
    sh.SetWorkingDirectory(StartIn)
    if (Icon[0]):
        sh.SetIconLocation(Icon[0], Icon[1])

    # Save the link itself.
    sh.QueryInterface(pythoncom.IID_IPersistFile).Save(Path, 0)
Ejemplo n.º 22
0
def create_win_shortcut(name,
                        target,
                        arguments="",
                        startin="",
                        icon="",
                        description="",
                        menugroup="OpenAlea"):
    """ Create windows shortcut
    
    :param name: link name
    :param target: executable file path (ex : Pythonroot + pythonw.exe)
    :param arguments: (ex python module path)
    :param startin: execution path (same as python module path)
    :param icon: icon path (ex Pythonroot + '\\py.ico')
    :param description: ...
    :param menugroup: Menu group entry

    :example:
    
        >>> TempDir = os.environ["TEMP"]
        >>> Name        =  "New Link"
        >>> Target      =  Pythonroot + "pythonw.exe "
        >>> Arguments   =  TempDir + "\\test.py"
        >>> StartIn     =  TempDir
        >>> Icon        =  Pythonroot + "\\py.ico"
        >>> Description = "New Link"
        >>> create_win_shortcut(Path,Target,Arguments,StartIn,Icon,Description)
    """

    (Name, Target, Arguments, StartIn, Icon, Description, MenuGroup) = \
        (name, target, arguments, startin, icon, description, menugroup)

    if ((not 'win32' in sys.platform)):
        return

    try:
        from openalea.deploy import get_base_dir
        win32dir = get_base_dir('pywin32')
        os.environ['PATH'] += ';' + os.path.join(win32dir, 'pywin32_system32')
        from win32com.shell import shell, shellcon
    except Exception as e:
        print(e)
        print("ERROR : pywin32 is not installed. Cannot create shortcut.")
        return

    import win32api
    import pythoncom

    MenuRoot = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_PROGRAMS, 0, 0)
    MenuRoot = MenuRoot + "\\" + MenuGroup + "\\"

    if (not os.path.isdir(MenuRoot)):
        os.mkdir(MenuRoot)

    Path = MenuRoot + "\\%s.lnk" % (Name)
    Icon = (Icon, 0)

    # Get the shell interface.
    sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
                                    pythoncom.CLSCTX_INPROC_SERVER,
                                    shell.IID_IShellLink)

    # Set the data
    sh.SetPath(Target)
    sh.SetDescription(Description)
    sh.SetArguments(Arguments)
    sh.SetWorkingDirectory(StartIn)
    if (Icon[0]):
        sh.SetIconLocation(Icon[0], Icon[1])

    # Save the link itself.
    sh.QueryInterface(pythoncom.IID_IPersistFile).Save(Path, 0)