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

wxGUI: Fixed bare 'except' for psmap/ #4623

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arohanajit
Copy link
Contributor

Replace bare except with specific font creation error handling

  • Adds except (ValueError, wx.PyAssertionError) in makePSFont() to handle invalid font parameters and system font failures

Improve text measurement error handling

  • Adds except (wx.PyAssertionError, ValueError) in getTextExtent() for device context and text measurement failures

@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python labels Oct 31, 2024
@echoix
Copy link
Member

echoix commented Oct 31, 2024

Can the title better represent what is changed here? E722 isn't fixed for all wxGUI, only one file is fixed here and other wxGUI remains

@arohanajit arohanajit changed the title wxGUI: Fixed bare 'except' wxGUI: Fixed bare 'except' for psmap/ Oct 31, 2024
@@ -1049,7 +1049,7 @@ def makePSFont(self, textDict):
fn = wx.Font(
pointSize=fontsize, family=family, style=style, weight=weight, face=face
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the parameters need to be updated:

Suggested change
pointSize=fontsize, family=family, style=style, weight=weight, face=face
pointSize=fontsize, family=family, style=style, weight=weight, faceName=face

see https://docs.wxpython.org/wx.Font.html#wx.Font.__init__

@@ -1049,7 +1049,7 @@ def makePSFont(self, textDict):
fn = wx.Font(
pointSize=fontsize, family=family, style=style, weight=weight, face=face
)
except:
except (ValueError, wx.PyAssertionError):
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why these two?

@@ -1071,7 +1071,7 @@ def getTextExtent(self, textDict):
dc.SetFont(fn)
w, h, lh = dc.GetFullMultiLineTextExtent(textDict["text"])
return (w, h)
except:
except (wx.PyAssertionError, ValueError):
Copy link
Contributor

Choose a reason for hiding this comment

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

KeyError?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI wxGUI related Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants