Commit Graph

337 Commits

Author SHA1 Message Date
lojack5
2ea917b0b5 Python <3.9 typing compat: list
Subscribing builtins.list wasn't added until Python 3.9 so use
`typing.List` where applicable.
2023-10-18 13:08:54 -06:00
lojack5
17438ac318 Python <3.10 typing compat: unions
Use `typing.Optional` and `typing.Union` where applicable, as direct
union (`|`) type annotations were added in Python 3.10
2023-10-18 13:06:31 -06:00
lojack5
3958d89217 Optional fixing of wx prefix in cleanName
This fixes erroneous wx. prepended to `version` variable in methods'
parameters.
2023-10-18 12:27:00 -06:00
lojack5
1fa0df5db5 Add typing to handwritten code for core.pyi 2023-10-18 12:27:00 -06:00
lojack5
3d5290f46c Another type-conversion edge case: void -> Any 2023-10-18 12:27:00 -06:00
lojack5
e84d7abcba Possible way to handle enums.
Named enums with 'Flags' in the name use `enum.IntFlag`, all other enums
use `enum.IntEnum`.  We have to bring the enum members into the containing
scope to match the original behaviour. Further, since these enums are typing
information only, and not actually in wx proper, we prevent them from appearing
to leak the the user by marking as non-exported (prepend '_' to the name), then
make a TypeAlias to the enum or an int.  This way type signatures still claim
to accept integers as appropriate.

I like this solution best, because we preserved the information about which
enum members are expected for method/function parameters, while not leaking
non-existant classes out of the type-stubs, and not complaining about using
integers.

There's still a few undefined but referenced enums (ex:
richtext.TextAttrDimensionFlags). These are most likely a union of some of
the other flags/enum types already defined, but the work to pull that information
from the C++ source is probably too much.
2023-10-18 12:27:00 -06:00
lojack5
e14be4fbb4 Edge case on type-conversions: typdef int wxCoord 2023-10-18 12:26:59 -06:00
lojack5
ec15761d5b Better generated global variables
Use the more generic type rather than a literal type. Before, a type-checker
would infer an int defined this way as `Literal[0]` vs the more correctly
generic `int` for example.
2023-10-18 12:26:59 -06:00
lojack5
3e634c0794 Better generated member variables 2023-10-18 12:26:59 -06:00
lojack5
7aad3d4c70 Better generated properties
By directly referencing their setter and getter methods,
and due to the typing work already done for methods, we now have
type information attached to properties.

There are a few edge cases of setters/getters not having the proper
number of arguments for a getter(0) or setter(1), but most cases are
handled. The incorrect number of arguments may be missing default
arguments from what the extraction code figures out from the C++ code?
2023-10-18 12:26:59 -06:00
lojack5
2c6100cead Enable return-type annotations
With the work from the previous commits, it's as simple as
no longer lopping off the args string at the '->' marker.
(And one minor fixup to the makePyArgsString code).
2023-10-18 12:26:58 -06:00
lojack5
6b6b810cc4 Process overloaded functions and methods 2023-10-18 12:26:58 -06:00
lojack5
7f74a5fd65 Prepare for changes in generated #define and global variables
These will be changing to annotation statements, so FixWxPrefix needs to
be able to detect this still (proper thing to look for in this case is
`ast.AnnAssign`).
2023-10-18 12:26:58 -06:00
lojack5
fa2bde419f Extract type information in makePyArgsString
One unexpected type of '...' required adding a new transformation
that modifies both the name and the type to just '*args', so added
a preferred method `FixWxPrefix.parseNameAndType` which processes
both strings at once.

Also fixes cleanType to recursively call cleanType on sub-types
(was improperly calling cleanName).

With this, method and function signatures now have type annotations
which are mostly correct (100% correct in the "it compiles" sense).
Thankfully, the incorrect type-hints don't cause errors due to using
stringized annotations (by importing annotations from __future__).

Importantly, the overload signatures now have been fully sanitized.
Before this, there was one instance of a variable named `is`, and another
named `/Transfer/` - both invalid identifiers. I stopped looking after
those. Since theses signatures are valid Python code, this opens up the
opportunity to use `typing.overload` to fully expose those.

Edge-cases in type-hints will be addressed in later commits.
2023-10-18 12:26:58 -06:00
lojack5
a28de82bbb Ensure needed imports from typing are included in type-stubs
Leverages the `writeSection` machinery, with a tweak to specify to add a
new section to the beginning of a file, after the header. This ensures
the required imports gets updated (and also only imported once per file)
if new imports are needed for type-hints. Hint: there's a few more to come.
2023-10-18 12:26:10 -06:00
lojack5
d303548d43 Move local _cleanName to FixWxPrefix.cleanName
This allows for building `FixWxPrefix.cleanType` on top of it, for use
in processing type-hint strings in the future. It also exposes the method
to `FunctionDef.makePyArgString` in the future, which has easier access to
the types of arguments and returns. And possibly further in the future,
other `***Def` classes can make use of it (constant definitions, etc).
2023-10-18 12:19:00 -06:00
lojack5
07de1d515e [etgtools] Disable text wrapping for specific lines in docstrings
The line-wrapping causes issues once the python signatures become too long,
as textwrap isn't smart enough to split the lines on valid continuation points
for code. I had one instance of splitting a line in the middle of a string ->
SyntaxError on next run of etg due to the generated PYI file having an
unterminated string.

Specificially, disable splitting for lines that start (ignoring spaces) with
a specific string - in this case any line starting with the name of the
function or method this is a docstring for.
2023-10-18 12:18:48 -06:00
Robin Dunn
9d19ba1ee7 Guard against None returned for the top-level parent node 2022-05-09 22:11:22 -07:00
Scott Talbert
aa1ef7bd75 Update ETG scripts to support wxWidgets 3.1.6 functionality
Fixes #2136.
2022-05-02 22:33:58 -04:00
Robin Dunn
3197c46797 Add support for using setCppCode on function objects 2021-01-18 14:15:57 -08:00
Robin Dunn
f5a18224b7 Merge pull request #1879 from swt2c/fix_sipgenerator_conditional
Fix conditional in sip_generator generateCppMethod_sip()
2021-01-05 12:45:20 -08:00
Robin Dunn
12db41dad1 Ensure SIP knows about the item container pure virtuals. 2020-12-29 18:11:05 -08:00
Scott Talbert
730cdb2107 Fix conditional in sip_generator generateCppMethod_sip()
When I added this code in 5e190eb, it was intended to be used in all cases
except for constructors and destructors.  Instead, it was used in all cases.
This broke the wxRegion constructor and possibly other things.

Fixes #1878.
2020-12-21 23:31:17 -05:00
Robin Dunn
7a839de248 Make it possible to call a function that post-processes the generated ReST doc for a class. 2020-11-11 15:40:05 -08:00
Stefan Brüns
08c895a379 Do not strip wx prefix from parameter names
Parameter names should not be mangled, as this causes mismatches between
extractor and xml data:

```
SEVERE: Incompatibility between function/method signature and list of parameters in `wx.html.HtmlHelpWindow.__init__`:
The parameter `WindowID` appears in the method signature but could not be found in the parameter list.
  ==> Function/Method signature from `extractors`: __init__(parent, WindowID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.BORDER_NONE, helpStyle=HF_DEFAULT_STYLE, data=None)
  ==> Parameter list from wxWidgets XML items:     ['parent', 'wxWindowID', 'pos', 'size', 'style', 'helpStyle', 'data']
```
```
  ==> Function/Method signature from `extractors`: SetAssertMode(AppAssertMode)
  ==> Parameter list from wxWidgets XML items:     ['wxAppAssertMode']
```
2020-10-02 00:12:08 +02:00
Robin Dunn
4b9b8ad93e Add the EnableVisibleFocus virtual method to all window classes 2020-09-10 13:06:31 -07:00
Robin Dunn
92f8cd2d55 Fix lots of misspelled words 2020-07-14 11:38:32 -07:00
Robin Dunn
b60eaf3dc1 Merge pull request #1711 from wxWidgets/fix-issue1706
Add `IsNull()` checks for all property methods in GraphicsObject classes
2020-07-02 20:45:08 -07:00
Robin Dunn
ca257209e6 Add ability to use %PreMethodCode% for more than just the mustHaveApp check 2020-07-02 15:48:48 -07:00
Stefan Brüns
b45ec07194 Use explicit wxString::c_str conversion for sipFindType(const char*) 2020-07-01 15:13:07 +02:00
Scott Talbert
5e190eb42e Fix stack overflow when overriding wx.CustomObject.SetData
In the implementation of wx.CustomData.SetData, we need to check the
sipSelfWasArg variable to determine whether to call the parent class
implementation of SetData.  To do this, we switched to using addCppMethod_sip
which allows us to access the sipSelfWasArg variable.  The sip generator
stuff for CppMethod_sip needed some additions to match the behavior of
CppMethod.
2020-05-31 13:43:32 -04:00
Robin Dunn
06b08ecc05 Move fixDialogProperty to tweaker_tools, and use it on more property classes 2020-04-23 15:13:40 -07:00
Robin Dunn
2baac81cee Merge pull request #1579 from wxWidgets/fix-1567-AnimationDecoder
Use generic animation classes on all platforms
2020-04-06 20:16:51 -07:00
Per A. Brodtkorb
426258b7b7 Adding missing close for open and replaced "fid=open(filename) fid.close()"
statements with the safer "with open(filename) as fid:" blocks.

Also removed unnecessary "try: ... finally: pass" statements
and refactored code from img2py function into _write_image and _replace_non_alphanumeric_with_underscore

Fixes #1574
2020-03-25 10:36:38 +01:00
Robin Dunn
a263e02639 Some additional default typeVal items for the stubs generator 2020-03-24 18:39:20 -07:00
Robin Dunn
799d94b50f Enable adding extra TypeHeader text in wxListWrapperTemplate 2020-03-24 17:36:22 -07:00
Per A. Brodtkorb
e4e8bf8317 Fixes issue 1571:
Adding missing close for open.
If the "close()" call is missing after a "open(filename)" call, the filename isn't guaranteed to be closed before the interpreter exits.
This is generally a bad practice as explained here: https://stackoverflow.com/questions/7395542/is-explicitly-closing-files-important

Also replaced "fid=open(filename) fid.close()" statements for files with the safer
"with open(filename) as fid:" blocks. See https://www.python.org/dev/peps/pep-0343/
2020-03-23 17:16:44 +01:00
Per A. Brodtkorb
033c18fd9f Fixes issue #1556
Replaced XXX.keys() calls with idiomatic python 3 calls that are compatible with python 2 such as eg:
 * replaced "y = xxx.keys()" or "y = list(xxx.keys())" with just "y = list(xxx)"
 * replaced "sorted(xxx.keys())" or "sorted(list(xxx.keys()))" with just "sorted(xxx)"
 * replaced "if not A in B.keys():" with "if A not in B:"
 * replaced "for A in B.keys():"  with "for A in B:"

See also https://python-future.org/compatible_idioms.html
https://python-future.org/compatible_idioms.html#dict-keys-values-items-as-a-list
2020-03-20 18:51:19 +01:00
Robin Dunn
b503793e5e Add ability to make global name strings from a wchar_t constant 2020-03-17 17:46:56 -07:00
Robin Dunn
9f2cc54b48 Update copyright years 2020-03-10 11:41:39 -07:00
Robin Dunn
65c8397ddb Tweak 3.x versions in the docs to 4.x, to adjust for the difference in version numbers 2019-12-20 16:34:58 -08:00
Robin Dunn
8614e1ae09 Handle <ndash> and <mdash> tags in the docs xml 2019-10-30 18:19:25 -07:00
Robin Dunn
09404e63f5 Simplify postprocessing, remove changes no longer needed, or edit them for Sphinx 2.2.0. 2019-10-03 14:54:50 -07:00
Robin Dunn
b430a16ec3 Ensure sip knows that wxLog has a default ctor and a dtor 2019-08-13 15:25:40 -07:00
Robin Dunn
a09ddd8c27 Add some missing methods in BitmapComboBox 2019-07-17 12:00:41 -07:00
Robin Dunn
54dc9ac457 Add EnableSystemTheme method to the classes which support it 2019-06-12 13:33:26 -07:00
Robin Dunn
41a4841eb2 Fix extraction of the template parameter name 2019-05-29 14:14:43 -07:00
Robin Dunn
5d078557bf Lots of updates to get caught up with wxWidgets master (3.1.3+) 2019-05-23 21:43:40 -07:00
Robin Dunn
b24dc5088b Give char pointers a value in stubbed code
(cherry picked from commit fc14b8ecc4)
2019-05-21 16:14:29 -07:00
Robin Dunn
0378328d45 Merge pull request #1201 from RobinD42/fix-issue1198
Fix access to members of transient wx.VisualAttributes

(cherry picked from commit d6324a0578)
2019-04-13 16:25:55 -07:00