Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Refining Project Features

00:00 After the feature you wanted is implemented, it’s not set in stone. You can always tweak it, you can refine it, you can change it. You can completely change your mind or you can just improve it, enhance it.

00:11 And that’s what you’ll do in this lesson. You’re going to refine the feature that Codex implemented last time. When you’re in a directory and you want to open Codex, you can always run the command codex.

00:23 But when you do that, you get a new conversation. So if you quit, what you can do is run codex resume --last so that Codex opens the previous conversation it had.

00:34 So now you should see in front of you the transcript of the previous conversation. Running /diff should show you the changes that Codex implemented.

00:47 And while it might not be immediately obvious, there’s a couple of redundancies here. The methods on_something_button_pressed are completely irrelevant because you can use the @on decorator that Textual provides directly on the methods that are being called.

01:07 So you can ask Codex to make this small change. So you’re going to press Q to quit the diff output. And now you can type something like “Apply the @on decorators directly on the action methods, removing the need for the auxiliary methods.” Now, what was the name of those methods?

01:34 I think on_delete_button_pressed. Exactly. on_delete_button_pressed, and on_clear_all_button_pressed. Now, obviously, this only makes sense for the exact output from this run.

01:53 For you, you might have had a slightly different result. And so it might not make sense to ask for these exact changes. Once Codex is done, you can look at the diff again.

02:04 It shows the diff here with a bit more color. You can see it removed the auxiliary methods and put the event handlers on the correct methods. A different change you could ask for is “To prevent accidental deletion of contacts, use the QuestionDialog to confirm whenever the user tries to delete one or all contacts.” This is just to give you another example of a change that you might ask for, a refinement you might ask for.

02:42 Sometimes, Codex will do this out of the box. You don’t even have to ask for it. Again, you give it a second.

02:51 And now you can run /diff to get the diff. It looks reasonable. Now you quit Codex and you run rpcontacts. There’s no contacts, so you’ll add a couple.

03:15 Let’s add two more.

03:21 And a third one.

03:27 And now you can try deleting the middle one. And now, no, I don’t want to delete the middle one. Now you can try deleting the third one. You confirm. And now you can try to use the keyboard binding C to clear all.

03:41 And you say no, and it doesn’t delete anything. And now you confirm and you delete. And now pressing D or the button does nothing because there’s no contacts.

03:53 And pressing Clear All or C does nothing. So now you can press Q to exit the application. So it looks like the implementation was correct. Now in hindsight, I got lucky.

04:06 The thing that you should always do is when you have relevant and reasonable changes, you commit them. Because again, you never know what Codex will do. It’s easier to use git to roll back a change than to tell Codex, I don’t like your change, go back.

04:21 So what should have happened was when Codex implemented the deletion and the clearing all, those changes should have been committed so that when you go into the refinements, you have that checkpoint. But late is better than never.

04:37 You can run git diff and it will show you the exact same changes because after all, Codex is working on this code. You can quit the diff and now you can add the tui.py file so you can commit it.

04:54 So you’re going to add it and you’re going to commit saying allow deletion and clearing of contacts. There you go. So now that you’ve used Codex to implement and refine a feature in your Python project, it’s time to review everything you learned.

Become a Member to join the conversation.