Changeset 3929


Ignore:
Timestamp:
Apr 24, 2019 9:18:45 AM (2 years ago)
Author:
vondreele
Message:

makeBat now recognizes old GSAS-II shortcuts & allows alternative name or Cancel (no new shortcut)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/makeBat.py

    r3927 r3929  
    9797            oldBat = winreg.QueryValue(oldopen,None).split()[0]
    9898            if oldBat != G2bat:
    99                 dlg = wx.MessageDialog(None,'gpx files already assigned to: \n'+oldBat+'\n Replace with: '+G2bat+'?','GSAS-II gpx in use',
     99                dlg = wx.MessageDialog(None,'gpx files already assigned in registry to: \n'+oldBat+'\n Replace with: '+G2bat+'?','GSAS-II gpx in use',
    100100                        wx.YES_NO | wx.ICON_QUESTION)
    101101                if dlg.ShowModal() == wx.ID_YES:
     
    106106    if new:
    107107        # Associate a script and icon with .gpx files
    108         #gpxkey = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, '.gpx')
    109108        gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\.gpx')
    110109        winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II.project')
     
    119118        winreg.CloseKey(openkey)
    120119        winreg.CloseKey(gpxkey)
    121         print('Assigned icon and batch file to .gpx files')
     120        print('Assigned icon and batch file to .gpx files in registery')
    122121    else:
    123         print('old assignment of icon and batch file is retained')
     122        print('old assignment of icon and batch file in registery is retained')
    124123
    125124    try:
     
    139138        desktop = win32com.shell.shell.SHGetFolderPath(
    140139            0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0)
    141         shortcut = os.path.join(desktop, "GSAS-II.lnk")
    142         shell = win32com.client.Dispatch('WScript.Shell')
    143         shobj = shell.CreateShortCut(shortcut)
    144         shobj.Targetpath = G2bat
    145         #shobj.WorkingDirectory = wDir # could specify a default project location here
    146         shobj.IconLocation = G2icon
    147         shobj.save()
    148         print('Created shortcut to start GSAS-II on desktop')
     140        shortbase = "GSAS-II.lnk"
     141        shortcut = os.path.join(desktop, shortbase)
     142        save = True
     143        if win32com.shell.shell.SHGetFileInfo(shortcut,0,0)[0]:
     144            print('GSAS-II shortcut exists!')
     145            dlg = wx.FileDialog(None, 'Choose new GSAS-II shortcut name',  desktop, shortbase,
     146                wildcard='GSAS-II shortcut (*.lnk)|*.lnk',style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
     147            try:
     148                if dlg.ShowModal() == wx.ID_OK:
     149                    shortcut = dlg.GetPath()
     150                else:
     151                    save = False
     152            finally:
     153                dlg.Destroy()
     154        if save:
     155            shell = win32com.client.Dispatch('WScript.Shell')
     156            shobj = shell.CreateShortCut(shortcut)
     157            shobj.Targetpath = G2bat
     158            #shobj.WorkingDirectory = wDir # could specify a default project location here
     159            shobj.IconLocation = G2icon
     160            shobj.save()
     161            print('Created shortcut to start GSAS-II on desktop')
     162        else:
     163            print('No shortcut for this GSAS-II created on desktop')
    149164    except ImportError:
    150165        print('Module pywin32 not present, will not make desktop shortcut')
Note: See TracChangeset for help on using the changeset viewer.