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

GUI: fix crashing due to File menu translation issues #4513

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

petrasovaa
Copy link
Contributor

This should fix #3222 and a duplicate #4491. It tries to first find the translated version of File menu, if it fails, it looks for untranslated version. I could replicate #4491 and this fixes it, GUI starts again.

@petrasovaa petrasovaa added bug Something isn't working backport to 8.4 PR needs to be backported to release branch 8.4 labels Oct 14, 2024
@petrasovaa petrasovaa added this to the 8.4.1 milestone Oct 14, 2024
@petrasovaa petrasovaa requested a review from marisn October 14, 2024 14:58
@petrasovaa petrasovaa self-assigned this Oct 14, 2024
@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python labels Oct 14, 2024
@echoix
Copy link
Member

echoix commented Oct 14, 2024

I don't think what I'm going to suggest below is better than this PR, but it is a reflexion. I find it weird that the menu items would be acted upon with translated titles as keys. I was searching to see if there would be an abstraction between what the menu item represents and the translated and displayed value was, but closest I got was title vs label, but couldn't answer myself on the difference.

However, in this specific case of the file menu (or help, or about, etc), it seems that wx has some special handling for some common items, that are handled in a platform-specific manner (especially on mac). See the first example of https://wiki.wxpython.org/How%20to%20use%20the%20Internationalization%20-%20i18n%20%28Phoenix%29, where some predefined ids are used (wx.GetStockLabel(wx.ID_FILE))

    def _createControls(self):
        # A Statusbar in the bottom of the window
        self.CreateStatusBar(1)
        sMsg = 'wxPython ' + wx.version()
        self.SetStatusText(sMsg)

        # Menu bar
        menubar = wx.MenuBar()
        # File menu
        filemenu = wx.Menu()
        filemenu.Append(wx.ID_EXIT)
        menubar.Append(filemenu, wx.GetStockLabel(wx.ID_FILE))
        # Help menu
        helpmenu = wx.Menu()
        helpmenu.Append(wx.ID_ABOUT)
        menubar.Append(helpmenu, wx.GetStockLabel(wx.ID_HELP))

        self.SetMenuBar(menubar)

        # Add a panel to the frame (needed under Windows to have a nice background)
        pnl = wx.Panel(self, wx.ID_ANY)

        szrMain = wx.BoxSizer(wx.VERTICAL)
        szrMain.AddStretchSpacer(1)
        label = wx.StaticText(pnl, wx.ID_STATIC, _("Welcome from wxWidgets"))
        fnt = label.GetFont().MakeLarger().MakeLarger()
        label.SetFont(fnt)
        szrMain.Add(label, 0, wx.ALL|wx.ALIGN_CENTER, 10)
        szrMain.AddStretchSpacer(1)
        pnl.SetSizer(szrMain)

The Ids are https://docs.wxpython.org/wx.StandardID.enumeration.html, GetStockLabel is described herehttps://docs.wxpython.org/wx.functions.html#wx.GetStockLabel, and (older) info on special ids is here https://wiki.wxpython.org/SpecialIDs.

I know most of the docs for wxPython are old, but there has now been a change in maintainership since the beginning of September 2024, the original person was getting old and ill. Transfer of the infrastructure wasn't completed yet, but they released a version since.

@petrasovaa
Copy link
Contributor Author

However, in this specific case of the file menu (or help, or about, etc), it seems that wx has some special handling for some common items, that are handled in a platform-specific manner (especially on mac). See the first example of

Yes, but the menu is generated from xml, so it's somewhat inconvenient to deal with the Stock IDs...

@petrasovaa
Copy link
Contributor Author

I know most of the docs for wxPython are old, but there has now been a change in maintainership since the beginning of September 2024, the original person was getting old and ill. Transfer of the infrastructure wasn't completed yet, but they released a version since.

Is there somewhere more info publicly on this?

@echoix
Copy link
Member

echoix commented Oct 14, 2024

The README of the project, plus following the quite long threads when the community was trying to get in touch with the maintainers (maintainer), at one point where he responded. wxWidgets/Phoenix#2553, plus related threads, and some threads in a discourse forum of wxPython.

At least one new maintainer can push to PyPI plus, and there are more than one person in GitHub organization (publicly).

The release made the fixes for Python 3.12 available.

At least since September, the bus factor isn't of 0 (some had even said that the bus has already past before the author's reply).

@echoix
Copy link
Member

echoix commented Oct 14, 2024

However, in this specific case of the file menu (or help, or about, etc), it seems that wx has some special handling for some common items, that are handled in a platform-specific manner (especially on mac). See the first example of

Yes, but the menu is generated from xml, so it's somewhat inconvenient to deal with the Stock IDs...

Ok, I didn't know that for these, I knew about the dialogs for the modules though.

But do you know what a label in the Menu (MenuBar or MenuItem?) would mean, compared to the title?
As I see it currently, a bad translation, or two separate strings translated to the same string in a language would cause problems identifying the correct menu item. It is a bug not discovered yet, but Murphy's law is always watching us.

@petrasovaa
Copy link
Contributor Author

But do you know what a label in the Menu (MenuBar or MenuItem?) would mean, compared to the title? As I see it currently, a bad translation, or two separate strings translated to the same string in a language would cause problems identifying the correct menu item. It is a bug not discovered yet, but Murphy's law is always watching us.

What do you mean with title specifically, we don't use it anywhere, no?

@echoix
Copy link
Member

echoix commented Oct 14, 2024

The menu.FindMenu refers to this function, right?

But do you know what a label in the Menu (MenuBar or MenuItem?) would mean, compared to the title? As I see it currently, a bad translation, or two separate strings translated to the same string in a language would cause problems identifying the correct menu item. It is a bug not discovered yet, but Murphy's law is always watching us.

What do you mean with title specifically, we don't use it anywhere, no?

The menu.FindMenu refers to this function, right? https://docs.wxpython.org/wx.MenuBar.html#wx.MenuBar.FindMenu

@petrasovaa
Copy link
Contributor Author

The menu.FindMenu refers to this function, right? https://docs.wxpython.org/wx.MenuBar.html#wx.MenuBar.FindMenu

The doc says it uses either title or label, we don't use titles (whatever that is) so I don't see any issues.

@echoix
Copy link
Member

echoix commented Oct 15, 2024

Ok, so anyways, this PR isn't wrong, so let's go forward with it.

@petrasovaa petrasovaa merged commit 941b52f into OSGeo:main Oct 17, 2024
26 of 27 checks passed
@petrasovaa petrasovaa deleted the gui-crash-translations branch October 17, 2024 15:02
@petrasovaa petrasovaa removed the backport to 8.4 PR needs to be backported to release branch 8.4 label Oct 17, 2024
@a0x8o a0x8o mentioned this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working GUI wxGUI related Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] g.gui: Cannot display GUI becasuse of wxMenuBar error
2 participants