Commit Graph

43 Commits

Author SHA1 Message Date
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
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
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
Robin Dunn
92f8cd2d55 Fix lots of misspelled words 2020-07-14 11:38:32 -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
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
Robin Dunn
9f2cc54b48 Update copyright years 2020-03-10 11:41:39 -07:00
Robin Dunn
b77c88a280 Merge tag 'wxPython-4.0.2' into wxPy-4.0.x
(cherry picked from commit 4c56c39e52)
2018-06-17 22:04:22 -07:00
Robin Dunn
18bbfac7f9 Fixes for things exposed by the new .pyi files tests. 2017-02-14 18:32:15 -08:00
Robin Dunn
9c87092819 Turn off the generation of the .pi files. The new official standard is .pyi files. 2017-02-13 21:24:54 -08:00
Robin Dunn
9d172ddc8a Update copyright in etgtools 2017-02-13 16:18:47 -08:00
Robin Dunn
96a0901c15 Allow ignoring items just for the pi generator 2017-01-22 19:31:39 -08:00
Metallicow
067569d785 Trim trailing space etgtools directory 2016-12-05 16:26:04 -06:00
Robin Dunn
50c1acd136 Don't use "*args, **kw" in the docs when only one of the overloads is not ignored. 2016-08-05 16:21:35 -07:00
Robin Dunn
b6488bfb7c Put the module docstring in the .pi and .pyi files too 2016-05-19 20:56:39 -07:00
Robin Dunn
6a0e7cf50c Generate interface files for PyCharm too.
Currently they are just copies of what we were already doing for WingIDE, but we can add more advanced things like type-hinting later...
2016-05-07 19:16:27 -07:00
Robin Dunn
30e7d68f76 Allow typedefs to be nested in classes. 2015-03-03 20:53:18 -08:00
Robin Dunn
bb9ac44914 Allow overriding the list of base class names to be used in the *.pi files.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@74144 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2013-06-08 23:35:25 +00:00
Robin Dunn
742d02d53b Enable handling #define's that are string constants
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73498 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2013-02-12 05:12:23 +00:00
Robin Dunn
35fd2e16bf Update copyright year
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73416 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2013-01-21 02:13:03 +00:00
Robin Dunn
0e6e598099 Support isStatic for PyMethods
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73261 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-12-23 03:08:03 +00:00
Robin Dunn
794a237843 Sometimes when we remove the wx prefix we really want to make it be "wx.Name" instead.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73037 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-11-27 01:23:36 +00:00
Robin Dunn
153eb2f0ac Some fixes in the generation of the pi files related to default parameter values.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72971 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-11-17 22:20:53 +00:00
Robin Dunn
e8d7197917 Allow cppSignature and pyArgsString for CppMethods too
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72929 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-11-09 04:38:43 +00:00
Robin Dunn
56b9ffbc87 fix missing newline
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72275 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-08-02 05:39:31 +00:00
Robin Dunn
e7359ac55a Add extra flags and info to enable template specialization typdefs to be documented like a class. Use it with wxScrolledWindow and wxScrolledCanvas.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-06-12 20:56:21 +00:00
Robin Dunn
f697317ebc Classes without explicit bases still derive from object
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71721 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-06-12 20:56:15 +00:00
Robin Dunn
26a4ade258 Use absolute import
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71600 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-05-30 03:24:06 +00:00
Robin Dunn
b41df0b779 Many, many (many!) changes needed to build and run the Phoenix extension modules with Python 3. Where possible changes were made such that the code works with both Python 2.7 and 3.2 without conditionals. In general the following types of changes were made:
* Changed imports to use either absolute or explicit relative imports.  Implicit relative imports are no longer allowed.

 * Changes to accomodate standard library classes or modues moving to other locations, or being removed entirely.

 * Changes related to print becoming a function, execfile being removed, u'' no longer allowed, and other syntax related issues.

 * Working around C APIs that have changed or simply vanished. (PyInt, PyString, PyBytes, etc.)

 * Dealing with text file objects using strings vs binary file objects using bytes, auto-encoding, and etc.

 * Replacing the use of PyCObject with PyCapsule and dealing with an apparent bug where PyCapsule objects can't be imported from submodules within a package.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71554 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-05-24 23:28:02 +00:00
Robin Dunn
29d1610e0e Fix pi generation of global variables when there is something in front of the wx preifx
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71533 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-05-22 00:17:59 +00:00
Robin Dunn
68d0292399 Remove extra symbols from global variables before writing the code for the pi file
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71496 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-05-19 06:22:32 +00:00
Robin Dunn
289888aa8e Don't write a function stub if there is no pyName (such as for operator functions)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71048 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-03-29 16:59:34 +00:00
Robin Dunn
1d54d41e7b Encode generator output as utf-8 in case there is any non-ascii text
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71022 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-03-26 19:22:19 +00:00
Robin Dunn
8bac95e6e0 minor tweaks for the pi generator
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70973 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-03-22 20:30:45 +00:00
Robin Dunn
497e10bd43 Add wrappers for the NameStr globals and a few other tweaks to get the code in core.pi to be valid
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70258 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-01-04 05:57:19 +00:00
Robin Dunn
c001fd35f6 FIx a couple issues in the pi generator where it is not generating proper code.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70217 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2011-12-31 02:45:21 +00:00
Robin Dunn
a47c664ec3 Prevent from generating some syntax errors in the pi_generator, and other generator tweaks
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70080 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2011-12-22 01:20:25 +00:00
Robin Dunn
9912e33123 * Add PyFunctionDef and PyClassDef extractor classes, which can be used for defining pure python functions and classes instead of just including them as blocks of text. This way the meta-data is preserved so it can be used by generators such as the sphinx generator.
* Implement wx.CallAfter and wx.CallLater this way for the initial test cases.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2011-12-15 02:36:01 +00:00
Robin Dunn
470c088a85 * Add the pi generator (for "Python Interface" files used by WingIDE and maybe others.)
* Some improvements in docstring generation
* refactor and shuffle some code around

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@69497 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2011-10-21 08:09:26 +00:00