mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-05 19:40:12 +01:00
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...
This commit is contained in:
@@ -3,17 +3,22 @@
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created: 18-Oct-2011
|
||||
# Copyright: (c) 2013 by Total Control Software
|
||||
# Copyright: (c) 2011-2016 by Total Control Software
|
||||
# License: wxWindows License
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
"""
|
||||
This generator will create "Python Interface" files, which define a skeleton
|
||||
verison of the classes, functions, attributes, docstrings, etc. as Python
|
||||
code. This is useful for enabling some introspcetion of things located in
|
||||
version of the classes, functions, attributes, docstrings, etc. as Python
|
||||
code. This is useful for enabling some introspection of things located in
|
||||
extension modules where there is less information available for
|
||||
introspection. The .pi files are used by WingIDE for assisting with code
|
||||
completion, displaying docstrings in the source assistant panel, etc.
|
||||
|
||||
NOTE: PyCharm has a similar feature but the file extension is .pyi in that
|
||||
case. For now we'll just make a copy of the .pi file, but PyCharm also
|
||||
supports Python 3.5 style type annotations in the interface files so we may
|
||||
want to add some type info to that version of the file eventually...
|
||||
"""
|
||||
|
||||
import sys, os, re
|
||||
@@ -26,21 +31,44 @@ from etgtools.tweaker_tools import FixWxPrefix, magicMethods, \
|
||||
|
||||
phoenixRoot = os.path.abspath(os.path.split(__file__)[0]+'/..')
|
||||
|
||||
header = """\
|
||||
header_pi = """\
|
||||
# -*- coding: utf-8 -*-
|
||||
#---------------------------------------------------------------------------
|
||||
# This file is generated by wxPython's PI generator. Do not edit by hand.
|
||||
#
|
||||
# (The *.pi files are used by WingIDE to provide more information than it is
|
||||
# able to glean from introspection of extension types and methods.)
|
||||
# The *.pi files are used by WingIDE to provide more information than it is
|
||||
# able to glean from introspection of extension types and methods. They are
|
||||
# not intended to be imported, executed or used for any other purpose other
|
||||
# than providing info to the IDE. If you don't use WingIDE you can safely
|
||||
# ignore this file.
|
||||
#
|
||||
# Copyright: (c) 2013 by Total Control Software
|
||||
# See: https://wingware.com/doc/edit/helping-wing-analyze-code
|
||||
#
|
||||
# Copyright: (c) 2011-2016 by Total Control Software
|
||||
# License: wxWindows License
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
"""
|
||||
|
||||
header_pyi = """\
|
||||
# -*- coding: utf-8 -*-
|
||||
#---------------------------------------------------------------------------
|
||||
# This file is generated by wxPython's PI generator. Do not edit by hand.
|
||||
#
|
||||
# The *.pyi files are used by PyCharm to provide more information than it is
|
||||
# able to glean from introspection of extension types and methods. They are
|
||||
# not intended to be imported, executed or used for any other purpose other
|
||||
# than providing info to the IDE. If you don't use PyCharm you can safely
|
||||
# ignore this file.
|
||||
#
|
||||
# See: https://www.jetbrains.com/help/pycharm/2016.1/type-hinting-in-pycharm.html
|
||||
#
|
||||
# Copyright: (c) 2011-2016 by Total Control Software
|
||||
# License: wxWindows License
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
"""
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
@@ -53,20 +81,28 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
|
||||
# Write the contents of the stream to the destination file
|
||||
if not destFile:
|
||||
name = module.module + '.pi'
|
||||
name = module.module
|
||||
if name.startswith('_'):
|
||||
name = name[1:]
|
||||
destFile = os.path.join(phoenixRoot, 'wx', name)
|
||||
|
||||
if not os.path.exists(destFile):
|
||||
# create the file and write the header
|
||||
f = textfile_open(destFile, 'wt')
|
||||
f.write(header)
|
||||
f.close()
|
||||
|
||||
self.writeSection(destFile, module.name, stream.getvalue())
|
||||
|
||||
|
||||
|
||||
destFile_pi = destFile + '.pi'
|
||||
destFile_pyi = destFile + '.pyi'
|
||||
|
||||
def _checkAndWriteHeader(destFile, header):
|
||||
if not os.path.exists(destFile):
|
||||
# create the file and write the header
|
||||
f = textfile_open(destFile, 'wt')
|
||||
f.write(header)
|
||||
f.close()
|
||||
|
||||
_checkAndWriteHeader(destFile_pi, header_pi)
|
||||
_checkAndWriteHeader(destFile_pyi, header_pyi)
|
||||
|
||||
self.writeSection(destFile_pi, module.name, stream.getvalue())
|
||||
self.writeSection(destFile_pyi, module.name, stream.getvalue())
|
||||
|
||||
|
||||
def writeSection(self, destFile, sectionName, sectionText):
|
||||
"""
|
||||
Read all the lines from destFile, remove those currently between
|
||||
|
||||
Reference in New Issue
Block a user