def set_appusermodel(window_id, appid, icon_path, relaunch_command, relaunch_display_name): from win32com.propsys import propsys, pscon store = propsys.SHGetPropertyStoreForWindow(window_id, propsys.IID_IPropertyStore) id = store.GetValue(pscon.PKEY_AppUserModel_ID) store.SetValue(pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(appid)) store.SetValue(pscon.PKEY_AppUserModel_RelaunchCommand, propsys.PROPVARIANTType(relaunch_command)) store.SetValue(pscon.PKEY_AppUserModel_RelaunchDisplayNameResource, propsys.PROPVARIANTType(relaunch_display_name)) store.SetValue(pscon.PKEY_AppUserModel_RelaunchIconResource, propsys.PROPVARIANTType(icon_path))
def set_appusermodel( window_id, appid=None, icon_path=None, relaunch_command=None, relaunch_display_name=None, appname=None, ): """Set the appID details for the window, configuring how it appears in the taskbar and its pinning/relaunching behaviour. If appid, icon_path, relaunch_command or relaunch_display_name are None, they will be inferred from the appname, which must not be None if the other arguments are not provided. If the appid matches one of our known apps, then the other arguments will be ignored, as if appname was passed in and all other arguments were None. This is so that we can fix faulty relaunch commands being produced by older versions of the apps whilst accepting how they call us, without crashing, for backwards compatibility.""" _check_windows() if appid is not None: for known_appname, known_appid in appids.items(): if appid == known_appid: appname = known_appname appid = icon_path = relaunch_command = relaunch_display_name = None if appid is None: appid = appids[appname] if icon_path is None: icon_path = os.path.join(labscript_installation, appname, appname + '.ico') if relaunch_command is None: target, args = launch_command(appname) relaunch_command = ' '.join([target, args]) if relaunch_display_name is None: relaunch_display_name = app_descriptions[appname] store = propsys.SHGetPropertyStoreForWindow(window_id, propsys.IID_IPropertyStore) id = store.GetValue(pscon.PKEY_AppUserModel_ID) store.SetValue(pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(appid)) store.SetValue( pscon.PKEY_AppUserModel_RelaunchCommand, propsys.PROPVARIANTType(relaunch_command), ) store.SetValue( pscon.PKEY_AppUserModel_RelaunchDisplayNameResource, propsys.PROPVARIANTType(relaunch_display_name), ) store.SetValue(pscon.PKEY_AppUserModel_RelaunchIconResource, propsys.PROPVARIANTType(icon_path))
def make_shortcut(appname): """Create a shortcut file in the labscript suite install dir for the given app""" shortcut_path = os.path.join(labscript_installation, launcher_name(appname)) app_dir = os.path.join(labscript_installation, appname) _check_windows() shell = Dispatch('WScript.Shell') shortcut = shell.CreateShortcut(shortcut_path) target, args = launch_command(appname) shortcut.TargetPath = target shortcut.Arguments = args shortcut.WorkingDirectory = '"%s"' % app_dir shortcut.IconLocation = os.path.join(app_dir, appname + '.ico') shortcut.Description = app_descriptions[appname] shortcut.save() store = propsys.SHGetPropertyStoreFromParsingName( shortcut_path, None, shellcon.GPS_READWRITE, propsys.IID_IPropertyStore) store.SetValue( pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(str(appids[appname]), pythoncom.VT_LPWSTR), ) store.Commit() return shortcut_path
def get_link(self): link = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) properties = link.QueryInterface(propsys.IID_IPropertyStore) properties.SetValue(pscon.PKEY_AppUserModel_IsDestListSeparator, propsys.PROPVARIANTType(True)) properties.Commit() return link
def set_window_group(hwnd, lhandle): try: ps = propsys.SHGetPropertyStoreForWindow(hwnd) key = propsys.PSGetPropertyKeyFromName("System.AppUserModel.ID") value = propsys.PROPVARIANTType(lhandle) log("win32 hooks: calling %s(%s, %s)", ps.SetValue, key, value) ps.SetValue(key, value) except Exception as e: log("set_window_group(%s, %s)", hwnd, lhandle, exc_info=True) log.error("Error: failed to set group leader '%s':", lhandle) log.error(" %s", e)
def set_group(leader): try: log("win32 hooks: set_group(%#x)", leader.handle) ps = propsys.SHGetPropertyStoreForWindow(handle) key = propsys.PSGetPropertyKeyFromName( "System.AppUserModel.ID") value = propsys.PROPVARIANTType(leader.handle) log("win32 hooks: calling %s(%s, %s)", ps.SetValue, key, value) ps.SetValue(key, value) except Exception as e: log.error("failed to set group leader: %s", e)
def make_shortcut(path, target, arguments, working_directory, icon_path, description, appid): _check_windows() shell = Dispatch('WScript.Shell') shortcut = shell.CreateShortcut(path) shortcut.TargetPath = target shortcut.Arguments = arguments shortcut.WorkingDirectory = working_directory shortcut.IconLocation = icon_path shortcut.Description = description shortcut.save() store = propsys.SHGetPropertyStoreFromParsingName( path, None, shellcon.GPS_READWRITE, propsys.IID_IPropertyStore) store.SetValue( pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(str(appid), pythoncom.VT_LPWSTR), ) store.Commit()
def get_link(self): link = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) link.SetPath(self.command) if self.command_args: args = ' '.join(map(cmd_escape, self.command_args)) link.SetArguments(args) if self._working_directory: link.SetWorkingDirectory(self._working_directory) if self.icon: link.SetIconLocation(self.icon, self.icon_index) properties = link.QueryInterface(propsys.IID_IPropertyStore) properties.SetValue(pscon.PKEY_Title, propsys.PROPVARIANTType(self.title)) properties.Commit() return link
def win32_propsys_set_group_leader(self, leader): """ implements set group leader using propsys """ hwnd = get_window_handle(self) if not hwnd: return try: lhandle = leader.handle except: return if not lhandle: return #returns the setter method we can use try: log("win32 hooks: set_group(%#x)", lhandle) propsys = get_propsys() ps = propsys.SHGetPropertyStoreForWindow(hwnd) key = propsys.PSGetPropertyKeyFromName("System.AppUserModel.ID") value = propsys.PROPVARIANTType(lhandle) log("win32 hooks: calling %s(%s, %s)", ps.SetValue, key, value) ps.SetValue(key, value) except Exception as e: log.error("failed to set group leader: %s", e)
def create_shortcut( shortcut_path, target, arguments=(), working_directory=None, icon_file=None, display_name=None, appusermodel_id=None, ): """Create a Windows shortcut at the given path, which should be a filepath ending in '.lnk'. Arguments should be a list or tuple of arguments - not a single string of arguments separated by spaces.""" shortcut_path = Path(shortcut_path) shortcut_path.parent.mkdir(parents=True, exist_ok=True) _checkwindows() objShell = Dispatch('WScript.Shell') shortcut = objShell.CreateShortcut(str(shortcut_path)) shortcut.TargetPath = str(target) if arguments: shortcut.Arguments = list2cmdline(arguments) if working_directory is not None: shortcut.WorkingDirectory = str(working_directory) if icon_file is not None: shortcut.IconLocation = str(icon_file) if display_name is not None: shortcut.Description = display_name shortcut.save() if appusermodel_id is not None: # Edit the shortcut to associate the AppUserModel_ID with it: store = propsys.SHGetPropertyStoreFromParsingName( str(shortcut_path), None, shellcon.GPS_READWRITE, propsys.IID_IPropertyStore) store.SetValue(pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(appusermodel_id)) store.Commit()
def run(self): self.mainWindow = PipboyMainWindow() if (self.startedFromWin32Launcher): basepath = os.path.dirname(os.path.realpath(__file__)) launcherpath = os.path.abspath( os.path.join(basepath, os.pardir, 'PyPipBoyApp-Launcher.exe')) print('launcherpath: ' + str(launcherpath)) if 'nt' in os.name: from win32com.propsys import propsys, pscon import pythoncom hwnd = self.mainWindow.winId() propStore = propsys.SHGetPropertyStoreForWindow( hwnd, propsys.IID_IPropertyStore) propStore.SetValue( pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(u'matzman666.pypipboyapp.win32', pythoncom.VT_ILLEGAL)) propStore.SetValue( pscon.PKEY_AppUserModel_RelaunchDisplayNameResource, propsys.PROPVARIANTType('PyPipBoyApp', pythoncom.VT_ILLEGAL)) propStore.SetValue( pscon.PKEY_AppUserModel_RelaunchCommand, propsys.PROPVARIANTType(launcherpath, pythoncom.VT_ILLEGAL)) propStore.Commit() # Load Styles self._loadStyles() # Load widgets self.helpWidget = uic.loadUi(os.path.join('ui', 'helpwidget.ui')) self.helpWidget.textBrowser.setSource( QtCore.QUrl.fromLocalFile( os.path.join('ui', 'res', 'helpwidget.html'))) self.mainWindow.addDockWidget(QtCore.Qt.TopDockWidgetArea, self.helpWidget) self._loadWidgets() # Restore saved window state savedFullScreen = bool( int(self.settings.value('mainwindow/fullscreen', 0))) if savedFullScreen: self.mainWindow.showFullScreen() savedGeometry = self.settings.value('mainwindow/geometry') if savedGeometry: self.mainWindow.restoreGeometry(savedGeometry) savedState = self.settings.value('mainwindow/windowstate') if savedState: self.mainWindow.restoreState(savedState) # Create widgets menu entry self.widgetMenu.setTitle('Widgets') menuActions = self.mainWindow.menuBar().actions() self.mainWindow.menuBar().insertMenu(menuActions[len(menuActions) - 1], self.widgetMenu) # connect with main window self.mainWindow.actionConnect.triggered.connect( self.startAutoDiscovery) self.mainWindow.actionConnectTo.triggered.connect( self.showConnectToDialog) self.mainWindow.actionDisconnect.triggered.connect(self.disconnect) self.mainWindow.actionQuit.triggered.connect(self.requestQuit) self.mainWindow.signalWantsToQuit.connect(self.requestQuit) self.mainWindow.actionShowAbout.triggered.connect(self.showAboutDialog) self.mainWindow.actionShowAboutQt.triggered.connect(self.aboutQt) self.mainWindow.actionAuto_Connect_on_Start_up.triggered.connect( self.autoConnectToggled) self.mainWindow.actionExportData.triggered.connect(self.exportData) self.mainWindow.actionImportData.triggered.connect(self.importData) self.mainWindow.actionVersionCheck.triggered.connect( self.startVersionCheckVerbose) stayOnTop = bool(int(self.settings.value('mainwindow/stayOnTop', 0))) self.mainWindow.actionStayOnTop.toggled.connect( self.setWindowStayOnTop) self.mainWindow.actionStayOnTop.setChecked(stayOnTop) promptBeforeQuit = bool( int(self.settings.value('mainwindow/promptBeforeQuit', 1))) self.mainWindow.actionPromptBeforeQuit.toggled.connect( self.setPromptBeforeQuit) self.mainWindow.actionPromptBeforeQuit.setChecked(promptBeforeQuit) self.mainWindow.actionRelayModeSettings.triggered.connect( self._slotRelayModeSettings) # Init Relay Mode self.relayModeEnabled = bool( int(self.settings.value('mainwindow/relayModeEnabled', 0))) self.relayModeAutodiscovery = bool( int(self.settings.value('mainwindow/relayModeAutodiscovery', 0))) self.relayModePort = int( self.settings.value('mainwindow/relayModePort', 27000)) self.relayController = RelayController(self.dataManager) if self.relayModeEnabled: self.relayController.startRelayService(port=self.relayModePort) if self.relayModeAutodiscovery: self.relayController.startAutodiscoverService() # Main window is ready, so show it self.mainWindow.init(self, self.networkChannel, self.dataManager) self._initWidgets() self.mainWindow.show() # start main event loop if int(self.settings.value('mainwindow/autoconnect', 0)): self.mainWindow.actionAuto_Connect_on_Start_up.setChecked(True) host = 'localhost' port = 27000 if self.settings.value('mainwindow/lasthost'): host = self.settings.value('mainwindow/lasthost') if self.settings.value('mainwindow/lastport'): port = int(self.settings.value('mainwindow/lastport')) self.signalConnectToHost.emit(host, port, True) self.startVersionCheck() sys.exit(self.exec_())