srcanamdw/codescanner/pyinstaller/e2etests/win32/testcomext.py
author noe\swadi
Thu, 18 Feb 2010 12:29:02 +0530
changeset 1 22878952f6e2
permissions -rw-r--r--
Committing the CodeScanner Core tool This component has been moved from the StaticAnaApps package. BUG : 5889 (http://developer.symbian.org/webbugs/show_bug.cgi?id=5889).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     1
#! /usr/bin/env python
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     2
# Copyright (C) 2005, Giovanni Bajo
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     3
# Based on previous work under copyright (c) 1999, 2002 McMillan Enterprises, Inc.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     4
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     5
# This program is free software; you can redistribute it and/or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     6
# modify it under the terms of the GNU General Public License
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     7
# as published by the Free Software Foundation; either version 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     8
# of the License, or (at your option) any later version.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     9
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    10
# This program is distributed in the hope that it will be useful,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    13
# GNU General Public License for more details.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    14
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    16
# along with this program; if not, write to the Free Software
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
from win32com.shell import shell
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
import win32api
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
import pythoncom
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
import os
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
import sys
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
def CreateShortCut(Path, Target,Arguments = "", StartIn = "", Icon = ("",0), Description = ""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
    # Get the shell interface.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
    sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
        pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
    # Get an IPersist interface
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
    persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
    # Set the data
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
    sh.SetPath(Target)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
    sh.SetDescription(Description)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
    sh.SetArguments(Arguments)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
    sh.SetWorkingDirectory(StartIn)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
    sh.SetIconLocation(Icon[0],Icon[1])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
#    sh.SetShowCmd( win32con.SW_SHOWMINIMIZED)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
    # Save the link itself.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
    persist.Save(Path, 1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
    print "Saved to", Path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
if __name__ == "__main__":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
    try:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
        TempDir = os.environ["TEMP"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
        WinRoot = os.environ["windir"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    49
        Path        =  TempDir
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    50
        Target      =  os.path.normpath(sys.executable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    51
        Arguments   =  ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    52
        StartIn     =  TempDir
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    53
        Icon        = ("", 0)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    54
        Description = "py made shortcut"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    55
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    56
        CreateShortCut(Path,Target,Arguments,StartIn,Icon,Description)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    57
    except Exception, e:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    58
        print "Failed!", e
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    59
        import traceback
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    60
        traceback.print_exc()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    61
    raw_input("Press any key to continue...")