Since the `hasattr` test can go away, you might as well make this:

```python
project = os.path.dirname(window.project_file_name())
```

Then the next few lines can be deleted, and the `else` becomes:

```python
if project is None:
```