mu-editor / mu

A small, simple editor for beginner Python programmers. Written in Python and Qt5.
http://codewith.mu
GNU General Public License v3.0
1.41k stars 435 forks source link

Utils: Create a script to convert Python stub files into Qscintilla autocompletion files #2291

Open carlosperate opened 2 years ago

carlosperate commented 2 years ago

We can create Python script in the utils folder to convert Python stub files (.py or .pyi files) into the files that Qscintilla takes to generate the autocompletion.

Example input stub files to use: https://github.com/oivron/microbit-stubs/tree/master/microbit/lib Example output file for Qscintilla: https://github.com/mu-editor/mu/blob/master/mu/modes/api/microbit.py

We should also a bit of documentation (could be the file header) to indicate how it works and where to find some of the stub files generated.

Jeffrey04 commented 2 years ago

so the goal is to turn

def panic() -> None:
    """
    Put micro:bit in panic() mode and display an unhappy face.
    Press the reset button to exit panic() mode.
    """
    pass

into the following?

_("panic() \nPut micro:bit in panic() mode and display an unhappy face. Press the reset button to exit panic() mode.")

What about instance methods?

class _Accelerometer(object):
    def get_x(self) -> int:
        """
        Return micro:bit's tilt (X acceleration) in milli-g's.
        """
        pass
carlosperate commented 2 years ago

so the goal is to turn

def panic() -> None:
    """
    Put micro:bit in panic() mode and display an unhappy face.
    Press the reset button to exit panic() mode.
    """
    pass

into the following?

_("panic() \nPut micro:bit in panic() mode and display an unhappy face. Press the reset button to exit panic() mode.")

Yes 👍

What about instance methods?

class _Accelerometer(object):
    def get_x(self) -> int:
        """
        Return micro:bit's tilt (X acceleration) in milli-g's.
        """
        pass

For the micro:bit API, classes for built in board features have a single instance by default. So the user cannot initialise a new instance of the micro:bit accelerometer class. In this case it looks like the API just follows a similar pattern a module functions: https://github.com/mu-editor/mu/blob/9fe47acf97096649d94cd26b379247f73e74d6ee/mu/modes/api/microbit.py#L76

For thinsg like MicroPython PyBoard I2C calsses (which you can initilisate) it looks very similar: https://github.com/mu-editor/mu/blob/9fe47acf97096649d94cd26b379247f73e74d6ee/mu/modes/api/pyboard.py#L175

Jeffrey04 commented 2 years ago

i try to submit a PR then