First time here? Check out the FAQ!
1

save project from API

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.

steve1964's avatar
114
steve1964
asked 2022-09-09 02:10:54 -0600
Wingware Support's avatar
4.2k
Wingware Support
updated 2022-09-09 10:22:36 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

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

Wingware Support's avatar
4.2k
Wingware Support
answered 2022-09-09 10:28:26 -0600
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

I'm trying this code in my plugin:

app = wingapi.gApplication  
app.ExecuteCommand('new-project')
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.

steve1964's avatar
114
steve1964
answered 2022-09-13 05:44:07 -0600, updated 2022-09-13 05:45:35 -0600
edit flag offensive 0 remove flag delete link

Comments

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 -0600) 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)
    app.ExecuteCommand('new-project')

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