Skip to content

Pick new picture name from filename #3428

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

Merged

Conversation

itafraze
Copy link
Contributor

@itafraze itafraze commented Aug 9, 2024

I found it desirable that the default name for newly created picture elements should not be <None>. I was thinking just to replace it with a New picture, but again, adding more than one picture element before renaming them makes it harder to distinguish between them later.

Todo:

  • Replace default picture element name <None> with New picture (or a translation of it)
  • Keep New picture picture element name if name extraction from filename fails
  • Run regression tests
  • Add test

PR Checklist

PR Type

  • Bug fix
  • Feature
  • Chore (refactoring, formatting, local variables, other cleanup)
  • Documentation content changes

What is the current behavior?

  1. Add a Picture element from the General toolbox;
  2. The new element default name is Null, replaced on the UI with <None>;
  3. Select picture... on the right sidebar and pick a valid image file;
  4. The name of the picture element keeps the same, <None>;

image

Bonus:
5. Selecting picture elements in the tree view of the left sidebar does not select the image in the diagram, so it is not possible to tell which image is which. On the contrary, selecting it in the diagram will highlight it in the tree view.

What is the new behavior?

  1. Add a Picture element from the General toolbox.
  2. The new element default name is New picture
  3. Select picture... on the right sidebar and pick a valid image file;
  4. The name of the picture element is replaced with the filename (non alphanumeric characters replaced with _;
  5. Select picture... again to replace the image with anothe valid image file;
  6. The name of the picture element does not change, assuming that if the same element has been updated and perhaps also previously renamed, its because it continues to serve the same scope.

image

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Development and test on local environment on Linux (Fedora 40). I am not able to test it on Windows and MacOS, but I suspect that the change is not OS dependent.

@github-actions github-actions bot added the python Pull requests that update Python code label Aug 9, 2024
@itafraze
Copy link
Contributor Author

itafraze commented Aug 9, 2024

Regression tests

$ git show
commit 283fb7d7297f5f9a2d8e5140e8349fa7ed0db1bd 
Author: Emanuele Zarfati <zarfati.tecno@gmail.com>
Date:   Wed Aug 28 15:55:39 2024 +0200

    Add picture select tests
Click to expand the test results
$ poetry run pytest
================================================================ test session starts ================================================================
platform linux -- Python 3.12.5, pytest-8.3.2, pluggy-1.5.0
Using --randomly-seed=362997691
rootdir: *
configfile: pyproject.toml
testpaths: gaphor, tests, docs
plugins: randomly-3.15.0, cov-5.0.0, archon-0.0.6, mock-3.14.0, xdoctest-1.2.0, hypothesis-6.111.2
collected 2032 items                                                                                                                                

gaphor/UML/actions/tests/test_actionspropertypages.py .......                                                                                 [  0%]
gaphor/UML/actions/tests/test_activitynodes.py .....                                                                                          [  0%]
gaphor/core/modeling/tests/test_elementfactory.py ..............                                                                              [  1%]
gaphor/ui/tests/test_statuswindow.py .                                                                                                        [  1%]
gaphor/diagram/tests/test_copypaste_link.py ..........                                                                                        [  1%]
gaphor/UML/usecases/tests/test_extend.py ....                                                                                                 [  2%]
gaphor/UML/profiles/tests/test_extensionconnect.py .......                                                                                    [  2%]
gaphor/UML/actions/tests/test_flow.py ....                                                                                                    [  2%]
gaphor/UML/actions/tests/test_copypaste.py ...                                                                                                [  2%]
gaphor/services/tests/test_properties.py ...                                                                                                  [  2%]
gaphor/storage/tests/test_storage_c4_upgrades.py .                                                                                            [  2%]
gaphor/ui/tests/test_modelbrowser.py .......................                                                                                  [  4%]
gaphor/UML/tests/test_copypaste.py ...                                                                                                        [  4%]
gaphor/UML/actions/tests/test_callbehaviouraction.py ..                                                                                       [  4%]
gaphor/UML/classes/tests/test_interface.py ..                                                                                                 [  4%]
gaphor/core/styling/tests/test_compiler.py ..........................................                                                         [  6%]
gaphor/UML/states/tests/test_group.py ........                                                                                                [  6%]
gaphor/ui/tests/test_mainwindow.py ..s..s...                                                                                                  [  7%]
gaphor/ui/tests/test_macosshim.py s                                                                                                           [  7%]
gaphor/ui/tests/test_treemodel.py .................                                                                                           [  8%]
gaphor/UML/classes/tests/test_generalizationconnect.py ........                                                                               [  8%]
gaphor/SysML/tests/test_sysml.py .......                                                                                                      [  8%]
gaphor/ui/tests/test_main.py ..                                                                                                               [  9%]
gaphor/UML/deployments/tests/test_connector.py ..                                                                                             [  9%]
gaphor/UML/classes/tests/test_associationconnect.py ...x...........                                                                           [  9%]
gaphor/core/modeling/tests/test_properties.py ...............................                                                                 [ 11%]
gaphor/diagram/tools/tests/test_dropzone.py ..                                                                                                [ 11%]
gaphor/UML/tests/test_uml2_overrides.py ....                                                                                                  [ 11%]
gaphor/storage/tests/test_mergeconflict.py .                                                                                                  [ 11%]
gaphor/UML/interactions/tests/test_copypaste.py ..                                                                                            [ 11%]
gaphor/services/tests/test_undo_presentation.py .....................                                                                         [ 12%]
gaphor/plugins/autolayout/tests/test_pydot.py .........                                                                                       [ 13%]
gaphor/UML/actions/tests/test_objectnode.py ...                                                                                               [ 13%]
gaphor/core/modeling/tests/test_presentation.py ..........                                                                                    [ 13%]
gaphor/diagram/general/tests/test_simpleitem.py ...                                                                                           [ 14%]
gaphor/UML/deployments/tests/test_copypaste.py .                                                                                              [ 14%]
gaphor/diagram/tests/test_shapes.py ..................                                                                                        [ 15%]
gaphor/UML/states/tests/test_copypaste.py ..                                                                                                  [ 15%]
gaphor/diagram/tests/test_segment.py .                                                                                                        [ 15%]
tests/test_properties.py ...........................................................................................                          [ 19%]
gaphor/ui/tests/test_modelchanged.py ..                                                                                                       [ 19%]
gaphor/C4Model/tests/test_grouping.py ....                                                                                                    [ 19%]
gaphor/UML/profiles/tests/test_packageimportconnect.py ...                                                                                    [ 20%]
gaphor/UML/tests/test_iconname.py .                                                                                                           [ 20%]
gaphor/SysML/tests/test_diagramtype.py .                                                                                                      [ 20%]
gaphor/diagram/tools/tests/test_txtool.py .                                                                                                   [ 20%]
gaphor/UML/classes/tests/test_class.py ...                                                                                                    [ 20%]
tests/test_composite_association.py .                                                                                                         [ 20%]
gaphor/ui/tests/test_filedialog.py ..........                                                                                                 [ 20%]
gaphor/diagram/general/tests/test_generalpropertypages.py .........                                                                           [ 21%]
tests/test_multiple_associations.py ..                                                                                                        [ 21%]
tests/test_action_issue.py .                                                                                                                  [ 21%]
gaphor/SysML/blocks/tests/test_group.py ...                                                                                                   [ 21%]
gaphor/diagram/tests/test_text.py .......................                                                                                     [ 22%]
tests/test_session_recovery.py ..................                                                                                             [ 23%]
gaphor/UML/states/tests/test_transition_connect.py ........                                                                                   [ 24%]
gaphor/storage/tests/test_storage_message_item_upgrade.py .                                                                                   [ 24%]
gaphor/UML/actions/tests/test_partition.py ...                                                                                                [ 24%]
gaphor/UML/interactions/tests/test_executionspecification.py ...........                                                                      [ 24%]
gaphor/SysML/tests/test_diagramitems.py .................................                                                                     [ 26%]
gaphor/services/tests/test_moduleloader.py .                                                                                                  [ 26%]
tests/test_presentations.py .................                                                                                                 [ 27%]
gaphor/services/tests/test_componentregistry.py ..                                                                                            [ 27%]
gaphor/storage/tests/test_recovery_eventlog.py .x.....                                                                                        [ 27%]
gaphor/ui/modelmerge/tests/test_organize_uml.py ..........                                                                                    [ 28%]
tests/test_model_consistency.py .                                                                                                             [ 28%]
gaphor/ui/tests/test_filemanager.py .......s.                                                                                                 [ 28%]
gaphor/core/changeset/tests/test_compare.py ....................                                                                              [ 29%]
gaphor/services/tests/test_modelinglanguage.py ....                                                                                           [ 29%]
gaphor/ui/installschemas/tests/test_installschemas.py .                                                                                       [ 29%]
gaphor/UML/usecases/tests/test_actor.py ...                                                                                                   [ 30%]
gaphor/ui/tests/test_copyservice.py ..                                                                                                        [ 30%]
tests/test_elements_have_owner.py ....                                                                                                        [ 30%]
gaphor/SysML/blocks/tests/test_connectors.py ........                                                                                         [ 30%]
gaphor/core/tests/test_eventmanager.py ....                                                                                                   [ 31%]
gaphor/extensions/tests/test_sphinx.py ..                                                                                                     [ 31%]
gaphor/UML/tests/test_umlfmt.py .....................................                                                                         [ 32%]
gaphor/UML/classes/tests/test_containmentconnect.py ........                                                                                  [ 33%]
gaphor/UML/interactions/tests/test_interactionspropertypages.py ..                                                                            [ 33%]
gaphor/storage/tests/test_storage.py ...............                                                                                          [ 34%]
gaphor/UML/actions/tests/test_partitionpage.py ...                                                                                            [ 34%]
gaphor/core/modeling/tests/test_elementdispatcher.py ...............                                                                          [ 35%]
gaphor/storage/tests/test_storage_uml_2_5_upgrade.py ......                                                                                   [ 35%]
gaphor/UML/actions/tests/test_actionseditors.py ...                                                                                           [ 35%]
gaphor/UML/tests/test_interactions.py ....                                                                                                    [ 35%]
gaphor/SysML/requirements/tests/test_connectors.py .......                                                                                    [ 36%]
gaphor/UML/tests/test_state_machine.py ............................................................                                           [ 38%]
gaphor/ui/tests/test_toolbox.py ......                                                                                                        [ 39%]
gaphor/core/modeling/tests/test_collection.py ..............                                                                                  [ 39%]
gaphor/tests/test_raises.py ....                                                                                                              [ 40%]
gaphor/UML/actions/tests/test_pin.py .                                                                                                        [ 40%]
gaphor/ui/tests/test_elementeditor.py ...                                                                                                     [ 40%]
gaphor/plugins/errorreports/tests/test_errorreport.py ...                                                                                     [ 40%]
gaphor/tests/test_transaction.py ........                                                                                                     [ 40%]
gaphor/UML/states/tests/test_drop.py ...                                                                                                      [ 41%]
gaphor/tests/test_version.py .                                                                                                                [ 41%]
gaphor/diagram/tests/test_copypaste_full.py ........                                                                                          [ 41%]
gaphor/storage/tests/test_parser.py ....                                                                                                      [ 41%]
gaphor/services/tests/test_undomanager.py ..................                                                                                  [ 42%]
gaphor/SysML/tests/test_sysmlfmt.py ......                                                                                                    [ 42%]
gaphor/UML/profiles/tests/test_copypaste.py ..                                                                                                [ 42%]
gaphor/diagram/tests/test_instanteditors.py ...                                                                                               [ 43%]
gaphor/diagram/tests/test_presentation.py ........                                                                                            [ 43%]
gaphor/core/styling/tests/test_css.py .....................................................                                                   [ 46%]
gaphor/UML/interactions/tests/test_message.py ....                                                                                            [ 46%]
gaphor/core/modeling/tests/test_literal_eval.py ......                                                                                        [ 46%]
gaphor/core/modeling/tests/test_style_attributes.py ..............                                                                            [ 47%]
gaphor/core/styling/tests/test_cascading.py ...........                                                                                       [ 47%]
gaphor/tests/test_entrypoint.py ...                                                                                                           [ 47%]
tests/test_plugins.py .                                                                                                                       [ 48%]
gaphor/SysML/allocations/tests/test_allocate_relationship.py .........................                                                        [ 49%]
gaphor/SysML/blocks/tests/test_proxy_port.py ....                                                                                             [ 49%]
gaphor/UML/usecases/tests/test_connect.py ..                                                                                                  [ 49%]
gaphor/UML/actions/tests/test_forknode.py ...                                                                                                 [ 49%]
gaphor/UML/interactions/tests/test_drop.py .                                                                                                  [ 49%]
gaphor/UML/usecases/tests/test_grouping.py ...                                                                                                [ 49%]
gaphor/UML/interactions/tests/test_group.py .                                                                                                 [ 49%]
gaphor/diagram/general/tests/test_comment.py ............                                                                                     [ 50%]
gaphor/UML/tests/test_recipes.py ................                                                                                             [ 51%]
tests/test_package_removal.py ..                                                                                                              [ 51%]
gaphor/ui/modelmerge/tests/test_organize.py .................                                                                                 [ 52%]
gaphor/UML/classes/tests/test_dependencyconnect.py ..........                                                                                 [ 52%]
gaphor/ui/tests/test_handletool.py ......                                                                                                     [ 53%]
gaphor/UML/classes/tests/test_interfaceconnect.py .......                                                                                     [ 53%]
tests/test_load_model.py .                                                                                                                    [ 53%]
gaphor/UML/tests/test_sanitizerservice.py .............                                                                                       [ 54%]
gaphor/UML/classes/tests/test_classeseditors.py .                                                                                             [ 54%]
gaphor/tests/test_action.py ....                                                                                                              [ 54%]
gaphor/diagram/tools/tests/test_handlemove.py ...                                                                                             [ 54%]
tests/test_comment_line_placement.py .                                                                                                        [ 54%]
gaphor/core/modeling/tests/test_modelinglanguage.py ...                                                                                       [ 54%]
gaphor/ui/tests/test_treesearch.py .....                                                                                                      [ 54%]
gaphor/storage/tests/test_xmlwriter.py .....                                                                                                  [ 55%]
gaphor/UML/actions/tests/test_grouping.py ......                                                                                              [ 55%]
gaphor/C4Model/tests/test_modelinglanguage.py ......                                                                                          [ 55%]
gaphor/diagram/tests/test_group.py ........                                                                                                   [ 56%]
gaphor/ui/tests/test_greeter.py ..                                                                                                            [ 56%]
gaphor/UML/classes/tests/test_classespropertypages.py ..........                                                                              [ 56%]
gaphor/UML/classes/tests/test_associationpropertypages.py ...                                                                                 [ 56%]
gaphor/UML/interactions/tests/test_ordering.py ..                                                                                             [ 56%]
gaphor/UML/tests/test_uml2.py ...........................                                                                                     [ 58%]
gaphor/SysML/tests/test_diagramlabel.py ..                                                                                                    [ 58%]
tests/test_remove_unused_elements.py ..                                                                                                       [ 58%]
gaphor/UML/actions/tests/test_activitypropertypage.py ................                                                                        [ 59%]
gaphor/services/tests/test_undo_diagram.py ..                                                                                                 [ 59%]
tests/test_auto_layouting.py .                                                                                                                [ 59%]
gaphor/diagram/tests/test_merge.py .                                                                                                          [ 59%]
gaphor/diagram/tests/test_copypaste.py ..                                                                                                     [ 59%]
gaphor/plugins/console/tests/test_consolewindow.py .                                                                                          [ 59%]
tests/test_architecture.py ........                                                                                                           [ 60%]
gaphor/UML/profiles/tests/test_stereotypepage.py ..                                                                                           [ 60%]
gaphor/plugins/console/tests/test_console.py .....                                                                                            [ 60%]
gaphor/diagram/tests/test_propertypages.py .......                                                                                            [ 60%]
gaphor/UML/classes/tests/test_interfacerealizationconnect.py ...                                                                              [ 60%]
gaphor/UML/classes/tests/test_datatype_connect.py .                                                                                           [ 60%]
gaphor/UML/deployments/tests/test_connect.py ................                                                                                 [ 61%]
gaphor/ui/tests/test_recentfiles.py ...                                                                                                       [ 61%]
gaphor/UML/classes/tests/test_dependencypropertypages.py ..                                                                                   [ 61%]
gaphor/core/changeset/tests/test_apply.py .....................                                                                               [ 62%]
gaphor/storage/tests/test_group.py .                                                                                                          [ 63%]
gaphor/UML/actions/tests/test_action.py ..                                                                                                    [ 63%]
gaphor/SysML/blocks/tests/test_block.py ..                                                                                                    [ 63%]
gaphor/SysML/tests/test_propertypages.py ....................                                                                                 [ 64%]
gaphor/UML/tests/test_drop.py .......                                                                                                         [ 64%]
tests/test_undo.py ................                                                                                                           [ 65%]
gaphor/core/modeling/tests/test_diagram_style.py ....                                                                                         [ 65%]
gaphor/extensions/tests/test_ipython.py .                                                                                                     [ 65%]
gaphor/storage/tests/test_loading.py ......                                                                                                   [ 65%]
gaphor/UML/tests/test_diagramitems.py ....................................................................................................... [ 70%]
..................................................                                                                                            [ 73%]
gaphor/ui/tests/test_actiongroup.py ...........                                                                                               [ 73%]
gaphor/UML/actions/tests/test_flowconnect.py ........................................                                                         [ 75%]
gaphor/storage/tests/test_recovery_recorder.py ................                                                                               [ 76%]
gaphor/UML/tests/test_group.py ..........                                                                                                     [ 77%]
gaphor/ui/tests/test_diagrampage.py ....                                                                                                      [ 77%]
tests/test_models_up_to_date.py .....                                                                                                         [ 77%]
gaphor/tests/test_settings.py ..                                                                                                              [ 77%]
gaphor/ui/tests/test_help.py ...                                                                                                              [ 77%]
gaphor/UML/states/tests/test_transition.py .                                                                                                  [ 77%]
gaphor/core/modeling/tests/test_diagram.py ..........                                                                                         [ 78%]
gaphor/core/styling/tests/test_declarations.py ............................                                                                   [ 79%]
gaphor/ui/tests/test_lifecycle.py ....                                                                                                        [ 80%]
gaphor/diagram/general/tests/test_generaleditors.py .                                                                                         [ 80%]
gaphor/tests/test_i18n.py .                                                                                                                   [ 80%]
gaphor/action.py .                                                                                                                            [ 80%]
gaphor/core/modeling/element.py .                                                                                                             [ 80%]
gaphor/core/modeling/collection.py .                                                                                                          [ 80%]
gaphor/storage/storage.py .                                                                                                                   [ 80%]
gaphor/storage/upgrade_canvasitem.py .                                                                                                        [ 80%]
gaphor/transaction.py .                                                                                                                       [ 80%]
gaphor/UML/classes/tests/test_association.py ........                                                                                         [ 80%]
gaphor/UML/usecases/tests/test_include.py ....                                                                                                [ 81%]
gaphor/UML/interactions/tests/test_messageconnect.py ...................                                                                      [ 81%]
gaphor/UML/tests/test_umllex.py ......................................                                                                        [ 83%]
gaphor/UML/deployments/tests/test_grouping.py .......                                                                                         [ 84%]
gaphor/C4Model/tests/test_propertypages.py ..                                                                                                 [ 84%]
tests/test_diagramexport.py ....                                                                                                              [ 84%]
gaphor/storage/tests/test_storage_upgrades.py ...............                                                                                 [ 85%]
gaphor/core/styling/tests/test_inherit.py ..                                                                                                  [ 85%]
gaphor/core/modeling/tests/test_element.py ..                                                                                                 [ 85%]
gaphor/tests/test_application.py ....                                                                                                         [ 85%]
gaphor/UML/classes/tests/test_enumerationpropertypages.py ..                                                                                  [ 85%]
gaphor/tests/test_babel.py .                                                                                                                  [ 85%]
gaphor/diagram/tests/test_iconname.py .                                                                                                       [ 85%]
gaphor/UML/profiles/tests/test_classifier_stereotypes.py .......                                                                              [ 86%]
gaphor/ui/tests/test_notifier.py ...                                                                                                          [ 86%]
gaphor/UML/states/tests/test_pseudostates.py ............                                                                                     [ 86%]
gaphor/diagram/tools/tests/test_shortcut.py ..                                                                                                [ 86%]
gaphor/diagram/tools/tests/test_tool_set.py ...                                                                                               [ 87%]
gaphor/UML/classes/tests/test_realizationconnect.py .....                                                                                     [ 87%]
gaphor/diagram/tests/test_export.py .....                                                                                                     [ 87%]
gaphor/UML/actions/tests/test_pinconnect.py .......                                                                                           [ 87%]
gaphor/UML/states/tests/test_propertypages.py .....                                                                                           [ 88%]
tests/test_unioncache_in_derived_response.py .                                                                                                [ 88%]
gaphor/UML/profiles/tests/test_stereotypepropertypages.py .....                                                                               [ 88%]
gaphor/diagram/tests/test_styling.py .                                                                                                        [ 88%]
gaphor/ui/tests/test_selftest.py .                                                                                                            [ 88%]
gaphor/plugins/console/tests/test_docstring_formatting.py ...                                                                                 [ 88%]
gaphor/SysML/tests/test_drop.py ....                                                                                                          [ 88%]
gaphor/UML/actions/tests/test_drop.py .......                                                                                                 [ 89%]
gaphor/codegen/tests/test_coder.py .......................                                                                                    [ 90%]
tests/test_issue_gaphas.py .                                                                                                                  [ 90%]
gaphor/ui/modelmerge/tests/test_modelmerge.py .                                                                                               [ 90%]
gaphor/UML/profiles/tests/test_metaclasspropertypage.py ..                                                                                    [ 90%]
gaphor/diagram/tests/test_copypaste_grouping.py ...                                                                                           [ 90%]
gaphor/tests/test_main.py ......                                                                                                              [ 91%]
gaphor/UML/states/tests/test_states.py .....                                                                                                  [ 91%]
gaphor/ui/tests/test_menufragment.py .                                                                                                        [ 91%]
gaphor/UML/tests/test_activity.py ...........................                                                                                 [ 92%]
tests/test_placement_tools.py ............................................................................................................... [ 98%]
............................                                                                                                                  [ 99%]
gaphor/UML/classes/tests/test_copypaste.py ..........                                                                                         [100%]

============================================== 2026 passed, 4 skipped, 2 xfailed in 162.89s (0:02:42) ===============================================

@itafraze itafraze changed the title WIP: Pick new picture name from filename Pick new picture name from filename Aug 9, 2024
@itafraze
Copy link
Contributor Author

itafraze commented Aug 10, 2024

Editing /models/Core.gaphor could allow to change the default name of a picture element. However:

Case 1
Specifying the derived type with "/" as prefix to the attribute name causes the coder to not generate any code:
image

$ poetry run poe coremodel
Poe => coremodel
No translations were found for language en_GB.UTF-8: [Errno 2] No translation file found for domain: 'gaphor'
WARNING:gaphor.codegen.coder:Derived attribute Picture.name has no implementation.
class Picture(Element):
    content: _attribute[str] = _attribute("content", str)

$\textcolor{orange}{\textsf{\textbf{Case 1} does not apply as I confused '/' with '}\wedge\textsf{'. Anyway, the latter, inherited-property (9.2.4.2), is not supported in Gaphor}}$

Case 2
Without specifying the derived inherited type (without "/" '^' prefix) the coder generates (nearly) the expected initialisation:
image

class Picture(Element):
    content: _attribute[str] = _attribute("content", str)
    name: _attribute[str] = _attribute("name", str, default=""ABC"")

However the quotes are not escaped and #3432 does not allow to set "New Picture" as default.

@itafraze itafraze force-pushed the feature/pick-new-picture-name-from-filename branch from f1cbc19 to 5ef5e63 Compare August 16, 2024 18:00
@amolenaar
Copy link
Member

@itafraze Is this something that still needs work?

Element already has a name property, so we should not need to repeat it. At the time the picture class was created that was not yet the case, though.

@itafraze
Copy link
Contributor Author

@amolenaar Initially I was waiting for #3448 to decide what the best approach would be.

Picture inherits name from Element, but it is autogenerated code. I cannot add manually a default value.

class Picture(Element):
content: _attribute[str] = _attribute("content", str)

My first idea was to add the default value as

image

but coder does not support the explicit inheritance ^ and it does not have idea that name exists since Element is overridden:

override Element
from gaphor.core.modeling.element import Element

By removing the initial ^ and with #3448 the above generates

class Picture(Element):
    content: _attribute[str] = _attribute("content", str)
    name: _attribute[str] = _attribute("name", str, default="New Picture")

which works. But I don't like that the language is fixed, i.e. it should be

    name: _attribute[str] = _attribute("name", str, default=diagram.gettext("New Picture"))

Sum up

At the moment, I think a better approach would be to add a `config_func' to

new_item_factory(general.PictureItem, Picture),

def picture_config(picture_item: general.PictureItem) -> None:
    picture_item.subject.name = gettext("New Picture")
        ToolDef(
            "toolbox-picture",
            gettext("Picture"),
            "gaphor-picture-symbolic",
            None,
            new_item_factory(general.PictureItem, Picture, config_func=picture_config),
        ),

@amolenaar
Copy link
Member

I agree that using a config function is the better approach. Overriding a commonly used attribute such as name, can have some funky side effects, like element names not updating in the model browser (it's checking for the Element.name attribute).

@itafraze itafraze force-pushed the feature/pick-new-picture-name-from-filename branch from 5ef5e63 to 283fb7d Compare August 28, 2024 14:08
@github-actions github-actions bot added the translation Everything regarding translation, localization, and internationalization label Aug 28, 2024
@itafraze itafraze marked this pull request as ready for review August 28, 2024 15:43
@itafraze itafraze force-pushed the feature/pick-new-picture-name-from-filename branch from 9a1a82b to 4e37cf5 Compare September 2, 2024 08:26
pyproject.toml Outdated
@@ -63,6 +63,7 @@ hypothesis = "^6.54.5"
ipython = "^8.5.0"
sphinx = ">=6,<9"
babelgladeextractor = "^0.7"
pytest-mock = "^3.14.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it easier to use monkeypatch instead? I removed pytest-mock (which is a shallow wrapper around unittest.mock) from the dependencies a while ago.

Comment on lines 153 to 158
self.subject.subject.name = "".join(
chr
if chr.isalnum() or (chr in [" ", "_", "-"])
else "_"
for chr in Path(filename).stem
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to a function, so it can be tested more easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# Test code
picture.subject.name = "old_name"
temp_image = os.path.abspath("data/logos/gaphor-24x24.png")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more in line with the rest of the code to use pathlib.Path instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@amolenaar
Copy link
Member

This looks really good. I had a few small remarks. If you feel like fixing those, please do. If not, then I can merge this. I'll take care of the merge conflict.

@itafraze
Copy link
Contributor Author

itafraze commented Sep 6, 2024

Thanks for the review! I'll take a look at it this weekend and get back with updates.

@itafraze itafraze force-pushed the feature/pick-new-picture-name-from-filename branch from 4e37cf5 to aa573a9 Compare September 15, 2024 14:59
@amolenaar
Copy link
Member

Thanks @itafraze. This is a really nice improvement!

@amolenaar amolenaar merged commit 531eea9 into gaphor:main Sep 16, 2024
22 checks passed
@itafraze itafraze deleted the feature/pick-new-picture-name-from-filename branch September 16, 2024 10:43
@danyeaw danyeaw added feature A new feature and removed python Pull requests that update Python code translation Everything regarding translation, localization, and internationalization labels Sep 19, 2024
@danyeaw
Copy link
Member

danyeaw commented Sep 19, 2024

@all-contributors please add @itafraze for code

Copy link
Contributor

@danyeaw

@itafraze already contributed before to code

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

Successfully merging this pull request may close these issues.

3 participants