Title: pythonnet overloads difference between v2.5.2 and v3.0.1 · Issue #2197 · pythonnet/pythonnet · GitHub
Open Graph Title: pythonnet overloads difference between v2.5.2 and v3.0.1 · Issue #2197 · pythonnet/pythonnet
X Title: pythonnet overloads difference between v2.5.2 and v3.0.1 · Issue #2197 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.0.1 Python version: 3.9 Operating System: Win10 .NET Runtime: 4.0.30319.42000 Details Currently i am porting a module that uses pythonnet 2.5.2 with python 3.8. One part of that module creates a new font,...
Open Graph Description: Environment Pythonnet version: 3.0.1 Python version: 3.9 Operating System: Win10 .NET Runtime: 4.0.30319.42000 Details Currently i am porting a module that uses pythonnet 2.5.2 with python 3.8. One...
X Description: Environment Pythonnet version: 3.0.1 Python version: 3.9 Operating System: Win10 .NET Runtime: 4.0.30319.42000 Details Currently i am porting a module that uses pythonnet 2.5.2 with python 3.8. One...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2197
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"pythonnet overloads difference between v2.5.2 and v3.0.1","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.0.1\r\n- Python version: 3.9\r\n- Operating System: Win10\r\n- .NET Runtime: 4.0.30319.42000\r\n\r\n### Details\r\n\r\n\r\n\r\nCurrently i am porting a module that uses pythonnet 2.5.2 with python 3.8. One part of that module creates a new font, for .net objects, such as Labels...\r\n\r\nIn my past approach (pythonnet 2.5.2; python 3.8) i had to use the following overload to perform this action\r\n\r\n`new_font = Font.Overloads[String, Single, FontStyle](font_type, font_size, font_style)`\r\n\r\nThe overload was needed, because in some combinations of the font_style, i got the following exception (for a combination that will trigger this exception, see the example at the end of the question):\r\n\r\n```\r\nnew_font = Font(font_type, font_size, int(font_style))\r\nSystem.ArgumentException: Ungültiger Parameter.\r\n bei System.Drawing.Font.CreateNativeFont()\r\n\r\n bei System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)\r\n\r\n bei System.Drawing.Font..ctor(String familyName, Single emSize, GraphicsUnit unit)\r\n```\r\n\r\nSo far so good. If i use the same overload approach with pythonnet 3.0.1 and python 3.9, it wont work due the following exception.\r\n\r\n```\r\nnew_font = Font.Overloads[String, Single, FontStyle](font_type, font_size, font_style) \r\nTypeError: No method matches given arguments for Font..ctor: (\u003cclass 'float'\u003e, \u003cclass 'System.Drawing.FontStyle'\u003e)\r\n```\r\n\r\nBut if i skip the overload, it seems to work now? So my questions is, which approach is the \"right one\" to implement a robust font setter with the current pythonnet version?\r\n\r\nFor better understanding, here a minimal example to reproduce my issue\r\n\r\n```\r\nimport clr\r\nclr.AddReference(\"System\")\r\nclr.AddReference(\"System.Drawing\")\r\nfrom System.Drawing import Font \r\nfrom System.Drawing import FontStyle \r\nfrom System import String \r\nfrom System import Single\r\n\r\nfont_type = \"Arial\"\r\nfont_size = 12.0\r\nfont_style = FontStyle.Regular | FontStyle.Bold\r\n\r\n# fails with pythonnet 3.0.1; works with pythonnet 2.5.2\r\nnew_font = Font.Overloads[String, Single, FontStyle](font_type, font_size, font_style) \r\n\r\n# works with pythonnet 3.0.1, but fails with pythonnet 2.5.2\r\nnew_font = Font(font_type, font_size, font_style)\r\n```\r\n\r\nI also created a question here in stackoverflow https://stackoverflow.com/questions/76668946/pythonnet-overloads-difference-between-v2-5-2-and-v3-0-1 (actually I copied my question and added it here)\r\n","author":{"url":"https://github.com/stranger0612","@type":"Person","name":"stranger0612"},"datePublished":"2023-07-20T05:32:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/2197/pythonnet/issues/2197"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:07b18c08-3418-b427-1e2f-f9a47bc708f6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEBC:1B4AF9:28E1BA:36C926:697152B4 |
| html-safe-nonce | 85fcf3f2c1129eacfe5e485531212f0b32d9ef7d4bcf168457ac916369c5cefb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUJDOjFCNEFGOToyOEUxQkE6MzZDOTI2OjY5NzE1MkI0IiwidmlzaXRvcl9pZCI6IjcxMTAxODIzOTAyMjIzNzc2NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 39f98be0afe805ccadd7c48b39c40e27e15a41f2a9354bd34d5eb04f6688e03f |
| hovercard-subject-tag | issue:1813191881 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/2197/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aebc9c9268970709f562045d82f879c861104e72ead8d3c02581af1e442171d7/pythonnet/pythonnet/issues/2197 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aebc9c9268970709f562045d82f879c861104e72ead8d3c02581af1e442171d7/pythonnet/pythonnet/issues/2197 |
| og:image:alt | Environment Pythonnet version: 3.0.1 Python version: 3.9 Operating System: Win10 .NET Runtime: 4.0.30319.42000 Details Currently i am porting a module that uses pythonnet 2.5.2 with python 3.8. One... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | stranger0612 |
| hostname | github.com |
| expected-hostname | github.com |
| None | da7cbccf7f40bcd9540003423d9bef63b2fe7bb0b73fc59d91b5ae5b46000c90 |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c9e6c71b091ca750658a3b2e3c82b0b85555f788 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width