First time here? Check out the FAQ!
0

Self customized preferences strip script failed to work for Wing Pro 7.2.5.1.

Hi,

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

main.update-history
main.last-prefs-page
main.prefs-version

For this purpose, I create the following script ~/.wingpro7/scripts/preferences-strip.py 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
  scripts_directory=topdir(__file__)
  settings_directory=os.path.dirname(scripts_directory)
  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
          else:
              if flag and not re.match(r'[ ]', line):
                  flag = False
          if not flag:
              lines.append(line)

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

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
547
hongyi-zhao
asked 2020-09-14 04:18:12 -0500
Wingware Support's avatar
4.1k
Wingware Support
updated 2020-09-14 09:27:13 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

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
4.1k
Wingware Support
answered 2020-09-14 08:58:53 -0500
edit flag offensive 0 remove flag delete link

Comments

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:

#!/bin/sh
/path/to/wing "$@"
python script-to-prune-prefs.py

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: https://wingware.com/doc/scripting/index

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