Ask Your Question
1

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

asked 2020-06-02 18:08:39 -0500

hongyi-zhao's avatar

updated 2020-06-03 18:38:04 -0500

Hi,

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

Regards.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-06-03 09:18:03 -0500

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.

edit flag offensive delete link more

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 -0500 )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 -0500 )edit
0

answered 2020-06-02 20:35:55 -0500

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.

edit flag offensive delete link more

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 -0500 )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

2 followers

Stats

Asked: 2020-06-02 18:08:39 -0500

Seen: 500 times

Last updated: Jun 03 '20