def onRemove(self, event): if self.currentItem == None: return #Remove shortcuts and app folder name = self.apps[self.currentItem].name #Get the desktop and start folders desktopShortcut = os.path.join(winshell.desktop(), name + '.lnk') startmenuShortcut = os.path.join(winshell.start_menu(), name + '.lnk') #Get the app dir appDir = getAppDir(name) if os.path.exists(desktopShortcut): os.remove(desktopShortcut) if os.path.exists(startmenuShortcut): os.remove(startmenuShortcut) if os.path.exists(appDir): files = os.listdir(appDir) for f in files: f_path = os.path.join(appDir, f) if os.path.isfile(f_path): os.remove(f_path) os.rmdir(appDir) self.populateList()
def createShortcuts(self, pathToIcon, pathToExec, pathToConfig, name, desktop, start): #Init pythoncom pythoncom.CoInitialize() #Create a shortcut shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) #Get the desktop and start folders desktopDir = winshell.desktop() startmenuDir = winshell.start_menu() #Set the exe path (to the desktopifyBrowser.exe) shortcut.SetPath(pathToExec) #Set the icon path for the downloaded favicon shortcut.SetIconLocation(pathToIcon, 0) #Set the config file as an argument shortcut.SetArguments(pathToConfig) #Save the shortcut persist_file = shortcut.QueryInterface(pythoncom.IID_IPersistFile) if desktop and desktopDir: persist_file.Save(os.path.join(desktopDir, name + ".lnk"), 0) if start and startmenuDir: persist_file.Save(os.path.join(startmenuDir, name + ".lnk"), 0)
def create_shortcut(directory, boolean): desktop = winshell.desktop() start_menu = winshell.start_menu() if boolean == 1: pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(desktop, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') elif boolean == 2: pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(start_menu, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') elif boolean == 3: pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(desktop, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(start_menu, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') elif boolean == 0: pass
def create_shortcut(desktop_shortcut_name, target_path, exe, icon_path): desktop = winshell.desktop() path = os.path.join(desktop, desktop_shortcut_name) remove_file(path) exe = os.path.join(target_path, exe) create_shortcut_file(path, exe, target_path, icon_path) start_menu = winshell.start_menu() path = os.path.join(start_menu, "Programs", "Kyton", "FbgUI.lnk") remove_file(path) if not os.path.isdir(os.path.join(start_menu, "Programs", "Kyton")): os.mkdir(os.path.join(start_menu, "Programs", "Kyton")) exe = os.path.join(target_path, "fbgui.exe") create_shortcut_file(path, exe, target_path, icon_path)
def uninstall(directory): try: del_dir = directory install_folder_name = directory.split('\\')[-1] directory = os.path.normpath(directory + os.sep + os.pardir) os.chdir(directory) except: return 'not a directory' if install_folder_name not in os.listdir(): return 'not a directory' os.chmod(del_dir, stat.S_IWRITE) try: shutil.rmtree(install_folder_name, ignore_errors=True) except: return 'error deleting a file' try: os.remove(install_folder_name) except: pass desktop = winshell.desktop() start_menu = winshell.start_menu() os.chdir(desktop) try: os.remove('PyPassMan.lnk') except: pass os.chdir(start_menu) try: os.remove('PyPassMan.lnk') except: pass
def func_install(self, gui_app): try: import sys guestOS = sys.platform # Require Python 3 to work if sys.version_info.major < 3: raise PythonVersionError else: gui_app.printcmd("OK: Python 3") try: pip = __import__('pip') gui_app.printcmd("OK: Pip") except ModuleNotFoundError: gui_app.printcmd("Warning: Pip module not found.") gui_app.printcmd( " Required dependencies won't be automatically installed." ) try: from pip._internal import main as pipmain except: from pip import main as pipmain self.pipmain = pipmain # List of modules required by SimCav simcav_modules = ['tkinter', 'numpy', 'requests', 'matplotlib' ] #, 'itertools', 'os', 'pickle', 'webbrowser'] # The last ones, commented, are part of the standard python distribution. # List of modules required by the installer installation_modules = [] if guestOS == 'win32': installation_modules.append('winshell') installed_modules = [] # Check that modules exist / can be imported gui_app.printcmd("\nChecking required modules:") haveIinstalled = False for i in simcav_modules + installation_modules: try: __import__(i) gui_app.printcmd("OK: " + i) except ModuleNotFoundError: gui_app.printcmd('x: ' + i) gui_app.printcmd( '\n Module ' + i + ' not found, but is required for SimCav to work') useranswer = gui_app.askuserbox( "Should I try to install '" + i + "'?") if useranswer: haveIinstalled = self.install(i) if haveIinstalled: if i in installation_modules: installed_modules.append(i) else: raise PipInstallError(i) else: raise NotModuleError(i) gui_app.printcmd( '\nAll dependencies satisfied! Continuing installation...\n') #=============================================== # SIMCAV INSTALLATION # Locations if guestOS == 'win32': import winshell user_home = winshell.folder("profile") else: user_home = os.path.expanduser('~') simcav_home = os.path.join(user_home, 'SimCav') gui_app.printcmd('Install location: ' + simcav_home) # Checking / creating SimCav folder if not os.path.exists(simcav_home): os.makedirs(simcav_home) user_proceed = gui_app.askuserbox( "This will install SimCav in your system.\nContinue?") else: user_proceed = gui_app.askuserbox( "The install directory already exist \n(" + simcav_home + ")\nOverwrite?") if not user_proceed: raise UserCancel install_window.update_idletasks() # Downloading files import requests simcav_api = 'https://gitlab.com/api/v4/projects/6789132/repository/' simcav_url = 'https://gitlab.com/simcav/simcav/raw/master-old/' # Required files simcav_files = [ 'simcav_main.py', 'simcav_CavityComputation.py', 'scrolledframe.py', 'simcav_ElementFeatures.py', 'simcav_abcd.py', 'simcav_simulator.py', 'tooltips.py', 'simcav_uninstaller.py', 'simcav_updater.py', 'misc.py' ] simcav_icons = [] simcav_saves = [] simcav_misc = [ 'LICENSE', 'Disclaimer.txt', 'README.md', 'CHANGELOG' ] # Get icons list from repo r = requests.get(simcav_api + 'tree?ref=master-old&per_page=100', params={'path': 'Icons/'}) if r.status_code == requests.codes.ok: gui_app.printcmd('\n Established connection.') else: gui_app.printcmd('\n Error connecting, try again later.') return for i in r.json(): if not '.svg' in i['name']: simcav_icons.append(i['name']) # Get saves list from repo r = requests.get(simcav_api + 'tree?ref=master-old&per_page=100', params={'path': 'Saves/'}) for i in r.json(): simcav_saves.append(i['name']) #================================= gui_app.printcmd('\n Creating subfolders...') # Icons folder try: icons_folder = os.path.join(simcav_home, 'Icons') if not os.path.exists(icons_folder): os.makedirs(icons_folder) except: gui_app.printcmd("Error creating 'Icons' folder") # Saves folder try: saves_folder = os.path.join(simcav_home, 'Saves') if not os.path.exists(saves_folder): os.makedirs(saves_folder) except: gui_app.printcmd("Error creating 'Saves' folder") #================================= #Downloading SimCav files gui_app.printcmd('\n Downloading modules...') for i in simcav_files: gui_app.printcmd(" Downloading " + i) self.download_file(simcav_url + i, os.path.join(simcav_home, i)) gui_app.printcmd('\n Downloading icons...') for i in simcav_icons: gui_app.printcmd(" Downloading " + i) self.download_file(simcav_url + 'Icons/' + i, os.path.join(icons_folder, i)) gui_app.printcmd('\n Downloading examples...') for i in simcav_saves: gui_app.printcmd(" Downloading " + i) self.download_file(simcav_url + 'Saves/' + i, os.path.join(saves_folder, i)) gui_app.printcmd('\n Downloading readmes...') for i in simcav_misc: gui_app.printcmd(" Downloading " + i) self.download_file(simcav_url + i, os.path.join(simcav_home, i)) gui_app.printcmd('\n Downloading manual...') if not 'manual.pdf' in os.listdir(simcav_home): self.download_file(simcav_url + 'Manual/manual.pdf', os.path.join(simcav_home, 'manual.pdf')) #gui_app.printcmd('\n Files downloaded') #================================================================= # Create system links gui_app.printcmd('\n Creating shortcuts...') # Create desktop shortcut if guestOS == 'win32': # NOT WORKING YET def create_shortcut(thepath, thehome): gui_app.printcmd('\n Creating shortcut in ' + thepath) python_path = os.path.join(os.path.dirname(sys.executable), 'pythonw.exe') mainfile_path = os.path.join(thehome, 'simcav_main.py') icons_folder = os.path.join(thehome, 'Icons') with winshell.shortcut(thepath) as thelink: thelink.path = python_path thelink.arguments = '"' + mainfile_path + '"' thelink.working_directory = thehome thelink.description = "Shortcut to SimCav" thelink.icon_location = (os.path.join( icons_folder, 'logo-tg3.ico'), 0) # Create icon in Desktop #python_path = os.path.dirname(sys.executable) shortcut_path = os.path.join(winshell.desktop(), 'SimCav.lnk') create_shortcut(shortcut_path, simcav_home) # Create StartMenu access startmenu_path = os.path.join(winshell.start_menu(), 'Programs', 'SimCav.lnk') create_shortcut(startmenu_path, simcav_home) elif guestOS == 'linux': desktop_path = os.path.join(os.path.join(user_home, 'Desktop'), 'SimCav.desktop') desktop_content = "[Desktop Entry]\nType=Application\nName=SimCav\nGenericName=Laser cavity simulator\nComment=Application for design and simulation of laser resonators\nExec=python " + os.path.join( simcav_home, 'simcav_main.py' ) + "\nIcon=" + os.path.join( icons_folder, 'logo-tg3.png' ) + "\nPath=" + simcav_home + "\nTerminal=false\nStartupNotify=false\nCategories=Education;Science" with open(desktop_path, 'w') as desktop_file: desktop_file.write(desktop_content) with open( os.path.join(user_home, '.local', 'share', 'applications', 'SimCav.desktop'), 'w') as desktop_file: desktop_file.write(desktop_content) gui_app.printcmd('\nInstallation finished!') except Exception as inst: gui_app.printcmd('\nError: ' + type(inst).__name__) if type(inst).__name__ in [ 'PythonVersionError', 'NotModuleError', 'PipInstallError', 'UserCancel' ]: gui_app.printcmd(inst.message) else: raise finally: for i in installed_modules: self.uninstall(i) gui_app.printcmd('\nYou may close this window.')
def test_start_menu(self): self.assert_folder_exists("start_menu personal", winshell.start_menu(0)) self.assert_folder_exists("start_menu common", winshell.start_menu(1))