First time here? Check out the FAQ!

Self customized preferences strip script failed to work for Wing Pro


Each time when I am quitting wing, I want to let it strip the following sections from the ~/.wingpro7/preferences:


For this purpose, I create the following script ~/.wingpro7/scripts/ with the following content:

import wingapi

def topdir(file):
    return os.path.dirname(os.path.abspath(os.path.expanduser(file)))

def _quitting():
  # Do something here
  import os
  import re

  flag = False
  preferences = settings_directory + '/preferences'
  lines = []
  with open(preferences, 'r') as f:
      for line in f:
          line = line.strip('\n')
          if re.match(r'^main[.](update-history|last-prefs-page|prefs-version)', line):
              flag = True
              if flag and not re.match(r'[ ]', line):
                  flag = False
          if not flag:

  with open(preferences, 'w') as f:
      f.write('\n'.join(str(item) for item in lines))

wingapi.gApplication.fSingletons.fGuiMgr.connect('about-to-quit', _quitting)

But after I quit wing, it seems the script don't strip the corresponding sections from the ~/.wingpro7/preferences, see following for detail:

$ egrep 'main\.(last-prefs-page|prefs-version)' .wingpro7/preferences
main.last-prefs-page = (0,
main.prefs-version = 8

Any hints for this problem?

Regards, HY

hongyi-zhao's avatar
asked 2020-09-14 04:18:12 -0500
Wingware Support's avatar
Wingware Support
updated 2020-09-14 09:27:13 -0500
edit flag offensive 0 remove flag close merge delete


add a comment see more comments

1 Answer


It looks like about-to-quit is emitted prior to saving everything and thus the preferences get overwritten. It wasn't really intended for this purpose. Instead of writing this as a script for Wing I would instead write a wrapper that runs Wing and then when it exits strips the preferences file. The wrapper will need to pass through all args to Wing, of course.

Wingware Support's avatar
Wingware Support
answered 2020-09-14 08:58:53 -0500
edit flag offensive 0 remove flag delete link


Still, I'm not so clear on how to do it. Any more hints for this job?

hongyi-zhao's avatar hongyi-zhao (2020-09-14 21:14:46 -0500) edit

On Linux or macOS it would be something like this:

/path/to/wing "$@"

Then do 'chmod +x <scriptname>' with <scriptname> replaced by whatever you called this script. Then starting that script will run Wing and fix the prefs at the end, after Wing exits.

Wingware Support's avatar Wingware Support (2020-09-15 08:47:51 -0500) edit

If so, what's the purpose of ~/.wingpro7/scripts/ directory? IMO, it seems if such job can be done in the ~/.wingpro7/scripts/, it will be more graceful.

Regards, HY

hongyi-zhao's avatar hongyi-zhao (2020-09-15 08:55:02 -0500) edit

Look at the scripting API to see what it's for -- tons of things, but also not everything imaginable:

Wingware Support's avatar Wingware Support (2020-09-15 09:15:21 -0500) edit

If I use this method, then the wingapi relevant codes should be pruned from the script. Am I right?

hongyi-zhao's avatar hongyi-zhao (2020-09-15 17:57:16 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer