Ask Your Question

Self customized preferences strip script failed to work for Wing Pro

asked 2020-09-14 04:18:12 -0600

hongyi-zhao gravatar image

updated 2020-09-14 09:27:13 -0600


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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-09-14 08:58:53 -0600

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.

edit flag offensive delete link more


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

hongyi-zhao gravatar imagehongyi-zhao ( 2020-09-14 21:14:46 -0600 )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 gravatar imageWingware Support ( 2020-09-15 08:47:51 -0600 )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 gravatar imagehongyi-zhao ( 2020-09-15 08:55:02 -0600 )edit

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

Wingware Support gravatar imageWingware Support ( 2020-09-15 09:15:21 -0600 )edit

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

hongyi-zhao gravatar imagehongyi-zhao ( 2020-09-15 17:57:16 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-09-14 04:18:12 -0600

Seen: 78 times

Last updated: Sep 14 '20