First time here? Check out the FAQ!
1

Let wing running a script when user close/exit it.

Hi,

How can I let wing running a script when user close/exit it?

Regards.

hongyi-zhao's avatar
547
hongyi-zhao
asked 2020-06-02 18:08:39 -0600, updated 2020-06-03 18:38:04 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

If you are talking about the Debugger, it should work to use the Debug > Processes > Detach from Process menu item and then the debug process will continue and not be terminated when Wing quits.

Wingware Support's avatar
4.2k
Wingware Support
answered 2020-06-02 20:35:55 -0600
edit flag offensive 0 remove flag delete link

Comments

No, I mean the general case. When I exit/close wing, this event can trigger some script to do a post-processing job for me.

hongyi-zhao's avatar hongyi-zhao (2020-06-02 20:54:21 -0600) edit
add a comment see more comments
0

You can write an extension script as described in https://wingware.com/doc/scripting and connect to a signal that is emitted when Wing quits. This isn't currently exposed in the API (I'll see if we can add this, and thus am marking this ticket as a feature-request) but you can reach through the API to do it, something like this:

import wingapi

def _quitting():
  # Do something here
  pass

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

There is also a signal called 'quit' that can be used instead. The one above is emitted when the mainloop is still running while 'quit' is emitted after the mainloop exits. In your case either is probably fine.

Wingware Support's avatar
4.2k
Wingware Support
answered 2020-06-03 09:18:03 -0600
edit flag offensive 0 remove flag delete link

Comments

Thanks a lot, based on your above instructions. I write the following script in ~/.wingpro7/scripts named as preferences-strip.py and it does the trick:

import wingapi

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

  # https://ask.wingware.com/question/2091/the-meaning-for-the-perference-option-mainlast-prefs-page/
  # https://ask.wingware.com/question/2085/duplicates-entries-generated-for-mainupdate-history-list-in-the-wingpro7preferences/
  flag = False
  preferences = os.environ['HOME'] + '/.wingpro7/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)', 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')

  pass

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

But I still cannot figure out why you use pass command on the example codes. Any hints?

Regards.

hongyi-zhao's avatar hongyi-zhao (2020-06-03 19:03:27 -0600) edit

"pass" does nothing. It's used in Python as a place-holder so you can write something that's syntactically correct but doesn't have actual code in it yet. You can remove it from your code above...

Wingware Support's avatar Wingware Support (2020-06-03 22:56:10 -0600) 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