Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExportDialogDeclarative2 #1065

Merged
merged 8 commits into from
Jun 12, 2024
Merged

Conversation

cmeyer
Copy link
Collaborator

@cmeyer cmeyer commented Jun 11, 2024

  • Refactored Export Dialog in Declarative Mode
  • Do not pass redundant/unused 'parent_window'. Do not assign export dialog to unused variable.
  • Clean up instance variables in export dialog and its model.
  • Ensure that correct writer index is initialized.
  • Change export filename building to use pathlib.
  • Improve dialog box with default width and stretches.
  • Ensure selected writer is saved in preferences when export is pressed.
  • Fix issue where filename has a '.' (isodate on mac/linux).

Tiomat85 and others added 8 commits June 11, 2024 14:27
Fixed the bug with no checkboxes led to duplicate filenames, stopping all duplicate names happening.
Reimplemented in Declarative UI model.
Extracted the settings to a dataclass that can be re-used for scripting.
Extracted the export functionality to a static function that can be re-used for scripting.
@cmeyer
Copy link
Collaborator Author

cmeyer commented Jun 11, 2024

@Tiomat85 Thanks for the PR! Much improved. In the interest of moving your PR forward, I made a number of changes to clean up the code and fix bugs. By the time I was through I had made more changes than expected, so I decided to create a new PR with explanations of the changes. I squashed your changes, then made several commits on top of yours, described in order below.

If you're ok with these changes, approve this PR (or if not, make comments) and I'll merge asap.

0c7513b self explanatory minor changes

335800e the main thing here was to (a) eliminate "optional" instance variables. now writer is always assigned in the ExportDialogViewModel.__init__ method. Optional instance variables can lead to bugs down the road. As a general rule, I try to assign to all used variables in __init__ so we always know they're present (lest you end up with AttributeErrors when inadvertently accessing something that hasn't been assigned yet. In addition to that, I removed redundant writer and directory instance variables on the ExportDialog class, which are available unambiguously on the viewmodel.

a631cb1 the existing PR didn't initialize file_type_index (now called writer_index) with the correct index to match the writer. So the user could think they were exporting as JPEG (the first writer) but in actuality they would export with PNG (as assigned to writer). this fixes that.

6991f2f changes the build_filepath to use the pathlib Python module, which is more modern and easier to use. In addition, assumes now that directory_path exists before calling. Also renames to use "file path" in place of "file name" where appropriate.

c4bc0e3 minor cleanup to make the dialog look nicer. Still might need some more improvement (such as eliding the directory name, and making the 'prefix' select automatically). Note, along the way I fixed an issue where the file format combo box was bound to file_type_index.value rather than file_type_index (now called writer_index). also changed the "prefix string" to use create_line_edit (single line edit) rather than create_text_edit (multi-line edit).

6714529 ensure that the last exported file type preference is saved.

557c22a fixes a bug introduced by my pathlib changes, but I left it in here to be instructive. in this case, the isodate gives a string with a period on some platforms; then when replacing the extension, it will truncate at the period and add the suffix. this change just replaces '.' with '_' which is probably what is wanted in most cases anyway.

More items to-do (after merge):

  • elide the directory string to fit to width. the UserInterface.py truncate_string_to_width may be helpful.
  • clean up the prefix string to auto-enable if user enters prefix string
  • save the other preferences from viewmodel. the UserInterface.StringPersistentModel and similar classes may be helpful here.

@cmeyer
Copy link
Collaborator Author

cmeyer commented Jun 12, 2024

@Tiomat85 Is it ok to merge this? (I saw the other PR was closed)

@Tiomat85
Copy link
Contributor

Tiomat85 commented Jun 12, 2024 via email

@cmeyer cmeyer merged commit 1fe216a into nion-software:master Jun 12, 2024
13 checks passed
@cmeyer
Copy link
Collaborator Author

cmeyer commented Jun 12, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants