First time here? Check out the FAQ!
1

Running a function from command line

  • retag add tags

I would like to open the IDE, load a project and start execution from a specified function of the project, everything from the command line. I'm able to invoke wing-personal passing the .wpr and this works fine, my project is loaded and ready to start. How can I automatically start execution (calling a selected function) from the same command line launching the IDE? I would need to execute in debug mode but also in non-debug mode.

steve1964's avatar
114
steve1964
asked 2022-11-08 04:12:11 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

There's no support for that level of control from the command line. However, you could write an extension script to do this. It could look at sys.argv and act accordingly. For example, if you add an arg at launch time like say 'wing9 --debug-file=/path/to/my/file.py' it will ignore the unknown arg but you can still see it with sys.argv in your script. Something like this:

import sys
import os
import wingapi

def _custom_launch_args():
  app = wingapi.gApplication

  # Prevent re-processing args if scripts are later reloaded
  if getattr(wingapi, '_processed_args', False):
    return
  wingapi._processed_args = True

  def find_filename(ftype):
    for arg in sys.argv:
      if arg.startswith(ftype):
        filename = arg[len(ftype):]
        if os.path.exists(filename):
          return filename
    return None

  filename = find_filename('--debug-file=')
  if filename is not None:
    app.OpenEditor(filename)
    app.ExecuteCommand('debug-file(show_dialog=False)')
    return

  filename = find_filename('--execute-file=')
  if filename is not None:
    app.OpenEditor(filename)
    app.ExecuteCommand('execute-file')

_custom_launch_args()

You can try this by dropping it into the 'scripts' directory below the Settings Directory reported in Wing's About box, then quit Wing and try launching with --debug-file= or --execute-file= arg. You may want to test with os.path.isabs(filename) and use os.path.abspath(filename) if not. Other than that I think the above should work.

See https://wingware.com/doc/scripting for details on scripting/extending the IDE.

Wingware Support's avatar
4k
Wingware Support
answered 2022-11-08 08:12:58 -0600
edit flag offensive 0 remove flag delete link

Comments

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