PyWinRT is a community-supported fork of the pywinrt tool from the Microsoft xlang project.

Overview

PyWinRT

PyWinRT is a community-supported fork of the pywinrt tool from the Microsoft xlang project.

PyWinRT is just a code generation tool. The Python bindings for the Windows SDK generated by this tool can be found at https://pypi.org/project/winsdk.

This tool is used in conjunction with cppwinrt to generate Python bindings for Windows Runtime APIs. It can be used with the Windows SDK and with custom components.

Projects that use PyWinRT

Issues
  • Some identifiers conflict with Python keywords

    Some identifiers conflict with Python keywords

    Some identifiers, like attribute names and parameter names can conflict with Python keywords. For example, HttpContentRangeHeaderValue currently has several syntax errors in the generated type hints due to the use of the name from.

    bug 
    opened by dlech 2
  • Duplicate definitions of type vars.

    Duplicate definitions of type vars.

    The code generator currently emits TypeVars for each class that uses them. However most classes reuse the same common names like T, K and V. Mypy complains about this with Cannot redefine "T" as a type variable mypy(error) and Invalid assignment target mypy(error).

    To fix this, we would probably need to make a separate pass that iterates all of the classes in a module and collects the generic type arguments and only emits unique ones at the beginning of the module.

    bug 
    opened by dlech 0
  • async operations should not be typing.Optional

    async operations should not be typing.Optional

    In #7, we changed most type hints to be typing.Optional to be safe. However, async operation are one case where we can always be sure that the return type is not null.

    bug 
    opened by dlech 0
  • Question : does pywinrt.exe tool need to be rebuilt separately for each python version/syntax ?

    Question : does pywinrt.exe tool need to be rebuilt separately for each python version/syntax ?

    Currently, I'm trying to understand how "language versions" fit in the WinRT language projections when light up scenarios dont work.

    A Question out of curiosity.

    Suppose there are two python version v3.11 and v4. Both versions have slightly different syntax. In order to support both versions/syntaxes , Does the pywinrt.exe tool has to be rebuilt separately for each version/syntax ?

    A simple Yes/No answer will do. Thanks.

    opened by ghost 0
  • Make most type hints use `typing.Optional`.

    Make most type hints use `typing.Optional`.

    The WinRT metadata does not include information about nullability, so basically we have to assume that everything is an IInspectable is nullable.

    https://github.com/microsoft/xlang/issues/716

    bug 
    opened by dlech 0
  • Empty namespaces are missing __init__.py

    Empty namespaces are missing __init__.py

    Namespaces that only contain other namespaces are missing __init__.py (see build logs).

    We need to look at all generated namespaces and fill in the gaps. There is already generated_namespaces that collects this list as a starting point.

    https://github.com/pywinrt/pywinrt/blob/74215ca19727793718e4e5ee244a82b5f5943893/src/tool/python/main.cpp#L158

    bug 
    opened by dlech 0
  • boxing and unboxing System.Object

    boxing and unboxing System.Object

    APIs that use System.Object/IInspectable need to be boxed and unboxed. See https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/boxing.

    We could implement automatic unboxing by using the IPropertyValue.Type property. However, automatic boxing won't work for scalars since Python only has one int and float type while WinRT has multiple sizes of each that need to be specified.

    As a workaround we can currently implement boxing and unboxing in Python:

    
    def box(value: typing.Any, type_: typing.Optional[wf.PropertyType] = None) -> _winrt.Object:
        if value is None:
            return value
    
        if isinstance(value, _winrt.Object):
            return value
    
        if type_ is None:
            raise NotImplementedError
    
        match type_:
            case wf.PropertyType.EMPTY:
                return wf.PropertyValue.create_empty()
            case wf.PropertyType.UINT8:
                return wf.PropertyValue.create_uint8(value)
            case wf.PropertyType.INT16:
                return wf.PropertyValue.create_int16(value)
            case wf.PropertyType.UINT16:
                return wf.PropertyValue.create_uint16(value)
            case wf.PropertyType.STRING:
                return wf.PropertyValue.create_string(value)
    
            case _:
                raise NotImplementedError
    
    
    def unbox(value: _winrt.Object) -> typing.Any:
        if value is None:
            return value
    
        value = wf.IPropertyValue._from(value)
    
        match value.type:
            case wf.PropertyType.EMPTY:
                return None
            case wf.PropertyType.UINT8:
                return value.get_uint8()
            case wf.PropertyType.INT16:
                return value.get_int16()
            case wf.PropertyType.UINT16:
                return value.get_uint16()
            ...
            case wf.PropertyType.STRING:
                return value.get_string()
            ....
            case _:
                raise NotImplementedError
    
    enhancement 
    opened by dlech 0
  • Github action to generate diffs of generated code

    Github action to generate diffs of generated code

    When making changes to the code generator, it is helpful to perform a diff on the generated code to see what effect it actual had. One way to do this could be to maintain an independent branch with generated code and have a github action automatically run the code generator and create commits.

    devops 
    opened by dlech 0
  • Use TestWinRT for tests.

    Use TestWinRT for tests.

    Currently, we have tests for a subset of the Windows SDK. We could additionally use https://github.com/microsoft/TestWinRT since this is what it was designed for. It is available as a NuGet package. https://www.nuget.org/packages/KennyKerr.Windows.TestWinRT

    devops 
    opened by dlech 0
  • documentation

    documentation

    There are several aspects of documentation that are needed:

    • [ ] contributor docs - how to build from source, directory structure (where to find things) - this can be a single CONTRIBUING.md file similar to https://github.com/microsoft/xlang/blob/master/src/readme.md
    • [ ] pywinrt.exe usage docs - how to use the command line tool itself, install from nuget
    • [ ] bindings docs - How to use the bindings. Name translations (lower_snake_case). How overloads works (based on arg count), How events work. How async works. How buffers work. How iterators work. How System.Array works.

    Being a Python-oriented project, using Sphinx doc probably makes sense.

    documentation 
    opened by dlech 0
  • caching Python wrapper objects

    caching Python wrapper objects

    Currently, if a WinRT object is passed to Python, a new Python object is created unconditionally. This means comparing two Python objects returned from WinRT APIs using is doesn't work as expected. There is probably some performance consideration too (we should measure this).

    Ideally, it would be nice if we could implement something like the GObject toggle reference. However, I am not aware of a way to hook the reference counting mechanism of WinRT object.

    There seems to be some previous attempt to use a global map, but according to the comments, this leaked objects and the code is currently commented out.

    https://github.com/pywinrt/pywinrt/blob/dd88f7f629e1c27d5774251dab7610cbcda72e6a/src/tool/python/strings/winrt_module.cpp#L72-L92

    enhancement 
    opened by dlech 0
Releases(v1.0.0-beta.4)
  • v1.0.0-beta.4(Apr 23, 2022)

    Added

    • Added special case for Windows.Graphics.Capture to include additional Interop namespace (winsdk#5).

    Changed

    • Changed async operation interface types to never be typing.Optional (issue#11).
    • Interface type hints are now typing.Protocol.
    • Improved exception raising.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-beta.3(Apr 10, 2022)

    Changed

    • Type hints for reference types are now all typing.Optional (issue#7).

    Fixed

    • Fixed identifiers conflicting with Python keywords (issue#6).
    • Fixed broken version comparison in _winrt.pyi.
    • Fixed @typing.overload used on methods that are not overloaded.
    • Fixed not throwing error if initialize_with_window() fails.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-beta.2(Feb 12, 2022)

  • v1.0.0-beta.1(Jan 28, 2022)

    Added

    • Added this changelog.
    • Implemented Python buffer protocol for IBuffer and IMemoryBufferReference.
    • Added support for canceling async operations.
    • Added generation of type hint files.
    • Added _winrt.initialize_with_window() function.
    • Added runtime support for PEP 585 generic types.

    Changed

    • Improved error handling.
    • Allow any sequence, not just list for System.Array arguments.
    • Allow buffer protocol for System.Array arguments of fundamental types.
    • Replaced use of deprecated asyncio.get_event_loop().
    • Make use of DefaultOverloadAttribute when generating overloads.
    • Renamed _winrt.winrt_base type to _winrt.Object.

    Fixed

    • Fixed error handling in GUID code.
    • Fixed __enter__() and __exit__() methods on IClosable.
    • Fixed memory leaks of WinRT objects.
    • Fixed use after free of Python objects.

    Removed

    • Removed selecting apartment thread type during module init.
    Source code(tar.gz)
    Source code(zip)
Converts file formats supported by AdPlug to VGM format.

adlib2vgm Converts file formats supported by AdPlug to VGM format. Notice This tool is originally designed to work with the RetroWave OPL3 Sound Card.

SudoMaker 12 Feb 8, 2022
This device repo aims to support booting AOSP on SDM845 devices supported by the mainline Linux kernel

device/generic/sdm845 (AOSP device config for SDM845 devices) This device repo aims to support booting AOSP on SDM845 devices supported by the mainlin

Caleb Connolly 15 Apr 7, 2022
Unix pager (with very rich functionality) designed for work with tables. Designed for PostgreSQL, but MySQL is supported too. Works well with pgcli too. Can be used as CSV or TSV viewer too. It supports searching, selecting rows, columns, or block and export selected area to clipboard.

Unix pager (with very rich functionality) designed for work with tables. Designed for PostgreSQL, but MySQL is supported too. Works well with pgcli too. Can be used as CSV or TSV viewer too. It supports searching, selecting rows, columns, or block and export selected area to clipboard.

Pavel Stehule 1.8k May 14, 2022
An easy to build CO2 Monitor/Meter with Android and iOS App for real time visualization and charting of air data, data logger, a variety of communication options (BLE, WIFI, MQTT, ESP-Now) and many supported sensors.

CO2-Gadget An easy to build CO2 Monitor/Meter with cell phone App for real time visualization and charting of air data, datalogger, a variety of commu

Mariete 16 May 13, 2022
Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64).

HPC Emerg Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64). Exa

Ammar Faizi 7 Jan 19, 2022
Msm8953 common kernel // ysl daisy sakura supported :)

Linux kernel release 4.x <http://kernel.org/> These are the release notes for Linux version 4. Read them carefully, as they tell you what this is al

Giovanni Ricca 3 Jan 29, 2022
Fork of junaburg's picom fork with a patch for rounded corners and shadows

picom new! : You'll now also find tryone's dual_kawase blur for the new backend, as well as rounded corners from sdhand if they are so desired, merged

Arian Rezazadeh 28 May 12, 2022
Matryoshka loader is a tool that red team operators can leverage to generate shellcode for Microsoft Office document phishing payloads.

Overview Matryoshka loader is a tool that red team operators can leverage to generate shellcode for an egghunter to bypass size-limitations and perfor

Praetorian 25 Apr 25, 2022
Bobby Cooke 261 May 11, 2022
This repository is to share the EdgeAI Lab with Microcontrollers Series material to the entire community

This repository is to share the EdgeAI Lab with Microcontrollers Series material to the entire community. We will share documents, presentations and source code of two demo applications.

Machine Learning Tokyo 15 Oct 23, 2021
Best Method to get Globally Banned from the cfx.re community

Lua-Executor Best Method to get Globally Banned from the cfx.re community Since cheaters have been going crazy selling 'their' hacks, and often gets d

Scopes 6 Jan 31, 2022
Arduino core for GD32 devices, community developed, based on original GigaDevice's core

GD32 Arduino Core (New) This is a Arduino core is based off of the original GigaDevice core that was provided by the company in early June 2021 (see h

null 30 May 3, 2022
Contains platform and API specific code written by Primal community members.

PrimalPlus Contains platform and API specific code written by Primal community members. How to use The general idea is to simply copy the files from t

Game Engine Series 11 May 11, 2022
KeePassXC is a cross-platform community-driven port of the Windows application “Keepass Password Safe”.

KeePassXC KeePassXC is a modern, secure, and open-source password manager that stores and manages your most sensitive information. You can run KeePass

KeePassXC 12.9k May 17, 2022
Resources and forum for the Chinese community, maintained and moderated by CoinSummer & PL.

Awesome Filecoin 请注意:本文中的链接并非全部是官方链接,部分链接是第三方链接,有些甚至是收费链接,请大家注意区分。 1. Website 1.1 浏览器 FilFox - 6Block 团队开发的 Filecoin 浏览器 Filscan - IPFS原力团队开发的 Filecoi

Filecoin 345 May 7, 2022
Animated sprite editor & pixel art tool -- Fork of the last GPLv2 commit of Aseprite

LibreSprite Introduction LibreSprite is a free and open source program for creating and animating your sprites. Real-time animation previews. Onion sk

null 2.4k May 18, 2022
This is the Secure Software Development Project fork of Checked C

Checked C This is the Secure Software Development Project fork of Checked C. The Checked C extension was originally developed at Microsoft from 2016-2

Secure Software Development Project 4 Jan 21, 2022
Bungie's Oni modified so it compiles with Microsoft Visual Studio 2019.

OniFoxed What's this? This is a modified variant of the recently leaked Oni source code so that it compiles under Microsoft Visual Studio 2019 with so

Mark Sowden 43 May 8, 2022
Had a tough time playing Microsoft Wordament ? Well WORDament_Solver has your back. It suggests you meaningful words you can use while playing the game and help you top the leaderboard.

WORDament_Solver Had a tough time playing Microsoft Wordament ? Well WORDament_Solver has your back. It suggests you meaningful words you can use whil

Tushar Agarwal 3 Aug 19, 2021