Ask Your Question

save project from API

asked 2022-09-09 02:10:54 -0500

steve1964's avatar

updated 2022-09-09 10:22:36 -0500

I need to create automatically a Wing project from the extension API. I started to use NewProject() in class CAPIApplication but I can not find an API way to save it as a .wpr file with a specified path and name.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2022-09-13 05:44:07 -0500

steve1964's avatar

updated 2022-09-13 05:45:35 -0500

I'm trying this code in my plugin:

app = wingapi.gApplication  
prj = app.GetProject()  
prj_filename = prj.GetFilename()
prj_dir, prj_name = os.path.split(prj_filename)
print('DIR', prj_dir, 'NAME', prj_name)

The new-project command is nice since it may work interactively and create all the initial stuff. Especially, the end use can select the folder and the project name from dialogs. However, I do not understand why the prj.GetFilename does not return the filename of the newly created project. I need a way to know the folder and name after creation.

edit flag offensive delete link more


The issue is that the new-project command displays the dialog and then returns -- at the point that the next line runs, the user has just seen the dialog and hasn't specified the filename yet. The 'project-open' signal on the wingapi application object will be emitted when the new project object is created, which occurs after the user has used the dialog. You might connect to that and then save when it's created if you want to set the name.

Wingware Support's avatar Wingware Support  ( 2022-09-13 14:27:12 -0500 )edit

I tried the following:

def opened_cb(filename: str): 
    print('CALLBACK:', filename)

def create_new_project():   
    app = wingapi.gApplication      
    app.Connect('project-open', opened_cb)

The callback is called but the filename is still a default, not the one chosen by the user

steve1964's avatar steve1964  ( 2022-09-13 15:02:34 -0500 )edit

Yes, the filename is unknown when the project object is created. There isn't a signal in wingapi for when a name is chosen, though you could go beyond the api for this. The project is always saved when a filename is chosen, though, so I wonder if an extra save is needed.

Wingware Support's avatar Wingware Support  ( 2022-09-13 15:41:35 -0500 )edit

Could you please show how to do this? The API seems powerful but this apparently simple task looks hard...

Also, is there any way inside a plugin to get a string as input from the user through a simple dialog box? This could be an alternative, since I could ask the user for a name and then use that name to create the project.

steve1964's avatar steve1964  ( 2022-09-13 16:02:18 -0500 )edit

I'm not clear what you're trying to do. Are you trying to save a project to a filename that the script supplies? Or, do you want to use the filename that the user enters after using the new project dialog, creating the project, and then using the button to save the project?

Wingware Support's avatar Wingware Support  ( 2022-09-13 16:12:32 -0500 )edit

answered 2022-09-09 10:28:26 -0500

You should be able to do this with the save-project-as command, invoked as follows from a script:

import wingapi
wingapi.gApplication.ExecuteCommand('save-project-as', filename='whatever.wpr')

For the most part, the API doesn't include functionality that is available by executing commands in the command reference at

edit flag offensive delete link more

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: 2022-09-09 02:10:54 -0500

Seen: 96 times

Last updated: Sep 15 '22